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
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Mongo::Operation::Write::Command::UpdateUser do
3
+ describe Mongo::Operation::UpdateUser do
4
4
 
5
5
  describe '#execute' do
6
6
 
@@ -45,28 +45,6 @@ describe Mongo::Server::Connection do
45
45
  server.disconnect!
46
46
  end
47
47
 
48
- describe '#connectable?' do
49
-
50
- context 'when the connection is not connectable' do
51
-
52
- let(:bad_address) do
53
- Mongo::Address.new('127.0.0.1:666')
54
- end
55
-
56
- let(:bad_server) do
57
- Mongo::Server.new(bad_address, cluster, monitoring, listeners, TEST_OPTIONS)
58
- end
59
-
60
- let(:connection) do
61
- described_class.new(bad_server)
62
- end
63
-
64
- it 'returns false' do
65
- expect(connection).to_not be_connectable
66
- end
67
- end
68
- end
69
-
70
48
  describe '#connect!' do
71
49
 
72
50
  context 'when no socket exists' do
@@ -30,6 +30,17 @@ describe Mongo::ServerSelector do
30
30
  it 'returns a read preference of class Primary' do
31
31
  expect(selector).to be_a(Mongo::ServerSelector::Primary)
32
32
  end
33
+
34
+ context 'when the mode is a string' do
35
+
36
+ let(:name) do
37
+ 'primary'
38
+ end
39
+
40
+ it 'returns a read preference of class Primary' do
41
+ expect(selector).to be_a(Mongo::ServerSelector::Primary)
42
+ end
43
+ end
33
44
  end
34
45
 
35
46
  context 'when the mode is primary_preferred' do
@@ -40,6 +51,17 @@ describe Mongo::ServerSelector do
40
51
  it 'returns a read preference of class PrimaryPreferred' do
41
52
  expect(selector).to be_a(Mongo::ServerSelector::PrimaryPreferred)
42
53
  end
54
+
55
+ context 'when the mode is a string' do
56
+
57
+ let(:name) do
58
+ 'primary_preferred'
59
+ end
60
+
61
+ it 'returns a read preference of class PrimaryPreferred' do
62
+ expect(selector).to be_a(Mongo::ServerSelector::PrimaryPreferred)
63
+ end
64
+ end
43
65
  end
44
66
 
45
67
  context 'when the mode is secondary' do
@@ -50,6 +72,17 @@ describe Mongo::ServerSelector do
50
72
  it 'returns a read preference of class Secondary' do
51
73
  expect(selector).to be_a(Mongo::ServerSelector::Secondary)
52
74
  end
75
+
76
+ context 'when the mode is a string' do
77
+
78
+ let(:name) do
79
+ 'secondary'
80
+ end
81
+
82
+ it 'returns a read preference of class Secondary' do
83
+ expect(selector).to be_a(Mongo::ServerSelector::Secondary)
84
+ end
85
+ end
53
86
  end
54
87
 
55
88
  context 'when the mode is secondary_preferred' do
@@ -60,6 +93,17 @@ describe Mongo::ServerSelector do
60
93
  it 'returns a read preference of class SecondaryPreferred' do
61
94
  expect(selector).to be_a(Mongo::ServerSelector::SecondaryPreferred)
62
95
  end
96
+
97
+ context 'when the mode is a string' do
98
+
99
+ let(:name) do
100
+ 'secondary_preferred'
101
+ end
102
+
103
+ it 'returns a read preference of class SecondaryPreferred' do
104
+ expect(selector).to be_a(Mongo::ServerSelector::SecondaryPreferred)
105
+ end
106
+ end
63
107
  end
64
108
 
65
109
  context 'when the mode is nearest' do
@@ -70,6 +114,17 @@ describe Mongo::ServerSelector do
70
114
  it 'returns a read preference of class Nearest' do
71
115
  expect(selector).to be_a(Mongo::ServerSelector::Nearest)
72
116
  end
117
+
118
+ context 'when the mode is a string' do
119
+
120
+ let(:name) do
121
+ 'nearest'
122
+ end
123
+
124
+ it 'returns a read preference of class Nearest' do
125
+ expect(selector).to be_a(Mongo::ServerSelector::Nearest)
126
+ end
127
+ end
73
128
  end
74
129
 
75
130
  context 'when a mode is not provided' do
@@ -81,48 +81,6 @@ describe Mongo::Server do
81
81
  end
82
82
  end
83
83
 
