mongo 2.2.0.rc0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dcc9c2c71373a6cf0c7ecc20e34dc665a3609113
4
- data.tar.gz: b0586f936825521d4d1b720aaab115094c754b52
3
+ metadata.gz: 0b03a2e7ce5246f9d38690f731f53d29a5469d30
4
+ data.tar.gz: aaca95e6f570d466155c87d4c549a4f3c5bc0341
5
5
  SHA512:
6
- metadata.gz: 4bd095acd88b753375c7b32441645a7f79bd6e79fa66c4b49d1d16f98a17a3ebb88628132d863dee8a49132b0ad06cd540fc329b37d3250e1793ecf0ce0fbb55
7
- data.tar.gz: 8081fad549d197c92f9b573694b32a1813030fcde279e98ab117dd9d4b601b5bb2139a720c218b03fadd3315a8a9f391066f7ad96c99f194ce1cf186b6a56673
6
+ metadata.gz: f6fa180a5c94bcb5d7a809d170c8ec12ec28d0d6035575ef0cc677b9f4c68ec81c26411948f071945b2b2d829b192e0312f29416d2c3a589830c5ee40f90b133
7
+ data.tar.gz: fce85899375de257592434225cd1db4e3d3971e8b85b6ec111ef30c967e0fa0e817569b843dc0f3c342d7e58749c259a8111cc2b9d741ef321dc335a1ad08bab
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -63,6 +63,20 @@ module Mongo
63
63
  host == other.host && port == other.port
64
64
  end
65
65
 
66
+ # Check equality for hashing.
67
+ #
68
+ # @example Check hashing equality.
69
+ # address.eql?(other)
70
+ #
71
+ # @param [ Object ] other The other object.
72
+ #
73
+ # @return [ true, false ] If the objects are equal.
74
+ #
75
+ # @since 2.2.0
76
+ def eql?(other)
77
+ self == other
78
+ end
79
+
66
80
  # Calculate the hash value for the address.
67
81
  #
68
82
  # @example Calculate the hash value.
@@ -106,12 +106,34 @@ module Mongo
106
106
  @options = options.freeze
107
107
  @topology = Topology.initial(seeds, options)
108
108
  @update_lock = Mutex.new
109
+ @pool_lock = Mutex.new
109
110
 
110
111
  subscribe_to(Event::STANDALONE_DISCOVERED, Event::StandaloneDiscovered.new(self))
111
112
  subscribe_to(Event::DESCRIPTION_CHANGED, Event::DescriptionChanged.new(self))
112
113
  subscribe_to(Event::PRIMARY_ELECTED, Event::PrimaryElected.new(self))
113
114
 
114
115
  seeds.each{ |seed| add(seed) }
116
+ ObjectSpace.define_finalizer(self, self.class.finalize(pools))
117
+ end
118
+
119
+ # Finalize the cluster for garbage collection. Disconnects all the scoped
120
+ # connection pools.
121
+ #
122
+ # @example Finalize the cluster.
123
+ # Cluster.finalize(pools)
124
+ #
125
+ # @param [ Hash<Address, Server::ConnectionPool> ] pools The connection
126
+ # pools.
127
+ #
128
+ # @return [ Proc ] The Finalizer.
129
+ #
130
+ # @since 2.2.0
131
+ def self.finalize(pools)
132
+ proc do
133
+ pools.values.each do |pool|
134
+ pool.disconnect!
135
+ end
136
+ end
115
137
  end
116
138
 
117
139
  # Get the nicer formatted string for use in inspection.
@@ -168,6 +190,22 @@ module Mongo
168
190
  options[:max_read_retries] || MAX_READ_RETRIES
169
191
  end
170
192
 
193
+ # Get the scoped connection pool for the server.
194
+ #
195
+ # @example Get the connection pool.
196
+ # cluster.pool(server)
197
+ #
198
+ # @param [ Server ] server The server.
199
+ #
200
+ # @return [ Server::ConnectionPool ] The connection pool.
201
+ #
202
+ # @since 2.2.0
203
+ def pool(server)
204
+ @pool_lock.synchronize do
205
+ pools[server.address] ||= Server::ConnectionPool.get(server)
206
+ end
207
+ end
208
+
171
209
  # Get the interval, in seconds, in which a mongos read operation is
172
210
  # retried.
173
211
  #
@@ -339,6 +377,10 @@ module Mongo
339
377
  !@topology.single? || direct_connection?(address)
340
378
  end
341
379
 
380
+ def pools
381
+ @pools ||= {}
382
+ end
383
+
342
384
  def servers_list
343
385
  @update_lock.synchronize do
344
386
  @servers.reduce([]) do |servers, server|
@@ -79,7 +79,7 @@ module Mongo
79
79
  # @example Convert the DBRef to raw BSON.
