mongo 2.2.7 → 2.3.0

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.
Files changed (266) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/LICENSE +1 -1
  5. data/README.md +1 -1
  6. data/Rakefile +1 -1
  7. data/lib/mongo.rb +1 -1
  8. data/lib/mongo/address.rb +1 -1
  9. data/lib/mongo/address/ipv4.rb +1 -1
  10. data/lib/mongo/address/ipv6.rb +1 -1
  11. data/lib/mongo/address/unix.rb +1 -1
  12. data/lib/mongo/auth.rb +1 -1
  13. data/lib/mongo/auth/cr.rb +1 -1
  14. data/lib/mongo/auth/ldap.rb +1 -1
  15. data/lib/mongo/auth/roles.rb +1 -1
  16. data/lib/mongo/auth/user.rb +1 -1
  17. data/lib/mongo/auth/user/view.rb +5 -5
  18. data/lib/mongo/auth/x509.rb +1 -1
  19. data/lib/mongo/bson.rb +1 -1
  20. data/lib/mongo/bulk_write.rb +4 -4
  21. data/lib/mongo/bulk_write/combineable.rb +1 -1
  22. data/lib/mongo/bulk_write/ordered_combiner.rb +1 -1
  23. data/lib/mongo/bulk_write/result.rb +1 -1
  24. data/lib/mongo/bulk_write/result_combiner.rb +1 -1
  25. data/lib/mongo/bulk_write/transformable.rb +1 -1
  26. data/lib/mongo/bulk_write/unordered_combiner.rb +1 -1
  27. data/lib/mongo/bulk_write/validatable.rb +1 -1
  28. data/lib/mongo/client.rb +2 -2
  29. data/lib/mongo/cluster.rb +15 -3
  30. data/lib/mongo/cluster/cursor_reaper.rb +174 -0
  31. data/lib/mongo/cluster/topology.rb +1 -1
  32. data/lib/mongo/cluster/topology/replica_set.rb +1 -1
  33. data/lib/mongo/cluster/topology/sharded.rb +1 -1
  34. data/lib/mongo/cluster/topology/single.rb +1 -1
  35. data/lib/mongo/cluster/topology/unknown.rb +1 -1
  36. data/lib/mongo/collection.rb +5 -4
  37. data/lib/mongo/collection/view.rb +4 -4
  38. data/lib/mongo/collection/view/aggregation.rb +2 -2
  39. data/lib/mongo/collection/view/builder.rb +1 -1
  40. data/lib/mongo/collection/view/builder/aggregation.rb +1 -1
  41. data/lib/mongo/collection/view/builder/find_command.rb +1 -1
  42. data/lib/mongo/collection/view/builder/flags.rb +1 -1
  43. data/lib/mongo/collection/view/builder/map_reduce.rb +1 -1
  44. data/lib/mongo/collection/view/builder/modifiers.rb +1 -1
  45. data/lib/mongo/collection/view/builder/op_query.rb +1 -1
  46. data/lib/mongo/collection/view/explainable.rb +1 -1
  47. data/lib/mongo/collection/view/immutable.rb +1 -1
  48. data/lib/mongo/collection/view/iterable.rb +2 -2
  49. data/lib/mongo/collection/view/map_reduce.rb +3 -3
  50. data/lib/mongo/collection/view/readable.rb +23 -6
  51. data/lib/mongo/collection/view/writable.rb +3 -3
  52. data/lib/mongo/cursor.rb +50 -7
  53. data/lib/mongo/cursor/builder.rb +1 -1
  54. data/lib/mongo/cursor/builder/get_more_command.rb +1 -1
  55. data/lib/mongo/cursor/builder/kill_cursors_command.rb +29 -1
  56. data/lib/mongo/cursor/builder/op_get_more.rb +1 -1
  57. data/lib/mongo/cursor/builder/op_kill_cursors.rb +29 -1
  58. data/lib/mongo/database.rb +4 -4
  59. data/lib/mongo/database/view.rb +2 -2
  60. data/lib/mongo/dbref.rb +4 -3
  61. data/lib/mongo/error.rb +1 -1
  62. data/lib/mongo/error/bulk_write_error.rb +1 -1
  63. data/lib/mongo/error/closed_stream.rb +1 -1
  64. data/lib/mongo/error/extra_file_chunk.rb +1 -1
  65. data/lib/mongo/error/file_not_found.rb +1 -1
  66. data/lib/mongo/error/invalid_bulk_operation.rb +1 -1
  67. data/lib/mongo/error/invalid_bulk_operation_type.rb +1 -1
  68. data/lib/mongo/error/invalid_collection_name.rb +1 -1
  69. data/lib/mongo/error/invalid_database_name.rb +1 -1
  70. data/lib/mongo/error/invalid_document.rb +1 -1
  71. data/lib/mongo/error/invalid_file.rb +1 -1
  72. data/lib/mongo/error/invalid_file_revision.rb +1 -1
  73. data/lib/mongo/error/invalid_nonce.rb +1 -1
  74. data/lib/mongo/error/invalid_replacement_document.rb +1 -1
  75. data/lib/mongo/error/invalid_server_preference.rb +1 -1
  76. data/lib/mongo/error/invalid_signature.rb +1 -1
  77. data/lib/mongo/error/invalid_update_document.rb +1 -1
  78. data/lib/mongo/error/invalid_uri.rb +1 -1
  79. data/lib/mongo/error/invalid_write_concern.rb +1 -1
  80. data/lib/mongo/error/max_bson_size.rb +1 -1
  81. data/lib/mongo/error/max_message_size.rb +1 -1
  82. data/lib/mongo/error/missing_file_chunk.rb +1 -1
  83. data/lib/mongo/error/multi_index_drop.rb +1 -1
  84. data/lib/mongo/error/need_primary_server.rb +1 -1
  85. data/lib/mongo/error/no_server_available.rb +4 -2
  86. data/lib/mongo/error/operation_failure.rb +1 -1
  87. data/lib/mongo/error/parser.rb +1 -1
  88. data/lib/mongo/error/socket_error.rb +1 -1
  89. data/lib/mongo/error/socket_timeout_error.rb +1 -1
  90. data/lib/mongo/error/unchangeable_collection_option.rb +1 -1
  91. data/lib/mongo/error/unexpected_chunk_length.rb +1 -1
  92. data/lib/mongo/error/unexpected_response.rb +1 -1
  93. data/lib/mongo/error/unsupported_features.rb +1 -1
  94. data/lib/mongo/event.rb +1 -1
  95. data/lib/mongo/event/description_changed.rb +1 -1
  96. data/lib/mongo/event/publisher.rb +1 -1
  97. data/lib/mongo/event/subscriber.rb +1 -1
  98. data/lib/mongo/grid.rb +1 -1
  99. data/lib/mongo/grid/file.rb +6 -2
  100. data/lib/mongo/grid/file/chunk.rb +6 -4
  101. data/lib/mongo/grid/file/info.rb +7 -3
  102. data/lib/mongo/grid/fs_bucket.rb +12 -6
  103. data/lib/mongo/grid/stream.rb +1 -1
  104. data/lib/mongo/grid/stream/read.rb +2 -4
  105. data/lib/mongo/grid/stream/write.rb +4 -3
  106. data/lib/mongo/index.rb +1 -1
  107. data/lib/mongo/index/view.rb +5 -4
  108. data/lib/mongo/loggable.rb +1 -1
  109. data/lib/mongo/logger.rb +1 -1
  110. data/lib/mongo/monitoring.rb +1 -1
  111. data/lib/mongo/operation.rb +1 -1
  112. data/lib/mongo/operation/commands.rb +1 -1
  113. data/lib/mongo/operation/commands/aggregate.rb +7 -7
  114. data/lib/mongo/operation/commands/aggregate/result.rb +1 -1
  115. data/lib/mongo/operation/commands/collections_info.rb +10 -9
  116. data/lib/mongo/operation/commands/collections_info/result.rb +1 -1
  117. data/lib/mongo/operation/commands/command.rb +1 -1
  118. data/lib/mongo/operation/commands/indexes.rb +12 -11
  119. data/lib/mongo/operation/commands/list_collections.rb +1 -1
  120. data/lib/mongo/operation/commands/list_collections/result.rb +1 -1
  121. data/lib/mongo/operation/commands/list_indexes.rb +1 -1
  122. data/lib/mongo/operation/commands/list_indexes/result.rb +1 -1
  123. data/lib/mongo/operation/commands/map_reduce.rb +1 -1
  124. data/lib/mongo/operation/commands/map_reduce/result.rb +1 -1
  125. data/lib/mongo/operation/commands/user_query.rb +11 -10
  126. data/lib/mongo/operation/commands/users_info.rb +2 -2
  127. data/lib/mongo/operation/commands/users_info/result.rb +1 -1
  128. data/lib/mongo/operation/executable.rb +8 -7
  129. data/lib/mongo/operation/kill_cursors.rb +2 -2
  130. data/lib/mongo/operation/limited.rb +1 -1
  131. data/lib/mongo/operation/read.rb +1 -1
  132. data/lib/mongo/operation/read/get_more.rb +2 -2
  133. data/lib/mongo/operation/read/query.rb +1 -1
  134. data/lib/mongo/operation/read/query/result.rb +1 -1
  135. data/lib/mongo/operation/read_preference.rb +10 -10
  136. data/lib/mongo/operation/result.rb +1 -1
  137. data/lib/mongo/operation/specifiable.rb +2 -2
  138. data/lib/mongo/operation/write.rb +1 -1
  139. data/lib/mongo/operation/write/bulk.rb +1 -1
  140. data/lib/mongo/operation/write/bulk/bulkable.rb +9 -9
  141. data/lib/mongo/operation/write/bulk/delete.rb +3 -3
  142. data/lib/mongo/operation/write/bulk/delete/result.rb +1 -1
  143. data/lib/mongo/operation/write/bulk/insert.rb +5 -5
  144. data/lib/mongo/operation/write/bulk/insert/result.rb +1 -1
  145. data/lib/mongo/operation/write/bulk/legacy_mergable.rb +1 -1
  146. data/lib/mongo/operation/write/bulk/mergable.rb +1 -1
  147. data/lib/mongo/operation/write/bulk/update.rb +3 -3
  148. data/lib/mongo/operation/write/bulk/update/result.rb +1 -1
  149. data/lib/mongo/operation/write/command.rb +1 -1
  150. data/lib/mongo/operation/write/command/create_index.rb +1 -1
  151. data/lib/mongo/operation/write/command/create_user.rb +1 -1
  152. data/lib/mongo/operation/write/command/delete.rb +1 -1
  153. data/lib/mongo/operation/write/command/drop_index.rb +1 -1
  154. data/lib/mongo/operation/write/command/insert.rb +11 -1
  155. data/lib/mongo/operation/write/command/remove_user.rb +1 -1
  156. data/lib/mongo/operation/write/command/update.rb +1 -1
  157. data/lib/mongo/operation/write/command/update_user.rb +1 -1
  158. data/lib/mongo/operation/write/command/writable.rb +7 -6
  159. data/lib/mongo/operation/write/create_index.rb +1 -1
  160. data/lib/mongo/operation/write/create_user.rb +1 -1
  161. data/lib/mongo/operation/write/delete.rb +1 -1
  162. data/lib/mongo/operation/write/delete/result.rb +1 -1
  163. data/lib/mongo/operation/write/drop_index.rb +5 -5
  164. data/lib/mongo/operation/write/gle.rb +3 -3
  165. data/lib/mongo/operation/write/idable.rb +1 -1
  166. data/lib/mongo/operation/write/insert.rb +5 -5
  167. data/lib/mongo/operation/write/insert/result.rb +1 -1
  168. data/lib/mongo/operation/write/remove_user.rb +1 -1
  169. data/lib/mongo/operation/write/update.rb +1 -1
  170. data/lib/mongo/operation/write/update/result.rb +1 -1
  171. data/lib/mongo/operation/write/update_user.rb +1 -1
  172. data/lib/mongo/operation/write/write_command_enabled.rb +10 -9
  173. data/lib/mongo/protocol/bit_vector.rb +2 -2
  174. data/lib/mongo/protocol/delete.rb +1 -1
  175. data/lib/mongo/protocol/get_more.rb +1 -1
  176. data/lib/mongo/protocol/insert.rb +5 -1
  177. data/lib/mongo/protocol/kill_cursors.rb +1 -1
  178. data/lib/mongo/protocol/message.rb +9 -5
  179. data/lib/mongo/protocol/query.rb +1 -1
  180. data/lib/mongo/protocol/reply.rb +1 -1
  181. data/lib/mongo/protocol/serializers.rb +8 -8
  182. data/lib/mongo/protocol/update.rb +1 -1
  183. data/lib/mongo/server.rb +40 -3
  184. data/lib/mongo/server/connectable.rb +1 -1
  185. data/lib/mongo/server/connection.rb +4 -2
  186. data/lib/mongo/server/connection_pool.rb +1 -1
  187. data/lib/mongo/server/connection_pool/queue.rb +1 -1
  188. data/lib/mongo/server/context.rb +3 -1
  189. data/lib/mongo/server/description.rb +1 -1
  190. data/lib/mongo/server/description/inspector/description_changed.rb +1 -1
  191. data/lib/mongo/server/monitor.rb +1 -1
  192. data/lib/mongo/server_selector.rb +2 -1
  193. data/lib/mongo/server_selector/nearest.rb +1 -1
  194. data/lib/mongo/server_selector/primary.rb +1 -1
  195. data/lib/mongo/server_selector/primary_preferred.rb +1 -1
  196. data/lib/mongo/server_selector/secondary.rb +1 -1
  197. data/lib/mongo/server_selector/secondary_preferred.rb +1 -1
  198. data/lib/mongo/server_selector/selectable.rb +12 -7
  199. data/lib/mongo/socket.rb +1 -1
  200. data/lib/mongo/socket/ssl.rb +1 -1
  201. data/lib/mongo/socket/tcp.rb +1 -1
  202. data/lib/mongo/socket/unix.rb +1 -1
  203. data/lib/mongo/uri.rb +1 -1
  204. data/lib/mongo/version.rb +2 -2
  205. data/lib/mongo/write_concern/acknowledged.rb +1 -1
  206. data/lib/mongo/write_concern/normalizable.rb +1 -1
  207. data/lib/mongo/write_concern/unacknowledged.rb +1 -1
  208. data/mongo.gemspec +1 -1
  209. data/spec/mongo/client_spec.rb +2 -2
  210. data/spec/mongo/cluster/cursor_reaper_spec.rb +216 -0
  211. data/spec/mongo/cluster_spec.rb +36 -5
  212. data/spec/mongo/collection/view/aggregation_spec.rb +2 -2
  213. data/spec/mongo/collection/view/map_reduce_spec.rb +2 -2
  214. data/spec/mongo/collection/view/readable_spec.rb +203 -5
  215. data/spec/mongo/collection/view_spec.rb +10 -0
  216. data/spec/mongo/collection_spec.rb +64 -18
  217. data/spec/mongo/cursor_spec.rb +89 -0
  218. data/spec/mongo/database_spec.rb +79 -13
  219. data/spec/mongo/grid/fs_bucket_spec.rb +119 -1
  220. data/spec/mongo/grid/stream/write_spec.rb +63 -12
  221. data/spec/mongo/index/view_spec.rb +19 -0
  222. data/spec/mongo/operation/commands/aggregate_spec.rb +10 -7
  223. data/spec/mongo/operation/commands/collections_info_spec.rb +1 -1
  224. data/spec/mongo/operation/commands/command_spec.rb +3 -3
  225. data/spec/mongo/operation/commands/indexes_spec.rb +1 -1
  226. data/spec/mongo/operation/commands/map_reduce_spec.rb +2 -2
  227. data/spec/mongo/operation/kill_cursors_spec.rb +10 -19
  228. data/spec/mongo/operation/read/get_more_spec.rb +13 -25
  229. data/spec/mongo/operation/read/query_spec.rb +26 -30
  230. data/spec/mongo/operation/read_preference_spec.rb +11 -11
  231. data/spec/mongo/operation/specifiable_spec.rb +31 -0
  232. data/spec/mongo/operation/write/bulk/delete_spec.rb +16 -18
  233. data/spec/mongo/operation/write/bulk/insert_spec.rb +17 -18
  234. data/spec/mongo/operation/write/bulk/update_spec.rb +20 -25
  235. data/spec/mongo/operation/write/command/delete_spec.rb +26 -32
  236. data/spec/mongo/operation/write/command/insert_spec.rb +24 -31
  237. data/spec/mongo/operation/write/command/update_spec.rb +24 -32
  238. data/spec/mongo/operation/write/create_index_spec.rb +4 -4
  239. data/spec/mongo/operation/write/create_user_spec.rb +3 -3
  240. data/spec/mongo/operation/write/delete_spec.rb +51 -22
  241. data/spec/mongo/operation/write/drop_index_spec.rb +2 -2
  242. data/spec/mongo/operation/write/insert_spec.rb +42 -11
  243. data/spec/mongo/operation/write/remove_user_spec.rb +4 -4
  244. data/spec/mongo/operation/write/update_spec.rb +34 -6
  245. data/spec/mongo/operation/write/update_user_spec.rb +1 -1
  246. data/spec/mongo/server/connection_spec.rb +22 -14
  247. data/spec/mongo/server_selection_spec.rb +2 -2
  248. data/spec/mongo/server_selector/nearest_spec.rb +4 -4
  249. data/spec/mongo/server_selector/primary_preferred_spec.rb +4 -4
  250. data/spec/mongo/server_selector/primary_spec.rb +2 -2
  251. data/spec/mongo/server_selector/secondary_preferred_spec.rb +4 -4
  252. data/spec/mongo/server_selector/secondary_spec.rb +3 -3
  253. data/spec/mongo/server_selector_spec.rb +82 -3
  254. data/spec/mongo/server_spec.rb +0 -20
  255. data/spec/support/command_monitoring.rb +1 -1
  256. data/spec/support/connection_string.rb +1 -1
  257. data/spec/support/crud.rb +1 -1
  258. data/spec/support/crud/read.rb +1 -1
  259. data/spec/support/crud/write.rb +1 -1
  260. data/spec/support/gridfs.rb +1 -1
  261. data/spec/support/shared/server_selector.rb +3 -3
  262. metadata +7 -10
  263. metadata.gz.sig +0 -0
  264. data/lib/csasl/csasl.bundle +0 -0
  265. data/spec/mongo/operation/write/response_spec.rb +0 -85
  266. data/spec/support/shared/operation.rb +0 -100