84
- describe '#connectable?' do
85
-
86
- context 'when the server is connectable' do
87
-
88
- let(:server) do
89
- described_class.new(address, cluster, monitoring, listeners, TEST_OPTIONS)
90
- end
91
-
92
- after do
93
- server.disconnect!
94
- end
95
-
96
- before do
97
- expect(cluster).to receive(:pool).with(server).and_return(pool)
98
- end
99
-
100
- it 'returns true' do
101
- expect(server).to be_connectable
102
- end
103
- end
104
-
105
- context 'when the server is not connectable' do
106
-
107
- let(:bad_address) do
108
- Mongo::Address.new('127.0.0.1:666')
109
- end
110
-
111
- let(:server) do
112
- described_class.new(bad_address, cluster, monitoring, listeners, TEST_OPTIONS)
113
- end
114
-
115
- before do
116
- expect(cluster).to receive(:pool).with(server).and_return(pool)
117
- server.disconnect!
118
- end
119
-
120
- it 'returns false' do
121
- expect(server).to_not be_connectable
122
- end
123
- end
124
- end
125
-
126
84
  describe '#disconnect!' do
127
85
 
128
86
  let(:server) do
@@ -206,7 +206,7 @@ describe Mongo::Session::SessionPool, if: test_sessions? do
206
206
  queue << double('session', session_id: id)
207
207
  end
208
208
  pool.instance_variable_set(:@queue, queue)
209
- expect(Mongo::Operation::Commands::Command).to receive(:new).at_least(:twice).and_call_original
209
+ expect(Mongo::Operation::Command).to receive(:new).at_least(:twice).and_call_original
210
210
  end
211
211
 
212
212
  let(:end_sessions_commands) do
@@ -896,10 +896,10 @@ describe Mongo::URI::SRVProtocol do
896
896
  end
897
897
 
898
898
  context 'when an app name option is provided' do
899
- let(:options) { "appname=reports" }
899
+ let(:options) { "appname=srv_test" }
900
900
 
901
901
  it 'sets the app name on the client' do
902
- expect(Mongo::Client.new(string).options[:app_name]).to eq(:reports)
902
+ expect(Mongo::Client.new(string).options[:app_name]).to eq(:srv_test)
903
903
  end
904
904
  end
905
905
 
@@ -962,10 +962,10 @@ describe Mongo::URI do
962
962
  end
963
963
 
964
964
  context 'when an app name option is provided' do
965
- let(:options) { "appname=reports" }
965
+ let(:options) { "appname=uri_test" }
966
966
 
967
967
  it 'sets the app name on the client' do
968
- expect(Mongo::Client.new(string).options[:app_name]).to eq(:reports)
968
+ expect(Mongo::Client.new(string).options[:app_name]).to eq(:uri_test)
969
969
  end
970
970
  end
971
971
 
@@ -40,24 +40,11 @@ data:
40
40
  contentType: "application/octet-stream"
41
41
  aliases: []
42
42
  metadata: {}
43
- -
44
- _id: { "$oid" : "000000000000000000000005" }
45
- length: 8
46
- chunkSize: 4
47
- uploadDate: { "$date" : "1970-01-01T00:00:00.000Z" }
48
- md5: "dd254cdc958e53abaa67da9f797125f5"
49
- filename: "length-8-with-empty-chunk"
50
- contentType: "application/octet-stream"
51
- aliases: []
52
- metadata: {}
53
43
  chunks:
54
44
  - { _id : { "$oid" : "000000000000000000000001" }, files_id : { "$oid" : "000000000000000000000002" }, n : 0, data : { $hex : "" } }
55
45
  - { _id : { "$oid" : "000000000000000000000002" }, files_id : { "$oid" : "000000000000000000000003" }, n : 0, data : { $hex : "1122" } }
56
46
  - { _id : { "$oid" : "000000000000000000000003" }, files_id : { "$oid" : "000000000000000000000004" }, n : 0, data : { $hex : "11223344" } }
57
47
  - { _id : { "$oid" : "000000000000000000000004" }, files_id : { "$oid" : "000000000000000000000004" }, n : 1, data : { $hex : "55667788" } }
58
- - { _id : { "$oid" : "000000000000000000000005" }, files_id : { "$oid" : "000000000000000000000005" }, n : 0, data : { $hex : "11223344" } }
59
- - { _id : { "$oid" : "000000000000000000000006" }, files_id : { "$oid" : "000000000000000000000005" }, n : 1, data : { $hex : "55667788" } }
60
- - { _id : { "$oid" : "000000000000000000000007" }, files_id : { "$oid" : "000000000000000000000005" }, n : 2, data : { $hex : "" } }
61
48
 