80
80
  # dbref.to_bson
81
81
  #
82
- # @param [ String ] encoded The encoded BSON to append to.
82
+ # @param [ String ] buffer The encoded BSON buffer to append to.
83
83
  #
84
84
  # @return [ String ] The raw BSON.
85
85
  #
@@ -92,7 +92,7 @@ module Mongo
92
92
 
93
93
  # Deserialize the hash from BSON, converting to a DBRef if appropriate.
94
94
  #
95
- # @param [ IO ] bson The bson representing a hash.
95
+ # @param [ String ] buffer The bson representing a hash.
96
96
  #
97
97
  # @return [ Hash, DBRef ] The decoded hash or DBRef.
98
98
  #
@@ -128,7 +128,7 @@ module Mongo
128
128
  # @example Convert the chunk to BSON.
129
129
  # chunk.to_bson
130
130
  #
131
- # @param [ String ] encoded The encoded data to append to.
131
+ # @param [ String ] buffer The encoded data buffer to append to.
132
132
  #
133
133
  # @return [ String ] The raw BSON data.
134
134
  #
@@ -24,7 +24,7 @@ module Mongo
24
24
 
25
25
  # Initializes a BitVector with a layout
26
26
  #
27
- # @param layout [Array<Symbol>] the array of fields in the bit vector
27
+ # @param layout [ Array<Symbol> ] the array of fields in the bit vector
28
28
  def initialize(layout)
29
29
  @masks = {}
30
30
  layout.each_with_index do |field, index|
@@ -34,9 +34,10 @@ module Mongo
34
34
 
35
35
  # Serializes vector by encoding each symbol according to its mask
36
36
  #
37
- # @param buffer [IO] Buffer to receive the serialized vector
38
- # @param value [Array<Symbol>] Array of flags to encode
39
- # @return [IO] Buffer that received the serialized vector
37
+ # @param buffer [ String ] Buffer to receive the serialized vector
38
+ # @param value [ Array<Symbol> ] Array of flags to encode
39
+ #
40
+ # @return [ String ] Buffer that received the serialized vector
40
41
  def serialize(buffer, value)
41
42
  bits = 0
42
43
  value.each { |flag| bits |= @masks[flag] }
@@ -45,8 +46,9 @@ module Mongo
45
46
 
46
47
  # Deserializes vector by decoding the symbol according to its mask
47
48
  #
48
- # @param io [IO] Stream containing the vector to be deserialized
49
- # @return [Array<Symbol>] Flags contained in the vector
49
+ # @param [ String ] buffer Buffer containing the vector to be deserialized.
50
+ #
51
+ # @return [ Array<Symbol> ] Flags contained in the vector
50
52
  def deserialize(buffer)
51
53
  vector = buffer.get_int32
52
54
  flags = []
@@ -46,17 +46,19 @@ module Mongo
46
46
 
47
47
  # Serializes the header value into the buffer
48
48
  #
49
- # @param buffer [String] Buffer to receive the serialized value.
50
- # @param value [String] Header value to be serialized.
51
- # @return [String] Buffer with serialized value.
49
+ # @param buffer [ String ] Buffer to receive the serialized value.
50
+ # @param value [ String ] Header value to be serialized.
51
+ #
52
+ # @return [ String ] Buffer with serialized value.
52
53
  def self.serialize(buffer, value)
53
54
  buffer.put_bytes(value.pack(HEADER_PACK))
54
55
  end
55
56
 
56
57
  # Deserializes the header value from the IO stream
57
58
  #
58
- # @param io [IO] IO stream containing the message header.
59
- # @return [Array<Fixnum>] Array consisting of the deserialized
59
+ # @param [ String ] buffer Buffer containing the message header.
60
+ #
61
+ # @return [ Array<Fixnum> ] Array consisting of the deserialized
60
62
  # length, request id, response id, and op code.
61
63
  def self.deserialize(buffer)
62
64
  buffer.get_bytes(16).unpack(HEADER_PACK)
@@ -70,9 +72,10 @@ module Mongo
70
72
 
71
73
  # Serializes a C style string into the buffer
72
74
  #
73
- # @param buffer [String] Buffer to receive the serialized CString.
74
- # @param value [String] The string to be serialized.
75
- # @return [String] Buffer with serialized value.
75
+ # @param buffer [ String ] Buffer to receive the serialized CString.
76
+ # @param value [ String ] The string to be serialized.
77
+ #
78
+ # @return [ String ] Buffer with serialized value.
76
79
  def self.serialize(buffer, value)
77
80
  buffer.put_cstring(value)
78
81
  end
@@ -85,9 +88,10 @@ module Mongo
85
88
 
86
89
  # Serializes a 32-bit Zero into the buffer
87
90
  #
