|
24 | 24 | import com.mongodb.MongoNamespace;
|
25 | 25 | import com.mongodb.MongoWriteConcernException;
|
26 | 26 | import com.mongodb.MongoWriteException;
|
| 27 | +import com.mongodb.WriteConcern; |
27 | 28 | import com.mongodb.assertions.Assertions;
|
28 | 29 | import com.mongodb.client.model.CreateCollectionOptions;
|
29 | 30 | import com.mongodb.client.model.Filters;
|
@@ -312,15 +313,6 @@ private void assertBulkWriteHandlesCursorRequiringGetMore(final boolean transact
|
312 | 313 | }
|
313 | 314 | }
|
314 | 315 |
|
315 |
| - private static Stream<Arguments> testBulkWriteErrorsForUnacknowledgedTooLargeInsertArgs() { |
316 |
| - return Stream.of( |
317 |
| - arguments("insert", false), |
318 |
| - arguments("insert", true), |
319 |
| - arguments("replace", false), |
320 |
| - arguments("replace", true) |
321 |
| - ); |
322 |
| - } |
323 |
| - |
324 | 316 | @DisplayName("11. MongoClient.bulkWrite batch splits when the addition of a new namespace exceeds the maximum message size")
|
325 | 317 | @Test
|
326 | 318 | protected void testBulkWriteSplitsWhenExceedingMaxMessageSizeBytesDueToNsInfo() {
|
@@ -442,6 +434,40 @@ protected void testBulkWriteErrorsForAutoEncryption() {
|
442 | 434 | }
|
443 | 435 | }
|
444 | 436 |
|
| 437 | + @DisplayName("15. MongoClient.bulkWrite with unacknowledged write concern uses w:0 for all batches") |
| 438 | + @Test |
| 439 | + protected void testWriteConcernOfAllBatchesWhenUnacknowledgedRequested() { |
| 440 | + assumeTrue(serverVersionAtLeast(8, 0)); |
| 441 | + assumeFalse(isServerlessTest()); |
| 442 | + TestCommandListener commandListener = new TestCommandListener(); |
| 443 | + try (MongoClient client = createMongoClient(getMongoClientSettingsBuilder().addCommandListener(commandListener) |
| 444 | + .writeConcern(WriteConcern.UNACKNOWLEDGED))) { |
| 445 | + MongoDatabase database = droppedDatabase(client); |
| 446 | + database.createCollection(NAMESPACE.getCollectionName()); |
| 447 | + Document helloResponse = database.runCommand(new Document("hello", 1)); |
| 448 | + int maxBsonObjectSize = helloResponse.getInteger("maxBsonObjectSize"); |
| 449 | + int maxMessageSizeBytes = helloResponse.getInteger("maxMessageSizeBytes"); |
| 450 | + ClientNamespacedWriteModel model = ClientNamespacedWriteModel.insertOne( |
| 451 | + NAMESPACE, |
| 452 | + new Document("a", join("", nCopies(maxBsonObjectSize - 500, "b")))); |
| 453 | + int numModels = maxMessageSizeBytes / maxBsonObjectSize + 1; |
| 454 | + ClientBulkWriteResult result = client.bulkWrite(nCopies(numModels, model), clientBulkWriteOptions().ordered(false)); |
| 455 | + assertFalse(result.isAcknowledged()); |
| 456 | + List<CommandStartedEvent> startedBulkWriteCommandEvents = commandListener.getCommandStartedEvents("bulkWrite"); |
| 457 | + assertEquals(2, startedBulkWriteCommandEvents.size()); |
| 458 | + CommandStartedEvent firstEvent = startedBulkWriteCommandEvents.get(0); |
| 459 | + BsonDocument firstCommand = firstEvent.getCommand(); |
| 460 | + CommandStartedEvent secondEvent = startedBulkWriteCommandEvents.get(1); |
| 461 | + BsonDocument secondCommand = secondEvent.getCommand(); |
| 462 | + assertEquals(numModels - 1, firstCommand.getArray("ops").size()); |
| 463 | + assertEquals(1, secondCommand.getArray("ops").size()); |
| 464 | + assertEquals(firstEvent.getOperationId(), secondEvent.getOperationId()); |
| 465 | + assertEquals(0, firstCommand.getDocument("writeConcern").getInt32("w").intValue()); |
| 466 | + assertEquals(0, secondCommand.getDocument("writeConcern").getInt32("w").intValue()); |
| 467 | + assertEquals(numModels, database.getCollection(NAMESPACE.getCollectionName()).countDocuments()); |
| 468 | + } |
| 469 | + } |
| 470 | + |
445 | 471 | /**
|
446 | 472 | * This test is not from the specification.
|
447 | 473 | */
|
|
0 commit comments