mongo 1.3.0 → 1.12.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data/{LICENSE.txt → LICENSE} +1 -1
- data/README.md +122 -271
- data/Rakefile +25 -209
- data/VERSION +1 -0
- data/bin/mongo_console +31 -9
- data/lib/mongo/bulk_write_collection_view.rb +387 -0
- data/lib/mongo/collection.rb +576 -269
- data/lib/mongo/collection_writer.rb +364 -0
- data/lib/mongo/connection/node.rb +249 -0
- data/lib/mongo/connection/pool.rb +340 -0
- data/lib/mongo/connection/pool_manager.rb +320 -0
- data/lib/mongo/connection/sharding_pool_manager.rb +67 -0
- data/lib/mongo/connection/socket/socket_util.rb +37 -0
- data/lib/mongo/connection/socket/ssl_socket.rb +95 -0
- data/lib/mongo/connection/socket/tcp_socket.rb +87 -0
- data/lib/mongo/connection/socket/unix_socket.rb +39 -0
- data/lib/mongo/connection/socket.rb +18 -0
- data/lib/mongo/connection.rb +7 -875
- data/lib/mongo/cursor.rb +403 -117
- data/lib/mongo/db.rb +444 -243
- data/lib/mongo/exception.rb +145 -0
- data/lib/mongo/functional/authentication.rb +455 -0
- data/lib/mongo/functional/logging.rb +85 -0
- data/lib/mongo/functional/read_preference.rb +183 -0
- data/lib/mongo/functional/scram.rb +556 -0
- data/lib/mongo/functional/uri_parser.rb +409 -0
- data/lib/mongo/functional/write_concern.rb +66 -0
- data/lib/mongo/functional.rb +20 -0
- data/lib/mongo/gridfs/grid.rb +30 -24
- data/lib/mongo/gridfs/grid_ext.rb +6 -10
- data/lib/mongo/gridfs/grid_file_system.rb +38 -20
- data/lib/mongo/gridfs/grid_io.rb +84 -75
- data/lib/mongo/gridfs.rb +18 -0
- data/lib/mongo/legacy.rb +140 -0
- data/lib/mongo/mongo_client.rb +697 -0
- data/lib/mongo/mongo_replica_set_client.rb +535 -0
- data/lib/mongo/mongo_sharded_client.rb +159 -0
- data/lib/mongo/networking.rb +372 -0
- data/lib/mongo/{util → utils}/conversions.rb +29 -8
- data/lib/mongo/{util → utils}/core_ext.rb +28 -18
- data/lib/mongo/{util → utils}/server_version.rb +4 -6
- data/lib/mongo/{util → utils}/support.rb +29 -31
- data/lib/mongo/utils/thread_local_variable_manager.rb +25 -0
- data/lib/mongo/utils.rb +19 -0
- data/lib/mongo.rb +51 -50
- data/mongo.gemspec +29 -32
- data/test/functional/authentication_test.rb +39 -0
- data/test/functional/bulk_api_stress_test.rb +133 -0
- data/test/functional/bulk_write_collection_view_test.rb +1198 -0
- data/test/functional/client_test.rb +627 -0
- data/test/functional/collection_test.rb +2175 -0
- data/test/functional/collection_writer_test.rb +83 -0
- data/test/{conversions_test.rb → functional/conversions_test.rb} +47 -3
- data/test/functional/cursor_fail_test.rb +57 -0
- data/test/functional/cursor_message_test.rb +56 -0
- data/test/functional/cursor_test.rb +683 -0
- data/test/functional/db_api_test.rb +835 -0
- data/test/functional/db_connection_test.rb +25 -0
- data/test/functional/db_test.rb +348 -0
- data/test/functional/grid_file_system_test.rb +285 -0
- data/test/{grid_io_test.rb → functional/grid_io_test.rb} +72 -11
- data/test/{grid_test.rb → functional/grid_test.rb} +88 -15
- data/test/functional/pool_test.rb +136 -0
- data/test/functional/safe_test.rb +98 -0
- data/test/functional/ssl_test.rb +29 -0
- data/test/functional/support_test.rb +62 -0
- data/test/functional/timeout_test.rb +60 -0
- data/test/functional/uri_test.rb +446 -0
- data/test/functional/write_concern_test.rb +118 -0
- data/test/helpers/general.rb +50 -0
- data/test/helpers/test_unit.rb +476 -0
- data/test/replica_set/authentication_test.rb +37 -0
- data/test/replica_set/basic_test.rb +189 -0
- data/test/replica_set/client_test.rb +393 -0
- data/test/replica_set/connection_test.rb +138 -0
- data/test/replica_set/count_test.rb +66 -0
- data/test/replica_set/cursor_test.rb +220 -0
- data/test/replica_set/insert_test.rb +157 -0
- data/test/replica_set/max_values_test.rb +151 -0
- data/test/replica_set/pinning_test.rb +105 -0
- data/test/replica_set/query_test.rb +73 -0
- data/test/replica_set/read_preference_test.rb +219 -0
- data/test/replica_set/refresh_test.rb +211 -0
- data/test/replica_set/replication_ack_test.rb +95 -0
- data/test/replica_set/ssl_test.rb +32 -0
- data/test/sharded_cluster/basic_test.rb +203 -0
- data/test/shared/authentication/basic_auth_shared.rb +260 -0
- data/test/shared/authentication/bulk_api_auth_shared.rb +249 -0
- data/test/shared/authentication/gssapi_shared.rb +176 -0
- data/test/shared/authentication/sasl_plain_shared.rb +96 -0
- data/test/shared/authentication/scram_shared.rb +92 -0
- data/test/shared/ssl_shared.rb +235 -0
- data/test/test_helper.rb +53 -94
- data/test/threading/basic_test.rb +120 -0
- data/test/tools/mongo_config.rb +708 -0
- data/test/tools/mongo_config_test.rb +160 -0
- data/test/unit/client_test.rb +381 -0
- data/test/unit/collection_test.rb +89 -53
- data/test/unit/connection_test.rb +282 -32
- data/test/unit/cursor_test.rb +206 -8
- data/test/unit/db_test.rb +55 -13
- data/test/unit/grid_test.rb +43 -16
- data/test/unit/mongo_sharded_client_test.rb +48 -0
- data/test/unit/node_test.rb +93 -0
- data/test/unit/pool_manager_test.rb +111 -0
- data/test/unit/read_pref_test.rb +406 -0
- data/test/unit/read_test.rb +159 -0
- data/test/unit/safe_test.rb +69 -36
- data/test/unit/sharding_pool_manager_test.rb +84 -0
- data/test/unit/write_concern_test.rb +175 -0
- data.tar.gz.sig +3 -0
- metadata +227 -216
- metadata.gz.sig +0 -0
- data/docs/CREDITS.md +0 -123
- data/docs/FAQ.md +0 -116
- data/docs/GridFS.md +0 -158
- data/docs/HISTORY.md +0 -244
- data/docs/RELEASES.md +0 -33
- data/docs/REPLICA_SETS.md +0 -72
- data/docs/TUTORIAL.md +0 -247
- data/docs/WRITE_CONCERN.md +0 -28
- data/lib/mongo/exceptions.rb +0 -71
- data/lib/mongo/gridfs/grid_io_fix.rb +0 -38
- data/lib/mongo/repl_set_connection.rb +0 -342
- data/lib/mongo/test.rb +0 -20
- data/lib/mongo/util/pool.rb +0 -177
- data/lib/mongo/util/uri_parser.rb +0 -185
- data/test/async/collection_test.rb +0 -224
- data/test/async/connection_test.rb +0 -24
- data/test/async/cursor_test.rb +0 -162
- data/test/async/worker_pool_test.rb +0 -99
- data/test/auxillary/1.4_features.rb +0 -166
- data/test/auxillary/authentication_test.rb +0 -68
- data/test/auxillary/autoreconnect_test.rb +0 -41
- data/test/auxillary/fork_test.rb +0 -30
- data/test/auxillary/repl_set_auth_test.rb +0 -58
- data/test/auxillary/slave_connection_test.rb +0 -36
- data/test/auxillary/threaded_authentication_test.rb +0 -101
- data/test/bson/binary_test.rb +0 -15
- data/test/bson/bson_test.rb +0 -649
- data/test/bson/byte_buffer_test.rb +0 -208
- data/test/bson/hash_with_indifferent_access_test.rb +0 -38
- data/test/bson/json_test.rb +0 -17
- data/test/bson/object_id_test.rb +0 -154
- data/test/bson/ordered_hash_test.rb +0 -204
- data/test/bson/timestamp_test.rb +0 -24
- data/test/collection_test.rb +0 -910
- data/test/connection_test.rb +0 -309
- data/test/cursor_fail_test.rb +0 -75
- data/test/cursor_message_test.rb +0 -43
- data/test/cursor_test.rb +0 -483
- data/test/db_api_test.rb +0 -726
- data/test/db_connection_test.rb +0 -15
- data/test/db_test.rb +0 -287
- data/test/grid_file_system_test.rb +0 -243
- data/test/load/resque/load.rb +0 -21
- data/test/load/resque/processor.rb +0 -26
- data/test/load/thin/load.rb +0 -24
- data/test/load/unicorn/load.rb +0 -23
- data/test/load/unicorn/unicorn.rb +0 -29
- data/test/replica_sets/connect_test.rb +0 -94
- data/test/replica_sets/connection_string_test.rb +0 -32
- data/test/replica_sets/count_test.rb +0 -35
- data/test/replica_sets/insert_test.rb +0 -53
- data/test/replica_sets/pooled_insert_test.rb +0 -55
- data/test/replica_sets/query_secondaries.rb +0 -96
- data/test/replica_sets/query_test.rb +0 -51
- data/test/replica_sets/replication_ack_test.rb +0 -66
- data/test/replica_sets/rs_test_helper.rb +0 -27
- data/test/safe_test.rb +0 -68
- data/test/support/hash_with_indifferent_access.rb +0 -186
- data/test/support/keys.rb +0 -45
- data/test/support_test.rb +0 -18
- data/test/threading/threading_with_large_pool_test.rb +0 -90
- data/test/threading_test.rb +0 -87
- data/test/tools/auth_repl_set_manager.rb +0 -14
- data/test/tools/load.rb +0 -58
- data/test/tools/repl_set_manager.rb +0 -266
- data/test/tools/sharding_manager.rb +0 -202
- data/test/tools/test.rb +0 -4
- data/test/unit/pool_test.rb +0 -9
- data/test/unit/repl_set_connection_test.rb +0 -59
- data/test/uri_test.rb +0 -91
@@ -1,94 +0,0 @@
|
|
1
|
-
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
-
require './test/replica_sets/rs_test_helper'
|
3
|
-
|
4
|
-
# NOTE: This test expects a replica set of three nodes to be running on RS.host,
|
5
|
-
# on ports TEST_PORT, RS.ports[1], and TEST + 2.
|
6
|
-
class ConnectTest < Test::Unit::TestCase
|
7
|
-
include Mongo
|
8
|
-
|
9
|
-
def setup
|
10
|
-
RS.restart_killed_nodes
|
11
|
-
end
|
12
|
-
|
13
|
-
def teardown
|
14
|
-
RS.restart_killed_nodes
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_connect_with_deprecated_multi
|
18
|
-
@conn = Connection.multi([[RS.host, RS.ports[0]], [RS.host, RS.ports[1]]], :name => RS.name)
|
19
|
-
assert @conn.is_a?(ReplSetConnection)
|
20
|
-
assert @conn.connected?
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_connect_bad_name
|
24
|
-
assert_raise_error(ReplicaSetConnectionError, "-wrong") do
|
25
|
-
ReplSetConnection.new([RS.host, RS.ports[0]], [RS.host, RS.ports[1]],
|
26
|
-
[RS.host, RS.ports[2]], :rs_name => RS.name + "-wrong")
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_connect
|
31
|
-
@conn = ReplSetConnection.new([RS.host, RS.ports[0]], [RS.host, RS.ports[1]],
|
32
|
-
[RS.host, RS.ports[2]], :name => RS.name)
|
33
|
-
assert @conn.connected?
|
34
|
-
assert @conn.read_primary?
|
35
|
-
assert @conn.primary?
|
36
|
-
|
37
|
-
assert_equal RS.primary, @conn.primary
|
38
|
-
assert_equal RS.secondaries.sort, @conn.secondaries.sort
|
39
|
-
assert_equal RS.arbiters.sort, @conn.arbiters.sort
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_host_port_accessors
|
43
|
-
@conn = ReplSetConnection.new([RS.host, RS.ports[0]], [RS.host, RS.ports[1]],
|
44
|
-
[RS.host, RS.ports[2]], :name => RS.name)
|
45
|
-
|
46
|
-
assert_equal @conn.host, RS.primary[0]
|
47
|
-
assert_equal @conn.port, RS.primary[1]
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_connect_with_primary_node_killed
|
51
|
-
node = RS.kill_primary
|
52
|
-
|
53
|
-
# Becuase we're killing the primary and trying to connect right away,
|
54
|
-
# this is going to fail right away.
|
55
|
-
assert_raise_error(ConnectionFailure, "Failed to connect to primary node") do
|
56
|
-
@conn = ReplSetConnection.new([RS.host, RS.ports[0]], [RS.host, RS.ports[1]],
|
57
|
-
[RS.host, RS.ports[2]])
|
58
|
-
end
|
59
|
-
|
60
|
-
# This allows the secondary to come up as a primary
|
61
|
-
rescue_connection_failure do
|
62
|
-
@conn = ReplSetConnection.new([RS.host, RS.ports[0]], [RS.host, RS.ports[1]],
|
63
|
-
[RS.host, RS.ports[2]])
|
64
|
-
end
|
65
|
-
assert @conn.connected?
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_connect_with_secondary_node_killed
|
69
|
-
node = RS.kill_secondary
|
70
|
-
|
71
|
-
@conn = ReplSetConnection.new([RS.host, RS.ports[0]], [RS.host, RS.ports[1]],
|
72
|
-
[RS.host, RS.ports[2]])
|
73
|
-
assert @conn.connected?
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_connect_with_third_node_killed
|
77
|
-
RS.kill(RS.get_node_from_port(RS.ports[2]))
|
78
|
-
|
79
|
-
@conn = ReplSetConnection.new([RS.host, RS.ports[0]], [RS.host, RS.ports[1]],
|
80
|
-
[RS.host, RS.ports[2]])
|
81
|
-
assert @conn.connected?
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_connect_with_primary_stepped_down
|
85
|
-
RS.step_down_primary
|
86
|
-
|
87
|
-
rescue_connection_failure do
|
88
|
-
@conn = ReplSetConnection.new([RS.host, RS.ports[0]], [RS.host, RS.ports[1]],
|
89
|
-
[RS.host, RS.ports[2]])
|
90
|
-
end
|
91
|
-
assert @conn.connected?
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
-
require './test/replica_sets/rs_test_helper'
|
3
|
-
|
4
|
-
# NOTE: This test expects a replica set of three nodes to be running on RS.host,
|
5
|
-
# on ports TEST_PORT, RS.ports[1], and TEST + 2.
|
6
|
-
class ConnectionStringTest < Test::Unit::TestCase
|
7
|
-
include Mongo
|
8
|
-
|
9
|
-
def setup
|
10
|
-
RS.restart_killed_nodes
|
11
|
-
end
|
12
|
-
|
13
|
-
def teardown
|
14
|
-
RS.restart_killed_nodes
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_connect_with_connection_string
|
18
|
-
@conn = Connection.from_uri("mongodb://#{RS.host}:#{RS.ports[0]},#{RS.host}:#{RS.ports[1]}?replicaset=#{RS.name}")
|
19
|
-
assert @conn.is_a?(ReplSetConnection)
|
20
|
-
assert @conn.connected?
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_connect_with_full_connection_string
|
24
|
-
@conn = Connection.from_uri("mongodb://#{RS.host}:#{RS.ports[0]},#{RS.host}:#{RS.ports[1]}?replicaset=#{RS.name};safe=true;w=2;fsync=true;slaveok=true")
|
25
|
-
assert @conn.is_a?(ReplSetConnection)
|
26
|
-
assert @conn.connected?
|
27
|
-
assert_equal 2, @conn.safe[:w]
|
28
|
-
assert @conn.safe[:fsync]
|
29
|
-
assert @conn.read_pool
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
-
require './test/replica_sets/rs_test_helper'
|
3
|
-
|
4
|
-
# NOTE: This test expects a replica set of three nodes to be running
|
5
|
-
# on the local host.
|
6
|
-
class ReplicaSetCountTest < Test::Unit::TestCase
|
7
|
-
include Mongo
|
8
|
-
|
9
|
-
def setup
|
10
|
-
@conn = ReplSetConnection.new([RS.host, RS.ports[0]], [RS.host, RS.ports[1]], [RS.host, RS.ports[2]])
|
11
|
-
@db = @conn.db(MONGO_TEST_DB)
|
12
|
-
@db.drop_collection("test-sets")
|
13
|
-
@coll = @db.collection("test-sets")
|
14
|
-
end
|
15
|
-
|
16
|
-
def teardown
|
17
|
-
RS.restart_killed_nodes
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_correct_count_after_insertion_reconnect
|
21
|
-
@coll.insert({:a => 20}, :safe => {:w => 2, :wtimeout => 10000})
|
22
|
-
assert_equal 1, @coll.count
|
23
|
-
|
24
|
-
# Kill the current master node
|
25
|
-
@node = RS.kill_primary
|
26
|
-
|
27
|
-
rescue_connection_failure do
|
28
|
-
@coll.insert({:a => 30}, :safe => true)
|
29
|
-
end
|
30
|
-
|
31
|
-
@coll.insert({:a => 40}, :safe => true)
|
32
|
-
assert_equal 3, @coll.count, "Second count failed"
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
-
require './test/replica_sets/rs_test_helper'
|
3
|
-
|
4
|
-
# NOTE: This test expects a replica set of three nodes to be running
|
5
|
-
# on the local host.
|
6
|
-
class ReplicaSetInsertTest < Test::Unit::TestCase
|
7
|
-
include Mongo
|
8
|
-
|
9
|
-
def setup
|
10
|
-
@conn = ReplSetConnection.new([TEST_HOST, RS.ports[0]], [TEST_HOST, RS.ports[1]], [TEST_HOST, RS.ports[2]])
|
11
|
-
@db = @conn.db(MONGO_TEST_DB)
|
12
|
-
@db.drop_collection("test-sets")
|
13
|
-
@coll = @db.collection("test-sets")
|
14
|
-
end
|
15
|
-
|
16
|
-
def teardown
|
17
|
-
RS.restart_killed_nodes
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_insert
|
21
|
-
@coll.save({:a => 20}, :safe => true)
|
22
|
-
|
23
|
-
RS.kill_primary
|
24
|
-
|
25
|
-
rescue_connection_failure do
|
26
|
-
@coll.save({:a => 30}, :safe => true)
|
27
|
-
end
|
28
|
-
|
29
|
-
@coll.save({:a => 40}, :safe => true)
|
30
|
-
@coll.save({:a => 50}, :safe => true)
|
31
|
-
@coll.save({:a => 60}, :safe => true)
|
32
|
-
@coll.save({:a => 70}, :safe => true)
|
33
|
-
|
34
|
-
# Restart the old master and wait for sync
|
35
|
-
RS.restart_killed_nodes
|
36
|
-
sleep(1)
|
37
|
-
results = []
|
38
|
-
|
39
|
-
rescue_connection_failure do
|
40
|
-
@coll.find.each {|r| results << r}
|
41
|
-
[20, 30, 40, 50, 60, 70].each do |a|
|
42
|
-
assert results.any? {|r| r['a'] == a}, "Could not find record for a => #{a}"
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
@coll.save({:a => 80}, :safe => true)
|
47
|
-
@coll.find.each {|r| results << r}
|
48
|
-
[20, 30, 40, 50, 60, 70, 80].each do |a|
|
49
|
-
assert results.any? {|r| r['a'] == a}, "Could not find record for a => #{a} on second find"
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
-
require './test/replica_sets/rs_test_helper'
|
3
|
-
|
4
|
-
# NOTE: This test expects a replica set of three nodes to be running
|
5
|
-
# on the local host.
|
6
|
-
class ReplicaSetPooledInsertTest < Test::Unit::TestCase
|
7
|
-
include Mongo
|
8
|
-
|
9
|
-
def setup
|
10
|
-
@conn = ReplSetConnection.new([RS.host, RS.ports[0]], [RS.host, RS.ports[1]],
|
11
|
-
[RS.host, RS.ports[2]], :pool_size => 10, :timeout => 5)
|
12
|
-
@db = @conn.db(MONGO_TEST_DB)
|
13
|
-
@db.drop_collection("test-sets")
|
14
|
-
@coll = @db.collection("test-sets")
|
15
|
-
end
|
16
|
-
|
17
|
-
def teardown
|
18
|
-
RS.restart_killed_nodes
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_insert
|
22
|
-
expected_results = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
23
|
-
@coll.save({:a => -1}, :safe => true)
|
24
|
-
|
25
|
-
RS.kill_primary
|
26
|
-
|
27
|
-
threads = []
|
28
|
-
10.times do |i|
|
29
|
-
threads[i] = Thread.new do
|
30
|
-
rescue_connection_failure do
|
31
|
-
@coll.save({:a => i}, :safe => true)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
# Restart the old master and wait for sync
|
37
|
-
RS.restart_killed_nodes
|
38
|
-
sleep(1)
|
39
|
-
results = []
|
40
|
-
|
41
|
-
rescue_connection_failure do
|
42
|
-
@coll.find.each {|r| results << r}
|
43
|
-
expected_results.each do |a|
|
44
|
-
assert results.any? {|r| r['a'] == a}, "Could not find record for a => #{a}"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
@coll.save({:a => 10}, :safe => true)
|
49
|
-
@coll.find.each {|r| results << r}
|
50
|
-
(expected_results + [10]).each do |a|
|
51
|
-
assert results.any? {|r| r['a'] == a}, "Could not find record for a => #{a} on second find"
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
@@ -1,96 +0,0 @@
|
|
1
|
-
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
-
require './test/replica_sets/rs_test_helper'
|
3
|
-
|
4
|
-
# NOTE: This test expects a replica set of three nodes to be running
|
5
|
-
# on the local host.
|
6
|
-
class ReplicaSetQuerySecondariesTest < Test::Unit::TestCase
|
7
|
-
include Mongo
|
8
|
-
|
9
|
-
def setup
|
10
|
-
@conn = ReplSetConnection.new([RS.host, RS.ports[0]], :read_secondary => true)
|
11
|
-
@db = @conn.db(MONGO_TEST_DB)
|
12
|
-
@db.drop_collection("test-sets")
|
13
|
-
end
|
14
|
-
|
15
|
-
def teardown
|
16
|
-
RS.restart_killed_nodes
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_read_primary
|
20
|
-
rescue_connection_failure do
|
21
|
-
assert !@conn.read_primary?
|
22
|
-
assert !@conn.primary?
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_con
|
27
|
-
assert @conn.primary_pool, "No primary pool!"
|
28
|
-
assert @conn.read_pool, "No read pool!"
|
29
|
-
assert @conn.primary_pool.port != @conn.read_pool.port,
|
30
|
-
"Primary port and read port at the same!"
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_query_secondaries
|
34
|
-
@coll = @db.collection("test-sets", :safe => {:w => 3, :wtimeout => 10000})
|
35
|
-
@coll.save({:a => 20})
|
36
|
-
@coll.save({:a => 30})
|
37
|
-
@coll.save({:a => 40})
|
38
|
-
results = []
|
39
|
-
@coll.find.each {|r| results << r["a"]}
|
40
|
-
assert results.include?(20)
|
41
|
-
assert results.include?(30)
|
42
|
-
assert results.include?(40)
|
43
|
-
|
44
|
-
RS.kill_primary
|
45
|
-
|
46
|
-
results = []
|
47
|
-
rescue_connection_failure do
|
48
|
-
@coll.find.each {|r| results << r}
|
49
|
-
[20, 30, 40].each do |a|
|
50
|
-
assert results.any? {|r| r['a'] == a}, "Could not find record for a => #{a}"
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_kill_primary
|
56
|
-
@coll = @db.collection("test-sets", :safe => {:w => 3, :wtimeout => 10000})
|
57
|
-
@coll.save({:a => 20})
|
58
|
-
@coll.save({:a => 30})
|
59
|
-
assert_equal 2, @coll.find.to_a.length
|
60
|
-
|
61
|
-
# Should still be able to read immediately after killing master node
|
62
|
-
RS.kill_primary
|
63
|
-
assert_equal 2, @coll.find.to_a.length
|
64
|
-
rescue_connection_failure do
|
65
|
-
@coll.save({:a => 50}, :safe => {:w => 2, :wtimeout => 10000})
|
66
|
-
end
|
67
|
-
RS.restart_killed_nodes
|
68
|
-
@coll.save({:a => 50}, :safe => {:w => 2, :wtimeout => 10000})
|
69
|
-
assert_equal 4, @coll.find.to_a.length
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_kill_secondary
|
73
|
-
@coll = @db.collection("test-sets", {:safe => {:w => 3, :wtimeout => 10000}})
|
74
|
-
@coll.save({:a => 20})
|
75
|
-
@coll.save({:a => 30})
|
76
|
-
assert_equal 2, @coll.find.to_a.length
|
77
|
-
|
78
|
-
read_node = RS.get_node_from_port(@conn.read_pool.port)
|
79
|
-
RS.kill(read_node)
|
80
|
-
|
81
|
-
# Should fail immediately on next read
|
82
|
-
old_read_pool_port = @conn.read_pool.port
|
83
|
-
assert_raise ConnectionFailure do
|
84
|
-
@coll.find.to_a.length
|
85
|
-
end
|
86
|
-
|
87
|
-
# Should eventually reconnect and be able to read
|
88
|
-
rescue_connection_failure do
|
89
|
-
length = @coll.find.to_a.length
|
90
|
-
assert_equal 2, length
|
91
|
-
end
|
92
|
-
new_read_pool_port = @conn.read_pool.port
|
93
|
-
assert old_read_pool != new_read_pool
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
-
require './test/replica_sets/rs_test_helper'
|
3
|
-
|
4
|
-
# NOTE: This test expects a replica set of three nodes to be running
|
5
|
-
# on the local host.
|
6
|
-
class ReplicaSetQueryTest < Test::Unit::TestCase
|
7
|
-
include Mongo
|
8
|
-
|
9
|
-
def setup
|
10
|
-
@conn = ReplSetConnection.new([RS.host, RS.ports[0]])
|
11
|
-
@db = @conn.db(MONGO_TEST_DB)
|
12
|
-
@db.drop_collection("test-sets")
|
13
|
-
@coll = @db.collection("test-sets")
|
14
|
-
end
|
15
|
-
|
16
|
-
def teardown
|
17
|
-
RS.restart_killed_nodes
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_query
|
21
|
-
@coll.save({:a => 20}, :safe => {:w => 3})
|
22
|
-
@coll.save({:a => 30}, :safe => {:w => 3})
|
23
|
-
@coll.save({:a => 40}, :safe => {:w => 3})
|
24
|
-
results = []
|
25
|
-
@coll.find.each {|r| results << r}
|
26
|
-
[20, 30, 40].each do |a|
|
27
|
-
assert results.any? {|r| r['a'] == a}, "Could not find record for a => #{a}"
|
28
|
-
end
|
29
|
-
|
30
|
-
puts "Benchmark before failover: #{benchmark_queries}"
|
31
|
-
|
32
|
-
RS.kill_primary
|
33
|
-
|
34
|
-
results = []
|
35
|
-
rescue_connection_failure do
|
36
|
-
@coll.find.each {|r| results << r}
|
37
|
-
[20, 30, 40].each do |a|
|
38
|
-
assert results.any? {|r| r['a'] == a}, "Could not find record for a => #{a}"
|
39
|
-
end
|
40
|
-
|
41
|
-
puts "Benchmark after failover: #{benchmark_queries}"
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def benchmark_queries
|
46
|
-
t1 = Time.now
|
47
|
-
10000.times { @coll.find_one }
|
48
|
-
Time.now - t1
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
-
require './test/replica_sets/rs_test_helper'
|
3
|
-
|
4
|
-
# NOTE: This test expects a replica set of three nodes to be running on local host.
|
5
|
-
class ReplicaSetAckTest < Test::Unit::TestCase
|
6
|
-
include Mongo
|
7
|
-
|
8
|
-
def setup
|
9
|
-
RS.ensure_up
|
10
|
-
|
11
|
-
@conn = ReplSetConnection.new([RS.host, RS.ports[0]])
|
12
|
-
|
13
|
-
@slave1 = Connection.new(@conn.secondary_pools[0].host,
|
14
|
-
@conn.secondary_pools[0].port, :slave_ok => true)
|
15
|
-
|
16
|
-
assert !@slave1.read_primary?
|
17
|
-
|
18
|
-
@db = @conn.db(MONGO_TEST_DB)
|
19
|
-
@db.drop_collection("test-sets")
|
20
|
-
@col = @db.collection("test-sets")
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_safe_mode_with_w_failure
|
24
|
-
assert_raise_error OperationFailure, "timeout" do
|
25
|
-
@col.insert({:foo => 1}, :safe => {:w => 4, :wtimeout => 1, :fsync => true})
|
26
|
-
end
|
27
|
-
assert_raise_error OperationFailure, "timeout" do
|
28
|
-
@col.update({:foo => 1}, {:foo => 2}, :safe => {:w => 4, :wtimeout => 1, :fsync => true})
|
29
|
-
end
|
30
|
-
assert_raise_error OperationFailure, "timeout" do
|
31
|
-
@col.remove({:foo => 2}, :safe => {:w => 4, :wtimeout => 1, :fsync => true})
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_safe_mode_replication_ack
|
36
|
-
@col.insert({:baz => "bar"}, :safe => {:w => 2, :wtimeout => 5000})
|
37
|
-
|
38
|
-
assert @col.insert({:foo => "0" * 5000}, :safe => {:w => 2, :wtimeout => 5000})
|
39
|
-
assert_equal 2, @slave1[MONGO_TEST_DB]["test-sets"].count
|
40
|
-
|
41
|
-
assert @col.update({:baz => "bar"}, {:baz => "foo"}, :safe => {:w => 2, :wtimeout => 5000})
|
42
|
-
assert @slave1[MONGO_TEST_DB]["test-sets"].find_one({:baz => "foo"})
|
43
|
-
|
44
|
-
assert @col.remove({}, :safe => {:w => 2, :wtimeout => 5000})
|
45
|
-
assert_equal 0, @slave1[MONGO_TEST_DB]["test-sets"].count
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_last_error_responses
|
49
|
-
20.times { @col.insert({:baz => "bar"}) }
|
50
|
-
response = @db.get_last_error(:w => 2, :wtimeout => 5000)
|
51
|
-
assert response['ok'] == 1
|
52
|
-
assert response['lastOp']
|
53
|
-
|
54
|
-
@col.update({}, {:baz => "foo"}, :multi => true)
|
55
|
-
response = @db.get_last_error(:w => 2, :wtimeout => 5000)
|
56
|
-
assert response['ok'] == 1
|
57
|
-
assert response['lastOp']
|
58
|
-
|
59
|
-
@col.remove({})
|
60
|
-
response = @db.get_last_error(:w => 2, :wtimeout => 5000)
|
61
|
-
assert response['ok'] == 1
|
62
|
-
assert response['n'] == 20
|
63
|
-
assert response['lastOp']
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
-
require './test/test_helper'
|
3
|
-
require './test/tools/repl_set_manager'
|
4
|
-
|
5
|
-
unless defined? RS
|
6
|
-
RS = ReplSetManager.new
|
7
|
-
RS.start_set
|
8
|
-
end
|
9
|
-
|
10
|
-
class Test::Unit::TestCase
|
11
|
-
|
12
|
-
# Generic code for rescuing connection failures and retrying operations.
|
13
|
-
# This could be combined with some timeout functionality.
|
14
|
-
def rescue_connection_failure(max_retries=60)
|
15
|
-
retries = 0
|
16
|
-
begin
|
17
|
-
yield
|
18
|
-
rescue Mongo::ConnectionFailure => ex
|
19
|
-
puts "Rescue attempt #{retries}: from #{ex}"
|
20
|
-
retries += 1
|
21
|
-
raise ex if retries > max_retries
|
22
|
-
sleep(1)
|
23
|
-
retry
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
data/test/safe_test.rb
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
require './test/test_helper'
|
2
|
-
include Mongo
|
3
|
-
|
4
|
-
class SafeTest < Test::Unit::TestCase
|
5
|
-
context "Safe mode propogation: " do
|
6
|
-
setup do
|
7
|
-
@con = standard_connection(:safe => {:w => 1})
|
8
|
-
@db = @con[MONGO_TEST_DB]
|
9
|
-
@col = @db['test-safe']
|
10
|
-
@col.create_index([[:a, 1]], :unique => true)
|
11
|
-
@col.remove
|
12
|
-
end
|
13
|
-
|
14
|
-
should "propogate safe option on insert" do
|
15
|
-
@col.insert({:a => 1})
|
16
|
-
|
17
|
-
assert_raise_error(OperationFailure, "duplicate key") do
|
18
|
-
@col.insert({:a => 1})
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
should "allow safe override on insert" do
|
23
|
-
@col.insert({:a => 1})
|
24
|
-
@col.insert({:a => 1}, :safe => false)
|
25
|
-
end
|
26
|
-
|
27
|
-
should "propogate safe option on update" do
|
28
|
-
@col.insert({:a => 1})
|
29
|
-
@col.insert({:a => 2})
|
30
|
-
|
31
|
-
assert_raise_error(OperationFailure, "duplicate key") do
|
32
|
-
@col.update({:a => 2}, {:a => 1})
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
should "allow safe override on update" do
|
37
|
-
@col.insert({:a => 1})
|
38
|
-
@col.insert({:a => 2})
|
39
|
-
@col.update({:a => 2}, {:a => 1}, :safe => false)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
context "Safe error objects" do
|
44
|
-
setup do
|
45
|
-
@con = standard_connection
|
46
|
-
@db = @con[MONGO_TEST_DB]
|
47
|
-
@col = @db['test']
|
48
|
-
@col.remove
|
49
|
-
@col.insert({:a => 1})
|
50
|
-
@col.insert({:a => 1})
|
51
|
-
@col.insert({:a => 1})
|
52
|
-
end
|
53
|
-
|
54
|
-
should "return object on update" do
|
55
|
-
response = @col.update({:a => 1}, {"$set" => {:a => 2}},
|
56
|
-
:multi => true, :safe => true)
|
57
|
-
|
58
|
-
assert response['updatedExisting']
|
59
|
-
assert_equal 3, response['n']
|
60
|
-
end
|
61
|
-
|
62
|
-
should "return object on remove" do
|
63
|
-
response = @col.remove({}, :safe => true)
|
64
|
-
assert_equal 3, response['n']
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|