mongo 2.5.1 → 2.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (275) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +3 -2
  3. data.tar.gz.sig +0 -0
  4. data/Rakefile +1 -1
  5. data/lib/mongo/auth/user/view.rb +4 -4
  6. data/lib/mongo/bulk_write.rb +14 -19
  7. data/lib/mongo/cluster.rb +4 -2
  8. data/lib/mongo/cluster/app_metadata.rb +1 -1
  9. data/lib/mongo/cluster/reapers/cursor_reaper.rb +1 -1
  10. data/lib/mongo/collection.rb +13 -13
  11. data/lib/mongo/collection/view.rb +2 -1
  12. data/lib/mongo/collection/view/aggregation.rb +1 -1
  13. data/lib/mongo/collection/view/change_stream.rb +1 -1
  14. data/lib/mongo/collection/view/iterable.rb +4 -4
  15. data/lib/mongo/collection/view/map_reduce.rb +3 -3
  16. data/lib/mongo/collection/view/readable.rb +26 -20
  17. data/lib/mongo/collection/view/writable.rb +12 -12
  18. data/lib/mongo/cursor.rb +4 -7
  19. data/lib/mongo/database.rb +2 -2
  20. data/lib/mongo/database/view.rb +1 -1
  21. data/lib/mongo/grid/stream/write.rb +1 -1
  22. data/lib/mongo/index/view.rb +3 -3
  23. data/lib/mongo/operation.rb +38 -24
  24. data/lib/mongo/operation/aggregate.rb +53 -0
  25. data/lib/mongo/operation/aggregate/command.rb +59 -0
  26. data/lib/mongo/operation/aggregate/op_msg.rb +54 -0
  27. data/lib/mongo/operation/aggregate/result.rb +87 -0
  28. data/lib/mongo/operation/collections_info.rb +62 -0
  29. data/lib/mongo/operation/collections_info/result.rb +39 -0
  30. data/lib/mongo/operation/{executable.rb → command.rb} +16 -13
  31. data/lib/mongo/operation/command/command.rb +38 -0
  32. data/lib/mongo/operation/command/op_msg.rb +53 -0
  33. data/lib/mongo/operation/count.rb +48 -0
  34. data/lib/mongo/operation/count/command.rb +38 -0
  35. data/lib/mongo/operation/count/op_msg.rb +38 -0
  36. data/lib/mongo/operation/create.rb +48 -0
  37. data/lib/mongo/operation/create/command.rb +38 -0
  38. data/lib/mongo/operation/create/op_msg.rb +37 -0
  39. data/lib/mongo/operation/create_index.rb +48 -0
  40. data/lib/mongo/operation/create_index/command.rb +42 -0
  41. data/lib/mongo/operation/create_index/op_msg.rb +41 -0
  42. data/lib/mongo/operation/create_user.rb +48 -0
  43. data/lib/mongo/operation/{commands → create_user}/command.rb +13 -19
  44. data/lib/mongo/operation/create_user/op_msg.rb +41 -0
  45. data/lib/mongo/operation/delete.rb +38 -0
  46. data/lib/mongo/operation/delete/bulk_result.rb +46 -0
  47. data/lib/mongo/operation/delete/command.rb +59 -0
  48. data/lib/mongo/operation/delete/legacy.rb +69 -0
  49. data/lib/mongo/operation/delete/op_msg.rb +60 -0
  50. data/lib/mongo/operation/{write/delete → delete}/result.rb +18 -16
  51. data/lib/mongo/operation/distinct.rb +48 -0
  52. data/lib/mongo/operation/distinct/command.rb +38 -0
  53. data/lib/mongo/operation/distinct/op_msg.rb +38 -0
  54. data/lib/mongo/operation/drop.rb +48 -0
  55. data/lib/mongo/operation/drop/command.rb +38 -0
  56. data/lib/mongo/operation/{commands/count.rb → drop/op_msg.rb} +16 -6
  57. data/lib/mongo/operation/drop_database.rb +48 -0
  58. data/lib/mongo/operation/drop_database/command.rb +38 -0
  59. data/lib/mongo/operation/drop_database/op_msg.rb +37 -0
  60. data/lib/mongo/operation/drop_index.rb +48 -0
  61. data/lib/mongo/operation/drop_index/command.rb +42 -0
  62. data/lib/mongo/operation/{limited.rb → drop_index/op_msg.rb} +19 -15
  63. data/lib/mongo/operation/explain.rb +52 -0
  64. data/lib/mongo/operation/explain/command.rb +54 -0
  65. data/lib/mongo/operation/explain/legacy.rb +53 -0
  66. data/lib/mongo/operation/explain/op_msg.rb +54 -0
  67. data/lib/mongo/operation/explain/result.rb +50 -0
  68. data/lib/mongo/operation/find.rb +52 -0
  69. data/lib/mongo/operation/find/command.rb +54 -0
  70. data/lib/mongo/operation/find/legacy.rb +55 -0
  71. data/lib/mongo/operation/{read/query → find/legacy}/result.rb +3 -3
  72. data/lib/mongo/operation/find/op_msg.rb +59 -0
  73. data/lib/mongo/operation/find/result.rb +60 -0
  74. data/lib/mongo/operation/{commands/users_info/result.rb → get_more.rb} +20 -22
  75. data/lib/mongo/operation/get_more/command.rb +54 -0
  76. data/lib/mongo/operation/{commands/find.rb → get_more/legacy.rb} +15 -8
  77. data/lib/mongo/operation/get_more/op_msg.rb +58 -0
  78. data/lib/mongo/operation/get_more/result.rb +60 -0
  79. data/lib/mongo/operation/indexes.rb +52 -0
  80. data/lib/mongo/operation/indexes/command.rb +54 -0
  81. data/lib/mongo/operation/indexes/legacy.rb +57 -0
  82. data/lib/mongo/operation/indexes/op_msg.rb +54 -0
  83. data/lib/mongo/operation/indexes/result.rb +97 -0
  84. data/lib/mongo/operation/insert.rb +40 -0
  85. data/lib/mongo/operation/insert/bulk_result.rb +70 -0
  86. data/lib/mongo/operation/insert/command.rb +65 -0
  87. data/lib/mongo/operation/insert/legacy.rb +72 -0
  88. data/lib/mongo/operation/insert/op_msg.rb +61 -0
  89. data/lib/mongo/operation/insert/result.rb +64 -0
  90. data/lib/mongo/operation/kill_cursors.rb +25 -14
  91. data/lib/mongo/operation/{takes_write_concern.rb → kill_cursors/command.rb} +14 -12
  92. data/lib/mongo/operation/kill_cursors/legacy.rb +37 -0
  93. data/lib/mongo/operation/kill_cursors/op_msg.rb +37 -0
  94. data/lib/mongo/operation/list_collections.rb +49 -0
  95. data/lib/mongo/operation/list_collections/command.rb +60 -0
  96. data/lib/mongo/operation/list_collections/op_msg.rb +53 -0
  97. data/lib/mongo/operation/list_collections/result.rb +92 -0
  98. data/lib/mongo/operation/map_reduce.rb +49 -0
  99. data/lib/mongo/operation/map_reduce/command.rb +55 -0
  100. data/lib/mongo/operation/map_reduce/op_msg.rb +54 -0
  101. data/lib/mongo/operation/map_reduce/result.rb +129 -0
  102. data/lib/mongo/operation/parallel_scan.rb +49 -0
  103. data/lib/mongo/operation/parallel_scan/command.rb +67 -0
  104. data/lib/mongo/operation/parallel_scan/op_msg.rb +61 -0
  105. data/lib/mongo/operation/parallel_scan/result.rb +61 -0
  106. data/lib/mongo/operation/remove_user.rb +48 -0
  107. data/lib/mongo/operation/remove_user/command.rb +42 -0
  108. data/lib/mongo/operation/remove_user/op_msg.rb +41 -0
  109. data/lib/mongo/operation/result.rb +3 -1
  110. data/lib/mongo/operation/shared/bypass_document_validation.rb +36 -0
  111. data/lib/mongo/operation/{causally_consistent.rb → shared/causal_consistency_supported.rb} +5 -5
  112. data/lib/mongo/operation/shared/executable.rb +45 -0
  113. data/lib/mongo/operation/shared/idable.rb +64 -0
  114. data/lib/mongo/operation/{commands/distinct.rb → shared/limited.rb} +10 -7
  115. data/lib/mongo/operation/{object_id_generator.rb → shared/object_id_generator.rb} +2 -2
  116. data/lib/mongo/operation/{read_preference.rb → shared/read_preference_supported.rb} +14 -24
  117. data/lib/mongo/operation/shared/result/aggregatable.rb +75 -0
  118. data/lib/mongo/operation/shared/sessions_supported.rb +79 -0
  119. data/lib/mongo/operation/{specifiable.rb → shared/specifiable.rb} +40 -4
  120. data/lib/mongo/operation/shared/write.rb +81 -0
  121. data/lib/mongo/operation/shared/write_concern_supported.rb +39 -0
  122. data/lib/mongo/operation/update.rb +38 -0
  123. data/lib/mongo/operation/update/bulk_result.rb +126 -0
  124. data/lib/mongo/operation/update/command.rb +60 -0
  125. data/lib/mongo/operation/update/legacy.rb +80 -0
  126. data/lib/mongo/operation/{write/update → update/legacy}/result.rb +4 -82
  127. data/lib/mongo/operation/update/op_msg.rb +60 -0
  128. data/lib/mongo/operation/update/result.rb +102 -0
  129. data/lib/mongo/operation/update_user.rb +48 -0
  130. data/lib/mongo/operation/update_user/command.rb +41 -0
  131. data/lib/mongo/operation/update_user/op_msg.rb +41 -0
  132. data/lib/mongo/operation/users_info.rb +49 -0
  133. data/lib/mongo/operation/users_info/command.rb +58 -0
  134. data/lib/mongo/operation/users_info/op_msg.rb +57 -0
  135. data/lib/mongo/operation/{commands/collections_info → users_info}/result.rb +18 -17
  136. data/lib/mongo/server.rb +3 -5
  137. data/lib/mongo/server/connectable.rb +3 -3
  138. data/lib/mongo/server/connection.rb +14 -0
  139. data/lib/mongo/server_selector.rb +1 -1
  140. data/lib/mongo/server_selector/selectable.rb +3 -12
  141. data/lib/mongo/session.rb +13 -1
  142. data/lib/mongo/session/session_pool.rb +1 -1
  143. data/lib/mongo/version.rb +1 -1
  144. data/spec/mongo/client_spec.rb +15 -22
  145. data/spec/mongo/cluster/app_metadata_spec.rb +19 -3
  146. data/spec/mongo/cluster/cursor_reaper_spec.rb +37 -0
  147. data/spec/mongo/cluster_spec.rb +2 -2
  148. data/spec/mongo/collection/view/change_stream_spec.rb +2 -2
  149. data/spec/mongo/collection_spec.rb +105 -14
  150. data/spec/mongo/cursor_spec.rb +11 -11
  151. data/spec/mongo/grid/fs_bucket_spec.rb +5 -0
  152. data/spec/mongo/max_staleness_spec.rb +3 -1
  153. data/spec/mongo/operation/{commands/aggregate → aggregate}/result_spec.rb +1 -1
  154. data/spec/mongo/operation/{commands/aggregate_spec.rb → aggregate_spec.rb} +1 -1
  155. data/spec/mongo/operation/{commands/collections_info_spec.rb → collections_info_spec.rb} +4 -2
  156. data/spec/mongo/operation/{commands/command_spec.rb → command_spec.rb} +1 -1
  157. data/spec/mongo/operation/{write/command/create_index_spec.rb → create_index_spec.rb} +1 -1
  158. data/spec/mongo/operation/{write/create_user_spec.rb → create_user_spec.rb} +1 -1
  159. data/spec/mongo/operation/{write/bulk/delete_spec.rb → delete/bulk_spec.rb} +8 -8
  160. data/spec/mongo/operation/delete/command_spec.rb +111 -0
  161. data/spec/mongo/operation/{write/command/delete_spec.rb → delete/op_msg_spec.rb} +40 -34
  162. data/spec/mongo/operation/{write/delete_spec.rb → delete_spec.rb} +7 -7
  163. data/spec/mongo/operation/{write/command/drop_index_spec.rb → drop_index_spec.rb} +1 -1
  164. data/spec/mongo/operation/{read/query_spec.rb → find/legacy_spec.rb} +2 -2
  165. data/spec/mongo/operation/{read/get_more_spec.rb → get_more_spec.rb} +3 -3
  166. data/spec/mongo/operation/{commands/indexes_spec.rb → indexes_spec.rb} +6 -4
  167. data/spec/mongo/operation/{write/bulk/insert_spec.rb → insert/bulk_spec.rb} +9 -9
  168. data/spec/mongo/operation/insert/command_spec.rb +110 -0
  169. data/spec/mongo/operation/{write/command/insert_spec.rb → insert/op_msg_spec.rb} +51 -41
  170. data/spec/mongo/operation/{write/insert_spec.rb → insert_spec.rb} +2 -2
  171. data/spec/mongo/operation/kill_cursors_spec.rb +2 -2
  172. data/spec/mongo/operation/limited_spec.rb +3 -3
  173. data/spec/mongo/operation/{commands/map_reduce_spec.rb → map_reduce_spec.rb} +1 -1
  174. data/spec/mongo/operation/read_preference_spec.rb +2 -2
  175. data/spec/mongo/operation/{write/command/remove_user_spec.rb → remove_user_spec.rb} +1 -1
  176. data/spec/mongo/operation/{write/bulk/update_spec.rb → update/bulk_spec.rb} +8 -8
  177. data/spec/mongo/operation/update/command_spec.rb +114 -0
  178. data/spec/mongo/operation/{write/command/update_spec.rb → update/op_msg_spec.rb} +49 -40
  179. data/spec/mongo/operation/{write/update_spec.rb → update_spec.rb} +6 -6
  180. data/spec/mongo/operation/{write/command/update_user_spec.rb → update_user_spec.rb} +1 -1
  181. data/spec/mongo/server/connection_spec.rb +0 -22
  182. data/spec/mongo/server_selector_spec.rb +55 -0
  183. data/spec/mongo/server_spec.rb +0 -42
  184. data/spec/mongo/session/session_pool_spec.rb +1 -1
  185. data/spec/mongo/uri/srv_protocol_spec.rb +2 -2
  186. data/spec/mongo/uri_spec.rb +2 -2
  187. data/spec/support/gridfs_tests/delete.yml +4 -38
  188. data/spec/support/gridfs_tests/download.yml +12 -30
  189. data/spec/support/server_selection.rb +1 -1
  190. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Nearest.yml +0 -1
  191. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Nearest_multiple.yml +0 -1
  192. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Nearest_non_matching.yml +0 -1
  193. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/PossiblePrimary.yml +15 -0
  194. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/PossiblePrimaryNearest.yml +15 -0
  195. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Primary.yml +0 -3
  196. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/PrimaryPreferred.yml +0 -1
  197. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/PrimaryPreferred_non_matching.yml +0 -1
  198. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Secondary.yml +0 -1
  199. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/SecondaryPreferred.yml +0 -1
  200. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/SecondaryPreferred_non_matching.yml +0 -1
  201. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Secondary_non_matching.yml +0 -1
  202. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Nearest.yml +0 -1
  203. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Nearest_multiple.yml +0 -1
  204. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Nearest_non_matching.yml +0 -1
  205. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Primary.yml +0 -3
  206. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/PrimaryPreferred.yml +0 -1
  207. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/PrimaryPreferred_non_matching.yml +0 -1
  208. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Secondary.yml +0 -1
  209. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/SecondaryPreferred.yml +0 -1
  210. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/SecondaryPreferred_non_matching.yml +0 -1
  211. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Secondary_non_matching.yml +0 -1
  212. data/spec/support/server_selection/selection/Sharded/read/Nearest.yml +21 -0
  213. data/spec/support/server_selection/selection/Sharded/read/Primary.yml +19 -0
  214. data/spec/support/server_selection/selection/Sharded/read/PrimaryPreferred.yml +21 -0
  215. data/spec/support/server_selection/selection/Sharded/read/Secondary.yml +21 -0
  216. data/spec/support/server_selection/selection/Sharded/read/SecondaryPreferred.yml +0 -5
  217. data/spec/support/server_selection/selection/Single/read/SecondaryPreferred.yml +0 -1
  218. data/spec/support/server_selection/selection/Unknown/read/SecondaryPreferred.yml +0 -1
  219. data/spec/support/shared/session.rb +46 -5
  220. metadata +174 -116
  221. metadata.gz.sig +1 -2
  222. data/lib/mongo/operation/commands.rb +0 -31
  223. data/lib/mongo/operation/commands/aggregate.rb +0 -63
  224. data/lib/mongo/operation/commands/aggregate/result.rb +0 -89
  225. data/lib/mongo/operation/commands/collections_info.rb +0 -71
  226. data/lib/mongo/operation/commands/create.rb +0 -49
  227. data/lib/mongo/operation/commands/drop.rb +0 -49
  228. data/lib/mongo/operation/commands/drop_database.rb +0 -49
  229. data/lib/mongo/operation/commands/explain.rb +0 -27
  230. data/lib/mongo/operation/commands/explain/result.rb +0 -52
  231. data/lib/mongo/operation/commands/find/result.rb +0 -62
  232. data/lib/mongo/operation/commands/get_more.rb +0 -27
  233. data/lib/mongo/operation/commands/get_more/result.rb +0 -62
  234. data/lib/mongo/operation/commands/indexes.rb +0 -73
  235. data/lib/mongo/operation/commands/list_collections.rb +0 -48
  236. data/lib/mongo/operation/commands/list_collections/result.rb +0 -94
  237. data/lib/mongo/operation/commands/list_indexes.rb +0 -48
  238. data/lib/mongo/operation/commands/list_indexes/result.rb +0 -98
  239. data/lib/mongo/operation/commands/map_reduce.rb +0 -65
  240. data/lib/mongo/operation/commands/map_reduce/result.rb +0 -131
  241. data/lib/mongo/operation/commands/parallel_scan.rb +0 -54
  242. data/lib/mongo/operation/commands/parallel_scan/result.rb +0 -64
  243. data/lib/mongo/operation/commands/users_info.rb +0 -52
  244. data/lib/mongo/operation/read.rb +0 -16
  245. data/lib/mongo/operation/read/get_more.rb +0 -52
  246. data/lib/mongo/operation/read/query.rb +0 -55
  247. data/lib/mongo/operation/uses_command_op_msg.rb +0 -78
  248. data/lib/mongo/operation/write.rb +0 -22
  249. data/lib/mongo/operation/write/bulk.rb +0 -20
  250. data/lib/mongo/operation/write/bulk/bulkable.rb +0 -82
  251. data/lib/mongo/operation/write/bulk/delete.rb +0 -71
  252. data/lib/mongo/operation/write/bulk/delete/result.rb +0 -71
  253. data/lib/mongo/operation/write/bulk/insert.rb +0 -96
  254. data/lib/mongo/operation/write/bulk/insert/result.rb +0 -129
  255. data/lib/mongo/operation/write/bulk/legacy_mergable.rb +0 -87
  256. data/lib/mongo/operation/write/bulk/mergable.rb +0 -73
  257. data/lib/mongo/operation/write/bulk/update.rb +0 -81
  258. data/lib/mongo/operation/write/bulk/update/result.rb +0 -196
  259. data/lib/mongo/operation/write/command.rb +0 -23
  260. data/lib/mongo/operation/write/command/create_index.rb +0 -79
  261. data/lib/mongo/operation/write/command/create_user.rb +0 -61
  262. data/lib/mongo/operation/write/command/delete.rb +0 -79
  263. data/lib/mongo/operation/write/command/drop_index.rb +0 -80
  264. data/lib/mongo/operation/write/command/insert.rb +0 -69
  265. data/lib/mongo/operation/write/command/remove_user.rb +0 -60
  266. data/lib/mongo/operation/write/command/update.rb +0 -77
  267. data/lib/mongo/operation/write/command/update_user.rb +0 -61
  268. data/lib/mongo/operation/write/command/writable.rb +0 -70
  269. data/lib/mongo/operation/write/delete.rb +0 -75
  270. data/lib/mongo/operation/write/gle.rb +0 -49
  271. data/lib/mongo/operation/write/idable.rb +0 -63
  272. data/lib/mongo/operation/write/insert.rb +0 -74
  273. data/lib/mongo/operation/write/insert/result.rb +0 -62
  274. data/lib/mongo/operation/write/update.rb +0 -91
  275. data/lib/mongo/operation/write/write_command_enabled.rb +0 -77
