File tree Expand file tree Collapse file tree 4 files changed +70
-0
lines changed Expand file tree Collapse file tree 4 files changed +70
-0
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ module Topology
40
40
# @example Get the initial cluster topology.
41
41
# Topology.initial(topology: :replica_set)
42
42
#
43
+ # @param [ Array<String> ] seeds The addresses of the configured servers.
43
44
# @param [ Hash ] options The cluster options.
44
45
#
45
46
# @return [ ReplicaSet, Sharded, Single ] The topology.
Original file line number Diff line number Diff line change 60
60
expect ( topology ) . to be_a ( Mongo ::Cluster ::Topology ::Single )
61
61
end
62
62
end
63
+
64
+ context 'when provided a single mongos' , if : single_mongos? do
65
+
66
+ let ( :topology ) do
67
+ described_class . initial ( ADDRESSES , { } )
68
+ end
69
+
70
+ it 'returns a single topology' do
71
+ expect ( topology ) . to be_a ( Mongo ::Cluster ::Topology ::Single )
72
+ end
73
+ end
74
+
75
+ context 'when provided a single replica set member' , if : single_rs_member? do
76
+
77
+ let ( :topology ) do
78
+ described_class . initial ( ADDRESSES , { } )
79
+ end
80
+
81
+ it 'returns a single topology' do
82
+ expect ( topology ) . to be_a ( Mongo ::Cluster ::Topology ::Single )
83
+ end
84
+ end
63
85
end
64
86
end
65
87
end
Original file line number Diff line number Diff line change 126
126
expect ( cluster . scan! ) . to be true
127
127
end
128
128
end
129
+
130
+ describe '#servers' do
131
+
132
+ context 'when topology is single' , if : single_seed? do
133
+
134
+ let ( :cluster ) do
135
+ described_class . new ( ADDRESSES )
136
+ end
137
+
138
+ context 'when the server is a mongos' , if : single_mongos? do
139
+
140
+ it 'returns the mongos' do
141
+ expect ( cluster . servers . size ) . to eq ( 1 )
142
+ end
143
+ end
144
+
145
+ context 'when the server is a replica set member' , if : single_rs_member? do
146
+
147
+ it 'returns the replica set member' do
148
+ expect ( cluster . servers . size ) . to eq ( 1 )
149
+ end
150
+ end
151
+ end
152
+ end
129
153
end
Original file line number Diff line number Diff line change @@ -99,6 +99,29 @@ def sharded?
99
99
$sharded ||= $mongo_client. cluster . sharded?
100
100
end
101
101
102
+ # Determine whether the single address provided is a replica set member.
103
+ #
104
+ # @since 2.0.0
105
+ def single_rs_member?
106
+ $mongo_client ||= initialize_scanned_client!
107
+ single_seed? && $mongo_client. cluster . servers . first . replica_set_name
108
+ end
109
+
110
+ # Determine whether the single address provided is a mongos.
111
+ #
112
+ # @since 2.0.0
113
+ def single_mongos?
114
+ $mongo_client ||= initialize_scanned_client!
115
+ single_seed? && $mongo_client. cluster . servers . first . mongos?
116
+ end
117
+
118
+ # Determine whether a single address was provided.
119
+ #
120
+ # @since 2.0.0
121
+ def single_seed?
122
+ ADDRESSES . size == 1
123
+ end
124
+
102
125
# For instances where behaviour is different on different versions, we need to
103
126
# determine in the specs if we are 2.6 or higher.
104
127
#
You can’t perform that action at this time.
0 commit comments