mongo 2.3.1 → 2.4.0.rc0
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 +0 -0
- data.tar.gz.sig +2 -3
- data/lib/mongo/bulk_write.rb +8 -7
- data/lib/mongo/bulk_write/combineable.rb +4 -0
- data/lib/mongo/bulk_write/transformable.rb +17 -5
- data/lib/mongo/bulk_write/validatable.rb +1 -0
- data/lib/mongo/client.rb +3 -0
- data/lib/mongo/cluster.rb +8 -0
- data/lib/mongo/cluster/app_metadata.rb +135 -0
- data/lib/mongo/collection.rb +42 -10
- data/lib/mongo/collection/view.rb +15 -1
- data/lib/mongo/collection/view/aggregation.rb +5 -0
- data/lib/mongo/collection/view/builder/aggregation.rb +13 -3
- data/lib/mongo/collection/view/builder/find_command.rb +7 -21
- data/lib/mongo/collection/view/builder/map_reduce.rb +22 -5
- data/lib/mongo/collection/view/iterable.rb +1 -0
- data/lib/mongo/collection/view/map_reduce.rb +5 -0
- data/lib/mongo/collection/view/readable.rb +35 -14
- data/lib/mongo/collection/view/writable.rb +54 -23
- data/lib/mongo/cursor/builder/get_more_command.rb +2 -3
- data/lib/mongo/database.rb +10 -2
- data/lib/mongo/error.rb +2 -0
- data/lib/mongo/error/invalid_application_name.rb +38 -0
- data/lib/mongo/error/invalid_server_preference.rb +24 -3
- data/lib/mongo/error/unsupported_collation.rb +51 -0
- data/lib/mongo/index/view.rb +28 -15
- data/lib/mongo/operation.rb +6 -0
- data/lib/mongo/operation/commands.rb +3 -0
- data/lib/mongo/operation/commands/aggregate.rb +10 -10
- data/lib/mongo/operation/commands/create.rb +45 -0
- data/lib/mongo/operation/commands/drop.rb +45 -0
- data/lib/mongo/operation/commands/drop_database.rb +45 -0
- data/lib/mongo/operation/commands/map_reduce.rb +12 -1
- data/lib/mongo/operation/commands/parallel_scan.rb +1 -0
- data/lib/mongo/operation/read_preference.rb +9 -9
- data/lib/mongo/operation/specifiable.rb +34 -0
- data/lib/mongo/operation/takes_write_concern.rb +35 -0
- data/lib/mongo/operation/write/bulk/bulkable.rb +1 -1
- data/lib/mongo/operation/write/command/create_index.rb +6 -0
- data/lib/mongo/operation/write/command/drop_index.rb +6 -0
- data/lib/mongo/operation/write/command/insert.rb +1 -1
- data/lib/mongo/operation/write/command/update.rb +1 -0
- data/lib/mongo/operation/write/command/writable.rb +2 -2
- data/lib/mongo/operation/write/create_index.rb +2 -2
- data/lib/mongo/operation/write/create_user.rb +1 -1
- data/lib/mongo/operation/write/delete.rb +5 -1
- data/lib/mongo/operation/write/gle.rb +1 -1
- data/lib/mongo/operation/write/insert.rb +2 -2
- data/lib/mongo/operation/write/remove_user.rb +1 -1
- data/lib/mongo/operation/write/update.rb +5 -1
- data/lib/mongo/operation/write/update_user.rb +1 -1
- data/lib/mongo/operation/write/write_command_enabled.rb +10 -2
- data/lib/mongo/protocol/insert.rb +1 -2
- data/lib/mongo/protocol/query.rb +3 -7
- data/lib/mongo/server.rb +8 -3
- data/lib/mongo/server/connection.rb +17 -11
- data/lib/mongo/server/description.rb +22 -0
- data/lib/mongo/server/description/features.rb +2 -0
- data/lib/mongo/server/monitor.rb +5 -0
- data/lib/mongo/server/monitor/connection.rb +11 -0
- data/lib/mongo/server_selector/nearest.rb +9 -6
- data/lib/mongo/server_selector/primary.rb +4 -0
- data/lib/mongo/server_selector/primary_preferred.rb +7 -1
- data/lib/mongo/server_selector/secondary.rb +5 -0
- data/lib/mongo/server_selector/secondary_preferred.rb +7 -2
- data/lib/mongo/server_selector/selectable.rb +57 -10
- data/lib/mongo/socket/ssl.rb +1 -0
- data/lib/mongo/uri.rb +4 -0
- data/lib/mongo/version.rb +1 -1
- data/lib/mongo/write_concern.rb +1 -0
- data/mongo.gemspec +1 -1
- data/spec/mongo/auth/cr_spec.rb +7 -1
- data/spec/mongo/auth/ldap_spec.rb +7 -1
- data/spec/mongo/auth/scram_spec.rb +7 -1
- data/spec/mongo/auth/x509_spec.rb +7 -1
- data/spec/mongo/bulk_write_spec.rb +598 -5
- data/spec/mongo/client_spec.rb +47 -1
- data/spec/mongo/cluster/app_metadata_spec.rb +104 -0
- data/spec/mongo/cluster/topology/replica_set_spec.rb +14 -8
- data/spec/mongo/cluster/topology/sharded_spec.rb +9 -3
- data/spec/mongo/cluster/topology/single_spec.rb +10 -4
- data/spec/mongo/cluster_spec.rb +29 -0
- data/spec/mongo/collection/view/aggregation_spec.rb +139 -0
- data/spec/mongo/collection/view/builder/find_command_spec.rb +6 -243
- data/spec/mongo/collection/view/map_reduce_spec.rb +104 -0
- data/spec/mongo/collection/view/readable_spec.rb +83 -0
- data/spec/mongo/collection/view/writable_spec.rb +447 -1
- data/spec/mongo/collection/view_spec.rb +57 -0
- data/spec/mongo/collection_spec.rb +926 -101
- data/spec/mongo/crud_spec.rb +4 -5
- data/spec/mongo/database_spec.rb +99 -1
- data/spec/mongo/index/view_spec.rb +360 -31
- data/spec/mongo/max_staleness_spec.rb +108 -0
- data/spec/mongo/operation/read_preference_spec.rb +8 -8
- data/spec/mongo/operation/write/command/delete_spec.rb +1 -1
- data/spec/mongo/operation/write/command/insert_spec.rb +1 -1
- data/spec/mongo/operation/write/command/update_spec.rb +1 -1
- data/spec/mongo/server/connection_pool_spec.rb +3 -1
- data/spec/mongo/server/connection_spec.rb +17 -7
- data/spec/mongo/server/description/features_spec.rb +50 -0
- data/spec/mongo/server/description_spec.rb +9 -3
- data/spec/mongo/server_selection_spec.rb +5 -3
- data/spec/mongo/server_selector/nearest_spec.rb +73 -0
- data/spec/mongo/server_selector/primary_preferred_spec.rb +73 -0
- data/spec/mongo/server_selector/primary_spec.rb +36 -0
- data/spec/mongo/server_selector/secondary_preferred_spec.rb +73 -0
- data/spec/mongo/server_selector/secondary_spec.rb +73 -0
- data/spec/mongo/server_selector_spec.rb +53 -0
- data/spec/mongo/server_spec.rb +3 -1
- data/spec/mongo/uri_spec.rb +54 -0
- data/spec/mongo/write_concern_spec.rb +18 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/support/authorization.rb +8 -1
- data/spec/support/crud.rb +15 -0
- data/spec/support/crud/read.rb +27 -19
- data/spec/support/crud/write.rb +28 -3
- data/spec/support/crud_tests/read/aggregate.yml +15 -3
- data/spec/support/crud_tests/read/count.yml +14 -3
- data/spec/support/crud_tests/read/distinct.yml +13 -1
- data/spec/support/crud_tests/read/find.yml +12 -2
- data/spec/support/crud_tests/write/deleteMany.yml +22 -1
- data/spec/support/crud_tests/write/deleteOne.yml +20 -1
- data/spec/support/crud_tests/write/findOneAndDelete.yml +27 -2
- data/spec/support/crud_tests/write/findOneAndReplace.yml +43 -14
- data/spec/support/crud_tests/write/findOneAndUpdate.yml +50 -8
- data/spec/support/crud_tests/write/replaceOne.yml +34 -10
- data/spec/support/crud_tests/write/updateMany.yml +42 -11
- data/spec/support/crud_tests/write/updateOne.yml +32 -7
- data/spec/support/max_staleness/ReplicaSetNoPrimary/DefaultNoMaxStaleness.yml +26 -0
- data/spec/support/max_staleness/ReplicaSetNoPrimary/Incompatible.yml +25 -0
- data/spec/support/max_staleness/ReplicaSetNoPrimary/LastUpdateTime.yml +33 -0
- data/spec/support/max_staleness/ReplicaSetNoPrimary/Nearest.yml +33 -0
- data/spec/support/max_staleness/ReplicaSetNoPrimary/Nearest2.yml +33 -0
- data/spec/support/max_staleness/ReplicaSetNoPrimary/PrimaryPreferred.yml +27 -0
- data/spec/support/max_staleness/ReplicaSetNoPrimary/PrimaryPreferred_tags.yml +36 -0
- data/spec/support/max_staleness/ReplicaSetNoPrimary/Secondary.yml +51 -0
- data/spec/support/max_staleness/ReplicaSetNoPrimary/SecondaryPreferred.yml +26 -0
- data/spec/support/max_staleness/ReplicaSetNoPrimary/SecondaryPreferred_tags.yml +51 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/DefaultNoMaxStaleness.yml +26 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/Incompatible.yml +25 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/LastUpdateTime.yml +35 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/MaxStalenessTooSmall.yml +25 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/MaxStalenessWithModePrimary.yml +23 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/Nearest.yml +33 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/Nearest2.yml +33 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/Nearest_tags.yml +36 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/PrimaryPreferred.yml +27 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/PrimaryPreferred_incompatible.yml +27 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred.yml +26 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred_tags.yml +59 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred_tags2.yml +43 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/Secondary_tags.yml +59 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/Secondary_tags2.yml +43 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/ShortHeartbeartShortMaxStaleness.yml +29 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/ShortHeartbeartShortMaxStaleness2.yml +29 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/ZeroMaxStaleness.yml +27 -0
- data/spec/support/max_staleness/Sharded/Incompatible.yml +25 -0
- data/spec/support/max_staleness/Sharded/SmallMaxStaleness.yml +20 -0
- data/spec/support/max_staleness/Single/Incompatible.yml +18 -0
- data/spec/support/max_staleness/Single/SmallMaxStaleness.yml +20 -0
- data/spec/support/server_selection.rb +25 -0
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Nearest_multiple.yml +27 -0
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Secondary_multi_tags.yml +31 -0
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Secondary_multi_tags2.yml +31 -0
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Nearest_multiple.yml +34 -0
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/SecondaryPreferred_tags.yml +28 -0
- data/spec/support/shared/server_selector.rb +4 -3
- metadata +91 -6
- metadata.gz.sig +0 -0
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Max Staleness Spec' do
|
4
|
+
|
5
|
+
include Mongo::ServerSelection::Read
|
6
|
+
|
7
|
+
MAX_STALENESS_TESTS.each do |file|
|
8
|
+
|
9
|
+
spec = Mongo::ServerSelection::Read::Spec.new(file)
|
10
|
+
|
11
|
+
context(spec.description) do
|
12
|
+
|
13
|
+
let(:topology) do
|
14
|
+
spec.type.new({})
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:monitoring) do
|
18
|
+
Mongo::Monitoring.new
|
19
|
+
end
|
20
|
+
|
21
|
+
let(:listeners) do
|
22
|
+
Mongo::Event::Listeners.new
|
23
|
+
end
|
24
|
+
|
25
|
+
let(:options) do
|
26
|
+
if spec.heartbeat_frequency
|
27
|
+
TEST_OPTIONS.merge(heartbeat_frequency: spec.heartbeat_frequency)
|
28
|
+
else
|
29
|
+
copy = TEST_OPTIONS.dup
|
30
|
+
copy.delete(:heartbeat_frequency)
|
31
|
+
copy
|
32
|
+
end.merge!(server_selection_timeout: 0.2)
|
33
|
+
end
|
34
|
+
|
35
|
+
let(:cluster) do
|
36
|
+
double('cluster').tap do |c|
|
37
|
+
allow(c).to receive(:topology).and_return(topology)
|
38
|
+
allow(c).to receive(:single?).and_return(topology.single?)
|
39
|
+
allow(c).to receive(:sharded?).and_return(topology.sharded?)
|
40
|
+
allow(c).to receive(:replica_set?).and_return(topology.replica_set?)
|
41
|
+
allow(c).to receive(:options).and_return(options.merge(server_selection_timeout: 0.2))
|
42
|
+
allow(c).to receive(:scan!).and_return(true)
|
43
|
+
allow(c).to receive(:app_metadata).and_return(app_metadata)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
let(:candidate_servers) do
|
48
|
+
spec.candidate_servers.collect do |server|
|
49
|
+
features = double('features').tap do |feat|
|
50
|
+
allow(feat).to receive(:max_staleness_enabled?).and_return(server['maxWireVersion'] >= 5)
|
51
|
+
end
|
52
|
+
address = Mongo::Address.new(server['address'])
|
53
|
+
Mongo::Server.new(address, cluster, monitoring, listeners, options).tap do |s|
|
54
|
+
allow(s).to receive(:average_round_trip_time).and_return(server['avg_rtt_ms'])
|
55
|
+
allow(s).to receive(:tags).and_return(server['tags'])
|
56
|
+
allow(s).to receive(:secondary?).and_return(server['type'] == 'RSSecondary')
|
57
|
+
allow(s).to receive(:primary?).and_return(server['type'] == 'RSPrimary')
|
58
|
+
allow(s).to receive(:connectable?).and_return(true)
|
59
|
+
allow(s).to receive(:last_write_date).and_return(server['lastWrite']['lastWriteDate']['$numberLong'].to_i * 1000)
|
60
|
+
allow(s).to receive(:last_scan).and_return(server['lastUpdateTime'] * 1000)
|
61
|
+
allow(s).to receive(:features).and_return(features)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
let(:in_latency_window) do
|
67
|
+
spec.in_latency_window.collect do |server|
|
68
|
+
Mongo::Server.new(Mongo::Address.new(server['address']), cluster, monitoring, listeners)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
let(:server_selector_definition) do
|
73
|
+
{ mode: spec.read_preference['mode'] }.tap do |definition|
|
74
|
+
definition[:tag_sets] = spec.read_preference['tag_sets']
|
75
|
+
definition[:max_staleness] = spec.max_staleness if spec.max_staleness
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
let(:server_selector) do
|
80
|
+
Mongo::ServerSelector.get(server_selector_definition)
|
81
|
+
end
|
82
|
+
|
83
|
+
before do
|
84
|
+
allow(cluster).to receive(:servers).and_return(candidate_servers)
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'Valid read preference and matching server available', unless: spec.invalid_max_staleness? do
|
88
|
+
|
89
|
+
it 'Finds all suitable servers in the latency window', if: spec.replica_set? do
|
90
|
+
expect(server_selector.send(:select, cluster.servers)).to match_array(in_latency_window)
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'Finds the most suitable server in the latency window' do
|
94
|
+
expect(in_latency_window).to include(server_selector.select_server(cluster))
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context 'when the max staleness cannot be applied', if: spec.invalid_max_staleness? do
|
99
|
+
|
100
|
+
it 'Raises exception' do
|
101
|
+
expect do
|
102
|
+
server_selector.select_server(cluster)
|
103
|
+
end.to raise_exception(Mongo::Error::InvalidServerPreference)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -55,7 +55,7 @@ describe Mongo::Operation::ReadPreference do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'returns a special selector' do
|
58
|
-
expect(operation.send(:
|
58
|
+
expect(operation.send(:update_selector_for_read_pref, operation.send(:selector), server)).to eq(expected)
|
59
59
|
end
|
60
60
|
|
61
61
|
context 'when the selector already has $query in it' do
|
@@ -70,7 +70,7 @@ describe Mongo::Operation::ReadPreference do
|
|
70
70
|
end
|
71
71
|
|
72
72
|
it 'returns an unaltered special selector' do
|
73
|
-
expect(operation.send(:
|
73
|
+
expect(operation.send(:update_selector_for_read_pref, operation.send(:selector), server)).to eq(expected)
|
74
74
|
end
|
75
75
|
end
|
76
76
|
end
|
@@ -82,7 +82,7 @@ describe Mongo::Operation::ReadPreference do
|
|
82
82
|
end
|
83
83
|
|
84
84
|
it 'returns a selector' do
|
85
|
-
expect(operation.send(:
|
85
|
+
expect(operation.send(:update_selector_for_read_pref, operation.send(:selector), server)).to eq(selector)
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
@@ -168,7 +168,7 @@ describe Mongo::Operation::ReadPreference do
|
|
168
168
|
end
|
169
169
|
|
170
170
|
it 'does not set the slave_ok flag' do
|
171
|
-
expect(operation.send(:
|
171
|
+
expect(operation.send(:update_options_for_slave_ok, operation.send(:options), server)).to eq(expected)
|
172
172
|
end
|
173
173
|
end
|
174
174
|
|
@@ -183,7 +183,7 @@ describe Mongo::Operation::ReadPreference do
|
|
183
183
|
end
|
184
184
|
|
185
185
|
it 'sets the slave_ok flag' do
|
186
|
-
expect(operation.send(:
|
186
|
+
expect(operation.send(:update_options_for_slave_ok, operation.send(:options), server)).to eq(expected)
|
187
187
|
end
|
188
188
|
end
|
189
189
|
end
|
@@ -205,7 +205,7 @@ describe Mongo::Operation::ReadPreference do
|
|
205
205
|
end
|
206
206
|
|
207
207
|
it 'does not set the slave_ok flag' do
|
208
|
-
expect(operation.send(:
|
208
|
+
expect(operation.send(:update_options_for_slave_ok, operation.send(:options), server)).to eq(expected)
|
209
209
|
end
|
210
210
|
end
|
211
211
|
|
@@ -222,7 +222,7 @@ describe Mongo::Operation::ReadPreference do
|
|
222
222
|
end
|
223
223
|
|
224
224
|
it 'sets the slave_ok flag' do
|
225
|
-
expect(operation.send(:
|
225
|
+
expect(operation.send(:update_options_for_slave_ok, operation.send(:options), server)).to eq(expected)
|
226
226
|
end
|
227
227
|
end
|
228
228
|
|
@@ -237,7 +237,7 @@ describe Mongo::Operation::ReadPreference do
|
|
237
237
|
end
|
238
238
|
|
239
239
|
it 'does not set the slave_ok flag' do
|
240
|
-
expect(operation.send(:
|
240
|
+
expect(operation.send(:update_options_for_slave_ok, operation.send(:options), server)).to eq(expected)
|
241
241
|
end
|
242
242
|
end
|
243
243
|
end
|
@@ -104,7 +104,7 @@ describe Mongo::Operation::Write::Command::Update do
|
|
104
104
|
|
105
105
|
it 'creates the correct Command message' do
|
106
106
|
expect(Mongo::Protocol::Query).to receive(:new).with(TEST_DB, '$cmd', expected_selector, { limit: -1 })
|
107
|
-
op.send(:message)
|
107
|
+
op.send(:message, double('server'))
|
108
108
|
end
|
109
109
|
end
|
110
110
|
end
|
@@ -14,8 +14,14 @@ describe Mongo::Server::Connection do
|
|
14
14
|
Mongo::Event::Listeners.new
|
15
15
|
end
|
16
16
|
|
17
|
+
let(:app_metadata) do
|
18
|
+
Mongo::Cluster::AppMetadata.new(authorized_client.cluster)
|
19
|
+
end
|
20
|
+
|
17
21
|
let(:cluster) do
|
18
|
-
double('cluster')
|
22
|
+
double('cluster').tap do |cl|
|
23
|
+
allow(cl).to receive(:app_metadata).and_return(app_metadata)
|
24
|
+
end
|
19
25
|
end
|
20
26
|
|
21
27
|
let(:server) do
|
@@ -59,7 +65,7 @@ describe Mongo::Server::Connection do
|
|
59
65
|
context 'when no socket exists' do
|
60
66
|
|
61
67
|
let(:connection) do
|
62
|
-
described_class.new(server)
|
68
|
+
described_class.new(server, server.options)
|
63
69
|
end
|
64
70
|
|
65
71
|
let!(:result) do
|
@@ -86,7 +92,7 @@ describe Mongo::Server::Connection do
|
|
86
92
|
context 'when a socket exists' do
|
87
93
|
|
88
94
|
let(:connection) do
|
89
|
-
described_class.new(server)
|
95
|
+
described_class.new(server, server.options)
|
90
96
|
end
|
91
97
|
|
92
98
|
before do
|
@@ -163,7 +169,7 @@ describe Mongo::Server::Connection do
|
|
163
169
|
context 'when a socket is not connected' do
|
164
170
|
|
165
171
|
let(:connection) do
|
166
|
-
described_class.new(server)
|
172
|
+
described_class.new(server, server.options)
|
167
173
|
end
|
168
174
|
|
169
175
|
it 'does not raise an error' do
|
@@ -174,7 +180,7 @@ describe Mongo::Server::Connection do
|
|
174
180
|
context 'when a socket is connected' do
|
175
181
|
|
176
182
|
let(:connection) do
|
177
|
-
described_class.new(server)
|
183
|
+
described_class.new(server, server.options)
|
178
184
|
end
|
179
185
|
|
180
186
|
before do
|
@@ -431,7 +437,7 @@ describe Mongo::Server::Connection do
|
|
431
437
|
context 'when host and port are provided' do
|
432
438
|
|
433
439
|
let(:connection) do
|
434
|
-
described_class.new(server)
|
440
|
+
described_class.new(server, server.options)
|
435
441
|
end
|
436
442
|
|
437
443
|
it 'sets the address' do
|
@@ -535,7 +541,7 @@ describe Mongo::Server::Connection do
|
|
535
541
|
describe '#auth_mechanism' do
|
536
542
|
|
537
543
|
let(:connection) do
|
538
|
-
described_class.new(server)
|
544
|
+
described_class.new(server, server.options)
|
539
545
|
end
|
540
546
|
|
541
547
|
let(:reply) do
|
@@ -564,6 +570,7 @@ describe Mongo::Server::Connection do
|
|
564
570
|
socket = connection.instance_variable_get(:@socket)
|
565
571
|
max_message_size = connection.send(:max_message_size)
|
566
572
|
allow(Mongo::Protocol::Reply).to receive(:deserialize).with(socket, max_message_size).and_return(reply)
|
573
|
+
connection.send(:handshake!)
|
567
574
|
expect(connection.send(:default_mechanism)).to eq(:scram)
|
568
575
|
end
|
569
576
|
end
|
@@ -574,6 +581,7 @@ describe Mongo::Server::Connection do
|
|
574
581
|
socket = connection.instance_variable_get(:@socket)
|
575
582
|
max_message_size = connection.send(:max_message_size)
|
576
583
|
allow(Mongo::Protocol::Reply).to receive(:deserialize).with(socket, max_message_size).and_return(reply)
|
584
|
+
connection.send(:handshake!)
|
577
585
|
expect(connection.send(:default_mechanism)).to eq(:scram)
|
578
586
|
end
|
579
587
|
end
|
@@ -595,6 +603,7 @@ describe Mongo::Server::Connection do
|
|
595
603
|
socket = connection.instance_variable_get(:@socket)
|
596
604
|
max_message_size = connection.send(:max_message_size)
|
597
605
|
allow(Mongo::Protocol::Reply).to receive(:deserialize).with(socket, max_message_size).and_return(reply)
|
606
|
+
connection.send(:handshake!)
|
598
607
|
expect(connection.send(:default_mechanism)).to eq(:scram)
|
599
608
|
end
|
600
609
|
end
|
@@ -605,6 +614,7 @@ describe Mongo::Server::Connection do
|
|
605
614
|
socket = connection.instance_variable_get(:@socket)
|
606
615
|
max_message_size = connection.send(:max_message_size)
|
607
616
|
allow(Mongo::Protocol::Reply).to receive(:deserialize).with(socket, max_message_size).and_return(reply)
|
617
|
+
connection.send(:handshake!)
|
608
618
|
expect(connection.send(:default_mechanism)).to eq(:mongodb_cr)
|
609
619
|
end
|
610
620
|
end
|
@@ -56,6 +56,56 @@ describe Mongo::Server::Description::Features do
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
+
describe '#collation_enabled?' do
|
60
|
+
|
61
|
+
context 'when the wire range includes 5' do
|
62
|
+
|
63
|
+
let(:features) do
|
64
|
+
described_class.new(0..5)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'returns true' do
|
68
|
+
expect(features).to be_collation_enabled
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'when the wire range does not include 5' do
|
73
|
+
|
74
|
+
let(:features) do
|
75
|
+
described_class.new(0..2)
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'returns false' do
|
79
|
+
expect(features).to_not be_collation_enabled
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe '#max_staleness_enabled?' do
|
85
|
+
|
86
|
+
context 'when the wire range includes 5' do
|
87
|
+
|
88
|
+
let(:features) do
|
89
|
+
described_class.new(0..5)
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'returns true' do
|
93
|
+
expect(features).to be_max_staleness_enabled
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'when the wire range does not include 5' do
|
98
|
+
|
99
|
+
let(:features) do
|
100
|
+
described_class.new(0..2)
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'returns false' do
|
104
|
+
expect(features).to_not be_max_staleness_enabled
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
59
109
|
describe '#find_command_enabled?' do
|
60
110
|
|
61
111
|
context 'when the wire range includes 4' do
|
@@ -35,6 +35,12 @@ describe Mongo::Server::Description do
|
|
35
35
|
Mongo::Monitoring.new
|
36
36
|
end
|
37
37
|
|
38
|
+
let(:cluster) do
|
39
|
+
double('cluster').tap do |cl|
|
40
|
+
allow(cl).to receive(:app_metadata).and_return(app_metadata)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
38
44
|
describe '#arbiter?' do
|
39
45
|
|
40
46
|
context 'when the server is an arbiter' do
|
@@ -587,7 +593,7 @@ describe Mongo::Server::Description do
|
|
587
593
|
end
|
588
594
|
|
589
595
|
let(:server) do
|
590
|
-
Mongo::Server.new(address,
|
596
|
+
Mongo::Server.new(address, cluster, monitoring, listeners)
|
591
597
|
end
|
592
598
|
|
593
599
|
let(:description) do
|
@@ -608,7 +614,7 @@ describe Mongo::Server::Description do
|
|
608
614
|
end
|
609
615
|
|
610
616
|
let(:server) do
|
611
|
-
Mongo::Server.new(other_address,
|
617
|
+
Mongo::Server.new(other_address, cluster, monitoring, listeners)
|
612
618
|
end
|
613
619
|
|
614
620
|
it 'returns false' do
|
@@ -674,7 +680,7 @@ describe Mongo::Server::Description do
|
|
674
680
|
end
|
675
681
|
|
676
682
|
let(:server) do
|
677
|
-
Mongo::Server.new(server_address,
|
683
|
+
Mongo::Server.new(server_address, cluster, monitoring, listeners)
|
678
684
|
end
|
679
685
|
|
680
686
|
context 'when the server is included in the description hosts list' do
|
@@ -28,13 +28,14 @@ describe 'Server Selection' do
|
|
28
28
|
allow(c).to receive(:single?).and_return(topology.single?)
|
29
29
|
allow(c).to receive(:sharded?).and_return(topology.sharded?)
|
30
30
|
allow(c).to receive(:replica_set?).and_return(topology.replica_set?)
|
31
|
+
allow(c).to receive(:app_metadata).and_return(app_metadata)
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
34
35
|
let(:candidate_servers) do
|
35
36
|
spec.candidate_servers.collect do |server|
|
36
37
|
address = Mongo::Address.new(server['address'])
|
37
|
-
Mongo::Server.new(address,
|
38
|
+
Mongo::Server.new(address, cluster, monitoring, listeners, TEST_OPTIONS).tap do |s|
|
38
39
|
allow(s).to receive(:average_round_trip_time).and_return(server['avg_rtt_ms'])
|
39
40
|
allow(s).to receive(:tags).and_return(server['tags'])
|
40
41
|
allow(s).to receive(:secondary?).and_return(server['type'] == 'RSSecondary')
|
@@ -47,7 +48,7 @@ describe 'Server Selection' do
|
|
47
48
|
let(:in_latency_window) do
|
48
49
|
spec.in_latency_window.collect do |server|
|
49
50
|
address = Mongo::Address.new(server['address'])
|
50
|
-
Mongo::Server.new(address,
|
51
|
+
Mongo::Server.new(address, cluster, monitoring, listeners, TEST_OPTIONS).tap do |s|
|
51
52
|
allow(s).to receive(:average_round_trip_time).and_return(server['avg_rtt_ms'])
|
52
53
|
allow(s).to receive(:tags).and_return(server['tags'])
|
53
54
|
allow(s).to receive(:connectable?).and_return(true)
|
@@ -64,12 +65,13 @@ describe 'Server Selection' do
|
|
64
65
|
allow(cluster).to receive(:servers).and_return(candidate_servers)
|
65
66
|
allow(cluster).to receive(:options).and_return(server_selection_timeout: 0.2)
|
66
67
|
allow(cluster).to receive(:scan!).and_return(true)
|
68
|
+
allow(cluster).to receive(:app_metadata).and_return(app_metadata)
|
67
69
|
end
|
68
70
|
|
69
71
|
context 'Valid read preference and matching server available', if: spec.server_available? do
|
70
72
|
|
71
73
|
it 'Finds all suitable servers in the latency window', if: spec.replica_set? do
|
72
|
-
expect(server_selector.send(:select, cluster.servers)).to
|
74
|
+
expect(server_selector.send(:select, cluster.servers)).to match_array(in_latency_window)
|
73
75
|
end
|
74
76
|
|
75
77
|
it 'Finds the most suitable server in the latency window' do
|