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

68 lines
2.3 KiB
Ruby
Raw Normal View History

$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'mongo'
require 'test/unit'
2010-09-09 19:58:51 +00:00
require './test/test_helper'
# NOTE: This test expects a replica set of three nodes to be running on local host.
class ReplicaSetAckTest < Test::Unit::TestCase
include Mongo
def setup
2010-12-13 19:07:32 +00:00
@conn = ReplSetConnection.multi([TEST_HOST, TEST_PORT], [TEST_HOST, TEST_PORT + 1],
[TEST_HOST, TEST_PORT + 2])
2010-12-10 16:12:30 +00:00
master = [@conn.primary_pool.host, @conn.primary_pool.port]
2010-12-13 19:07:32 +00:00
@slave1 = Connection.new(@conn.secondary_pools[0].host,
@conn.secondary_pools[0].port, :slave_ok => true)
@db = @conn.db(MONGO_TEST_DB)
@db.drop_collection("test-sets")
@col = @db.collection("test-sets")
end
def test_safe_mode_with_w_failure
2010-12-10 16:12:30 +00:00
assert_raise_error OperationFailure, "timeout" do
@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
@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
@col.remove({:foo => 2}, :safe => {:w => 4, :wtimeout => 1, :fsync => true})
end
end
def test_safe_mode_replication_ack
2010-12-10 16:12:30 +00:00
@col.insert({:baz => "bar"}, :safe => {:w => 2, :wtimeout => 1000})
2010-12-10 16:12:30 +00:00
assert @col.insert({:foo => "0" * 10000}, :safe => {:w => 2, :wtimeout => 1000})
assert_equal 2, @slave1[MONGO_TEST_DB]["test-sets"].count
2010-12-10 16:12:30 +00:00
assert @col.update({:baz => "bar"}, {:baz => "foo"}, :safe => {:w => 2, :wtimeout => 1000})
assert @slave1[MONGO_TEST_DB]["test-sets"].find_one({:baz => "foo"})
2010-12-10 16:12:30 +00:00
assert @col.remove({}, :safe => {:w => 2, :wtimeout => 1000})
assert_equal 0, @slave1[MONGO_TEST_DB]["test-sets"].count
end
def test_last_error_responses
20.times { @col.insert({:baz => "bar"}) }
2010-12-10 16:12:30 +00:00
response = @db.get_last_error(:w => 2, :wtimeout => 10000)
assert response['ok'] == 1
assert response['lastOp']
@col.update({}, {:baz => "foo"}, :multi => true)
2010-12-10 16:12:30 +00:00
response = @db.get_last_error(:w => 2, :wtimeout => 1000)
assert response['ok'] == 1
assert response['lastOp']
@col.remove({})
2010-12-10 16:12:30 +00:00
response = @db.get_last_error(:w => 2, :wtimeout => 1000)
assert response['ok'] == 1
assert response['n'] == 20
assert response['lastOp']
end
end