88
- # @param buffer [String] Buffer to receive the serialized Zero.
89
- # @param value [Fixnum] Ignored value.
90
- # @return [String] Buffer with serialized value.
91
+ # @param buffer [ String ] Buffer to receive the serialized Zero.
92
+ # @param value [ Fixnum ] Ignored value.
93
+ #
94
+ # @return [ String ] Buffer with serialized value.
91
95
  def self.serialize(buffer, value)
92
96
  buffer.put_int32(ZERO)
93
97
  end
@@ -100,8 +104,9 @@ module Mongo
100
104
 
101
105
  # Serializes a fixnum to a 4-byte 32-bit integer
102
106
  #
103
- # @param buffer [String] Buffer to receive the serialized Int32.
104
- # @param value [Fixnum] 32-bit integer to be serialized.
107
+ # @param buffer [ String ] Buffer to receive the serialized Int32.
108
+ # @param value [ Fixnum ] 32-bit integer to be serialized.
109
+ #
105
110
  # @return [String] Buffer with serialized value.
106
111
  def self.serialize(buffer, value)
107
112
  buffer.put_int32(value)
@@ -109,8 +114,9 @@ module Mongo
109
114
 
110
115
  # Deserializes a 32-bit Fixnum from the IO stream
111
116
  #
112
- # @param io [IO] IO stream containing the 32-bit integer
113
- # @return [Fixnum] Deserialized Int32
117
+ # @param [ String ] buffer Buffer containing the 32-bit integer
118
+ #
119
+ # @return [ Fixnum ] Deserialized Int32
114
120
  def self.deserialize(buffer)
115
121
  buffer.get_int32
116
122
  end
@@ -123,16 +129,18 @@ module Mongo
123
129
 
124
130
  # Serializes a fixnum to an 8-byte 64-bit integer
125
131
  #
126
- # @param buffer [String] Buffer to receive the serialized Int64.
127
- # @param value [Fixnum] 64-bit integer to be serialized.
128
- # @return [String] Buffer with serialized value.
132
+ # @param buffer [ String ] Buffer to receive the serialized Int64.
133
+ # @param value [ Fixnum ] 64-bit integer to be serialized.
134
+ #
135
+ # @return [ String ] Buffer with serialized value.
129
136
  def self.serialize(buffer, value)
130
137
  buffer.put_int64(value)
131
138
  end
132
139
 
133
140
  # Deserializes a 64-bit Fixnum from the IO stream
134
141
  #
135
- # @param io [IO] IO stream containing the 64-bit integer.
142
+ # @param [ String ] buffer Buffer containing the 64-bit integer.
143
+ #
136
144
  # @return [Fixnum] Deserialized Int64.
137
145
  def self.deserialize(buffer)
138
146
  buffer.get_int64
@@ -146,9 +154,10 @@ module Mongo
146
154
 
147
155
  # Serializes a document into the buffer
148
156
  #
149
- # @param buffer [String] Buffer to receive the BSON encoded document.
150
- # @param value [Hash] Document to serialize as BSON.
151
- # @return [String] Buffer with serialized value.
157
+ # @param buffer [ String ] Buffer to receive the BSON encoded document.
158
+ # @param value [ Hash ] Document to serialize as BSON.
159
+ #
160
+ # @return [ String ] Buffer with serialized value.
152
161
  def self.serialize(buffer, value, max_bson_size = nil)
153
162
  start_size = buffer.length
154
163
  value.to_bson(buffer)
@@ -159,8 +168,9 @@ module Mongo
159
168
 
160
169
  # Deserializes a document from the IO stream
161
170
  #
162
- # @param io [IO] IO stream containing the BSON encoded document.
163
- # @return [Hash] The decoded BSON document.
171
+ # @param [ String ] buffer Buffer containing the BSON encoded document.
172
+ #
173
+ # @return [ Hash ] The decoded BSON document.
164
174
  def self.deserialize(buffer)
165
175
  BSON::Document.from_bson(buffer)
166
176
  end
@@ -120,6 +120,19 @@ module Mongo
120
120
  monitor.stop! and true
121
121
  end
122
122
 
123
+ # When the server is flagged for garbage collection, stop the monitor
124
+ # thread.
125
+ #
126
+ # @example Finalize the object.
127
+ # Server.finalize(monitor)
128
+ #
129
+ # @param [ Server::Monitor ] monitor The server monitor.
130
+ #
131
+ # @since 2.2.0
132
+ def self.finalize(monitor)
133
+ proc { monitor.stop! }
134
+ end
135
+
123
136
  # Instantiate a new server object. Will start the background refresh and
124
137
  # subscribe to the appropriate events.
125
138
  #
@@ -145,6 +158,7 @@ module Mongo
145
158
  @monitor = Monitor.new(address, event_listeners, options)
146
159
  monitor.scan!
147
160
  monitor.run!