@@ -239,11 +239,15 @@ describe Mongo::Cursor do
239
239
  (1..3).map{ |i| { field: "test#{i}" }}
240
240
  end
241
241
 
242
+ let(:cluster) do
243
+ authorized_client.cluster
244
+ end
245
+
242
246
  before do
243
247
  authorized_collection.insert_many(documents)
244
- cursor_reaper.schedule_kill_cursor(cursor.id,
245
- cursor.send(:kill_cursors_op_spec),
246
- cursor.instance_variable_get(:@server))
248
+ cluster.schedule_kill_cursor(cursor.id,
249
+ cursor.send(:kill_cursors_op_spec),
250
+ cursor.instance_variable_get(:@server))
247
251
  end
248
252
 
249
253
  after do
@@ -263,12 +267,8 @@ describe Mongo::Cursor do
263
267
  view.instance_variable_get(:@cursor)
264
268
  end
265
269
 
266
- let(:cursor_reaper) do
267
- authorized_client.cluster.instance_variable_get(:@cursor_reaper)
268
- end
269
-
270
- it 'schedules a kill cursors op', unless: sessions_enabled? do
271
- sleep(Mongo::Cluster::PeriodicExecutor::FREQUENCY)
270
+ it 'schedules a kill cursors op' do
271
+ cluster.instance_variable_get(:@periodic_executor).flush
272
272
  expect {
273
273
  cursor.to_a
274
274
  }.to raise_exception(Mongo::Error::OperationFailure)
