mongo 1.9.2 → 1.10.0.rc0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/LICENSE +1 -1
- data/README.md +94 -334
- data/Rakefile +6 -4
- data/VERSION +1 -1
- data/bin/mongo_console +13 -6
- data/lib/mongo.rb +22 -27
- data/lib/mongo/bulk_write_collection_view.rb +352 -0
- data/lib/mongo/collection.rb +128 -188
- data/lib/mongo/collection_writer.rb +348 -0
- data/lib/mongo/connection.rb +19 -0
- data/lib/mongo/{util → connection}/node.rb +15 -1
- data/lib/mongo/{util → connection}/pool.rb +34 -19
- data/lib/mongo/{util → connection}/pool_manager.rb +8 -2
- data/lib/mongo/{util → connection}/sharding_pool_manager.rb +1 -1
- data/lib/mongo/connection/socket.rb +18 -0
- data/lib/mongo/{util → connection/socket}/socket_util.rb +5 -2
- data/lib/mongo/{util → connection/socket}/ssl_socket.rb +3 -4
- data/lib/mongo/{util → connection/socket}/tcp_socket.rb +25 -15
- data/lib/mongo/{util → connection/socket}/unix_socket.rb +6 -4
- data/lib/mongo/cursor.rb +113 -47
- data/lib/mongo/db.rb +203 -131
- data/lib/mongo/{exceptions.rb → exception.rb} +7 -1
- data/lib/mongo/functional.rb +19 -0
- data/lib/mongo/functional/authentication.rb +303 -0
- data/lib/mongo/{util → functional}/logging.rb +1 -1
- data/lib/mongo/{util → functional}/read_preference.rb +49 -1
- data/lib/mongo/{util → functional}/uri_parser.rb +81 -69
- data/lib/mongo/{util → functional}/write_concern.rb +2 -1
- data/{test/unit/pool_test.rb → lib/mongo/gridfs.rb} +5 -10
- data/lib/mongo/gridfs/grid.rb +1 -3
- data/lib/mongo/gridfs/grid_ext.rb +1 -1
- data/lib/mongo/gridfs/grid_file_system.rb +1 -1
- data/lib/mongo/gridfs/grid_io.rb +1 -1
- data/lib/mongo/legacy.rb +63 -8
- data/lib/mongo/mongo_client.rb +128 -154
- data/lib/mongo/mongo_replica_set_client.rb +17 -11
- data/lib/mongo/mongo_sharded_client.rb +2 -1
- data/lib/mongo/networking.rb +19 -10
- data/lib/mongo/utils.rb +19 -0
- data/lib/mongo/{util → utils}/conversions.rb +1 -1
- data/lib/mongo/{util → utils}/core_ext.rb +1 -1
- data/lib/mongo/{util → utils}/server_version.rb +1 -1
- data/lib/mongo/{util → utils}/support.rb +10 -57
- data/lib/mongo/{util → utils}/thread_local_variable_manager.rb +1 -1
- data/test/functional/authentication_test.rb +8 -21
- data/test/functional/bulk_write_collection_view_test.rb +782 -0
- data/test/functional/{connection_test.rb → client_test.rb} +153 -78
- data/test/functional/collection_test.rb +343 -97
- data/test/functional/collection_writer_test.rb +83 -0
- data/test/functional/conversions_test.rb +1 -3
- data/test/functional/cursor_fail_test.rb +3 -3
- data/test/functional/cursor_message_test.rb +3 -3
- data/test/functional/cursor_test.rb +38 -3
- data/test/functional/db_api_test.rb +5 -5
- data/test/functional/db_connection_test.rb +2 -2
- data/test/functional/db_test.rb +35 -11
- data/test/functional/grid_file_system_test.rb +2 -2
- data/test/functional/grid_io_test.rb +2 -2
- data/test/functional/grid_test.rb +2 -2
- data/test/functional/pool_test.rb +2 -3
- data/test/functional/safe_test.rb +5 -5
- data/test/functional/ssl_test.rb +22 -102
- data/test/functional/support_test.rb +1 -1
- data/test/functional/timeout_test.rb +6 -22
- data/test/functional/uri_test.rb +113 -12
- data/test/functional/write_concern_test.rb +6 -6
- data/test/helpers/general.rb +50 -0
- data/test/helpers/test_unit.rb +309 -0
- data/test/replica_set/authentication_test.rb +8 -23
- data/test/replica_set/basic_test.rb +41 -14
- data/test/replica_set/client_test.rb +179 -117
- data/test/replica_set/complex_connect_test.rb +6 -7
- data/test/replica_set/connection_test.rb +46 -38
- data/test/replica_set/count_test.rb +2 -2
- data/test/replica_set/cursor_test.rb +8 -8
- data/test/replica_set/insert_test.rb +64 -2
- data/test/replica_set/max_values_test.rb +59 -10
- data/test/replica_set/pinning_test.rb +2 -2
- data/test/replica_set/query_test.rb +2 -2
- data/test/replica_set/read_preference_test.rb +6 -6
- data/test/replica_set/refresh_test.rb +7 -7
- data/test/replica_set/replication_ack_test.rb +5 -5
- data/test/replica_set/ssl_test.rb +24 -106
- data/test/sharded_cluster/basic_test.rb +43 -15
- data/test/shared/authentication/basic_auth_shared.rb +215 -0
- data/test/shared/authentication/sasl_plain_shared.rb +96 -0
- data/test/shared/ssl_shared.rb +173 -0
- data/test/test_helper.rb +31 -199
- data/test/threading/basic_test.rb +29 -3
- data/test/tools/mongo_config.rb +45 -20
- data/test/tools/mongo_config_test.rb +1 -1
- data/test/unit/client_test.rb +136 -57
- data/test/unit/collection_test.rb +31 -55
- data/test/unit/connection_test.rb +135 -72
- data/test/unit/cursor_test.rb +2 -2
- data/test/unit/db_test.rb +19 -15
- data/test/unit/grid_test.rb +2 -2
- data/test/unit/mongo_sharded_client_test.rb +17 -15
- data/test/unit/node_test.rb +2 -2
- data/test/unit/pool_manager_test.rb +7 -5
- data/test/unit/read_pref_test.rb +82 -2
- data/test/unit/read_test.rb +14 -14
- data/test/unit/safe_test.rb +9 -9
- data/test/unit/sharding_pool_manager_test.rb +11 -5
- data/test/unit/write_concern_test.rb +9 -9
- metadata +71 -56
- metadata.gz.sig +0 -0
- data/test/functional/threading_test.rb +0 -109
- data/test/shared/authentication.rb +0 -121
- data/test/unit/util_test.rb +0 -69
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2013
|
1
|
+
# Copyright (C) 2009-2013 MongoDB, Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -13,34 +13,19 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
15
|
require 'test_helper'
|
16
|
-
require 'shared/authentication'
|
16
|
+
require 'shared/authentication/basic_auth_shared'
|
17
|
+
require 'shared/authentication/sasl_plain_shared'
|
17
18
|
|
18
19
|
class ReplicaSetAuthenticationTest < Test::Unit::TestCase
|
19
20
|
include Mongo
|
20
|
-
include
|
21
|
+
include BasicAuthTests
|
22
|
+
include SASLPlainTests
|
21
23
|
|
22
24
|
def setup
|
23
25
|
ensure_cluster(:rs)
|
24
|
-
@client
|
25
|
-
@db
|
26
|
+
@client = MongoReplicaSetClient.new(@rs.repl_set_seeds)
|
27
|
+
@db = @client[TEST_DB]
|
28
|
+
@host_info = @rs.repl_set_seeds.join(',')
|
26
29
|
init_auth
|
27
30
|
end
|
28
|
-
|
29
|
-
def test_authenticate_with_connection_uri
|
30
|
-
@db.add_user('eunice', 'uritest')
|
31
|
-
|
32
|
-
client =
|
33
|
-
MongoReplicaSetClient.from_uri(
|
34
|
-
"mongodb://eunice:uritest@#{@rs.repl_set_seeds.join(',')}/#{@db.name}" +
|
35
|
-
"?replicaSet=#{@rs.repl_set_name}")
|
36
|
-
|
37
|
-
assert client
|
38
|
-
assert_equal client.auths.size, 1
|
39
|
-
assert client[MONGO_TEST_DB]['auth_test'].count
|
40
|
-
|
41
|
-
auth = client.auths.first
|
42
|
-
assert_equal @db.name, auth[:db_name]
|
43
|
-
assert_equal 'eunice', auth[:username]
|
44
|
-
assert_equal 'uritest', auth[:password]
|
45
|
-
end
|
46
31
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2013
|
1
|
+
# Copyright (C) 2009-2013 MongoDB, Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
require 'test_helper'
|
16
16
|
|
17
|
-
class
|
17
|
+
class ReplicaSetBasicTest < Test::Unit::TestCase
|
18
18
|
|
19
19
|
def setup
|
20
20
|
ensure_cluster(:rs)
|
@@ -88,30 +88,57 @@ class BasicTest < Test::Unit::TestCase
|
|
88
88
|
client.close
|
89
89
|
end
|
90
90
|
|
91
|
+
def test_write_commands_and_operations
|
92
|
+
seeds = @rs.repl_set_seeds
|
93
|
+
args = {:name => @rs.repl_set_name}
|
94
|
+
@client = MongoReplicaSetClient.new(seeds, args)
|
95
|
+
@coll = @client[TEST_DB]['test-write-commands-and-operations']
|
96
|
+
with_write_commands_and_operations(@client) do
|
97
|
+
@coll.remove
|
98
|
+
@coll.insert({:foo => "bar"})
|
99
|
+
assert_equal(1, @coll.count)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
91
103
|
context "Socket pools" do
|
92
104
|
context "checking out writers" do
|
93
105
|
setup do
|
94
106
|
seeds = @rs.repl_set_seeds
|
95
107
|
args = {:name => @rs.repl_set_name}
|
96
108
|
@client = MongoReplicaSetClient.new(seeds, args)
|
97
|
-
@coll = @client[
|
109
|
+
@coll = @client[TEST_DB]['test-connection-exceptions']
|
98
110
|
end
|
99
111
|
|
100
112
|
should "close the connection on send_message for major exceptions" do
|
101
|
-
@client
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
113
|
+
with_write_operations(@client) do # explicit even if w 0 maps to write operations
|
114
|
+
@client.expects(:checkout_writer).raises(SystemStackError)
|
115
|
+
@client.expects(:close)
|
116
|
+
begin
|
117
|
+
@coll.insert({:foo => "bar"}, :w => 0)
|
118
|
+
rescue SystemStackError
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
should "close the connection on send_write_command for major exceptions" do
|
124
|
+
with_write_commands(@client) do
|
125
|
+
@client.expects(:checkout_reader).raises(SystemStackError)
|
126
|
+
@client.expects(:close)
|
127
|
+
begin
|
128
|
+
@coll.insert({:foo => "bar"})
|
129
|
+
rescue SystemStackError
|
130
|
+
end
|
106
131
|
end
|
107
132
|
end
|
108
133
|
|
109
134
|
should "close the connection on send_message_with_gle for major exceptions" do
|
110
|
-
@client
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
135
|
+
with_write_operations(@client) do
|
136
|
+
@client.expects(:checkout_writer).raises(SystemStackError)
|
137
|
+
@client.expects(:close)
|
138
|
+
begin
|
139
|
+
@coll.insert({:foo => "bar"})
|
140
|
+
rescue SystemStackError
|
141
|
+
end
|
115
142
|
end
|
116
143
|
end
|
117
144
|
|
@@ -130,7 +157,7 @@ class BasicTest < Test::Unit::TestCase
|
|
130
157
|
seeds = @rs.repl_set_seeds
|
131
158
|
args = {:name => @rs.repl_set_name}
|
132
159
|
@client = MongoReplicaSetClient.new(seeds, args)
|
133
|
-
@coll = @client[
|
160
|
+
@coll = @client[TEST_DB]['test-connection-exceptions']
|
134
161
|
end
|
135
162
|
|
136
163
|
should "close the connection on receive_message for major exceptions" do
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2013
|
1
|
+
# Copyright (C) 2009-2013 MongoDB, Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
require 'test_helper'
|
16
16
|
|
17
|
-
class
|
17
|
+
class ReplicaSetClientTest < Test::Unit::TestCase
|
18
18
|
|
19
19
|
def setup
|
20
20
|
ensure_cluster(:rs)
|
@@ -77,35 +77,35 @@ class ClientTest < Test::Unit::TestCase
|
|
77
77
|
|
78
78
|
def test_connect_with_primary_stepped_down
|
79
79
|
@client = MongoReplicaSetClient.new @rs.repl_set_seeds
|
80
|
-
@client[
|
81
|
-
assert @client[
|
80
|
+
@client[TEST_DB]['bar'].save({:a => 1}, {:w => 3})
|
81
|
+
assert @client[TEST_DB]['bar'].find_one
|
82
82
|
|
83
83
|
primary = Mongo::MongoClient.new(*@client.primary)
|
84
84
|
assert_raise Mongo::ConnectionFailure do
|
85
|
-
primary
|
85
|
+
perform_step_down(primary)
|
86
86
|
end
|
87
87
|
assert @client.connected?
|
88
88
|
|
89
89
|
rescue_connection_failure do
|
90
|
-
@client[
|
90
|
+
@client[TEST_DB]['bar'].find_one
|
91
91
|
end
|
92
|
-
@client[
|
92
|
+
@client[TEST_DB]['bar'].find_one
|
93
93
|
end
|
94
94
|
|
95
95
|
def test_connect_with_primary_killed
|
96
96
|
@client = MongoReplicaSetClient.new @rs.repl_set_seeds
|
97
97
|
assert @client.connected?
|
98
|
-
@client[
|
99
|
-
assert @client[
|
98
|
+
@client[TEST_DB]['bar'].save({:a => 1}, {:w => 3})
|
99
|
+
assert @client[TEST_DB]['bar'].find_one
|
100
100
|
|
101
101
|
@rs.primary.kill(Signal.list['KILL'])
|
102
102
|
|
103
103
|
sleep(3)
|
104
104
|
|
105
105
|
rescue_connection_failure do
|
106
|
-
@client[
|
106
|
+
@client[TEST_DB]['bar'].find_one
|
107
107
|
end
|
108
|
-
@client[
|
108
|
+
@client[TEST_DB]['bar'].find_one
|
109
109
|
end
|
110
110
|
|
111
111
|
def test_save_with_primary_stepped_down
|
@@ -114,84 +114,101 @@ class ClientTest < Test::Unit::TestCase
|
|
114
114
|
|
115
115
|
primary = Mongo::MongoClient.new(*@client.primary)
|
116
116
|
assert_raise Mongo::ConnectionFailure do
|
117
|
-
primary
|
117
|
+
perform_step_down(primary)
|
118
118
|
end
|
119
119
|
|
120
120
|
rescue_connection_failure do
|
121
|
-
@client[
|
121
|
+
@client[TEST_DB]['bar'].save({:a => 1}, {:w => 2})
|
122
122
|
end
|
123
|
-
@client[
|
123
|
+
@client[TEST_DB]['bar'].find_one
|
124
124
|
end
|
125
125
|
|
126
|
-
#def test_connect_with_first_node_removed
|
127
|
-
#
|
128
|
-
#
|
129
|
-
|
130
|
-
#
|
131
|
-
#
|
132
|
-
#
|
133
|
-
#
|
134
|
-
#
|
135
|
-
#
|
136
|
-
#
|
137
|
-
#
|
138
|
-
#
|
139
|
-
|
140
|
-
#
|
141
|
-
#
|
142
|
-
|
143
|
-
#
|
144
|
-
#
|
145
|
-
#
|
146
|
-
|
147
|
-
#
|
148
|
-
#
|
149
|
-
#
|
150
|
-
#
|
151
|
-
|
152
|
-
#
|
153
|
-
#
|
154
|
-
|
155
|
-
#
|
156
|
-
|
157
|
-
#
|
158
|
-
|
159
|
-
#
|
160
|
-
#
|
161
|
-
#
|
162
|
-
#
|
163
|
-
|
164
|
-
#
|
165
|
-
#
|
166
|
-
#
|
167
|
-
|
168
|
-
#
|
169
|
-
#
|
170
|
-
#
|
171
|
-
#
|
172
|
-
|
173
|
-
#
|
174
|
-
#
|
175
|
-
#
|
176
|
-
#
|
177
|
-
|
178
|
-
#
|
179
|
-
#
|
180
|
-
|
181
|
-
#
|
182
|
-
#
|
183
|
-
#
|
184
|
-
#
|
185
|
-
#
|
186
|
-
#
|
187
|
-
#
|
188
|
-
|
189
|
-
#
|
190
|
-
#
|
191
|
-
#
|
192
|
-
#
|
193
|
-
#
|
194
|
-
#end
|
126
|
+
# def test_connect_with_first_node_removed
|
127
|
+
# @client = MongoReplicaSetClient.new @rs.repl_set_seeds
|
128
|
+
# @client[TEST_DB]['bar'].save({:a => 1}, {:w => 3})
|
129
|
+
|
130
|
+
# # Make sure everyone's views of optimes are caught up
|
131
|
+
# loop do
|
132
|
+
# break if @rs.repl_set_get_status.all? do |status|
|
133
|
+
# members = status['members']
|
134
|
+
# primary_optime = members.find{|m| m['state'] == 1}['optime'].seconds
|
135
|
+
# members.any?{|m| m['state'] == 2 && primary_optime - m['optime'].seconds < 5}
|
136
|
+
# end
|
137
|
+
# sleep 1
|
138
|
+
# end
|
139
|
+
|
140
|
+
# old_primary = [@client.primary_pool.host, @client.primary_pool.port]
|
141
|
+
# old_primary_conn = Mongo::MongoClient.new(*old_primary)
|
142
|
+
|
143
|
+
# assert_raise Mongo::ConnectionFailure do
|
144
|
+
# perform_step_down(old_primary_conn)
|
145
|
+
# end
|
146
|
+
|
147
|
+
# # Wait for new primary
|
148
|
+
# rescue_connection_failure do
|
149
|
+
# sleep 1 until @rs.primary
|
150
|
+
# end
|
151
|
+
|
152
|
+
# new_primary = [@rs.primary.host, @rs.primary.port]
|
153
|
+
# new_primary_conn = Mongo::MongoClient.new(*new_primary)
|
154
|
+
|
155
|
+
# assert new_primary != old_primary
|
156
|
+
|
157
|
+
# config = nil
|
158
|
+
|
159
|
+
# # Remove old primary from replset
|
160
|
+
# rescue_connection_failure do
|
161
|
+
# config = @client['local']['system.replset'].find_one
|
162
|
+
# end
|
163
|
+
|
164
|
+
# old_member = config['members'].select {|m| m['host'] == old_primary.join(':')}.first
|
165
|
+
# config['members'].reject! {|m| m['host'] == old_primary.join(':')}
|
166
|
+
# config['version'] += 1
|
167
|
+
|
168
|
+
# begin
|
169
|
+
# new_primary_conn['admin'].command({'replSetReconfig' => config})
|
170
|
+
# rescue Mongo::ConnectionFailure
|
171
|
+
# end
|
172
|
+
|
173
|
+
# # Wait for the dust to settle
|
174
|
+
# rescue_connection_failure do
|
175
|
+
# assert @client[TEST_DB]['bar'].find_one
|
176
|
+
# end
|
177
|
+
|
178
|
+
# begin
|
179
|
+
# # Make sure a new connection skips the old primary
|
180
|
+
# @new_conn = MongoReplicaSetClient.new @rs.repl_set_seeds
|
181
|
+
# @new_conn.connect
|
182
|
+
# new_nodes = @new_conn.secondaries + [@new_conn.primary]
|
183
|
+
# assert !new_nodes.include?(old_primary)
|
184
|
+
# ensure
|
185
|
+
# # Add the old primary back
|
186
|
+
# config['members'] << old_member
|
187
|
+
# config['version'] += 1
|
188
|
+
|
189
|
+
# begin
|
190
|
+
# new_primary_conn['admin'].command({'replSetReconfig' => config})
|
191
|
+
# rescue Mongo::ConnectionFailure
|
192
|
+
# end
|
193
|
+
# end
|
194
|
+
# end
|
195
|
+
|
196
|
+
def test_connect_with_hung_first_node
|
197
|
+
hung_node = nil
|
198
|
+
begin
|
199
|
+
hung_node = IO.popen('nc -lk 127.0.0.1 29999 >/dev/null 2>&1')
|
200
|
+
|
201
|
+
Timeout.timeout(3) do
|
202
|
+
@client = MongoReplicaSetClient.new(['localhost:29999'] + @rs.repl_set_seeds,
|
203
|
+
:connect_timeout => 2)
|
204
|
+
@client.connect
|
205
|
+
end
|
206
|
+
assert ['localhost:29999'] != @client.primary
|
207
|
+
assert !@client.secondaries.include?('localhost:29999')
|
208
|
+
ensure
|
209
|
+
Process.kill("KILL", hung_node.pid) if hung_node
|
210
|
+
end
|
211
|
+
end
|
195
212
|
|
196
213
|
def test_connect_with_connection_string
|
197
214
|
@client = MongoClient.from_uri("mongodb://#{@rs.replicas[0].host_port},#{@rs.replicas[1].host_port}?replicaset=#{@rs.repl_set_name}")
|
@@ -200,29 +217,33 @@ class ClientTest < Test::Unit::TestCase
|
|
200
217
|
end
|
201
218
|
|
202
219
|
def test_connect_with_connection_string_in_env_var
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
220
|
+
uri = "mongodb://#{@rs.replicas[0].host_port},#{@rs.replicas[1].host_port}?replicaset=#{@rs.repl_set_name}"
|
221
|
+
with_preserved_env_uri(uri) do
|
222
|
+
@client = MongoReplicaSetClient.new
|
223
|
+
assert !@client.nil?
|
224
|
+
assert_equal 2, @client.seeds.length
|
225
|
+
assert_equal @rs.replicas[0].host, @client.seeds[0][0]
|
226
|
+
assert_equal @rs.replicas[1].host, @client.seeds[1][0]
|
227
|
+
assert_equal @rs.replicas[0].port, @client.seeds[0][1]
|
228
|
+
assert_equal @rs.replicas[1].port, @client.seeds[1][1]
|
229
|
+
assert_equal @rs.repl_set_name, @client.replica_set_name
|
230
|
+
assert @client.connected?
|
231
|
+
end
|
213
232
|
end
|
214
233
|
|
215
234
|
def test_connect_with_connection_string_in_implicit_mongodb_uri
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
235
|
+
uri = "mongodb://#{@rs.replicas[0].host_port},#{@rs.replicas[1].host_port}?replicaset=#{@rs.repl_set_name}"
|
236
|
+
with_preserved_env_uri(uri) do
|
237
|
+
@client = MongoClient.from_uri
|
238
|
+
assert !@client.nil?
|
239
|
+
assert_equal 2, @client.seeds.length
|
240
|
+
assert_equal @rs.replicas[0].host, @client.seeds[0][0]
|
241
|
+
assert_equal @rs.replicas[1].host, @client.seeds[1][0]
|
242
|
+
assert_equal @rs.replicas[0].port, @client.seeds[0][1]
|
243
|
+
assert_equal @rs.replicas[1].port, @client.seeds[1][1]
|
244
|
+
assert_equal @rs.repl_set_name, @client.replica_set_name
|
245
|
+
assert @client.connected?
|
246
|
+
end
|
226
247
|
end
|
227
248
|
|
228
249
|
def test_connect_with_new_seed_format
|
@@ -247,26 +268,67 @@ class ClientTest < Test::Unit::TestCase
|
|
247
268
|
end
|
248
269
|
|
249
270
|
def test_connect_with_full_connection_string_in_env_var
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
271
|
+
uri = "mongodb://#{@rs.replicas[0].host_port},#{@rs.replicas[1].host_port}?replicaset=#{@rs.repl_set_name};w=2;fsync=true;slaveok=true"
|
272
|
+
with_preserved_env_uri(uri) do
|
273
|
+
@client = MongoReplicaSetClient.new
|
274
|
+
assert !@client.nil?
|
275
|
+
assert @client.connected?
|
276
|
+
assert_equal 2, @client.write_concern[:w]
|
277
|
+
assert @client.write_concern[:fsync]
|
278
|
+
assert @client.read_pool
|
279
|
+
end
|
257
280
|
end
|
258
281
|
|
259
282
|
def test_connect_options_override_env_var
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
283
|
+
uri = "mongodb://#{@rs.replicas[0].host_port},#{@rs.replicas[1].host_port}?replicaset=#{@rs.repl_set_name};w=2;fsync=true;slaveok=true"
|
284
|
+
with_preserved_env_uri(uri) do
|
285
|
+
@client = MongoReplicaSetClient.new({:w => 0})
|
286
|
+
assert !@client.nil?
|
287
|
+
assert @client.connected?
|
288
|
+
assert_equal 0, @client.write_concern[:w]
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
def test_ipv6
|
293
|
+
@client = MongoReplicaSetClient.new(@rs.repl_set_seeds)
|
294
|
+
with_ipv6_enabled(@client) do
|
295
|
+
assert MongoReplicaSetClient.new(["[::1]:#{@rs.replicas[0].port}"])
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
def test_ipv6_with_uri
|
300
|
+
@client = MongoReplicaSetClient.new(@rs.repl_set_seeds)
|
301
|
+
with_ipv6_enabled(@client) do
|
302
|
+
uri = "mongodb://[::1]:#{@rs.replicas[0].port},[::1]:#{@rs.replicas[1].port}"
|
303
|
+
with_preserved_env_uri(uri) do
|
304
|
+
assert MongoReplicaSetClient.new
|
305
|
+
end
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
def test_ipv6_with_uri_opts
|
310
|
+
@client = MongoReplicaSetClient.new(@rs.repl_set_seeds)
|
311
|
+
with_ipv6_enabled(@client) do
|
312
|
+
uri = "mongodb://[::1]:#{@rs.replicas[0].port},[::1]:#{@rs.replicas[1].port}/?safe=true;"
|
313
|
+
with_preserved_env_uri(uri) do
|
314
|
+
assert MongoReplicaSetClient.new
|
315
|
+
end
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
def test_ipv6_with_different_formats
|
320
|
+
@client = MongoReplicaSetClient.new(@rs.repl_set_seeds)
|
321
|
+
with_ipv6_enabled(@client) do
|
322
|
+
uri = "mongodb://[::1]:#{@rs.replicas[0].port},localhost:#{@rs.replicas[1].port}"
|
323
|
+
with_preserved_env_uri(uri) do
|
324
|
+
assert MongoReplicaSetClient.new
|
325
|
+
end
|
326
|
+
end
|
265
327
|
end
|
266
328
|
|
267
329
|
def test_find_and_modify_with_secondary_read_preference
|
268
|
-
@client = MongoReplicaSetClient.new
|
269
|
-
collection = @client[
|
330
|
+
@client = MongoReplicaSetClient.new @rs.repl_set_seeds
|
331
|
+
collection = @client[TEST_DB].collection('test', :read => :secondary)
|
270
332
|
collection << { :a => 1, :processed => false}
|
271
333
|
|
272
334
|
collection.find_and_modify(
|