@@ -28,11 +28,13 @@ import org.bson.BsonDocument
28
28
import org.bson.BsonInt32
29
29
import org.bson.BsonString
30
30
import org.bson.codecs.BsonDocumentCodec
31
+ import spock.lang.IgnoreIf
31
32
import spock.lang.Shared
32
33
33
34
import static com.mongodb.ClusterFixture.getCredentialList
34
35
import static com.mongodb.ClusterFixture.getPrimary
35
36
import static com.mongodb.ClusterFixture.getSslSettings
37
+ import static com.mongodb.ClusterFixture.isSharded
36
38
import static com.mongodb.WriteConcern.ACKNOWLEDGED
37
39
import static com.mongodb.WriteConcern.UNACKNOWLEDGED
38
40
import static com.mongodb.connection.ProtocolTestHelper.execute
@@ -104,6 +106,7 @@ class WriteProtocolSpecification extends OperationFunctionalSpecification {
104
106
async << [false , true ]
105
107
}
106
108
109
+ @IgnoreIf ({ isSharded() })
107
110
def ' should execute split unacknowledged inserts' () {
108
111
given :
109
112
def binary = new BsonBinary (new byte [15000000 ])
@@ -150,7 +153,9 @@ class WriteProtocolSpecification extends OperationFunctionalSpecification {
150
153
where :
151
154
async << [false , true ]
152
155
}
153
- def ' should ignore write errors on split unacknowledged inserts' () {
156
+
157
+ @IgnoreIf ({ isSharded() })
158
+ def ' should stop writing on write error when an ordered unacknowledged inserts must be split' () {
154
159
given :
155
160
def binary = new BsonBinary (new byte [15000000 ])
156
161
def documentOne = new BsonDocument (' _id' , new BsonInt32 (1 )). append(' b' , binary)
@@ -166,14 +171,40 @@ class WriteProtocolSpecification extends OperationFunctionalSpecification {
166
171
167
172
when :
168
173
execute(protocol, connection, async)
174
+ // force acknowledgement
175
+ new CommandProtocol (getDatabaseName(), new BsonDocument (' ping' , new BsonInt32 (1 )),
176
+ new NoOpFieldNameValidator (), new BsonDocumentCodec ()). execute(connection)
169
177
170
178
then :
171
179
getCollectionHelper(). count() == 1
172
180
173
- cleanup :
181
+ where :
182
+ async << [false , true ]
183
+ }
184
+
185
+ @IgnoreIf ({ isSharded() })
186
+ def ' should continue writing on write error when an unordered unacknowledged inserts must be split' () {
187
+ given :
188
+ def binary = new BsonBinary (new byte [15000000 ])
189
+ def documentOne = new BsonDocument (' _id' , new BsonInt32 (1 )). append(' b' , binary)
190
+ def documentTwo = new BsonDocument (' _id' , new BsonInt32 (2 )). append(' b' , binary)
191
+ def documentThree = new BsonDocument (' _id' , new BsonInt32 (3 )). append(' b' , binary)
192
+ def documentFour = new BsonDocument (' _id' , new BsonInt32 (4 )). append(' b' , binary)
193
+
194
+ def insertRequest = [new InsertRequest (documentOne), new InsertRequest (documentTwo),
195
+ new InsertRequest (documentThree), new InsertRequest (documentFour)]
196
+ def protocol = new InsertProtocol (getNamespace(), false , UNACKNOWLEDGED , insertRequest)
197
+
198
+ getCollectionHelper(). insertDocuments(documentOne)
199
+
200
+ when :
201
+ execute(protocol, connection, async)
174
202
// force acknowledgement
175
- new CommandProtocol (getDatabaseName(), new BsonDocument (' drop' , new BsonString (getCollectionName())),
176
- new NoOpFieldNameValidator (), new BsonDocumentCodec ()). execute(connection)
203
+ new CommandProtocol (getDatabaseName(), new BsonDocument (' ping' , new BsonInt32 (1 )),
204
+ new NoOpFieldNameValidator (), new BsonDocumentCodec ()). execute(connection)
205
+
206
+ then :
207
+ getCollectionHelper(). count() == 4
177
208
178
209
where :
179
210
async << [false , true ]
@@ -203,4 +234,29 @@ class WriteProtocolSpecification extends OperationFunctionalSpecification {
203
234
where :
204
235
async << [false , true ]
205
236
}
237
+
238
+ @IgnoreIf ({ isSharded() })
239
+ def ' should not report write errors on split unacknowledged inserts' () {
240
+ given :
241
+ def binary = new BsonBinary (new byte [15000000 ])
242
+ def documentOne = new BsonDocument (' _id' , new BsonInt32 (1 )). append(' b' , binary)
243
+ def documentTwo = new BsonDocument (' _id' , new BsonInt32 (2 )). append(' b' , binary)
244
+ def documentThree = new BsonDocument (' _id' , new BsonInt32 (3 )). append(' b' , binary)
245
+ def documentFour = new BsonDocument (' _id' , new BsonInt32 (4 )). append(' b' , binary)
246
+
247
+ def insertRequest = [new InsertRequest (documentOne), new InsertRequest (documentTwo),
248
+ new InsertRequest (documentThree), new InsertRequest (documentFour)]
249
+ def protocol = new InsertProtocol (getNamespace(), true , UNACKNOWLEDGED , insertRequest)
250
+
251
+ getCollectionHelper(). insertDocuments(documentOne)
252
+
253
+ when :
254
+ execute(protocol, connection, async)
255
+
256
+ then :
257
+ getCollectionHelper(). count() == 1
258
+
259
+ where :
260
+ async << [false , true ]
261
+ }
206
262
}
0 commit comments