@@ -277,7 +277,7 @@ describe Mongo::Cursor do
277
277
  context 'when the cursor is unregistered before the kill cursors operations are executed' do
278
278
 
279
279
  it 'does not send a kill cursors operation for the unregistered cursor' do
280
- cursor_reaper.unregister_cursor(cursor.id)
280
+ cluster.unregister_cursor(cursor.id)
281
281
  expect(cursor.to_a.size).to eq(documents.size)
282
282
  end
283
283
  end
@@ -416,7 +416,7 @@ describe Mongo::Cursor do
416
416
  end
417
417
 
418
418
  let(:reply) do
419
- Mongo::Operation::Read::Query.new(query_spec)
419
+ Mongo::Operation::Find.new(query_spec)
420
420
  end
421
421
 
422
422
  let(:cursor) do
@@ -1101,6 +1101,11 @@ describe Mongo::Grid::FSBucket do
1101
1101
  fs.upload_from_stream(filename, file)
1102
1102
  }.to raise_exception(IOError)
1103
1103
  end
1104
+
1105
+ it 'closes the stream' do
1106
+ begin; fs.upload_from_stream(filename, file); rescue; end
1107
+ expect(stream.closed?).to be(true)
1108
+ end
1104
1109
  end
1105
1110
 
1106
1111
  context 'when stream#abort raises an OperationFailure' do
