@@ -28,11 +28,13 @@ import org.bson.BsonDocument
2828import org.bson.BsonInt32
2929import org.bson.BsonString
3030import org.bson.codecs.BsonDocumentCodec
31+ import spock.lang.IgnoreIf
3132import spock.lang.Shared
3233
3334import static com.mongodb.ClusterFixture.getCredentialList
3435import static com.mongodb.ClusterFixture.getPrimary
3536import static com.mongodb.ClusterFixture.getSslSettings
37+ import static com.mongodb.ClusterFixture.isSharded
3638import static com.mongodb.WriteConcern.ACKNOWLEDGED
3739import static com.mongodb.WriteConcern.UNACKNOWLEDGED
3840import static com.mongodb.connection.ProtocolTestHelper.execute
@@ -104,6 +106,7 @@ class WriteProtocolSpecification extends OperationFunctionalSpecification {
104106 async << [false , true ]
105107 }
106108
109+ @IgnoreIf ({ isSharded() })
107110 def ' should execute split unacknowledged inserts' () {
108111 given :
109112 def binary = new BsonBinary (new byte [15000000 ])
@@ -150,7 +153,9 @@ class WriteProtocolSpecification extends OperationFunctionalSpecification {
150153 where :
151154 async << [false , true ]
152155 }
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' () {
154159 given :
155160 def binary = new BsonBinary (new byte [15000000 ])
156161 def documentOne = new BsonDocument (' _id' , new BsonInt32 (1 )). append(' b' , binary)
@@ -166,14 +171,40 @@ class WriteProtocolSpecification extends OperationFunctionalSpecification {
166171
167172 when :
168173 execute(protocol, connection, async)
174+ // force acknowledgement
175+ new CommandProtocol (getDatabaseName(), new BsonDocument (' ping' , new BsonInt32 (1 )),
176+ new NoOpFieldNameValidator (), new BsonDocumentCodec ()). execute(connection)
169177
170178 then :
171179 getCollectionHelper(). count() == 1
172180
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)
174202 // 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
177208
178209 where :
179210 async << [false , true ]
@@ -203,4 +234,29 @@ class WriteProtocolSpecification extends OperationFunctionalSpecification {
203234 where :
204235 async << [false , true ]
205236 }
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+ }
206262}
0 commit comments