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
@@ -13,6 +13,53 @@ describe Mongo::ServerSelector::Nearest do
|
|
13
13
|
it_behaves_like 'a server selector accepting tag sets'
|
14
14
|
it_behaves_like 'a server selector with sensitive data in its options'
|
15
15
|
|
16
|
+
describe '#initialize' do
|
17
|
+
|
18
|
+
context 'when max_staleness is provided' do
|
19
|
+
|
20
|
+
let(:options) do
|
21
|
+
{ max_staleness: 60 }
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'sets the max_staleness option' do
|
25
|
+
expect(selector.max_staleness).to eq(options[:max_staleness])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#==' do
|
31
|
+
|
32
|
+
context 'when max staleness is the same' do
|
33
|
+
|
34
|
+
let(:options) do
|
35
|
+
{ max_staleness: 60 }
|
36
|
+
end
|
37
|
+
|
38
|
+
let(:other) do
|
39
|
+
described_class.new(options)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'returns true' do
|
43
|
+
expect(selector).to eq(other)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'when max staleness is different' do
|
48
|
+
|
49
|
+
let(:other_options) do
|
50
|
+
{ max_staleness: 30 }
|
51
|
+
end
|
52
|
+
|
53
|
+
let(:other) do
|
54
|
+
described_class.new(other_options)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'returns false' do
|
58
|
+
expect(selector).not_to eq(other)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
16
63
|
describe '#to_mongos' do
|
17
64
|
|
18
65
|
context 'tag set not provided' do
|
@@ -38,6 +85,32 @@ describe Mongo::ServerSelector::Nearest do
|
|
38
85
|
)
|
39
86
|
end
|
40
87
|
end
|
88
|
+
|
89
|
+
context 'max staleness not provided' do
|
90
|
+
|
91
|
+
let(:expected) do
|
92
|
+
{ :mode => 'nearest' }
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'returns a read preference formatted for mongos' do
|
96
|
+
expect(selector.to_mongos).to eq(expected)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'max staleness provided' do
|
101
|
+
|
102
|
+
let(:max_staleness) do
|
103
|
+
60
|
104
|
+
end
|
105
|
+
|
106
|
+
let(:expected) do
|
107
|
+
{ :mode => 'nearest', maxStalenessMS: 60000 }
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'returns a read preference formatted for mongos' do
|
111
|
+
expect(selector.to_mongos).to eq(expected)
|
112
|
+
end
|
113
|
+
end
|
41
114
|
end
|
42
115
|
|
43
116
|
describe '#select' do
|
@@ -13,6 +13,53 @@ describe Mongo::ServerSelector::PrimaryPreferred do
|
|
13
13
|
it_behaves_like 'a server selector accepting tag sets'
|
14
14
|
it_behaves_like 'a server selector with sensitive data in its options'
|
15
15
|
|
16
|
+
describe '#initialize' do
|
17
|
+
|
18
|
+
context 'when max_staleness is provided' do
|
19
|
+
|
20
|
+
let(:options) do
|
21
|
+
{ max_staleness: 60 }
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'sets the max_staleness option' do
|
25
|
+
expect(selector.max_staleness).to eq(options[:max_staleness])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#==' do
|
31
|
+
|
32
|
+
context 'when max staleness is the same' do
|
33
|
+
|
34
|
+
let(:options) do
|
35
|
+
{ max_staleness: 60 }
|
36
|
+
end
|
37
|
+
|
38
|
+
let(:other) do
|
39
|
+
described_class.new(options)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'returns true' do
|
43
|
+
expect(selector).to eq(other)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'when max staleness is different' do
|
48
|
+
|
49
|
+
let(:other_options) do
|
50
|
+
{ max_staleness: 30 }
|
51
|
+
end
|
52
|
+
|
53
|
+
let(:other) do
|
54
|
+
described_class.new(other_options)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'returns false' do
|
58
|
+
expect(selector).not_to eq(other)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
16
63
|
describe '#to_mongos' do
|
17
64
|
|
18
65
|
context 'tag sets not provided' do
|
@@ -31,6 +78,32 @@ describe Mongo::ServerSelector::PrimaryPreferred do
|
|
31
78
|
)
|
32
79
|
end
|
33
80
|
end
|
81
|
+
|
82
|
+
context 'max staleness not provided' do
|
83
|
+
|
84
|
+
let(:expected) do
|
85
|
+
{ :mode => 'primaryPreferred' }
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'returns a read preference formatted for mongos' do
|
89
|
+
expect(selector.to_mongos).to eq(expected)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'max staleness provided' do
|
94
|
+
|
95
|
+
let(:max_staleness) do
|
96
|
+
60
|
97
|
+
end
|
98
|
+
|
99
|
+
let(:expected) do
|
100
|
+
{ :mode => 'primaryPreferred', maxStalenessMS: 60000 }
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'returns a read preference formatted for mongos' do
|
104
|
+
expect(selector.to_mongos).to eq(expected)
|
105
|
+
end
|
106
|
+
end
|
34
107
|
end
|
35
108
|
|
36
109
|
describe '#select' do
|
@@ -11,6 +11,22 @@ describe Mongo::ServerSelector::Primary do
|
|
11
11
|
end
|
12
12
|
it_behaves_like 'a server selector with sensitive data in its options'
|
13
13
|
|
14
|
+
describe '#initialize' do
|
15
|
+
|
16
|
+
context 'when max_staleness is provided' do
|
17
|
+
|
18
|
+
let(:options) do
|
19
|
+
{ max_staleness: 60 }
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'raises an exception' do
|
23
|
+
expect {
|
24
|
+
selector
|
25
|
+
}.to raise_exception(Mongo::Error::InvalidServerPreference)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
14
30
|
describe '#tag_sets' do
|
15
31
|
|
16
32
|
context 'tags not provided' do
|
@@ -39,6 +55,26 @@ describe Mongo::ServerSelector::Primary do
|
|
39
55
|
it 'returns nil' do
|
40
56
|
expect(selector.to_mongos).to be_nil
|
41
57
|
end
|
58
|
+
|
59
|
+
context 'max staleness not provided' do
|
60
|
+
|
61
|
+
it 'returns nil' do
|
62
|
+
expect(selector.to_mongos).to be_nil
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'max staleness provided' do
|
67
|
+
|
68
|
+
let(:max_staleness) do
|
69
|
+
60
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'raises an error' do
|
73
|
+
expect {
|
74
|
+
selector
|
75
|
+
}.to raise_exception(Mongo::Error::InvalidServerPreference)
|
76
|
+
end
|
77
|
+
end
|
42
78
|
end
|
43
79
|
|
44
80
|
describe '#select' do
|
@@ -13,6 +13,53 @@ describe Mongo::ServerSelector::SecondaryPreferred do
|
|
13
13
|
|
14
14
|
it_behaves_like 'a server selector accepting tag sets'
|
15
15
|
|
16
|
+
describe '#initialize' do
|
17
|
+
|
18
|
+
context 'when max_staleness is provided' do
|
19
|
+
|
20
|
+
let(:options) do
|
21
|
+
{ max_staleness: 60 }
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'sets the max_staleness option' do
|
25
|
+
expect(selector.max_staleness).to eq(options[:max_staleness])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#==' do
|
31
|
+
|
32
|
+
context 'when max staleness is the same' do
|
33
|
+
|
34
|
+
let(:options) do
|
35
|
+
{ max_staleness: 60 }
|
36
|
+
end
|
37
|
+
|
38
|
+
let(:other) do
|
39
|
+
described_class.new(options)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'returns true' do
|
43
|
+
expect(selector).to eq(other)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'when max staleness is different' do
|
48
|
+
|
49
|
+
let(:other_options) do
|
50
|
+
{ max_staleness: 30 }
|
51
|
+
end
|
52
|
+
|
53
|
+
let(:other) do
|
54
|
+
described_class.new(other_options)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'returns false' do
|
58
|
+
expect(selector).not_to eq(other)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
16
63
|
describe '#to_mongos' do
|
17
64
|
|
18
65
|
context 'tag sets provided' do
|
@@ -34,6 +81,32 @@ describe Mongo::ServerSelector::SecondaryPreferred do
|
|
34
81
|
expect(selector.to_mongos).to be_nil
|
35
82
|
end
|
36
83
|
end
|
84
|
+
|
85
|
+
context 'max staleness not provided' do
|
86
|
+
|
87
|
+
let(:expected) do
|
88
|
+
{ :mode => 'secondaryPreferred' }
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'returns nil' do
|
92
|
+
expect(selector.to_mongos).to be_nil
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'max staleness provided' do
|
97
|
+
|
98
|
+
let(:max_staleness) do
|
99
|
+
60
|
100
|
+
end
|
101
|
+
|
102
|
+
let(:expected) do
|
103
|
+
{ :mode => 'secondaryPreferred', maxStalenessMS: 60000 }
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'returns a read preference formatted for mongos' do
|
107
|
+
expect(selector.to_mongos).to eq(expected)
|
108
|
+
end
|
109
|
+
end
|
37
110
|
end
|
38
111
|
|
39
112
|
describe '#select' do
|
@@ -13,6 +13,53 @@ describe Mongo::ServerSelector::Secondary do
|
|
13
13
|
|
14
14
|
it_behaves_like 'a server selector accepting tag sets'
|
15
15
|
|
16
|
+
describe '#initialize' do
|
17
|
+
|
18
|
+
context 'when max_staleness is provided' do
|
19
|
+
|
20
|
+
let(:options) do
|
21
|
+
{ max_staleness: 60 }
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'sets the max_staleness option' do
|
25
|
+
expect(selector.max_staleness).to eq(options[:max_staleness])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#==' do
|
31
|
+
|
32
|
+
context 'when max staleness is the same' do
|
33
|
+
|
34
|
+
let(:options) do
|
35
|
+
{ max_staleness: 60 }
|
36
|
+
end
|
37
|
+
|
38
|
+
let(:other) do
|
39
|
+
described_class.new(options)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'returns true' do
|
43
|
+
expect(selector).to eq(other)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'when max staleness is different' do
|
48
|
+
|
49
|
+
let(:other_options) do
|
50
|
+
{ max_staleness: 30 }
|
51
|
+
end
|
52
|
+
|
53
|
+
let(:other) do
|
54
|
+
described_class.new(other_options)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'returns false' do
|
58
|
+
expect(selector).not_to eq(other)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
16
63
|
describe '#to_mongos' do
|
17
64
|
|
18
65
|
it 'returns read preference formatted for mongos' do
|
@@ -30,6 +77,32 @@ describe Mongo::ServerSelector::Secondary do
|
|
30
77
|
)
|
31
78
|
end
|
32
79
|
end
|
80
|
+
|
81
|
+
context 'max staleness not provided' do
|
82
|
+
|
83
|
+
let(:expected) do
|
84
|
+
{ :mode => 'secondary' }
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'returns a read preference formatted for mongos' do
|
88
|
+
expect(selector.to_mongos).to eq(expected)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'max staleness provided' do
|
93
|
+
|
94
|
+
let(:max_staleness) do
|
95
|
+
60
|
96
|
+
end
|
97
|
+
|
98
|
+
let(:expected) do
|
99
|
+
{ :mode => 'secondary', maxStalenessMS: 60000 }
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'returns a read preference formatted for mongos' do
|
103
|
+
expect(selector.to_mongos).to eq(expected)
|
104
|
+
end
|
105
|
+
end
|
33
106
|
end
|
34
107
|
|
35
108
|
describe '#select' do
|
@@ -291,4 +291,57 @@ describe Mongo::ServerSelector do
|
|
291
291
|
|
292
292
|
it_behaves_like 'a ServerSelector'
|
293
293
|
end
|
294
|
+
|
295
|
+
describe '#inspect' do
|
296
|
+
|
297
|
+
let(:options) do
|
298
|
+
{}
|
299
|
+
end
|
300
|
+
|
301
|
+
let(:read_pref) do
|
302
|
+
described_class.get({ mode: mode }.merge(options))
|
303
|
+
end
|
304
|
+
|
305
|
+
context 'when the mode is primary' do
|
306
|
+
|
307
|
+
let(:mode) do
|
308
|
+
:primary
|
309
|
+
end
|
310
|
+
|
311
|
+
it 'includes the mode in the inspect string' do
|
312
|
+
expect(read_pref.inspect).to match(/#{mode.to_s}/i)
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
context 'when there are tag sets' do
|
317
|
+
|
318
|
+
let(:mode) do
|
319
|
+
:secondary
|
320
|
+
end
|
321
|
+
|
322
|
+
let(:options) do
|
323
|
+
{ tag_sets: [{ 'data_center' => 'nyc' }] }
|
324
|
+
end
|
325
|
+
|
326
|
+
it 'includes the tag sets in the inspect string' do
|
327
|
+
expect(read_pref.inspect).to include(options[:tag_sets].inspect)
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
context 'when there is a max staleness set' do
|
332
|
+
|
333
|
+
let(:mode) do
|
334
|
+
:secondary
|
335
|
+
end
|
336
|
+
|
337
|
+
let(:options) do
|
338
|
+
{ max_staleness: 123 }
|
339
|
+
end
|
340
|
+
|
341
|
+
it 'includes the tag sets in the inspect string' do
|
342
|
+
expect(read_pref.inspect).to match(/max_staleness/i)
|
343
|
+
expect(read_pref.inspect).to match(/123/)
|
344
|
+
end
|
345
|
+
end
|
346
|
+
end
|
294
347
|
end
|