62
49
  tests:
63
50
  -
@@ -72,7 +59,7 @@ tests:
72
59
  -
73
60
  { delete : "expected.files", deletes : [
74
61
  { q : { _id : { "$oid" : "000000000000000000000001" } }, limit : 1 }
75
- ] }
62
+ ] }
76
63
  -
77
64
  description: "Delete when length is 0 and there is one extra empty chunk"
78
65
  act:
@@ -107,23 +94,6 @@ tests:
107
94
  { delete : "expected.chunks", deletes : [
108
95
  { q : { files_id : { "$oid" : "000000000000000000000004" } }, limit : 0 }
109
96
  ] }
110
- -
111
- description: "Delete when length is 8 and there is one extra empty chunk"
112
- act:
113
- operation: delete
114
- arguments:
115
- id: { "$oid" : "000000000000000000000005" }
116
- assert:
117
- result: void
118
- data:
119
- -
120
- { delete : "expected.files", deletes : [
121
- { q : { _id : { "$oid" : "000000000000000000000005" } }, limit : 1 }
122
- ] }
123
- -
124
- { delete : "expected.chunks", deletes : [
125
- { q : { files_id : { "$oid" : "000000000000000000000005" } }, limit : 0 }
126
- ] }
127
97
  -
128
98
  description: "Delete when files entry does not exist"
129
99
  act:
@@ -138,20 +108,16 @@ tests:
138
108
  data:
139
109
  -
140
110
  { delete : "fs.files", deletes : [
141
- { q : { _id : { "$oid" : "000000000000000000000005" } }, limit : 1 }
111
+ { q : { _id : { "$oid" : "000000000000000000000004" } }, limit : 1 }
142
112
  ] }
143
113
  act:
144
114
  operation: delete
145
115
  arguments:
146
- id: { "$oid" : "000000000000000000000005" }
116
+ id: { "$oid" : "000000000000000000000004" }
147
117
  assert:
148
118
  error: "FileNotFound"
149
119
  data:
150
120
  -
151
121
  { delete : "expected.files", deletes : [
152
- { q : { _id : { "$oid" : "000000000000000000000005" } }, limit : 1 }
153
- ] }
154
- -
155
- { delete : "expected.chunks", deletes : [
156
- { q : { files_id : { "$oid" : "000000000000000000000005" } }, limit : 0 }
122
+ { q : { _id : { "$oid" : "000000000000000000000004" } }, limit : 1 }
157
123
  ] }
@@ -52,11 +52,10 @@ data:
52
52
  metadata: {}
53
53
  -
54
54
  _id: { "$oid" : "000000000000000000000006" }
55
- length: 12
55
+ length: 2
56
56
  chunkSize: 4
57
57
  uploadDate: { "$date" : "1970-01-01T00:00:00.000Z" }
58
- md5: "6289ac1db331d1c7677a4b7e123178f9"
59
- filename: "length-12-with-empty-chunk"
58
+ md5: "c700ed4fdb1d27055aa3faa2c2432283"
60
59
  contentType: "application/octet-stream"
61
60
  aliases: []
62
61
  metadata: {}
@@ -68,10 +67,7 @@ data:
68
67
  - { _id : { "$oid" : "000000000000000000000005" }, files_id : { "$oid" : "000000000000000000000005" }, n : 0, data : { $hex : "11223344" } }
69
68
  - { _id : { "$oid" : "000000000000000000000006" }, files_id : { "$oid" : "000000000000000000000005" }, n : 1, data : { $hex : "55667788" } }
70
69
  - { _id : { "$oid" : "000000000000000000000007" }, files_id : { "$oid" : "000000000000000000000005" }, n : 2, data : { $hex : "99aa" } }
71
- - { _id : { "$oid" : "000000000000000000000008" }, files_id : { "$oid" : "000000000000000000000006" }, n : 0, data : { $hex : "11223344" } }
72
- - { _id : { "$oid" : "000000000000000000000009" }, files_id : { "$oid" : "000000000000000000000006" }, n : 1, data : { $hex : "55667788" } }
73
- - { _id : { "$oid" : "000000000000000000000010" }, files_id : { "$oid" : "000000000000000000000006" }, n : 2, data : { $hex : "99aabbcc" } }
74
- - { _id : { "$oid" : "000000000000000000000011" }, files_id : { "$oid" : "000000000000000000000006" }, n : 3, data : { $hex : "" } }
70
+ - { _id : { "$oid" : "000000000000000000000008" }, files_id : { "$oid" : "000000000000000000000006" }, n : 0, data : { $hex : "1122" } }
75
71
 