@@ -113,7 +113,8 @@ describe Mongo::Server::Connection do
113
113
  TEST_OPTIONS.merge(
114
114
  :user => 'notauser',
115
115
  :password => 'password',
116
- :database => TEST_DB )
116
+ :database => TEST_DB,
117
+ :heartbeat_frequency => 30)
117
118
  )
118
119
  end
119
120
 
@@ -130,7 +131,6 @@ describe Mongo::Server::Connection do
130
131
  end
131
132
 
132
133
  it 'marks the server as unknown' do
133
- pending 'Server must be set as unknown'
134
134
  expect(server).to be_unknown
135
135
  end
136
136
  end
@@ -261,11 +261,11 @@ describe Mongo::Server::Connection do
261
261
  end
262
262
 
263
263
  let(:query_bob) do
264
- Mongo::Protocol::Query.new(TEST_DB, TEST_COLL, { 'name' => 'bob' })
264
+ Mongo::Protocol::Query.new(TEST_DB, TEST_COLL, { name: 'bob' })
265
265
  end
266
266
 
267
267
  let(:query_alice) do
268
- Mongo::Protocol::Query.new(TEST_DB, TEST_COLL, { 'name' => 'alice' })
268
+ Mongo::Protocol::Query.new(TEST_DB, TEST_COLL, { name: 'alice' })
269
269
  end