@@ -67,7 +67,9 @@ describe 'Max Staleness Spec' do
67
67
 
68
68
  let(:in_latency_window) do
69
69
  spec.in_latency_window.collect do |server|
70
- Mongo::Server.new(Mongo::Address.new(server['address']), cluster, monitoring, listeners, options)
70
+ s = Mongo::Server.new(Mongo::Address.new(server['address']), cluster, monitoring, listeners, options)
71
+ s.monitor.stop!
72
+ s
71
73
  end
72
74
  end
73
75
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Mongo::Operation::Commands::Aggregate::Result do
3
+ describe Mongo::Operation::Aggregate::Result do
4
4
 
5
5
  let(:result) do
6
6
  described_class.new(reply)
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Mongo::Operation::Commands::Aggregate do
3
+ describe Mongo::Operation::Aggregate do
4
4
 
5
5
  let(:options) do
6
6
  {}
@@ -1,9 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Mongo::Operation::Commands::CollectionsInfo do
3
+ describe Mongo::Operation::CollectionsInfo do
4
4
 
5
5
  let(:spec) do
6
- { :db_name => TEST_DB }
6
+ { selector: { listCollections: 1 },
7
+ db_name: TEST_DB
8
+ }
7
9
  end
8
10
 
9
11
  let(:names) do
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Mongo::Operation::Commands::Command do
3
+ describe Mongo::Operation::Command do
4
4
 
