RUBY-378 new ReplSetConnection format

This commit is contained in:
Tyler Brock 2012-02-16 10:59:09 -05:00
parent fec284ee99
commit 78fc1debbe
2 changed files with 20 additions and 3 deletions

View File

@ -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

View File

@ -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")