mongo 2.0.0.beta → 2.0.0.rc

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/Rakefile +14 -1
  5. data/lib/mongo.rb +2 -1
  6. data/lib/mongo/auth.rb +2 -2
  7. data/lib/mongo/bulk_write.rb +52 -0
  8. data/lib/mongo/bulk_write/bulk_writable.rb +191 -0
  9. data/lib/mongo/bulk_write/deletable.rb +60 -0
  10. data/lib/mongo/bulk_write/insertable.rb +52 -0
  11. data/lib/mongo/bulk_write/ordered_bulk_write.rb +48 -0
  12. data/lib/mongo/bulk_write/replacable.rb +57 -0
  13. data/lib/mongo/bulk_write/unordered_bulk_write.rb +46 -0
  14. data/lib/mongo/bulk_write/updatable.rb +68 -0
  15. data/lib/mongo/client.rb +15 -2
  16. data/lib/mongo/cluster/topology/replica_set.rb +1 -1
  17. data/lib/mongo/cluster/topology/sharded.rb +1 -1
  18. data/lib/mongo/cluster/topology/standalone.rb +1 -1
  19. data/lib/mongo/cluster/topology/unknown.rb +1 -1
  20. data/lib/mongo/collection.rb +1 -1
  21. data/lib/mongo/collection/view/aggregation.rb +1 -1
  22. data/lib/mongo/collection/view/readable.rb +1 -1
  23. data/lib/mongo/collection/view/writable.rb +5 -5
  24. data/lib/mongo/cursor.rb +0 -2
  25. data/lib/mongo/error.rb +4 -3
  26. data/lib/mongo/error/{bulk_write_failure.rb → bulk_write_error.rb} +2 -2
  27. data/lib/mongo/error/invalid_bulk_operation.rb +2 -2
  28. data/lib/mongo/error/invalid_bulk_operation_type.rb +36 -0
  29. data/lib/mongo/error/{empty_batch.rb → multi_index_drop.rb} +5 -10
  30. data/lib/mongo/grid/file/metadata.rb +1 -8
  31. data/lib/mongo/grid/fs.rb +5 -5
  32. data/lib/mongo/index/view.rb +90 -34
  33. data/lib/mongo/operation.rb +0 -1
  34. data/lib/mongo/operation/aggregate.rb +2 -2
  35. data/lib/mongo/operation/aggregate/result.rb +4 -0
  36. data/lib/mongo/operation/bulk_delete/result.rb +2 -127
  37. data/lib/mongo/operation/bulk_insert/result.rb +2 -132
  38. data/lib/mongo/operation/bulk_update/result.rb +2 -142
  39. data/lib/mongo/operation/command.rb +1 -1
  40. data/lib/mongo/operation/executable.rb +3 -3
  41. data/lib/mongo/operation/list_collections/result.rb +0 -2
  42. data/lib/mongo/operation/map_reduce.rb +1 -1
  43. data/lib/mongo/operation/read/collections_info.rb +1 -1
  44. data/lib/mongo/operation/read/get_more.rb +1 -1
  45. data/lib/mongo/operation/read/indexes.rb +1 -1
  46. data/lib/mongo/operation/read/list_collections.rb +1 -1
  47. data/lib/mongo/operation/read/list_indexes.rb +1 -1
  48. data/lib/mongo/operation/read/query.rb +1 -1
  49. data/lib/mongo/operation/specifiable.rb +18 -1
  50. data/lib/mongo/operation/write.rb +2 -0
  51. data/lib/mongo/operation/write/bulk_delete.rb +5 -19
  52. data/lib/mongo/operation/write/bulk_insert.rb +9 -40
  53. data/lib/mongo/operation/write/bulk_mergable.rb +67 -0
  54. data/lib/mongo/operation/write/bulk_update.rb +5 -19
  55. data/lib/mongo/operation/write/command.rb +1 -1
  56. data/lib/mongo/operation/write/command/{ensure_index.rb → create_index.rb} +4 -9
  57. data/lib/mongo/operation/write/command/delete.rb +4 -4
  58. data/lib/mongo/operation/write/command/drop_index.rb +1 -1
  59. data/lib/mongo/operation/write/command/insert.rb +4 -4
  60. data/lib/mongo/operation/write/command/update.rb +4 -4
  61. data/lib/mongo/operation/write/create_index.rb +12 -7
  62. data/lib/mongo/operation/write/create_user.rb +1 -1
  63. data/lib/mongo/operation/write/delete.rb +1 -1
  64. data/lib/mongo/operation/write/drop_index.rb +1 -1
  65. data/lib/mongo/operation/write/insert.rb +1 -1
  66. data/lib/mongo/operation/write/legacy_bulk_mergable.rb +83 -0
  67. data/lib/mongo/operation/write/remove_user.rb +1 -1
  68. data/lib/mongo/operation/write/update.rb +1 -1
  69. data/lib/mongo/{bulk.rb → options.rb} +2 -2
  70. data/lib/mongo/options/mapper.rb +78 -0
  71. data/lib/mongo/server.rb +2 -2
  72. data/lib/mongo/server/connection_pool/queue.rb +1 -1
  73. data/lib/mongo/server/description.rb +1 -1
  74. data/lib/mongo/server/description/inspector.rb +1 -1
  75. data/lib/mongo/server_selector.rb +1 -1
  76. data/lib/mongo/socket/unix.rb +2 -4
  77. data/lib/mongo/version.rb +1 -1
  78. data/lib/mongo/write_concern/acknowledged.rb +15 -1
  79. data/lib/mongo/write_concern/normalizable.rb +0 -22
  80. data/lib/mongo/write_concern/unacknowledged.rb +12 -0
  81. data/spec/mongo/bulk/bulk_write_spec.rb +178 -91
  82. data/spec/mongo/collection/view/aggregation_spec.rb +14 -1
  83. data/spec/mongo/collection/view/explainable_spec.rb +1 -1
  84. data/spec/mongo/collection/view/map_reduce_spec.rb +2 -2
  85. data/spec/mongo/collection/view/readable_spec.rb +2 -2
  86. data/spec/mongo/collection/view/writable_spec.rb +7 -7
  87. data/spec/mongo/collection/view_spec.rb +14 -5
  88. data/spec/mongo/collection_spec.rb +5 -5
  89. data/spec/mongo/cursor_spec.rb +3 -3
  90. data/spec/mongo/database_spec.rb +4 -8
  91. data/spec/mongo/grid/fs_spec.rb +8 -8
  92. data/spec/mongo/index/view_spec.rb +139 -35
  93. data/spec/mongo/operation/aggregate_spec.rb +14 -22
  94. data/spec/mongo/operation/command_spec.rb +8 -16
  95. data/spec/mongo/operation/map_reduce_spec.rb +1 -1
  96. data/spec/mongo/operation/read/indexes_spec.rb +2 -2
  97. data/spec/mongo/operation/write/bulk_delete_spec.rb +1 -239
  98. data/spec/mongo/operation/write/bulk_insert_spec.rb +3 -234
  99. data/spec/mongo/operation/write/bulk_update_spec.rb +1 -289
  100. data/spec/mongo/operation/write/command/delete_spec.rb +0 -13
  101. data/spec/mongo/operation/write/command/insert_spec.rb +0 -14
  102. data/spec/mongo/operation/write/command/update_spec.rb +0 -14
  103. data/spec/mongo/operation/write/{ensure_index_spec.rb → create_index_spec.rb} +8 -26
  104. data/spec/mongo/operation/write/delete_spec.rb +1 -1
  105. data/spec/mongo/operation/write/drop_index_spec.rb +1 -1
  106. data/spec/mongo/operation/write/insert_spec.rb +3 -3
  107. data/spec/mongo/operation/write/update_spec.rb +1 -1
  108. data/spec/mongo/server_selection_spec.rb +2 -2
  109. data/spec/support/authorization.rb +4 -2
  110. data/spec/support/server_selection.rb +25 -8
  111. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Nearest.yml +4 -10
  112. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Nearest_non_matching.yml +6 -12
  113. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Primary.yml +4 -6
  114. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/PrimaryPreferred.yml +4 -10
  115. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/PrimaryPreferred_non_matching.yml +6 -12
  116. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Secondary.yml +4 -10
  117. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/SecondaryPreferred.yml +4 -10
  118. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/SecondaryPreferred_non_matching.yml +6 -12
  119. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Secondary_non_matching.yml +6 -12
  120. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Nearest.yml +9 -17
  121. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Nearest_non_matching.yml +9 -17
  122. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Primary.yml +6 -10
  123. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/PrimaryPreferred.yml +11 -21
  124. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/PrimaryPreferred_non_matching.yml +11 -18
  125. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Secondary.yml +31 -0
  126. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/SecondaryPreferred.yml +31 -0
  127. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/SecondaryPreferred_non_matching.yml +29 -0
  128. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Secondary_non_matching.yml +26 -0
  129. data/spec/support/server_selection/selection/Sharded/read/SecondaryPreferred.yml +4 -10
  130. data/spec/support/server_selection/selection/Single/read/SecondaryPreferred.yml +2 -6
  131. data/spec/support/server_selection/selection/Unknown/read/SecondaryPreferred.yml +0 -2
  132. data/spec/support/shared/bulk_write.rb +109 -72
  133. metadata +29 -10
  134. metadata.gz.sig +0 -0
  135. data/lib/mongo/bulk/bulk_write.rb +0 -307
  136. data/lib/mongo/operation/batchable.rb +0 -103