76
72
  tests:
77
73
  -
@@ -119,15 +115,6 @@ tests:
119
115
  options: { }
120
116
  assert:
121
117
  result: { $hex : "112233445566778899aa" }
122
- -
123
- description: "Download when there are three chunks and one extra empty chunk at the end"
124
- act:
125
- operation: download
126
- arguments:
127
- id: { "$oid" : "000000000000000000000006" }
128
- options: { }
129
- assert:
130
- result: { $hex : "112233445566778899aabbcc" }
131
118
  -
132
119
  description: "Download when files entry does not exist"
133
120
  act:
@@ -165,20 +152,6 @@ tests:
165
152
  id: { "$oid" : "000000000000000000000005" }
166
153
  assert:
167
154
  error: "ChunkIsMissing"
168
- -
169
- description: "Download when there is an extra chunk"
170
- arrange:
171
- data:
172
- -
173
- { insert : "fs.chunks", documents : [
174
- { _id : { "$oid" : "000000000000000000000012" }, files_id : { "$oid" : "000000000000000000000004" }, n : 2, data : { $hex : "99" } }
175
- ] }
176
- act:
177
- operation: download
178
- arguments:
179
- id: { "$oid" : "000000000000000000000004" }
180
- assert:
181
- error: "ExtraChunk"
182
155
  -
183
156
  description: "Download when an intermediate chunk is the wrong size"
184
157
  arrange:
@@ -208,3 +181,12 @@ tests:
208
181
  id: { "$oid" : "000000000000000000000005" }
209
182
  assert:
210
183
  error: "ChunkIsWrongSize"
184
+ -
185
+ description: "Download legacy file with no name"
186
+ act:
187
+ operation: download
188
+ arguments:
189
+ id: { "$oid" : "000000000000000000000006" }
190
+ options: { }
191
+ assert:
192
+ result: { $hex : "1122" }
@@ -149,7 +149,7 @@ module Mongo
149
149
  #
150
150
  # @since 2.0.0
151
151
  def candidate_servers
152
- @candidate_servers.select { |s| s['type'] != 'Unknown' }
152
+ @candidate_servers.select { |s| !['Unknown', 'PossiblePrimary'].include?(s['type']) }
153
153
  end
154
154
 
155
155
  private
@@ -1,4 +1,3 @@
1
- ---
2
1
  topology_description:
3
2
  type: ReplicaSetNoPrimary
4
3
  servers:
@@ -1,4 +1,3 @@
1
- ---
2
1
  topology_description:
3
2
  type: ReplicaSetNoPrimary
4
3
  servers:
@@ -1,4 +1,3 @@
1
- ---
2
1
  topology_description:
3
2
  type: ReplicaSetNoPrimary
4
3
  servers:
@@ -0,0 +1,15 @@
1
+ # Test that PossiblePrimary isn't candidate for any read preference mode.
2
+ ---
3
+ topology_description:
4
+ type: ReplicaSetNoPrimary
5
+ servers:
6
+ - address: b:27017
7
+ avg_rtt_ms: 5
8
+ type: PossiblePrimary
9
+ operation: read
10
+ read_preference:
11
+ mode: Primary
12
+ tag_sets:
13
+ - {}
14
+ suitable_servers: []
15
+ in_latency_window: []
@@ -0,0 +1,15 @@
1
+ # Test that PossiblePrimary isn't candidate for any read preference mode.
2
+ ---
3
+ topology_description:
4
+ type: ReplicaSetNoPrimary
5
+ servers:
6
+ - address: b:27017
7
+ avg_rtt_ms: 5
8
+ type: PossiblePrimary
9
+ operation: read
10
+ read_preference:
11
+ mode: Nearest
12
+ tag_sets:
13
+ - {}
14
+ suitable_servers: []
15
+ in_latency_window: []
@@ -1,4 +1,3 @@
1
- ---
2
1
  topology_description:
3
2
  type: ReplicaSetNoPrimary
4
3
  servers:
@@ -15,7 +14,5 @@ topology_description:
15
14
  operation: read
16
15
  read_preference:
17
16
  mode: Primary
18
- tag_sets:
19
- - {}
20
17
  suitable_servers: []
21
18
  in_latency_window: []
@@ -1,4 +1,3 @@
1
- ---
2
1
  topology_description:
3
2
  type: ReplicaSetNoPrimary
4
3
  servers: