2011-10-07 17:55:09 +00:00
|
|
|
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
|
|
require './test/replica_sets/rs_test_helper'
|
|
|
|
|
2011-11-03 15:17:36 +00:00
|
|
|
class BasicTest < Test::Unit::TestCase
|
|
|
|
include ReplicaSetTest
|
2011-10-07 17:55:09 +00:00
|
|
|
|
|
|
|
def teardown
|
2011-11-03 15:17:36 +00:00
|
|
|
self.rs.restart_killed_nodes
|
2011-10-07 17:55:09 +00:00
|
|
|
@conn.close if defined?(@conn) && @conn
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_connect
|
2011-11-03 15:17:36 +00:00
|
|
|
@conn = ReplSetConnection.new([self.rs.host, self.rs.ports[1]], [self.rs.host, self.rs.ports[0]],
|
|
|
|
[self.rs.host, self.rs.ports[2]], :name => self.rs.name)
|
2011-10-07 17:55:09 +00:00
|
|
|
assert @conn.connected?
|
|
|
|
|
2011-11-03 15:17:36 +00:00
|
|
|
assert_equal self.rs.primary, @conn.primary
|
|
|
|
assert_equal self.rs.secondaries.sort, @conn.secondaries.sort
|
|
|
|
assert_equal self.rs.arbiters.sort, @conn.arbiters.sort
|
2011-10-07 17:55:09 +00:00
|
|
|
|
2011-11-03 15:17:36 +00:00
|
|
|
@conn = ReplSetConnection.new([self.rs.host, self.rs.ports[1]], [self.rs.host, self.rs.ports[0]],
|
|
|
|
:name => self.rs.name)
|
2011-10-07 17:55:09 +00:00
|
|
|
assert @conn.connected?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_accessors
|
2011-11-03 15:17:36 +00:00
|
|
|
seeds = [[self.rs.host, self.rs.ports[0]], [self.rs.host, self.rs.ports[1]],
|
|
|
|
[self.rs.host, self.rs.ports[2]]]
|
|
|
|
args = seeds << {:name => self.rs.name}
|
2011-10-17 19:36:47 +00:00
|
|
|
@conn = ReplSetConnection.new(*args)
|
2011-10-07 17:55:09 +00:00
|
|
|
|
2011-11-03 15:17:36 +00:00
|
|
|
assert_equal @conn.host, self.rs.primary[0]
|
|
|
|
assert_equal @conn.port, self.rs.primary[1]
|
2011-10-07 17:55:09 +00:00
|
|
|
assert_equal @conn.host, @conn.primary_pool.host
|
|
|
|
assert_equal @conn.port, @conn.primary_pool.port
|
2011-11-03 15:17:36 +00:00
|
|
|
assert_equal @conn.nodes.sort, @conn.seeds.sort
|
2011-10-07 17:55:09 +00:00
|
|
|
assert_equal 2, @conn.secondaries.length
|
2011-11-03 15:17:36 +00:00
|
|
|
assert_equal 0, @conn.arbiters.length
|
2011-10-07 17:55:09 +00:00
|
|
|
assert_equal 2, @conn.secondary_pools.length
|
2011-11-03 15:17:36 +00:00
|
|
|
assert_equal self.rs.name, @conn.replica_set_name
|
2011-10-07 17:55:09 +00:00
|
|
|
assert @conn.secondary_pools.include?(@conn.read_pool)
|
2011-10-13 21:58:20 +00:00
|
|
|
assert_equal 5, @conn.tag_map.keys.length
|
2011-10-07 17:55:09 +00:00
|
|
|
assert_equal 90, @conn.refresh_interval
|
2011-11-03 15:17:36 +00:00
|
|
|
assert_equal @conn.refresh_mode, false
|
2011-10-07 17:55:09 +00:00
|
|
|
end
|
|
|
|
end
|