270
270
 
271
271
  after do
@@ -278,14 +278,14 @@ describe Mongo::Server::Connection do
278
278
  connection.dispatch([ insert, query_bob ])
279
279
  end
280
280
 
281
- it 'raises an UnexpectedResponse' do
281
+ it 'raises an UnexpectedResponse error' do
282
282
  expect {
283
283
  connection.dispatch([ query_alice ])
284
284
  }.to raise_error(Mongo::Error::UnexpectedResponse,
285
285
  /Got response for request ID \d+ but expected response for request ID \d+/)
286
286
  end
287
287
 
288
- it "doesn't break subsequent requests" do
288
+ it 'does not affect subsequent requests' do
289
289
  expect {
290
290
  connection.dispatch([ query_alice ])
291
291
  }.to raise_error(Mongo::Error::UnexpectedResponse)
@@ -294,7 +294,7 @@ describe Mongo::Server::Connection do
294
294
  end
295
295
  end
296
296
 
297
- context 'when a request is brutaly interrupted (Thread.kill)' do
297
+ context 'when a request is interrupted (Thread.kill)' do
298
298
 
299
299
  let(:documents) do
300
300
  [{ 'name' => 'bob' }, { 'name' => 'alice' }]
@@ -305,11 +305,11 @@ describe Mongo::Server::Connection do
305
305
  end
