mongo 2.2.7 → 2.3.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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/LICENSE +1 -1
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/lib/mongo.rb +1 -1
- data/lib/mongo/address.rb +1 -1
- data/lib/mongo/address/ipv4.rb +1 -1
- data/lib/mongo/address/ipv6.rb +1 -1
- data/lib/mongo/address/unix.rb +1 -1
- data/lib/mongo/auth.rb +1 -1
- data/lib/mongo/auth/cr.rb +1 -1
- data/lib/mongo/auth/ldap.rb +1 -1
- data/lib/mongo/auth/roles.rb +1 -1
- data/lib/mongo/auth/user.rb +1 -1
- data/lib/mongo/auth/user/view.rb +5 -5
- data/lib/mongo/auth/x509.rb +1 -1
- data/lib/mongo/bson.rb +1 -1
- data/lib/mongo/bulk_write.rb +4 -4
- data/lib/mongo/bulk_write/combineable.rb +1 -1
- data/lib/mongo/bulk_write/ordered_combiner.rb +1 -1
- data/lib/mongo/bulk_write/result.rb +1 -1
- data/lib/mongo/bulk_write/result_combiner.rb +1 -1
- data/lib/mongo/bulk_write/transformable.rb +1 -1
- data/lib/mongo/bulk_write/unordered_combiner.rb +1 -1
- data/lib/mongo/bulk_write/validatable.rb +1 -1
- data/lib/mongo/client.rb +2 -2
- data/lib/mongo/cluster.rb +15 -3
- data/lib/mongo/cluster/cursor_reaper.rb +174 -0
- data/lib/mongo/cluster/topology.rb +1 -1
- data/lib/mongo/cluster/topology/replica_set.rb +1 -1
- data/lib/mongo/cluster/topology/sharded.rb +1 -1
- data/lib/mongo/cluster/topology/single.rb +1 -1
- data/lib/mongo/cluster/topology/unknown.rb +1 -1
- data/lib/mongo/collection.rb +5 -4
- data/lib/mongo/collection/view.rb +4 -4
- data/lib/mongo/collection/view/aggregation.rb +2 -2
- data/lib/mongo/collection/view/builder.rb +1 -1
- data/lib/mongo/collection/view/builder/aggregation.rb +1 -1
- data/lib/mongo/collection/view/builder/find_command.rb +1 -1
- data/lib/mongo/collection/view/builder/flags.rb +1 -1
- data/lib/mongo/collection/view/builder/map_reduce.rb +1 -1
- data/lib/mongo/collection/view/builder/modifiers.rb +1 -1
- data/lib/mongo/collection/view/builder/op_query.rb +1 -1
- data/lib/mongo/collection/view/explainable.rb +1 -1
- data/lib/mongo/collection/view/immutable.rb +1 -1
- data/lib/mongo/collection/view/iterable.rb +2 -2
- data/lib/mongo/collection/view/map_reduce.rb +3 -3
- data/lib/mongo/collection/view/readable.rb +23 -6
- data/lib/mongo/collection/view/writable.rb +3 -3
- data/lib/mongo/cursor.rb +50 -7
- data/lib/mongo/cursor/builder.rb +1 -1
- data/lib/mongo/cursor/builder/get_more_command.rb +1 -1
- data/lib/mongo/cursor/builder/kill_cursors_command.rb +29 -1
- data/lib/mongo/cursor/builder/op_get_more.rb +1 -1
- data/lib/mongo/cursor/builder/op_kill_cursors.rb +29 -1
- data/lib/mongo/database.rb +4 -4
- data/lib/mongo/database/view.rb +2 -2
- data/lib/mongo/dbref.rb +4 -3
- data/lib/mongo/error.rb +1 -1
- data/lib/mongo/error/bulk_write_error.rb +1 -1
- data/lib/mongo/error/closed_stream.rb +1 -1
- data/lib/mongo/error/extra_file_chunk.rb +1 -1
- data/lib/mongo/error/file_not_found.rb +1 -1
- data/lib/mongo/error/invalid_bulk_operation.rb +1 -1
- data/lib/mongo/error/invalid_bulk_operation_type.rb +1 -1
- data/lib/mongo/error/invalid_collection_name.rb +1 -1
- data/lib/mongo/error/invalid_database_name.rb +1 -1
- data/lib/mongo/error/invalid_document.rb +1 -1
- data/lib/mongo/error/invalid_file.rb +1 -1
- data/lib/mongo/error/invalid_file_revision.rb +1 -1
- data/lib/mongo/error/invalid_nonce.rb +1 -1
- data/lib/mongo/error/invalid_replacement_document.rb +1 -1
- data/lib/mongo/error/invalid_server_preference.rb +1 -1
- data/lib/mongo/error/invalid_signature.rb +1 -1
- data/lib/mongo/error/invalid_update_document.rb +1 -1
- data/lib/mongo/error/invalid_uri.rb +1 -1
- data/lib/mongo/error/invalid_write_concern.rb +1 -1
- data/lib/mongo/error/max_bson_size.rb +1 -1
- data/lib/mongo/error/max_message_size.rb +1 -1
- data/lib/mongo/error/missing_file_chunk.rb +1 -1
- data/lib/mongo/error/multi_index_drop.rb +1 -1
- data/lib/mongo/error/need_primary_server.rb +1 -1
- data/lib/mongo/error/no_server_available.rb +4 -2
- data/lib/mongo/error/operation_failure.rb +1 -1
- data/lib/mongo/error/parser.rb +1 -1
- data/lib/mongo/error/socket_error.rb +1 -1
- data/lib/mongo/error/socket_timeout_error.rb +1 -1
- data/lib/mongo/error/unchangeable_collection_option.rb +1 -1
- data/lib/mongo/error/unexpected_chunk_length.rb +1 -1
- data/lib/mongo/error/unexpected_response.rb +1 -1
- data/lib/mongo/error/unsupported_features.rb +1 -1
- data/lib/mongo/event.rb +1 -1
- data/lib/mongo/event/description_changed.rb +1 -1
- data/lib/mongo/event/publisher.rb +1 -1
- data/lib/mongo/event/subscriber.rb +1 -1
- data/lib/mongo/grid.rb +1 -1
- data/lib/mongo/grid/file.rb +6 -2
- data/lib/mongo/grid/file/chunk.rb +6 -4
- data/lib/mongo/grid/file/info.rb +7 -3
- data/lib/mongo/grid/fs_bucket.rb +12 -6
- data/lib/mongo/grid/stream.rb +1 -1
- data/lib/mongo/grid/stream/read.rb +2 -4
- data/lib/mongo/grid/stream/write.rb +4 -3
- data/lib/mongo/index.rb +1 -1
- data/lib/mongo/index/view.rb +5 -4
- data/lib/mongo/loggable.rb +1 -1
- data/lib/mongo/logger.rb +1 -1
- data/lib/mongo/monitoring.rb +1 -1
- data/lib/mongo/operation.rb +1 -1
- data/lib/mongo/operation/commands.rb +1 -1
- data/lib/mongo/operation/commands/aggregate.rb +7 -7
- data/lib/mongo/operation/commands/aggregate/result.rb +1 -1
- data/lib/mongo/operation/commands/collections_info.rb +10 -9
- data/lib/mongo/operation/commands/collections_info/result.rb +1 -1
- data/lib/mongo/operation/commands/command.rb +1 -1
- data/lib/mongo/operation/commands/indexes.rb +12 -11
- data/lib/mongo/operation/commands/list_collections.rb +1 -1
- data/lib/mongo/operation/commands/list_collections/result.rb +1 -1
- data/lib/mongo/operation/commands/list_indexes.rb +1 -1
- data/lib/mongo/operation/commands/list_indexes/result.rb +1 -1
- data/lib/mongo/operation/commands/map_reduce.rb +1 -1
- data/lib/mongo/operation/commands/map_reduce/result.rb +1 -1
- data/lib/mongo/operation/commands/user_query.rb +11 -10
- data/lib/mongo/operation/commands/users_info.rb +2 -2
- data/lib/mongo/operation/commands/users_info/result.rb +1 -1
- data/lib/mongo/operation/executable.rb +8 -7
- data/lib/mongo/operation/kill_cursors.rb +2 -2
- data/lib/mongo/operation/limited.rb +1 -1
- data/lib/mongo/operation/read.rb +1 -1
- data/lib/mongo/operation/read/get_more.rb +2 -2
- data/lib/mongo/operation/read/query.rb +1 -1
- data/lib/mongo/operation/read/query/result.rb +1 -1
- data/lib/mongo/operation/read_preference.rb +10 -10
- data/lib/mongo/operation/result.rb +1 -1
- data/lib/mongo/operation/specifiable.rb +2 -2
- data/lib/mongo/operation/write.rb +1 -1
- data/lib/mongo/operation/write/bulk.rb +1 -1
- data/lib/mongo/operation/write/bulk/bulkable.rb +9 -9
- data/lib/mongo/operation/write/bulk/delete.rb +3 -3
- data/lib/mongo/operation/write/bulk/delete/result.rb +1 -1
- data/lib/mongo/operation/write/bulk/insert.rb +5 -5
- data/lib/mongo/operation/write/bulk/insert/result.rb +1 -1
- data/lib/mongo/operation/write/bulk/legacy_mergable.rb +1 -1
- data/lib/mongo/operation/write/bulk/mergable.rb +1 -1
- data/lib/mongo/operation/write/bulk/update.rb +3 -3
- data/lib/mongo/operation/write/bulk/update/result.rb +1 -1
- data/lib/mongo/operation/write/command.rb +1 -1
- data/lib/mongo/operation/write/command/create_index.rb +1 -1
- data/lib/mongo/operation/write/command/create_user.rb +1 -1
- data/lib/mongo/operation/write/command/delete.rb +1 -1
- data/lib/mongo/operation/write/command/drop_index.rb +1 -1
- data/lib/mongo/operation/write/command/insert.rb +11 -1
- data/lib/mongo/operation/write/command/remove_user.rb +1 -1
- data/lib/mongo/operation/write/command/update.rb +1 -1
- data/lib/mongo/operation/write/command/update_user.rb +1 -1
- data/lib/mongo/operation/write/command/writable.rb +7 -6
- data/lib/mongo/operation/write/create_index.rb +1 -1
- data/lib/mongo/operation/write/create_user.rb +1 -1
- data/lib/mongo/operation/write/delete.rb +1 -1
- data/lib/mongo/operation/write/delete/result.rb +1 -1
- data/lib/mongo/operation/write/drop_index.rb +5 -5
- data/lib/mongo/operation/write/gle.rb +3 -3
- data/lib/mongo/operation/write/idable.rb +1 -1
- data/lib/mongo/operation/write/insert.rb +5 -5
- data/lib/mongo/operation/write/insert/result.rb +1 -1
- data/lib/mongo/operation/write/remove_user.rb +1 -1
- data/lib/mongo/operation/write/update.rb +1 -1
- data/lib/mongo/operation/write/update/result.rb +1 -1
- data/lib/mongo/operation/write/update_user.rb +1 -1
- data/lib/mongo/operation/write/write_command_enabled.rb +10 -9
- data/lib/mongo/protocol/bit_vector.rb +2 -2
- data/lib/mongo/protocol/delete.rb +1 -1
- data/lib/mongo/protocol/get_more.rb +1 -1
- data/lib/mongo/protocol/insert.rb +5 -1
- data/lib/mongo/protocol/kill_cursors.rb +1 -1
- data/lib/mongo/protocol/message.rb +9 -5
- data/lib/mongo/protocol/query.rb +1 -1
- data/lib/mongo/protocol/reply.rb +1 -1
- data/lib/mongo/protocol/serializers.rb +8 -8
- data/lib/mongo/protocol/update.rb +1 -1
- data/lib/mongo/server.rb +40 -3
- data/lib/mongo/server/connectable.rb +1 -1
- data/lib/mongo/server/connection.rb +4 -2
- data/lib/mongo/server/connection_pool.rb +1 -1
- data/lib/mongo/server/connection_pool/queue.rb +1 -1
- data/lib/mongo/server/context.rb +3 -1
- data/lib/mongo/server/description.rb +1 -1
- data/lib/mongo/server/description/inspector/description_changed.rb +1 -1
- data/lib/mongo/server/monitor.rb +1 -1
- data/lib/mongo/server_selector.rb +2 -1
- data/lib/mongo/server_selector/nearest.rb +1 -1
- data/lib/mongo/server_selector/primary.rb +1 -1
- data/lib/mongo/server_selector/primary_preferred.rb +1 -1
- data/lib/mongo/server_selector/secondary.rb +1 -1
- data/lib/mongo/server_selector/secondary_preferred.rb +1 -1
- data/lib/mongo/server_selector/selectable.rb +12 -7
- data/lib/mongo/socket.rb +1 -1
- data/lib/mongo/socket/ssl.rb +1 -1
- data/lib/mongo/socket/tcp.rb +1 -1
- data/lib/mongo/socket/unix.rb +1 -1
- data/lib/mongo/uri.rb +1 -1
- data/lib/mongo/version.rb +2 -2
- data/lib/mongo/write_concern/acknowledged.rb +1 -1
- data/lib/mongo/write_concern/normalizable.rb +1 -1
- data/lib/mongo/write_concern/unacknowledged.rb +1 -1
- data/mongo.gemspec +1 -1
- data/spec/mongo/client_spec.rb +2 -2
- data/spec/mongo/cluster/cursor_reaper_spec.rb +216 -0
- data/spec/mongo/cluster_spec.rb +36 -5
- data/spec/mongo/collection/view/aggregation_spec.rb +2 -2
- data/spec/mongo/collection/view/map_reduce_spec.rb +2 -2
- data/spec/mongo/collection/view/readable_spec.rb +203 -5
- data/spec/mongo/collection/view_spec.rb +10 -0
- data/spec/mongo/collection_spec.rb +64 -18
- data/spec/mongo/cursor_spec.rb +89 -0
- data/spec/mongo/database_spec.rb +79 -13
- data/spec/mongo/grid/fs_bucket_spec.rb +119 -1
- data/spec/mongo/grid/stream/write_spec.rb +63 -12
- data/spec/mongo/index/view_spec.rb +19 -0
- data/spec/mongo/operation/commands/aggregate_spec.rb +10 -7
- data/spec/mongo/operation/commands/collections_info_spec.rb +1 -1
- data/spec/mongo/operation/commands/command_spec.rb +3 -3
- data/spec/mongo/operation/commands/indexes_spec.rb +1 -1
- data/spec/mongo/operation/commands/map_reduce_spec.rb +2 -2
- data/spec/mongo/operation/kill_cursors_spec.rb +10 -19
- data/spec/mongo/operation/read/get_more_spec.rb +13 -25
- data/spec/mongo/operation/read/query_spec.rb +26 -30
- data/spec/mongo/operation/read_preference_spec.rb +11 -11
- data/spec/mongo/operation/specifiable_spec.rb +31 -0
- data/spec/mongo/operation/write/bulk/delete_spec.rb +16 -18
- data/spec/mongo/operation/write/bulk/insert_spec.rb +17 -18
- data/spec/mongo/operation/write/bulk/update_spec.rb +20 -25
- data/spec/mongo/operation/write/command/delete_spec.rb +26 -32
- data/spec/mongo/operation/write/command/insert_spec.rb +24 -31
- data/spec/mongo/operation/write/command/update_spec.rb +24 -32
- data/spec/mongo/operation/write/create_index_spec.rb +4 -4
- data/spec/mongo/operation/write/create_user_spec.rb +3 -3
- data/spec/mongo/operation/write/delete_spec.rb +51 -22
- data/spec/mongo/operation/write/drop_index_spec.rb +2 -2
- data/spec/mongo/operation/write/insert_spec.rb +42 -11
- data/spec/mongo/operation/write/remove_user_spec.rb +4 -4
- data/spec/mongo/operation/write/update_spec.rb +34 -6
- data/spec/mongo/operation/write/update_user_spec.rb +1 -1
- data/spec/mongo/server/connection_spec.rb +22 -14
- data/spec/mongo/server_selection_spec.rb +2 -2
- data/spec/mongo/server_selector/nearest_spec.rb +4 -4
- data/spec/mongo/server_selector/primary_preferred_spec.rb +4 -4
- data/spec/mongo/server_selector/primary_spec.rb +2 -2
- data/spec/mongo/server_selector/secondary_preferred_spec.rb +4 -4
- data/spec/mongo/server_selector/secondary_spec.rb +3 -3
- data/spec/mongo/server_selector_spec.rb +82 -3
- data/spec/mongo/server_spec.rb +0 -20
- data/spec/support/command_monitoring.rb +1 -1
- data/spec/support/connection_string.rb +1 -1
- data/spec/support/crud.rb +1 -1
- data/spec/support/crud/read.rb +1 -1
- data/spec/support/crud/write.rb +1 -1
- data/spec/support/gridfs.rb +1 -1
- data/spec/support/shared/server_selector.rb +3 -3
- metadata +7 -10
- metadata.gz.sig +0 -0
- data/lib/csasl/csasl.bundle +0 -0
- data/spec/mongo/operation/write/response_spec.rb +0 -85
- data/spec/support/shared/operation.rb +0 -100
@@ -113,7 +113,8 @@ describe Mongo::Server::Connection do
|
|
113
113
|
TEST_OPTIONS.merge(
|
114
114
|
:user => 'notauser',
|
115
115
|
:password => 'password',
|
116
|
-
:database => TEST_DB
|
116
|
+
:database => TEST_DB,
|
117
|
+
:heartbeat_frequency => 30)
|
117
118
|
)
|
118
119
|
end
|
119
120
|
|
@@ -130,7 +131,6 @@ describe Mongo::Server::Connection do
|
|
130
131
|
end
|
131
132
|
|
132
133
|
it 'marks the server as unknown' do
|
133
|
-
pending 'Server must be set as unknown'
|
134
134
|
expect(server).to be_unknown
|
135
135
|
end
|
136
136
|
end
|
@@ -261,11 +261,11 @@ describe Mongo::Server::Connection do
|
|
261
261
|
end
|
262
262
|
|
263
263
|
let(:query_bob) do
|
264
|
-
Mongo::Protocol::Query.new(TEST_DB, TEST_COLL, {
|
264
|
+
Mongo::Protocol::Query.new(TEST_DB, TEST_COLL, { name: 'bob' })
|
265
265
|
end
|
266
266
|
|
267
267
|
let(:query_alice) do
|
268
|
-
Mongo::Protocol::Query.new(TEST_DB, TEST_COLL, {
|
268
|
+
Mongo::Protocol::Query.new(TEST_DB, TEST_COLL, { name: 'alice' })
|
269
269
|
end
|
270
270
|
|
271
271
|
after do
|
@@ -278,14 +278,14 @@ describe Mongo::Server::Connection do
|
|
278
278
|
connection.dispatch([ insert, query_bob ])
|
279
279
|
end
|
280
280
|
|
281
|
-
it 'raises an UnexpectedResponse' do
|
281
|
+
it 'raises an UnexpectedResponse error' do
|
282
282
|
expect {
|
283
283
|
connection.dispatch([ query_alice ])
|
284
284
|
}.to raise_error(Mongo::Error::UnexpectedResponse,
|
285
285
|
/Got response for request ID \d+ but expected response for request ID \d+/)
|
286
286
|
end
|
287
287
|
|
288
|
-
it
|
288
|
+
it 'does not affect subsequent requests' do
|
289
289
|
expect {
|
290
290
|
connection.dispatch([ query_alice ])
|
291
291
|
}.to raise_error(Mongo::Error::UnexpectedResponse)
|
@@ -294,7 +294,7 @@ describe Mongo::Server::Connection do
|
|
294
294
|
end
|
295
295
|
end
|
296
296
|
|
297
|
-
context 'when a request is
|
297
|
+
context 'when a request is interrupted (Thread.kill)' do
|
298
298
|
|
299
299
|
let(:documents) do
|
300
300
|
[{ 'name' => 'bob' }, { 'name' => 'alice' }]
|
@@ -305,11 +305,11 @@ describe Mongo::Server::Connection do
|
|
305
305
|
end
|
306
306
|
|
307
307
|
let(:query_bob) do
|
308
|
-
Mongo::Protocol::Query.new(TEST_DB, TEST_COLL, {
|
308
|
+
Mongo::Protocol::Query.new(TEST_DB, TEST_COLL, { name: 'bob' })
|
309
309
|
end
|
310
310
|
|
311
311
|
let(:query_alice) do
|
312
|
-
Mongo::Protocol::Query.new(TEST_DB, TEST_COLL, {
|
312
|
+
Mongo::Protocol::Query.new(TEST_DB, TEST_COLL, { name: 'alice' })
|
313
313
|
end
|
314
314
|
|
315
315
|
before do
|
@@ -320,7 +320,7 @@ describe Mongo::Server::Connection do
|
|
320
320
|
authorized_collection.delete_many
|
321
321
|
end
|
322
322
|
|
323
|
-
it
|
323
|
+
it 'closes the socket and does not use it for subsequent requests' do
|
324
324
|
t = Thread.new {
|
325
325
|
# Kill the thread just before the reply is read
|
326
326
|
allow(Mongo::Protocol::Reply).to receive(:deserialize_header) { t.kill }
|
@@ -332,7 +332,6 @@ describe Mongo::Server::Connection do
|
|
332
332
|
end
|
333
333
|
end
|
334
334
|
|
335
|
-
|
336
335
|
context 'when the message exceeds the max size' do
|
337
336
|
|
338
337
|
context 'when the message is an insert' do
|
@@ -547,9 +546,6 @@ describe Mongo::Server::Connection do
|
|
547
546
|
|
548
547
|
before do
|
549
548
|
connection.connect!
|
550
|
-
socket = connection.instance_variable_get(:@socket)
|
551
|
-
max_message_size = connection.send(:max_message_size)
|
552
|
-
allow(Mongo::Protocol::Reply).to receive(:deserialize).with(socket, max_message_size).and_return(reply)
|
553
549
|
end
|
554
550
|
|
555
551
|
context 'when the ismaster response indicates the auth mechanism is :scram' do
|
@@ -565,6 +561,9 @@ describe Mongo::Server::Connection do
|
|
565
561
|
context 'when the server auth mechanism is scram', if: scram_sha_1_enabled? do
|
566
562
|
|
567
563
|
it 'uses scram' do
|
564
|
+
socket = connection.instance_variable_get(:@socket)
|
565
|
+
max_message_size = connection.send(:max_message_size)
|
566
|
+
allow(Mongo::Protocol::Reply).to receive(:deserialize).with(socket, max_message_size).and_return(reply)
|
568
567
|
expect(connection.send(:default_mechanism)).to eq(:scram)
|
569
568
|
end
|
570
569
|
end
|
@@ -572,6 +571,9 @@ describe Mongo::Server::Connection do
|
|
572
571
|
context 'when the server auth mechanism is the default (mongodb_cr)', unless: scram_sha_1_enabled? do
|
573
572
|
|
574
573
|
it 'uses scram' do
|
574
|
+
socket = connection.instance_variable_get(:@socket)
|
575
|
+
max_message_size = connection.send(:max_message_size)
|
576
|
+
allow(Mongo::Protocol::Reply).to receive(:deserialize).with(socket, max_message_size).and_return(reply)
|
575
577
|
expect(connection.send(:default_mechanism)).to eq(:scram)
|
576
578
|
end
|
577
579
|
end
|
@@ -590,6 +592,9 @@ describe Mongo::Server::Connection do
|
|
590
592
|
context 'when the server auth mechanism is scram', if: scram_sha_1_enabled? do
|
591
593
|
|
592
594
|
it 'uses scram' do
|
595
|
+
socket = connection.instance_variable_get(:@socket)
|
596
|
+
max_message_size = connection.send(:max_message_size)
|
597
|
+
allow(Mongo::Protocol::Reply).to receive(:deserialize).with(socket, max_message_size).and_return(reply)
|
593
598
|
expect(connection.send(:default_mechanism)).to eq(:scram)
|
594
599
|
end
|
595
600
|
end
|
@@ -597,6 +602,9 @@ describe Mongo::Server::Connection do
|
|
597
602
|
context 'when the server auth mechanism is the default (mongodb_cr)', unless: scram_sha_1_enabled? do
|
598
603
|
|
599
604
|
it 'uses mongodb_cr' do
|
605
|
+
socket = connection.instance_variable_get(:@socket)
|
606
|
+
max_message_size = connection.send(:max_message_size)
|
607
|
+
allow(Mongo::Protocol::Reply).to receive(:deserialize).with(socket, max_message_size).and_return(reply)
|
600
608
|
expect(connection.send(:default_mechanism)).to eq(:mongodb_cr)
|
601
609
|
end
|
602
610
|
end
|
@@ -57,12 +57,12 @@ describe 'Server Selection' do
|
|
57
57
|
|
58
58
|
let(:server_selector) do
|
59
59
|
Mongo::ServerSelector.get(:mode => spec.read_preference['mode'],
|
60
|
-
:tag_sets => spec.read_preference['tag_sets']
|
61
|
-
:server_selection_timeout => 1)
|
60
|
+
:tag_sets => spec.read_preference['tag_sets'])
|
62
61
|
end
|
63
62
|
|
64
63
|
before do
|
65
64
|
allow(cluster).to receive(:servers).and_return(candidate_servers)
|
65
|
+
allow(cluster).to receive(:options).and_return(server_selection_timeout: 0.2)
|
66
66
|
allow(cluster).to receive(:scan!).and_return(true)
|
67
67
|
end
|
68
68
|
|
@@ -85,10 +85,10 @@ describe Mongo::ServerSelector::Nearest do
|
|
85
85
|
context 'tag sets provided' do
|
86
86
|
let(:tag_sets) { [tag_set] }
|
87
87
|
let(:matching_primary) do
|
88
|
-
|
88
|
+
make_server(:primary, :tags => server_tags, address: default_address)
|
89
89
|
end
|
90
90
|
let(:matching_secondary) do
|
91
|
-
|
91
|
+
make_server(:secondary, :tags => server_tags, address: default_address)
|
92
92
|
end
|
93
93
|
|
94
94
|
context 'single candidate' do
|
@@ -173,8 +173,8 @@ describe Mongo::ServerSelector::Nearest do
|
|
173
173
|
end
|
174
174
|
|
175
175
|
context 'high latency servers' do
|
176
|
-
let(:far_primary) {
|
177
|
-
let(:far_secondary) {
|
176
|
+
let(:far_primary) { make_server(:primary, :average_round_trip_time => 113, address: default_address) }
|
177
|
+
let(:far_secondary) { make_server(:secondary, :average_round_trip_time => 114, address: default_address) }
|
178
178
|
|
179
179
|
context 'single candidate' do
|
180
180
|
|
@@ -81,11 +81,11 @@ describe Mongo::ServerSelector::PrimaryPreferred do
|
|
81
81
|
let(:tag_sets) { [tag_set] }
|
82
82
|
|
83
83
|
let(:matching_primary) do
|
84
|
-
|
84
|
+
make_server(:primary, :tags => server_tags, address: default_address )
|
85
85
|
end
|
86
86
|
|
87
87
|
let(:matching_secondary) do
|
88
|
-
|
88
|
+
make_server(:secondary, :tags => server_tags, address: default_address )
|
89
89
|
end
|
90
90
|
|
91
91
|
context 'single candidate' do
|
@@ -171,8 +171,8 @@ describe Mongo::ServerSelector::PrimaryPreferred do
|
|
171
171
|
end
|
172
172
|
|
173
173
|
context 'high latency servers' do
|
174
|
-
let(:far_primary) {
|
175
|
-
let(:far_secondary) {
|
174
|
+
let(:far_primary) { make_server(:primary, :average_round_trip_time => 100, address: default_address) }
|
175
|
+
let(:far_secondary) { make_server(:secondary, :average_round_trip_time => 113, address: default_address) }
|
176
176
|
|
177
177
|
context 'single candidate' do
|
178
178
|
|
@@ -76,8 +76,8 @@ describe Mongo::ServerSelector::Primary do
|
|
76
76
|
end
|
77
77
|
|
78
78
|
context 'high latency candidates' do
|
79
|
-
let(:far_primary) {
|
80
|
-
let(:far_secondary) {
|
79
|
+
let(:far_primary) { make_server(:primary, :average_round_trip_time => 100, address: default_address) }
|
80
|
+
let(:far_secondary) { make_server(:secondary, :average_round_trip_time => 120, address: default_address) }
|
81
81
|
|
82
82
|
context 'single candidate' do
|
83
83
|
|
@@ -87,11 +87,11 @@ describe Mongo::ServerSelector::SecondaryPreferred do
|
|
87
87
|
end
|
88
88
|
|
89
89
|
let(:matching_primary) do
|
90
|
-
|
90
|
+
make_server(:primary, :tags => server_tags, address: default_address)
|
91
91
|
end
|
92
92
|
|
93
93
|
let(:matching_secondary) do
|
94
|
-
|
94
|
+
make_server(:secondary, :tags => server_tags, address: default_address)
|
95
95
|
end
|
96
96
|
|
97
97
|
context 'single candidate' do
|
@@ -170,8 +170,8 @@ describe Mongo::ServerSelector::SecondaryPreferred do
|
|
170
170
|
end
|
171
171
|
|
172
172
|
context 'high latency servers' do
|
173
|
-
let(:far_primary) {
|
174
|
-
let(:far_secondary) {
|
173
|
+
let(:far_primary) { make_server(:primary, :average_round_trip_time => 100, address: default_address) }
|
174
|
+
let(:far_secondary) { make_server(:secondary, :average_round_trip_time => 113, address: default_address) }
|
175
175
|
|
176
176
|
context 'single candidate' do
|
177
177
|
|
@@ -76,7 +76,7 @@ describe Mongo::ServerSelector::Secondary do
|
|
76
76
|
|
77
77
|
context 'tag sets provided' do
|
78
78
|
let(:tag_sets) { [tag_set] }
|
79
|
-
let(:matching_secondary) {
|
79
|
+
let(:matching_secondary) { make_server(:secondary, :tags => server_tags, address: default_address) }
|
80
80
|
|
81
81
|
context 'single candidate' do
|
82
82
|
|
@@ -134,8 +134,8 @@ describe Mongo::ServerSelector::Secondary do
|
|
134
134
|
end
|
135
135
|
|
136
136
|
context 'high latency servers' do
|
137
|
-
let(:far_primary) {
|
138
|
-
let(:far_secondary) {
|
137
|
+
let(:far_primary) { make_server(:primary, :average_round_trip_time => 100, address: default_address) }
|
138
|
+
let(:far_secondary) { make_server(:secondary, :average_round_trip_time => 113, address: default_address) }
|
139
139
|
|
140
140
|
context 'single candidate' do
|
141
141
|
|
@@ -10,6 +10,17 @@ describe Mongo::ServerSelector do
|
|
10
10
|
described_class.get(:mode => name, :tag_sets => tag_sets)
|
11
11
|
end
|
12
12
|
|
13
|
+
context 'when a server selector object is passed' do
|
14
|
+
|
15
|
+
let(:name) do
|
16
|
+
:primary
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'returns the object' do
|
20
|
+
expect(described_class.get(selector)).to be(selector)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
13
24
|
context 'when the mode is primary' do
|
14
25
|
|
15
26
|
let(:name) do
|
@@ -134,7 +145,7 @@ describe Mongo::ServerSelector do
|
|
134
145
|
context 'when #select returns a list of nils' do
|
135
146
|
|
136
147
|
let(:servers) do
|
137
|
-
[
|
148
|
+
[ make_server(:primary) ]
|
138
149
|
end
|
139
150
|
|
140
151
|
let(:cluster) do
|
@@ -143,11 +154,12 @@ describe Mongo::ServerSelector do
|
|
143
154
|
allow(c).to receive(:single?).and_return(false)
|
144
155
|
allow(c).to receive(:sharded?).and_return(false)
|
145
156
|
allow(c).to receive(:scan!).and_return(true)
|
157
|
+
allow(c).to receive(:options).and_return(server_selection_timeout: 0.1)
|
146
158
|
end
|
147
159
|
end
|
148
160
|
|
149
161
|
let(:read_pref) do
|
150
|
-
described_class.get(mode: :primary
|
162
|
+
described_class.get(mode: :primary).tap do |pref|
|
151
163
|
allow(pref).to receive(:select).and_return([ nil, nil ])
|
152
164
|
end
|
153
165
|
end
|
@@ -158,6 +170,72 @@ describe Mongo::ServerSelector do
|
|
158
170
|
end.to raise_exception(Mongo::Error::NoServerAvailable)
|
159
171
|
end
|
160
172
|
end
|
173
|
+
|
174
|
+
context 'when the cluster has a server_selection_timeout set' do
|
175
|
+
|
176
|
+
let(:servers) do
|
177
|
+
[ make_server(:secondary), make_server(:primary) ]
|
178
|
+
end
|
179
|
+
|
180
|
+
let(:cluster) do
|
181
|
+
double('cluster').tap do |c|
|
182
|
+
allow(c).to receive(:servers).and_return(servers)
|
183
|
+
allow(c).to receive(:single?).and_return(false)
|
184
|
+
allow(c).to receive(:sharded?).and_return(false)
|
185
|
+
allow(c).to receive(:scan!).and_return(true)
|
186
|
+
allow(c).to receive(:options).and_return(server_selection_timeout: 0)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
let(:read_pref) do
|
191
|
+
described_class.get(mode: :nearest)
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'uses the server_selection_timeout of the cluster' do
|
195
|
+
expect{
|
196
|
+
read_pref.select_server(cluster)
|
197
|
+
}.to raise_exception(Mongo::Error::NoServerAvailable)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
context 'when the cluster has a local_threshold set' do
|
202
|
+
|
203
|
+
let(:near_server) do
|
204
|
+
make_server(:secondary).tap do |s|
|
205
|
+
allow(s).to receive(:connectable?).and_return(true)
|
206
|
+
allow(s).to receive(:average_round_trip_time).and_return(100)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
let(:far_server) do
|
211
|
+
make_server(:secondary).tap do |s|
|
212
|
+
allow(s).to receive(:connectable?).and_return(true)
|
213
|
+
allow(s).to receive(:average_round_trip_time).and_return(200)
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
let(:servers) do
|
218
|
+
[ near_server, far_server ]
|
219
|
+
end
|
220
|
+
|
221
|
+
let(:cluster) do
|
222
|
+
double('cluster').tap do |c|
|
223
|
+
allow(c).to receive(:servers).and_return(servers)
|
224
|
+
allow(c).to receive(:single?).and_return(false)
|
225
|
+
allow(c).to receive(:sharded?).and_return(false)
|
226
|
+
allow(c).to receive(:scan!).and_return(true)
|
227
|
+
allow(c).to receive(:options).and_return(local_threshold: 0.050)
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
let(:read_pref) do
|
232
|
+
described_class.get(mode: :nearest)
|
233
|
+
end
|
234
|
+
|
235
|
+
it 'uses the local_threshold of the cluster' do
|
236
|
+
expect(read_pref.select_server(cluster)).to eq(near_server)
|
237
|
+
end
|
238
|
+
end
|
161
239
|
end
|
162
240
|
|
163
241
|
shared_context 'a ServerSelector' do
|
@@ -174,11 +252,12 @@ describe Mongo::ServerSelector do
|
|
174
252
|
allow(c).to receive(:single?).and_return(single)
|
175
253
|
allow(c).to receive(:sharded?).and_return(sharded)
|
176
254
|
allow(c).to receive(:scan!).and_return(true)
|
255
|
+
allow(c).to receive(:options).and_return(server_selection_timeout: 0.1)
|
177
256
|
end
|
178
257
|
end
|
179
258
|
|
180
259
|
let(:read_pref) do
|
181
|
-
described_class.get(mode: :primary
|
260
|
+
described_class.get(mode: :primary)
|
182
261
|
end
|
183
262
|
|
184
263
|
it 'raises a NoServerAvailable error' do
|
data/spec/mongo/server_spec.rb
CHANGED
@@ -116,26 +116,6 @@ describe Mongo::Server do
|
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
|
-
describe '#context' do
|
120
|
-
|
121
|
-
let(:server) do
|
122
|
-
described_class.new(address, cluster, monitoring, listeners, TEST_OPTIONS)
|
123
|
-
end
|
124
|
-
|
125
|
-
let(:context) do
|
126
|
-
server.context
|
127
|
-
end
|
128
|
-
|
129
|
-
after do
|
130
|
-
expect(cluster).to receive(:pool).with(server).and_return(pool)
|
131
|
-
server.disconnect!
|
132
|
-
end
|
133
|
-
|
134
|
-
it 'returns a new server context' do
|
135
|
-
expect(context.server).to eq(server)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
119
|
describe '#disconnect!' do
|
140
120
|
|
141
121
|
let(:server) do
|
data/spec/support/crud.rb
CHANGED
data/spec/support/crud/read.rb
CHANGED
data/spec/support/crud/write.rb
CHANGED
data/spec/support/gridfs.rb
CHANGED