mongo 2.1.0.beta → 2.1.0.rc0
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/Rakefile +2 -2
- data/lib/mongo.rb +2 -3
- data/lib/mongo/address.rb +7 -5
- data/lib/mongo/address/unix.rb +2 -2
- data/lib/mongo/auth/ldap/conversation.rb +6 -2
- data/lib/mongo/auth/scram/conversation.rb +8 -2
- data/lib/mongo/auth/user/view.rb +21 -0
- data/lib/mongo/bulk_write.rb +155 -23
- data/lib/mongo/bulk_write/combineable.rb +51 -0
- data/lib/mongo/bulk_write/ordered_combiner.rb +55 -0
- data/lib/mongo/bulk_write/result.rb +61 -8
- data/lib/mongo/bulk_write/result_combiner.rb +117 -0
- data/lib/mongo/bulk_write/transformable.rb +117 -0
- data/lib/mongo/bulk_write/unordered_combiner.rb +52 -0
- data/lib/mongo/bulk_write/validatable.rb +62 -0
- data/lib/mongo/client.rb +7 -3
- data/lib/mongo/cluster.rb +3 -3
- data/lib/mongo/cluster/topology/replica_set.rb +8 -6
- data/lib/mongo/cluster/topology/unknown.rb +5 -2
- data/lib/mongo/collection.rb +75 -4
- data/lib/mongo/collection/view.rb +1 -2
- data/lib/mongo/collection/view/aggregation.rb +13 -8
- data/lib/mongo/collection/view/immutable.rb +6 -6
- data/lib/mongo/collection/view/iterable.rb +13 -4
- data/lib/mongo/collection/view/map_reduce.rb +22 -17
- data/lib/mongo/collection/view/readable.rb +121 -70
- data/lib/mongo/cursor.rb +5 -1
- data/lib/mongo/database.rb +3 -3
- data/lib/mongo/database/view.rb +1 -1
- data/lib/mongo/error.rb +7 -0
- data/lib/mongo/{bulk_write/unordered_bulk_write.rb → error/closed_stream.rb} +12 -21
- data/lib/mongo/{bulk_write/ordered_bulk_write.rb → error/extra_file_chunk.rb} +13 -27
- data/lib/mongo/error/file_not_found.rb +37 -0
- data/lib/mongo/error/invalid_file.rb +2 -2
- data/lib/mongo/error/invalid_file_revision.rb +37 -0
- data/lib/mongo/error/invalid_uri.rb +5 -4
- data/lib/mongo/error/missing_file_chunk.rb +38 -0
- data/lib/mongo/error/operation_failure.rb +1 -1
- data/lib/mongo/error/unchangeable_collection_option.rb +38 -0
- data/lib/mongo/error/unexpected_chunk_length.rb +39 -0
- data/lib/mongo/grid.rb +2 -1
- data/lib/mongo/grid/file.rb +12 -9
- data/lib/mongo/grid/file/chunk.rb +6 -6
- data/lib/mongo/grid/file/{metadata.rb → info.rb} +41 -39
- data/lib/mongo/grid/fs_bucket.rb +441 -0
- data/lib/mongo/grid/stream.rb +64 -0
- data/lib/mongo/grid/stream/read.rb +208 -0
- data/lib/mongo/grid/stream/write.rb +187 -0
- data/lib/mongo/index/view.rb +1 -1
- data/lib/mongo/loggable.rb +34 -57
- data/lib/mongo/logger.rb +16 -78
- data/lib/mongo/monitoring.rb +1 -5
- data/lib/mongo/monitoring/command_log_subscriber.rb +35 -17
- data/lib/mongo/monitoring/event/command_succeeded.rb +20 -1
- data/lib/mongo/monitoring/publishable.rb +22 -12
- data/lib/mongo/operation.rb +3 -6
- data/lib/mongo/operation/commands.rb +24 -0
- data/lib/mongo/operation/{aggregate.rb → commands/aggregate.rb} +3 -41
- data/lib/mongo/operation/{aggregate → commands/aggregate}/result.rb +0 -0
- data/lib/mongo/operation/commands/collections_info.rb +66 -0
- data/lib/mongo/operation/{command.rb → commands/command.rb} +2 -18
- data/lib/mongo/operation/commands/indexes.rb +70 -0
- data/lib/mongo/operation/commands/list_collections.rb +54 -0
- data/lib/mongo/operation/commands/list_collections/result.rb +112 -0
- data/lib/mongo/operation/commands/list_indexes.rb +56 -0
- data/lib/mongo/operation/commands/list_indexes/result.rb +115 -0
- data/lib/mongo/operation/{map_reduce.rb → commands/map_reduce.rb} +3 -41
- data/lib/mongo/operation/{map_reduce → commands/map_reduce}/result.rb +0 -0
- data/lib/mongo/operation/{parallel_scan.rb → commands/parallel_scan.rb} +3 -23
- data/lib/mongo/operation/{parallel_scan → commands/parallel_scan}/result.rb +0 -0
- data/lib/mongo/operation/commands/user_query.rb +69 -0
- data/lib/mongo/operation/commands/users_info.rb +53 -0
- data/lib/mongo/operation/commands/users_info/result.rb +36 -0
- data/lib/mongo/operation/executable.rb +4 -68
- data/lib/mongo/operation/kill_cursors.rb +3 -3
- data/lib/mongo/operation/read.rb +0 -4
- data/lib/mongo/operation/read/get_more.rb +2 -22
- data/lib/mongo/operation/read/query.rb +2 -21
- data/lib/mongo/operation/{read_preferrable.rb → read_preference.rb} +3 -2
- data/lib/mongo/operation/specifiable.rb +24 -0
- data/lib/mongo/operation/write.rb +2 -0
- data/lib/mongo/operation/write/bulk.rb +6 -3
- data/lib/mongo/operation/write/bulk/bulkable.rb +82 -0
- data/lib/mongo/operation/write/bulk/delete.rb +71 -0
- data/lib/mongo/operation/write/bulk/delete/result.rb +74 -0
- data/lib/mongo/operation/write/bulk/insert.rb +96 -0
- data/lib/mongo/operation/write/bulk/insert/result.rb +129 -0
- data/lib/mongo/operation/write/bulk/legacy_mergable.rb +87 -0
- data/lib/mongo/operation/write/bulk/mergable.rb +71 -0
- data/lib/mongo/operation/write/bulk/update.rb +81 -0
- data/lib/mongo/operation/write/bulk/update/result.rb +174 -0
- data/lib/mongo/operation/write/command/create_index.rb +0 -1
- data/lib/mongo/operation/write/command/create_user.rb +0 -1
- data/lib/mongo/operation/write/command/delete.rb +0 -1
- data/lib/mongo/operation/write/command/drop_index.rb +0 -1
- data/lib/mongo/operation/write/command/insert.rb +0 -1
- data/lib/mongo/operation/write/command/remove_user.rb +0 -1
- data/lib/mongo/operation/write/command/update.rb +0 -1
- data/lib/mongo/operation/write/command/update_user.rb +0 -1
- data/lib/mongo/operation/write/command/writable.rb +13 -18
- data/lib/mongo/operation/write/create_index.rb +4 -27
- data/lib/mongo/operation/write/create_user.rb +4 -30
- data/lib/mongo/operation/write/delete.rb +5 -28
- data/lib/mongo/operation/write/drop_index.rb +3 -3
- data/lib/mongo/operation/write/gle.rb +48 -0
- data/lib/mongo/operation/write/idable.rb +5 -0
- data/lib/mongo/operation/write/insert.rb +2 -24
- data/lib/mongo/operation/write/remove_user.rb +4 -27
- data/lib/mongo/operation/write/update.rb +4 -32
- data/lib/mongo/operation/write/update_user.rb +4 -30
- data/lib/mongo/operation/write/write_command_enabled.rb +53 -0
- data/lib/mongo/options/mapper.rb +4 -2
- data/lib/mongo/protocol/delete.rb +68 -3
- data/lib/mongo/protocol/get_more.rb +54 -2
- data/lib/mongo/protocol/insert.rb +59 -1
- data/lib/mongo/protocol/kill_cursors.rb +53 -4
- data/lib/mongo/protocol/message.rb +12 -12
- data/lib/mongo/protocol/query.rb +139 -65
- data/lib/mongo/protocol/reply.rb +69 -1
- data/lib/mongo/protocol/update.rb +70 -1
- data/lib/mongo/server/connection.rb +11 -3
- data/lib/mongo/server/description.rb +29 -0
- data/lib/mongo/server/description/features.rb +2 -1
- data/lib/mongo/server/monitor.rb +2 -2
- data/lib/mongo/server_selector.rb +14 -10
- data/lib/mongo/server_selector/selectable.rb +24 -22
- data/lib/mongo/socket.rb +6 -3
- data/lib/mongo/socket/tcp.rb +2 -2
- data/lib/mongo/socket/unix.rb +5 -8
- data/lib/mongo/uri.rb +243 -139
- data/lib/mongo/version.rb +1 -1
- data/spec/mongo/address/unix_spec.rb +1 -1
- data/spec/mongo/address_spec.rb +25 -0
- data/spec/mongo/auth/ldap/conversation_spec.rb +43 -0
- data/spec/mongo/auth/user/view_spec.rb +26 -1
- data/spec/mongo/bulk_write/ordered_combiner_spec.rb +271 -0
- data/spec/mongo/bulk_write/unordered_combiner_spec.rb +239 -0
- data/spec/mongo/bulk_write_spec.rb +332 -166
- data/spec/mongo/client_spec.rb +25 -0
- data/spec/mongo/cluster/topology/replica_set_spec.rb +2 -0
- data/spec/mongo/collection/view/aggregation_spec.rb +65 -0
- data/spec/mongo/collection/view/immutable_spec.rb +103 -0
- data/spec/mongo/collection/view/map_reduce_spec.rb +98 -3
- data/spec/mongo/collection/view/readable_spec.rb +17 -30
- data/spec/mongo/collection/view_spec.rb +233 -7
- data/spec/mongo/collection_spec.rb +360 -18
- data/spec/mongo/command_monitoring_spec.rb +51 -0
- data/spec/mongo/connection_string_spec.rb +137 -0
- data/spec/mongo/database_spec.rb +27 -11
- data/spec/mongo/grid/file/chunk_spec.rb +5 -5
- data/spec/mongo/grid/file/{metadata_spec.rb → info_spec.rb} +29 -17
- data/spec/mongo/grid/file_spec.rb +8 -8
- data/spec/mongo/grid/fs_bucket_spec.rb +1020 -0
- data/spec/mongo/grid/stream/read_spec.rb +275 -0
- data/spec/mongo/grid/stream/write_spec.rb +440 -0
- data/spec/mongo/grid/stream_spec.rb +48 -0
- data/spec/mongo/gridfs_spec.rb +50 -0
- data/spec/mongo/logger_spec.rb +0 -40
- data/spec/mongo/monitoring/command_log_subscriber_spec.rb +76 -0
- data/spec/mongo/operation/{aggregate_spec.rb → commands/aggregate_spec.rb} +0 -42
- data/spec/mongo/operation/{read → commands}/collections_info_spec.rb +1 -1
- data/spec/mongo/operation/{command_spec.rb → commands/command_spec.rb} +0 -0
- data/spec/mongo/operation/{read → commands}/indexes_spec.rb +1 -1
- data/spec/mongo/operation/{map_reduce_spec.rb → commands/map_reduce_spec.rb} +0 -18
- data/spec/mongo/operation/kill_cursors_spec.rb +1 -1
- data/spec/mongo/operation/{read_preferrable_spec.rb → read_preference_spec.rb} +11 -11
- data/spec/mongo/operation/write/bulk/{bulk_delete_spec.rb → delete_spec.rb} +1 -12
- data/spec/mongo/operation/write/bulk/{bulk_insert_spec.rb → insert_spec.rb} +1 -12
- data/spec/mongo/operation/write/bulk/{bulk_update_spec.rb → update_spec.rb} +1 -12
- data/spec/mongo/operation/write/insert_spec.rb +0 -11
- data/spec/mongo/protocol/kill_cursors_spec.rb +5 -3
- data/spec/mongo/server/description_spec.rb +42 -0
- data/spec/mongo/server/monitor_spec.rb +21 -0
- data/spec/mongo/server_discovery_and_monitoring_spec.rb +1 -0
- data/spec/mongo/server_selection_spec.rb +3 -3
- data/spec/mongo/server_selector/nearest_spec.rb +34 -27
- data/spec/mongo/server_selector/primary_preferred_spec.rb +31 -30
- data/spec/mongo/server_selector/primary_spec.rb +14 -13
- data/spec/mongo/server_selector/secondary_preferred_spec.rb +27 -26
- data/spec/mongo/server_selector/secondary_spec.rb +23 -22
- data/spec/mongo/server_selector_spec.rb +87 -24
- data/spec/mongo/socket/unix_spec.rb +52 -0
- data/spec/mongo/uri_spec.rb +251 -39
- data/spec/spec_helper.rb +11 -4
- data/spec/support/authorization.rb +4 -5
- data/spec/support/command_monitoring.rb +365 -0
- data/spec/support/command_monitoring/bulkWrite.yml +73 -0
- data/spec/support/command_monitoring/command.yml +42 -0
- data/spec/support/command_monitoring/deleteMany.yml +55 -0
- data/spec/support/command_monitoring/deleteOne.yml +55 -0
- data/spec/support/command_monitoring/find.yml +219 -0
- data/spec/support/command_monitoring/insertMany.yml +81 -0
- data/spec/support/command_monitoring/insertOne.yml +51 -0
- data/spec/support/command_monitoring/updateMany.yml +67 -0
- data/spec/support/command_monitoring/updateOne.yml +95 -0
- data/spec/support/connection_string.rb +228 -0
- data/spec/support/connection_string_tests/invalid-uris.yml +193 -0
- data/spec/support/connection_string_tests/valid-auth.yml +256 -0
- data/spec/support/connection_string_tests/valid-host_identifiers.yml +121 -0
- data/spec/support/connection_string_tests/valid-options.yml +30 -0
- data/spec/support/connection_string_tests/valid-unix_socket-absolute.yml +197 -0
- data/spec/support/connection_string_tests/valid-unix_socket-relative.yml +213 -0
- data/spec/support/connection_string_tests/valid-warnings.yml +55 -0
- data/spec/support/crud.rb +3 -1
- data/spec/support/crud/read.rb +14 -10
- data/spec/support/crud/write.rb +36 -9
- data/spec/support/gridfs.rb +637 -0
- data/spec/support/gridfs_tests/delete.yml +157 -0
- data/spec/support/gridfs_tests/download.yml +210 -0
- data/spec/support/gridfs_tests/download_by_name.yml +113 -0
- data/spec/support/gridfs_tests/upload.yml +158 -0
- data/spec/support/sdam/rs/equal_electionids.yml +1 -2
- data/spec/support/sdam/rs/new_primary_new_electionid.yml +0 -3
- data/spec/support/sdam/rs/primary_mismatched_me.yml +37 -0
- data/spec/support/sdam/rs/primary_to_no_primary_mismatched_me.yml +75 -0
- data/spec/support/sdam/rs/secondary_mismatched_me.yml +37 -0
- data/spec/support/sdam/single/direct_connection_rsarbiter.yml +1 -1
- data/spec/support/sdam/single/direct_connection_rsprimary.yml +1 -1
- data/spec/support/sdam/single/direct_connection_rssecondary.yml +1 -1
- data/spec/support/sdam/single/direct_connection_slave.yml +1 -1
- data/spec/support/sdam/single/direct_connection_standalone.yml +1 -1
- data/spec/support/sdam/single/not_ok_response.yml +0 -1
- data/spec/support/server_discovery_and_monitoring.rb +3 -1
- data/spec/support/server_selection.rb +3 -1
- data/spec/support/shared/bulk_write.rb +192 -0
- data/spec/support/shared/server_selector.rb +21 -12
- metadata +147 -57
- metadata.gz.sig +0 -0
- data/lib/mongo/bulk_write/bulk_writable.rb +0 -252
- data/lib/mongo/bulk_write/deletable.rb +0 -57
- data/lib/mongo/bulk_write/insertable.rb +0 -49
- data/lib/mongo/bulk_write/replacable.rb +0 -58
- data/lib/mongo/bulk_write/updatable.rb +0 -69
- data/lib/mongo/grid/fs.rb +0 -146
- data/lib/mongo/operation/list_collections/result.rb +0 -114
- data/lib/mongo/operation/list_indexes/result.rb +0 -118
- data/lib/mongo/operation/read/collections_info.rb +0 -68
- data/lib/mongo/operation/read/indexes.rb +0 -69
- data/lib/mongo/operation/read/list_collections.rb +0 -76
- data/lib/mongo/operation/read/list_indexes.rb +0 -78
- data/lib/mongo/operation/write/bulk/bulk_delete.rb +0 -145
- data/lib/mongo/operation/write/bulk/bulk_delete/result.rb +0 -75
- data/lib/mongo/operation/write/bulk/bulk_insert.rb +0 -132
- data/lib/mongo/operation/write/bulk/bulk_insert/result.rb +0 -130
- data/lib/mongo/operation/write/bulk/bulk_mergable.rb +0 -67
- data/lib/mongo/operation/write/bulk/bulk_update.rb +0 -154
- data/lib/mongo/operation/write/bulk/bulk_update/result.rb +0 -174
- data/lib/mongo/operation/write/bulk/legacy_bulk_mergable.rb +0 -83
- data/spec/mongo/grid/fs_spec.rb +0 -160
- data/spec/mongo/loggable_spec.rb +0 -63
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Mongo::Operation::Write::
|
3
|
+
describe Mongo::Operation::Write::Bulk::Insert do
|
4
4
|
include_context 'operation'
|
5
5
|
|
6
6
|
let(:documents) do
|
@@ -74,17 +74,6 @@ describe Mongo::Operation::Write::BulkInsert do
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
-
describe '#dup' do
|
78
|
-
|
79
|
-
context 'deep copy' do
|
80
|
-
|
81
|
-
it 'copies the list of documents' do
|
82
|
-
copy = op.dup
|
83
|
-
expect(copy.spec[:documents]).to_not be(op.spec[:documents])
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
77
|
describe 'document ids' do
|
89
78
|
|
90
79
|
context 'when documents do not contain an id' do
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Mongo::Operation::Write::
|
3
|
+
describe Mongo::Operation::Write::Bulk::Update do
|
4
4
|
include_context 'operation'
|
5
5
|
|
6
6
|
let(:documents) do
|
@@ -72,17 +72,6 @@ describe Mongo::Operation::Write::BulkUpdate do
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
describe '#dup' do
|
76
|
-
|
77
|
-
context 'deep copy' do
|
78
|
-
|
79
|
-
it 'copies the list of updates' do
|
80
|
-
copy = op.dup
|
81
|
-
expect(copy.spec[:updates]).not_to be(op.spec[:updates])
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
75
|
describe '#execute' do
|
87
76
|
|
88
77
|
before do
|
@@ -73,17 +73,6 @@ describe Mongo::Operation::Write::Insert do
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
-
describe '#dup' do
|
77
|
-
|
78
|
-
context 'deep copy' do
|
79
|
-
|
80
|
-
it 'copies the list of documents' do
|
81
|
-
copy = insert.dup
|
82
|
-
expect(copy.spec[:documents]).to_not be(insert.spec[:documents])
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
76
|
describe 'document ids' do
|
88
77
|
|
89
78
|
context 'when documents do not contain an id' do
|
@@ -5,8 +5,10 @@ describe Mongo::Protocol::KillCursors do
|
|
5
5
|
let(:opcode) { 2007 }
|
6
6
|
let(:cursor_ids) { [123, 456, 789] }
|
7
7
|
let(:id_count) { cursor_ids.size }
|
8
|
+
let(:collection) { TEST_COLL }
|
9
|
+
let(:database) { TEST_DB }
|
8
10
|
let(:message) do
|
9
|
-
described_class.new(cursor_ids)
|
11
|
+
described_class.new(collection, database, cursor_ids)
|
10
12
|
end
|
11
13
|
|
12
14
|
describe '#initialize' do
|
@@ -26,7 +28,7 @@ describe Mongo::Protocol::KillCursors do
|
|
26
28
|
|
27
29
|
context 'when the cursor ids are equal' do
|
28
30
|
let(:other) do
|
29
|
-
described_class.new(cursor_ids)
|
31
|
+
described_class.new(collection, database, cursor_ids)
|
30
32
|
end
|
31
33
|
|
32
34
|
it 'returns true' do
|
@@ -36,7 +38,7 @@ describe Mongo::Protocol::KillCursors do
|
|
36
38
|
|
37
39
|
context 'when the cursor ids are not equal' do
|
38
40
|
let(:other) do
|
39
|
-
described_class.new([123, 456])
|
41
|
+
described_class.new(collection, database, [123, 456])
|
40
42
|
end
|
41
43
|
|
42
44
|
it 'returns false' do
|
@@ -617,6 +617,48 @@ describe Mongo::Server::Description do
|
|
617
617
|
end
|
618
618
|
end
|
619
619
|
|
620
|
+
describe '#me_mismatch?' do
|
621
|
+
|
622
|
+
let(:description) do
|
623
|
+
described_class.new(address, config)
|
624
|
+
end
|
625
|
+
|
626
|
+
context 'when the server address matches the me field' do
|
627
|
+
|
628
|
+
let(:config) do
|
629
|
+
replica.merge('me' => address.to_s)
|
630
|
+
end
|
631
|
+
|
632
|
+
it 'returns false' do
|
633
|
+
expect(description.me_mismatch?).to be(false)
|
634
|
+
end
|
635
|
+
end
|
636
|
+
|
637
|
+
context 'when the server address does not match the me field' do
|
638
|
+
|
639
|
+
let(:config) do
|
640
|
+
replica.merge('me' => 'localhost:27020')
|
641
|
+
end
|
642
|
+
|
643
|
+
it 'returns true' do
|
644
|
+
expect(description.me_mismatch?).to be(true)
|
645
|
+
end
|
646
|
+
end
|
647
|
+
|
648
|
+
context 'when there is no me field' do
|
649
|
+
|
650
|
+
let(:config) do
|
651
|
+
replica.tap do |r|
|
652
|
+
r.delete('me')
|
653
|
+
end
|
654
|
+
end
|
655
|
+
|
656
|
+
it 'returns false' do
|
657
|
+
expect(description.me_mismatch?).to be(false)
|
658
|
+
end
|
659
|
+
end
|
660
|
+
end
|
661
|
+
|
620
662
|
describe '#lists_server?' do
|
621
663
|
|
622
664
|
let(:description) do
|
@@ -171,4 +171,25 @@ describe Mongo::Server::Monitor do
|
|
171
171
|
end
|
172
172
|
end
|
173
173
|
end
|
174
|
+
|
175
|
+
describe '#stop' do
|
176
|
+
|
177
|
+
let(:monitor) do
|
178
|
+
described_class.new(address, listeners, TEST_OPTIONS)
|
179
|
+
end
|
180
|
+
|
181
|
+
let!(:thread) do
|
182
|
+
monitor.run!
|
183
|
+
end
|
184
|
+
|
185
|
+
before do
|
186
|
+
expect(monitor.connection).to receive(:disconnect!).and_call_original
|
187
|
+
monitor.stop!
|
188
|
+
sleep(1)
|
189
|
+
end
|
190
|
+
|
191
|
+
it 'kills the monitor thread' do
|
192
|
+
expect(thread.stop?).to be(true)
|
193
|
+
end
|
194
|
+
end
|
174
195
|
end
|
@@ -54,9 +54,9 @@ describe 'Server Selection' do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
let(:server_selector) do
|
57
|
-
Mongo::ServerSelector.get(
|
58
|
-
|
59
|
-
|
57
|
+
Mongo::ServerSelector.get(:mode => spec.read_preference['mode'],
|
58
|
+
:tag_sets => spec.read_preference['tag_sets'],
|
59
|
+
:server_selection_timeout => 1)
|
60
60
|
end
|
61
61
|
|
62
62
|
before do
|
@@ -2,30 +2,37 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Mongo::ServerSelector::Nearest do
|
4
4
|
|
5
|
+
let(:name) { :nearest }
|
6
|
+
|
5
7
|
include_context 'server selector'
|
6
8
|
|
7
|
-
it_behaves_like 'a
|
8
|
-
let(:name) { :nearest }
|
9
|
+
it_behaves_like 'a server selector mode' do
|
9
10
|
let(:slave_ok) { true }
|
10
11
|
end
|
11
12
|
|
12
|
-
it_behaves_like 'a
|
13
|
+
it_behaves_like 'a server selector accepting tag sets'
|
13
14
|
|
14
15
|
describe '#to_mongos' do
|
15
16
|
|
16
17
|
context 'tag set not provided' do
|
18
|
+
|
19
|
+
let(:expected) do
|
20
|
+
{ :mode => 'nearest' }
|
21
|
+
end
|
22
|
+
|
17
23
|
it 'returns a read preference formatted for mongos' do
|
18
|
-
expect(
|
24
|
+
expect(selector.to_mongos).to eq(expected)
|
19
25
|
end
|
20
26
|
end
|
21
27
|
|
22
28
|
context 'tag set provided' do
|
29
|
+
|
23
30
|
let(:tag_sets) do
|
24
31
|
[tag_set]
|
25
32
|
end
|
26
33
|
|
27
34
|
it 'returns a read preference formatted for mongos' do
|
28
|
-
expect(
|
35
|
+
expect(selector.to_mongos).to eq(
|
29
36
|
{ :mode => 'nearest', :tags => tag_sets }
|
30
37
|
)
|
31
38
|
end
|
@@ -38,7 +45,7 @@ describe Mongo::ServerSelector::Nearest do
|
|
38
45
|
let(:candidates) { [] }
|
39
46
|
|
40
47
|
it 'returns an empty array' do
|
41
|
-
expect(
|
48
|
+
expect(selector.send(:select, candidates)).to be_empty
|
42
49
|
end
|
43
50
|
end
|
44
51
|
|
@@ -46,7 +53,7 @@ describe Mongo::ServerSelector::Nearest do
|
|
46
53
|
let(:candidates) { [primary] }
|
47
54
|
|
48
55
|
it 'returns an array with the primary' do
|
49
|
-
expect(
|
56
|
+
expect(selector.send(:select, candidates)).to eq([primary])
|
50
57
|
end
|
51
58
|
end
|
52
59
|
|
@@ -54,7 +61,7 @@ describe Mongo::ServerSelector::Nearest do
|
|
54
61
|
let(:candidates) { [secondary] }
|
55
62
|
|
56
63
|
it 'returns an array with the secondary' do
|
57
|
-
expect(
|
64
|
+
expect(selector.send(:select, candidates)).to eq([secondary])
|
58
65
|
end
|
59
66
|
end
|
60
67
|
|
@@ -62,7 +69,7 @@ describe Mongo::ServerSelector::Nearest do
|
|
62
69
|
let(:candidates) { [primary, secondary] }
|
63
70
|
|
64
71
|
it 'returns an array with the primary and secondary' do
|
65
|
-
expect(
|
72
|
+
expect(selector.send(:select, candidates)).to match_array([primary, secondary])
|
66
73
|
end
|
67
74
|
end
|
68
75
|
|
@@ -70,7 +77,7 @@ describe Mongo::ServerSelector::Nearest do
|
|
70
77
|
let(:candidates) { [secondary, secondary] }
|
71
78
|
|
72
79
|
it 'returns an array with the secondaries' do
|
73
|
-
expect(
|
80
|
+
expect(selector.send(:select, candidates)).to match_array([secondary, secondary])
|
74
81
|
end
|
75
82
|
end
|
76
83
|
|
@@ -89,7 +96,7 @@ describe Mongo::ServerSelector::Nearest do
|
|
89
96
|
let(:candidates) { [primary] }
|
90
97
|
|
91
98
|
it 'returns an empty array' do
|
92
|
-
expect(
|
99
|
+
expect(selector.send(:select, candidates)).to be_empty
|
93
100
|
end
|
94
101
|
end
|
95
102
|
|
@@ -97,7 +104,7 @@ describe Mongo::ServerSelector::Nearest do
|
|
97
104
|
let(:candidates) { [matching_primary] }
|
98
105
|
|
99
106
|
it 'returns an array with the primary' do
|
100
|
-
expect(
|
107
|
+
expect(selector.send(:select, candidates)).to eq([matching_primary])
|
101
108
|
end
|
102
109
|
end
|
103
110
|
|
@@ -105,7 +112,7 @@ describe Mongo::ServerSelector::Nearest do
|
|
105
112
|
let(:candidates) { [secondary] }
|
106
113
|
|
107
114
|
it 'returns an empty array' do
|
108
|
-
expect(
|
115
|
+
expect(selector.send(:select, candidates)).to be_empty
|
109
116
|
end
|
110
117
|
end
|
111
118
|
|
@@ -113,7 +120,7 @@ describe Mongo::ServerSelector::Nearest do
|
|
113
120
|
let(:candidates) { [matching_secondary] }
|
114
121
|
|
115
122
|
it 'returns an array with the matching secondary' do
|
116
|
-
expect(
|
123
|
+
expect(selector.send(:select, candidates)).to eq([matching_secondary])
|
117
124
|
end
|
118
125
|
end
|
119
126
|
end
|
@@ -124,7 +131,7 @@ describe Mongo::ServerSelector::Nearest do
|
|
124
131
|
let(:candidates) { [primary, secondary, secondary] }
|
125
132
|
|
126
133
|
it 'returns an empty array' do
|
127
|
-
expect(
|
134
|
+
expect(selector.send(:select, candidates)).to be_empty
|
128
135
|
end
|
129
136
|
end
|
130
137
|
|
@@ -132,7 +139,7 @@ describe Mongo::ServerSelector::Nearest do
|
|
132
139
|
let(:candidates) { [matching_primary, secondary, secondary] }
|
133
140
|
|
134
141
|
it 'returns an array with the matching primary' do
|
135
|
-
expect(
|
142
|
+
expect(selector.send(:select, candidates)).to eq([matching_primary])
|
136
143
|
end
|
137
144
|
end
|
138
145
|
|
@@ -140,7 +147,7 @@ describe Mongo::ServerSelector::Nearest do
|
|
140
147
|
let(:candidates) { [primary, matching_secondary, secondary] }
|
141
148
|
|
142
149
|
it 'returns an array with the matching secondary' do
|
143
|
-
expect(
|
150
|
+
expect(selector.send(:select, candidates)).to eq([matching_secondary])
|
144
151
|
end
|
145
152
|
end
|
146
153
|
|
@@ -149,7 +156,7 @@ describe Mongo::ServerSelector::Nearest do
|
|
149
156
|
let(:expected) { [matching_secondary, matching_secondary] }
|
150
157
|
|
151
158
|
it 'returns an array with the matching secondaries' do
|
152
|
-
expect(
|
159
|
+
expect(selector.send(:select, candidates)).to eq(expected)
|
153
160
|
end
|
154
161
|
end
|
155
162
|
|
@@ -158,7 +165,7 @@ describe Mongo::ServerSelector::Nearest do
|
|
158
165
|
let(:expected) { [matching_primary, matching_secondary] }
|
159
166
|
|
160
167
|
it 'returns an array with the matching primary and secondary' do
|
161
|
-
expect(
|
168
|
+
expect(selector.send(:select, candidates)).to match_array(expected)
|
162
169
|
end
|
163
170
|
end
|
164
171
|
end
|
@@ -174,7 +181,7 @@ describe Mongo::ServerSelector::Nearest do
|
|
174
181
|
let(:candidates) { [far_primary] }
|
175
182
|
|
176
183
|
it 'returns array with far primary' do
|
177
|
-
expect(
|
184
|
+
expect(selector.send(:select, candidates)).to eq([far_primary])
|
178
185
|
end
|
179
186
|
end
|
180
187
|
|
@@ -182,7 +189,7 @@ describe Mongo::ServerSelector::Nearest do
|
|
182
189
|
let(:candidates) { [far_secondary] }
|
183
190
|
|
184
191
|
it 'returns array with far primary' do
|
185
|
-
expect(
|
192
|
+
expect(selector.send(:select, candidates)).to eq([far_secondary])
|
186
193
|
end
|
187
194
|
end
|
188
195
|
end
|
@@ -193,7 +200,7 @@ describe Mongo::ServerSelector::Nearest do
|
|
193
200
|
let(:candidates) { [primary, secondary] }
|
194
201
|
|
195
202
|
it 'returns array with primary and secondary' do
|
196
|
-
expect(
|
203
|
+
expect(selector.send(:select, candidates)).to match_array(
|
197
204
|
[primary, secondary]
|
198
205
|
)
|
199
206
|
end
|
@@ -203,7 +210,7 @@ describe Mongo::ServerSelector::Nearest do
|
|
203
210
|
let(:candidates) { [primary, far_secondary] }
|
204
211
|
|
205
212
|
it 'returns array with local primary' do
|
206
|
-
expect(
|
213
|
+
expect(selector.send(:select, candidates)).to eq([primary])
|
207
214
|
end
|
208
215
|
end
|
209
216
|
|
@@ -211,7 +218,7 @@ describe Mongo::ServerSelector::Nearest do
|
|
211
218
|
let(:candidates) { [far_primary, secondary] }
|
212
219
|
|
213
220
|
it 'returns array with local secondary' do
|
214
|
-
expect(
|
221
|
+
expect(selector.send(:select, candidates)).to eq([secondary])
|
215
222
|
end
|
216
223
|
end
|
217
224
|
|
@@ -220,7 +227,7 @@ describe Mongo::ServerSelector::Nearest do
|
|
220
227
|
let(:expected) { [far_primary, far_secondary] }
|
221
228
|
|
222
229
|
it 'returns array with both servers' do
|
223
|
-
expect(
|
230
|
+
expect(selector.send(:select, candidates)).to match_array(expected)
|
224
231
|
end
|
225
232
|
end
|
226
233
|
|
@@ -231,7 +238,7 @@ describe Mongo::ServerSelector::Nearest do
|
|
231
238
|
let(:expected) { [primary, secondary] }
|
232
239
|
|
233
240
|
it 'returns array with local primary and local secondary' do
|
234
|
-
expect(
|
241
|
+
expect(selector.send(:select, candidates)).to match_array(expected)
|
235
242
|
end
|
236
243
|
end
|
237
244
|
|
@@ -240,7 +247,7 @@ describe Mongo::ServerSelector::Nearest do
|
|
240
247
|
let(:expected) { [secondary, secondary] }
|
241
248
|
|
242
249
|
it 'returns array with the two local secondaries' do
|
243
|
-
expect(
|
250
|
+
expect(selector.send(:select, candidates)).to match_array(expected)
|
244
251
|
end
|
245
252
|
end
|
246
253
|
end
|
@@ -2,21 +2,22 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Mongo::ServerSelector::PrimaryPreferred do
|
4
4
|
|
5
|
+
let(:name) { :primary_preferred }
|
6
|
+
|
5
7
|
include_context 'server selector'
|
6
8
|
|
7
|
-
it_behaves_like 'a
|
8
|
-
let(:name) { :primary_preferred }
|
9
|
+
it_behaves_like 'a server selector mode' do
|
9
10
|
let(:slave_ok) { true }
|
10
11
|
end
|
11
12
|
|
12
|
-
it_behaves_like 'a
|
13
|
+
it_behaves_like 'a server selector accepting tag sets'
|
13
14
|
|
14
15
|
describe '#to_mongos' do
|
15
16
|
|
16
17
|
context 'tag sets not provided' do
|
17
18
|
|
18
19
|
it 'returns a read preference formatted for mongos' do
|
19
|
-
expect(
|
20
|
+
expect(selector.to_mongos).to eq({ :mode => 'primaryPreferred' })
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
@@ -24,7 +25,7 @@ describe Mongo::ServerSelector::PrimaryPreferred do
|
|
24
25
|
let(:tag_sets) { [tag_set] }
|
25
26
|
|
26
27
|
it 'returns a read preference formatted for mongos' do
|
27
|
-
expect(
|
28
|
+
expect(selector.to_mongos).to eq(
|
28
29
|
{ :mode => 'primaryPreferred', :tags => tag_sets}
|
29
30
|
)
|
30
31
|
end
|
@@ -37,7 +38,7 @@ describe Mongo::ServerSelector::PrimaryPreferred do
|
|
37
38
|
let(:candidates) { [] }
|
38
39
|
|
39
40
|
it 'returns an empty array' do
|
40
|
-
expect(
|
41
|
+
expect(selector.send(:select, candidates)).to be_empty
|
41
42
|
end
|
42
43
|
end
|
43
44
|
|
@@ -45,7 +46,7 @@ describe Mongo::ServerSelector::PrimaryPreferred do
|
|
45
46
|
let(:candidates) { [primary] }
|
46
47
|
|
47
48
|
it 'returns an array with the primary' do
|
48
|
-
expect(
|
49
|
+
expect(selector.send(:select, candidates)).to eq( [primary] )
|
49
50
|
end
|
50
51
|
end
|
51
52
|
|
@@ -53,7 +54,7 @@ describe Mongo::ServerSelector::PrimaryPreferred do
|
|
53
54
|
let(:candidates) { [secondary] }
|
54
55
|
|
55
56
|
it 'returns an array with the secondary' do
|
56
|
-
expect(
|
57
|
+
expect(selector.send(:select, candidates)).to eq( [secondary] )
|
57
58
|
end
|
58
59
|
end
|
59
60
|
|
@@ -62,7 +63,7 @@ describe Mongo::ServerSelector::PrimaryPreferred do
|
|
62
63
|
let(:expected) { [primary] }
|
63
64
|
|
64
65
|
it 'returns an array with the primary' do
|
65
|
-
expect(
|
66
|
+
expect(selector.send(:select, candidates)).to eq(expected)
|
66
67
|
end
|
67
68
|
end
|
68
69
|
|
@@ -71,7 +72,7 @@ describe Mongo::ServerSelector::PrimaryPreferred do
|
|
71
72
|
let(:expected) { [primary] }
|
72
73
|
|
73
74
|
it 'returns an array with the primary' do
|
74
|
-
expect(
|
75
|
+
expect(selector.send(:select, candidates)).to eq(expected)
|
75
76
|
end
|
76
77
|
end
|
77
78
|
|
@@ -92,7 +93,7 @@ describe Mongo::ServerSelector::PrimaryPreferred do
|
|
92
93
|
let(:candidates) { [primary] }
|
93
94
|
|
94
95
|
it 'returns array with primary' do
|
95
|
-
expect(
|
96
|
+
expect(selector.send(:select, candidates)).to eq([primary])
|
96
97
|
end
|
97
98
|
end
|
98
99
|
|
@@ -100,7 +101,7 @@ describe Mongo::ServerSelector::PrimaryPreferred do
|
|
100
101
|
let(:candidates) { [matching_primary] }
|
101
102
|
|
102
103
|
it 'returns array with matching primary' do
|
103
|
-
expect(
|
104
|
+
expect(selector.send(:select, candidates)).to eq([matching_primary])
|
104
105
|
end
|
105
106
|
end
|
106
107
|
|
@@ -108,7 +109,7 @@ describe Mongo::ServerSelector::PrimaryPreferred do
|
|
108
109
|
let(:candidates) { [matching_secondary] }
|
109
110
|
|
110
111
|
it 'returns array with matching secondary' do
|
111
|
-
expect(
|
112
|
+
expect(selector.send(:select, candidates)).to eq([matching_secondary])
|
112
113
|
end
|
113
114
|
end
|
114
115
|
|
@@ -116,7 +117,7 @@ describe Mongo::ServerSelector::PrimaryPreferred do
|
|
116
117
|
let(:candidates) { [secondary] }
|
117
118
|
|
118
119
|
it 'returns an empty array' do
|
119
|
-
expect(
|
120
|
+
expect(selector.send(:select, candidates)).to be_empty
|
120
121
|
end
|
121
122
|
end
|
122
123
|
end
|
@@ -127,7 +128,7 @@ describe Mongo::ServerSelector::PrimaryPreferred do
|
|
127
128
|
let(:candidates) { [primary, secondary, secondary] }
|
128
129
|
|
129
130
|
it 'returns an array with the primary' do
|
130
|
-
expect(
|
131
|
+
expect(selector.send(:select, candidates)).to eq([primary])
|
131
132
|
end
|
132
133
|
end
|
133
134
|
|
@@ -135,7 +136,7 @@ describe Mongo::ServerSelector::PrimaryPreferred do
|
|
135
136
|
let(:candidates) { [matching_primary, secondary, secondary] }
|
136
137
|
|
137
138
|
it 'returns an array of the primary' do
|
138
|
-
expect(
|
139
|
+
expect(selector.send(:select, candidates)).to eq([matching_primary])
|
139
140
|
end
|
140
141
|
end
|
141
142
|
|
@@ -144,7 +145,7 @@ describe Mongo::ServerSelector::PrimaryPreferred do
|
|
144
145
|
let(:expected) { [primary] }
|
145
146
|
|
146
147
|
it 'returns an array of the primary' do
|
147
|
-
expect(
|
148
|
+
expect(selector.send(:select, candidates)).to eq(expected)
|
148
149
|
end
|
149
150
|
end
|
150
151
|
|
@@ -153,7 +154,7 @@ describe Mongo::ServerSelector::PrimaryPreferred do
|
|
153
154
|
let(:expected) { [primary] }
|
154
155
|
|
155
156
|
it 'returns an array of the primary ' do
|
156
|
-
expect(
|
157
|
+
expect(selector.send(:select, candidates)).to eq(expected)
|
157
158
|
end
|
158
159
|
end
|
159
160
|
|
@@ -162,7 +163,7 @@ describe Mongo::ServerSelector::PrimaryPreferred do
|
|
162
163
|
let(:expected) { [primary] }
|
163
164
|
|
164
165
|
it 'returns an array of the primary' do
|
165
|
-
expect(
|
166
|
+
expect(selector.send(:select, candidates)).to eq(expected)
|
166
167
|
end
|
167
168
|
end
|
168
169
|
end
|
@@ -178,7 +179,7 @@ describe Mongo::ServerSelector::PrimaryPreferred do
|
|
178
179
|
let(:candidates) { [far_primary] }
|
179
180
|
|
180
181
|
it 'returns array with far primary' do
|
181
|
-
expect(
|
182
|
+
expect(selector.send(:select, candidates)).to eq([far_primary])
|
182
183
|
end
|
183
184
|
end
|
184
185
|
|
@@ -186,7 +187,7 @@ describe Mongo::ServerSelector::PrimaryPreferred do
|
|
186
187
|
let(:candidates) { [far_secondary] }
|
187
188
|
|
188
189
|
it 'returns array with far primary' do
|
189
|
-
expect(
|
190
|
+
expect(selector.send(:select, candidates)).to eq([far_secondary])
|
190
191
|
end
|
191
192
|
|
192
193
|
end
|
@@ -201,7 +202,7 @@ describe Mongo::ServerSelector::PrimaryPreferred do
|
|
201
202
|
let(:expected) { [primary] }
|
202
203
|
|
203
204
|
it 'returns an array of the primary' do
|
204
|
-
expect(
|
205
|
+
expect(selector.send(:select, candidates)).to eq(expected)
|
205
206
|
end
|
206
207
|
end
|
207
208
|
|
@@ -210,7 +211,7 @@ describe Mongo::ServerSelector::PrimaryPreferred do
|
|
210
211
|
let(:expected) { [primary] }
|
211
212
|
|
212
213
|
it 'returns an array of the primary' do
|
213
|
-
expect(
|
214
|
+
expect(selector.send(:select, candidates)).to eq(expected)
|
214
215
|
end
|
215
216
|
end
|
216
217
|
|
@@ -219,7 +220,7 @@ describe Mongo::ServerSelector::PrimaryPreferred do
|
|
219
220
|
let(:expected) { [far_primary] }
|
220
221
|
|
221
222
|
it 'returns an array of the far primary' do
|
222
|
-
expect(
|
223
|
+
expect(selector.send(:select, candidates)).to eq(expected)
|
223
224
|
end
|
224
225
|
end
|
225
226
|
|
@@ -228,7 +229,7 @@ describe Mongo::ServerSelector::PrimaryPreferred do
|
|
228
229
|
let(:expected) { [far_primary] }
|
229
230
|
|
230
231
|
it 'returns an array of the far primary' do
|
231
|
-
expect(
|
232
|
+
expect(selector.send(:select, candidates)).to eq(expected)
|
232
233
|
end
|
233
234
|
end
|
234
235
|
|
@@ -239,7 +240,7 @@ describe Mongo::ServerSelector::PrimaryPreferred do
|
|
239
240
|
let(:expected) { [primary] }
|
240
241
|
|
241
242
|
it 'returns an array of the primary' do
|
242
|
-
expect(
|
243
|
+
expect(selector.send(:select, candidates)).to eq(expected)
|
243
244
|
end
|
244
245
|
end
|
245
246
|
|
@@ -248,7 +249,7 @@ describe Mongo::ServerSelector::PrimaryPreferred do
|
|
248
249
|
let(:expected) { [far_primary] }
|
249
250
|
|
250
251
|
it 'returns an array with primary' do
|
251
|
-
expect(
|
252
|
+
expect(selector.send(:select, candidates)).to eq(expected)
|
252
253
|
end
|
253
254
|
end
|
254
255
|
end
|
@@ -261,7 +262,7 @@ describe Mongo::ServerSelector::PrimaryPreferred do
|
|
261
262
|
let(:expected) { [secondary] }
|
262
263
|
|
263
264
|
it 'returns an array with the secondary' do
|
264
|
-
expect(
|
265
|
+
expect(selector.send(:select, candidates)).to eq(expected)
|
265
266
|
end
|
266
267
|
end
|
267
268
|
|
@@ -270,7 +271,7 @@ describe Mongo::ServerSelector::PrimaryPreferred do
|
|
270
271
|
let(:expected) { [secondary] }
|
271
272
|
|
272
273
|
it 'returns an array of the secondary' do
|
273
|
-
expect(
|
274
|
+
expect(selector.send(:select, candidates)).to eq(expected)
|
274
275
|
end
|
275
276
|
end
|
276
277
|
|
@@ -279,7 +280,7 @@ describe Mongo::ServerSelector::PrimaryPreferred do
|
|
279
280
|
let(:expected) { [secondary, secondary] }
|
280
281
|
|
281
282
|
it 'returns an array of the secondary' do
|
282
|
-
expect(
|
283
|
+
expect(selector.send(:select, candidates)).to eq(expected)
|
283
284
|
end
|
284
285
|
end
|
285
286
|
end
|