306
306
 
307
307
  let(:query_bob) do
308
- Mongo::Protocol::Query.new(TEST_DB, TEST_COLL, { 'name' => 'bob' })
308
+ Mongo::Protocol::Query.new(TEST_DB, TEST_COLL, { name: 'bob' })
309
309
  end
310
310
 
311
311
  let(:query_alice) do
312
- Mongo::Protocol::Query.new(TEST_DB, TEST_COLL, { 'name' => 'alice' })
312
+ Mongo::Protocol::Query.new(TEST_DB, TEST_COLL, { name: 'alice' })
313
313
  end
314
314
 
315
315
  before do
@@ -320,7 +320,7 @@ describe Mongo::Server::Connection do
320
320
  authorized_collection.delete_many
321
321
  end
322
322
 
323
- it "closes the socket and does not use it for subsequent requests" do
323
+ it 'closes the socket and does not use it for subsequent requests' do
324
324
  t = Thread.new {
325
325
  # Kill the thread just before the reply is read
326
326
  allow(Mongo::Protocol::Reply).to receive(:deserialize_header) { t.kill }
@@ -332,7 +332,6 @@ describe Mongo::Server::Connection do
332
332
  end
333
333
  end
334
334
 
335
-
336
335
  context 'when the message exceeds the max size' do
337
336
 
338
337
  context 'when the message is an insert' do
@@ -547,9 +546,6 @@ describe Mongo::Server::Connection do
547
546
 
548
547
  before do
549
548
  connection.connect!
550
- socket = connection.instance_variable_get(:@socket)
551
- max_message_size = connection.send(:max_message_size)
552
- allow(Mongo::Protocol::Reply).to receive(:deserialize).with(socket, max_message_size).and_return(reply)
553
549
  end
554
550
 
555
551
  context 'when the ismaster response indicates the auth mechanism is :scram' do
@@ -565,6 +561,9 @@ describe Mongo::Server::Connection do
565
561
  context 'when the server auth mechanism is scram', if: scram_sha_1_enabled? do
566
562
 
567
563
  it 'uses scram' do
564
+ socket = connection.instance_variable_get(:@socket)
565
+ max_message_size = connection.send(:max_message_size)
566
+ allow(Mongo::Protocol::Reply).to receive(:deserialize).with(socket, max_message_size).and_return(reply)
568
567
  expect(connection.send(:default_mechanism)).to eq(:scram)
569
568
  end
570
569
  end
@@ -572,6 +571,9 @@ describe Mongo::Server::Connection do
572
571
  context 'when the server auth mechanism is the default (mongodb_cr)', unless: scram_sha_1_enabled? do
573
572
 
574
573
  it 'uses scram' do
574
+ socket = connection.instance_variable_get(:@socket)
575
+ max_message_size = connection.send(:max_message_size)
576
+ allow(Mongo::Protocol::Reply).to receive(:deserialize).with(socket, max_message_size).and_return(reply)
575
577
  expect(connection.send(:default_mechanism)).to eq(:scram)
576
578
  end
577
579
  end
@@ -590,6 +592,9 @@ describe Mongo::Server::Connection do
590
592
  context 'when the server auth mechanism is scram', if: scram_sha_1_enabled? do
591
593
 
592
594
  it 'uses scram' do
595
+ socket = connection.instance_variable_get(:@socket)
596
+ max_message_size = connection.send(:max_message_size)
597
+ allow(Mongo::Protocol::Reply).to receive(:deserialize).with(socket, max_message_size).and_return(reply)
593
598
  expect(connection.send(:default_mechanism)).to eq(:scram)
594
599
  end
595
600
  end
@@ -597,6 +602,9 @@ describe Mongo::Server::Connection do
597
602
  context 'when the server auth mechanism is the default (mongodb_cr)', unless: scram_sha_1_enabled? do
598
603
 
599
604
  it 'uses mongodb_cr' do
605
+ socket = connection.instance_variable_get(:@socket)
606
+ max_message_size = connection.send(:max_message_size)
607
+ allow(Mongo::Protocol::Reply).to receive(:deserialize).with(socket, max_message_size).and_return(reply)
600
608
  expect(connection.send(:default_mechanism)).to eq(:mongodb_cr)
601
609
  end
602
610
  end
@@ -57,12 +57,12 @@ describe 'Server Selection' do
57
57
 
58
58
  let(:server_selector) do
59
59
  Mongo::ServerSelector.get(:mode => spec.read_preference['mode'],
60
- :tag_sets => spec.read_preference['tag_sets'],
61
- :server_selection_timeout => 1)
60
+ :tag_sets => spec.read_preference['tag_sets'])
62
61
  end
