2012-01-20 15:56:39 +00:00
|
|
|
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
|
|
require './test/replica_sets/rs_test_helper'
|
|
|
|
|
|
|
|
class ComplexConnectTest < Test::Unit::TestCase
|
2012-01-30 00:05:17 +00:00
|
|
|
|
|
|
|
def setup
|
|
|
|
ensure_rs
|
|
|
|
end
|
2012-01-20 15:56:39 +00:00
|
|
|
|
|
|
|
def teardown
|
2012-01-30 00:05:17 +00:00
|
|
|
@rs.restart_killed_nodes
|
2012-01-20 15:56:39 +00:00
|
|
|
@conn.close if defined?(@conn) && @conn
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_complex_connect
|
2012-01-30 00:05:17 +00:00
|
|
|
primary = Connection.new(@rs.host, @rs.ports[0])
|
2012-01-20 15:56:39 +00:00
|
|
|
|
2012-04-04 20:44:01 +00:00
|
|
|
@conn = ReplSetConnection.new([
|
|
|
|
"#{@rs.host}:#{@rs.ports[2]}",
|
|
|
|
"#{@rs.host}:#{@rs.ports[1]}",
|
|
|
|
"#{@rs.host}:#{@rs.ports[0]}",
|
|
|
|
])
|
2012-01-20 15:56:39 +00:00
|
|
|
|
2012-01-20 16:00:38 +00:00
|
|
|
@conn['test']['foo'].insert({:a => 1})
|
2012-01-20 15:56:39 +00:00
|
|
|
assert @conn['test']['foo'].find_one
|
|
|
|
|
|
|
|
config = primary['local']['system.replset'].find_one
|
|
|
|
config['version'] += 1
|
|
|
|
config['members'].delete_if do |member|
|
2012-01-30 00:05:17 +00:00
|
|
|
member['host'].include?(@rs.ports[2].to_s)
|
2012-01-20 15:56:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
assert_raise ConnectionFailure do
|
|
|
|
primary['admin'].command({:replSetReconfig => config})
|
|
|
|
end
|
2012-01-30 00:05:17 +00:00
|
|
|
@rs.ensure_up
|
2012-01-20 15:56:39 +00:00
|
|
|
assert_raise ConnectionFailure do
|
|
|
|
primary['admin'].command({:replSetStepDown => 1})
|
|
|
|
end
|
|
|
|
|
|
|
|
rescue_connection_failure do
|
|
|
|
assert @conn['test']['foo'].find_one
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|