@@ -79,7 +79,7 @@ module Mongo
79
79
  # @example Get the server context.
80
80
  # server.context
81
81
  #
82
- # @return [ Mongo::Server::Context ] The server context.
82
+ # @return [ Mongo::Server::Context ] context The server context.
83
83
  #
84
84
  # @since 2.0.0
85
85
  def context
@@ -149,7 +149,7 @@ module Mongo
149
149
  # @example Are the provided tags a subset of the server's tags.
150
150
  # server.matches_tag_set?({ 'rack' => 'a', 'dc' => 'nyc' })
151
151
  #
152
- # @param [ Hash ] The tag set to compare to the server's tags.
152
+ # @param [ Hash ] tag_set The tag set to compare to the server's tags.
153
153
  #
154
154
  # @return [ true, false ] If the provided tags are a subset of the server's tags.
155
155
  #
@@ -84,7 +84,7 @@ module Mongo
84
84
  # @example Create the queue.
85
85
  # Mongo::Pool::Queue.new(max_pool_size: 5) { Connection.new }
86
86
  #
87
- # @param [ Integer ] size The initial size of the queue.
87
+ # @param [ Hash ] options The options.
88
88
  #
89
89
  # @option options [ Integer ] :max_pool_size The maximum size.
90
90
  # @option options [ Integer ] :min_pool_size The minimum size.
