2010-08-02 22:19:54 +00:00
|
|
|
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2010-12-14 22:38:52 +00:00
|
|
|
require './test/replica_sets/rs_test_helper'
|
2010-08-02 22:19:54 +00:00
|
|
|
|
|
|
|
class ReplicaSetAckTest < Test::Unit::TestCase
|
|
|
|
|
|
|
|
def setup
|
2012-01-30 00:05:17 +00:00
|
|
|
ensure_rs
|
2012-02-18 23:29:52 +00:00
|
|
|
@conn = ReplSetConnection.new(build_seeds(1))
|
2010-08-02 22:19:54 +00:00
|
|
|
|
2010-12-13 19:07:32 +00:00
|
|
|
@slave1 = Connection.new(@conn.secondary_pools[0].host,
|
|
|
|
@conn.secondary_pools[0].port, :slave_ok => true)
|
2010-08-02 22:19:54 +00:00
|
|
|
|
2010-12-29 18:01:05 +00:00
|
|
|
assert !@slave1.read_primary?
|
|
|
|
|
2010-08-02 22:19:54 +00:00
|
|
|
@db = @conn.db(MONGO_TEST_DB)
|
|
|
|
@db.drop_collection("test-sets")
|
|
|
|
@col = @db.collection("test-sets")
|
|
|
|
end
|
|
|
|
|
2011-08-25 15:27:58 +00:00
|
|
|
def teardown
|
2012-01-30 00:05:17 +00:00
|
|
|
@rs.restart_killed_nodes
|
2011-08-25 15:27:58 +00:00
|
|
|
@conn.close if @conn
|
|
|
|
end
|
|
|
|
|
2010-08-02 22:19:54 +00:00
|
|
|
def test_safe_mode_with_w_failure
|
2010-12-10 16:12:30 +00:00
|
|
|
assert_raise_error OperationFailure, "timeout" do
|
2010-08-02 22:19:54 +00:00
|
|
|
@col.insert({:foo => 1}, :safe => {:w => 4, :wtimeout => 1, :fsync => true})
|
|
|
|
end
|
2010-12-10 16:12:30 +00:00
|
|
|
assert_raise_error OperationFailure, "timeout" do
|
2010-08-02 22:19:54 +00:00
|
|
|
@col.update({:foo => 1}, {:foo => 2}, :safe => {:w => 4, :wtimeout => 1, :fsync => true})
|
|
|
|
end
|
2010-12-10 16:12:30 +00:00
|
|
|
assert_raise_error OperationFailure, "timeout" do
|
2010-08-02 22:19:54 +00:00
|
|
|
@col.remove({:foo => 2}, :safe => {:w => 4, :wtimeout => 1, :fsync => true})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_safe_mode_replication_ack
|
2011-08-16 20:47:07 +00:00
|
|
|
@col.insert({:baz => "bar"}, :safe => {:w => 3, :wtimeout => 5000})
|
2010-08-02 22:19:54 +00:00
|
|
|
|
2011-08-16 20:47:07 +00:00
|
|
|
assert @col.insert({:foo => "0" * 5000}, :safe => {:w => 3, :wtimeout => 5000})
|
2010-08-02 22:19:54 +00:00
|
|
|
assert_equal 2, @slave1[MONGO_TEST_DB]["test-sets"].count
|
|
|
|
|
2011-08-16 20:47:07 +00:00
|
|
|
assert @col.update({:baz => "bar"}, {:baz => "foo"}, :safe => {:w => 3, :wtimeout => 5000})
|
2010-08-02 22:19:54 +00:00
|
|
|
assert @slave1[MONGO_TEST_DB]["test-sets"].find_one({:baz => "foo"})
|
|
|
|
|
2011-08-16 20:47:07 +00:00
|
|
|
assert @col.remove({}, :safe => {:w => 3, :wtimeout => 5000})
|
2010-08-02 22:19:54 +00:00
|
|
|
assert_equal 0, @slave1[MONGO_TEST_DB]["test-sets"].count
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_last_error_responses
|
|
|
|
20.times { @col.insert({:baz => "bar"}) }
|
2010-12-14 22:38:52 +00:00
|
|
|
response = @db.get_last_error(:w => 2, :wtimeout => 5000)
|
2010-08-02 22:19:54 +00:00
|
|
|
assert response['ok'] == 1
|
|
|
|
assert response['lastOp']
|
|
|
|
|
|
|
|
@col.update({}, {:baz => "foo"}, :multi => true)
|
2010-12-14 22:38:52 +00:00
|
|
|
response = @db.get_last_error(:w => 2, :wtimeout => 5000)
|
2010-08-02 22:19:54 +00:00
|
|
|
assert response['ok'] == 1
|
|
|
|
assert response['lastOp']
|
|
|
|
|
|
|
|
@col.remove({})
|
2010-12-14 22:38:52 +00:00
|
|
|
response = @db.get_last_error(:w => 2, :wtimeout => 5000)
|
2010-08-02 22:19:54 +00:00
|
|
|
assert response['ok'] == 1
|
|
|
|
assert response['n'] == 20
|
|
|
|
assert response['lastOp']
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|