mongo 2.4.3 → 2.5.0.beta
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 +3 -2
- data.tar.gz.sig +0 -0
- data/lib/mongo.rb +3 -2
- data/lib/mongo/auth/cr.rb +6 -4
- data/lib/mongo/auth/cr/conversation.rb +33 -17
- data/lib/mongo/auth/ldap.rb +4 -2
- data/lib/mongo/auth/ldap/conversation.rb +19 -9
- data/lib/mongo/auth/scram.rb +7 -4
- data/lib/mongo/auth/scram/conversation.rb +62 -24
- data/lib/mongo/auth/user.rb +10 -0
- data/lib/mongo/auth/user/view.rb +44 -22
- data/lib/mongo/auth/x509.rb +4 -2
- data/lib/mongo/auth/x509/conversation.rb +19 -9
- data/lib/mongo/bulk_write.rb +33 -27
- data/lib/mongo/bulk_write/combineable.rb +5 -0
- data/lib/mongo/bulk_write/transformable.rb +2 -0
- data/lib/mongo/bulk_write/validatable.rb +4 -0
- data/lib/mongo/client.rb +123 -12
- data/lib/mongo/cluster.rb +52 -11
- data/lib/mongo/cluster/app_metadata.rb +8 -2
- data/lib/mongo/cluster/cursor_reaper.rb +0 -1
- data/lib/mongo/cluster/topology.rb +1 -1
- data/lib/mongo/collection.rb +114 -27
- data/lib/mongo/collection/view.rb +8 -2
- data/lib/mongo/collection/view/aggregation.rb +11 -7
- data/lib/mongo/collection/view/builder/aggregation.rb +5 -1
- data/lib/mongo/collection/view/builder/find_command.rb +5 -3
- data/lib/mongo/collection/view/builder/map_reduce.rb +11 -3
- data/lib/mongo/collection/view/builder/op_query.rb +1 -1
- data/lib/mongo/collection/view/change_stream.rb +160 -0
- data/lib/mongo/collection/view/change_stream/retryable.rb +57 -0
- data/lib/mongo/collection/view/iterable.rb +11 -10
- data/lib/mongo/collection/view/map_reduce.rb +22 -18
- data/lib/mongo/collection/view/readable.rb +51 -37
- data/lib/mongo/collection/view/writable.rb +72 -40
- data/lib/mongo/cursor.rb +25 -4
- data/lib/mongo/cursor/builder/get_more_command.rb +4 -2
- data/lib/mongo/database.rb +22 -11
- data/lib/mongo/database/view.rb +16 -12
- data/lib/mongo/error.rb +5 -0
- data/lib/mongo/error/invalid_session.rb +36 -0
- data/lib/mongo/error/missing_resume_token.rb +39 -0
- data/lib/mongo/error/operation_failure.rb +17 -0
- data/lib/mongo/error/parser.rb +3 -2
- data/lib/mongo/error/unknown_payload_type.rb +41 -0
- data/lib/mongo/error/unsupported_array_filters.rb +51 -0
- data/lib/mongo/error/unsupported_message_type.rb +23 -0
- data/lib/mongo/grid/fs_bucket.rb +5 -4
- data/lib/mongo/grid/stream/read.rb +3 -2
- data/lib/mongo/grid/stream/write.rb +2 -2
- data/lib/mongo/index/view.rb +35 -25
- data/lib/mongo/monitoring/event/secure.rb +14 -0
- data/lib/mongo/operation.rb +16 -0
- data/lib/mongo/operation/commands.rb +1 -0
- data/lib/mongo/operation/commands/aggregate.rb +9 -5
- data/lib/mongo/operation/commands/aggregate/result.rb +1 -1
- data/lib/mongo/operation/commands/collections_info.rb +6 -6
- data/lib/mongo/operation/commands/command.rb +2 -1
- data/lib/mongo/operation/commands/create.rb +6 -2
- data/lib/mongo/operation/commands/drop.rb +6 -2
- data/lib/mongo/operation/commands/drop_database.rb +6 -2
- data/lib/mongo/operation/commands/explain.rb +27 -0
- data/lib/mongo/operation/commands/explain/result.rb +52 -0
- data/lib/mongo/operation/commands/indexes.rb +1 -1
- 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 +8 -4
- data/lib/mongo/operation/commands/map_reduce/result.rb +13 -1
- data/lib/mongo/operation/commands/user_query.rb +1 -1
- data/lib/mongo/operation/commands/users_info.rb +6 -2
- data/lib/mongo/operation/executable.rb +4 -1
- data/lib/mongo/operation/read_preference.rb +10 -5
- data/lib/mongo/operation/result.rb +26 -2
- data/lib/mongo/operation/specifiable.rb +13 -1
- data/lib/mongo/operation/uses_command_op_msg.rb +47 -0
- data/lib/mongo/operation/write/bulk/bulkable.rb +4 -1
- data/lib/mongo/operation/write/bulk/insert/result.rb +4 -4
- data/lib/mongo/operation/write/command/create_index.rb +6 -1
- data/lib/mongo/operation/write/command/delete.rb +28 -4
- data/lib/mongo/operation/write/command/drop_index.rb +6 -1
- data/lib/mongo/operation/write/command/insert.rb +22 -18
- data/lib/mongo/operation/write/command/update.rb +24 -9
- data/lib/mongo/operation/write/command/writable.rb +14 -1
- data/lib/mongo/operation/write/insert.rb +4 -1
- data/lib/mongo/operation/write/insert/result.rb +2 -2
- data/lib/mongo/operation/write/update.rb +7 -1
- data/lib/mongo/operation/write/write_command_enabled.rb +20 -3
- data/lib/mongo/protocol.rb +3 -0
- data/lib/mongo/protocol/bit_vector.rb +2 -2
- data/lib/mongo/protocol/compressed.rb +135 -0
- data/lib/mongo/protocol/delete.rb +8 -6
- data/lib/mongo/protocol/get_more.rb +8 -6
- data/lib/mongo/protocol/insert.rb +8 -6
- data/lib/mongo/protocol/kill_cursors.rb +8 -6
- data/lib/mongo/protocol/message.rb +31 -3
- data/lib/mongo/protocol/msg.rb +172 -0
- data/lib/mongo/protocol/query.rb +26 -6
- data/lib/mongo/protocol/registry.rb +76 -0
- data/lib/mongo/protocol/reply.rb +10 -5
- data/lib/mongo/protocol/serializers.rb +224 -0
- data/lib/mongo/protocol/update.rb +8 -6
- data/lib/mongo/retryable.rb +4 -2
- data/lib/mongo/server.rb +6 -3
- data/lib/mongo/server/connectable.rb +1 -1
- data/lib/mongo/server/connection.rb +30 -8
- data/lib/mongo/server/description.rb +25 -1
- data/lib/mongo/server/description/features.rb +4 -1
- data/lib/mongo/server/monitor.rb +5 -0
- data/lib/mongo/server/monitor/connection.rb +50 -2
- data/lib/mongo/server_selector/nearest.rb +10 -4
- data/lib/mongo/server_selector/primary.rb +20 -0
- data/lib/mongo/server_selector/primary_preferred.rb +10 -4
- data/lib/mongo/server_selector/secondary.rb +10 -4
- data/lib/mongo/server_selector/secondary_preferred.rb +24 -4
- data/lib/mongo/session.rb +180 -0
- data/lib/mongo/session/server_session.rb +73 -0
- data/lib/mongo/session/session_pool.rb +161 -0
- data/lib/mongo/uri.rb +11 -0
- data/lib/mongo/version.rb +1 -1
- data/mongo.gemspec +2 -1
- data/spec/mongo/auth/cr_spec.rb +12 -0
- data/spec/mongo/auth/ldap_spec.rb +2 -0
- data/spec/mongo/auth/scram/conversation_spec.rb +6 -6
- data/spec/mongo/auth/scram_spec.rb +25 -1
- data/spec/mongo/auth/user/view_spec.rb +268 -76
- data/spec/mongo/auth/x509_spec.rb +2 -0
- data/spec/mongo/bulk_write_spec.rb +435 -5
- data/spec/mongo/client_spec.rb +356 -39
- data/spec/mongo/cluster/app_metadata_spec.rb +2 -2
- data/spec/mongo/cluster_spec.rb +176 -0
- data/spec/mongo/collection/view/aggregation_spec.rb +33 -12
- data/spec/mongo/collection/view/builder/find_command_spec.rb +46 -6
- data/spec/mongo/collection/view/change_stream_spec.rb +814 -0
- data/spec/mongo/collection/view/map_reduce_spec.rb +94 -17
- data/spec/mongo/collection/view/readable_spec.rb +3 -12
- data/spec/mongo/collection_spec.rb +1048 -42
- data/spec/mongo/cursor/builder/get_more_command_spec.rb +19 -0
- data/spec/mongo/cursor_spec.rb +2 -2
- data/spec/mongo/database_spec.rb +50 -1
- data/spec/mongo/grid/fs_bucket_spec.rb +225 -137
- data/spec/mongo/grid/stream/read_spec.rb +2 -2
- data/spec/mongo/index/view_spec.rb +146 -8
- data/spec/mongo/monitoring/event/secure_spec.rb +42 -0
- data/spec/mongo/operation/read/query_spec.rb +2 -1
- data/spec/mongo/operation/specifiable_spec.rb +2 -2
- data/spec/mongo/operation/write/command/delete_spec.rb +96 -13
- data/spec/mongo/operation/write/command/insert_spec.rb +111 -12
- data/spec/mongo/operation/write/command/update_spec.rb +93 -10
- data/spec/mongo/operation/write/delete_spec.rb +1 -1
- data/spec/mongo/operation/write/insert_spec.rb +1 -1
- data/spec/mongo/operation/write/update_spec.rb +1 -1
- data/spec/mongo/protocol/compressed_spec.rb +66 -0
- data/spec/mongo/protocol/delete_spec.rb +14 -0
- data/spec/mongo/protocol/get_more_spec.rb +14 -0
- data/spec/mongo/protocol/insert_spec.rb +14 -0
- data/spec/mongo/protocol/kill_cursors_spec.rb +14 -0
- data/spec/mongo/protocol/msg_spec.rb +499 -0
- data/spec/mongo/protocol/query_spec.rb +45 -0
- data/spec/mongo/protocol/registry_spec.rb +31 -0
- data/spec/mongo/protocol/reply_spec.rb +14 -0
- data/spec/mongo/protocol/update_spec.rb +14 -0
- data/spec/mongo/retryable_spec.rb +6 -2
- data/spec/mongo/sdam_spec.rb +4 -0
- data/spec/mongo/server/connection_spec.rb +4 -2
- data/spec/mongo/server/description_spec.rb +28 -1
- data/spec/mongo/session/server_session_spec.rb +16 -0
- data/spec/mongo/session/session_pool_spec.rb +194 -0
- data/spec/mongo/uri_spec.rb +31 -2
- data/spec/spec_helper.rb +104 -0
- data/spec/support/authorization.rb +6 -1
- data/spec/support/crud.rb +3 -1
- data/spec/support/crud/write.rb +6 -1
- data/spec/support/crud_tests/write/findOneAndUpdate-arrayFilters.yml +69 -0
- data/spec/support/crud_tests/write/updateMany-arrayFilters.yml +63 -0
- data/spec/support/crud_tests/write/updateOne-arrayFilters.yml +109 -0
- data/spec/support/sdam/rs/discover_arbiters.yml +1 -1
- data/spec/support/sdam/rs/discover_passives.yml +2 -2
- data/spec/support/sdam/rs/discover_primary.yml +1 -1
- data/spec/support/sdam/rs/discover_secondary.yml +1 -1
- data/spec/support/sdam/rs/discovery.yml +4 -4
- data/spec/support/sdam/rs/equal_electionids.yml +1 -0
- data/spec/support/sdam/rs/ghost_discovered.yml +1 -1
- data/spec/support/sdam/rs/hosts_differ_from_seeds.yml +1 -1
- data/spec/support/sdam/rs/ls_timeout.yml +88 -0
- data/spec/support/sdam/rs/member_reconfig.yml +2 -2
- data/spec/support/sdam/rs/member_standalone.yml +2 -2
- data/spec/support/sdam/rs/new_primary.yml +2 -2
- data/spec/support/sdam/rs/new_primary_new_electionid.yml +3 -0
- data/spec/support/sdam/rs/new_primary_new_setversion.yml +3 -0
- data/spec/support/sdam/rs/new_primary_wrong_set_name.yml +2 -2
- data/spec/support/sdam/rs/non_rs_member.yml +1 -1
- data/spec/support/sdam/rs/normalize_case.yml +1 -1
- data/spec/support/sdam/rs/null_election_id.yml +4 -0
- data/spec/support/sdam/rs/primary_becomes_standalone.yml +2 -2
- data/spec/support/sdam/rs/primary_changes_set_name.yml +2 -2
- data/spec/support/sdam/rs/primary_disconnect.yml +2 -2
- data/spec/support/sdam/rs/primary_disconnect_electionid.yml +5 -0
- data/spec/support/sdam/rs/primary_disconnect_setversion.yml +5 -0
- data/spec/support/sdam/rs/primary_hint_from_secondary_with_mismatched_me.yml +58 -0
- data/spec/support/sdam/rs/primary_reports_new_member.yml +4 -4
- data/spec/support/sdam/rs/primary_to_no_primary_mismatched_me.yml +2 -2
- data/spec/support/sdam/rs/primary_wrong_set_name.yml +1 -1
- data/spec/support/sdam/rs/response_from_removed.yml +2 -2
- data/spec/support/sdam/rs/rsother_discovered.yml +1 -1
- data/spec/support/sdam/rs/sec_not_auth.yml +1 -1
- data/spec/support/sdam/rs/secondary_wrong_set_name.yml +1 -1
- data/spec/support/sdam/rs/secondary_wrong_set_name_with_primary.yml +2 -2
- data/spec/support/sdam/rs/setversion_without_electionid.yml +2 -0
- data/spec/support/sdam/rs/stepdown_change_set_name.yml +2 -2
- data/spec/support/sdam/rs/unexpected_mongos.yml +1 -1
- data/spec/support/sdam/rs/use_setversion_without_electionid.yml +3 -0
- data/spec/support/sdam/rs/wrong_set_name.yml +1 -1
- data/spec/support/sdam/sharded/ls_timeout_mongos.yml +97 -0
- data/spec/support/sdam/sharded/mongos_disconnect.yml +3 -3
- data/spec/support/sdam/sharded/multiple_mongoses.yml +1 -1
- data/spec/support/sdam/sharded/non_mongos_removed.yml +1 -1
- data/spec/support/sdam/sharded/normalize_uri_case.yml +1 -1
- data/spec/support/sdam/single/direct_connection_external_ip.yml +1 -1
- data/spec/support/sdam/single/direct_connection_mongos.yml +1 -1
- 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/ls_timeout_standalone.yml +35 -0
- data/spec/support/sdam/single/not_ok_response.yml +1 -1
- data/spec/support/sdam/single/standalone_removed.yml +1 -1
- data/spec/support/sdam/single/unavailable_seed.yml +1 -1
- data/spec/support/server_discovery_and_monitoring.rb +4 -0
- data/spec/support/shared/session.rb +236 -0
- metadata +53 -15
- metadata.gz.sig +0 -0
@@ -68,11 +68,11 @@ describe Mongo::Grid::FSBucket::Stream::Read do
|
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'sets the read preference' do
|
71
|
-
expect(stream.read_preference).to eq(
|
71
|
+
expect(stream.read_preference).to eq(options[:read])
|
72
72
|
end
|
73
73
|
|
74
74
|
it 'sets the read preference on the view' do
|
75
|
-
expect(stream.send(:view).read).to eq(
|
75
|
+
expect(stream.send(:view).read).to eq(BSON::Document.new(options[:read]))
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
@@ -3,7 +3,11 @@ require 'spec_helper'
|
|
3
3
|
describe Mongo::Index::View do
|
4
4
|
|
5
5
|
let(:view) do
|
6
|
-
described_class.new(authorized_collection)
|
6
|
+
described_class.new(authorized_collection, options)
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:options) do
|
10
|
+
{}
|
7
11
|
end
|
8
12
|
|
9
13
|
describe '#drop_one' do
|
@@ -12,12 +16,34 @@ describe Mongo::Index::View do
|
|
12
16
|
{ another: -1 }
|
13
17
|
end
|
14
18
|
|
19
|
+
after do
|
20
|
+
begin; view.drop_one('another_-1'); rescue; end
|
21
|
+
end
|
22
|
+
|
15
23
|
before do
|
16
24
|
view.create_one(spec, unique: true)
|
17
25
|
end
|
18
26
|
|
19
|
-
|
20
|
-
|
27
|
+
context 'when provided a session' do
|
28
|
+
|
29
|
+
let(:view_with_session) do
|
30
|
+
described_class.new(authorized_collection, session: session)
|
31
|
+
end
|
32
|
+
|
33
|
+
let(:client) do
|
34
|
+
authorized_client
|
35
|
+
end
|
36
|
+
|
37
|
+
let(:operation) do
|
38
|
+
view_with_session.drop_one('another_-1')
|
39
|
+
end
|
40
|
+
|
41
|
+
let(:failed_operation) do
|
42
|
+
view_with_session.drop_one('_another_-1')
|
43
|
+
end
|
44
|
+
|
45
|
+
it_behaves_like 'an operation using a session'
|
46
|
+
it_behaves_like 'a failed operation using a session'
|
21
47
|
end
|
22
48
|
|
23
49
|
context 'when the index exists' do
|
@@ -123,6 +149,23 @@ describe Mongo::Index::View do
|
|
123
149
|
expect(result).to be_successful
|
124
150
|
end
|
125
151
|
|
152
|
+
context 'when provided a session' do
|
153
|
+
|
154
|
+
let(:view_with_session) do
|
155
|
+
described_class.new(authorized_collection, session: session)
|
156
|
+
end
|
157
|
+
|
158
|
+
let(:operation) do
|
159
|
+
view_with_session.drop_all
|
160
|
+
end
|
161
|
+
|
162
|
+
let(:client) do
|
163
|
+
authorized_client
|
164
|
+
end
|
165
|
+
|
166
|
+
it_behaves_like 'an operation using a session'
|
167
|
+
end
|
168
|
+
|
126
169
|
context 'when the collection has a write concern' do
|
127
170
|
|
128
171
|
let(:collection) do
|
@@ -183,6 +226,33 @@ describe Mongo::Index::View do
|
|
183
226
|
it 'returns ok' do
|
184
227
|
expect(result).to be_successful
|
185
228
|
end
|
229
|
+
|
230
|
+
context 'when provided a session' do
|
231
|
+
|
232
|
+
let(:view_with_session) do
|
233
|
+
described_class.new(authorized_collection, session: session)
|
234
|
+
end
|
235
|
+
|
236
|
+
let(:operation) do
|
237
|
+
view_with_session.create_many(
|
238
|
+
{ key: { random: 1 }, unique: true },
|
239
|
+
{ key: { testing: -1 }, unique: true }
|
240
|
+
)
|
241
|
+
end
|
242
|
+
|
243
|
+
let(:client) do
|
244
|
+
authorized_client
|
245
|
+
end
|
246
|
+
|
247
|
+
let(:failed_operation) do
|
248
|
+
view_with_session.create_many(
|
249
|
+
{ key: { random: 1 }, invalid: true }
|
250
|
+
)
|
251
|
+
end
|
252
|
+
|
253
|
+
it_behaves_like 'an operation using a session'
|
254
|
+
it_behaves_like 'a failed operation using a session'
|
255
|
+
end
|
186
256
|
end
|
187
257
|
|
188
258
|
context 'when collation is specified', if: collation_enabled? do
|
@@ -313,6 +383,31 @@ describe Mongo::Index::View do
|
|
313
383
|
it 'returns ok' do
|
314
384
|
expect(result).to be_successful
|
315
385
|
end
|
386
|
+
|
387
|
+
context 'when provided a session' do
|
388
|
+
|
389
|
+
let(:view_with_session) do
|
390
|
+
described_class.new(authorized_collection, session: session)
|
391
|
+
end
|
392
|
+
|
393
|
+
let(:operation) do
|
394
|
+
view_with_session.create_many([
|
395
|
+
{ key: { random: 1 }, unique: true },
|
396
|
+
{ key: { testing: -1 }, unique: true }
|
397
|
+
])
|
398
|
+
end
|
399
|
+
|
400
|
+
let(:failed_operation) do
|
401
|
+
view_with_session.create_many([ { key: { random: 1 }, invalid: true }])
|
402
|
+
end
|
403
|
+
|
404
|
+
let(:client) do
|
405
|
+
authorized_client
|
406
|
+
end
|
407
|
+
|
408
|
+
it_behaves_like 'an operation using a session'
|
409
|
+
it_behaves_like 'a failed operation using a session'
|
410
|
+
end
|
316
411
|
end
|
317
412
|
|
318
413
|
context 'when collation is specified' do
|
@@ -463,16 +558,38 @@ describe Mongo::Index::View do
|
|
463
558
|
view.create_one(spec, unique: true)
|
464
559
|
end
|
465
560
|
|
466
|
-
after do
|
467
|
-
begin; view.drop_one('random_1'); rescue; end
|
468
|
-
end
|
469
|
-
|
470
561
|
it 'returns ok' do
|
471
562
|
expect(result).to be_successful
|
472
563
|
end
|
473
564
|
|
565
|
+
context 'when provided a session' do
|
566
|
+
|
567
|
+
let(:view_with_session) do
|
568
|
+
described_class.new(authorized_collection, session: session)
|
569
|
+
end
|
570
|
+
|
571
|
+
let(:operation) do
|
572
|
+
view_with_session.create_one(spec, unique: true)
|
573
|
+
end
|
574
|
+
|
575
|
+
let(:failed_operation) do
|
576
|
+
view_with_session.create_one(spec, invalid: true)
|
577
|
+
end
|
578
|
+
|
579
|
+
let(:client) do
|
580
|
+
authorized_client
|
581
|
+
end
|
582
|
+
|
583
|
+
it_behaves_like 'an operation using a session'
|
584
|
+
it_behaves_like 'a failed operation using a session'
|
585
|
+
end
|
586
|
+
|
474
587
|
context 'when the collection has a write concern' do
|
475
588
|
|
589
|
+
after do
|
590
|
+
begin; view.drop_one('random_1'); rescue; end
|
591
|
+
end
|
592
|
+
|
476
593
|
let(:collection) do
|
477
594
|
authorized_collection.with(write: INVALID_WRITE_CONCERN)
|
478
595
|
end
|
@@ -514,6 +631,10 @@ describe Mongo::Index::View do
|
|
514
631
|
|
515
632
|
context 'when the index is created on an subdocument field' do
|
516
633
|
|
634
|
+
after do
|
635
|
+
begin; view.drop_one('random_1'); rescue; end
|
636
|
+
end
|
637
|
+
|
517
638
|
let(:spec) do
|
518
639
|
{ 'sub_document.random' => 1 }
|
519
640
|
end
|
@@ -632,7 +753,7 @@ describe Mongo::Index::View do
|
|
632
753
|
end
|
633
754
|
|
634
755
|
after do
|
635
|
-
view.drop_one('random_name')
|
756
|
+
begin; view.drop_one('random_name'); rescue; end
|
636
757
|
end
|
637
758
|
|
638
759
|
context 'when providing a name' do
|
@@ -657,6 +778,23 @@ describe Mongo::Index::View do
|
|
657
778
|
end
|
658
779
|
end
|
659
780
|
|
781
|
+
context 'when provided a session' do
|
782
|
+
|
783
|
+
let(:view_with_session) do
|
784
|
+
described_class.new(authorized_collection, session: session)
|
785
|
+
end
|
786
|
+
|
787
|
+
let(:operation) do
|
788
|
+
view_with_session.get(random: 1)
|
789
|
+
end
|
790
|
+
|
791
|
+
let(:client) do
|
792
|
+
authorized_client
|
793
|
+
end
|
794
|
+
|
795
|
+
it_behaves_like 'an operation using a session'
|
796
|
+
end
|
797
|
+
|
660
798
|
context 'when the index does not exist' do
|
661
799
|
|
662
800
|
it 'returns nil' do
|
@@ -54,4 +54,46 @@ describe Mongo::Monitoring::Event::Secure do
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
57
|
+
|
58
|
+
describe '#compression_allowed?' do
|
59
|
+
|
60
|
+
context 'when the selector represents a command for which compression is not allowed' do
|
61
|
+
|
62
|
+
let(:secure) do
|
63
|
+
klass.new
|
64
|
+
end
|
65
|
+
|
66
|
+
Mongo::Monitoring::Event::Secure::REDACTED_COMMANDS.each do |command|
|
67
|
+
|
68
|
+
let(:selector) do
|
69
|
+
{ command => 1 }
|
70
|
+
end
|
71
|
+
|
72
|
+
context "when the command is #{command}" do
|
73
|
+
|
74
|
+
it 'does not allow compression for the command' do
|
75
|
+
expect(secure.compression_allowed?(selector.keys.first)).to be(false)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'when the selector represents a command for which compression is allowed' do
|
82
|
+
|
83
|
+
let(:selector) do
|
84
|
+
{ ping: 1 }
|
85
|
+
end
|
86
|
+
|
87
|
+
let(:secure) do
|
88
|
+
klass.new
|
89
|
+
end
|
90
|
+
|
91
|
+
context 'when the command is :ping' do
|
92
|
+
|
93
|
+
it 'does not allow compression for the command' do
|
94
|
+
expect(secure.compression_allowed?(selector.keys.first)).to be(true)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
57
99
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Mongo::Operation::Read::Query do
|
3
|
+
describe Mongo::Operation::Read::Query, unless: op_msg_enabled? do
|
4
4
|
|
5
5
|
let(:selector) { { foo: 1 } }
|
6
6
|
let(:query_options) { {} }
|
@@ -71,6 +71,7 @@ describe Mongo::Operation::Read::Query do
|
|
71
71
|
double('secondary_server').tap do |server|
|
72
72
|
allow(server).to receive(:mongos?) { false }
|
73
73
|
allow(server).to receive(:cluster) { cluster_single }
|
74
|
+
allow(server).to receive(:features) { authorized_primary.features }
|
74
75
|
end
|
75
76
|
end
|
76
77
|
|
@@ -76,8 +76,8 @@ describe Mongo::Operation::Specifiable do
|
|
76
76
|
|
77
77
|
context 'when read is not specified' do
|
78
78
|
|
79
|
-
it 'returns
|
80
|
-
expect(specifiable.read).to
|
79
|
+
it 'returns nil' do
|
80
|
+
expect(specifiable.read).to be_nil
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|
@@ -86,21 +86,104 @@ describe Mongo::Operation::Write::Command::Delete do
|
|
86
86
|
|
87
87
|
describe '#message' do
|
88
88
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
89
|
+
context 'when the server supports OP_MSG' do
|
90
|
+
|
91
|
+
let(:global_args) do
|
92
|
+
{
|
93
|
+
delete: TEST_COLL,
|
94
|
+
ordered: true,
|
95
|
+
writeConcern: write_concern.options,
|
96
|
+
'$db' => TEST_DB
|
97
|
+
}
|
98
|
+
end
|
99
|
+
|
100
|
+
let(:expected_payload_1) do
|
101
|
+
{
|
102
|
+
type: 1,
|
103
|
+
payload: { identifier: 'deletes',
|
104
|
+
sequence: deletes
|
105
|
+
}
|
106
|
+
}
|
107
|
+
end
|
108
|
+
|
109
|
+
context 'when the topology is sharded', if: sharded? && op_msg_enabled? do
|
110
|
+
|
111
|
+
let(:expected_global_args) do
|
112
|
+
global_args.merge(Mongo::Operation::CLUSTER_TIME => authorized_client.cluster.cluster_time)
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'creates the correct OP_MSG message' do
|
116
|
+
authorized_client.command(ping:1)
|
117
|
+
expect(Mongo::Protocol::Msg).to receive(:new).with([:none], {}, expected_global_args, expected_payload_1)
|
118
|
+
op.send(:message, authorized_primary)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context 'when the topology is not sharded', if: !sharded? && op_msg_enabled? do
|
123
|
+
|
124
|
+
let(:expected_global_args) do
|
125
|
+
global_args
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'creates the correct OP_MSG message' do
|
129
|
+
authorized_client.command(ping:1)
|
130
|
+
expect(Mongo::Protocol::Msg).to receive(:new).with([:none], {}, expected_global_args, expected_payload_1)
|
131
|
+
op.send(:message, authorized_primary)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
context 'when the write concern is 0' do
|
136
|
+
|
137
|
+
let(:write_concern) do
|
138
|
+
Mongo::WriteConcern.get(w: 0)
|
139
|
+
end
|
140
|
+
|
141
|
+
context 'when the topology is sharded', if: sharded? && op_msg_enabled? do
|
142
|
+
|
143
|
+
let(:expected_global_args) do
|
144
|
+
global_args.merge(Mongo::Operation::CLUSTER_TIME => authorized_client.cluster.cluster_time)
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'creates the correct OP_MSG message' do
|
148
|
+
authorized_client.command(ping:1)
|
149
|
+
expect(Mongo::Protocol::Msg).to receive(:new).with([:more_to_come], {}, expected_global_args, expected_payload_1)
|
150
|
+
op.send(:message, authorized_primary)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context 'when the topology is not sharded', if: !sharded? && op_msg_enabled? do
|
155
|
+
|
156
|
+
let(:expected_global_args) do
|
157
|
+
global_args
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'creates the correct OP_MSG message' do
|
161
|
+
authorized_client.command(ping:1)
|
162
|
+
expect(Mongo::Protocol::Msg).to receive(:new).with([:more_to_come], {}, expected_global_args, expected_payload_1)
|
163
|
+
op.send(:message, authorized_primary)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
96
167
|
end
|
97
168
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
169
|
+
context 'when the server does not support OP_MSG' do
|
170
|
+
|
171
|
+
let(:expected_selector) do
|
172
|
+
{
|
173
|
+
:delete => authorized_collection.name,
|
174
|
+
:deletes => deletes,
|
175
|
+
:writeConcern => write_concern.options,
|
176
|
+
:ordered => true
|
177
|
+
}
|
178
|
+
end
|
179
|
+
|
180
|
+
it 'creates the correct query wire protocol message', unless: op_msg_enabled? do
|
181
|
+
expect(Mongo::Protocol::Query).to receive(:new).with(authorized_collection.database.name,
|
182
|
+
'$cmd',
|
183
|
+
expected_selector,
|
184
|
+
{ limit: -1 } )
|
185
|
+
op.send(:message, authorized_primary)
|
186
|
+
end
|
104
187
|
end
|
105
188
|
end
|
106
189
|
end
|
@@ -86,20 +86,119 @@ describe Mongo::Operation::Write::Command::Insert do
|
|
86
86
|
|
87
87
|
describe '#message' do
|
88
88
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
:
|
93
|
-
|
94
|
-
|
89
|
+
context 'when the server supports OP_MSG', if: op_msg_enabled? do
|
90
|
+
|
91
|
+
let(:documents) do
|
92
|
+
[ { foo: 1}, { bar: 2 }]
|
93
|
+
end
|
94
|
+
|
95
|
+
let(:global_args) do
|
96
|
+
{
|
97
|
+
insert: TEST_COLL,
|
98
|
+
ordered: true,
|
99
|
+
writeConcern: write_concern.options,
|
100
|
+
'$db' => TEST_DB
|
101
|
+
}
|
102
|
+
end
|
103
|
+
|
104
|
+
let(:expected_payload_1) do
|
105
|
+
{
|
106
|
+
type: 1,
|
107
|
+
payload: { identifier: 'documents',
|
108
|
+
sequence: documents
|
109
|
+
}
|
110
|
+
}
|
111
|
+
end
|
112
|
+
|
113
|
+
context 'when the topology is sharded', if: sharded? && op_msg_enabled? do
|
114
|
+
|
115
|
+
let(:expected_global_args) do
|
116
|
+
global_args.merge(Mongo::Operation::CLUSTER_TIME => authorized_client.cluster.cluster_time)
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'creates the correct OP_MSG message' do
|
120
|
+
authorized_client.command(ping:1)
|
121
|
+
expect(Mongo::Protocol::Msg).to receive(:new).with([:none],
|
122
|
+
{ validating_keys: true },
|
123
|
+
expected_global_args,
|
124
|
+
expected_payload_1)
|
125
|
+
op.send(:message, authorized_primary)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
context 'when the topology is not sharded', if: !sharded? && op_msg_enabled? do
|
130
|
+
|
131
|
+
let(:expected_global_args) do
|
132
|
+
global_args
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'creates the correct OP_MSG message' do
|
136
|
+
authorized_client.command(ping:1)
|
137
|
+
expect(Mongo::Protocol::Msg).to receive(:new).with([:none],
|
138
|
+
{ validating_keys: true },
|
139
|
+
expected_global_args,
|
140
|
+
expected_payload_1)
|
141
|
+
op.send(:message, authorized_primary)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context 'when the write concern is 0' do
|
146
|
+
|
147
|
+
let(:write_concern) do
|
148
|
+
Mongo::WriteConcern.get(w: 0)
|
149
|
+
end
|
150
|
+
|
151
|
+
context 'when the topology is sharded', if: sharded? && op_msg_enabled? do
|
152
|
+
|
153
|
+
let(:expected_global_args) do
|
154
|
+
global_args.merge(Mongo::Operation::CLUSTER_TIME => authorized_client.cluster.cluster_time)
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'creates the correct OP_MSG message' do
|
158
|
+
authorized_client.command(ping:1)
|
159
|
+
expect(Mongo::Protocol::Msg).to receive(:new).with([:more_to_come],
|
160
|
+
{ validating_keys: true },
|
161
|
+
expected_global_args,
|
162
|
+
expected_payload_1)
|
163
|
+
op.send(:message, authorized_primary)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
context 'when the topology is not sharded', if: !sharded? && op_msg_enabled? do
|
168
|
+
|
169
|
+
let(:expected_global_args) do
|
170
|
+
global_args
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'creates the correct OP_MSG message' do
|
174
|
+
authorized_client.command(ping:1)
|
175
|
+
expect(Mongo::Protocol::Msg).to receive(:new).with([:more_to_come],
|
176
|
+
{ validating_keys: true },
|
177
|
+
expected_global_args,
|
178
|
+
expected_payload_1)
|
179
|
+
op.send(:message, authorized_primary)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
95
183
|
end
|
96
184
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
185
|
+
context 'when the server does not support OP_MSG' do
|
186
|
+
|
187
|
+
let(:expected_selector) do
|
188
|
+
{ :documents => documents,
|
189
|
+
:insert => authorized_collection.name,
|
190
|
+
:writeConcern => write_concern.options,
|
191
|
+
:ordered => true
|
192
|
+
}
|
193
|
+
end
|
194
|
+
|
195
|
+
it 'creates a query wire protocol message with correct specs', unless: op_msg_enabled? do
|
196
|
+
expect(Mongo::Protocol::Query).to receive(:new).with(authorized_collection.database.name,
|
197
|
+
'$cmd',
|
198
|
+
expected_selector,
|
199
|
+
{ limit: -1, validating_keys: true })
|
200
|
+
op.send(:message, authorized_primary)
|
201
|
+
end
|
103
202
|
end
|
104
203
|
end
|
105
204
|
end
|