@@ -202,7 +202,7 @@ module Mongo
202
202
  # @example Instantiate the new description.
203
203
  # Description.new(address, { 'ismaster' => true }, 0.5)
204
204
  #
205
- # @param [ Address ] addressThe server address.
205
+ # @param [ Address ] address The server address.
206
206
  # @param [ Hash ] config The result of the ismaster command.
207
207
  # @param [ Float ] average_round_trip_time The moving average time (ms) the ismaster
208
208
  # call took to complete.
@@ -45,7 +45,7 @@ module Mongo
45
45
  # @example Create the new inspector.
46
46
  # Inspector.new(listeners)
47
47
  #
48
- # @param [ Event::Listeners ] The event listeners.
48
+ # @param [ Event::Listeners ] listeners The event listeners.
49
49
  #
50
50
  # @since 2.0.0
51
51
  def initialize(listeners)
@@ -69,7 +69,7 @@ module Mongo
69
69
  # @example Instantiate the exception.
70
70
  # Mongo::ServerSelector::NoServerAvailable.new(server_selector)
71
71
  #
72
- # @params [ Hash ] server_selector The server preference that could not be
72
+ # @param [ Hash ] server_selector The server preference that could not be
73
73
  # satisfied.
74
74
  #
75
75
  # @since 2.0.0
@@ -47,11 +47,9 @@ module Mongo
47
47
  # Initializes a new Unix socket.
48
48
  #
49
49
  # @example Create the Unix socket.
50
- # Unix.new('::1', 27017, 30)
51
- # Unix.new('127.0.0.1', 27017, 30)
50
+ # Unix.new('/path/to.sock', 27017, 30)
52
51
  #
53
- # @param [ String ] host The hostname or IP address.
54
- # @param [ Integer ] port The port number.
52
+ # @param [ String ] path The path.
55
53
  # @param [ Float ] timeout The socket timeout value.
56
54
  # @param [ Integer ] family The socket family.
57
55
  #
@@ -17,5 +17,5 @@ module Mongo
17
17
  # The current version of the driver.
18
18
  #
19
19
  # @since 2.0.0
20
- VERSION = '2.0.0.beta'.freeze
20
+ VERSION = '2.0.0.rc'.freeze
21
21
  end