63
62
 
64
63
  before do
65
64
  allow(cluster).to receive(:servers).and_return(candidate_servers)
65
+ allow(cluster).to receive(:options).and_return(server_selection_timeout: 0.2)
66
66
  allow(cluster).to receive(:scan!).and_return(true)
67
67
  end
68
68
 
@@ -85,10 +85,10 @@ describe Mongo::ServerSelector::Nearest do
85
85
  context 'tag sets provided' do
86
86
  let(:tag_sets) { [tag_set] }
87
87
  let(:matching_primary) do
88
- server(:primary, :tags => server_tags, address: default_address)
88
+ make_server(:primary, :tags => server_tags, address: default_address)
89
89
  end
90
90
  let(:matching_secondary) do
91
- server(:secondary, :tags => server_tags, address: default_address)
91
+ make_server(:secondary, :tags => server_tags, address: default_address)
92
92
  end
93
93
 
94
94
  context 'single candidate' do
@@ -173,8 +173,8 @@ describe Mongo::ServerSelector::Nearest do
173
173
  end
174
174
 
175
175
  context 'high latency servers' do
176
- let(:far_primary) { server(:primary, :average_round_trip_time => 113, address: default_address) }
177
- let(:far_secondary) { server(:secondary, :average_round_trip_time => 114, address: default_address) }
176
+ let(:far_primary) { make_server(:primary, :average_round_trip_time => 113, address: default_address) }
177
+ let(:far_secondary) { make_server(:secondary, :average_round_trip_time => 114, address: default_address) }
178
178
 