161
+ ObjectSpace.define_finalizer(self, self.class.finalize(monitor))
148
162
  end
149
163
 
150
164
  # Get a pretty printed server inspection.
@@ -168,7 +182,7 @@ module Mongo
168
182
  #
169
183
  # @since 2.0.0
170
184
  def pool
171
- @pool ||= ConnectionPool.get(self)
185
+ @pool ||= cluster.pool(self)
172
186
  end
173
187
 
174
188
  # Determine if the provided tags are a subset of the server's tags.
@@ -23,9 +23,6 @@ module Mongo
23
23
  class ConnectionPool
24
24
  include Loggable
25
25
 
26
- # Used for synchronization of pools access.
27
- MUTEX = Mutex.new
28
-
29
26
  # @return [ Hash ] options The pool options.
30
27
  attr_reader :options
31
28
 
@@ -131,22 +128,10 @@ module Mongo
131
128
  #
132
129
  # @since 2.0.0
133
130
  def get(server)
134
- MUTEX.synchronize do
135
- pools[server.address] ||= create_pool(server)
136
- end
137
- end
138
-
139
- private
140
-
141
- def create_pool(server)
142
131
  ConnectionPool.new(server.options) do
143
132
  Connection.new(server, server.options)
144
133
  end
145
134
  end
146
-
147
- def pools
148
- @pools ||= {}
149
- end
150
135
  end
151
136
  end
152
137
  end
@@ -364,7 +364,8 @@ module Mongo
364
364
  #
365
365
  # @since 2.0.0
366
366
  def other?
367
- !primary? && !secondary? && !passive? && !arbiter?
367
+ (!primary? && !secondary? && !passive? && !arbiter?) ||
368
+ (hidden? && !replica_set_name.nil?)
368
369
  end
369
370
 
370
371
  # Will return true if the server is passive.
@@ -17,5 +17,5 @@ module Mongo
17
17
  # The current version of the driver.
18
18
  #
19
19
  # @since 2.0.0
20
- VERSION = '2.2.0.rc0'.freeze
20
+ VERSION = '2.2.0'.freeze
21
21
  end
@@ -29,5 +29,5 @@ Gem::Specification.new do |s|
29
29
  s.has_rdoc = 'yard'
30
30
  s.bindir = 'bin'
31
31
 
32
- s.add_dependency 'bson', '~> 4.0.0.rc0'
32
+ s.add_dependency 'bson', '~> 4.0'
33
33
  end
@@ -521,7 +521,7 @@ describe Mongo::Collection do
521
521
  end
522
522
  end
523
523
 
524
- context 'when the user is not authorized' do
524
+ context 'when the user is not authorized', if: auth_enabled? do
525
525
 
526
526
  let(:view) do
527
527
  unauthorized_collection.find
@@ -180,7 +180,7 @@ describe Mongo::Database do
180
180
  end
181
181
  end
182
182
 
183
- context 'when the user is not authorized', unless: sharded? do
183
+ context 'when the user is not authorized', if: auth_enabled? do
184
184
 
185
185
  let(:database) do
186
186
  described_class.new(unauthorized_client, TEST_DB)
@@ -18,10 +18,14 @@ describe Mongo::Server::ConnectionPool do
18
18
  Mongo::Event::Listeners.new
19
19
  end
20
20
 
21
+ let(:cluster) do
22
+ double('cluster')
23
+ end
24
+
21
25
  describe '#checkin' do
22
26
 
23
27
  let(:server) do
24
- Mongo::Server.new(address, double('cluster'), monitoring, listeners, options)
28
+ Mongo::Server.new(address, cluster, monitoring, listeners, options)
25
29
  end
26
30
 
27
31
  let!(:pool) do
@@ -29,6 +33,7 @@ describe Mongo::Server::ConnectionPool do
29
33
  end
30
34
 
31
35
  after do
36
+ expect(cluster).to receive(:pool).with(server).and_return(pool)
32
37
  server.disconnect!
33
38
  end
34
39
 
@@ -55,7 +60,7 @@ describe Mongo::Server::ConnectionPool do
55
60
  describe '#checkout' do
56
61
 
57
62
  let(:server) do
58
- Mongo::Server.new(address, double('cluster'), monitoring, listeners, options)
63
+ Mongo::Server.new(address, cluster, monitoring, listeners, options)
59
64
  end
60
65
 
61
66
  let!(:pool) do
@@ -103,27 +108,24 @@ describe Mongo::Server::ConnectionPool do
103
108
  describe '#disconnect!' do
104
109
 
105
110
  let(:server) do
106
- Mongo::Server.new(address, double('cluster'), monitoring, listeners, options)
111
+ Mongo::Server.new(address, cluster, monitoring, listeners, options)
107
112
  end
108
113
 
109
114
  let!(:pool) do