@@ -31,7 +31,21 @@ module Mongo
31
31
  #
32
32
  # @since 2.0.0
33
33
  def get_last_error
34
- @get_last_error ||= { GET_LAST_ERROR => 1 }.merge(normalize(options))
34
+ @get_last_error ||= { GET_LAST_ERROR => 1 }.merge(
35
+ Options::Mapper.transform_values_to_strings(options)
36
+ )
37
+ end
38
+
39
+ # Get a human-readable string representation of an acknowledged write concern.
40
+ #
41
+ # @example Inspect the write concern.
42
+ # write_concern.inspect
43
+ #
44
+ # @return [ String ] A string representation of an acknowledged write concern.
45
+ #
46
+ # @since 2.0.0
47
+ def inspect
48
+ "<Mongo::WriteConcern::Acknowledged:0x#{object_id} options=#{options}>"
35
49
  end
36
50
  end
37
51
  end
@@ -46,28 +46,6 @@ module Mongo
46
46
  def initialize(options)
47
47
  @options = options.freeze
48
48
  end
49
-
50
- private
51
-
52
- # Normalizes symbol option values into strings, since symbol will raise
53
- # an error on the server side with the gle.
54
- #
55
- # @api private
56
- #
57
- # @example Normalize the options.
58
- # mode.normalize(:w => :majority)
59
- #
60
- # @param [ Hash ] options The options to normalize.
61
- #
62
- # @return [ Hash ] The hash with normalized values.
63
- #
64
- # @since 2.0.0
65
- def normalize(options)
66
- options.reduce({}) do |options, (key, value)|
67
- options[key] = value.is_a?(Symbol) ? value.to_s : value
68
- options
69
- end
70
- end
71
49
  end
72
50
  end
73
51
  end
@@ -38,6 +38,18 @@ module Mongo
38
38
  def get_last_error
39
39
  NOOP
40
40
  end
41
+
42
+ # Get a human-readable string representation of an unacknowledged write concern.
43
+ #
44
+ # @example Inspect the write concern.
45
+ # write_concern.inspect
46
+ #
47
+ # @return [ String ] A string representation of an unacknowledged write concern.
48
+ #
49
+ # @since 2.0.0
50
+ def inspect
51
+ "<Mongo::WriteConcern::Unacknowledged:0x#{object_id} options=#{options}>"
52
+ end
41
53
  end
42
54
  end
43
55
  end
@@ -3,138 +3,229 @@ require 'spec_helper'
3
3
  describe Mongo::BulkWrite do
4
4
 
5
5
  before do
6
- authorized_collection.find.remove_many
6
+ authorized_collection.find.delete_many
7
7
  end
8
8
 
9
- describe '#execute' do
9
+ after do
10
+ authorized_collection.find.delete_many
11
+ end
12
+
13
+ let(:bulk) do
14
+ described_class.get(authorized_collection, operations, options)
15
+ end
16
+
17
+ describe '#get' do
10
18
 
11
- let(:bulk) do
12
- described_class.new(operations, options, authorized_collection)
19
+ let(:operations) do
20
+ [{ insert_one: { _id: 0 } }]
13
21
  end
14
22
 
15
- context 'when the operations are ordered' do
23
+ context 'When an ordered bulk write object is created' do
16
24
 
17
25
  let(:options) do
18
26
  { ordered: true }
19
27
  end
20
28
 
21
- it_behaves_like 'a bulk write object'
29
+ it 'returns an OrderedBulkWrite object' do
30
+ expect(bulk).to be_a(Mongo::BulkWrite::OrderedBulkWrite)
31
+ end
32
+ end
22
33
 
23
- context 'when the insert batch requires splitting' do
34
+ context 'When an unordered bulk write object is created' do
24
35
 
25
- context 'when the operations exceed the max batch size' do
36
+ let(:options) do
37
+ { ordered: false }
38
+ end
26
39
 
27
- let(:error) do
28
- begin
29
- bulk.execute
30
- rescue => ex
31
- ex
32
- end
33
- end
40
+ it 'returns an UnorderedBulkWrite object' do
41
+ expect(bulk).to be_a(Mongo::BulkWrite::UnorderedBulkWrite)
42
+ end
43
+ end
34
44
 