179
179
  context 'single candidate' do
180
180
 
@@ -81,11 +81,11 @@ describe Mongo::ServerSelector::PrimaryPreferred do
81
81
  let(:tag_sets) { [tag_set] }
82
82
 
83
83
  let(:matching_primary) do
84
- server(:primary, :tags => server_tags, address: default_address )
84
+ make_server(:primary, :tags => server_tags, address: default_address )
85
85
  end
86
86
 
87
87
  let(:matching_secondary) do
88
- server(:secondary, :tags => server_tags, address: default_address )
88
+ make_server(:secondary, :tags => server_tags, address: default_address )
89
89
  end
90
90
 
91
91
  context 'single candidate' do
@@ -171,8 +171,8 @@ describe Mongo::ServerSelector::PrimaryPreferred do
171
171
  end
172
172
 
173
173
  context 'high latency servers' do
174
- let(:far_primary) { server(:primary, :average_round_trip_time => 100, address: default_address) }
175
- let(:far_secondary) { server(:secondary, :average_round_trip_time => 113, address: default_address) }
174
+ let(:far_primary) { make_server(:primary, :average_round_trip_time => 100, address: default_address) }
175
+ let(:far_secondary) { make_server(:secondary, :average_round_trip_time => 113, address: default_address) }
176
176
 
