minor: whitespace
This commit is contained in:
parent
29cc4b20e2
commit
6301a41254
@ -514,11 +514,11 @@ module Mongo
|
|||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def valid_opts
|
def valid_opts
|
||||||
GENERIC_OPTS + CONNECTION_OPTS
|
GENERIC_OPTS + CONNECTION_OPTS
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_opts(opts)
|
def check_opts(opts)
|
||||||
bad_opts = opts.keys.reject { |opt| valid_opts.include?(opt) }
|
bad_opts = opts.keys.reject { |opt| valid_opts.include?(opt) }
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ module Mongo
|
|||||||
|
|
||||||
# Instantiates and manages connections to a MongoDB replica set.
|
# Instantiates and manages connections to a MongoDB replica set.
|
||||||
class ReplSetConnection < Connection
|
class ReplSetConnection < Connection
|
||||||
|
|
||||||
REPL_SET_OPTS = [:read, :refresh_mode, :refresh_interval, :require_primary, :read_secondary, :rs_name]
|
REPL_SET_OPTS = [:read, :refresh_mode, :refresh_interval, :require_primary, :read_secondary, :rs_name]
|
||||||
|
|
||||||
attr_reader :replica_set_name, :seeds, :refresh_interval, :refresh_mode,
|
attr_reader :replica_set_name, :seeds, :refresh_interval, :refresh_mode,
|
||||||
@ -85,11 +85,11 @@ module Mongo
|
|||||||
else
|
else
|
||||||
opts = {}
|
opts = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
unless args.length > 0
|
unless args.length > 0
|
||||||
raise MongoArgumentError, "A ReplSetConnection requires at least one seed node."
|
raise MongoArgumentError, "A ReplSetConnection requires at least one seed node."
|
||||||
end
|
end
|
||||||
|
|
||||||
# This is temporary until support for the old format is dropped
|
# This is temporary until support for the old format is dropped
|
||||||
@seeds = []
|
@seeds = []
|
||||||
if args.first.last.is_a?(Integer)
|
if args.first.last.is_a?(Integer)
|
||||||
@ -103,30 +103,30 @@ module Mongo
|
|||||||
seeds << seed
|
seeds << seed
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: add a method for replacing this list of node.
|
# TODO: add a method for replacing this list of node.
|
||||||
@seeds.freeze
|
@seeds.freeze
|
||||||
|
|
||||||
# Refresh
|
# Refresh
|
||||||
@last_refresh = Time.now
|
@last_refresh = Time.now
|
||||||
@refresh_version = 0
|
@refresh_version = 0
|
||||||
|
|
||||||
# No connection manager by default.
|
# No connection manager by default.
|
||||||
@manager = nil
|
@manager = nil
|
||||||
|
|
||||||
# Lock for request ids.
|
# Lock for request ids.
|
||||||
@id_lock = Mutex.new
|
@id_lock = Mutex.new
|
||||||
|
|
||||||
@pool_mutex = Mutex.new
|
@pool_mutex = Mutex.new
|
||||||
@connected = false
|
@connected = false
|
||||||
|
|
||||||
@safe_mutex_lock = Mutex.new
|
@safe_mutex_lock = Mutex.new
|
||||||
@safe_mutexes = Hash.new {|hash, key| hash[key] = Mutex.new}
|
@safe_mutexes = Hash.new {|hash, key| hash[key] = Mutex.new}
|
||||||
|
|
||||||
check_opts(opts)
|
check_opts(opts)
|
||||||
setup(opts)
|
setup(opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
def valid_opts
|
def valid_opts
|
||||||
GENERIC_OPTS + REPL_SET_OPTS
|
GENERIC_OPTS + REPL_SET_OPTS
|
||||||
end
|
end
|
||||||
@ -450,11 +450,11 @@ module Mongo
|
|||||||
def setup(opts)
|
def setup(opts)
|
||||||
# Require a primary node to connect?
|
# Require a primary node to connect?
|
||||||
@require_primary = opts.fetch(:require_primary, true)
|
@require_primary = opts.fetch(:require_primary, true)
|
||||||
|
|
||||||
# Refresh
|
# Refresh
|
||||||
@refresh_mode = opts.fetch(:refresh_mode, false)
|
@refresh_mode = opts.fetch(:refresh_mode, false)
|
||||||
@refresh_interval = opts[:refresh_interval] || 90
|
@refresh_interval = opts[:refresh_interval] || 90
|
||||||
|
|
||||||
if @refresh_mode == :async
|
if @refresh_mode == :async
|
||||||
warn ":async refresh mode has been deprecated. Refresh
|
warn ":async refresh mode has been deprecated. Refresh
|
||||||
mode will be disabled."
|
mode will be disabled."
|
||||||
|
@ -26,30 +26,30 @@ class ConnectionTest < Test::Unit::TestCase
|
|||||||
should "default slave_ok to false" do
|
should "default slave_ok to false" do
|
||||||
assert !@conn.slave_ok?
|
assert !@conn.slave_ok?
|
||||||
end
|
end
|
||||||
|
|
||||||
should "warn if invalid options are specified" do
|
should "warn if invalid options are specified" do
|
||||||
conn = Connection.allocate
|
conn = Connection.allocate
|
||||||
opts = {:connect => false}
|
opts = {:connect => false}
|
||||||
|
|
||||||
ReplSetConnection::REPL_SET_OPTS.each do |opt|
|
ReplSetConnection::REPL_SET_OPTS.each do |opt|
|
||||||
conn.expects(:warn).with("#{opt} is not a valid option for #{conn.class}")
|
conn.expects(:warn).with("#{opt} is not a valid option for #{conn.class}")
|
||||||
opts[opt] = true
|
opts[opt] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
args = ['localhost', 27017, opts]
|
args = ['localhost', 27017, opts]
|
||||||
conn.send(:initialize, *args)
|
conn.send(:initialize, *args)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "given a replica set" do
|
context "given a replica set" do
|
||||||
should "warn if invalid options are specified" do
|
should "warn if invalid options are specified" do
|
||||||
conn = ReplSetConnection.allocate
|
conn = ReplSetConnection.allocate
|
||||||
opts = {:connect => false}
|
opts = {:connect => false}
|
||||||
|
|
||||||
Connection::CONNECTION_OPTS.each do |opt|
|
Connection::CONNECTION_OPTS.each do |opt|
|
||||||
conn.expects(:warn).with("#{opt} is not a valid option for #{conn.class}")
|
conn.expects(:warn).with("#{opt} is not a valid option for #{conn.class}")
|
||||||
opts[opt] = true
|
opts[opt] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
args = [['localhost:27017'], opts]
|
args = [['localhost:27017'], opts]
|
||||||
conn.send(:initialize, *args)
|
conn.send(:initialize, *args)
|
||||||
end
|
end
|
||||||
@ -73,21 +73,21 @@ class ConnectionTest < Test::Unit::TestCase
|
|||||||
@conn = Connection.from_uri("mongodb://#{host_name}/foo", :connect => false)
|
@conn = Connection.from_uri("mongodb://#{host_name}/foo", :connect => false)
|
||||||
assert_equal [host_name, 27017], @conn.host_to_try
|
assert_equal [host_name, 27017], @conn.host_to_try
|
||||||
end
|
end
|
||||||
|
|
||||||
should "set safe options on connection" do
|
should "set safe options on connection" do
|
||||||
host_name = "localhost"
|
host_name = "localhost"
|
||||||
opts = "safe=true&w=2&wtimeoutMS=1000&fsync=true&journal=true"
|
opts = "safe=true&w=2&wtimeoutMS=1000&fsync=true&journal=true"
|
||||||
@conn = Connection.from_uri("mongodb://#{host_name}/foo?#{opts}", :connect => false)
|
@conn = Connection.from_uri("mongodb://#{host_name}/foo?#{opts}", :connect => false)
|
||||||
assert_equal({:w => 2, :wtimeout => 1000, :fsync => true, :j => true}, @conn.safe)
|
assert_equal({:w => 2, :wtimeout => 1000, :fsync => true, :j => true}, @conn.safe)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "have wtimeoutMS take precidence over the depricated wtimeout" do
|
should "have wtimeoutMS take precidence over the depricated wtimeout" do
|
||||||
host_name = "localhost"
|
host_name = "localhost"
|
||||||
opts = "safe=true&wtimeout=100&wtimeoutMS=500"
|
opts = "safe=true&wtimeout=100&wtimeoutMS=500"
|
||||||
@conn = Connection.from_uri("mongodb://#{host_name}/foo?#{opts}", :connect => false)
|
@conn = Connection.from_uri("mongodb://#{host_name}/foo?#{opts}", :connect => false)
|
||||||
assert_equal({:wtimeout => 500}, @conn.safe)
|
assert_equal({:wtimeout => 500}, @conn.safe)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "set timeout options on connection" do
|
should "set timeout options on connection" do
|
||||||
host_name = "localhost"
|
host_name = "localhost"
|
||||||
opts = "connectTimeoutMS=1000&socketTimeoutMS=5000"
|
opts = "connectTimeoutMS=1000&socketTimeoutMS=5000"
|
||||||
|
Loading…
Reference in New Issue
Block a user