35
- let(:operations) do
36
- [].tap do |ops|
37
- 3000.times do |i|
38
- ops << { insert_one: { _id: i } }
39
- end
40
- ops << { insert_one: { _id: 0 } }
41
- ops << { insert_one: { _id: 3001 } }
42
- end
43
- end
45
+ context 'When ordered is not specified in options' do
44
46
 
45
- it 'raises an error' do
46
- expect(error).to be_a(Mongo::Error::BulkWriteFailure)
47
- end
47
+ let(:options) do
48
+ { }
49
+ end
50
+
51
+ it 'returns an OrderedBulkWrite object' do
52
+ expect(bulk).to be_a(Mongo::BulkWrite::OrderedBulkWrite)
53
+ end
54
+ end
55
+ end
56
+
57
+ describe 'Ordered bulk write' do
48
58
 
49
- it 'halts execution after first error and reports correct index' do
50
- expect(error.result['writeErrors'].first['index']).to eq(3000)
51
- expect(authorized_collection.find.count).to eq(3000)
59
+ let(:options) do
60
+ { ordered: true }
61
+ end
62
+
63
+ it_behaves_like 'a bulk write object'
64
+
65
+ context 'when the batch requires splitting' do
66
+
67
+ context 'when the operations are the same type' do
68
+
69
+ let(:error) do
70
+ begin
71
+ bulk.execute
72
+ rescue => ex
73
+ ex
74
+ end
75
+ end
76
+
77
+ let(:operations) do
78
+ [].tap do |ops|
79
+ 3000.times do |i|
80
+ ops << { insert_one: { _id: i } }
81
+ end
82
+ ops << { insert_one: { _id: 0 } }
83
+ ops << { insert_one: { _id: 3001 } }
52
84
  end
53
85
  end
86
+
87
+ it 'raises a BulkWriteError' do
88
+ expect(error).to be_a(Mongo::Error::BulkWriteError)
89
+ end
54
90
 
55
- context 'when the operations exceed the max bson size' do
91
+ it 'halts execution after first error and reports correct index' do
92
+ expect(error.result[:write_errors].first['index']).to eq(3000)
93
+ expect(authorized_collection.find.count).to eq(3000)
94
+ end
95
+ end
56
96
 
57
- let(:error) do
58
- begin
59
- bulk.execute
60
- rescue => ex
61
- ex
62
- end
97
+ context 'when operations are mixed types' do
98
+
99
+ let(:error) do
100
+ begin
101
+ bulk.execute
102
+ rescue => ex
103
+ ex
63
104
  end
105
+ end
64
106
 
65
- let(:operations) do
66
- [].tap do |ops|
67
- 6.times do |i|
68
- ops << { insert_one: { _id: i, x: 'y'*4000000 } }
69
- end
70
- ops << { insert_one: { _id: 0 } }
71
- ops << { insert_one: { _id: 100 } }
107
+ let(:operations) do
108
+ [].tap do |ops|
109
+ 2000.times do |i|
110
+ ops << { insert_one: { _id: i } }
72
111
  end
112
+ ops << { delete_one: { _id: 0 } }
113
+ ops << { insert_one: { _id: 1 } }
114
+ ops << { insert_one: { _id: 2000 } }
73
115
  end
116
+ end
74
117
 
75
- it 'raises an error' do
76
- expect(error).to be_a(Mongo::Error::BulkWriteFailure)
77
- end
118
+ it 'raises a BulkWriteError error' do
119
+ expect(error).to be_a(Mongo::Error::BulkWriteError)
120
+ end
78
121
 
79
- it 'splits messages into multiple messages' do
80
- error
81
- expect(authorized_collection.find.count).to eq(6)
82
- end
122
+ it 'halts execution after first error and reports correct index' do
123
+ expect(error.result[:write_errors].first['index']).to eq(2001)
124
+ expect(authorized_collection.find.count).to eq(1999)
83
125
  end
84
126
  end
85
- end
86
127
 
87
- context 'when the operations are unordered' do
128
+ context 'when the operations exceed the max bson size' do
88
129
 
89
- before do
90
- authorized_collection.find.remove_many
130
+ let(:error) do
131
+ begin
132
+ bulk.execute
133
+ rescue => ex
134
+ ex
135
+ end
136
+ end
137
+
138
+ let(:operations) do
139
+ [].tap do |ops|
140
+ 6.times do |i|
141
+ ops << { insert_one: { _id: i, x: 'y'*4000000 } }
142
+ end
143
+ ops << { insert_one: { _id: 0 } }
144
+ ops << { insert_one: { _id: 100 } }
145
+ end
146
+ end
147
+
148
+ it 'raises a BulkWriteError error' do
149
+ expect(error).to be_a(Mongo::Error::BulkWriteError)
150
+ end
151
+
152
+ it 'splits messages into multiple messages' do
153
+ error
154
+ expect(authorized_collection.find.count).to eq(6)
155
+ end
91
156
  end
