mongo 2.0.5 → 2.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/mongo/auth/cr/conversation.rb +0 -1
- data/lib/mongo/client.rb +19 -5
- data/lib/mongo/cluster.rb +84 -16
- data/lib/mongo/cluster/topology.rb +3 -4
- data/lib/mongo/cluster/topology/replica_set.rb +75 -0
- data/lib/mongo/cluster/topology/sharded.rb +60 -0
- data/lib/mongo/cluster/topology/single.rb +51 -0
- data/lib/mongo/cluster/topology/unknown.rb +62 -0
- data/lib/mongo/error/invalid_bulk_operation.rb +2 -1
- data/lib/mongo/event.rb +9 -9
- data/lib/mongo/event/{server_added.rb → description_changed.rb} +6 -5
- data/lib/mongo/event/{server_removed.rb → standalone_discovered.rb} +15 -15
- data/lib/mongo/operation/aggregate.rb +6 -5
- data/lib/mongo/operation/command.rb +5 -6
- data/lib/mongo/operation/kill_cursors.rb +3 -2
- data/lib/mongo/operation/map_reduce.rb +6 -5
- data/lib/mongo/operation/read/collections_info.rb +5 -4
- data/lib/mongo/operation/read/get_more.rb +8 -7
- data/lib/mongo/operation/read/indexes.rb +4 -3
- data/lib/mongo/operation/read/list_collections.rb +5 -4
- data/lib/mongo/operation/read/list_indexes.rb +7 -6
- data/lib/mongo/operation/read/query.rb +8 -7
- data/lib/mongo/operation/read_preferrable.rb +6 -2
- data/lib/mongo/operation/write/bulk/bulk_delete.rb +13 -12
- data/lib/mongo/operation/write/bulk/bulk_insert.rb +10 -9
- data/lib/mongo/operation/write/bulk/bulk_insert/result.rb +2 -2
- data/lib/mongo/operation/write/bulk/bulk_update.rb +12 -11
- data/lib/mongo/operation/write/create_index.rb +8 -7
- data/lib/mongo/operation/write/create_user.rb +4 -3
- data/lib/mongo/operation/write/delete.rb +13 -12
- data/lib/mongo/operation/write/drop_index.rb +6 -5
- data/lib/mongo/operation/write/insert.rb +8 -7
- data/lib/mongo/operation/write/insert/result.rb +1 -1
- data/lib/mongo/operation/write/remove_user.rb +4 -3
- data/lib/mongo/operation/write/update.rb +10 -9
- data/lib/mongo/operation/write/update_user.rb +4 -3
- data/lib/mongo/server.rb +8 -15
- data/lib/mongo/server/context.rb +2 -2
- data/lib/mongo/server/description.rb +65 -3
- data/lib/mongo/server/description/features.rb +2 -1
- data/lib/mongo/server/description/inspector.rb +5 -5
- data/lib/mongo/server/description/inspector/{server_added.rb → description_changed.rb} +3 -5
- data/lib/mongo/server/description/inspector/{server_removed.rb → standalone_discovered.rb} +12 -15
- data/lib/mongo/version.rb +1 -1
- data/spec/mongo/auth/cr_spec.rb +1 -1
- data/spec/mongo/auth/ldap_spec.rb +1 -1
- data/spec/mongo/auth/scram_spec.rb +1 -1
- data/spec/mongo/auth/x509_spec.rb +1 -1
- data/spec/mongo/client_spec.rb +4 -0
- data/spec/mongo/cluster/topology/replica_set_spec.rb +254 -4
- data/spec/mongo/cluster/topology/sharded_spec.rb +70 -19
- data/spec/mongo/cluster/topology/single_spec.rb +25 -4
- data/spec/mongo/cluster/topology/unknown_spec.rb +167 -0
- data/spec/mongo/cluster/topology_spec.rb +6 -6
- data/spec/mongo/cluster_spec.rb +179 -1
- data/spec/mongo/operation/read_preferrable_spec.rb +81 -28
- data/spec/mongo/operation/write/bulk/bulk_delete_spec.rb +1 -0
- data/spec/mongo/server/connection_pool_spec.rb +10 -10
- data/spec/mongo/server/connection_spec.rb +1 -1
- data/spec/mongo/server/description/features_spec.rb +23 -3
- data/spec/mongo/server/description/inspector/description_changed_spec.rb +78 -0
- data/spec/mongo/server/description_spec.rb +238 -0
- data/spec/mongo/server/monitor_spec.rb +1 -1
- data/spec/mongo/server_discovery_and_monitoring_spec.rb +20 -4
- data/spec/mongo/server_selection_spec.rb +2 -2
- data/spec/mongo/server_spec.rb +12 -8
- data/spec/support/authorization.rb +8 -8
- data/spec/support/sdam/rs/discover_passives.yml +36 -0
- data/spec/support/sdam/rs/new_primary_wrong_set_name.yml +2 -2
- data/spec/support/sdam/rs/primary_becomes_standalone.yml +1 -1
- data/spec/support/sdam/rs/primary_changes_set_name.yml +2 -2
- data/spec/support/sdam/rs/primary_disconnect.yml +1 -1
- data/spec/support/sdam/rs/primary_wrong_set_name.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/sharded/single_mongos.yml +33 -0
- data/spec/support/shared/operation.rb +12 -4
- data/spec/support/shared/server_selector.rb +1 -1
- metadata +12 -10
- metadata.gz.sig +0 -0
- data/spec/mongo/server/description/inspector/server_added_spec.rb +0 -92
- data/spec/mongo/server/description/inspector/server_removed_spec.rb +0 -95
@@ -13,19 +13,19 @@ describe Mongo::Cluster::Topology::Single do
|
|
13
13
|
describe '.servers' do
|
14
14
|
|
15
15
|
let(:mongos) do
|
16
|
-
Mongo::Server.new(address, Mongo::Event::Listeners.new, TEST_OPTIONS)
|
16
|
+
Mongo::Server.new(address, double('cluster'), Mongo::Event::Listeners.new, TEST_OPTIONS)
|
17
17
|
end
|
18
18
|
|
19
19
|
let(:standalone) do
|
20
|
-
Mongo::Server.new(address, Mongo::Event::Listeners.new, TEST_OPTIONS)
|
20
|
+
Mongo::Server.new(address, double('cluster'), Mongo::Event::Listeners.new, TEST_OPTIONS)
|
21
21
|
end
|
22
22
|
|
23
23
|
let(:standalone_two) do
|
24
|
-
Mongo::Server.new(address, Mongo::Event::Listeners.new, TEST_OPTIONS)
|
24
|
+
Mongo::Server.new(address, double('cluster'), Mongo::Event::Listeners.new, TEST_OPTIONS)
|
25
25
|
end
|
26
26
|
|
27
27
|
let(:replica_set) do
|
28
|
-
Mongo::Server.new(address, Mongo::Event::Listeners.new, TEST_OPTIONS)
|
28
|
+
Mongo::Server.new(address, double('cluster'), Mongo::Event::Listeners.new, TEST_OPTIONS)
|
29
29
|
end
|
30
30
|
|
31
31
|
let(:mongos_description) do
|
@@ -76,4 +76,25 @@ describe Mongo::Cluster::Topology::Single do
|
|
76
76
|
expect(topology).to be_single
|
77
77
|
end
|
78
78
|
end
|
79
|
+
|
80
|
+
describe '#add_hosts?' do
|
81
|
+
|
82
|
+
it 'returns false' do
|
83
|
+
expect(topology.add_hosts?(double('description'), [])).to eq(false)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe '#remove_hosts?' do
|
88
|
+
|
89
|
+
it 'returns false' do
|
90
|
+
expect(topology.remove_hosts?(double('description'))).to eq(false)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe '#remove_server?' do
|
95
|
+
|
96
|
+
it 'returns false' do
|
97
|
+
expect(topology.remove_server?(double('description'), double('server'))).to eq(false)
|
98
|
+
end
|
99
|
+
end
|
79
100
|
end
|
@@ -0,0 +1,167 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mongo::Cluster::Topology::Unknown do
|
4
|
+
|
5
|
+
let(:topology) do
|
6
|
+
described_class.new({})
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '.servers' do
|
10
|
+
|
11
|
+
let(:servers) do
|
12
|
+
topology.servers([ double('mongos'), double('standalone') ])
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'returns an empty array' do
|
16
|
+
expect(servers).to eq([ ])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '.replica_set?' do
|
21
|
+
|
22
|
+
it 'returns false' do
|
23
|
+
expect(topology).to_not be_replica_set
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '.sharded?' do
|
28
|
+
|
29
|
+
it 'returns false' do
|
30
|
+
expect(topology).not_to be_sharded
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '.single?' do
|
35
|
+
|
36
|
+
it 'returns false' do
|
37
|
+
expect(topology).not_to be_single
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '.unknown?' do
|
42
|
+
|
43
|
+
it 'returns true' do
|
44
|
+
expect(topology.unknown?).to be(true)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#add_hosts?' do
|
49
|
+
|
50
|
+
context 'when the description is from an unknown server' do
|
51
|
+
|
52
|
+
let(:description) do
|
53
|
+
double('description').tap do |d|
|
54
|
+
allow(d).to receive(:unknown?).and_return(true)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'returns false' do
|
59
|
+
expect(topology.add_hosts?(description, [])).to be(false)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'when the description is from a ghost server' do
|
64
|
+
|
65
|
+
let(:description) do
|
66
|
+
double('description').tap do |d|
|
67
|
+
allow(d).to receive(:unknown?).and_return(false)
|
68
|
+
allow(d).to receive(:ghost?).and_return(true)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'returns false' do
|
73
|
+
expect(topology.add_hosts?(description, [])).to be(false)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'when the description is not from an unknown or ghost' do
|
78
|
+
|
79
|
+
let(:description) do
|
80
|
+
double('description').tap do |d|
|
81
|
+
allow(d).to receive(:unknown?).and_return(false)
|
82
|
+
allow(d).to receive(:ghost?).and_return(false)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'returns true' do
|
87
|
+
expect(topology.add_hosts?(description, [])).to be(true)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe '#remove_hosts?' do
|
93
|
+
|
94
|
+
context 'when the description is from a standalone' do
|
95
|
+
|
96
|
+
let(:description) do
|
97
|
+
double('description').tap do |d|
|
98
|
+
allow(d).to receive(:standalone?).and_return(true)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'returns true' do
|
103
|
+
expect(topology.remove_hosts?(description)).to be(true)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'when the description is not from a standalone' do
|
108
|
+
|
109
|
+
let(:description) do
|
110
|
+
double('description').tap do |d|
|
111
|
+
allow(d).to receive(:standalone?).and_return(false)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'returns true' do
|
116
|
+
expect(topology.remove_hosts?(description)).to be(false)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe '#remove_server?' do
|
122
|
+
|
123
|
+
context 'when the description is from a standalone' do
|
124
|
+
|
125
|
+
let(:description) do
|
126
|
+
double('description').tap do |d|
|
127
|
+
allow(d).to receive(:standalone?).and_return(true)
|
128
|
+
allow(d).to receive(:is_server?).and_return(true)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
context 'when the description is from the server in question' do
|
133
|
+
|
134
|
+
it 'returns true' do
|
135
|
+
expect(topology.remove_server?(description, double('server'))).to be(true)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
context 'when the description is not from the server in question' do
|
140
|
+
|
141
|
+
let(:description) do
|
142
|
+
double('description').tap do |d|
|
143
|
+
allow(d).to receive(:standalone?).and_return(true)
|
144
|
+
allow(d).to receive(:is_server?).and_return(false)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'returns false' do
|
149
|
+
expect(topology.remove_server?(description, double('server'))).to be(false)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context 'when the description is not from a standalone' do
|
155
|
+
|
156
|
+
let(:description) do
|
157
|
+
double('description').tap do |d|
|
158
|
+
allow(d).to receive(:standalone?).and_return(false)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'returns false' do
|
163
|
+
expect(topology.remove_server?(description, double('server'))).to be(false)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
@@ -60,26 +60,26 @@ describe Mongo::Cluster::Topology do
|
|
60
60
|
described_class.initial([], {})
|
61
61
|
end
|
62
62
|
|
63
|
-
it 'returns
|
64
|
-
expect(topology).to be_a(Mongo::Cluster::Topology::
|
63
|
+
it 'returns an unknown topology' do
|
64
|
+
expect(topology).to be_a(Mongo::Cluster::Topology::Unknown)
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
68
|
context 'when provided a single mongos', if: single_mongos? do
|
69
69
|
|
70
70
|
let(:topology) do
|
71
|
-
described_class.initial(ADDRESSES,
|
71
|
+
described_class.initial(ADDRESSES, TEST_OPTIONS)
|
72
72
|
end
|
73
73
|
|
74
|
-
it 'returns a
|
75
|
-
expect(topology).to be_a(Mongo::Cluster::Topology::
|
74
|
+
it 'returns a sharded topology' do
|
75
|
+
expect(topology).to be_a(Mongo::Cluster::Topology::Sharded)
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
79
|
context 'when provided a single replica set member', if: single_rs_member? do
|
80
80
|
|
81
81
|
let(:topology) do
|
82
|
-
described_class.initial(ADDRESSES,
|
82
|
+
described_class.initial(ADDRESSES, TEST_OPTIONS)
|
83
83
|
end
|
84
84
|
|
85
85
|
it 'returns a single topology' do
|
data/spec/mongo/cluster_spec.rb
CHANGED
@@ -88,7 +88,7 @@ describe Mongo::Cluster do
|
|
88
88
|
context 'when the option is not provided' do
|
89
89
|
|
90
90
|
let(:cluster) do
|
91
|
-
described_class.new([ '127.0.0.1:27017' ], TEST_OPTIONS)
|
91
|
+
described_class.new([ '127.0.0.1:27017' ], TEST_OPTIONS.dup.delete_if { |k| k == :replica_set })
|
92
92
|
end
|
93
93
|
|
94
94
|
it 'returns nil' do
|
@@ -209,4 +209,182 @@ describe Mongo::Cluster do
|
|
209
209
|
end
|
210
210
|
end
|
211
211
|
end
|
212
|
+
|
213
|
+
describe '#remove' do
|
214
|
+
|
215
|
+
let(:address_a) do
|
216
|
+
Mongo::Address.new('127.0.0.1:27017')
|
217
|
+
end
|
218
|
+
|
219
|
+
let(:address_b) do
|
220
|
+
Mongo::Address.new('127.0.0.1:27018')
|
221
|
+
end
|
222
|
+
|
223
|
+
let(:server_a) do
|
224
|
+
Mongo::Server.new(address_a, cluster, Mongo::Event::Listeners.new)
|
225
|
+
end
|
226
|
+
|
227
|
+
let(:server_b) do
|
228
|
+
Mongo::Server.new(address_b, cluster, Mongo::Event::Listeners.new)
|
229
|
+
end
|
230
|
+
|
231
|
+
let(:servers) do
|
232
|
+
[ server_a, server_b ]
|
233
|
+
end
|
234
|
+
|
235
|
+
let(:addresses) do
|
236
|
+
[ address_a, address_b ]
|
237
|
+
end
|
238
|
+
|
239
|
+
before do
|
240
|
+
cluster.instance_variable_set(:@servers, servers)
|
241
|
+
cluster.instance_variable_set(:@addresses, addresses)
|
242
|
+
cluster.remove('127.0.0.1:27017')
|
243
|
+
end
|
244
|
+
|
245
|
+
it 'removes the host from the list of servers' do
|
246
|
+
expect(cluster.instance_variable_get(:@servers)).to eq([server_b])
|
247
|
+
end
|
248
|
+
|
249
|
+
it 'removes the host from the list of addresses' do
|
250
|
+
expect(cluster.instance_variable_get(:@addresses)).to eq([address_b])
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
describe '#add_hosts' do
|
255
|
+
|
256
|
+
let(:servers) do
|
257
|
+
[nil]
|
258
|
+
end
|
259
|
+
|
260
|
+
let(:hosts) do
|
261
|
+
["127.0.0.1:27018"]
|
262
|
+
end
|
263
|
+
|
264
|
+
let(:description) do
|
265
|
+
Mongo::Server::Description.new(double('address'), { 'hosts' => hosts })
|
266
|
+
end
|
267
|
+
|
268
|
+
before do
|
269
|
+
cluster.instance_variable_set(:@servers, servers)
|
270
|
+
cluster.instance_variable_set(:@topology, topology)
|
271
|
+
end
|
272
|
+
|
273
|
+
context 'when the topology allows servers to be added' do
|
274
|
+
|
275
|
+
let(:topology) do
|
276
|
+
double('topology').tap do |t|
|
277
|
+
allow(t).to receive(:add_hosts?).and_return(true)
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
it 'adds the servers' do
|
282
|
+
expect(cluster).to receive(:add).once
|
283
|
+
cluster.add_hosts(description)
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
context 'when the topology does not allow servers to be added' do
|
288
|
+
|
289
|
+
let(:topology) do
|
290
|
+
double('topology').tap do |t|
|
291
|
+
allow(t).to receive(:add_hosts?).and_return(false)
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
it 'does not add the servers' do
|
296
|
+
expect(cluster).not_to receive(:add)
|
297
|
+
cluster.add_hosts(description)
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
describe '#remove_hosts' do
|
303
|
+
|
304
|
+
let(:listeners) do
|
305
|
+
Mongo::Event::Listeners.new
|
306
|
+
end
|
307
|
+
|
308
|
+
let(:address) do
|
309
|
+
Mongo::Address.new('127.0.0.1:27017')
|
310
|
+
end
|
311
|
+
|
312
|
+
let(:server) do
|
313
|
+
Mongo::Server.new(address, cluster, listeners)
|
314
|
+
end
|
315
|
+
|
316
|
+
let(:servers) do
|
317
|
+
[ server ]
|
318
|
+
end
|
319
|
+
|
320
|
+
let(:hosts) do
|
321
|
+
["127.0.0.1:27018"]
|
322
|
+
end
|
323
|
+
|
324
|
+
let(:description) do
|
325
|
+
Mongo::Server::Description.new(double('address'), { 'hosts' => hosts })
|
326
|
+
end
|
327
|
+
|
328
|
+
context 'when the topology allows servers to be removed' do
|
329
|
+
|
330
|
+
context 'when the topology allows a specific server to be removed' do
|
331
|
+
|
332
|
+
let(:topology) do
|
333
|
+
double('topology').tap do |t|
|
334
|
+
allow(t).to receive(:remove_hosts?).and_return(true)
|
335
|
+
allow(t).to receive(:remove_server?).and_return(true)
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
before do
|
340
|
+
cluster.instance_variable_set(:@servers, servers)
|
341
|
+
cluster.instance_variable_set(:@topology, topology)
|
342
|
+
end
|
343
|
+
|
344
|
+
it 'removes the servers' do
|
345
|
+
expect(cluster).to receive(:remove).once
|
346
|
+
cluster.remove_hosts(description)
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
context 'when the topology does not allow a specific server to be removed' do
|
351
|
+
|
352
|
+
let(:topology) do
|
353
|
+
double('topology').tap do |t|
|
354
|
+
allow(t).to receive(:remove_hosts?).and_return(true)
|
355
|
+
allow(t).to receive(:remove_server?).and_return(false)
|
356
|
+
end
|
357
|
+
end
|
358
|
+
|
359
|
+
before do
|
360
|
+
cluster.instance_variable_set(:@servers, servers)
|
361
|
+
cluster.instance_variable_set(:@topology, topology)
|
362
|
+
end
|
363
|
+
|
364
|
+
it 'removes the servers' do
|
365
|
+
expect(cluster).not_to receive(:remove)
|
366
|
+
cluster.remove_hosts(description)
|
367
|
+
end
|
368
|
+
end
|
369
|
+
end
|
370
|
+
|
371
|
+
context 'when the topology does not allow servers to be removed' do
|
372
|
+
|
373
|
+
let(:topology) do
|
374
|
+
double('topology').tap do |t|
|
375
|
+
allow(t).to receive(:remove_hosts?).and_return(false)
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
379
|
+
before do
|
380
|
+
cluster.instance_variable_set(:@servers, servers)
|
381
|
+
cluster.instance_variable_set(:@topology, topology)
|
382
|
+
end
|
383
|
+
|
384
|
+
it 'does not remove the servers' do
|
385
|
+
expect(cluster).not_to receive(:remove)
|
386
|
+
cluster.remove_hosts(description)
|
387
|
+
end
|
388
|
+
end
|
389
|
+
end
|
212
390
|
end
|
@@ -10,14 +10,22 @@ describe Mongo::Operation::ReadPreferrable do
|
|
10
10
|
{}
|
11
11
|
end
|
12
12
|
|
13
|
-
let(:
|
14
|
-
|
13
|
+
let(:cluster_double) do
|
14
|
+
double('cluster')
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:single?) do
|
18
|
+
true
|
15
19
|
end
|
16
20
|
|
17
|
-
let(:
|
21
|
+
let(:mongos?) do
|
18
22
|
false
|
19
23
|
end
|
20
24
|
|
25
|
+
let(:read_pref) do
|
26
|
+
Mongo::ServerSelector.get
|
27
|
+
end
|
28
|
+
|
21
29
|
let(:read_preferrable) do
|
22
30
|
Class.new do
|
23
31
|
include Mongo::Operation::ReadPreferrable
|
@@ -30,8 +38,9 @@ describe Mongo::Operation::ReadPreferrable do
|
|
30
38
|
|
31
39
|
let(:context) do
|
32
40
|
double('context').tap do |c|
|
33
|
-
allow(c).to receive(:
|
34
|
-
allow(
|
41
|
+
allow(c).to receive(:cluster).and_return(cluster_double)
|
42
|
+
allow(cluster_double).to receive(:single?).and_return(single?)
|
43
|
+
allow(c).to receive(:mongos?).and_return(mongos?)
|
35
44
|
end
|
36
45
|
end
|
37
46
|
|
@@ -60,7 +69,7 @@ describe Mongo::Operation::ReadPreferrable do
|
|
60
69
|
selector.merge(:$readPreference => read_pref.to_mongos)
|
61
70
|
end
|
62
71
|
|
63
|
-
it 'returns
|
72
|
+
it 'returns an unaltered special selector' do
|
64
73
|
expect(read_preferrable.send(:update_selector, context)).to eq(expected)
|
65
74
|
end
|
66
75
|
end
|
@@ -72,14 +81,14 @@ describe Mongo::Operation::ReadPreferrable do
|
|
72
81
|
Mongo::ServerSelector.get(:mode => mode)
|
73
82
|
end
|
74
83
|
|
75
|
-
it 'returns a
|
84
|
+
it 'returns a selector' do
|
76
85
|
expect(read_preferrable.send(:update_selector, context)).to eq(selector)
|
77
86
|
end
|
78
87
|
end
|
79
88
|
|
80
89
|
context 'when the server is a mongos' do
|
81
90
|
|
82
|
-
let(:mongos) do
|
91
|
+
let(:mongos?) do
|
83
92
|
true
|
84
93
|
end
|
85
94
|
|
@@ -131,6 +140,10 @@ describe Mongo::Operation::ReadPreferrable do
|
|
131
140
|
|
132
141
|
context 'when the server is not a mongos' do
|
133
142
|
|
143
|
+
let(:mongos?) do
|
144
|
+
false
|
145
|
+
end
|
146
|
+
|
134
147
|
let(:mode) do
|
135
148
|
:secondary_preferred
|
136
149
|
end
|
@@ -138,31 +151,31 @@ describe Mongo::Operation::ReadPreferrable do
|
|
138
151
|
it_behaves_like 'not a selector updater'
|
139
152
|
end
|
140
153
|
|
141
|
-
context 'when the
|
154
|
+
context 'when the topology is Single' do
|
142
155
|
|
143
|
-
let(:
|
144
|
-
|
156
|
+
let(:single?) do
|
157
|
+
true
|
145
158
|
end
|
146
159
|
|
147
|
-
|
148
|
-
{ :flags => [ :slave_ok ] }
|
149
|
-
end
|
160
|
+
context 'when the server is a mongos' do
|
150
161
|
|
151
|
-
|
152
|
-
|
153
|
-
|
162
|
+
let(:mongos?) do
|
163
|
+
true
|
164
|
+
end
|
154
165
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
end
|
166
|
+
let(:expected) do
|
167
|
+
{ }
|
168
|
+
end
|
159
169
|
|
160
|
-
|
170
|
+
it 'does not set the slave_ok flag' do
|
171
|
+
expect(read_preferrable.send(:update_options, context)).to eq(expected)
|
172
|
+
end
|
173
|
+
end
|
161
174
|
|
162
|
-
context 'when the
|
175
|
+
context 'when the server is not a mongos' do
|
163
176
|
|
164
|
-
let(:
|
165
|
-
|
177
|
+
let(:mongos?) do
|
178
|
+
false
|
166
179
|
end
|
167
180
|
|
168
181
|
let(:expected) do
|
@@ -173,20 +186,60 @@ describe Mongo::Operation::ReadPreferrable do
|
|
173
186
|
expect(read_preferrable.send(:update_options, context)).to eq(expected)
|
174
187
|
end
|
175
188
|
end
|
189
|
+
end
|
176
190
|
|
177
|
-
|
191
|
+
context 'when the topology is not Single' do
|
192
|
+
|
193
|
+
let(:single?) do
|
194
|
+
false
|
195
|
+
end
|
196
|
+
|
197
|
+
context 'when there is no read preference set' do
|
178
198
|
|
179
199
|
let(:read_pref) do
|
180
|
-
Mongo::ServerSelector.get
|
200
|
+
Mongo::ServerSelector.get
|
181
201
|
end
|
182
202
|
|
183
203
|
let(:expected) do
|
184
204
|
{ }
|
185
205
|
end
|
186
206
|
|
187
|
-
it '
|
207
|
+
it 'does not set the slave_ok flag' do
|
188
208
|
expect(read_preferrable.send(:update_options, context)).to eq(expected)
|
189
209
|
end
|
190
210
|
end
|
211
|
+
|
212
|
+
context 'when there is a read preference' do
|
213
|
+
|
214
|
+
context 'when the read preference requires the slave_ok flag' do
|
215
|
+
|
216
|
+
let(:read_pref) do
|
217
|
+
Mongo::ServerSelector.get(:mode => :secondary)
|
218
|
+
end
|
219
|
+
|
220
|
+
let(:expected) do
|
221
|
+
{ :flags => [ :slave_ok ] }
|
222
|
+
end
|
223
|
+
|
224
|
+
it 'sets the slave_ok flag' do
|
225
|
+
expect(read_preferrable.send(:update_options, context)).to eq(expected)
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
context 'when the read preference does not require the slave_ok flag' do
|
230
|
+
|
231
|
+
let(:read_pref) do
|
232
|
+
Mongo::ServerSelector.get(:mode => :primary)
|
233
|
+
end
|
234
|
+
|
235
|
+
let(:expected) do
|
236
|
+
{ }
|
237
|
+
end
|
238
|
+
|
239
|
+
it 'does not set the slave_ok flag' do
|
240
|
+
expect(read_preferrable.send(:update_options, context)).to eq(expected)
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
191
244
|
end
|
192
245
|
end
|