177
177
  context 'single candidate' do
178
178
 
@@ -76,8 +76,8 @@ describe Mongo::ServerSelector::Primary do
76
76
  end
77
77
 
78
78
  context 'high latency candidates' do
79
- let(:far_primary) { server(:primary, :average_round_trip_time => 100, address: default_address) }
80
- let(:far_secondary) { server(:secondary, :average_round_trip_time => 120, address: default_address) }
79
+ let(:far_primary) { make_server(:primary, :average_round_trip_time => 100, address: default_address) }
80
+ let(:far_secondary) { make_server(:secondary, :average_round_trip_time => 120, address: default_address) }
81
81
 
82
82
  context 'single candidate' do
83
83
 
@@ -87,11 +87,11 @@ describe Mongo::ServerSelector::SecondaryPreferred do
87
87
  end
88
88
 
89
89
  let(:matching_primary) do
90
- server(:primary, :tags => server_tags, address: default_address)
90
+ make_server(:primary, :tags => server_tags, address: default_address)
91
91
  end
92
92
 
93
93
  let(:matching_secondary) do
94
- server(:secondary, :tags => server_tags, address: default_address)
94
+ make_server(:secondary, :tags => server_tags, address: default_address)
95
95
  end
96
96
 
97
97
  context 'single candidate' do
@@ -170,8 +170,8 @@ describe Mongo::ServerSelector::SecondaryPreferred do
170
170
  end
171
171
 
172
172
  context 'high latency servers' do
173
- let(:far_primary) { server(:primary, :average_round_trip_time => 100, address: default_address) }
174
- let(:far_secondary) { server(:secondary, :average_round_trip_time => 113, address: default_address) }
173
+ let(:far_primary) { make_server(:primary, :average_round_trip_time => 100, address: default_address) }
174
+ let(:far_secondary) { make_server(:secondary, :average_round_trip_time => 113, address: default_address) }
175
175
 
176
176
  context 'single candidate' do
177
177
 
@@ -76,7 +76,7 @@ describe Mongo::ServerSelector::Secondary do
76
76
 
77
77
  context 'tag sets provided' do
78
78
  let(:tag_sets) { [tag_set] }
79
- let(:matching_secondary) { server(:secondary, :tags => server_tags, address: default_address) }
79
+ let(:matching_secondary) { make_server(:secondary, :tags => server_tags, address: default_address) }
80
80
 
81
81
  context 'single candidate' do
82
82
 
@@ -134,8 +134,8 @@ describe Mongo::ServerSelector::Secondary do
134
134
  end
135
135
 
136
136
  context 'high latency servers' do
137
- let(:far_primary) { server(:primary, :average_round_trip_time => 100, address: default_address) }
138
- let(:far_secondary) { server(:secondary, :average_round_trip_time => 113, address: default_address) }
137
+ let(:far_primary) { make_server(:primary, :average_round_trip_time => 100, address: default_address) }
138
+ let(:far_secondary) { make_server(:secondary, :average_round_trip_time => 113, address: default_address) }
139
139
 
140
140
  context 'single candidate' do
141
141
 
@@ -10,6 +10,17 @@ describe Mongo::ServerSelector do
10
10
  described_class.get(:mode => name, :tag_sets => tag_sets)
11
11
  end
12
12
 
13
+ context 'when a server selector object is passed' do
14
+
15
+ let(:name) do
16
+ :primary
17
+ end
18
+
19
+ it 'returns the object' do
20
+ expect(described_class.get(selector)).to be(selector)
21
+ end
22
+ end
23
+
13
24
  context 'when the mode is primary' do
14
25
 
15
26
  let(:name) do
@@ -134,7 +145,7 @@ describe Mongo::ServerSelector do
134
145
  context 'when #select returns a list of nils' do
135
146
 
136
147
  let(:servers) do
137
- [ server(:primary) ]
148
+ [ make_server(:primary) ]
138
149
  end
139
150
 
140
151
  let(:cluster) do
@@ -143,11 +154,12 @@ describe Mongo::ServerSelector do
143
154
  allow(c).to receive(:single?).and_return(false)
144
155
  allow(c).to receive(:sharded?).and_return(false)
145
156
  allow(c).to receive(:scan!).and_return(true)
157
+ allow(c).to receive(:options).and_return(server_selection_timeout: 0.1)
146
158
  end
147
159
  end
148
160
 
149
161
  let(:read_pref) do
150
- described_class.get(mode: :primary, server_selection_timeout: 0.1).tap do |pref|
162
+ described_class.get(mode: :primary).tap do |pref|
151
163
  allow(pref).to receive(:select).and_return([ nil, nil ])
