From 78fc1debbe8c44f0a7129d30dc8c478a4ea8bc4e Mon Sep 17 00:00:00 2001 From: Tyler Brock Date: Thu, 16 Feb 2012 10:59:09 -0500 Subject: [PATCH] RUBY-378 new ReplSetConnection format --- lib/mongo/repl_set_connection.rb | 18 +++++++++++++++--- test/replica_sets/connect_test.rb | 5 +++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/mongo/repl_set_connection.rb b/lib/mongo/repl_set_connection.rb index d70a041..414caa7 100644 --- a/lib/mongo/repl_set_connection.rb +++ b/lib/mongo/repl_set_connection.rb @@ -85,14 +85,26 @@ module Mongo 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) + warn "Initiating a ReplSetConnection with seeds passed as individual [host, port] array arguments is deprecated." + warn "Please specify hosts as 'host:port' strings; the old format will be removed in v2.0" + @seeds = args + else + args.first.map do |host_port| + seed = host_port.split(":") + seed[1] = seed[1].to_i + seeds << seed + end + end - # The original, immutable list of seed node. # TODO: add a method for replacing this list of node. - @seeds = args @seeds.freeze # TODO: get rid of this diff --git a/test/replica_sets/connect_test.rb b/test/replica_sets/connect_test.rb index 45c2290..cf41aa2 100644 --- a/test/replica_sets/connect_test.rb +++ b/test/replica_sets/connect_test.rb @@ -108,6 +108,11 @@ class ConnectTest < Test::Unit::TestCase assert @conn.is_a?(ReplSetConnection) assert @conn.connected? end + + def test_connect_with_new_seed_format + @conn = ReplSetConnection.new(["#{@rs.host}:#{@rs.ports[0]}','#{@rs.host}:#{@rs.ports[1]}','#{@rs.host}:#{@rs.ports[2]}"]) + assert @conn.connected? + end def test_connect_with_full_connection_string @conn = Connection.from_uri("mongodb://#{@rs.host}:#{@rs.ports[0]},#{@rs.host}:#{@rs.ports[1]}?replicaset=#{@rs.name};safe=true;w=2;fsync=true;slaveok=true")