Java Code Examples for com.mongodb.bulk.BulkWriteResult#acknowledged()
The following examples show how to use
com.mongodb.bulk.BulkWriteResult#acknowledged() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BulkWriteResultAckFlowTest.java From ditto with Eclipse Public License 2.0 | 6 votes |
@Test public void allSuccess() { final List<AbstractWriteModel> writeModels = generate5WriteModels(); final BulkWriteResult result = BulkWriteResult.acknowledged(0, 3, 1, 1, List.of(new BulkWriteUpsert(0, new BsonString("upsert 0")), new BulkWriteUpsert(4, new BsonString("upsert 4"))) ); // WHEN final WriteResultAndErrors resultAndErrors = WriteResultAndErrors.success(writeModels, result); final String message = runBulkWriteResultAckFlowAndGetFirstLogEntry(resultAndErrors); // THEN actorSystem.log().info(message); assertThat(message).contains("Acknowledged: Success"); }
Example 2
Source File: BulkWriteResultAckFlowTest.java From ditto with Eclipse Public License 2.0 | 6 votes |
@Test public void partialSuccess() { final List<AbstractWriteModel> writeModels = generate5WriteModels(); final BulkWriteResult result = BulkWriteResult.acknowledged(1, 2, 1, 2, List.of()); final List<BulkWriteError> updateFailure = List.of( new BulkWriteError(11000, "E11000 duplicate key error", new BsonDocument(), 3), new BulkWriteError(50, "E50 operation timed out", new BsonDocument(), 4) ); // WHEN: BulkWriteResultAckFlow receives partial update success with errors, one of which is not duplicate key final WriteResultAndErrors resultAndErrors = WriteResultAndErrors.failure(writeModels, new MongoBulkWriteException(result, updateFailure, null, new ServerAddress())); final String message = runBulkWriteResultAckFlowAndGetFirstLogEntry(resultAndErrors); // THEN: the non-duplicate-key error triggers a failure acknowledgement actorSystem.log().info(message); for (int i = 3; i < 5; ++i) { assertThat(expectUpdateThingResponse(writeModels.get(i).getMetadata().getThingId())) .describedAs("response is failure") .returns(false, UpdateThingResponse::isSuccess); } assertThat(message).contains("Acknowledged: PartialSuccess"); }
Example 3
Source File: BulkWriteResultAckFlowTest.java From ditto with Eclipse Public License 2.0 | 6 votes |
@Test public void errorIndexOutOfBoundError() { final List<AbstractWriteModel> writeModels = generate5WriteModels(); final BulkWriteResult result = BulkWriteResult.acknowledged(1, 2, 1, 2, List.of()); final List<BulkWriteError> updateFailure = List.of( new BulkWriteError(11000, "E11000 duplicate key error", new BsonDocument(), 0), new BulkWriteError(50, "E50 operation timed out", new BsonDocument(), 5) ); // WHEN: BulkWriteResultAckFlow receives partial update success with at least 1 error with out-of-bound index final WriteResultAndErrors resultAndErrors = WriteResultAndErrors.failure(writeModels, new MongoBulkWriteException(result, updateFailure, null, new ServerAddress())); final String message = runBulkWriteResultAckFlowAndGetFirstLogEntry(resultAndErrors); // THEN: All updates are considered failures actorSystem.log().info(message); for (final AbstractWriteModel writeModel : writeModels) { final UpdateThingResponse response = expectUpdateThingResponse(writeModel.getMetadata().getThingId()); assertThat(response).describedAs("response is failure").returns(false, UpdateThingResponse::isSuccess); } assertThat(message).contains("ConsistencyError[indexOutOfBound]"); }