mongo 2.13.3 → 2.14.0.rc1
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/lib/mongo/address/ipv4.rb +1 -1
- data/lib/mongo/address/ipv6.rb +1 -1
- data/lib/mongo/address.rb +1 -1
- data/lib/mongo/bulk_write.rb +17 -0
- data/lib/mongo/caching_cursor.rb +74 -0
- data/lib/mongo/client.rb +47 -8
- data/lib/mongo/cluster/topology/single.rb +1 -1
- data/lib/mongo/cluster.rb +3 -3
- data/lib/mongo/collection/view/aggregation.rb +25 -4
- data/lib/mongo/collection/view/builder/find_command.rb +38 -18
- data/lib/mongo/collection/view/explainable.rb +27 -8
- data/lib/mongo/collection/view/iterable.rb +72 -12
- data/lib/mongo/collection/view/readable.rb +12 -2
- data/lib/mongo/collection/view/writable.rb +15 -1
- data/lib/mongo/collection/view.rb +24 -20
- data/lib/mongo/collection.rb +26 -2
- data/lib/mongo/crypt/encryption_io.rb +6 -6
- data/lib/mongo/cursor.rb +1 -0
- data/lib/mongo/database/view.rb +1 -1
- data/lib/mongo/database.rb +8 -14
- data/lib/mongo/error/invalid_read_concern.rb +28 -0
- data/lib/mongo/error/server_certificate_revoked.rb +22 -0
- data/lib/mongo/error/unsupported_option.rb +14 -12
- data/lib/mongo/error.rb +2 -0
- data/lib/mongo/grid/fs_bucket.rb +37 -37
- data/lib/mongo/lint.rb +2 -1
- data/lib/mongo/logger.rb +3 -3
- data/lib/mongo/operation/aggregate/result.rb +9 -8
- data/lib/mongo/operation/collections_info/command.rb +0 -5
- data/lib/mongo/operation/collections_info/result.rb +3 -16
- data/lib/mongo/operation/delete/bulk_result.rb +2 -0
- data/lib/mongo/operation/delete/result.rb +3 -0
- data/lib/mongo/operation/explain/command.rb +4 -0
- data/lib/mongo/operation/explain/legacy.rb +4 -0
- data/lib/mongo/operation/explain/op_msg.rb +6 -0
- data/lib/mongo/operation/explain/result.rb +3 -0
- data/lib/mongo/operation/find/legacy/result.rb +2 -0
- data/lib/mongo/operation/find/result.rb +3 -0
- data/lib/mongo/operation/get_more/result.rb +3 -0
- data/lib/mongo/operation/indexes/result.rb +5 -0
- data/lib/mongo/operation/insert/bulk_result.rb +5 -0
- data/lib/mongo/operation/insert/result.rb +5 -0
- data/lib/mongo/operation/list_collections/result.rb +5 -0
- data/lib/mongo/operation/map_reduce/result.rb +10 -0
- data/lib/mongo/operation/parallel_scan/command.rb +2 -1
- data/lib/mongo/operation/parallel_scan/result.rb +4 -0
- data/lib/mongo/operation/result.rb +35 -6
- data/lib/mongo/operation/shared/bypass_document_validation.rb +1 -0
- data/lib/mongo/operation/shared/causal_consistency_supported.rb +1 -0
- data/lib/mongo/operation/shared/collections_info_or_list_collections.rb +2 -0
- data/lib/mongo/operation/shared/executable.rb +1 -0
- data/lib/mongo/operation/shared/idable.rb +2 -1
- data/lib/mongo/operation/shared/limited.rb +1 -0
- data/lib/mongo/operation/shared/object_id_generator.rb +1 -0
- data/lib/mongo/operation/shared/read_preference_supported.rb +36 -38
- data/lib/mongo/operation/shared/result/aggregatable.rb +1 -0
- data/lib/mongo/operation/shared/sessions_supported.rb +3 -3
- data/lib/mongo/operation/shared/specifiable.rb +1 -0
- data/lib/mongo/operation/shared/write.rb +1 -0
- data/lib/mongo/operation/shared/write_concern_supported.rb +1 -0
- data/lib/mongo/operation/update/legacy/result.rb +7 -0
- data/lib/mongo/operation/update/result.rb +8 -0
- data/lib/mongo/operation/users_info/result.rb +3 -0
- data/lib/mongo/operation.rb +2 -0
- data/lib/mongo/protocol/msg.rb +2 -2
- data/lib/mongo/protocol/query.rb +11 -11
- data/lib/mongo/query_cache.rb +242 -0
- data/lib/mongo/retryable.rb +8 -1
- data/lib/mongo/server/connection_common.rb +2 -2
- data/lib/mongo/server/connection_pool.rb +3 -0
- data/lib/mongo/server/monitor/connection.rb +3 -3
- data/lib/mongo/server/monitor.rb +1 -1
- data/lib/mongo/server/pending_connection.rb +2 -2
- data/lib/mongo/server/push_monitor.rb +1 -1
- data/lib/mongo/server.rb +5 -1
- data/lib/mongo/server_selector/base.rb +5 -1
- data/lib/mongo/server_selector/secondary_preferred.rb +7 -2
- data/lib/mongo/session.rb +3 -0
- data/lib/mongo/socket/ocsp_cache.rb +97 -0
- data/lib/mongo/socket/ocsp_verifier.rb +368 -0
- data/lib/mongo/socket/ssl.rb +45 -24
- data/lib/mongo/socket.rb +6 -4
- data/lib/mongo/srv/monitor.rb +7 -13
- data/lib/mongo/srv/resolver.rb +14 -10
- data/lib/mongo/timeout.rb +2 -0
- data/lib/mongo/uri/options_mapper.rb +582 -0
- data/lib/mongo/uri/srv_protocol.rb +3 -2
- data/lib/mongo/uri.rb +21 -390
- data/lib/mongo/utils.rb +12 -1
- data/lib/mongo/version.rb +1 -1
- data/lib/mongo.rb +9 -0
- data/spec/NOTES.aws-auth.md +12 -7
- data/spec/README.md +56 -1
- data/spec/integration/bson_symbol_spec.rb +2 -4
- data/spec/integration/bulk_write_spec.rb +48 -0
- data/spec/integration/client_authentication_options_spec.rb +55 -28
- data/spec/integration/connection_pool_populator_spec.rb +3 -1
- data/spec/integration/cursor_reaping_spec.rb +53 -17
- data/spec/integration/ocsp_connectivity_spec.rb +26 -0
- data/spec/integration/ocsp_verifier_cache_spec.rb +188 -0
- data/spec/integration/ocsp_verifier_spec.rb +334 -0
- data/spec/integration/query_cache_spec.rb +1045 -0
- data/spec/integration/query_cache_transactions_spec.rb +179 -0
- data/spec/integration/retryable_writes/retryable_writes_40_and_newer_spec.rb +1 -0
- data/spec/integration/retryable_writes/shared/performs_legacy_retries.rb +2 -0
- data/spec/integration/sdam_error_handling_spec.rb +69 -18
- data/spec/integration/sdam_events_spec.rb +7 -8
- data/spec/integration/server_selection_spec.rb +36 -0
- data/spec/integration/srv_monitoring_spec.rb +38 -3
- data/spec/integration/srv_spec.rb +56 -0
- data/spec/lite_spec_helper.rb +4 -2
- data/spec/mongo/address_spec.rb +1 -1
- data/spec/mongo/caching_cursor_spec.rb +70 -0
- data/spec/mongo/client_construction_spec.rb +54 -1
- data/spec/mongo/client_encryption_spec.rb +10 -16
- data/spec/mongo/client_spec.rb +40 -0
- data/spec/mongo/cluster/topology/single_spec.rb +14 -5
- data/spec/mongo/cluster_spec.rb +3 -0
- data/spec/mongo/collection/view/explainable_spec.rb +87 -4
- data/spec/mongo/collection/view/map_reduce_spec.rb +2 -0
- data/spec/mongo/collection_spec.rb +60 -0
- data/spec/mongo/crypt/auto_decryption_context_spec.rb +1 -1
- data/spec/mongo/crypt/auto_encryption_context_spec.rb +1 -1
- data/spec/mongo/crypt/data_key_context_spec.rb +1 -1
- data/spec/mongo/crypt/explicit_decryption_context_spec.rb +1 -1
- data/spec/mongo/crypt/explicit_encryption_context_spec.rb +1 -1
- data/spec/mongo/database_spec.rb +44 -64
- data/spec/mongo/error/no_server_available_spec.rb +1 -1
- data/spec/mongo/index/view_spec.rb +2 -4
- data/spec/mongo/logger_spec.rb +13 -11
- data/spec/mongo/operation/read_preference_legacy_spec.rb +19 -9
- data/spec/mongo/operation/read_preference_op_msg_spec.rb +3 -3
- data/spec/mongo/query_cache_spec.rb +279 -0
- data/spec/mongo/server/app_metadata_shared.rb +7 -33
- data/spec/mongo/server/connection_pool_spec.rb +7 -3
- data/spec/mongo/server/connection_spec.rb +14 -7
- data/spec/mongo/server_selector/secondary_preferred_spec.rb +6 -6
- data/spec/mongo/socket/ssl_spec.rb +1 -1
- data/spec/mongo/socket_spec.rb +1 -1
- data/spec/mongo/uri/srv_protocol_spec.rb +64 -33
- data/spec/mongo/uri_option_parsing_spec.rb +11 -11
- data/spec/mongo/uri_spec.rb +68 -41
- data/spec/mongo/utils_spec.rb +39 -0
- data/spec/runners/auth.rb +3 -0
- data/spec/runners/connection_string.rb +35 -124
- data/spec/runners/transactions/operation.rb +2 -13
- data/spec/spec_tests/cmap_spec.rb +7 -3
- data/spec/spec_tests/data/change_streams/change-streams-errors.yml +0 -1
- data/spec/spec_tests/data/change_streams/change-streams.yml +0 -1
- data/spec/spec_tests/data/cmap/pool-checkout-connection.yml +6 -2
- data/spec/spec_tests/data/cmap/pool-create-min-size.yml +3 -0
- data/spec/spec_tests/data/connection_string/valid-warnings.yml +24 -0
- data/spec/spec_tests/data/sdam_monitoring/discovered_standalone.yml +1 -3
- data/spec/spec_tests/data/sdam_monitoring/standalone.yml +2 -2
- data/spec/spec_tests/data/sdam_monitoring/standalone_repeated.yml +2 -2
- data/spec/spec_tests/data/sdam_monitoring/standalone_suppress_equal_description_changes.yml +2 -2
- data/spec/spec_tests/data/sdam_monitoring/standalone_to_rs_with_me_mismatch.yml +2 -2
- data/spec/spec_tests/data/uri_options/auth-options.yml +25 -0
- data/spec/spec_tests/data/uri_options/compression-options.yml +6 -3
- data/spec/spec_tests/data/uri_options/read-preference-options.yml +24 -0
- data/spec/spec_tests/data/uri_options/ruby-connection-options.yml +1 -0
- data/spec/spec_tests/data/uri_options/tls-options.yml +160 -4
- data/spec/spec_tests/dns_seedlist_discovery_spec.rb +9 -1
- data/spec/spec_tests/uri_options_spec.rb +31 -33
- data/spec/support/certificates/atlas-ocsp-ca.crt +28 -0
- data/spec/support/certificates/atlas-ocsp.crt +41 -0
- data/spec/support/client_registry.rb +4 -8
- data/spec/support/client_registry_macros.rb +4 -4
- data/spec/support/common_shortcuts.rb +45 -0
- data/spec/support/constraints.rb +23 -0
- data/spec/support/lite_constraints.rb +24 -0
- data/spec/support/matchers.rb +16 -0
- data/spec/support/ocsp +1 -0
- data/spec/support/session_registry.rb +52 -0
- data/spec/support/spec_config.rb +22 -12
- data/spec/support/spec_setup.rb +38 -48
- data/spec/support/utils.rb +19 -1
- data.tar.gz.sig +1 -3
- metadata +938 -933
- metadata.gz.sig +0 -0
- data/spec/integration/secondary_reads_spec.rb +0 -102
- data/spec/shared/LICENSE +0 -20
- data/spec/shared/bin/get-mongodb-download-url +0 -17
- data/spec/shared/lib/mrss/child_process_helper.rb +0 -80
- data/spec/shared/lib/mrss/cluster_config.rb +0 -221
- data/spec/shared/lib/mrss/constraints.rb +0 -346
- data/spec/shared/lib/mrss/docker_runner.rb +0 -265
- data/spec/shared/lib/mrss/lite_constraints.rb +0 -191
- data/spec/shared/lib/mrss/server_version_registry.rb +0 -115
- data/spec/shared/lib/mrss/spec_organizer.rb +0 -152
- data/spec/shared/lib/mrss/utils.rb +0 -15
- data/spec/shared/share/Dockerfile.erb +0 -231
- data/spec/shared/shlib/distro.sh +0 -73
- data/spec/shared/shlib/server.sh +0 -290
- data/spec/shared/shlib/set_env.sh +0 -128
@@ -268,7 +268,7 @@ describe Mongo::ClientEncryption do
|
|
268
268
|
it_behaves_like 'it creates a data key'
|
269
269
|
end
|
270
270
|
|
271
|
-
context 'with
|
271
|
+
context 'with invalid endpoint' do
|
272
272
|
let(:options) do
|
273
273
|
{
|
274
274
|
master_key: {
|
@@ -279,26 +279,20 @@ describe Mongo::ClientEncryption do
|
|
279
279
|
}
|
280
280
|
end
|
281
281
|
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
region: aws_region,
|
291
|
-
endpoint: "invalid-nonsense-endpoint.com"
|
292
|
-
}
|
293
|
-
}
|
282
|
+
let(:expected_message) do
|
283
|
+
# RUBY-2129: This error message could be more specific and inform the user
|
284
|
+
# that there is a problem with their KMS endpoint
|
285
|
+
if BSON::Environment.jruby?
|
286
|
+
/getservbyname.* failed/
|
287
|
+
else
|
288
|
+
/SocketError/
|
289
|
+
end
|
294
290
|
end
|
295
291
|
|
296
292
|
it 'raises an exception' do
|
297
|
-
# RUBY-2129: This error message could be more specific and inform the user
|
298
|
-
# that there is a problem with their KMS endpoint
|
299
293
|
expect do
|
300
294
|
data_key_id
|
301
|
-
end.to raise_error(Mongo::Error::KmsError,
|
295
|
+
end.to raise_error(Mongo::Error::KmsError, expected_message)
|
302
296
|
end
|
303
297
|
end
|
304
298
|
|
data/spec/mongo/client_spec.rb
CHANGED
@@ -894,4 +894,44 @@ describe Mongo::Client do
|
|
894
894
|
end
|
895
895
|
end
|
896
896
|
end
|
897
|
+
|
898
|
+
describe '#summary' do
|
899
|
+
|
900
|
+
context 'monitoring omitted' do
|
901
|
+
let(:client) do
|
902
|
+
new_local_client_nmio(
|
903
|
+
['127.0.0.1:27017'],
|
904
|
+
:read => { :mode => :primary },
|
905
|
+
:database => SpecConfig.instance.test_db
|
906
|
+
)
|
907
|
+
end
|
908
|
+
|
909
|
+
it 'indicates lack of monitoring' do
|
910
|
+
client.summary.should =~ /servers=.*UNKNOWN.*NO-MONITORING/
|
911
|
+
end
|
912
|
+
end
|
913
|
+
|
914
|
+
context 'monitoring present' do
|
915
|
+
let(:client) do
|
916
|
+
authorized_client
|
917
|
+
end
|
918
|
+
|
919
|
+
it 'does not indicate lack of monitoring' do
|
920
|
+
client.summary.should =~ /servers=.*(STANDALONE|PRIMARY|MONGOS)/
|
921
|
+
client.summary.should_not =~ /servers=.*(STANDALONE|PRIMARY|MONGOS).*NO-MONITORING/
|
922
|
+
end
|
923
|
+
end
|
924
|
+
|
925
|
+
context 'background threads killed' do
|
926
|
+
let(:client) do
|
927
|
+
authorized_client.tap do |client|
|
928
|
+
client.cluster.servers.map(&:disconnect!)
|
929
|
+
end
|
930
|
+
end
|
931
|
+
|
932
|
+
it 'does not indicate lack of monitoring' do
|
933
|
+
client.summary.should =~ /servers=.*(STANDALONE|PRIMARY|MONGOS).*NO-MONITORING/
|
934
|
+
end
|
935
|
+
end
|
936
|
+
end
|
897
937
|
end
|
@@ -113,19 +113,28 @@ describe Mongo::Cluster::Topology::Single do
|
|
113
113
|
monitoring, temp_cluster)
|
114
114
|
end
|
115
115
|
|
116
|
+
let(:server_1) do
|
117
|
+
double('server').tap do |server|
|
118
|
+
allow(server).to receive(:address).and_return(Mongo::Address.new('one'))
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
let(:server_2) do
|
123
|
+
double('server').tap do |server|
|
124
|
+
allow(server).to receive(:address).and_return(Mongo::Address.new('two'))
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
116
128
|
let(:temp_cluster) do
|
117
129
|
double('temp cluster').tap do |cluster|
|
118
|
-
allow(cluster).to receive(:servers_list).and_return([
|
119
|
-
double('server'),
|
120
|
-
double('server'),
|
121
|
-
])
|
130
|
+
allow(cluster).to receive(:servers_list).and_return([server_1, server_2])
|
122
131
|
end
|
123
132
|
end
|
124
133
|
|
125
134
|
it 'fails' do
|
126
135
|
expect do
|
127
136
|
topology
|
128
|
-
end.to raise_error(ArgumentError,
|
137
|
+
end.to raise_error(ArgumentError, /Cannot instantiate a single topology with more than one server in the cluster: one, two/)
|
129
138
|
end
|
130
139
|
end
|
131
140
|
end
|
data/spec/mongo/cluster_spec.rb
CHANGED
@@ -178,6 +178,9 @@ describe Mongo::Cluster do
|
|
178
178
|
before do
|
179
179
|
expect(server).to receive(:monitor).at_least(:once).and_return(monitor)
|
180
180
|
expect(monitor).to receive(:scan!)
|
181
|
+
|
182
|
+
# scan! complains that there isn't a monitor on the server, calls summary
|
183
|
+
allow(monitor).to receive(:running?)
|
181
184
|
end
|
182
185
|
|
183
186
|
it 'returns true' do
|
@@ -20,12 +20,95 @@ describe Mongo::Collection::View::Explainable do
|
|
20
20
|
|
21
21
|
describe '#explain' do
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
shared_examples 'executes the explain' do
|
24
|
+
context '3.0+ server' do
|
25
|
+
min_server_fcv '3.0'
|
26
|
+
|
27
|
+
context 'not sharded' do
|
28
|
+
require_topology :single, :replica_set
|
29
|
+
|
30
|
+
it 'executes the explain' do
|
31
|
+
explain[:queryPlanner][:namespace].should == authorized_collection.namespace
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'sharded' do
|
36
|
+
require_topology :sharded
|
37
|
+
|
38
|
+
context 'pre-3.2 server' do
|
39
|
+
max_server_version '3.0'
|
40
|
+
|
41
|
+
it 'executes the explain' do
|
42
|
+
explain[:queryPlanner][:parsedQuery].should be_a(Hash)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context '3.2+ server' do
|
47
|
+
min_server_fcv '3.2'
|
48
|
+
|
49
|
+
it 'executes the explain' do
|
50
|
+
explain[:queryPlanner][:mongosPlannerVersion].should == 1
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context '2.6 server' do
|
57
|
+
max_server_version '2.6'
|
58
|
+
|
59
|
+
it 'executes the explain' do
|
60
|
+
explain[:cursor].should == 'BasicCursor'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'without arguments' do
|
66
|
+
let(:explain) do
|
67
|
+
view.explain
|
68
|
+
end
|
69
|
+
|
70
|
+
include_examples 'executes the explain'
|
25
71
|
end
|
26
72
|
|
27
|
-
|
28
|
-
|
73
|
+
context 'with verbosity argument' do
|
74
|
+
let(:explain) do
|
75
|
+
view.explain(verbosity: verbosity)
|
76
|
+
end
|
77
|
+
|
78
|
+
shared_examples 'triggers server error' do
|
79
|
+
# 3.0 does not produce the error.
|
80
|
+
min_server_fcv '3.2'
|
81
|
+
|
82
|
+
it 'triggers server error' do
|
83
|
+
lambda do
|
84
|
+
explain
|
85
|
+
end.should raise_error(Mongo::Error::OperationFailure, /verbosity string must be/)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'valid symbol value' do
|
90
|
+
let(:verbosity) { :query_planner }
|
91
|
+
|
92
|
+
include_examples 'executes the explain'
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'valid string value' do
|
96
|
+
let(:verbosity) { 'executionStats' }
|
97
|
+
|
98
|
+
include_examples 'executes the explain'
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'invalid symbol value' do
|
102
|
+
let(:verbosity) { :bogus }
|
103
|
+
|
104
|
+
include_examples 'triggers server error'
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'invalid string value' do
|
108
|
+
let(:verbosity) { 'bogus' }
|
109
|
+
|
110
|
+
include_examples 'triggers server error'
|
111
|
+
end
|
29
112
|
end
|
30
113
|
end
|
31
114
|
end
|
@@ -581,6 +581,7 @@ describe Mongo::Collection::View::MapReduce do
|
|
581
581
|
|
582
582
|
context 'when the server is not valid for writing' do
|
583
583
|
clean_slate
|
584
|
+
require_warning_clean
|
584
585
|
|
585
586
|
before do
|
586
587
|
stop_monitoring(authorized_client)
|
@@ -661,6 +662,7 @@ describe Mongo::Collection::View::MapReduce do
|
|
661
662
|
|
662
663
|
context 'when the server is a valid for writing' do
|
663
664
|
clean_slate
|
665
|
+
require_warning_clean
|
664
666
|
|
665
667
|
before do
|
666
668
|
stop_monitoring(authorized_client)
|
@@ -821,6 +821,38 @@ describe Mongo::Collection do
|
|
821
821
|
end
|
822
822
|
end
|
823
823
|
|
824
|
+
context 'when write concern passed in as an option' do
|
825
|
+
min_server_fcv '3.4'
|
826
|
+
require_topology :replica_set
|
827
|
+
|
828
|
+
before do
|
829
|
+
database['collection_spec'].drop
|
830
|
+
end
|
831
|
+
|
832
|
+
let(:events) do
|
833
|
+
subscriber.command_started_events('create')
|
834
|
+
end
|
835
|
+
|
836
|
+
let(:options) do
|
837
|
+
{ write_concern: {w: 1} }
|
838
|
+
end
|
839
|
+
|
840
|
+
let!(:collection) do
|
841
|
+
authorized_collection.with(options)
|
842
|
+
end
|
843
|
+
|
844
|
+
let!(:command) do
|
845
|
+
Utils.get_command_event(authorized_client, 'create') do |client|
|
846
|
+
collection.create({ write_concern: {w: 2} })
|
847
|
+
end.command
|
848
|
+
end
|
849
|
+
|
850
|
+
it 'applies the write concern passed in as an option' do
|
851
|
+
expect(events.length).to eq(1)
|
852
|
+
expect(command[:writeConcern][:w]).to eq(2)
|
853
|
+
end
|
854
|
+
end
|
855
|
+
|
824
856
|
context 'when the server does not support write concern on the create command' do
|
825
857
|
max_server_version '3.2'
|
826
858
|
|
@@ -1059,6 +1091,34 @@ describe Mongo::Collection do
|
|
1059
1091
|
end
|
1060
1092
|
end
|
1061
1093
|
|
1094
|
+
context 'when write concern passed in as an option' do
|
1095
|
+
min_server_fcv '3.4'
|
1096
|
+
require_set_write_concern
|
1097
|
+
|
1098
|
+
let(:events) do
|
1099
|
+
subscriber.command_started_events('drop')
|
1100
|
+
end
|
1101
|
+
|
1102
|
+
let(:options) do
|
1103
|
+
{ write_concern: {w: 1} }
|
1104
|
+
end
|
1105
|
+
|
1106
|
+
let!(:collection) do
|
1107
|
+
authorized_collection.with(options)
|
1108
|
+
end
|
1109
|
+
|
1110
|
+
let!(:command) do
|
1111
|
+
Utils.get_command_event(authorized_client, 'drop') do |client|
|
1112
|
+
collection.drop({ write_concern: {w: 0} })
|
1113
|
+
end.command
|
1114
|
+
end
|
1115
|
+
|
1116
|
+
it 'applies the write concern passed in as an option' do
|
1117
|
+
expect(events.length).to eq(1)
|
1118
|
+
expect(command[:writeConcern][:w]).to eq(0)
|
1119
|
+
end
|
1120
|
+
end
|
1121
|
+
|
1062
1122
|
context 'when the server does not support write concern on the drop command' do
|
1063
1123
|
max_server_version '3.2'
|
1064
1124
|
|
@@ -188,7 +188,7 @@ describe Mongo::Crypt::DataKeyContext do
|
|
188
188
|
end
|
189
189
|
|
190
190
|
context 'with valid endpoint' do
|
191
|
-
let(:options) { { master_key: { region: 'us-east-2', key: 'arn', endpoint: 'kms
|
191
|
+
let(:options) { { master_key: { region: 'us-east-2', key: 'arn', endpoint: 'endpoint/to/kms' } } }
|
192
192
|
|
193
193
|
it 'does not raise an exception' do
|
194
194
|
expect do
|
data/spec/mongo/database_spec.rb
CHANGED
@@ -2,19 +2,6 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Mongo::Database do
|
4
4
|
|
5
|
-
shared_context 'more than 100 collections' do
|
6
|
-
let(:client) do
|
7
|
-
root_authorized_client.use('many-collections')
|
8
|
-
end
|
9
|
-
|
10
|
-
before do
|
11
|
-
120.times do |i|
|
12
|
-
client["coll-#{i}"].drop
|
13
|
-
client["coll-#{i}"].create
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
5
|
describe '#==' do
|
19
6
|
|
20
7
|
let(:database) do
|
@@ -241,20 +228,6 @@ describe Mongo::Database do
|
|
241
228
|
end
|
242
229
|
end
|
243
230
|
end
|
244
|
-
|
245
|
-
context 'when there are more than 100 collections' do
|
246
|
-
include_context 'more than 100 collections'
|
247
|
-
|
248
|
-
let(:collection_names) do
|
249
|
-
client.database.collection_names.sort
|
250
|
-
end
|
251
|
-
|
252
|
-
it 'lists all collections' do
|
253
|
-
collection_names.length.should == 120
|
254
|
-
collection_names.should include('coll-0')
|
255
|
-
collection_names.should include('coll-119')
|
256
|
-
end
|
257
|
-
end
|
258
231
|
end
|
259
232
|
|
260
233
|
describe '#list_collections' do
|
@@ -418,25 +391,6 @@ describe Mongo::Database do
|
|
418
391
|
end
|
419
392
|
end
|
420
393
|
end
|
421
|
-
|
422
|
-
context 'when there are more than 100 collections' do
|
423
|
-
include_context 'more than 100 collections'
|
424
|
-
|
425
|
-
let(:collections) do
|
426
|
-
client.database.list_collections
|
427
|
-
end
|
428
|
-
|
429
|
-
let(:collection_names) do
|
430
|
-
# 2.6 server prefixes collection names with database name
|
431
|
-
collections.map { |info| info['name'].sub(/^many-collections\./, '') }.sort
|
432
|
-
end
|
433
|
-
|
434
|
-
it 'lists all collections' do
|
435
|
-
collections.length.should == 120
|
436
|
-
collection_names.should include('coll-0')
|
437
|
-
collection_names.should include('coll-119')
|
438
|
-
end
|
439
|
-
end
|
440
394
|
end
|
441
395
|
|
442
396
|
describe '#collections' do
|
@@ -587,24 +541,6 @@ describe Mongo::Database do
|
|
587
541
|
end
|
588
542
|
end
|
589
543
|
end
|
590
|
-
|
591
|
-
context 'when there are more than 100 collections' do
|
592
|
-
include_context 'more than 100 collections'
|
593
|
-
|
594
|
-
let(:collections) do
|
595
|
-
client.database.collections
|
596
|
-
end
|
597
|
-
|
598
|
-
let(:collection_names) do
|
599
|
-
collections.map(&:name).sort
|
600
|
-
end
|
601
|
-
|
602
|
-
it 'lists all collections' do
|
603
|
-
collections.length.should == 120
|
604
|
-
collection_names.should include('coll-0')
|
605
|
-
collection_names.should include('coll-119')
|
606
|
-
end
|
607
|
-
end
|
608
544
|
end
|
609
545
|
|
610
546
|
describe '#command' do
|
@@ -889,6 +825,50 @@ describe Mongo::Database do
|
|
889
825
|
end
|
890
826
|
end
|
891
827
|
|
828
|
+
context 'when write concern is passed in as an option' do
|
829
|
+
min_server_fcv '3.4'
|
830
|
+
require_topology :single
|
831
|
+
|
832
|
+
let(:client_options) do
|
833
|
+
{
|
834
|
+
write_concern: {w: 0},
|
835
|
+
database: :test
|
836
|
+
}
|
837
|
+
end
|
838
|
+
|
839
|
+
let(:session) do
|
840
|
+
client.start_session
|
841
|
+
end
|
842
|
+
|
843
|
+
let(:subscriber) { EventSubscriber.new }
|
844
|
+
|
845
|
+
let(:client) do
|
846
|
+
root_authorized_client.tap do |client|
|
847
|
+
client.subscribe(Mongo::Monitoring::COMMAND, subscriber)
|
848
|
+
end.with(client_options)
|
849
|
+
end
|
850
|
+
|
851
|
+
let(:events) do
|
852
|
+
subscriber.command_started_events('dropDatabase')
|
853
|
+
end
|
854
|
+
|
855
|
+
let(:database_test_wc) do
|
856
|
+
client.database
|
857
|
+
end
|
858
|
+
|
859
|
+
let!(:command) do
|
860
|
+
Utils.get_command_event(client, 'dropDatabase') do |client|
|
861
|
+
database_test_wc.drop({ write_concern: {w: 'majority'} })
|
862
|
+
end.command
|
863
|
+
end
|
864
|
+
|
865
|
+
it 'applies the write concern passed in as an option' do
|
866
|
+
expect(events.length).to eq(1)
|
867
|
+
expect(command).to_not be_nil
|
868
|
+
expect(command[:writeConcern][:w]).to eq('majority')
|
869
|
+
end
|
870
|
+
end
|
871
|
+
|
892
872
|
context 'when the server does not support write concern on the dropDatabase command' do
|
893
873
|
max_server_version '3.2'
|
894
874
|
|
@@ -16,7 +16,7 @@ describe Mongo::Error::NoServerAvailable do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'is correct' do
|
19
|
-
expect(error.message).to eq('No primary server is available in cluster: #<Cluster topology=Unknown[127.0.0.1:27017] servers=[#<Server address=127.0.0.1:27017 UNKNOWN>]> with timeout=30, LT=0.015')
|
19
|
+
expect(error.message).to eq('No primary server is available in cluster: #<Cluster topology=Unknown[127.0.0.1:27017] servers=[#<Server address=127.0.0.1:27017 UNKNOWN NO-MONITORING>]> with timeout=30, LT=0.015')
|
20
20
|
end
|
21
21
|
|
22
22
|
context 'when cluster is nil' do
|
@@ -305,8 +305,7 @@ describe Mongo::Index::View do
|
|
305
305
|
{ key: { testing: -1 }, unique: true },
|
306
306
|
{ commit_quorum: 'unsupported-value' }
|
307
307
|
)
|
308
|
-
|
309
|
-
end.to raise_error(Mongo::Error::OperationFailure, /Commit quorum cannot be satisfied with the current replica set configuration|No write concern mode named 'unsupported-value' found in replica set configuration/)
|
308
|
+
end.to raise_error(Mongo::Error::OperationFailure, /Commit quorum cannot be satisfied with the current replica set configuration/)
|
310
309
|
end
|
311
310
|
end
|
312
311
|
end
|
@@ -965,8 +964,7 @@ describe Mongo::Index::View do
|
|
965
964
|
it 'raises an exception' do
|
966
965
|
expect do
|
967
966
|
view.create_one({ 'x' => 1 }, commit_quorum: 'unsupported-value')
|
968
|
-
|
969
|
-
end.to raise_error(Mongo::Error::OperationFailure, /Commit quorum cannot be satisfied with the current replica set configuration|No write concern mode named 'unsupported-value' found in replica set configuration/)
|
967
|
+
end.to raise_error(Mongo::Error::OperationFailure, /Commit quorum cannot be satisfied with the current replica set configuration/)
|
970
968
|
end
|
971
969
|
end
|
972
970
|
end
|
data/spec/mongo/logger_spec.rb
CHANGED
@@ -6,6 +6,16 @@ describe Mongo::Logger do
|
|
6
6
|
described_class.logger
|
7
7
|
end
|
8
8
|
|
9
|
+
around do |example|
|
10
|
+
saved_logger = Mongo::Logger.logger
|
11
|
+
|
12
|
+
begin
|
13
|
+
example.run
|
14
|
+
ensure
|
15
|
+
Mongo::Logger.logger = saved_logger
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
9
19
|
describe '.logger' do
|
10
20
|
|
11
21
|
context 'when no logger has been set' do
|
@@ -18,25 +28,21 @@ describe Mongo::Logger do
|
|
18
28
|
Mongo::Logger.logger = nil
|
19
29
|
end
|
20
30
|
|
21
|
-
after do
|
22
|
-
Mongo::Logger.logger = test_logger
|
23
|
-
end
|
24
|
-
|
25
31
|
it 'returns the default logger' do
|
26
|
-
expect(logger.level).to eq(Logger::
|
32
|
+
expect(logger.level).to eq(Logger::INFO)
|
27
33
|
end
|
28
34
|
end
|
29
35
|
|
30
36
|
context 'when a logger has been set' do
|
31
37
|
|
32
38
|
let(:info) do
|
33
|
-
Logger.new(
|
39
|
+
Logger.new(STDOUT).tap do |log|
|
34
40
|
log.level = Logger::INFO
|
35
41
|
end
|
36
42
|
end
|
37
43
|
|
38
44
|
let(:debug) do
|
39
|
-
Logger.new(
|
45
|
+
Logger.new(STDOUT).tap do |log|
|
40
46
|
log.level = Logger::DEBUG
|
41
47
|
end
|
42
48
|
end
|
@@ -45,10 +51,6 @@ describe Mongo::Logger do
|
|
45
51
|
described_class.logger = debug
|
46
52
|
end
|
47
53
|
|
48
|
-
after do
|
49
|
-
described_class.logger = info
|
50
|
-
end
|
51
|
-
|
52
54
|
it 'returns the provided logger' do
|
53
55
|
expect(logger.level).to eq(Logger::DEBUG)
|
54
56
|
end
|
@@ -46,10 +46,10 @@ describe Mongo::Operation::ReadPreferenceSupported do
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
describe '#
|
49
|
+
describe '#add_slave_ok_flag_maybe' do
|
50
50
|
|
51
51
|
let(:actual) do
|
52
|
-
operation.send(:
|
52
|
+
operation.send(:add_slave_ok_flag_maybe, operation.send(:options), connection)
|
53
53
|
end
|
54
54
|
|
55
55
|
shared_examples_for 'sets the slave_ok flag as expected' do
|
@@ -60,7 +60,9 @@ describe Mongo::Operation::ReadPreferenceSupported do
|
|
60
60
|
|
61
61
|
shared_examples_for 'never sets slave_ok' do
|
62
62
|
|
63
|
-
let(:expected)
|
63
|
+
let(:expected) do
|
64
|
+
{ }
|
65
|
+
end
|
64
66
|
|
65
67
|
context 'when no read preference is specified' do
|
66
68
|
let(:read_pref) { Mongo::ServerSelector.get }
|
@@ -83,7 +85,9 @@ describe Mongo::Operation::ReadPreferenceSupported do
|
|
83
85
|
|
84
86
|
shared_examples_for 'always sets slave_ok' do
|
85
87
|
|
86
|
-
let(:expected)
|
88
|
+
let(:expected) do
|
89
|
+
{ :flags => [ :slave_ok ] }
|
90
|
+
end
|
87
91
|
|
88
92
|
context 'when no read preference is specified' do
|
89
93
|
let(:read_pref) { Mongo::ServerSelector.get }
|
@@ -110,7 +114,9 @@ describe Mongo::Operation::ReadPreferenceSupported do
|
|
110
114
|
|
111
115
|
let(:read_pref) { Mongo::ServerSelector.get }
|
112
116
|
|
113
|
-
let(:expected)
|
117
|
+
let(:expected) do
|
118
|
+
{ }
|
119
|
+
end
|
114
120
|
|
115
121
|
it_behaves_like 'sets the slave_ok flag as expected'
|
116
122
|
end
|
@@ -121,7 +127,9 @@ describe Mongo::Operation::ReadPreferenceSupported do
|
|
121
127
|
|
122
128
|
let(:read_pref) { Mongo::ServerSelector.get(:mode => :secondary) }
|
123
129
|
|
124
|
-
let(:expected)
|
130
|
+
let(:expected) do
|
131
|
+
{ :flags => [ :slave_ok ] }
|
132
|
+
end
|
125
133
|
|
126
134
|
it_behaves_like 'sets the slave_ok flag as expected'
|
127
135
|
end
|
@@ -130,7 +138,9 @@ describe Mongo::Operation::ReadPreferenceSupported do
|
|
130
138
|
|
131
139
|
let(:read_pref) { Mongo::ServerSelector.get(:mode => :primary) }
|
132
140
|
|
133
|
-
let(:expected)
|
141
|
+
let(:expected) do
|
142
|
+
{ }
|
143
|
+
end
|
134
144
|
|
135
145
|
it_behaves_like 'sets the slave_ok flag as expected'
|
136
146
|
end
|
@@ -196,7 +206,7 @@ describe Mongo::Operation::ReadPreferenceSupported do
|
|
196
206
|
end
|
197
207
|
end
|
198
208
|
|
199
|
-
describe '#
|
209
|
+
describe '#update_selector_for_read_pref' do
|
200
210
|
|
201
211
|
let(:read_pref) do
|
202
212
|
Mongo::ServerSelector.get(:mode => mode)
|
@@ -205,7 +215,7 @@ describe Mongo::Operation::ReadPreferenceSupported do
|
|
205
215
|
# Behavior of sending $readPreference is the same regardless of topology.
|
206
216
|
shared_examples_for '$readPreference in the command' do
|
207
217
|
let(:actual) do
|
208
|
-
operation.send(:
|
218
|
+
operation.send(:update_selector_for_read_pref, operation.send(:selector), connection)
|
209
219
|
end
|
210
220
|
|
211
221
|
let(:expected_read_preference) do
|