157
+ end
158
+ end
92
159
 
93
- let(:options) do
94
- { ordered: false }
95
- end
160
+ describe 'Unordered bulk write' do
96
161
 
97
- let(:bulk) do
98
- described_class.new(operations, options, authorized_collection)
99
- end
162
+ let(:options) do
163
+ { ordered: false }
164
+ end
100
165
 
101
- it_behaves_like 'a bulk write object'
166
+ it_behaves_like 'a bulk write object'
102
167
 
103
- context 'when the insert batch requires splitting' do
168
+ context 'when the operations exceed the max batch size' do
104
169
 
105
- context 'when the operations exceed the max batch size' do
170
+ context 'when operations are all the same type' do
106
171
 
107
- let(:error) do
108
- begin
109
- bulk.execute
110
- rescue => ex
111
- ex
112
- end
172
+ let(:error) do
173
+ begin
174
+ bulk.execute
175
+ rescue => ex
176
+ ex
113
177
  end
178
+ end
114
179
 
115
- let(:operations) do
116
- [].tap do |ops|
117
- 3000.times do |i|
118
- ops << { insert_one: { _id: i } }
119
- end
120
- ops << { insert_one: { _id: 0 } }
121
- ops << { insert_one: { _id: 3001 } }
180
+ let(:operations) do
181
+ [].tap do |ops|
182
+ 3000.times do |i|
183
+ ops << { insert_one: { _id: i } }
122
184
  end
185
+ ops << { insert_one: { _id: 0 } }
186
+ ops << { insert_one: { _id: 3001 } }
123
187
  end
188
+ end
124
189
 
125
- after do
126
- authorized_collection.find.remove_many
127
- end
190
+ it 'raises a BulkWriteError error' do
191
+ expect(error).to be_a(Mongo::Error::BulkWriteError)
192
+ end
128
193
 
129
- it 'raises an error' do
130
- expect(error).to be_a(Mongo::Error::BulkWriteFailure)
194
+ it 'does not halt execution after first error' do
195
+ expect(error.result[:write_errors].first['index']).to eq(3000)
196
+ expect(authorized_collection.find.count).to eq(3001)
197
+ end
198
+ end
199
+
200
+ context 'when operations are mixed types' do
201
+
202
+ let(:error) do
203
+ begin
204
+ bulk.execute
205
+ rescue => ex
206
+ ex
131
207
  end
208
+ end
132
209
 
133
- it 'does not halt execution after first error' do
134
- expect(error.result['writeErrors'].first['index']).to eq(3000)
135
- expect(authorized_collection.find.count).to eq(3001)
210
+ let(:operations) do
211
+ [].tap do |ops|
212
+ 2000.times do |i|
213
+ ops << { insert_one: { _id: i } }
214
+ end
215
+ ops << { delete_one: { _id: 0 } }
216
+ ops << { insert_one: { _id: 1 } }
217
+ ops << { insert_one: { _id: 2000 } }
136
218
  end
137
219
  end
220
+
221
+ it 'raises a BulkWriteError error' do
222
+ expect(error).to be_a(Mongo::Error::BulkWriteError)
223
+ end
224
+
225
+ it 'does not halt execution after first error' do
226
+ expect(error.result[:write_errors].first['index']).to eq(2001)
227
+ expect(authorized_collection.find.count).to eq(2000)
228
+ end
138
229
  end
139
230
 
140
231
  context 'when the operations exceed the max bson size' do
@@ -157,12 +248,8 @@ describe Mongo::BulkWrite do
157
248
  end
158
249
  end
159
250
 
160
- after do
161
- authorized_collection.find.remove_many
162
- end
163
-
164
- it 'raises an error' do
165
- expect(error).to be_a(Mongo::Error::BulkWriteFailure)
251
+ it 'raises a BulkWriteError error' do
252
+ expect(error).to be_a(Mongo::Error::BulkWriteError)
166
253
  end
167
254
 
168
255
  it 'splits messages into multiple messages' do