5
5
  let(:selector) { { :ismaster => 1 } }
6
6
  let(:options) { { :limit => -1 } }
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Mongo::Operation::Write::Command::CreateIndex do
3
+ describe Mongo::Operation::CreateIndex do
4
4
 
5
5
  describe '#execute' do
6
6
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Mongo::Operation::Write::Command::CreateUser do
3
+ describe Mongo::Operation::CreateUser do
4
4
 
5
5
  describe '#execute' do
6
6
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Mongo::Operation::Write::Bulk::Delete do
3
+ describe Mongo::Operation::Delete do
4
4
 
5
5
  let(:documents) do
6
6
  [ { 'q' => { foo: 1 }, 'limit' => 1 } ]
@@ -61,7 +61,7 @@ describe Mongo::Operation::Write::Bulk::Delete do
61
61
  end
62
62
  end
63
63
 
64
- describe '#execute' do
64
+ describe '#bulk_execute' do
65
65
 
66
66
  before do
67
67
  authorized_collection.insert_many([
@@ -92,7 +92,7 @@ describe Mongo::Operation::Write::Bulk::Delete do
92
92
  end
93
93
 
94
94
  it 'deletes the document from the database' do
95
- op.execute(authorized_primary)
95
+ op.bulk_execute(authorized_primary)
96
96
  expect(authorized_collection.find.count).to eq(1)
97
97
  end
98
98
  end
@@ -116,7 +116,7 @@ describe Mongo::Operation::Write::Bulk::Delete do
116
116
  end
117
117
 
118
118
  it 'deletes the documents from the database' do
119
- op.execute(authorized_primary)
119
+ op.bulk_execute(authorized_primary)
120
120
  expect(authorized_collection.find.count).to eq(0)
121
121
  end
122
122
  end
@@ -152,7 +152,7 @@ describe Mongo::Operation::Write::Bulk::Delete do
152
152
  end
153
153
 
154
154
  it 'aborts after first error' do
155
- failing_delete.execute(authorized_primary)
155
+ failing_delete.bulk_execute(authorized_primary)
156
156
  expect(authorized_collection.find.count).to eq(2)
157
157
  end
158
158
  end
@@ -164,7 +164,7 @@ describe Mongo::Operation::Write::Bulk::Delete do
164
164
  end
165
165
 
166
166
  it 'aborts after first error' do
167
- failing_delete.execute(authorized_primary)
167
+ failing_delete.bulk_execute(authorized_primary)
168
168
  expect(authorized_collection.find.count).to eq(2)
169
169
  end
170
170
  end
@@ -201,7 +201,7 @@ describe Mongo::Operation::Write::Bulk::Delete do
201
201
  end
202
202
 
203
203
  it 'does not abort after first error' do
204
- failing_delete.execute(authorized_primary)
204
+ failing_delete.bulk_execute(authorized_primary)
205
205
  expect(authorized_collection.find.count).to eq(1)
206
206
  end
207
207
  end
@@ -213,7 +213,7 @@ describe Mongo::Operation::Write::Bulk::Delete do
213
213
  end
214
214
 
215
215
  it 'does not abort after first error' do
216
- failing_delete.execute(authorized_primary)
216
+ failing_delete.bulk_execute(authorized_primary)
217
217
  expect(authorized_collection.find.count).to eq(1)
218
218
  end
219
219
  end
@@ -0,0 +1,111 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mongo::Operation::Delete::Command do
4
+
5
+ let(:write_concern) do
6
+ Mongo::WriteConcern.get(WRITE_CONCERN)
7
+ end
8
+
9
+ let(:session) { nil }
10
+ let(:deletes) { [{:q => { :foo => 1 }, :limit => 1}] }
11
+ let(:spec) do
12
+ { :deletes => deletes,
13
+ :db_name => authorized_collection.database.name,
14
+ :coll_name => authorized_collection.name,
15
+ :write_concern => write_concern,
16
+ :ordered => true,
17
+ :session => session
18
+ }
19
+ end
20
+
21
+ let(:op) { described_class.new(spec) }
22
+
23
+ describe '#initialize' do
24
+
25
+ context 'spec' do
26
+
27
+ it 'sets the spec' do
28
+ expect(op.spec).to eq(spec)
29
+ end
30
+ end
31
+ end
32
+
33
+ describe '#==' do
34
+
35
+ context 'spec' do
36
+
37
+ context 'when two ops have the same specs' do
38
+ let(:other) { described_class.new(spec) }
39
+
40
+ it 'returns true' do
41
+ expect(op).to eq(other)
42
+ end
43
+ end
44
+
45
+ context 'when two ops have different specs' do
46
+ let(:other_deletes) { [{:q => { :bar => 1 }, :limit => 1}] }
47
+ let(:other_spec) do
48
+ { :deletes => other_deletes,
49
+ :db_name => authorized_collection.database.name,
50
+ :coll_name => authorized_collection.name,
51
+ :write_concern => write_concern,
52
+ :ordered => true
53
+ }
54
+ end
55
+ let(:other) { described_class.new(other_spec) }
56
+
57
+ it 'returns false' do
58
+ expect(op).not_to eq(other)
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ describe 'write concern' do
65
+
66
+ context 'when write concern is not specified' do
67
+
68
+ let(:spec) do
69
+ { :deletes => deletes,
70
+ :db_name => authorized_collection.database.name,
71
+ :coll_name => authorized_collection.name,
72
+ :ordered => true
73
+ }
74
+ end
75
+
76
+ it 'does not include write concern in the selector' do
77
+ expect(op.send(:command, double('server'))[:writeConcern]).to be_nil
78
+ end
79
+ end
80
+
81
+ context 'when write concern is specified' do
82
+
83
+ it 'includes write concern in the selector' do
84
+ expect(op.send(:command, double('server'))[:writeConcern]).to eq(write_concern.options)
85
+ end
86
+ end
87
+ end
88
+
89
+ describe '#message' do
90
+
91
+ context 'when the server does not support OP_MSG' do
92
+
93
+ let(:expected_selector) do
94
+ {
95
+ :delete => authorized_collection.name,
96
+ :deletes => deletes,
97
+ :writeConcern => write_concern.options,
98
+ :ordered => true
99
+ }
100
+ end
101
+
102
+ it 'creates the correct query wire protocol message', unless: op_msg_enabled? do
103
+ expect(Mongo::Protocol::Query).to receive(:new).with(authorized_collection.database.name,
104
+ '$cmd',
105
+ expected_selector,
106
+ { limit: -1 } )
107
+ op.send(:message, authorized_primary)
108
+ end
109
+ end
110
+ end
111
+ end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Mongo::Operation::Write::Command::Delete do
3
+ describe Mongo::Operation::Delete::OpMsg do
4
4
 
5
5
  let(:write_concern) do
6
6
  Mongo::WriteConcern.get(WRITE_CONCERN)
@@ -74,14 +74,14 @@ describe Mongo::Operation::Write::Command::Delete do
74
74
  end
75
75
 
76
76
  it 'does not include write concern in the selector' do
77
- expect(op.send(:selector)[:writeConcern]).to be_nil
77
+ expect(op.send(:command, authorized_primary)[:writeConcern]).to be_nil
78
78
  end
79
79
  end
80
80
 
81
81
  context 'when write concern is specified' do
82
82
 
83
83
  it 'includes write concern in the selector' do
84
- expect(op.send(:selector)[:writeConcern]).to eq(write_concern.options)
84
+ expect(op.send(:command, authorized_primary)[:writeConcern]).to eq(write_concern.options)
85
85
  end
86
86
  end
87
87
  end
@@ -164,28 +164,54 @@ describe Mongo::Operation::Write::Command::Delete do
164
164
  Mongo::WriteConcern.get(w: 0)
165
165
  end
166
166
 
167
- context 'when the topology is replica set or sharded', if: (replica_set? || sharded?) && op_msg_enabled? do
167
+ context 'when the session is implicit' do
168
168
 
169
- let(:expected_global_args) do
170
- global_args.delete(:lsid)
171
- global_args.merge!(Mongo::Operation::CLUSTER_TIME => authorized_client.cluster.cluster_time)
169
+ let(:session) do
170
+ # Use client#get_session so the session is implicit
171
+ authorized_client.send(:get_session)
172
172
  end
173
173
 
174
- it 'creates the correct OP_MSG message' do
175
- authorized_client.command(ping:1)
176
- expect(Mongo::Protocol::Msg).to receive(:new).with([:more_to_come], {}, expected_global_args, expected_payload_1)
177
- op.send(:message, authorized_primary)
174
+ context 'when the topology is replica set or sharded', if: test_sessions? do
175
+
176
+ let(:expected_global_args) do
177
+ global_args.delete(:lsid)
178
+ global_args.merge!(Mongo::Operation::CLUSTER_TIME => authorized_client.cluster.cluster_time)
179
+ end
180
+
181
+ it 'does not send a session id in the command' do
182
+ authorized_client.command(ping:1)
183
+ expect(Mongo::Protocol::Msg).to receive(:new).with([:more_to_come], {}, expected_global_args, expected_payload_1)
184
+ op.send(:message, authorized_primary)
185
+ end
186
+ end
187
+
188
+ context 'when the topology is standalone', if: standalone? && sessions_enabled? do
189
+
190
+ let(:expected_global_args) do
191
+ global_args.delete(:lsid)
192
+ global_args
193
+ end
194
+
195
+ it 'creates the correct OP_MSG message' do
196
+ authorized_client.command(ping:1)
197
+ expect(Mongo::Protocol::Msg).to receive(:new).with([:more_to_come], {}, expected_global_args, expected_payload_1)
198
+ op.send(:message, authorized_primary)
199
+ end
178
200
  end
179
201
  end
180
202
 
181
- context 'when the topology is standalone', if: standalone? && op_msg_enabled? do
203
+ context 'when the session is explicit', if: test_sessions? do
204
+
205
+ let(:session) do
206
+ authorized_client.start_session
207
+ end
182
208
 
183
209
  let(:expected_global_args) do
184
210
  global_args.delete(:lsid)
185
- global_args
211
+ global_args.merge!(Mongo::Operation::CLUSTER_TIME => authorized_client.cluster.cluster_time)
186
212
  end
187
213
 
188
- it 'creates the correct OP_MSG message' do
214
+ it 'does not send a session id in the command' do
189
215
  authorized_client.command(ping:1)
190
216
  expect(Mongo::Protocol::Msg).to receive(:new).with([:more_to_come], {}, expected_global_args, expected_payload_1)
191
217
  op.send(:message, authorized_primary)
@@ -193,25 +219,5 @@ describe Mongo::Operation::Write::Command::Delete do
193
219
  end
194
220
  end
195
221
  end
196
-
197
- context 'when the server does not support OP_MSG' do
198
-
199
- let(:expected_selector) do
200
- {
201
- :delete => authorized_collection.name,
202
- :deletes => deletes,
203
- :writeConcern => write_concern.options,
204
- :ordered => true
205
- }
206
- end
207
-
208
- it 'creates the correct query wire protocol message', unless: op_msg_enabled? do
209
- expect(Mongo::Protocol::Query).to receive(:new).with(authorized_collection.database.name,
210
- '$cmd',
211
- expected_selector,
212
- { limit: -1 } )
213
- op.send(:message, authorized_primary)
214
- end
215
- end
216
222
  end
217
223
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Mongo::Operation::Write::Delete do
3
+ describe Mongo::Operation::Delete do
4
4
 
5
5
  let(:document) do
6
6
  {
@@ -10,7 +10,7 @@ describe Mongo::Operation::Write::Delete do
10
10
  end
11
11
 
12
12
  let(:spec) do
13
- { :delete => document,
13
+ { :deletes => [ document ],
14
14
  :db_name => TEST_DB,
15
15
  :coll_name => TEST_COLL,
16
16
  :write_concern => Mongo::WriteConcern.get(WRITE_CONCERN),
@@ -46,7 +46,7 @@ describe Mongo::Operation::Write::Delete do
46
46
  let(:other_doc) { { :q => { :bar => 1 }, :limit => 1 } }
47
47
 
48
48
  let(:other_spec) do
49
- { :delete => other_doc,
49
+ { :deletes => [ other_doc ],
50
50
  :db_name => TEST_DB,
51
51
  :coll_name => TEST_COLL,
52
52
  :write_concern => Mongo::WriteConcern.get(WRITE_CONCERN),
@@ -79,7 +79,7 @@ describe Mongo::Operation::Write::Delete do
79
79
 
80
80
  let(:delete) do
81
81
  described_class.new({
82
- delete: document,
82
+ deletes: [ document ],
83
83
  db_name: TEST_DB,
84
84
  coll_name: TEST_COLL,
85
85
  write_concern: Mongo::WriteConcern.get(WRITE_CONCERN)
@@ -123,7 +123,7 @@ describe Mongo::Operation::Write::Delete do
123
123
 
124
124
  let(:delete) do
125
125
  described_class.new({
126
- delete: document,
126
+ deletes: [ document ],
127
127
  db_name: TEST_DB,
128
128
  coll_name: TEST_COLL,
129
129
  write_concern: Mongo::WriteConcern.get(WRITE_CONCERN)
@@ -187,7 +187,7 @@ describe Mongo::Operation::Write::Delete do
187
187
 
188
188
  let(:delete) do
189
189
  described_class.new({
190
- delete: document,
190
+ deletes: [ document ],
191
191
  db_name: TEST_DB,
192
192
  coll_name: TEST_COLL,
193
193
  write_concern: Mongo::WriteConcern.get(:w => 0)
@@ -204,7 +204,7 @@ describe Mongo::Operation::Write::Delete do
204
204
  end
205
205
 
206
206
  before do
207
- expect(delete).to receive(:execute_message).and_call_original
207
+ expect(Mongo::Operation::Delete::Legacy).to receive(:new).and_call_original
208
208
  end
209
209
 
210
210
  it 'uses op codes instead of write commands' do