mongo 2.0.2 → 2.0.3
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/address.rb +70 -11
- data/lib/mongo/address/ipv4.rb +23 -22
- data/lib/mongo/address/ipv6.rb +23 -22
- data/lib/mongo/address/unix.rb +18 -18
- data/lib/mongo/auth.rb +0 -1
- data/lib/mongo/auth/cr.rb +21 -2
- data/lib/mongo/auth/cr/conversation.rb +7 -4
- data/lib/mongo/auth/ldap.rb +14 -1
- data/lib/mongo/auth/scram.rb +15 -1
- data/lib/mongo/auth/scram/conversation.rb +3 -3
- data/lib/mongo/auth/user.rb +1 -1
- data/lib/mongo/auth/x509.rb +15 -1
- data/lib/mongo/cluster.rb +22 -8
- data/lib/mongo/cluster/topology.rb +7 -6
- data/lib/mongo/cluster/topology/replica_set.rb +5 -5
- data/lib/mongo/cluster/topology/sharded.rb +5 -5
- data/lib/mongo/cluster/topology/{standalone.rb → single.rb} +26 -22
- data/lib/mongo/cluster/topology/unknown.rb +6 -5
- data/lib/mongo/collection.rb +6 -1
- data/lib/mongo/collection/view.rb +1 -0
- data/lib/mongo/collection/view/readable.rb +5 -0
- data/lib/mongo/error.rb +4 -0
- data/lib/mongo/error/invalid_document.rb +1 -1
- data/lib/mongo/error/invalid_server_preference.rb +36 -0
- data/lib/mongo/error/invalid_uri.rb +37 -0
- data/lib/mongo/error/invalid_uri_option.rb +38 -0
- data/lib/mongo/error/no_server_available.rb +37 -0
- data/lib/mongo/operation/read_preferrable.rb +20 -4
- data/lib/mongo/protocol/query.rb +14 -1
- data/lib/mongo/server.rb +12 -0
- data/lib/mongo/server/connectable.rb +5 -1
- data/lib/mongo/server/connection.rb +1 -1
- data/lib/mongo/server/context.rb +2 -1
- data/lib/mongo/server_selector.rb +0 -19
- data/lib/mongo/server_selector/selectable.rb +4 -22
- data/lib/mongo/uri.rb +9 -55
- data/lib/mongo/version.rb +1 -1
- data/spec/mongo/address/ipv4_spec.rb +27 -6
- data/spec/mongo/address/ipv6_spec.rb +27 -6
- data/spec/mongo/address/unix_spec.rb +15 -4
- data/spec/mongo/auth/cr_spec.rb +2 -2
- data/spec/mongo/auth/ldap_spec.rb +2 -2
- data/spec/mongo/auth/scram_spec.rb +2 -2
- data/spec/mongo/auth/x509_spec.rb +2 -2
- data/spec/mongo/client_spec.rb +8 -0
- data/spec/mongo/cluster/topology/replica_set_spec.rb +6 -6
- data/spec/mongo/cluster/topology/sharded_spec.rb +5 -5
- data/spec/mongo/cluster/topology/{standalone_spec.rb → single_spec.rb} +7 -7
- data/spec/mongo/cluster/topology_spec.rb +31 -5
- data/spec/mongo/cluster_spec.rb +103 -21
- data/spec/mongo/collection/view/readable_spec.rb +18 -7
- data/spec/mongo/collection/view_spec.rb +13 -0
- data/spec/mongo/collection_spec.rb +7 -0
- data/spec/mongo/database_spec.rb +2 -2
- data/spec/mongo/protocol/query_spec.rb +29 -0
- data/spec/mongo/server/connection_pool_spec.rb +4 -4
- data/spec/mongo/server/connection_spec.rb +46 -10
- data/spec/mongo/server/monitor_spec.rb +2 -2
- data/spec/mongo/server_discovery_and_monitoring_spec.rb +23 -0
- data/spec/mongo/server_selection_rtt_spec.rb +2 -1
- data/spec/mongo/server_selection_spec.rb +6 -15
- data/spec/mongo/server_selector/nearest_spec.rb +1 -1
- data/spec/mongo/server_selector_spec.rb +53 -2
- data/spec/mongo/server_spec.rb +9 -9
- data/spec/mongo/socket/ssl_spec.rb +1 -1
- data/spec/mongo/uri_spec.rb +2 -2
- data/spec/spec_helper.rb +34 -5
- data/spec/support/authorization.rb +32 -46
- data/spec/support/server_discovery_and_monitoring.rb +1 -1
- data/spec/support/server_selection.rb +1 -25
- data/spec/support/shared/operation.rb +3 -0
- data/spec/support/shared/server_selector.rb +1 -1
- metadata +10 -7
- metadata.gz.sig +0 -0
- data/lib/mongo/auth/executable.rb +0 -52
data/lib/mongo/version.rb
CHANGED
@@ -2,12 +2,33 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Mongo::Address::IPv4 do
|
4
4
|
|
5
|
+
let(:resolver) do
|
6
|
+
described_class.new(*described_class.parse(address))
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'self.parse' do
|
10
|
+
|
11
|
+
context 'when a port is provided' do
|
12
|
+
|
13
|
+
it 'returns the host and port' do
|
14
|
+
expect(described_class.parse('127.0.0.1:27017')).to eq(['127.0.0.1', 27017])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'when no port is provided' do
|
19
|
+
|
20
|
+
it 'returns the host and port' do
|
21
|
+
expect(described_class.parse('127.0.0.1')).to eq(['127.0.0.1', 27017])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
5
26
|
describe '#initialize' do
|
6
27
|
|
7
28
|
context 'when a port is provided' do
|
8
29
|
|
9
|
-
let(:
|
10
|
-
|
30
|
+
let(:address) do
|
31
|
+
'127.0.0.1:27017'
|
11
32
|
end
|
12
33
|
|
13
34
|
it 'sets the port' do
|
@@ -21,8 +42,8 @@ describe Mongo::Address::IPv4 do
|
|
21
42
|
|
22
43
|
context 'when no port is provided' do
|
23
44
|
|
24
|
-
let(:
|
25
|
-
|
45
|
+
let(:address) do
|
46
|
+
'127.0.0.1'
|
26
47
|
end
|
27
48
|
|
28
49
|
it 'sets the port to 27017' do
|
@@ -37,8 +58,8 @@ describe Mongo::Address::IPv4 do
|
|
37
58
|
|
38
59
|
describe '#socket' do
|
39
60
|
|
40
|
-
let(:
|
41
|
-
|
61
|
+
let(:address) do
|
62
|
+
'127.0.0.1'
|
42
63
|
end
|
43
64
|
|
44
65
|
context 'when ssl options are provided' do
|
@@ -2,12 +2,33 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Mongo::Address::IPv6 do
|
4
4
|
|
5
|
+
let(:resolver) do
|
6
|
+
described_class.new(*described_class.parse(address))
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'self.parse' do
|
10
|
+
|
11
|
+
context 'when a port is provided' do
|
12
|
+
|
13
|
+
it 'returns the host and port' do
|
14
|
+
expect(described_class.parse('[::1]:27017')).to eq(['::1', 27017])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'when no port is provided' do
|
19
|
+
|
20
|
+
it 'returns the host and port' do
|
21
|
+
expect(described_class.parse('[::1]')).to eq(['::1', 27017])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
5
26
|
describe '#initialize' do
|
6
27
|
|
7
28
|
context 'when a port is provided' do
|
8
29
|
|
9
|
-
let(:
|
10
|
-
|
30
|
+
let(:address) do
|
31
|
+
'[::1]:27017'
|
11
32
|
end
|
12
33
|
|
13
34
|
it 'sets the port' do
|
@@ -21,8 +42,8 @@ describe Mongo::Address::IPv6 do
|
|
21
42
|
|
22
43
|
context 'when no port is provided' do
|
23
44
|
|
24
|
-
let(:
|
25
|
-
|
45
|
+
let(:address) do
|
46
|
+
'[::1]'
|
26
47
|
end
|
27
48
|
|
28
49
|
it 'sets the port to 27017' do
|
@@ -37,8 +58,8 @@ describe Mongo::Address::IPv6 do
|
|
37
58
|
|
38
59
|
describe '#socket' do
|
39
60
|
|
40
|
-
let(:
|
41
|
-
|
61
|
+
let(:address) do
|
62
|
+
'[::1]'
|
42
63
|
end
|
43
64
|
|
44
65
|
context 'when ssl options are provided' do
|
@@ -2,10 +2,21 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Mongo::Address::Unix do
|
4
4
|
|
5
|
+
let(:resolver) do
|
6
|
+
described_class.new(*described_class.parse(address))
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'self.parse' do
|
10
|
+
|
11
|
+
it 'returns the host and no port' do
|
12
|
+
expect(described_class.parse('/path/to/socket.sock')).to eq(['/path/to/socket.sock'])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
5
16
|
describe '#initialize' do
|
6
17
|
|
7
|
-
let(:
|
8
|
-
|
18
|
+
let(:address) do
|
19
|
+
'/path/to/socket.sock'
|
9
20
|
end
|
10
21
|
|
11
22
|
it 'sets the host' do
|
@@ -15,8 +26,8 @@ describe Mongo::Address::Unix do
|
|
15
26
|
|
16
27
|
describe '#socket' do
|
17
28
|
|
18
|
-
let(:
|
19
|
-
|
29
|
+
let(:address) do
|
30
|
+
'/path/to/socket.sock'
|
20
31
|
end
|
21
32
|
|
22
33
|
let(:socket) do
|
data/spec/mongo/auth/cr_spec.rb
CHANGED
@@ -7,11 +7,11 @@ describe Mongo::Auth::CR do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
let(:server) do
|
10
|
-
Mongo::Server.new(address, Mongo::Event::Listeners.new)
|
10
|
+
Mongo::Server.new(address, Mongo::Event::Listeners.new, TEST_OPTIONS)
|
11
11
|
end
|
12
12
|
|
13
13
|
let(:connection) do
|
14
|
-
Mongo::Server::Connection.new(server)
|
14
|
+
Mongo::Server::Connection.new(server, TEST_OPTIONS)
|
15
15
|
end
|
16
16
|
|
17
17
|
describe '#login' do
|
@@ -7,11 +7,11 @@ describe Mongo::Auth::LDAP do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
let(:server) do
|
10
|
-
Mongo::Server.new(address, Mongo::Event::Listeners.new)
|
10
|
+
Mongo::Server.new(address, Mongo::Event::Listeners.new, TEST_OPTIONS)
|
11
11
|
end
|
12
12
|
|
13
13
|
let(:connection) do
|
14
|
-
Mongo::Server::Connection.new(server)
|
14
|
+
Mongo::Server::Connection.new(server, TEST_OPTIONS)
|
15
15
|
end
|
16
16
|
|
17
17
|
let(:user) do
|
@@ -7,11 +7,11 @@ describe Mongo::Auth::SCRAM do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
let(:server) do
|
10
|
-
Mongo::Server.new(address, Mongo::Event::Listeners.new)
|
10
|
+
Mongo::Server.new(address, Mongo::Event::Listeners.new, TEST_OPTIONS)
|
11
11
|
end
|
12
12
|
|
13
13
|
let(:connection) do
|
14
|
-
Mongo::Server::Connection.new(server)
|
14
|
+
Mongo::Server::Connection.new(server, TEST_OPTIONS)
|
15
15
|
end
|
16
16
|
|
17
17
|
describe '#login' do
|
@@ -7,11 +7,11 @@ describe Mongo::Auth::X509 do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
let(:server) do
|
10
|
-
Mongo::Server.new(address, Mongo::Event::Listeners.new)
|
10
|
+
Mongo::Server.new(address, Mongo::Event::Listeners.new, TEST_OPTIONS)
|
11
11
|
end
|
12
12
|
|
13
13
|
let(:connection) do
|
14
|
-
Mongo::Server::Connection.new(server)
|
14
|
+
Mongo::Server::Connection.new(server, TEST_OPTIONS)
|
15
15
|
end
|
16
16
|
|
17
17
|
let(:user) do
|
data/spec/mongo/client_spec.rb
CHANGED
@@ -9,19 +9,19 @@ describe Mongo::Cluster::Topology::ReplicaSet do
|
|
9
9
|
describe '#servers' do
|
10
10
|
|
11
11
|
let(:mongos) do
|
12
|
-
Mongo::Server.new(address, Mongo::Event::Listeners.new)
|
12
|
+
Mongo::Server.new(address, Mongo::Event::Listeners.new, TEST_OPTIONS)
|
13
13
|
end
|
14
14
|
|
15
15
|
let(:standalone) do
|
16
|
-
Mongo::Server.new(address, Mongo::Event::Listeners.new)
|
16
|
+
Mongo::Server.new(address, Mongo::Event::Listeners.new, TEST_OPTIONS)
|
17
17
|
end
|
18
18
|
|
19
19
|
let(:replica_set) do
|
20
|
-
Mongo::Server.new(address, Mongo::Event::Listeners.new)
|
20
|
+
Mongo::Server.new(address, Mongo::Event::Listeners.new, TEST_OPTIONS)
|
21
21
|
end
|
22
22
|
|
23
23
|
let(:replica_set_two) do
|
24
|
-
Mongo::Server.new(address, Mongo::Event::Listeners.new)
|
24
|
+
Mongo::Server.new(address, Mongo::Event::Listeners.new, TEST_OPTIONS)
|
25
25
|
end
|
26
26
|
|
27
27
|
let(:mongos_description) do
|
@@ -92,10 +92,10 @@ describe Mongo::Cluster::Topology::ReplicaSet do
|
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
|
-
describe '.
|
95
|
+
describe '.single?' do
|
96
96
|
|
97
97
|
it 'returns false' do
|
98
|
-
expect(described_class.new({})).to_not
|
98
|
+
expect(described_class.new({})).to_not be_single
|
99
99
|
end
|
100
100
|
end
|
101
101
|
end
|
@@ -13,15 +13,15 @@ describe Mongo::Cluster::Topology::Sharded do
|
|
13
13
|
describe '.servers' do
|
14
14
|
|
15
15
|
let(:mongos) do
|
16
|
-
Mongo::Server.new(address, Mongo::Event::Listeners.new)
|
16
|
+
Mongo::Server.new(address, 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)
|
20
|
+
Mongo::Server.new(address, Mongo::Event::Listeners.new, TEST_OPTIONS)
|
21
21
|
end
|
22
22
|
|
23
23
|
let(:replica_set) do
|
24
|
-
Mongo::Server.new(address, Mongo::Event::Listeners.new)
|
24
|
+
Mongo::Server.new(address, Mongo::Event::Listeners.new, TEST_OPTIONS)
|
25
25
|
end
|
26
26
|
|
27
27
|
let(:mongos_description) do
|
@@ -65,10 +65,10 @@ describe Mongo::Cluster::Topology::Sharded do
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
-
describe '.
|
68
|
+
describe '.single?' do
|
69
69
|
|
70
70
|
it 'returns false' do
|
71
|
-
expect(topology).to_not
|
71
|
+
expect(topology).to_not be_single
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Mongo::Cluster::Topology::
|
3
|
+
describe Mongo::Cluster::Topology::Single do
|
4
4
|
|
5
5
|
let(:address) do
|
6
6
|
Mongo::Address.new('127.0.0.1:27017')
|
@@ -13,19 +13,19 @@ describe Mongo::Cluster::Topology::Standalone do
|
|
13
13
|
describe '.servers' do
|
14
14
|
|
15
15
|
let(:mongos) do
|
16
|
-
Mongo::Server.new(address, Mongo::Event::Listeners.new)
|
16
|
+
Mongo::Server.new(address, 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)
|
20
|
+
Mongo::Server.new(address, 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)
|
24
|
+
Mongo::Server.new(address, 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)
|
28
|
+
Mongo::Server.new(address, Mongo::Event::Listeners.new, TEST_OPTIONS)
|
29
29
|
end
|
30
30
|
|
31
31
|
let(:mongos_description) do
|
@@ -70,10 +70,10 @@ describe Mongo::Cluster::Topology::Standalone do
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
describe '.
|
73
|
+
describe '.single?' do
|
74
74
|
|
75
75
|
it 'returns true' do
|
76
|
-
expect(topology).to
|
76
|
+
expect(topology).to be_single
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
@@ -15,14 +15,18 @@ describe Mongo::Cluster::Topology do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
context 'when provided a
|
18
|
+
context 'when provided a single option' do
|
19
19
|
|
20
20
|
let(:topology) do
|
21
21
|
described_class.initial([ 'a' ], connect: :direct)
|
22
22
|
end
|
23
23
|
|
24
|
-
it 'returns a
|
25
|
-
expect(topology).to be_a(Mongo::Cluster::Topology::
|
24
|
+
it 'returns a single topology' do
|
25
|
+
expect(topology).to be_a(Mongo::Cluster::Topology::Single)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'sets the seed on the topology' do
|
29
|
+
expect(topology.seed).to eq('a')
|
26
30
|
end
|
27
31
|
end
|
28
32
|
|
@@ -56,8 +60,30 @@ describe Mongo::Cluster::Topology do
|
|
56
60
|
described_class.initial([], {})
|
57
61
|
end
|
58
62
|
|
59
|
-
it 'returns a
|
60
|
-
expect(topology).to be_a(Mongo::Cluster::Topology::
|
63
|
+
it 'returns a single topology' do
|
64
|
+
expect(topology).to be_a(Mongo::Cluster::Topology::Single)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'when provided a single mongos', if: single_mongos? do
|
69
|
+
|
70
|
+
let(:topology) do
|
71
|
+
described_class.initial(ADDRESSES, {})
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'returns a single topology' do
|
75
|
+
expect(topology).to be_a(Mongo::Cluster::Topology::Single)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'when provided a single replica set member', if: single_rs_member? do
|
80
|
+
|
81
|
+
let(:topology) do
|
82
|
+
described_class.initial(ADDRESSES, {})
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'returns a single topology' do
|
86
|
+
expect(topology).to be_a(Mongo::Cluster::Topology::Single)
|
61
87
|
end
|
62
88
|
end
|
63
89
|
end
|
data/spec/mongo/cluster_spec.rb
CHANGED
@@ -2,11 +2,11 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Mongo::Cluster do
|
4
4
|
|
5
|
-
|
5
|
+
let(:cluster) do
|
6
|
+
described_class.new(ADDRESSES, TEST_OPTIONS)
|
7
|
+
end
|
6
8
|
|
7
|
-
|
8
|
-
described_class.new([ '127.0.0.1:27017' ])
|
9
|
-
end
|
9
|
+
describe '#==' do
|
10
10
|
|
11
11
|
context 'when the other is a cluster' do
|
12
12
|
|
@@ -15,7 +15,7 @@ describe Mongo::Cluster do
|
|
15
15
|
context 'when the options are the same' do
|
16
16
|
|
17
17
|
let(:other) do
|
18
|
-
described_class.new(
|
18
|
+
described_class.new(ADDRESSES, TEST_OPTIONS)
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'returns true' do
|
@@ -26,7 +26,7 @@ describe Mongo::Cluster do
|
|
26
26
|
context 'when the options are not the same' do
|
27
27
|
|
28
28
|
let(:other) do
|
29
|
-
described_class.new([ '127.0.0.1:27017' ], :replica_set => 'test')
|
29
|
+
described_class.new([ '127.0.0.1:27017' ], TEST_OPTIONS.merge(:replica_set => 'test'))
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'returns false' do
|
@@ -38,7 +38,7 @@ describe Mongo::Cluster do
|
|
38
38
|
context 'when the addresses are not the same' do
|
39
39
|
|
40
40
|
let(:other) do
|
41
|
-
described_class.new([ '127.0.0.1:27018' ])
|
41
|
+
described_class.new([ '127.0.0.1:27018' ], TEST_OPTIONS)
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'returns false' do
|
@@ -61,10 +61,6 @@ describe Mongo::Cluster do
|
|
61
61
|
Mongo::ServerSelector.get
|
62
62
|
end
|
63
63
|
|
64
|
-
let(:cluster) do
|
65
|
-
described_class.new([ '127.0.0.1:27017' ])
|
66
|
-
end
|
67
|
-
|
68
64
|
it 'displays the cluster seeds and topology' do
|
69
65
|
expect(cluster.inspect).to include('topology')
|
70
66
|
expect(cluster.inspect).to include('servers')
|
@@ -77,14 +73,10 @@ describe Mongo::Cluster do
|
|
77
73
|
Mongo::ServerSelector.get
|
78
74
|
end
|
79
75
|
|
80
|
-
let(:cluster) do
|
81
|
-
described_class.new([ '127.0.0.1:27017' ], :replica_set => 'testing')
|
82
|
-
end
|
83
|
-
|
84
76
|
context 'when the option is provided' do
|
85
77
|
|
86
78
|
let(:cluster) do
|
87
|
-
described_class.new([ '127.0.0.1:27017' ], :replica_set => 'testing')
|
79
|
+
described_class.new([ '127.0.0.1:27017' ], TEST_OPTIONS.merge(:replica_set => 'testing'))
|
88
80
|
end
|
89
81
|
|
90
82
|
it 'returns the name' do
|
@@ -95,7 +87,7 @@ describe Mongo::Cluster do
|
|
95
87
|
context 'when the option is not provided' do
|
96
88
|
|
97
89
|
let(:cluster) do
|
98
|
-
described_class.new([ '127.0.0.1:27017' ])
|
90
|
+
described_class.new([ '127.0.0.1:27017' ], TEST_OPTIONS)
|
99
91
|
end
|
100
92
|
|
101
93
|
it 'returns nil' do
|
@@ -110,10 +102,6 @@ describe Mongo::Cluster do
|
|
110
102
|
Mongo::ServerSelector.get
|
111
103
|
end
|
112
104
|
|
113
|
-
let(:cluster) do
|
114
|
-
described_class.new([ '127.0.0.1:27017' ])
|
115
|
-
end
|
116
|
-
|
117
105
|
let(:known_servers) do
|
118
106
|
cluster.instance_variable_get(:@servers)
|
119
107
|
end
|
@@ -126,4 +114,98 @@ describe Mongo::Cluster do
|
|
126
114
|
expect(cluster.scan!).to be true
|
127
115
|
end
|
128
116
|
end
|
117
|
+
|
118
|
+
describe '#servers' do
|
119
|
+
|
120
|
+
context 'when topology is single', if: single_seed? do
|
121
|
+
|
122
|
+
context 'when the server is a mongos', if: single_mongos? do
|
123
|
+
|
124
|
+
it 'returns the mongos' do
|
125
|
+
expect(cluster.servers.size).to eq(1)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
context 'when the server is a replica set member', if: single_rs_member? do
|
130
|
+
|
131
|
+
it 'returns the replica set member' do
|
132
|
+
expect(cluster.servers.size).to eq(1)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
context 'when the cluster has no servers' do
|
138
|
+
|
139
|
+
let(:servers) do
|
140
|
+
[nil]
|
141
|
+
end
|
142
|
+
|
143
|
+
before do
|
144
|
+
cluster.instance_variable_set(:@servers, servers)
|
145
|
+
cluster.instance_variable_set(:@topology, topology)
|
146
|
+
end
|
147
|
+
|
148
|
+
context 'when topology is Single' do
|
149
|
+
|
150
|
+
let(:topology) do
|
151
|
+
Mongo::Cluster::Topology::Single.new({})
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'returns an empty array' do
|
155
|
+
expect(cluster.servers).to eq([])
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
context 'when topology is ReplicaSet' do
|
160
|
+
|
161
|
+
let(:topology) do
|
162
|
+
Mongo::Cluster::Topology::ReplicaSet.new({})
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'returns an empty array' do
|
166
|
+
expect(cluster.servers).to eq([])
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
context 'when topology is Sharded' do
|
171
|
+
|
172
|
+
let(:topology) do
|
173
|
+
Mongo::Cluster::Topology::Sharded.new({})
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'returns an empty array' do
|
177
|
+
expect(cluster.servers).to eq([])
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
context 'when topology is Unknown' do
|
182
|
+
|
183
|
+
let(:topology) do
|
184
|
+
Mongo::Cluster::Topology::Unknown.new({})
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'returns an empty array' do
|
188
|
+
expect(cluster.servers).to eq([])
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
describe '#add' do
|
195
|
+
|
196
|
+
context 'when topology is Single' do
|
197
|
+
|
198
|
+
let(:topology) do
|
199
|
+
Mongo::Cluster::Topology::Single.new({})
|
200
|
+
end
|
201
|
+
|
202
|
+
before do
|
203
|
+
cluster.add('a')
|
204
|
+
end
|
205
|
+
|
206
|
+
it 'does not add discovered servers to the cluster' do
|
207
|
+
expect(cluster.servers[0].address.seed).to_not eq('a')
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
129
211
|
end
|