2011-08-24 22:34:00 +00:00
|
|
|
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
|
|
require './test/replica_sets/rs_test_helper'
|
|
|
|
require 'benchmark'
|
|
|
|
|
|
|
|
class ReplicaSetRefreshTest < Test::Unit::TestCase
|
|
|
|
|
2011-09-13 21:50:01 +00:00
|
|
|
def setup
|
2012-01-30 00:05:17 +00:00
|
|
|
ensure_rs
|
2011-09-13 21:50:01 +00:00
|
|
|
end
|
|
|
|
|
2011-08-24 22:34:00 +00:00
|
|
|
def teardown
|
2012-01-30 00:05:17 +00:00
|
|
|
@rs.restart_killed_nodes
|
2012-04-04 20:44:01 +00:00
|
|
|
@conn.close if defined?(@conn)
|
2011-08-24 22:34:00 +00:00
|
|
|
end
|
|
|
|
|
2012-04-04 20:44:01 +00:00
|
|
|
=begin
|
2011-08-31 20:05:21 +00:00
|
|
|
def test_connect_speed
|
|
|
|
Benchmark.bm do |x|
|
|
|
|
x.report("Connect") do
|
|
|
|
10.times do
|
2012-02-18 23:29:52 +00:00
|
|
|
ReplSetConnection.new(build_seeds(3), :refresh_mode => false)
|
2011-08-31 20:05:21 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-02-18 23:29:52 +00:00
|
|
|
@con = ReplSetConnection.new(build_seeds(3), :refresh_mode => false)
|
2011-08-31 20:05:21 +00:00
|
|
|
|
|
|
|
x.report("manager") do
|
|
|
|
man = Mongo::PoolManager.new(@con, @con.seeds)
|
|
|
|
10.times do
|
|
|
|
man.connect
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-04-04 20:44:01 +00:00
|
|
|
=end
|
2011-08-31 20:05:21 +00:00
|
|
|
|
2011-12-06 19:38:14 +00:00
|
|
|
def test_connect_and_manual_refresh_with_secondaries_down
|
2012-01-30 00:05:17 +00:00
|
|
|
@rs.kill_all_secondaries
|
2012-02-14 00:21:11 +00:00
|
|
|
sleep(4)
|
2011-08-24 22:34:00 +00:00
|
|
|
|
|
|
|
rescue_connection_failure do
|
2012-02-18 23:29:52 +00:00
|
|
|
@conn = ReplSetConnection.new(build_seeds(3), :refresh_mode => false)
|
2011-08-24 22:34:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal [], @conn.secondaries
|
|
|
|
assert @conn.connected?
|
|
|
|
assert_equal @conn.read_pool, @conn.primary_pool
|
|
|
|
|
|
|
|
# Refresh with no change to set
|
|
|
|
@conn.refresh
|
|
|
|
assert_equal [], @conn.secondaries
|
|
|
|
assert @conn.connected?
|
|
|
|
assert_equal @conn.read_pool, @conn.primary_pool
|
|
|
|
|
2012-01-30 00:05:17 +00:00
|
|
|
@rs.restart_killed_nodes
|
2011-08-24 22:34:00 +00:00
|
|
|
assert_equal [], @conn.secondaries
|
|
|
|
assert @conn.connected?
|
|
|
|
assert_equal @conn.read_pool, @conn.primary_pool
|
|
|
|
|
|
|
|
# Refresh with everything up
|
|
|
|
@conn.refresh
|
|
|
|
assert @conn.read_pool
|
|
|
|
assert @conn.secondaries.length > 0
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_automated_refresh_with_secondaries_down
|
2012-01-30 00:05:17 +00:00
|
|
|
@rs.kill_all_secondaries
|
2012-02-14 00:21:11 +00:00
|
|
|
sleep(4)
|
|
|
|
|
2011-08-24 22:34:00 +00:00
|
|
|
rescue_connection_failure do
|
2012-02-18 23:29:52 +00:00
|
|
|
@conn = ReplSetConnection.new(build_seeds(3),
|
|
|
|
:refresh_interval => 2, :refresh_mode => :sync)
|
2011-08-24 22:34:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal [], @conn.secondaries
|
|
|
|
assert @conn.connected?
|
|
|
|
assert_equal @conn.read_pool, @conn.primary_pool
|
2011-11-18 20:47:06 +00:00
|
|
|
old_refresh_version = @conn.refresh_version
|
2011-08-24 22:34:00 +00:00
|
|
|
|
2012-01-30 00:05:17 +00:00
|
|
|
@rs.restart_killed_nodes
|
2011-10-14 13:52:11 +00:00
|
|
|
sleep(4)
|
2011-11-18 20:47:06 +00:00
|
|
|
@conn['foo']['bar'].find_one
|
|
|
|
@conn['foo']['bar'].insert({:a => 1})
|
|
|
|
|
|
|
|
assert @conn.refresh_version > old_refresh_version,
|
|
|
|
"Refresh version hasn't changed."
|
|
|
|
assert @conn.secondaries.length > 0,
|
|
|
|
"No secondaries have been added."
|
|
|
|
assert @conn.read_pool != @conn.primary_pool,
|
|
|
|
"Read pool and primary pool are identical."
|
2011-08-24 22:34:00 +00:00
|
|
|
end
|
2012-01-25 23:45:31 +00:00
|
|
|
|
|
|
|
def test_automated_refresh_when_secondary_goes_down
|
2012-02-18 23:29:52 +00:00
|
|
|
@conn = ReplSetConnection.new(build_seeds(3),
|
|
|
|
:refresh_interval => 2, :refresh_mode => :sync)
|
2012-01-25 23:45:31 +00:00
|
|
|
|
|
|
|
num_secondaries = @conn.secondary_pools.length
|
|
|
|
old_refresh_version = @conn.refresh_version
|
|
|
|
|
2012-04-04 19:10:11 +00:00
|
|
|
@rs.kill_secondary
|
2012-01-25 23:45:31 +00:00
|
|
|
sleep(4)
|
|
|
|
@conn['foo']['bar'].find_one
|
|
|
|
|
|
|
|
assert @conn.refresh_version > old_refresh_version,
|
|
|
|
"Refresh version hasn't changed."
|
|
|
|
assert_equal num_secondaries - 1, @conn.secondaries.length
|
|
|
|
assert_equal num_secondaries - 1, @conn.secondary_pools.length
|
|
|
|
|
2012-01-30 00:05:17 +00:00
|
|
|
@rs.restart_killed_nodes
|
2012-01-25 23:45:31 +00:00
|
|
|
end
|
2011-08-24 22:34:00 +00:00
|
|
|
|
|
|
|
def test_automated_refresh_with_removed_node
|
2012-02-18 23:29:52 +00:00
|
|
|
@conn = ReplSetConnection.new(build_seeds(3),
|
|
|
|
:refresh_interval => 2, :refresh_mode => :sync)
|
2011-08-24 22:34:00 +00:00
|
|
|
|
2011-11-18 20:47:06 +00:00
|
|
|
num_secondaries = @conn.secondary_pools.length
|
|
|
|
old_refresh_version = @conn.refresh_version
|
2011-08-25 22:52:20 +00:00
|
|
|
|
2012-01-30 00:05:17 +00:00
|
|
|
n = @rs.remove_secondary_node
|
2011-08-31 15:46:33 +00:00
|
|
|
sleep(4)
|
2011-11-18 20:47:06 +00:00
|
|
|
@conn['foo']['bar'].find_one
|
2011-08-25 22:52:20 +00:00
|
|
|
|
2011-11-18 20:47:06 +00:00
|
|
|
assert @conn.refresh_version > old_refresh_version,
|
|
|
|
"Refresh version hasn't changed."
|
|
|
|
assert_equal num_secondaries - 1, @conn.secondaries.length
|
|
|
|
assert_equal num_secondaries - 1, @conn.secondary_pools.length
|
2011-08-31 20:05:21 +00:00
|
|
|
|
2012-01-30 00:05:17 +00:00
|
|
|
@rs.add_node(n)
|
2011-08-24 22:34:00 +00:00
|
|
|
end
|
2011-08-25 22:52:20 +00:00
|
|
|
|
2011-08-31 20:05:21 +00:00
|
|
|
def test_adding_and_removing_nodes
|
2012-02-18 23:29:52 +00:00
|
|
|
@conn = ReplSetConnection.new(build_seeds(3),
|
|
|
|
:refresh_interval => 2, :refresh_mode => :sync)
|
2011-08-31 20:05:21 +00:00
|
|
|
|
2012-01-30 00:05:17 +00:00
|
|
|
@rs.add_node
|
2011-10-14 13:52:11 +00:00
|
|
|
sleep(4)
|
2011-11-18 20:47:06 +00:00
|
|
|
@conn['foo']['bar'].find_one
|
2011-08-31 20:05:21 +00:00
|
|
|
|
2012-02-18 23:29:52 +00:00
|
|
|
@conn2 = ReplSetConnection.new(build_seeds(3),
|
|
|
|
:refresh_interval => 2, :refresh_mode => :sync)
|
2011-08-31 20:05:21 +00:00
|
|
|
|
2011-11-18 20:47:06 +00:00
|
|
|
assert @conn2.secondaries.sort == @conn.secondaries.sort,
|
|
|
|
"Second connection secondaries not equal to first."
|
2011-08-31 20:05:21 +00:00
|
|
|
assert_equal 3, @conn.secondary_pools.length
|
|
|
|
assert_equal 3, @conn.secondaries.length
|
|
|
|
|
2011-10-14 13:52:11 +00:00
|
|
|
config = @conn['admin'].command({:ismaster => 1})
|
|
|
|
|
2012-01-30 00:05:17 +00:00
|
|
|
@rs.remove_secondary_node
|
2011-08-31 20:05:21 +00:00
|
|
|
sleep(4)
|
2011-10-14 13:52:11 +00:00
|
|
|
config = @conn['admin'].command({:ismaster => 1})
|
|
|
|
|
2011-08-31 20:05:21 +00:00
|
|
|
assert_equal 2, @conn.secondary_pools.length
|
|
|
|
assert_equal 2, @conn.secondaries.length
|
|
|
|
end
|
2011-08-24 22:34:00 +00:00
|
|
|
end
|