110
115
  described_class.get(server)
111
116
  end
112
117
 
113
- after do
114
- server.disconnect!
115
- end
116
-
117
118
  it 'disconnects the queue' do
118
- expect(pool.send(:queue)).to receive(:disconnect!).twice.and_call_original
119
- pool.disconnect!
119
+ expect(cluster).to receive(:pool).with(server).and_return(pool)
120
+ expect(pool.send(:queue)).to receive(:disconnect!).once.and_call_original
121
+ server.disconnect!
120
122
  end
121
123
  end
122
124
 
123
125
  describe '.get' do
124
126
 
125
127
  let(:server) do
126
- Mongo::Server.new(address, double('cluster'), monitoring, listeners, options)
128
+ Mongo::Server.new(address, cluster, monitoring, listeners, options)
127
129
  end
128
130
 
129
131
  let!(:pool) do
@@ -131,18 +133,19 @@ describe Mongo::Server::ConnectionPool do
131
133
  end
132
134
 
133
135
  after do
136
+ expect(cluster).to receive(:pool).with(server).and_return(pool)
134
137
  server.disconnect!
135
138
  end
136
139
 
137
140
  it 'returns the pool for the server' do
138
- expect(pool).to eql(described_class.get(server))
141
+ expect(pool).to_not be_nil
139
142
  end
140
143
  end
141
144
 
142
145
  describe '#inspect' do
143
146
 
144
147
  let(:server) do
145
- Mongo::Server.new(address, double('cluster'), monitoring, listeners, options)
148
+ Mongo::Server.new(address, cluster, monitoring, listeners, options)
146
149
  end
147
150
 
148
151
  let!(:pool) do
@@ -150,6 +153,7 @@ describe Mongo::Server::ConnectionPool do
150
153
  end
151
154
 
152
155
  after do
156
+ expect(cluster).to receive(:pool).with(server).and_return(pool)
153
157
  server.disconnect!
154
158
  end
155
159
 
@@ -165,7 +169,7 @@ describe Mongo::Server::ConnectionPool do
165
169
  describe '#with_connection' do
166
170
 
167
171
  let(:server) do
168
- Mongo::Server.new(address, double('cluster'), monitoring, listeners, options)
172
+ Mongo::Server.new(address, cluster, monitoring, listeners, options)
169
173
  end
170
174
 
171
175
  let!(:pool) do
@@ -14,27 +14,26 @@ describe Mongo::Server::Connection do
14
14
  Mongo::Event::Listeners.new
15
15
  end
16
16
 
17
+ let(:cluster) do
18
+ double('cluster')
19
+ end
20
+
17
21
  let(:server) do
