mongo 2.0.6 → 2.1.0
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 +5 -2
- data/lib/mongo/address/ipv4.rb +6 -1
- data/lib/mongo/address/unix.rb +2 -2
- data/lib/mongo/address.rb +18 -10
- data/lib/mongo/auth/cr/conversation.rb +1 -1
- data/lib/mongo/auth/ldap/conversation.rb +7 -3
- data/lib/mongo/auth/scram/conversation.rb +9 -3
- data/lib/mongo/auth/user/view.rb +23 -2
- data/lib/mongo/auth/x509/conversation.rb +1 -1
- 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 +191 -0
- data/lib/mongo/bulk_write/result_combiner.rb +117 -0
- data/lib/mongo/bulk_write/transformable.rb +132 -0
- data/lib/mongo/bulk_write/unordered_combiner.rb +52 -0
- data/lib/mongo/bulk_write/validatable.rb +62 -0
- data/lib/mongo/bulk_write.rb +159 -23
- data/lib/mongo/client.rb +52 -16
- data/lib/mongo/cluster/topology/replica_set.rb +27 -9
- data/lib/mongo/cluster/topology/sharded.rb +1 -1
- data/lib/mongo/cluster/topology/unknown.rb +5 -2
- data/lib/mongo/cluster.rb +42 -7
- data/lib/mongo/collection/view/aggregation.rb +48 -9
- data/lib/mongo/collection/view/immutable.rb +6 -6
- data/lib/mongo/collection/view/iterable.rb +18 -4
- data/lib/mongo/collection/view/map_reduce.rb +58 -17
- data/lib/mongo/collection/view/readable.rb +173 -42
- data/lib/mongo/collection/view/writable.rb +37 -23
- data/lib/mongo/collection/view.rb +2 -2
- data/lib/mongo/collection.rb +370 -33
- data/lib/mongo/cursor.rb +15 -3
- data/lib/mongo/database/view.rb +5 -4
- data/lib/mongo/database.rb +14 -4
- data/lib/mongo/dbref.rb +113 -0
- data/lib/mongo/error/closed_stream.rb +34 -0
- data/lib/mongo/error/extra_file_chunk.rb +34 -0
- data/lib/mongo/error/{invalid_uri_option.rb → file_not_found.rb} +11 -12
- 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/parser.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/error.rb +13 -2
- data/lib/mongo/event/description_changed.rb +1 -1
- data/lib/mongo/grid/file/chunk.rb +6 -6
- data/lib/mongo/grid/file/{metadata.rb → info.rb} +41 -39
- data/lib/mongo/grid/file.rb +13 -10
- data/lib/mongo/grid/fs_bucket.rb +448 -0
- data/lib/mongo/grid/stream/read.rb +208 -0
- data/lib/mongo/grid/stream/write.rb +187 -0
- data/lib/mongo/grid/stream.rb +64 -0
- data/lib/mongo/grid.rb +2 -1
- data/lib/mongo/index/view.rb +3 -3
- data/lib/mongo/index.rb +5 -0
- data/lib/mongo/loggable.rb +34 -57
- data/lib/mongo/logger.rb +16 -78
- data/lib/mongo/monitoring/command_log_subscriber.rb +112 -0
- data/lib/mongo/monitoring/event/command_failed.rb +96 -0
- data/lib/mongo/monitoring/event/command_started.rb +89 -0
- data/lib/mongo/monitoring/event/command_succeeded.rb +118 -0
- data/lib/mongo/monitoring/event/secure.rb +58 -0
- data/lib/mongo/monitoring/event.rb +18 -0
- data/lib/mongo/monitoring/publishable.rb +106 -0
- data/lib/mongo/monitoring.rb +195 -0
- data/lib/mongo/operation/{aggregate.rb → commands/aggregate.rb} +3 -41
- data/lib/mongo/operation/commands/collections_info/result.rb +39 -0
- data/lib/mongo/operation/commands/collections_info.rb +68 -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/result.rb +112 -0
- data/lib/mongo/operation/commands/list_collections.rb +54 -0
- data/lib/mongo/operation/commands/list_indexes/result.rb +116 -0
- data/lib/mongo/operation/commands/list_indexes.rb +56 -0
- data/lib/mongo/operation/{map_reduce → commands/map_reduce}/result.rb +1 -1
- data/lib/mongo/operation/{map_reduce.rb → commands/map_reduce.rb} +3 -41
- data/lib/mongo/operation/commands/parallel_scan/result.rb +72 -0
- data/lib/mongo/operation/commands/parallel_scan.rb +56 -0
- data/lib/mongo/operation/commands/user_query.rb +69 -0
- data/lib/mongo/{bulk_write/ordered_bulk_write.rb → operation/commands/users_info/result.rb} +18 -30
- data/lib/mongo/operation/commands/users_info.rb +53 -0
- data/lib/mongo/operation/commands.rb +24 -0
- data/lib/mongo/operation/executable.rb +4 -68
- data/lib/mongo/operation/kill_cursors.rb +3 -3
- data/lib/mongo/operation/read/get_more.rb +2 -22
- data/lib/mongo/{bulk_write/unordered_bulk_write.rb → operation/read/query/result.rb} +20 -26
- data/lib/mongo/operation/read/query.rb +4 -21
- data/lib/mongo/operation/read.rb +0 -4
- data/lib/mongo/operation/{read_preferrable.rb → read_preference.rb} +3 -2
- data/lib/mongo/operation/result.rb +13 -1
- data/lib/mongo/operation/specifiable.rb +42 -0
- data/lib/mongo/operation/write/bulk/bulkable.rb +82 -0
- data/lib/mongo/operation/write/bulk/delete/result.rb +74 -0
- data/lib/mongo/operation/write/bulk/delete.rb +71 -0
- data/lib/mongo/operation/write/bulk/insert/result.rb +129 -0
- data/lib/mongo/operation/write/bulk/insert.rb +96 -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/result.rb +174 -0
- data/lib/mongo/operation/write/bulk/update.rb +81 -0
- data/lib/mongo/operation/write/bulk.rb +6 -3
- 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 +6 -29
- 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 +13 -36
- data/lib/mongo/operation/write/update_user.rb +4 -30
- data/lib/mongo/operation/write/write_command_enabled.rb +53 -0
- data/lib/mongo/operation/write.rb +2 -0
- data/lib/mongo/operation.rb +32 -4
- data/lib/mongo/options/mapper.rb +4 -2
- data/lib/mongo/options/redacted.rb +156 -0
- data/lib/mongo/options.rb +1 -0
- data/lib/mongo/protocol/delete.rb +75 -15
- data/lib/mongo/protocol/get_more.rb +65 -13
- data/lib/mongo/protocol/insert.rb +85 -13
- data/lib/mongo/protocol/kill_cursors.rb +59 -14
- data/lib/mongo/protocol/message.rb +12 -12
- data/lib/mongo/protocol/query.rb +163 -37
- data/lib/mongo/protocol/reply.rb +103 -0
- data/lib/mongo/protocol/serializers.rb +1 -1
- data/lib/mongo/protocol/update.rb +82 -14
- data/lib/mongo/retryable.rb +83 -0
- data/lib/mongo/server/connectable.rb +21 -25
- data/lib/mongo/server/connection.rb +75 -4
- data/lib/mongo/server/connection_pool/queue.rb +15 -0
- data/lib/mongo/server/connection_pool.rb +12 -0
- data/lib/mongo/server/description/features.rb +2 -1
- data/lib/mongo/server/description.rb +52 -1
- data/lib/mongo/server/monitor/connection.rb +26 -2
- data/lib/mongo/server/monitor.rb +19 -3
- data/lib/mongo/server.rb +39 -5
- data/lib/mongo/server_selector/selectable.rb +40 -31
- data/lib/mongo/server_selector.rb +19 -10
- data/lib/mongo/socket/ssl.rb +28 -16
- data/lib/mongo/socket/tcp.rb +3 -3
- data/lib/mongo/socket/unix.rb +5 -8
- data/lib/mongo/socket.rb +11 -4
- data/lib/mongo/uri.rb +248 -137
- data/lib/mongo/version.rb +1 -1
- data/lib/mongo.rb +5 -3
- data/spec/mongo/address/unix_spec.rb +1 -1
- data/spec/mongo/address_spec.rb +25 -0
- data/spec/mongo/auth/cr_spec.rb +9 -1
- data/spec/mongo/auth/ldap/conversation_spec.rb +43 -0
- data/spec/mongo/auth/ldap_spec.rb +9 -1
- data/spec/mongo/auth/scram_spec.rb +9 -1
- data/spec/mongo/auth/user/view_spec.rb +26 -1
- data/spec/mongo/auth/x509_spec.rb +9 -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 +428 -0
- data/spec/mongo/client_spec.rb +167 -17
- data/spec/mongo/cluster/topology/replica_set_spec.rb +18 -9
- data/spec/mongo/cluster/topology/sharded_spec.rb +11 -3
- data/spec/mongo/cluster/topology/single_spec.rb +12 -4
- data/spec/mongo/cluster_spec.rb +55 -10
- data/spec/mongo/collection/view/aggregation_spec.rb +188 -1
- data/spec/mongo/collection/view/explainable_spec.rb +1 -1
- data/spec/mongo/collection/view/immutable_spec.rb +103 -0
- data/spec/mongo/collection/view/map_reduce_spec.rb +99 -4
- data/spec/mongo/collection/view/readable_spec.rb +238 -6
- data/spec/mongo/collection/view/writable_spec.rb +4 -4
- data/spec/mongo/collection/view_spec.rb +459 -71
- data/spec/mongo/collection_spec.rb +1291 -9
- data/spec/mongo/command_monitoring_spec.rb +51 -0
- data/spec/mongo/connection_string_spec.rb +115 -0
- data/spec/mongo/crud_spec.rb +2 -2
- data/spec/mongo/cursor_spec.rb +3 -3
- data/spec/mongo/database_spec.rb +47 -11
- data/spec/mongo/dbref_spec.rb +149 -0
- 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/monitoring/event/command_started_spec.rb +26 -0
- data/spec/mongo/monitoring/event/command_succeeded_spec.rb +26 -0
- data/spec/mongo/monitoring/event/secure_spec.rb +57 -0
- data/spec/mongo/monitoring_spec.rb +168 -0
- data/spec/mongo/operation/commands/aggregate_spec.rb +69 -0
- data/spec/mongo/operation/{read → commands}/collections_info_spec.rb +1 -1
- data/spec/mongo/operation/{command_spec.rb → commands/command_spec.rb} +0 -18
- data/spec/mongo/operation/{read → commands}/indexes_spec.rb +1 -1
- data/spec/mongo/operation/{map_reduce_spec.rb → commands/map_reduce_spec.rb} +1 -19
- data/spec/mongo/operation/kill_cursors_spec.rb +1 -17
- data/spec/mongo/operation/read/get_more_spec.rb +0 -16
- data/spec/mongo/operation/read/query_spec.rb +19 -16
- 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} +18 -29
- data/spec/mongo/operation/write/bulk/{bulk_insert_spec.rb → insert_spec.rb} +3 -14
- data/spec/mongo/operation/write/bulk/{bulk_update_spec.rb → update_spec.rb} +8 -19
- data/spec/mongo/operation/write/command/delete_spec.rb +0 -16
- data/spec/mongo/operation/write/command/insert_spec.rb +0 -16
- data/spec/mongo/operation/write/command/update_spec.rb +0 -16
- data/spec/mongo/operation/write/delete_spec.rb +4 -4
- data/spec/mongo/operation/write/insert_spec.rb +2 -13
- data/spec/mongo/operation/write/update_spec.rb +7 -7
- data/spec/mongo/options/redacted_spec.rb +350 -0
- data/spec/mongo/protocol/kill_cursors_spec.rb +5 -3
- data/spec/mongo/protocol/query_spec.rb +15 -30
- data/spec/mongo/retryable_spec.rb +147 -0
- data/spec/mongo/server/connection_pool/queue_spec.rb +16 -0
- data/spec/mongo/server/connection_pool_spec.rb +50 -6
- data/spec/mongo/server/connection_spec.rb +49 -4
- data/spec/mongo/server/description_spec.rb +49 -3
- data/spec/mongo/server/monitor_spec.rb +51 -0
- data/spec/mongo/server_discovery_and_monitoring_spec.rb +32 -59
- data/spec/mongo/server_selection_rtt_spec.rb +37 -57
- data/spec/mongo/server_selection_spec.rb +19 -9
- data/spec/mongo/server_selector/nearest_spec.rb +35 -27
- data/spec/mongo/server_selector/primary_preferred_spec.rb +32 -30
- data/spec/mongo/server_selector/primary_spec.rb +21 -14
- data/spec/mongo/server_selector/secondary_preferred_spec.rb +28 -26
- data/spec/mongo/server_selector/secondary_spec.rb +24 -22
- data/spec/mongo/server_selector_spec.rb +87 -24
- data/spec/mongo/server_spec.rb +94 -8
- data/spec/mongo/socket/ssl_spec.rb +123 -13
- data/spec/mongo/socket/unix_spec.rb +52 -0
- data/spec/mongo/uri_spec.rb +295 -67
- data/spec/spec_helper.rb +40 -24
- data/spec/support/authorization.rb +23 -9
- data/spec/support/certificates/client.pem +4 -4
- 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/command_monitoring.rb +365 -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/read.rb +22 -19
- data/spec/support/crud/write.rb +58 -27
- data/spec/support/crud.rb +10 -2
- 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/matchers.rb +1 -1
- data/spec/support/sdam/rs/equal_electionids.yml +44 -0
- data/spec/support/sdam/rs/new_primary_new_electionid.yml +95 -0
- data/spec/support/sdam/rs/null_election_id.yml +144 -0
- data/spec/support/sdam/rs/primary_disconnect_electionid.yml +124 -0
- 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/sharded/mongos_disconnect.yml +104 -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 +22 -3
- data/spec/support/server_selection.rb +3 -1
- data/spec/support/shared/bulk_write.rb +218 -22
- data/spec/support/shared/server_selector.rb +80 -14
- data.tar.gz.sig +0 -0
- metadata +188 -59
- metadata.gz.sig +0 -0
- data/lib/mongo/bulk_write/bulk_writable.rb +0 -196
- data/lib/mongo/bulk_write/deletable.rb +0 -56
- data/lib/mongo/bulk_write/insertable.rb +0 -48
- data/lib/mongo/bulk_write/replacable.rb +0 -57
- data/lib/mongo/bulk_write/updatable.rb +0 -68
- data/lib/mongo/grid/fs.rb +0 -149
- 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/result.rb +0 -75
- data/lib/mongo/operation/write/bulk/bulk_delete.rb +0 -145
- data/lib/mongo/operation/write/bulk/bulk_insert/result.rb +0 -130
- data/lib/mongo/operation/write/bulk/bulk_insert.rb +0 -132
- data/lib/mongo/operation/write/bulk/bulk_mergable.rb +0 -67
- data/lib/mongo/operation/write/bulk/bulk_update/result.rb +0 -162
- data/lib/mongo/operation/write/bulk/bulk_update.rb +0 -154
- data/lib/mongo/operation/write/bulk/legacy_bulk_mergable.rb +0 -83
- data/spec/mongo/bulk/bulk_write_spec.rb +0 -262
- data/spec/mongo/grid/fs_spec.rb +0 -160
- data/spec/mongo/loggable_spec.rb +0 -63
- data/spec/mongo/operation/aggregate_spec.rb +0 -127
- /data/lib/mongo/operation/{aggregate → commands/aggregate}/result.rb +0 -0
@@ -6,22 +6,30 @@ describe Mongo::Cluster::Topology::ReplicaSet do
|
|
6
6
|
Mongo::Address.new('127.0.0.1:27017')
|
7
7
|
end
|
8
8
|
|
9
|
+
let(:listeners) do
|
10
|
+
Mongo::Event::Listeners.new
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:monitoring) do
|
14
|
+
Mongo::Monitoring.new
|
15
|
+
end
|
16
|
+
|
9
17
|
describe '#servers' do
|
10
18
|
|
11
19
|
let(:mongos) do
|
12
|
-
Mongo::Server.new(address, double('cluster'),
|
20
|
+
Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
|
13
21
|
end
|
14
22
|
|
15
23
|
let(:standalone) do
|
16
|
-
Mongo::Server.new(address, double('cluster'),
|
24
|
+
Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
|
17
25
|
end
|
18
26
|
|
19
27
|
let(:replica_set) do
|
20
|
-
Mongo::Server.new(address, double('cluster'),
|
28
|
+
Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
|
21
29
|
end
|
22
30
|
|
23
31
|
let(:replica_set_two) do
|
24
|
-
Mongo::Server.new(address, double('cluster'),
|
32
|
+
Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
|
25
33
|
end
|
26
34
|
|
27
35
|
let(:mongos_description) do
|
@@ -102,11 +110,11 @@ describe Mongo::Cluster::Topology::ReplicaSet do
|
|
102
110
|
describe '#add_hosts?' do
|
103
111
|
|
104
112
|
let(:primary) do
|
105
|
-
Mongo::Server.new(address, double('cluster'),
|
113
|
+
Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
|
106
114
|
end
|
107
115
|
|
108
116
|
let(:secondary) do
|
109
|
-
Mongo::Server.new(address, double('cluster'),
|
117
|
+
Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
|
110
118
|
end
|
111
119
|
|
112
120
|
let(:primary_description) do
|
@@ -183,7 +191,7 @@ describe Mongo::Cluster::Topology::ReplicaSet do
|
|
183
191
|
describe '#remove_hosts?' do
|
184
192
|
|
185
193
|
let(:primary) do
|
186
|
-
Mongo::Server.new(address, double('cluster'),
|
194
|
+
Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
|
187
195
|
end
|
188
196
|
|
189
197
|
let(:primary_description) do
|
@@ -231,6 +239,7 @@ describe Mongo::Cluster::Topology::ReplicaSet do
|
|
231
239
|
double('description').tap do |d|
|
232
240
|
allow(d).to receive(:config).and_return({ 'ismaster' => true })
|
233
241
|
allow(d).to receive(:primary?).and_return(false)
|
242
|
+
allow(d).to receive(:me_mismatch?).and_return(false)
|
234
243
|
allow(d).to receive(:hosts).and_return([])
|
235
244
|
end
|
236
245
|
end
|
@@ -249,6 +258,7 @@ describe Mongo::Cluster::Topology::ReplicaSet do
|
|
249
258
|
allow(d).to receive(:hosts).and_return([ primary ])
|
250
259
|
allow(d).to receive(:replica_set_name).and_return('test')
|
251
260
|
allow(d).to receive(:replica_set_member?).and_return(true)
|
261
|
+
allow(d).to receive(:me_mismatch?).and_return(false)
|
252
262
|
end
|
253
263
|
end
|
254
264
|
|
@@ -262,7 +272,7 @@ describe Mongo::Cluster::Topology::ReplicaSet do
|
|
262
272
|
describe '#remove_server?' do
|
263
273
|
|
264
274
|
let(:secondary) do
|
265
|
-
Mongo::Server.new(address, double('cluster'),
|
275
|
+
Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
|
266
276
|
end
|
267
277
|
|
268
278
|
let(:secondary_description) do
|
@@ -346,6 +356,5 @@ describe Mongo::Cluster::Topology::ReplicaSet do
|
|
346
356
|
expect(topology.remove_server?(description, secondary)).to eq(false)
|
347
357
|
end
|
348
358
|
end
|
349
|
-
|
350
359
|
end
|
351
360
|
end
|
@@ -10,17 +10,24 @@ describe Mongo::Cluster::Topology::Sharded do
|
|
10
10
|
described_class.new({})
|
11
11
|
end
|
12
12
|
|
13
|
+
let(:monitoring) do
|
14
|
+
Mongo::Monitoring.new
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:listeners) do
|
18
|
+
Mongo::Event::Listeners.new
|
19
|
+
end
|
13
20
|
|
14
21
|
let(:mongos) do
|
15
|
-
Mongo::Server.new(address, double('cluster'),
|
22
|
+
Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
|
16
23
|
end
|
17
24
|
|
18
25
|
let(:standalone) do
|
19
|
-
Mongo::Server.new(address, double('cluster'),
|
26
|
+
Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
|
20
27
|
end
|
21
28
|
|
22
29
|
let(:replica_set) do
|
23
|
-
Mongo::Server.new(address, double('cluster'),
|
30
|
+
Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
|
24
31
|
end
|
25
32
|
|
26
33
|
let(:mongos_description) do
|
@@ -99,6 +106,7 @@ describe Mongo::Cluster::Topology::Sharded do
|
|
99
106
|
let(:description) do
|
100
107
|
double('description').tap do |d|
|
101
108
|
allow(d).to receive(:mongos?).and_return(false)
|
109
|
+
allow(d).to receive(:unknown?).and_return(false)
|
102
110
|
allow(d).to receive(:is_server?).and_return(true)
|
103
111
|
end
|
104
112
|
end
|
@@ -10,22 +10,30 @@ describe Mongo::Cluster::Topology::Single do
|
|
10
10
|
described_class.new({})
|
11
11
|
end
|
12
12
|
|
13
|
+
let(:monitoring) do
|
14
|
+
Mongo::Monitoring.new
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:listeners) do
|
18
|
+
Mongo::Event::Listeners.new
|
19
|
+
end
|
20
|
+
|
13
21
|
describe '.servers' do
|
14
22
|
|
15
23
|
let(:mongos) do
|
16
|
-
Mongo::Server.new(address, double('cluster'),
|
24
|
+
Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
|
17
25
|
end
|
18
26
|
|
19
27
|
let(:standalone) do
|
20
|
-
Mongo::Server.new(address, double('cluster'),
|
28
|
+
Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
|
21
29
|
end
|
22
30
|
|
23
31
|
let(:standalone_two) do
|
24
|
-
Mongo::Server.new(address, double('cluster'),
|
32
|
+
Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
|
25
33
|
end
|
26
34
|
|
27
35
|
let(:replica_set) do
|
28
|
-
Mongo::Server.new(address, double('cluster'),
|
36
|
+
Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
|
29
37
|
end
|
30
38
|
|
31
39
|
let(:mongos_description) do
|
data/spec/mongo/cluster_spec.rb
CHANGED
@@ -2,8 +2,12 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Mongo::Cluster do
|
4
4
|
|
5
|
+
let(:monitoring) do
|
6
|
+
Mongo::Monitoring.new
|
7
|
+
end
|
8
|
+
|
5
9
|
let(:cluster) do
|
6
|
-
described_class.new(ADDRESSES, TEST_OPTIONS)
|
10
|
+
described_class.new(ADDRESSES, monitoring, TEST_OPTIONS)
|
7
11
|
end
|
8
12
|
|
9
13
|
describe '#==' do
|
@@ -15,7 +19,7 @@ describe Mongo::Cluster do
|
|
15
19
|
context 'when the options are the same' do
|
16
20
|
|
17
21
|
let(:other) do
|
18
|
-
described_class.new(ADDRESSES, TEST_OPTIONS)
|
22
|
+
described_class.new(ADDRESSES, monitoring, TEST_OPTIONS)
|
19
23
|
end
|
20
24
|
|
21
25
|
it 'returns true' do
|
@@ -26,7 +30,7 @@ describe Mongo::Cluster do
|
|
26
30
|
context 'when the options are not the same' do
|
27
31
|
|
28
32
|
let(:other) do
|
29
|
-
described_class.new([ '127.0.0.1:27017' ], TEST_OPTIONS.merge(:replica_set => 'test'))
|
33
|
+
described_class.new([ '127.0.0.1:27017' ], monitoring, TEST_OPTIONS.merge(:replica_set => 'test'))
|
30
34
|
end
|
31
35
|
|
32
36
|
it 'returns false' do
|
@@ -38,7 +42,7 @@ describe Mongo::Cluster do
|
|
38
42
|
context 'when the addresses are not the same' do
|
39
43
|
|
40
44
|
let(:other) do
|
41
|
-
described_class.new([ '127.0.0.1:27018' ], TEST_OPTIONS)
|
45
|
+
described_class.new([ '127.0.0.1:27018' ], monitoring, TEST_OPTIONS)
|
42
46
|
end
|
43
47
|
|
44
48
|
it 'returns false' do
|
@@ -76,8 +80,11 @@ describe Mongo::Cluster do
|
|
76
80
|
context 'when the option is provided' do
|
77
81
|
|
78
82
|
let(:cluster) do
|
79
|
-
described_class.new(
|
80
|
-
|
83
|
+
described_class.new(
|
84
|
+
[ '127.0.0.1:27017' ],
|
85
|
+
monitoring,
|
86
|
+
TEST_OPTIONS.merge(:connect => :replica_set, :replica_set => 'testing')
|
87
|
+
)
|
81
88
|
end
|
82
89
|
|
83
90
|
it 'returns the name' do
|
@@ -88,7 +95,7 @@ describe Mongo::Cluster do
|
|
88
95
|
context 'when the option is not provided' do
|
89
96
|
|
90
97
|
let(:cluster) do
|
91
|
-
described_class.new([ '127.0.0.1:27017' ], TEST_OPTIONS.dup.delete_if { |k| k == :replica_set })
|
98
|
+
described_class.new([ '127.0.0.1:27017' ], monitoring, TEST_OPTIONS.dup.delete_if { |k| k == :replica_set })
|
92
99
|
end
|
93
100
|
|
94
101
|
it 'returns nil' do
|
@@ -210,6 +217,36 @@ describe Mongo::Cluster do
|
|
210
217
|
end
|
211
218
|
end
|
212
219
|
|
220
|
+
describe '#disconnect!' do
|
221
|
+
|
222
|
+
let(:known_servers) do
|
223
|
+
cluster.instance_variable_get(:@servers)
|
224
|
+
end
|
225
|
+
|
226
|
+
before do
|
227
|
+
known_servers.each do |server|
|
228
|
+
expect(server).to receive(:disconnect!).and_call_original
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
it 'disconnects each server and returns true' do
|
233
|
+
expect(cluster.disconnect!).to be(true)
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
describe '#reconnect!' do
|
238
|
+
|
239
|
+
before do
|
240
|
+
cluster.servers.each do |server|
|
241
|
+
expect(server).to receive(:reconnect!).and_call_original
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
it 'reconnects each server and returns true' do
|
246
|
+
expect(cluster.reconnect!).to be(true)
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
213
250
|
describe '#remove' do
|
214
251
|
|
215
252
|
let(:address_a) do
|
@@ -220,12 +257,16 @@ describe Mongo::Cluster do
|
|
220
257
|
Mongo::Address.new('127.0.0.1:27018')
|
221
258
|
end
|
222
259
|
|
260
|
+
let(:monitoring) do
|
261
|
+
Mongo::Monitoring.new
|
262
|
+
end
|
263
|
+
|
223
264
|
let(:server_a) do
|
224
|
-
Mongo::Server.new(address_a, cluster, Mongo::Event::Listeners.new)
|
265
|
+
Mongo::Server.new(address_a, cluster, monitoring, Mongo::Event::Listeners.new)
|
225
266
|
end
|
226
267
|
|
227
268
|
let(:server_b) do
|
228
|
-
Mongo::Server.new(address_b, cluster, Mongo::Event::Listeners.new)
|
269
|
+
Mongo::Server.new(address_b, cluster, monitoring, Mongo::Event::Listeners.new)
|
229
270
|
end
|
230
271
|
|
231
272
|
let(:servers) do
|
@@ -309,8 +350,12 @@ describe Mongo::Cluster do
|
|
309
350
|
Mongo::Address.new('127.0.0.1:27017')
|
310
351
|
end
|
311
352
|
|
353
|
+
let(:monitoring) do
|
354
|
+
Mongo::Monitoring.new
|
355
|
+
end
|
356
|
+
|
312
357
|
let(:server) do
|
313
|
-
Mongo::Server.new(address, cluster, listeners)
|
358
|
+
Mongo::Server.new(address, cluster, monitoring, listeners)
|
314
359
|
end
|
315
360
|
|
316
361
|
let(:servers) do
|
@@ -61,7 +61,7 @@ describe Mongo::Collection::View::Aggregation do
|
|
61
61
|
end
|
62
62
|
|
63
63
|
after do
|
64
|
-
authorized_collection.
|
64
|
+
authorized_collection.delete_many
|
65
65
|
end
|
66
66
|
|
67
67
|
context 'when a block is provided' do
|
@@ -176,6 +176,193 @@ describe Mongo::Collection::View::Aggregation do
|
|
176
176
|
it 'includes the option in the spec' do
|
177
177
|
expect(aggregation.send(:aggregate_spec)[:selector][:allowDiskUse]).to eq(true)
|
178
178
|
end
|
179
|
+
|
180
|
+
context 'when allow_disk_use is specified as an option' do
|
181
|
+
|
182
|
+
let(:options) do
|
183
|
+
{ :allow_disk_use => true }
|
184
|
+
end
|
185
|
+
|
186
|
+
let(:aggregation) do
|
187
|
+
described_class.new(view, pipeline, options)
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'includes the option in the spec' do
|
191
|
+
expect(aggregation.send(:aggregate_spec)[:selector][:allowDiskUse]).to eq(true)
|
192
|
+
end
|
193
|
+
|
194
|
+
context 'when #allow_disk_use is also called' do
|
195
|
+
|
196
|
+
let(:options) do
|
197
|
+
{ :allow_disk_use => true }
|
198
|
+
end
|
199
|
+
|
200
|
+
let(:aggregation) do
|
201
|
+
described_class.new(view, pipeline, options).allow_disk_use(false)
|
202
|
+
end
|
203
|
+
|
204
|
+
it 'overrides the first option with the second' do
|
205
|
+
expect(aggregation.send(:aggregate_spec)[:selector][:allowDiskUse]).to eq(false)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
context 'when max_time_ms is an option' do
|
212
|
+
|
213
|
+
let(:options) do
|
214
|
+
{ :max_time_ms => 100 }
|
215
|
+
end
|
216
|
+
|
217
|
+
it 'includes the option in the spec' do
|
218
|
+
expect(aggregation.send(:aggregate_spec)[:selector][:maxTimeMS]).to eq(options[:max_time_ms])
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
context 'when batch_size is set' do
|
223
|
+
|
224
|
+
context 'when batch_size is set on the view' do
|
225
|
+
|
226
|
+
let(:view_options) do
|
227
|
+
{ :batch_size => 10 }
|
228
|
+
end
|
229
|
+
|
230
|
+
it 'uses the batch_size on the view' do
|
231
|
+
expect(aggregation.send(:aggregate_spec)[:selector][:cursor][:batchSize]).to eq(view_options[:batch_size])
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
context 'when batch_size is provided in the options' do
|
236
|
+
|
237
|
+
let(:options) do
|
238
|
+
{ :batch_size => 20 }
|
239
|
+
end
|
240
|
+
|
241
|
+
it 'includes the option in the spec' do
|
242
|
+
expect(aggregation.send(:aggregate_spec)[:selector][:cursor][:batchSize]).to eq(options[:batch_size])
|
243
|
+
end
|
244
|
+
|
245
|
+
context 'when batch_size is also set on the view' do
|
246
|
+
|
247
|
+
let(:view_options) do
|
248
|
+
{ :batch_size => 10 }
|
249
|
+
end
|
250
|
+
|
251
|
+
it 'overrides the view batch_size with the option batch_size' do
|
252
|
+
expect(aggregation.send(:aggregate_spec)[:selector][:cursor][:batchSize]).to eq(options[:batch_size])
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
context 'when use_cursor is set' do
|
259
|
+
|
260
|
+
context 'when use_cursor is true' do
|
261
|
+
|
262
|
+
context 'when batch_size is set' do
|
263
|
+
|
264
|
+
let(:options) do
|
265
|
+
{ :use_cursor => true,
|
266
|
+
:batch_size => 10
|
267
|
+
}
|
268
|
+
end
|
269
|
+
|
270
|
+
it 'sets a batch size document in the spec' do
|
271
|
+
expect(aggregation.send(:aggregate_spec)[:selector][:cursor][:batchSize]).to eq(options[:batch_size])
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
context 'when batch_size is not set' do
|
276
|
+
|
277
|
+
let(:options) do
|
278
|
+
{ :use_cursor => true }
|
279
|
+
end
|
280
|
+
|
281
|
+
it 'sets an empty document in the spec' do
|
282
|
+
expect(aggregation.send(:aggregate_spec)[:selector][:cursor]).to eq({})
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
end
|
287
|
+
|
288
|
+
context 'when use_cursor is false' do
|
289
|
+
|
290
|
+
let(:options) do
|
291
|
+
{ :use_cursor => false }
|
292
|
+
end
|
293
|
+
|
294
|
+
context 'when batch_size is set' do
|
295
|
+
|
296
|
+
it 'does not set the cursor option in the spec' do
|
297
|
+
expect(aggregation.send(:aggregate_spec)[:selector][:cursor]).to be_nil
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
context 'when $out is in the pipeline', if: write_command_enabled? do
|
305
|
+
|
306
|
+
let(:pipeline) do
|
307
|
+
[{
|
308
|
+
"$group" => {
|
309
|
+
"_id" => "$city",
|
310
|
+
"totalpop" => { "$sum" => "$pop" }
|
311
|
+
}
|
312
|
+
},
|
313
|
+
{
|
314
|
+
'$out' => 'output_collection'
|
315
|
+
}
|
316
|
+
]
|
317
|
+
end
|
318
|
+
|
319
|
+
after do
|
320
|
+
authorized_client['output_collection'].delete_many
|
321
|
+
end
|
322
|
+
|
323
|
+
context 'when $out is a string' do
|
324
|
+
|
325
|
+
it 'does not allow the operation on a secondary' do
|
326
|
+
expect(aggregation.send(:secondary_ok?)).to be(false)
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
context 'when $out is a symbol' do
|
331
|
+
|
332
|
+
let(:pipeline) do
|
333
|
+
[{
|
334
|
+
"$group" => {
|
335
|
+
"_id" => "$city",
|
336
|
+
"totalpop" => { "$sum" => "$pop" }
|
337
|
+
}
|
338
|
+
},
|
339
|
+
{
|
340
|
+
:$out => 'output_collection'
|
341
|
+
}
|
342
|
+
]
|
343
|
+
end
|
344
|
+
|
345
|
+
it 'does not allow the operation on a secondary' do
|
346
|
+
expect(aggregation.send(:secondary_ok?)).to be(false)
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
|
351
|
+
context 'when the context is not a valid server for writing' do
|
352
|
+
|
353
|
+
it 'reroutes the operation to a primary' do
|
354
|
+
allow(aggregation).to receive(:valid_server?).and_return(false)
|
355
|
+
expect(Mongo::Logger.logger).to receive(:warn?).and_call_original
|
356
|
+
aggregation.to_a
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
360
|
+
context 'when the context is a valid server for writing' do
|
361
|
+
|
362
|
+
it 'does not reroute the operation to a primary' do
|
363
|
+
expect(Mongo::Logger.logger).not_to receive(:warn?)
|
364
|
+
aggregation.to_a
|
365
|
+
end
|
179
366
|
end
|
180
367
|
end
|
181
368
|
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mongo::Collection::View::Immutable do
|
4
|
+
|
5
|
+
let(:selector) do
|
6
|
+
{}
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:options) do
|
10
|
+
{}
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:view) do
|
14
|
+
Mongo::Collection::View.new(authorized_collection, selector, options)
|
15
|
+
end
|
16
|
+
|
17
|
+
after do
|
18
|
+
authorized_collection.delete_many
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#configure' do
|
22
|
+
|
23
|
+
context 'when the options has a modifiers document' do
|
24
|
+
|
25
|
+
let(:options) do
|
26
|
+
{ modifiers: { :$maxTimeMS => 500 } }
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:new_view) do
|
30
|
+
view.projection(_id: 1)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'returns a new view' do
|
34
|
+
expect(view).not_to be(new_view)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'creates a new options hash' do
|
38
|
+
expect(view.options).not_to be(new_view.options)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'keeps the modifier fields already in the options hash' do
|
42
|
+
expect(new_view.modifiers[:$maxTimeMS]).to eq(500)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'sets the option' do
|
46
|
+
expect(new_view.projection).to eq(_id: 1)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'creates a new modifiers document' do
|
50
|
+
expect(view.modifiers).not_to be(new_view.modifiers)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#configure_modifier' do
|
56
|
+
|
57
|
+
let(:new_view) do
|
58
|
+
view.sort('x' => Mongo::Index::ASCENDING)
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'when the options does not have a modifiers document' do
|
62
|
+
|
63
|
+
it 'returns a new view' do
|
64
|
+
expect(view).not_to be(new_view)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'returns a new view with the modifiers document containing the option' do
|
68
|
+
expect(new_view.modifiers[:$orderby]).to eq({ 'x' => Mongo::Index::ASCENDING })
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'when the options has a modifiers document' do
|
73
|
+
|
74
|
+
let(:options) do
|
75
|
+
{ modifiers: { :$maxTimeMS => 500 } }
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'returns a new view' do
|
79
|
+
expect(view).not_to be(new_view)
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'creates a new options hash' do
|
83
|
+
expect(view.options).not_to be(new_view.options)
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'keeps the fields already in the options hash and merges in the new one' do
|
87
|
+
expect(new_view.modifiers[:$maxTimeMS]).to eq(500)
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'sets the new value in the new view modifier document' do
|
91
|
+
expect(new_view.modifiers[:$orderby]).to eq('x' => Mongo::Index::ASCENDING)
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'returns that value when the corresponding option method is called' do
|
95
|
+
expect(new_view.sort).to eq({ 'x' => Mongo::Index::ASCENDING })
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'creates a new modifiers document' do
|
99
|
+
expect(view.modifiers).not_to be(new_view.modifiers)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|