152
164
  end
153
165
  end
@@ -158,6 +170,72 @@ describe Mongo::ServerSelector do
158
170
  end.to raise_exception(Mongo::Error::NoServerAvailable)
159
171
  end
160
172
  end
173
+
174
+ context 'when the cluster has a server_selection_timeout set' do
175
+
176
+ let(:servers) do
177
+ [ make_server(:secondary), make_server(:primary) ]
178
+ end
179
+
180
+ let(:cluster) do
181
+ double('cluster').tap do |c|
182
+ allow(c).to receive(:servers).and_return(servers)
183
+ allow(c).to receive(:single?).and_return(false)
184
+ allow(c).to receive(:sharded?).and_return(false)
185
+ allow(c).to receive(:scan!).and_return(true)
186
+ allow(c).to receive(:options).and_return(server_selection_timeout: 0)
187
+ end
188
+ end
189
+
190
+ let(:read_pref) do
191
+ described_class.get(mode: :nearest)
192
+ end
193
+
194
+ it 'uses the server_selection_timeout of the cluster' do
195
+ expect{
196
+ read_pref.select_server(cluster)
197
+ }.to raise_exception(Mongo::Error::NoServerAvailable)
198
+ end
199
+ end
200
+
201
+ context 'when the cluster has a local_threshold set' do
202
+
203
+ let(:near_server) do
204
+ make_server(:secondary).tap do |s|
205
+ allow(s).to receive(:connectable?).and_return(true)
206
+ allow(s).to receive(:average_round_trip_time).and_return(100)
207
+ end
208
+ end
209
+
210
+ let(:far_server) do
211
+ make_server(:secondary).tap do |s|
212
+ allow(s).to receive(:connectable?).and_return(true)
213
+ allow(s).to receive(:average_round_trip_time).and_return(200)
214
+ end
215
+ end
216
+
217
+ let(:servers) do
218
+ [ near_server, far_server ]
219
+ end
220
+
221
+ let(:cluster) do
222
+ double('cluster').tap do |c|
223
+ allow(c).to receive(:servers).and_return(servers)
224
+ allow(c).to receive(:single?).and_return(false)
225
+ allow(c).to receive(:sharded?).and_return(false)
226
+ allow(c).to receive(:scan!).and_return(true)
227
+ allow(c).to receive(:options).and_return(local_threshold: 0.050)
228
+ end
229
+ end
230
+
231
+ let(:read_pref) do
232
+ described_class.get(mode: :nearest)
233
+ end
234
+
235
+ it 'uses the local_threshold of the cluster' do
236
+ expect(read_pref.select_server(cluster)).to eq(near_server)
237
+ end
238
+ end
161
239
  end
162
240
 
163
241
  shared_context 'a ServerSelector' do
@@ -174,11 +252,12 @@ describe Mongo::ServerSelector do
174
252
  allow(c).to receive(:single?).and_return(single)
175
253
  allow(c).to receive(:sharded?).and_return(sharded)
176
254
  allow(c).to receive(:scan!).and_return(true)
255
+ allow(c).to receive(:options).and_return(server_selection_timeout: 0.1)
177
256
  end
178
257
  end
179
258
 
180
259
  let(:read_pref) do
181
- described_class.get(mode: :primary, server_selection_timeout: 0.1)
260
+ described_class.get(mode: :primary)
182
261
  end
183
262
 
184
263
  it 'raises a NoServerAvailable error' do
@@ -116,26 +116,6 @@ describe Mongo::Server do
116
116
  end
117
117
  end
118
118
 
119
- describe '#context' do
120
-
121
- let(:server) do
122
- described_class.new(address, cluster, monitoring, listeners, TEST_OPTIONS)
123
- end
124
-
125
- let(:context) do
126
- server.context
127
- end
128
-
129
- after do
130
- expect(cluster).to receive(:pool).with(server).and_return(pool)
131
- server.disconnect!
132
- end
133
-
134
- it 'returns a new server context' do
135
- expect(context.server).to eq(server)
136
- end
137
- end
138
-
139
119
  describe '#disconnect!' do
140
120
 
141
121
  let(:server) do
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014-2015 MongoDB, Inc.
1
+ # Copyright (C) 2014-2016 MongoDB, Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014-2015 MongoDB, Inc.
1
+ # Copyright (C) 2014-2016 MongoDB, Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014-2015 MongoDB, Inc.
1
+ # Copyright (C) 2014-2016 MongoDB, Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014-2015 MongoDB, Inc.
1
+ # Copyright (C) 2014-2016 MongoDB, Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014-2015 MongoDB, Inc.
1
+ # Copyright (C) 2014-2016 MongoDB, Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014-2015 MongoDB, Inc.
1
+ # Copyright (C) 2014-2016 MongoDB, Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.