mongo 1.10.2 → 1.11.1
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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/README.md +43 -9
- data/VERSION +1 -1
- data/lib/mongo.rb +1 -0
- data/lib/mongo/collection.rb +36 -21
- data/lib/mongo/connection/pool.rb +14 -22
- data/lib/mongo/cursor.rb +13 -0
- data/lib/mongo/db.rb +18 -13
- data/lib/mongo/functional.rb +0 -2
- data/lib/mongo/functional/authentication.rb +35 -25
- data/lib/mongo/legacy.rb +4 -4
- data/mongo.gemspec +0 -5
- data/test/functional/authentication_test.rb +3 -2
- data/test/functional/bulk_write_collection_view_test.rb +9 -14
- data/test/functional/client_test.rb +42 -43
- data/test/functional/collection_test.rb +1073 -995
- data/test/functional/collection_writer_test.rb +1 -1
- data/test/functional/cursor_fail_test.rb +3 -9
- data/test/functional/cursor_message_test.rb +14 -15
- data/test/functional/cursor_test.rb +224 -166
- data/test/functional/db_api_test.rb +262 -261
- data/test/functional/db_connection_test.rb +1 -3
- data/test/functional/db_test.rb +116 -115
- data/test/functional/grid_file_system_test.rb +108 -108
- data/test/functional/pool_test.rb +73 -0
- data/test/functional/timeout_test.rb +2 -0
- data/test/helpers/test_unit.rb +146 -11
- data/test/replica_set/authentication_test.rb +4 -2
- data/test/replica_set/basic_test.rb +5 -13
- data/test/replica_set/client_test.rb +8 -6
- data/test/replica_set/complex_connect_test.rb +3 -0
- data/test/replica_set/count_test.rb +2 -0
- data/test/replica_set/cursor_test.rb +5 -0
- data/test/replica_set/insert_test.rb +1 -1
- data/test/replica_set/max_values_test.rb +1 -1
- data/test/replica_set/pinning_test.rb +1 -1
- data/test/replica_set/query_test.rb +1 -1
- data/test/replica_set/read_preference_test.rb +7 -1
- data/test/replica_set/refresh_test.rb +11 -8
- data/test/replica_set/replication_ack_test.rb +2 -1
- data/test/sharded_cluster/basic_test.rb +17 -11
- data/test/shared/authentication/basic_auth_shared.rb +59 -98
- data/test/shared/authentication/bulk_api_auth_shared.rb +11 -21
- data/test/shared/authentication/gssapi_shared.rb +28 -21
- data/test/test_helper.rb +5 -0
- data/test/tools/mongo_config.rb +96 -11
- metadata +4 -5
- metadata.gz.sig +0 -0
- data/lib/mongo/functional/sasl_java.rb +0 -48
@@ -59,4 +59,77 @@ class PoolTest < Test::Unit::TestCase
|
|
59
59
|
end
|
60
60
|
threads.each(&:join)
|
61
61
|
end
|
62
|
+
|
63
|
+
def test_auth_network_error
|
64
|
+
# Make sure there's no semaphore leak if we get a network error
|
65
|
+
# when authenticating a new socket with cached credentials.
|
66
|
+
|
67
|
+
# Get a client with one socket so we detect if it's leaked.
|
68
|
+
client = MongoClient.new(TEST_HOST, TEST_PORT, :pool_size => 1, :pool_timeout => 1)
|
69
|
+
assert_equal 1, client.pool_size
|
70
|
+
|
71
|
+
# Set up the client with a pool
|
72
|
+
client[TEST_DB].command(:ping => 1)
|
73
|
+
|
74
|
+
# Close the one socket in the pool
|
75
|
+
pool = client.primary_pool
|
76
|
+
socket = pool.instance_variable_get(:@sockets).first
|
77
|
+
socket.close
|
78
|
+
|
79
|
+
# Simulate an authenticate() call on a different socket.
|
80
|
+
# Cache the creds on the client.
|
81
|
+
creds = {
|
82
|
+
:db_name => TEST_DB,
|
83
|
+
:username => TEST_USER,
|
84
|
+
:password => TEST_USER_PWD,
|
85
|
+
:source => TEST_DB,
|
86
|
+
:mechanism => Mongo::Authentication::DEFAULT_MECHANISM,
|
87
|
+
:extra => {}
|
88
|
+
}
|
89
|
+
client.auths << creds
|
90
|
+
|
91
|
+
# The client authenticates its socket with the
|
92
|
+
# new credential, but gets a socket.error.
|
93
|
+
client[TEST_DB]['ruby-test'].find_one
|
94
|
+
|
95
|
+
# # No semaphore leak, the pool is allowed to make a new socket.
|
96
|
+
assert_equal 1, pool.instance_variable_get(:@sockets).size
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_socket_cleanup
|
100
|
+
# Get a client with one socket so we detect if it's leaked.
|
101
|
+
client = MongoClient.new(TEST_HOST, TEST_PORT, :pool_size => 1, :pool_timeout => 1)
|
102
|
+
assert_equal 1, client.pool_size
|
103
|
+
|
104
|
+
# Set up the client with a pool
|
105
|
+
client[TEST_DB].command(:ping => 1)
|
106
|
+
|
107
|
+
# Simulate an authenticate() call on a different socket.
|
108
|
+
# Cache the creds on the client.
|
109
|
+
creds = {
|
110
|
+
:db_name => TEST_DB,
|
111
|
+
:username => TEST_USER,
|
112
|
+
:password => TEST_USER_PWD,
|
113
|
+
:source => TEST_DB,
|
114
|
+
:mechanism => Mongo::Authentication::DEFAULT_MECHANISM,
|
115
|
+
:extra => {}
|
116
|
+
}
|
117
|
+
client.auths << creds
|
118
|
+
|
119
|
+
# Mock the socket to raise a ConnectionFailure when applying auths
|
120
|
+
pool = client.primary_pool
|
121
|
+
socket = pool.instance_variable_get(:@sockets).first
|
122
|
+
socket.expects(:send).raises(ConnectionFailure)
|
123
|
+
|
124
|
+
# Checkout a socket from the pool to force it to get a new socket
|
125
|
+
pool.checkout
|
126
|
+
new_socket = pool.instance_variable_get(:@sockets).first
|
127
|
+
|
128
|
+
# Make sure the pool is cleaned up properly
|
129
|
+
assert_not_equal socket, new_socket
|
130
|
+
assert_equal 1, pool.instance_variable_get(:@sockets).size
|
131
|
+
assert_equal 1, pool.instance_variable_get(:@thread_ids_to_sockets).size
|
132
|
+
assert !pool.instance_variable_get(:@checked_out).include?(socket)
|
133
|
+
assert !pool.instance_variable_get(:@sockets).include?(socket)
|
134
|
+
end
|
62
135
|
end
|
@@ -17,6 +17,7 @@ require 'test_helper'
|
|
17
17
|
class TimeoutTest < Test::Unit::TestCase
|
18
18
|
|
19
19
|
def test_op_timeout
|
20
|
+
grant_admin_user_eval_role(standard_connection)
|
20
21
|
connection = standard_connection(:op_timeout => 0.5)
|
21
22
|
|
22
23
|
admin = connection.db('admin')
|
@@ -36,6 +37,7 @@ class TimeoutTest < Test::Unit::TestCase
|
|
36
37
|
client = standard_connection
|
37
38
|
db = client[TEST_DB]
|
38
39
|
coll = db['timeout-tests']
|
40
|
+
grant_admin_user_eval_role(client)
|
39
41
|
|
40
42
|
# prepare the database
|
41
43
|
coll.drop
|
data/test/helpers/test_unit.rb
CHANGED
@@ -12,10 +12,9 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
TEST_BASE = Test::Unit::TestCase
|
15
|
+
TEST_HOST = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost' unless defined? TEST_HOST
|
16
|
+
TEST_DATA = File.join(File.dirname(__FILE__), 'fixtures/data')
|
17
|
+
TEST_BASE = Test::Unit::TestCase
|
19
18
|
|
20
19
|
unless defined? TEST_PORT
|
21
20
|
TEST_PORT = if ENV['MONGO_RUBY_DRIVER_PORT']
|
@@ -59,6 +58,11 @@ class Test::Unit::TestCase
|
|
59
58
|
|
60
59
|
cluster_instance.start
|
61
60
|
instance_variable_set("@#{kind}", cluster_instance)
|
61
|
+
|
62
|
+
uri = "mongodb://#{TEST_USER}:#{TEST_USER_PWD}@" +
|
63
|
+
"#{cluster_instance.members_uri}"
|
64
|
+
uri += "?replicaset=#{@rs.repl_set_name}" if cluster_instance.replica_set?
|
65
|
+
instance_variable_set("@uri", uri)
|
62
66
|
end
|
63
67
|
|
64
68
|
# Generic helper to rescue and retry from a connection failure.
|
@@ -86,9 +90,15 @@ class Test::Unit::TestCase
|
|
86
90
|
# @return [MongoClient] The client instance.
|
87
91
|
def self.standard_connection(options={}, legacy=false)
|
88
92
|
if legacy
|
89
|
-
|
93
|
+
silently do
|
94
|
+
# We have to create the Connection object directly here instead of using TEST_URI
|
95
|
+
# because Connection#from_uri ends up creating a MongoClient object.
|
96
|
+
conn = Connection.new(TEST_HOST, TEST_PORT, options)
|
97
|
+
conn[TEST_DB].authenticate(TEST_USER, TEST_USER_PWD)
|
98
|
+
conn
|
99
|
+
end
|
90
100
|
else
|
91
|
-
MongoClient.
|
101
|
+
MongoClient.from_uri(TEST_URI, options)
|
92
102
|
end
|
93
103
|
end
|
94
104
|
|
@@ -218,6 +228,7 @@ class Test::Unit::TestCase
|
|
218
228
|
end
|
219
229
|
|
220
230
|
def with_forced_timeout(client, &block)
|
231
|
+
authenticate_client(client)
|
221
232
|
cmd_line_args = client['admin'].command({ :getCmdLineOpts => 1 })['argv']
|
222
233
|
if cmd_line_args.include?('enableTestCommands=1') && client.server_version >= "2.5.3"
|
223
234
|
begin
|
@@ -233,12 +244,8 @@ class Test::Unit::TestCase
|
|
233
244
|
end
|
234
245
|
end
|
235
246
|
|
236
|
-
def with_auth(client, &block)
|
237
|
-
cmd_line_args = client['admin'].command({ :getCmdLineOpts => 1 })['parsed']
|
238
|
-
yield if cmd_line_args.include?('auth')
|
239
|
-
end
|
240
|
-
|
241
247
|
def with_default_journaling(client, &block)
|
248
|
+
authenticate_client(client)
|
242
249
|
cmd_line_args = client['admin'].command({ :getCmdLineOpts => 1 })['parsed']
|
243
250
|
unless client.server_version < "2.0" || cmd_line_args.include?('nojournal')
|
244
251
|
yield
|
@@ -252,6 +259,7 @@ class Test::Unit::TestCase
|
|
252
259
|
end
|
253
260
|
|
254
261
|
def with_no_journaling(client, &block)
|
262
|
+
authenticate_client(client)
|
255
263
|
cmd_line_args = client['admin'].command({ :getCmdLineOpts => 1 })['parsed']
|
256
264
|
unless client.server_version < "2.0" || !cmd_line_args.include?('nojournal')
|
257
265
|
yield
|
@@ -259,6 +267,7 @@ class Test::Unit::TestCase
|
|
259
267
|
end
|
260
268
|
|
261
269
|
def with_ipv6_enabled(client, &block)
|
270
|
+
authenticate_client(client)
|
262
271
|
cmd_line_args = client['admin'].command({ :getCmdLineOpts => 1 })['parsed']
|
263
272
|
if cmd_line_args.include?('ipv6')
|
264
273
|
yield
|
@@ -310,14 +319,140 @@ class Test::Unit::TestCase
|
|
310
319
|
def subject_to_server_4754?(client)
|
311
320
|
# Until SERVER-4754 is resolved, profiling info is not collected
|
312
321
|
# when mongod is started with --auth in versions < 2.2
|
322
|
+
authenticate_client(client)
|
313
323
|
cmd_line_args = client['admin'].command({ :getCmdLineOpts => 1 })['parsed']
|
314
324
|
client.server_version < '2.2' && cmd_line_args.include?('auth')
|
315
325
|
end
|
326
|
+
|
327
|
+
# When testing under narrowed localhost exception, the admin user must have
|
328
|
+
# special permissions to run the db_eval command.
|
329
|
+
def grant_admin_user_eval_role(client)
|
330
|
+
if auth_enabled?(client) && client.server_version >= "2.6"
|
331
|
+
# we need to have anyAction on anyResource to run db_eval()
|
332
|
+
admin = client['admin']
|
333
|
+
any_priv = BSON::OrderedHash.new
|
334
|
+
any_priv[:resource] = { :anyResource => true }
|
335
|
+
any_priv[:actions] = ['anyAction']
|
336
|
+
|
337
|
+
create_role = BSON::OrderedHash.new
|
338
|
+
create_role[:createRole] = 'db_eval'
|
339
|
+
create_role[:privileges] = [any_priv]
|
340
|
+
create_role[:roles] = []
|
341
|
+
|
342
|
+
begin
|
343
|
+
admin.command(create_role)
|
344
|
+
rescue Mongo::OperationFailure => ex
|
345
|
+
# role already exists
|
346
|
+
end
|
347
|
+
|
348
|
+
grant_role = BSON::OrderedHash.new
|
349
|
+
grant_role[:grantRolesToUser] = TEST_USER
|
350
|
+
grant_role[:roles] = ['db_eval']
|
351
|
+
admin.command(grant_role)
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
355
|
+
# Return true if auth is enabled, false otherwise.
|
356
|
+
def auth_enabled?(client)
|
357
|
+
begin
|
358
|
+
cmd_line_args = client['admin'].command({ :getCmdLineOpts => 1 })['parsed']
|
359
|
+
return true if cmd_line_args.include?('auth') || cmd_line_args.include?('keyFile')
|
360
|
+
if security = cmd_line_args["security"]
|
361
|
+
return true if security["authorization"] == "enabled"
|
362
|
+
end
|
363
|
+
rescue OperationFailure => ex
|
364
|
+
# under narrowed localhost exception in > 2.7.1, getCmdLineOpts is not allowed
|
365
|
+
# unless you're authenticated.
|
366
|
+
return true if ex.message.include?("authorized") ||
|
367
|
+
(client.server_version >= "2.7.1" &&
|
368
|
+
ex.error_code == Mongo::ErrorCode::UNAUTHORIZED)
|
369
|
+
end
|
370
|
+
end
|
371
|
+
|
372
|
+
def with_auth(client, &block)
|
373
|
+
yield if auth_enabled?(client)
|
374
|
+
end
|
375
|
+
|
376
|
+
def authenticate_client(client)
|
377
|
+
client[TEST_DB].authenticate(TEST_USER, TEST_USER_PWD) unless client.auths.any? {|a| a[:source] == TEST_DB}
|
378
|
+
client
|
379
|
+
end
|
380
|
+
|
381
|
+
def self.ensure_admin_user
|
382
|
+
10.times do
|
383
|
+
begin
|
384
|
+
client = Mongo::MongoClient.new(TEST_HOST, TEST_PORT)
|
385
|
+
db = client[TEST_DB]
|
386
|
+
begin
|
387
|
+
db.authenticate(TEST_USER, TEST_USER_PWD)
|
388
|
+
rescue Mongo::AuthenticationError => ex
|
389
|
+
roles = [ 'dbAdminAnyDatabase',
|
390
|
+
'userAdminAnyDatabase',
|
391
|
+
'readWriteAnyDatabase',
|
392
|
+
'clusterAdmin' ]
|
393
|
+
db.add_user(TEST_USER, TEST_USER_PWD, nil, :roles => roles)
|
394
|
+
end
|
395
|
+
TEST_BASE.class_eval { class_variable_set("@@connected_single_mongod", true) }
|
396
|
+
break
|
397
|
+
rescue Mongo::ConnectionFailure
|
398
|
+
# mongod not available yet, wait a second and try again
|
399
|
+
sleep(1)
|
400
|
+
end
|
401
|
+
#puts "Not connected to a MongoD" unless client.connected?
|
402
|
+
end
|
403
|
+
end
|
404
|
+
|
405
|
+
def self.cleanup_users_and_dbs
|
406
|
+
not_cluster = TEST_BASE.class_eval { class_variables }.none? { |v| v =~ /@@cluster_/ }
|
407
|
+
|
408
|
+
if @@connected_single_mongod && not_cluster
|
409
|
+
client = Mongo::MongoClient.from_uri(TEST_URI)
|
410
|
+
db = client[TEST_DB]
|
411
|
+
begin
|
412
|
+
begin
|
413
|
+
db.authenticate(TEST_USER, TEST_USER_PWD)
|
414
|
+
|
415
|
+
rescue Mongo::ConnectionFailure, Mongo::MongoArgumentError
|
416
|
+
rescue Mongo::AuthenticationError
|
417
|
+
Test::Unit::TestCase.ensure_admin_user
|
418
|
+
db.authenticate(TEST_USER, TEST_USER_PWD)
|
419
|
+
end
|
420
|
+
|
421
|
+
client.database_names.each do |db_name|
|
422
|
+
if db_name =~ /^ruby_test*/
|
423
|
+
puts "[CLEAN-UP] Dropping '#{db_name}'..."
|
424
|
+
client.drop_database(db_name)
|
425
|
+
end
|
426
|
+
end
|
427
|
+
|
428
|
+
if client.server_version < '2.5'
|
429
|
+
db['system.users'].remove
|
430
|
+
else
|
431
|
+
db.command(:dropAllUsersFromDatabase => 1)
|
432
|
+
end
|
433
|
+
|
434
|
+
rescue Mongo::ConnectionFailure
|
435
|
+
# Nothing we can do about the mongod not being available
|
436
|
+
end
|
437
|
+
end
|
438
|
+
end
|
439
|
+
end
|
440
|
+
|
441
|
+
|
442
|
+
Test::Unit.at_start do
|
443
|
+
TEST_DB = ENV['TEST_DB'] || 'admin'
|
444
|
+
TEST_USER = ENV['TEST_USER'] || 'admin_user'
|
445
|
+
TEST_USER_PWD = ENV['TEST_USER_PWD'] || 'password'
|
446
|
+
TEST_URI = ENV['TEST_URI'] ||
|
447
|
+
"mongodb://#{TEST_USER}:#{TEST_USER_PWD}@#{TEST_HOST}:#{TEST_PORT}/#{TEST_DB}"
|
448
|
+
TEST_BASE.class_eval { class_variable_set("@@connected_single_mongod", false) }
|
449
|
+
Test::Unit::TestCase.ensure_admin_user
|
316
450
|
end
|
317
451
|
|
318
452
|
# Before and after hooks for the entire test run
|
319
453
|
# handles mop up after the cluster manager is done.
|
320
454
|
Test::Unit.at_exit do
|
455
|
+
Test::Unit::TestCase.cleanup_users_and_dbs
|
321
456
|
TEST_BASE.class_eval { class_variables }.select { |v| v =~ /@@cluster_/ }.each do |cluster|
|
322
457
|
TEST_BASE.class_eval { class_variable_get(cluster) }.stop
|
323
458
|
end
|
@@ -20,6 +20,7 @@ require 'shared/authentication/gssapi_shared'
|
|
20
20
|
|
21
21
|
class ReplicaSetAuthenticationTest < Test::Unit::TestCase
|
22
22
|
include Mongo
|
23
|
+
|
23
24
|
include BasicAuthTests
|
24
25
|
include SASLPlainTests
|
25
26
|
include BulkAPIAuthTests
|
@@ -27,9 +28,10 @@ class ReplicaSetAuthenticationTest < Test::Unit::TestCase
|
|
27
28
|
|
28
29
|
def setup
|
29
30
|
ensure_cluster(:rs)
|
30
|
-
@client = MongoReplicaSetClient.
|
31
|
+
@client = MongoReplicaSetClient.from_uri(@uri)
|
32
|
+
@admin = @client['admin']
|
31
33
|
@version = @client.server_version
|
32
|
-
@db = @client[
|
34
|
+
@db = @client['ruby-test']
|
33
35
|
@host_info = @rs.repl_set_seeds.join(',')
|
34
36
|
end
|
35
37
|
end
|
@@ -73,9 +73,7 @@ class ReplicaSetBasicTest < Test::Unit::TestCase
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def test_accessors
|
76
|
-
|
77
|
-
args = {:name => @rs.repl_set_name}
|
78
|
-
client = MongoReplicaSetClient.new(seeds, args)
|
76
|
+
client = MongoReplicaSetClient.from_uri(@uri)
|
79
77
|
assert_equal @rs.primary_name, [client.host, client.port].join(':')
|
80
78
|
assert_equal client.host, client.primary_pool.host
|
81
79
|
assert_equal client.port, client.primary_pool.port
|
@@ -89,9 +87,7 @@ class ReplicaSetBasicTest < Test::Unit::TestCase
|
|
89
87
|
end
|
90
88
|
|
91
89
|
def test_write_commands_and_operations
|
92
|
-
|
93
|
-
args = {:name => @rs.repl_set_name}
|
94
|
-
@client = MongoReplicaSetClient.new(seeds, args)
|
90
|
+
@client = MongoReplicaSetClient.from_uri(@uri)
|
95
91
|
@coll = @client[TEST_DB]['test-write-commands-and-operations']
|
96
92
|
with_write_commands_and_operations(@client) do
|
97
93
|
@coll.remove
|
@@ -101,7 +97,7 @@ class ReplicaSetBasicTest < Test::Unit::TestCase
|
|
101
97
|
end
|
102
98
|
|
103
99
|
def test_wnote_does_not_raise_exception_with_err_nil
|
104
|
-
@client = MongoReplicaSetClient.
|
100
|
+
@client = MongoReplicaSetClient.from_uri(@uri)
|
105
101
|
if @client.server_version < '2.5.5'
|
106
102
|
@coll = @client[TEST_DB]['test-wnote']
|
107
103
|
begin
|
@@ -117,9 +113,7 @@ class ReplicaSetBasicTest < Test::Unit::TestCase
|
|
117
113
|
context "Socket pools" do
|
118
114
|
context "checking out writers" do
|
119
115
|
setup do
|
120
|
-
|
121
|
-
args = {:name => @rs.repl_set_name}
|
122
|
-
@client = MongoReplicaSetClient.new(seeds, args)
|
116
|
+
@client = MongoReplicaSetClient.from_uri(@uri)
|
123
117
|
@coll = @client[TEST_DB]['test-connection-exceptions']
|
124
118
|
end
|
125
119
|
|
@@ -168,9 +162,7 @@ class ReplicaSetBasicTest < Test::Unit::TestCase
|
|
168
162
|
|
169
163
|
context "checking out readers" do
|
170
164
|
setup do
|
171
|
-
|
172
|
-
args = {:name => @rs.repl_set_name}
|
173
|
-
@client = MongoReplicaSetClient.new(seeds, args)
|
165
|
+
@client = MongoReplicaSetClient.from_uri(@uri)
|
174
166
|
@coll = @client[TEST_DB]['test-connection-exceptions']
|
175
167
|
end
|
176
168
|
|
@@ -26,7 +26,7 @@ class ReplicaSetClientTest < Test::Unit::TestCase
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_reconnection
|
29
|
-
@client = MongoReplicaSetClient.
|
29
|
+
@client = MongoReplicaSetClient.from_uri(@uri)
|
30
30
|
assert @client.connected?
|
31
31
|
|
32
32
|
manager = @client.local_manager
|
@@ -76,11 +76,12 @@ class ReplicaSetClientTest < Test::Unit::TestCase
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def test_connect_with_primary_stepped_down
|
79
|
-
@client = MongoReplicaSetClient.
|
79
|
+
@client = MongoReplicaSetClient.from_uri(@uri)
|
80
80
|
@client[TEST_DB]['bar'].save({:a => 1}, {:w => 3})
|
81
81
|
assert @client[TEST_DB]['bar'].find_one
|
82
82
|
|
83
83
|
primary = Mongo::MongoClient.new(*@client.primary)
|
84
|
+
authenticate_client(primary)
|
84
85
|
assert_raise Mongo::ConnectionFailure do
|
85
86
|
perform_step_down(primary)
|
86
87
|
end
|
@@ -93,7 +94,7 @@ class ReplicaSetClientTest < Test::Unit::TestCase
|
|
93
94
|
end
|
94
95
|
|
95
96
|
def test_connect_with_primary_killed
|
96
|
-
@client = MongoReplicaSetClient.
|
97
|
+
@client = MongoReplicaSetClient.from_uri(@uri)
|
97
98
|
assert @client.connected?
|
98
99
|
@client[TEST_DB]['bar'].save({:a => 1}, {:w => 3})
|
99
100
|
assert @client[TEST_DB]['bar'].find_one
|
@@ -109,10 +110,11 @@ class ReplicaSetClientTest < Test::Unit::TestCase
|
|
109
110
|
end
|
110
111
|
|
111
112
|
def test_save_with_primary_stepped_down
|
112
|
-
@client = MongoReplicaSetClient.
|
113
|
+
@client = MongoReplicaSetClient.from_uri(@uri)
|
113
114
|
assert @client.connected?
|
114
115
|
|
115
116
|
primary = Mongo::MongoClient.new(*@client.primary)
|
117
|
+
authenticate_client(primary)
|
116
118
|
assert_raise Mongo::ConnectionFailure do
|
117
119
|
perform_step_down(primary)
|
118
120
|
end
|
@@ -124,7 +126,7 @@ class ReplicaSetClientTest < Test::Unit::TestCase
|
|
124
126
|
end
|
125
127
|
|
126
128
|
# def test_connect_with_first_node_removed
|
127
|
-
# @client = MongoReplicaSetClient.
|
129
|
+
# @client = MongoReplicaSetClient.from_uri(@uri)
|
128
130
|
# @client[TEST_DB]['bar'].save({:a => 1}, {:w => 3})
|
129
131
|
|
130
132
|
# # Make sure everyone's views of optimes are caught up
|
@@ -331,7 +333,7 @@ class ReplicaSetClientTest < Test::Unit::TestCase
|
|
331
333
|
end
|
332
334
|
|
333
335
|
def test_find_and_modify_with_secondary_read_preference
|
334
|
-
@client = MongoReplicaSetClient.
|
336
|
+
@client = MongoReplicaSetClient.from_uri(@uri)
|
335
337
|
collection = @client[TEST_DB].collection('test', :read => :secondary)
|
336
338
|
id = BSON::ObjectId.new
|
337
339
|
collection << { :a => id, :processed => false }
|
@@ -27,6 +27,7 @@ class ComplexConnectTest < Test::Unit::TestCase
|
|
27
27
|
def test_complex_connect
|
28
28
|
host = @rs.servers.first.host
|
29
29
|
primary = MongoClient.new(host, @rs.primary.port)
|
30
|
+
authenticate_client(primary)
|
30
31
|
|
31
32
|
@client = MongoReplicaSetClient.new([
|
32
33
|
@rs.servers[2].host_port,
|
@@ -34,6 +35,7 @@ class ComplexConnectTest < Test::Unit::TestCase
|
|
34
35
|
@rs.servers[0].host_port
|
35
36
|
])
|
36
37
|
|
38
|
+
authenticate_client(@client)
|
37
39
|
version = @client.server_version
|
38
40
|
|
39
41
|
@client[TEST_DB]['complext-connect-test'].insert({:a => 1})
|
@@ -70,6 +72,7 @@ class ComplexConnectTest < Test::Unit::TestCase
|
|
70
72
|
end
|
71
73
|
|
72
74
|
primary = MongoClient.new(host, @rs.primary.port)
|
75
|
+
authenticate_client(primary)
|
73
76
|
assert_raise ConnectionFailure do
|
74
77
|
primary['admin'].command({:replSetReconfig => old_config})
|
75
78
|
end
|