mongo 1.7.1 → 1.8.0
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.
- data/{LICENSE.txt → LICENSE} +0 -0
- data/README.md +124 -111
- data/Rakefile +9 -325
- data/VERSION +1 -0
- data/bin/mongo_console +4 -4
- data/examples/admin.rb +43 -0
- data/examples/capped.rb +22 -0
- data/examples/cursor.rb +48 -0
- data/examples/gridfs.rb +44 -0
- data/examples/index_test.rb +126 -0
- data/examples/info.rb +31 -0
- data/examples/queries.rb +74 -0
- data/examples/replica_set.rb +26 -0
- data/examples/simple.rb +25 -0
- data/examples/strict.rb +35 -0
- data/examples/types.rb +36 -0
- data/{test/load → examples/web}/thin/load.rb +3 -1
- data/{test/load → examples/web}/unicorn/load.rb +5 -3
- data/lib/mongo.rb +8 -10
- data/lib/mongo/collection.rb +134 -114
- data/lib/mongo/cursor.rb +21 -14
- data/lib/mongo/db.rb +30 -28
- data/lib/mongo/exceptions.rb +1 -1
- data/lib/mongo/gridfs/grid.rb +8 -7
- data/lib/mongo/gridfs/grid_ext.rb +1 -1
- data/lib/mongo/gridfs/grid_file_system.rb +6 -5
- data/lib/mongo/gridfs/grid_io.rb +22 -19
- data/lib/mongo/legacy.rb +82 -0
- data/lib/mongo/{connection.rb → mongo_client.rb} +82 -61
- data/lib/mongo/{repl_set_connection.rb → mongo_replica_set_client.rb} +54 -39
- data/lib/mongo/{sharded_connection.rb → mongo_sharded_client.rb} +9 -9
- data/lib/mongo/networking.rb +25 -20
- data/lib/mongo/util/conversions.rb +1 -1
- data/lib/mongo/util/core_ext.rb +1 -1
- data/lib/mongo/util/logging.rb +20 -4
- data/lib/mongo/util/node.rb +16 -16
- data/lib/mongo/util/pool.rb +56 -27
- data/lib/mongo/util/pool_manager.rb +28 -27
- data/lib/mongo/util/server_version.rb +1 -1
- data/lib/mongo/util/sharding_pool_manager.rb +8 -8
- data/lib/mongo/util/ssl_socket.rb +1 -5
- data/lib/mongo/util/support.rb +24 -8
- data/lib/mongo/util/tcp_socket.rb +0 -4
- data/lib/mongo/util/uri_parser.rb +54 -38
- data/lib/mongo/util/write_concern.rb +67 -0
- data/mongo.gemspec +21 -32
- data/test/auxillary/{1.4_features.rb → 1.4_feature_test.rb} +4 -5
- data/test/auxillary/authentication_test.rb +18 -20
- data/test/auxillary/autoreconnect_test.rb +3 -5
- data/test/auxillary/fork_test.rb +5 -7
- data/test/auxillary/repl_set_auth_test.rb +13 -15
- data/test/auxillary/slave_connection_test.rb +8 -7
- data/test/auxillary/threaded_authentication_test.rb +15 -17
- data/test/bson/binary_test.rb +1 -1
- data/test/bson/bson_test.rb +60 -36
- data/test/bson/byte_buffer_test.rb +1 -1
- data/test/bson/hash_with_indifferent_access_test.rb +2 -2
- data/test/bson/json_test.rb +1 -2
- data/test/bson/object_id_test.rb +1 -2
- data/test/bson/ordered_hash_test.rb +1 -1
- data/test/bson/timestamp_test.rb +1 -1
- data/test/{collection_test.rb → functional/collection_test.rb} +57 -57
- data/test/{connection_test.rb → functional/connection_test.rb} +75 -89
- data/test/{conversions_test.rb → functional/conversions_test.rb} +1 -1
- data/test/{cursor_fail_test.rb → functional/cursor_fail_test.rb} +3 -29
- data/test/{cursor_message_test.rb → functional/cursor_message_test.rb} +1 -1
- data/test/{cursor_test.rb → functional/cursor_test.rb} +5 -1
- data/test/{db_api_test.rb → functional/db_api_test.rb} +8 -9
- data/test/{db_connection_test.rb → functional/db_connection_test.rb} +3 -5
- data/test/{db_test.rb → functional/db_test.rb} +13 -13
- data/test/{grid_file_system_test.rb → functional/grid_file_system_test.rb} +2 -2
- data/test/{grid_io_test.rb → functional/grid_io_test.rb} +6 -6
- data/test/{grid_test.rb → functional/grid_test.rb} +4 -10
- data/test/{pool_test.rb → functional/pool_test.rb} +1 -1
- data/test/functional/safe_test.rb +84 -0
- data/test/{support_test.rb → functional/support_test.rb} +1 -1
- data/test/{threading_test.rb → functional/threading_test.rb} +9 -9
- data/test/{timeout_test.rb → functional/timeout_test.rb} +1 -1
- data/test/{uri_test.rb → functional/uri_test.rb} +1 -1
- data/test/functional/write_concern_test.rb +104 -0
- data/test/replica_set/basic_test.rb +139 -0
- data/test/replica_set/client_test.rb +255 -0
- data/test/replica_set/complex_connect_test.rb +62 -0
- data/test/replica_set/connection_test.rb +255 -0
- data/test/{replica_sets → replica_set}/count_test.rb +17 -14
- data/test/replica_set/cursor_test.rb +75 -0
- data/test/{replica_sets → replica_set}/insert_test.rb +19 -16
- data/test/replica_set/query_test.rb +64 -0
- data/test/replica_set/refresh_test.rb +153 -0
- data/test/{replica_sets → replica_set}/replication_ack_test.rb +21 -17
- data/test/sharded_cluster/basic_test.rb +31 -50
- data/test/support/hash_with_indifferent_access.rb +1 -1
- data/test/test_helper.rb +56 -9
- data/test/threading/threading_with_large_pool_test.rb +8 -8
- data/test/tools/mongo_config.rb +270 -58
- data/test/tools/mongo_config_test.rb +146 -0
- data/test/unit/client_test.rb +230 -0
- data/test/unit/collection_test.rb +45 -32
- data/test/unit/connection_test.rb +82 -74
- data/test/unit/cursor_test.rb +14 -6
- data/test/unit/db_test.rb +8 -8
- data/test/unit/grid_test.rb +11 -11
- data/test/unit/node_test.rb +24 -24
- data/test/unit/pool_manager_test.rb +13 -13
- data/test/unit/pool_test.rb +1 -1
- data/test/unit/read_test.rb +21 -26
- data/test/unit/safe_test.rb +52 -33
- data/test/unit/util_test.rb +55 -0
- data/test/unit/write_concern_test.rb +161 -0
- metadata +158 -171
- data/docs/CREDITS.md +0 -123
- data/docs/FAQ.md +0 -116
- data/docs/GRID_FS.md +0 -158
- data/docs/HISTORY.md +0 -392
- data/docs/READ_PREFERENCE.md +0 -99
- data/docs/RELEASES.md +0 -54
- data/docs/REPLICA_SETS.md +0 -113
- data/docs/TAILABLE_CURSORS.md +0 -51
- data/docs/TUTORIAL.md +0 -356
- data/docs/WRITE_CONCERN.md +0 -31
- data/lib/mongo/gridfs/grid_io_fix.rb +0 -38
- data/lib/mongo/version.rb +0 -3
- data/test/bson/test_helper.rb +0 -30
- data/test/replica_sets/basic_test.rb +0 -119
- data/test/replica_sets/complex_connect_test.rb +0 -57
- data/test/replica_sets/complex_read_preference_test.rb +0 -237
- data/test/replica_sets/connect_test.rb +0 -156
- data/test/replica_sets/cursor_test.rb +0 -70
- data/test/replica_sets/pooled_insert_test.rb +0 -57
- data/test/replica_sets/query_test.rb +0 -50
- data/test/replica_sets/read_preference_test.rb +0 -234
- data/test/replica_sets/refresh_test.rb +0 -156
- data/test/replica_sets/refresh_with_threads_test.rb +0 -60
- data/test/replica_sets/rs_test_helper.rb +0 -39
- data/test/safe_test.rb +0 -68
- data/test/sharded_cluster/mongo_config_test.rb +0 -126
- data/test/sharded_cluster/sc_test_helper.rb +0 -39
- data/test/tools/repl_set_manager.rb +0 -418
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
include Mongo
|
3
|
+
|
4
|
+
class WriteConcernTest < Test::Unit::TestCase
|
5
|
+
context "Write concern propogation: " do
|
6
|
+
setup do
|
7
|
+
@con = standard_connection
|
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
|
+
#TODO: add write concern tests for remove
|
15
|
+
|
16
|
+
should "propogate write concern options on insert" do
|
17
|
+
@col.insert({:a => 1})
|
18
|
+
|
19
|
+
assert_raise_error(OperationFailure, "duplicate key") do
|
20
|
+
@col.insert({:a => 1})
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
should "allow write concern override on insert" do
|
25
|
+
@col.insert({:a => 1})
|
26
|
+
@col.insert({:a => 1}, :w => 0)
|
27
|
+
end
|
28
|
+
|
29
|
+
should "propogate write concern option on update" do
|
30
|
+
@col.insert({:a => 1})
|
31
|
+
@col.insert({:a => 2})
|
32
|
+
|
33
|
+
assert_raise_error(OperationFailure, "duplicate key") do
|
34
|
+
@col.update({:a => 2}, {:a => 1})
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
should "allow write concern override on update" do
|
39
|
+
@col.insert({:a => 1})
|
40
|
+
@col.insert({:a => 2})
|
41
|
+
@col.update({:a => 2}, {:a => 1}, :w => 0)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "Write concern error objects" do
|
46
|
+
setup do
|
47
|
+
@con = standard_connection
|
48
|
+
@db = @con[MONGO_TEST_DB]
|
49
|
+
@col = @db['test']
|
50
|
+
@col.remove
|
51
|
+
@col.insert({:a => 1})
|
52
|
+
@col.insert({:a => 1})
|
53
|
+
@col.insert({:a => 1})
|
54
|
+
end
|
55
|
+
|
56
|
+
should "return object on update" do
|
57
|
+
response = @col.update({:a => 1}, {"$set" => {:a => 2}},
|
58
|
+
:multi => true)
|
59
|
+
|
60
|
+
assert response['updatedExisting']
|
61
|
+
assert_equal 3, response['n']
|
62
|
+
end
|
63
|
+
|
64
|
+
should "return object on remove" do
|
65
|
+
response = @col.remove({})
|
66
|
+
assert_equal 3, response['n']
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "Write concern in gridfs" do
|
71
|
+
setup do
|
72
|
+
@db = standard_connection.db(MONGO_TEST_DB)
|
73
|
+
@grid = Mongo::GridFileSystem.new(@db)
|
74
|
+
@filename = 'sample'
|
75
|
+
end
|
76
|
+
|
77
|
+
teardown do
|
78
|
+
@grid.delete(@filename)
|
79
|
+
end
|
80
|
+
|
81
|
+
should "should acknowledge writes by default using md5" do
|
82
|
+
file = @grid.open(@filename, 'w')
|
83
|
+
file.write "Hello world!"
|
84
|
+
file.close
|
85
|
+
assert_equal file.client_md5, file.server_md5
|
86
|
+
end
|
87
|
+
|
88
|
+
should "should allow for unacknowledged writes" do
|
89
|
+
file = @grid.open(@filename, 'w', {:w => 0} )
|
90
|
+
file.write "Hello world!"
|
91
|
+
file.close
|
92
|
+
assert_nil file.client_md5, file.server_md5
|
93
|
+
end
|
94
|
+
|
95
|
+
should "should support legacy write concern api" do
|
96
|
+
file = @grid.open(@filename, 'w', {:safe => false} )
|
97
|
+
file.write "Hello world!"
|
98
|
+
file.close
|
99
|
+
assert_nil file.client_md5, file.server_md5
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class BasicTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
ensure_cluster(:rs)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.shutdown
|
10
|
+
@@cluster.stop
|
11
|
+
@@cluster.clobber
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_connect
|
15
|
+
client = MongoReplicaSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name)
|
16
|
+
assert client.connected?
|
17
|
+
assert_equal @rs.primary_name, client.primary.join(':')
|
18
|
+
assert_equal @rs.secondary_names.sort, client.secondaries.collect{|s| s.join(':')}.sort
|
19
|
+
assert_equal @rs.arbiter_names.sort, client.arbiters.collect{|s| s.join(':')}.sort
|
20
|
+
client.close
|
21
|
+
|
22
|
+
silently do
|
23
|
+
client = MongoReplicaSetClient.new(@rs.repl_set_seeds_old, :name => @rs.repl_set_name)
|
24
|
+
end
|
25
|
+
|
26
|
+
assert client.connected?
|
27
|
+
client.close
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_safe_option
|
31
|
+
client = MongoReplicaSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name)
|
32
|
+
assert client.connected?
|
33
|
+
assert client.write_concern[:w] > 0
|
34
|
+
client.close
|
35
|
+
client = MongoReplicaSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name, :w => 0)
|
36
|
+
assert client.connected?
|
37
|
+
assert client.write_concern[:w] < 1
|
38
|
+
client.close
|
39
|
+
client = MongoReplicaSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name, :w => 2)
|
40
|
+
assert client.connected?
|
41
|
+
assert client.write_concern[:w] > 0
|
42
|
+
client.close
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_multiple_concurrent_replica_set_connection
|
46
|
+
client1 = MongoReplicaSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name)
|
47
|
+
client2 = MongoReplicaSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name)
|
48
|
+
assert client1.connected?
|
49
|
+
assert client2.connected?
|
50
|
+
assert client1.manager != client2.manager
|
51
|
+
assert client1.local_manager != client2.local_manager
|
52
|
+
client1.close
|
53
|
+
client2.close
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_cache_original_seed_nodes
|
57
|
+
host = @rs.servers.first.host
|
58
|
+
seeds = @rs.repl_set_seeds << "#{host}:19356"
|
59
|
+
client = MongoReplicaSetClient.new(seeds, :name => @rs.repl_set_name)
|
60
|
+
assert client.connected?
|
61
|
+
assert client.seeds.include?([host, 19356]), "Original seed nodes not cached!"
|
62
|
+
assert_equal [host, 19356], client.seeds.last, "Original seed nodes not cached!"
|
63
|
+
client.close
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_accessors
|
67
|
+
seeds = @rs.repl_set_seeds
|
68
|
+
args = {:name => @rs.repl_set_name}
|
69
|
+
client = MongoReplicaSetClient.new(seeds, args)
|
70
|
+
assert_equal @rs.primary_name, [client.host, client.port].join(':')
|
71
|
+
assert_equal client.host, client.primary_pool.host
|
72
|
+
assert_equal client.port, client.primary_pool.port
|
73
|
+
assert_equal 2, client.secondaries.length
|
74
|
+
assert_equal 2, client.arbiters.length
|
75
|
+
assert_equal 2, client.secondary_pools.length
|
76
|
+
assert_equal @rs.repl_set_name, client.replica_set_name
|
77
|
+
assert client.secondary_pools.include?(client.read_pool(:secondary))
|
78
|
+
assert_equal 90, client.refresh_interval
|
79
|
+
assert_equal client.refresh_mode, false
|
80
|
+
client.close
|
81
|
+
end
|
82
|
+
|
83
|
+
context "Socket pools" do
|
84
|
+
context "checking out writers" do
|
85
|
+
setup do
|
86
|
+
seeds = @rs.repl_set_seeds
|
87
|
+
args = {:name => @rs.repl_set_name}
|
88
|
+
@client = MongoReplicaSetClient.new(seeds, args)
|
89
|
+
@coll = @client[MONGO_TEST_DB]['test-connection-exceptions']
|
90
|
+
end
|
91
|
+
|
92
|
+
should "close the connection on send_message for major exceptions" do
|
93
|
+
@client.expects(:checkout_writer).raises(SystemStackError)
|
94
|
+
@client.expects(:close)
|
95
|
+
begin
|
96
|
+
@coll.insert({:foo => "bar"})
|
97
|
+
rescue SystemStackError
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
should "close the connection on send_message_with_gle for major exceptions" do
|
102
|
+
@client.expects(:checkout_writer).raises(SystemStackError)
|
103
|
+
@client.expects(:close)
|
104
|
+
begin
|
105
|
+
@coll.insert({:foo => "bar"})
|
106
|
+
rescue SystemStackError
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
should "close the connection on receive_message for major exceptions" do
|
111
|
+
@client.expects(:checkout_reader).raises(SystemStackError)
|
112
|
+
@client.expects(:close)
|
113
|
+
begin
|
114
|
+
@coll.find({}, :read => :primary).next
|
115
|
+
rescue SystemStackError
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context "checking out readers" do
|
121
|
+
setup do
|
122
|
+
seeds = @rs.repl_set_seeds
|
123
|
+
args = {:name => @rs.repl_set_name}
|
124
|
+
@client = MongoReplicaSetClient.new(seeds, args)
|
125
|
+
@coll = @client[MONGO_TEST_DB]['test-connection-exceptions']
|
126
|
+
end
|
127
|
+
|
128
|
+
should "close the connection on receive_message for major exceptions" do
|
129
|
+
@client.expects(:checkout_reader).raises(SystemStackError)
|
130
|
+
@client.expects(:close)
|
131
|
+
begin
|
132
|
+
@coll.find({}, :read => :secondary).next
|
133
|
+
rescue SystemStackError
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
@@ -0,0 +1,255 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ClientTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
ensure_cluster(:rs)
|
7
|
+
@client = nil
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
@client.close if @client
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.shutdown
|
15
|
+
@@cluster.stop
|
16
|
+
@@cluster.clobber
|
17
|
+
end
|
18
|
+
|
19
|
+
# To reset after (test) failure
|
20
|
+
# rake test:cleanup
|
21
|
+
|
22
|
+
def step_down_command
|
23
|
+
# Adding force=true to avoid 'no secondaries within 10 seconds of my optime' errors
|
24
|
+
step_down_command = BSON::OrderedHash.new
|
25
|
+
step_down_command[:replSetStepDown] = 60
|
26
|
+
step_down_command[:force] = true
|
27
|
+
step_down_command
|
28
|
+
end
|
29
|
+
|
30
|
+
# TODO: test connect timeout.
|
31
|
+
|
32
|
+
def test_connect_with_deprecated_multi
|
33
|
+
#replica_host_ports = @rs.replicas.collect{|replica| [replica.host, replica.port]}
|
34
|
+
host = @rs.replicas.first.host
|
35
|
+
silently do
|
36
|
+
@client = MongoClient.multi([
|
37
|
+
# guaranteed to have one data-holding member
|
38
|
+
[host, @rs.replicas[0].port],
|
39
|
+
[host, @rs.replicas[1].port],
|
40
|
+
[host, @rs.replicas[2].port],
|
41
|
+
], :name => @rs.repl_set_name)
|
42
|
+
end
|
43
|
+
assert !@client.nil?
|
44
|
+
assert @client.connected?
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_connect_bad_name
|
48
|
+
assert_raise_error(ReplicaSetConnectionError, "-wrong") do
|
49
|
+
@client = MongoReplicaSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name + "-wrong")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_connect_with_first_secondary_node_terminated
|
54
|
+
@rs.secondaries.first.stop
|
55
|
+
|
56
|
+
rescue_connection_failure do
|
57
|
+
@client = MongoReplicaSetClient.new @rs.repl_set_seeds
|
58
|
+
end
|
59
|
+
assert @client.connected?
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_connect_with_last_secondary_node_terminated
|
63
|
+
@rs.secondaries.last.stop
|
64
|
+
|
65
|
+
rescue_connection_failure do
|
66
|
+
@client = MongoReplicaSetClient.new @rs.repl_set_seeds
|
67
|
+
end
|
68
|
+
assert @client.connected?
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_connect_with_primary_stepped_down
|
72
|
+
@client = MongoReplicaSetClient.new @rs.repl_set_seeds
|
73
|
+
@client[MONGO_TEST_DB]['bar'].save({:a => 1}, {:w => 3})
|
74
|
+
assert @client[MONGO_TEST_DB]['bar'].find_one
|
75
|
+
|
76
|
+
primary = Mongo::MongoClient.new(@client.primary_pool.host, @client.primary_pool.port)
|
77
|
+
assert_raise Mongo::ConnectionFailure do
|
78
|
+
primary['admin'].command(step_down_command)
|
79
|
+
end
|
80
|
+
assert @client.connected?
|
81
|
+
|
82
|
+
rescue_connection_failure do
|
83
|
+
@client[MONGO_TEST_DB]['bar'].find_one
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_connect_with_primary_killed
|
88
|
+
@client = MongoReplicaSetClient.new @rs.repl_set_seeds
|
89
|
+
assert @client.connected?
|
90
|
+
@client[MONGO_TEST_DB]['bar'].save({:a => 1}, {:w => 3})
|
91
|
+
assert @client[MONGO_TEST_DB]['bar'].find_one
|
92
|
+
|
93
|
+
@rs.primary.kill(Signal.list['KILL'])
|
94
|
+
|
95
|
+
rescue_connection_failure do
|
96
|
+
@client[MONGO_TEST_DB]['bar'].find_one
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_save_with_primary_stepped_down
|
101
|
+
@client = MongoReplicaSetClient.new @rs.repl_set_seeds
|
102
|
+
assert @client.connected?
|
103
|
+
|
104
|
+
primary = Mongo::MongoClient.new(@client.primary_pool.host, @client.primary_pool.port)
|
105
|
+
assert_raise Mongo::ConnectionFailure do
|
106
|
+
primary['admin'].command(step_down_command)
|
107
|
+
end
|
108
|
+
|
109
|
+
rescue_connection_failure do
|
110
|
+
@client[MONGO_TEST_DB]['bar'].save({:a => 1}, {:w => 3})
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
#def test_connect_with_first_node_removed
|
115
|
+
# @client = MongoReplicaSetClient.new @rs.repl_set_seeds
|
116
|
+
# @client[MONGO_TEST_DB]['bar'].save({:a => 1}, {:w => 3})
|
117
|
+
#
|
118
|
+
# old_primary = [@client.primary_pool.host, @client.primary_pool.port]
|
119
|
+
# old_primary_conn = Mongo::MongoClient.new(*old_primary)
|
120
|
+
# assert_raise Mongo::ConnectionFailure do
|
121
|
+
# old_primary_conn['admin'].command(step_down_command)
|
122
|
+
# end
|
123
|
+
#
|
124
|
+
# # Wait for new primary
|
125
|
+
# rescue_connection_failure do
|
126
|
+
# sleep 1 until @rs.get_node_with_state(1)
|
127
|
+
# end
|
128
|
+
#
|
129
|
+
# new_primary = @rs.get_all_host_pairs_with_state(1).first
|
130
|
+
# new_primary_conn = Mongo::MongoClient.new(*new_primary)
|
131
|
+
#
|
132
|
+
# config = nil
|
133
|
+
#
|
134
|
+
# # Remove old primary from replset
|
135
|
+
# rescue_connection_failure do
|
136
|
+
# config = @client['local']['system.replset'].find_one
|
137
|
+
# end
|
138
|
+
#
|
139
|
+
# old_member = config['members'].select {|m| m['host'] == old_primary.join(':')}.first
|
140
|
+
# config['members'].reject! {|m| m['host'] == old_primary.join(':')}
|
141
|
+
# config['version'] += 1
|
142
|
+
#
|
143
|
+
# begin
|
144
|
+
# new_primary_conn['admin'].command({'replSetReconfig' => config})
|
145
|
+
# rescue Mongo::ConnectionFailure
|
146
|
+
# end
|
147
|
+
#
|
148
|
+
# # Wait for the dust to settle
|
149
|
+
# rescue_connection_failure do
|
150
|
+
# assert @client[MONGO_TEST_DB]['bar'].find_one
|
151
|
+
# end
|
152
|
+
#
|
153
|
+
# # Make sure a new connection skips the old primary
|
154
|
+
# @new_conn = MongoReplicaSetClient.new @rs.repl_set_seeds
|
155
|
+
# @new_conn.connect
|
156
|
+
# new_nodes = [@new_conn.primary] + @new_conn.secondaries
|
157
|
+
# assert !(new_nodes).include?(old_primary)
|
158
|
+
#
|
159
|
+
# # Add the old primary back
|
160
|
+
# config['members'] << old_member
|
161
|
+
# config['version'] += 1
|
162
|
+
#
|
163
|
+
# begin
|
164
|
+
# new_primary_conn['admin'].command({'replSetReconfig' => config})
|
165
|
+
# rescue Mongo::ConnectionFailure
|
166
|
+
# end
|
167
|
+
#end
|
168
|
+
|
169
|
+
#def test_connect_with_hung_first_node
|
170
|
+
# hung_node = nil
|
171
|
+
# begin
|
172
|
+
# hung_node = IO.popen('nc -lk 127.0.0.1 29999 >/dev/null 2>&1')
|
173
|
+
#
|
174
|
+
# @client = MongoReplicaSetClient.new(['localhost:29999'] + @rs.repl_set_seeds,
|
175
|
+
# :connect_timeout => 2)
|
176
|
+
# @client.connect
|
177
|
+
# assert ['localhost:29999'] != @client.primary
|
178
|
+
# assert !@client.secondaries.include?('localhost:29999')
|
179
|
+
# ensure
|
180
|
+
# Process.kill("KILL", hung_node.pid) if hung_node
|
181
|
+
# end
|
182
|
+
#end
|
183
|
+
|
184
|
+
def test_connect_with_connection_string
|
185
|
+
@client = MongoClient.from_uri("mongodb://#{@rs.replicas[0].host_port},#{@rs.replicas[1].host_port}?replicaset=#{@rs.repl_set_name}")
|
186
|
+
assert !@client.nil?
|
187
|
+
assert @client.connected?
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_connect_with_connection_string_in_env_var
|
191
|
+
ENV['MONGODB_URI'] = "mongodb://#{@rs.replicas[0].host_port},#{@rs.replicas[1].host_port}?replicaset=#{@rs.repl_set_name}"
|
192
|
+
@client = MongoReplicaSetClient.new
|
193
|
+
assert !@client.nil?
|
194
|
+
assert_equal 2, @client.seeds.length
|
195
|
+
assert_equal @rs.replicas[0].host, @client.seeds[0][0]
|
196
|
+
assert_equal @rs.replicas[1].host, @client.seeds[1][0]
|
197
|
+
assert_equal @rs.replicas[0].port, @client.seeds[0][1]
|
198
|
+
assert_equal @rs.replicas[1].port, @client.seeds[1][1]
|
199
|
+
assert_equal @rs.repl_set_name, @client.replica_set_name
|
200
|
+
assert @client.connected?
|
201
|
+
end
|
202
|
+
|
203
|
+
def test_connect_with_connection_string_in_implicit_mongodb_uri
|
204
|
+
ENV['MONGODB_URI'] = "mongodb://#{@rs.replicas[0].host_port},#{@rs.replicas[1].host_port}?replicaset=#{@rs.repl_set_name}"
|
205
|
+
@client = MongoClient.from_uri
|
206
|
+
assert !@client.nil?
|
207
|
+
assert_equal 2, @client.seeds.length
|
208
|
+
assert_equal @rs.replicas[0].host, @client.seeds[0][0]
|
209
|
+
assert_equal @rs.replicas[1].host, @client.seeds[1][0]
|
210
|
+
assert_equal @rs.replicas[0].port, @client.seeds[0][1]
|
211
|
+
assert_equal @rs.replicas[1].port, @client.seeds[1][1]
|
212
|
+
assert_equal @rs.repl_set_name, @client.replica_set_name
|
213
|
+
assert @client.connected?
|
214
|
+
end
|
215
|
+
|
216
|
+
def test_connect_with_new_seed_format
|
217
|
+
@client = MongoReplicaSetClient.new @rs.repl_set_seeds
|
218
|
+
assert @client.connected?
|
219
|
+
end
|
220
|
+
|
221
|
+
def test_connect_with_old_seed_format
|
222
|
+
silently do
|
223
|
+
@client = MongoReplicaSetClient.new(@rs.replicas[0].host_port_a, @rs.replicas[1].host_port_a)
|
224
|
+
end
|
225
|
+
assert @client.connected?
|
226
|
+
end
|
227
|
+
|
228
|
+
def test_connect_with_full_connection_string
|
229
|
+
@client = MongoClient.from_uri("mongodb://#{@rs.replicas[0].host_port},#{@rs.replicas[1].host_port}?replicaset=#{@rs.repl_set_name};w=2;fsync=true;slaveok=true")
|
230
|
+
assert !@client.nil?
|
231
|
+
assert @client.connected?
|
232
|
+
assert_equal 2, @client.write_concern[:w]
|
233
|
+
assert @client.write_concern[:fsync]
|
234
|
+
assert @client.read_pool
|
235
|
+
end
|
236
|
+
|
237
|
+
def test_connect_with_full_connection_string_in_env_var
|
238
|
+
ENV['MONGODB_URI'] = "mongodb://#{@rs.replicas[0].host_port},#{@rs.replicas[1].host_port}?replicaset=#{@rs.repl_set_name};w=2;fsync=true;slaveok=true"
|
239
|
+
@client = MongoReplicaSetClient.new
|
240
|
+
assert !@client.nil?
|
241
|
+
assert @client.connected?
|
242
|
+
assert_equal 2, @client.write_concern[:w]
|
243
|
+
assert @client.write_concern[:fsync]
|
244
|
+
assert @client.read_pool
|
245
|
+
end
|
246
|
+
|
247
|
+
def test_connect_options_override_env_var
|
248
|
+
ENV['MONGODB_URI'] = "mongodb://#{@rs.replicas[0].host_port},#{@rs.replicas[1].host_port}?replicaset=#{@rs.repl_set_name};w=2;fsync=true;slaveok=true"
|
249
|
+
@client = MongoReplicaSetClient.new({:w => 0})
|
250
|
+
assert !@client.nil?
|
251
|
+
assert @client.connected?
|
252
|
+
assert_equal 0, @client.write_concern[:w]
|
253
|
+
end
|
254
|
+
|
255
|
+
end
|