mongo-ruby-driver/test/replica_sets/refresh_test.rb

130 lines
4.0 KiB
Ruby
Raw Normal View History

$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require './test/replica_sets/rs_test_helper'
require 'benchmark'
class ReplicaSetRefreshTest < Test::Unit::TestCase
2011-11-03 15:17:36 +00:00
include ReplicaSetTest
def setup
@conn = nil
end
def teardown
2011-11-03 15:17:36 +00:00
self.rs.restart_killed_nodes
@conn.close if @conn
end
def test_connect_speed
Benchmark.bm do |x|
x.report("Connect") do
10.times do
2011-11-03 15:17:36 +00:00
ReplSetConnection.new([self.rs.host, self.rs.ports[0]], [self.rs.host, self.rs.ports[1]],
[self.rs.host, self.rs.ports[2]], :refresh_mode => false)
end
end
2011-11-03 15:17:36 +00:00
@con = ReplSetConnection.new([self.rs.host, self.rs.ports[0]], [self.rs.host, self.rs.ports[1]],
[self.rs.host, self.rs.ports[2]], :refresh_mode => false)
x.report("manager") do
man = Mongo::PoolManager.new(@con, @con.seeds)
10.times do
man.connect
end
end
end
end
def test_connect_and_manual_refresh_with_secondaries_down
2011-11-03 15:17:36 +00:00
self.rs.kill_all_secondaries
rescue_connection_failure do
2011-11-03 15:17:36 +00:00
@conn = ReplSetConnection.new([self.rs.host, self.rs.ports[0]], [self.rs.host, self.rs.ports[1]],
[self.rs.host, self.rs.ports[2]], :refresh_mode => false)
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
2011-11-03 15:17:36 +00:00
self.rs.restart_killed_nodes
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
2011-11-03 15:17:36 +00:00
self.rs.kill_all_secondaries
rescue_connection_failure do
2011-11-03 15:17:36 +00:00
@conn = ReplSetConnection.new([self.rs.host, self.rs.ports[0]], [self.rs.host, self.rs.ports[1]],
[self.rs.host, self.rs.ports[2]], :refresh_interval => 2, :refresh_mode => :async)
end
assert_equal [], @conn.secondaries
assert @conn.connected?
assert_equal @conn.read_pool, @conn.primary_pool
2011-11-03 15:17:36 +00:00
self.rs.restart_killed_nodes
2011-10-14 13:52:11 +00:00
sleep(4)
assert @conn.read_pool != @conn.primary_pool, "Read pool and primary pool are identical."
assert @conn.secondaries.length > 0, "No secondaries have been added."
end
def test_automated_refresh_with_removed_node
2011-11-03 15:17:36 +00:00
@conn = ReplSetConnection.new([self.rs.host, self.rs.ports[0]], [self.rs.host, self.rs.ports[1]],
[self.rs.host, self.rs.ports[2]], :refresh_interval => 2, :refresh_mode => :async)
2011-08-26 14:59:49 +00:00
assert_equal 2, @conn.secondary_pools.length
assert_equal 2, @conn.secondaries.length
2011-11-03 15:17:36 +00:00
n = self.rs.remove_secondary_node
2011-08-31 15:46:33 +00:00
sleep(4)
2011-08-26 14:59:49 +00:00
assert_equal 1, @conn.secondaries.length
assert_equal 1, @conn.secondary_pools.length
2011-11-03 15:17:36 +00:00
self.rs.add_node(n)
end
def test_adding_and_removing_nodes
2011-11-04 20:53:28 +00:00
@conn = ReplSetConnection.new([self.rs.host, self.rs.ports[0]],
[self.rs.host, self.rs.ports[1]],
[self.rs.host, self.rs.ports[2]],
:refresh_interval => 2, :refresh_mode => :async)
2011-11-03 15:17:36 +00:00
self.rs.add_node
2011-10-14 13:52:11 +00:00
sleep(4)
2011-11-04 20:53:28 +00:00
@conn2 = ReplSetConnection.new([self.rs.host, self.rs.ports[0]],
[self.rs.host, self.rs.ports[1]],
[self.rs.host, self.rs.ports[2]],
:refresh_interval => 2, :refresh_mode => :async)
assert @conn2.secondaries == @conn.secondaries
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})
2011-11-03 15:17:36 +00:00
self.rs.remove_secondary_node
sleep(4)
2011-10-14 13:52:11 +00:00
config = @conn['admin'].command({:ismaster => 1})
assert_equal 2, @conn.secondary_pools.length
assert_equal 2, @conn.secondaries.length
end
end