Skip to content

Commit

Permalink
minor: whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerBrock committed Feb 27, 2012
1 parent 29cc4b2 commit 6301a41
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions lib/mongo/connection.rb
Expand Up @@ -514,11 +514,11 @@ def checkin(socket)
end

protected

def valid_opts
GENERIC_OPTS + CONNECTION_OPTS
end

def check_opts(opts)
bad_opts = opts.keys.reject { |opt| valid_opts.include?(opt) }

Expand Down
24 changes: 12 additions & 12 deletions lib/mongo/repl_set_connection.rb
Expand Up @@ -20,7 +20,7 @@ module Mongo

# Instantiates and manages connections to a MongoDB replica set.
class ReplSetConnection < Connection

REPL_SET_OPTS = [:read, :refresh_mode, :refresh_interval, :require_primary, :read_secondary, :rs_name]

attr_reader :replica_set_name, :seeds, :refresh_interval, :refresh_mode,
Expand Down Expand Up @@ -85,11 +85,11 @@ def initialize(*args)
else
opts = {}
end

unless args.length > 0
raise MongoArgumentError, "A ReplSetConnection requires at least one seed node."
end

# This is temporary until support for the old format is dropped
@seeds = []
if args.first.last.is_a?(Integer)
Expand All @@ -103,30 +103,30 @@ def initialize(*args)
seeds << seed
end
end

# TODO: add a method for replacing this list of node.
@seeds.freeze

# Refresh
@last_refresh = Time.now
@refresh_version = 0

# No connection manager by default.
@manager = nil

# Lock for request ids.
@id_lock = Mutex.new

@pool_mutex = Mutex.new
@connected = false

@safe_mutex_lock = Mutex.new
@safe_mutexes = Hash.new {|hash, key| hash[key] = Mutex.new}

check_opts(opts)
setup(opts)
end

def valid_opts
GENERIC_OPTS + REPL_SET_OPTS
end
Expand Down Expand Up @@ -450,11 +450,11 @@ def max_bson_size
def setup(opts)
# Require a primary node to connect?
@require_primary = opts.fetch(:require_primary, true)

# Refresh
@refresh_mode = opts.fetch(:refresh_mode, false)
@refresh_interval = opts[:refresh_interval] || 90

if @refresh_mode == :async
warn ":async refresh mode has been deprecated. Refresh
mode will be disabled."
Expand Down
18 changes: 9 additions & 9 deletions test/unit/connection_test.rb
Expand Up @@ -26,30 +26,30 @@ class ConnectionTest < Test::Unit::TestCase
should "default slave_ok to false" do
assert !@conn.slave_ok?
end

should "warn if invalid options are specified" do
conn = Connection.allocate
opts = {:connect => false}

ReplSetConnection::REPL_SET_OPTS.each do |opt|
conn.expects(:warn).with("#{opt} is not a valid option for #{conn.class}")
opts[opt] = true
end

args = ['localhost', 27017, opts]
conn.send(:initialize, *args)
end

context "given a replica set" do
should "warn if invalid options are specified" do
conn = ReplSetConnection.allocate
opts = {:connect => false}

Connection::CONNECTION_OPTS.each do |opt|
conn.expects(:warn).with("#{opt} is not a valid option for #{conn.class}")
opts[opt] = true
end

args = [['localhost:27017'], opts]
conn.send(:initialize, *args)
end
Expand All @@ -73,21 +73,21 @@ class ConnectionTest < Test::Unit::TestCase
@conn = Connection.from_uri("mongodb://#{host_name}/foo", :connect => false)
assert_equal [host_name, 27017], @conn.host_to_try
end

should "set safe options on connection" do
host_name = "localhost"
opts = "safe=true&w=2&wtimeoutMS=1000&fsync=true&journal=true"
@conn = Connection.from_uri("mongodb://#{host_name}/foo?#{opts}", :connect => false)
assert_equal({:w => 2, :wtimeout => 1000, :fsync => true, :j => true}, @conn.safe)
end

should "have wtimeoutMS take precidence over the depricated wtimeout" do
host_name = "localhost"
opts = "safe=true&wtimeout=100&wtimeoutMS=500"
@conn = Connection.from_uri("mongodb://#{host_name}/foo?#{opts}", :connect => false)
assert_equal({:wtimeout => 500}, @conn.safe)
end

should "set timeout options on connection" do
host_name = "localhost"
opts = "connectTimeoutMS=1000&socketTimeoutMS=5000"
Expand Down

0 comments on commit 6301a41

Please sign in to comment.