18
- Mongo::Server.new(address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
22
+ Mongo::Server.new(address, cluster, monitoring, listeners, TEST_OPTIONS)
23
+ end
24
+
25
+ let(:pool) do
26
+ double('pool')
19
27
  end
20
28
 
21
29
  after do
30
+ expect(cluster).to receive(:pool).with(server).and_return(pool)
31
+ expect(pool).to receive(:disconnect!).and_return(true)
22
32
  server.disconnect!
23
33
  end
24
34
 
25
35
  describe '#connectable?' do
26
36
 
27
- # context 'when the connection is connectable' do
28
-
29
- # let(:connection) do
30
- # described_class.new(server)
31
- # end
32
-
33
- # it 'returns true' do
34
- # expect(connection).to be_connectable
35
- # end
36
- # end
37
-
38
37
  context 'when the connection is not connectable' do
39
38
 
40
39
  let(:bad_address) do
@@ -42,7 +41,7 @@ describe Mongo::Server::Connection do
42
41
  end
43
42
 
44
43
  let(:bad_server) do
45
- Mongo::Server.new(bad_address, double('cluster'), monitoring, listeners, TEST_OPTIONS)
44
+ Mongo::Server.new(bad_address, cluster, monitoring, listeners, TEST_OPTIONS)
46
45
  end
47
46
 
48
47
  let(:connection) do
@@ -240,6 +239,55 @@ describe Mongo::Server::Connection do
240
239
  end
241
240
  end
242
241
 
242
+ context 'when the message exceeds the max size' do
243
+
244
+ context 'when the message is an insert' do
245
+
246
+ before do
247
+ allow(connection).to receive(:max_message_size).and_return(200)
248
+ end
249
+
250
+ let(:documents) do
251
+ [{ 'name' => 'testing' } ] * 10
252
+ end
253
+
254
+ let(:reply) do
255
+ connection.dispatch([ insert ])
256
+ end
257
+
258
+ it 'checks the size against the max message size' do
259
+ expect {
260
+ reply
261
+ }.to raise_exception(Mongo::Error::MaxMessageSize)
262
+ end
263
+ end
264
+
265
+ context 'when the message is a command' do
266
+
267
+ before do
268
+ allow(connection).to receive(:max_bson_object_size).and_return(100)
269
+ end
270
+
271
+ let(:selector) do
272
+ { :getlasterror => '1' }
273
+ end
274
+
275
+ let(:command) do
276
+ Mongo::Protocol::Query.new(TEST_DB, '$cmd', selector, :limit => -1)
277
+ end
278
+
279
+ let(:reply) do
280
+ connection.dispatch([ command ])
281
+ end
282
+
283
+ it 'checks the size against the max bson size' do
284
+ expect {
285
+ reply
286
+ }.to raise_exception(Mongo::Error::MaxBSONSize)
287
+ end
288
+ end
289
+ end
290
+
243
291
  context 'when a network or socket error occurs' do
244
292
 
245
293
  let(:socket) do
@@ -18,6 +18,10 @@ describe Mongo::Server do
18
18
  Mongo::Address.new('127.0.0.1:27017')
19
19
  end
20
20
 
21
+ let(:pool) do
22
+ Mongo::Server::ConnectionPool.get(server)
23
+ end
24
+
21
25
  describe '#==' do
22
26
 
23
27
  let(:server) do
@@ -25,6 +29,7 @@ describe Mongo::Server do
25
29
  end
26
30
 
27
31
  after do
32
+ expect(cluster).to receive(:pool).with(server).and_return(pool)
28
33
  server.disconnect!
29
34
  end
30
35
 
@@ -81,6 +86,10 @@ describe Mongo::Server do
81
86
  server.disconnect!
82
87
  end
83
88
 
89
+ before do
90
+ expect(cluster).to receive(:pool).with(server).and_return(pool)
91
+ end
92
+
84
93
  it 'returns true' do
85
94
  expect(server).to be_connectable
86
95
  end
@@ -97,6 +106,7 @@ describe Mongo::Server do
97
106
  end
98
107
 
99
108
  before do
109
+ expect(cluster).to receive(:pool).with(server).and_return(pool)
100
110
  server.disconnect!
101
111
  end
102
112
 
@@ -117,6 +127,7 @@ describe Mongo::Server do
117
127
  end
118
128
 
119
129
  after do
130
+ expect(cluster).to receive(:pool).with(server).and_return(pool)
120
131
  server.disconnect!
121
132
  end
122
133
 
@@ -133,6 +144,7 @@ describe Mongo::Server do
133
144
 
134
145
  it 'stops the monitor instance' do
135
146
  expect(server.instance_variable_get(:@monitor)).to receive(:stop!).and_return(true)
147
+ expect(cluster).to receive(:pool).with(server).and_return(pool)
136
148
  server.disconnect!
137
149
  end
138
150
  end
@@ -150,6 +162,7 @@ describe Mongo::Server do
150
162
  end
151
163
 
152
164
  after do
165
+ expect(cluster).to receive(:pool).with(server).and_return(pool)
153
166
  server.disconnect!
154
167
  end
155
168
 
@@ -166,25 +179,6 @@ describe Mongo::Server do
166
179
  end
167
180
  end
168
181
 
169
- describe '#pool' do
170
-
171
- let(:server) do
172
- described_class.new(address, cluster, monitoring, listeners, TEST_OPTIONS)
173
- end
174
-
175
- let(:pool) do
176
- server.pool
177
- end
178
-
179
- after do
180
- server.disconnect!
181
- end
182
-
183
- it 'returns the connection pool for the server' do
184
- expect(pool).to be_a(Mongo::Server::ConnectionPool)
185
- end
186
- end
187
-
188
182
  describe '#scan!' do
189
183
 
190
184
  let(:server) do
@@ -192,6 +186,7 @@ describe Mongo::Server do
192
186
  end
193
187
 
194
188
  after do
189
+ expect(cluster).to receive(:pool).with(server).and_return(pool)
195
190
  server.disconnect!
196
191
  end
197
192
 
@@ -211,6 +206,7 @@ describe Mongo::Server do
211
206
  end
212
207
 
213
208
  after do
209
+ expect(cluster).to receive(:pool).with(server).and_return(pool)
214
210
  server.disconnect!
215
211
  end
216
212
 
@@ -171,6 +171,15 @@ def failing_delete_doc
171
171
  { que: { field: 'test' } }
172
172
  end
173
173
 
174
+ # Try running a command on the admin database to see if the mongod was started with auth.
175
+ #
176
+ # @since 2.2.0
177
+ def auth_enabled?
178
+ $mongo_client ||= initialize_scanned_client!
179
+ begin; $mongo_client.use(:admin).command(getCmdLineOpts: 1); rescue; return true; end
180
+ false
181
+ end
182
+
174
183
  # Initializes a basic scanned client to do an ismaster check.
175
184
  #
176
185
  # @since 2.0.0
@@ -7,12 +7,21 @@ phases: [
7
7
  {
8
8
  responses: [
9
9
 
10
+ ["a:27017", {
11
+
12
+ ok: 1,
13
+ ismaster: false,
14
+ secondary: true,
15
+ hidden: true,
16
+ hosts: ["c:27017", "d:27017"],
17
+ setName: "rs"
18
+ }],
10
19
  ["b:27017", {
11
20
 
12
21
  ok: 1,
13
22
  ismaster: false,
14
23
  secondary: false,
15
- hosts: ["a:27017", "b:27017"],
24
+ hosts: ["c:27017", "d:27017"],
16
25
  setName: "rs"
17
26
  }]
18
27
  ],
@@ -23,14 +32,26 @@ phases: [
23
32
 
24
33
  "a:27017": {
25
34
 
26
- type: "Unknown",
27
- setName:
35
+ type: "RSOther",
36
+ setName: "rs"
28
37
  },
29
38
 
30
39
  "b:27017": {
31
40
 
32
41
  type: "RSOther",
33
42
  setName: "rs"
43
+ },
44
+
45
+ "c:27017": {
46
+
47
+ type: "Unknown",
48
+ setName:
49
+ },
50
+
51
+ "d:27017": {
52
+
53
+ type: "Unknown",
54
+ setName:
34
55
  }
35
56
  },
36
57
 
@@ -0,0 +1,59 @@
1
+ description: "Primary becomes a secondary with wrong setName"
2
+
3
+ uri: "mongodb://a/?replicaSet=rs"
4
+
5
+ phases: [
6
+
7
+ # Primary is discovered normally.
8
+ {
9
+ responses: [
10
+
11
+ ["a:27017", {
12
+
13
+ ok: 1,
14
+ ismaster: true,
15
+ hosts: ["a:27017"],
16
+ setName: "rs"
17
+ }]
18
+ ],
19
+
20
+ outcome: {
21
+
22
+ servers: {
23
+
24
+ "a:27017": {
25
+
26
+ type: "RSPrimary",
27
+ setName: "rs"
28
+ }
29
+ },
30
+
31
+ topologyType: "ReplicaSetWithPrimary",
32
+ setName: "rs"
33
+ }
34
+ },
35
+
36
+ # Primary changes its setName and becomes secondary.
37
+ # Remove it and change the topologyType.
38
+ {
39
+ responses: [
40
+
41
+ ["a:27017", {
42
+
43
+ ok: 1,
44
+ ismaster: false,
45
+ secondary: true,
46
+ hosts: ["a:27017"],
47
+ setName: "wrong"
48
+ }]
49
+ ],
50
+
51
+ outcome: {
52
+
53
+ servers: {},
54
+
55
+ topologyType: "ReplicaSetNoPrimary",
56
+ setName: "rs"
57
+ }
58
+ }
59
+ ]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0.rc0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Brock
@@ -14,7 +14,7 @@ cert_chain:
14
14
  -----BEGIN CERTIFICATE-----
15
15
  MIIDfDCCAmSgAwIBAgIBATANBgkqhkiG9w0BAQUFADBCMRQwEgYDVQQDDAtkcml2
16
16
  ZXItcnVieTEVMBMGCgmSJomT8ixkARkWBTEwZ2VuMRMwEQYKCZImiZPyLGQBGRYD
17
- Y29tMB4XDTE0MTEyMDE1NTYxOVoXDTE1MTEyMDE1NTYxOVowQjEUMBIGA1UEAwwL
17
+ Y29tMB4XDTE1MTIwNzE1MTcyNloXDTE2MTIwNjE1MTcyNlowQjEUMBIGA1UEAwwL
18
18
  ZHJpdmVyLXJ1YnkxFTATBgoJkiaJk/IsZAEZFgUxMGdlbjETMBEGCgmSJomT8ixk
19
19
  ARkWA2NvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANFdSAa8fRm1
20
20
  bAM9za6Z0fAH4g02bqM1NGnw8zJQrE/PFrFfY6IFCT2AsLfOwr1maVm7iU1+kdVI
@@ -25,14 +25,14 @@ cert_chain:
25
25
  u8KAcPHm5KkCAwEAAaN9MHswCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0O
26
26
  BBYEFFt3WbF+9JpUjAoj62cQBgNb8HzXMCAGA1UdEQQZMBeBFWRyaXZlci1ydWJ5
27
27
  QDEwZ2VuLmNvbTAgBgNVHRIEGTAXgRVkcml2ZXItcnVieUAxMGdlbi5jb20wDQYJ
28
- KoZIhvcNAQEFBQADggEBAKjvumG2Fy9zAoSc1OEcmAqqOfzx1U+isGyEsz1rs5eT
29
- HAIHsxaEdZTjSwDuqyelLDWJHWspeWU5pV5lepfI4cop29wwoPJIJ9Az2RMMbtdv
30
- gFApVb6QX61OMenFeOdJ/QZ3n9xcrxJZFdvrXQ5GjEU2anq3dJhFeESwIMlfVJC7
31
- 7XrlMxizzH712DPfy65dMj0Y39qHdoWYKeCkEoj5UWNcHRK9xgaHJR6prlXrIhgb
32
- o2UXDbWtz5PqoFd8EgNJAn3+BG1pwC9S9pVFG3WPucfAx/bE8iq/vvchHei5Y/Vo
33
- aAz5f/hY4zFeYWvGDBHYEXE1rTN2hhMSyJscPcFbmz0=
28
+ KoZIhvcNAQEFBQADggEBAL/5shZXBvCGGJcJqXyD2CJieOOH4EGUt/UKvSZ58lMz
29
+ QkW5aKG22GJbXesMq+dMm/+gzUB2ea9TzttBEE5ZM/eNvoxyf7yNUcFyLQ365S6P
30
+ rtQOj1Ms7ud5ffrhZJn1o7ayfY2ljQU0xLI2Yoyzl9XJq8U0TztS6Vk5wYIoLwUX
31
+ NWGRSbETPJyR4mtUEbgI5A+N7pakJPUKKK1zXzADflsx51jjP5rZJJltnoVsBBgN
32
+ EhIn2f8suSc9QAqYt7w4T+PMtjxWTVcXs+Uy2PbDtjhtEBz6ZsP6YSsOpJbrCjCV
33
+ wZtXjpRUvWz86V5vjhHCTE8fqfEb85aeDwUCckPzpio=
34
34
  -----END CERTIFICATE-----
35
- date: 2015-11-16 00:00:00.000000000 Z
35
+ date: 2015-12-07 00:00:00.000000000 Z
36
36
  dependencies:
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: bson
@@ -40,14 +40,14 @@ dependencies:
40
40
  requirements:
41
41
  - - "~>"
42
42
  - !ruby/object:Gem::Version
43
- version: 4.0.0.rc0
43
+ version: '4.0'
44
44
  type: :runtime
45
45
  prerelease: false
46
46
  version_requirements: !ruby/object:Gem::Requirement
47
47
  requirements:
48
48
  - - "~>"
49
49
  - !ruby/object:Gem::Version
50
- version: 4.0.0.rc0
50
+ version: '4.0'
51
51
  description: A Ruby driver for MongoDB
52
52
  email: mongodb-dev@googlegroups.com
53
53
  executables: []
@@ -59,7 +59,6 @@ files:
59
59
  - README.md
60
60
  - Rakefile
61
61
  - bin/mongo_console
62
- - lib/csasl/csasl.bundle
63
62
  - lib/mongo.rb
64
63
  - lib/mongo/address.rb
65
64
  - lib/mongo/address/ipv4.rb
@@ -493,6 +492,7 @@ files:
493
492
  - spec/support/sdam/rs/secondary_mismatched_me.yml
494
493
  - spec/support/sdam/rs/secondary_wrong_set_name.yml
495
494
  - spec/support/sdam/rs/secondary_wrong_set_name_with_primary.yml
495
+ - spec/support/sdam/rs/stepdown_change_set_name.yml
496
496
  - spec/support/sdam/rs/unexpected_mongos.yml
497
497
  - spec/support/sdam/rs/wrong_set_name.yml
498
498
  - spec/support/sdam/sharded/mongos_disconnect.yml
@@ -563,12 +563,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
563
563
  version: '0'
564
564
  required_rubygems_version: !ruby/object:Gem::Requirement
565
565
  requirements:
566
- - - ">"
566
+ - - ">="
567
567
  - !ruby/object:Gem::Version
568
- version: 1.3.1
568
+ version: '0'
569
569
  requirements: []
570
570
  rubyforge_project:
571
- rubygems_version: 2.4.6
571
+ rubygems_version: 2.4.8
572
572
  signing_key:
573
573
  specification_version: 4
574
574
  summary: Ruby driver for MongoDB
@@ -774,6 +774,7 @@ test_files:
774
774
  - spec/support/sdam/rs/secondary_mismatched_me.yml
775
775
  - spec/support/sdam/rs/secondary_wrong_set_name.yml
776
776
  - spec/support/sdam/rs/secondary_wrong_set_name_with_primary.yml
777
+ - spec/support/sdam/rs/stepdown_change_set_name.yml
777
778
  - spec/support/sdam/rs/unexpected_mongos.yml
778
779
  - spec/support/sdam/rs/wrong_set_name.yml
779
780
  - spec/support/sdam/sharded/mongos_disconnect.yml
metadata.gz.sig CHANGED
Binary file
Binary file