From 3c6e77a4a23df74b746653c3cd1ef9da67e7f9fa Mon Sep 17 00:00:00 2001 From: Kaloian Manassiev Date: Thu, 24 Mar 2022 11:02:44 +0000 Subject: SERVER-64520 Get rid of WriteErrorDetail --- src/mongo/s/write_ops/batch_write_op_test.cpp | 104 ++++++++++++-------------- 1 file changed, 49 insertions(+), 55 deletions(-) (limited to 'src/mongo/s/write_ops/batch_write_op_test.cpp') diff --git a/src/mongo/s/write_ops/batch_write_op_test.cpp b/src/mongo/s/write_ops/batch_write_op_test.cpp index 9ed96363de0..36dcb474b78 100644 --- a/src/mongo/s/write_ops/batch_write_op_test.cpp +++ b/src/mongo/s/write_ops/batch_write_op_test.cpp @@ -94,11 +94,7 @@ void buildErrResponse(int code, const std::string& message, BatchedCommandRespon } void addError(int code, const std::string& message, int index, BatchedCommandResponse* response) { - std::unique_ptr error(new WriteErrorDetail); - error->setStatus({ErrorCodes::Error(code), message}); - error->setIndex(index); - - response->addToErrDetails(error.release()); + response->addToErrDetails(write_ops::WriteError(index, {ErrorCodes::Error(code), message})); } void addWCError(BatchedCommandResponse* response) { @@ -187,8 +183,8 @@ TEST_F(BatchWriteOpTest, SingleError) { ASSERT(clientResponse.getOk()); ASSERT_EQUALS(clientResponse.sizeErrDetails(), 1u); - ASSERT_EQUALS(clientResponse.getErrDetailsAt(0)->toStatus().code(), response.toStatus().code()); - ASSERT(clientResponse.getErrDetailsAt(0)->toStatus().reason().find( + ASSERT_EQUALS(clientResponse.getErrDetailsAt(0).getStatus().code(), response.toStatus().code()); + ASSERT(clientResponse.getErrDetailsAt(0).getStatus().reason().find( response.toStatus().reason()) != std::string::npos); ASSERT_EQUALS(clientResponse.getN(), 0); } @@ -811,11 +807,11 @@ TEST_F(BatchWriteOpTest, MultiOpSingleShardErrorUnordered) { ASSERT_EQUALS(clientResponse.getN(), 1); ASSERT(clientResponse.isErrDetailsSet()); ASSERT_EQUALS(clientResponse.sizeErrDetails(), 1u); - ASSERT_EQUALS(clientResponse.getErrDetailsAt(0)->toStatus().code(), - response.getErrDetailsAt(0)->toStatus().code()); - ASSERT_EQUALS(clientResponse.getErrDetailsAt(0)->toStatus().reason(), - response.getErrDetailsAt(0)->toStatus().reason()); - ASSERT_EQUALS(clientResponse.getErrDetailsAt(0)->getIndex(), 1); + ASSERT_EQUALS(clientResponse.getErrDetailsAt(0).getStatus().code(), + response.getErrDetailsAt(0).getStatus().code()); + ASSERT_EQUALS(clientResponse.getErrDetailsAt(0).getStatus().reason(), + response.getErrDetailsAt(0).getStatus().reason()); + ASSERT_EQUALS(clientResponse.getErrDetailsAt(0).getIndex(), 1); } // Multi-op targeting test where two ops go to two separate shards and there's an error on each op @@ -863,16 +859,16 @@ TEST_F(BatchWriteOpTest, MultiOpTwoShardErrorsUnordered) { ASSERT_EQUALS(clientResponse.getN(), 0); ASSERT(clientResponse.isErrDetailsSet()); ASSERT_EQUALS(clientResponse.sizeErrDetails(), 2u); - ASSERT_EQUALS(clientResponse.getErrDetailsAt(0)->toStatus().code(), - response.getErrDetailsAt(0)->toStatus().code()); - ASSERT_EQUALS(clientResponse.getErrDetailsAt(0)->toStatus().reason(), - response.getErrDetailsAt(0)->toStatus().reason()); - ASSERT_EQUALS(clientResponse.getErrDetailsAt(0)->getIndex(), 0); - ASSERT_EQUALS(clientResponse.getErrDetailsAt(1)->toStatus().code(), - response.getErrDetailsAt(0)->toStatus().code()); - ASSERT_EQUALS(clientResponse.getErrDetailsAt(1)->toStatus().reason(), - response.getErrDetailsAt(0)->toStatus().reason()); - ASSERT_EQUALS(clientResponse.getErrDetailsAt(1)->getIndex(), 1); + ASSERT_EQUALS(clientResponse.getErrDetailsAt(0).getStatus().code(), + response.getErrDetailsAt(0).getStatus().code()); + ASSERT_EQUALS(clientResponse.getErrDetailsAt(0).getStatus().reason(), + response.getErrDetailsAt(0).getStatus().reason()); + ASSERT_EQUALS(clientResponse.getErrDetailsAt(0).getIndex(), 0); + ASSERT_EQUALS(clientResponse.getErrDetailsAt(1).getStatus().code(), + response.getErrDetailsAt(0).getStatus().code()); + ASSERT_EQUALS(clientResponse.getErrDetailsAt(1).getStatus().reason(), + response.getErrDetailsAt(0).getStatus().reason()); + ASSERT_EQUALS(clientResponse.getErrDetailsAt(1).getIndex(), 1); } // Multi-op targeting test where each op goes to both shards and there's an error on one op on one @@ -929,11 +925,11 @@ TEST_F(BatchWriteOpTest, MultiOpPartialSingleShardErrorUnordered) { ASSERT_EQUALS(clientResponse.getN(), 3); ASSERT(clientResponse.isErrDetailsSet()); ASSERT_EQUALS(clientResponse.sizeErrDetails(), 1u); - ASSERT_EQUALS(clientResponse.getErrDetailsAt(0)->toStatus().code(), - response.getErrDetailsAt(0)->toStatus().code()); - ASSERT_EQUALS(clientResponse.getErrDetailsAt(0)->toStatus().reason(), - response.getErrDetailsAt(0)->toStatus().reason()); - ASSERT_EQUALS(clientResponse.getErrDetailsAt(0)->getIndex(), 1); + ASSERT_EQUALS(clientResponse.getErrDetailsAt(0).getStatus().code(), + response.getErrDetailsAt(0).getStatus().code()); + ASSERT_EQUALS(clientResponse.getErrDetailsAt(0).getStatus().reason(), + response.getErrDetailsAt(0).getStatus().reason()); + ASSERT_EQUALS(clientResponse.getErrDetailsAt(0).getIndex(), 1); } // Multi-op targeting test where each op goes to both shards and there's an error on one op on one @@ -986,11 +982,11 @@ TEST_F(BatchWriteOpTest, MultiOpPartialSingleShardErrorOrdered) { ASSERT_EQUALS(clientResponse.getN(), 1); ASSERT(clientResponse.isErrDetailsSet()); ASSERT_EQUALS(clientResponse.sizeErrDetails(), 1u); - ASSERT_EQUALS(clientResponse.getErrDetailsAt(0)->toStatus().code(), - response.getErrDetailsAt(0)->toStatus().code()); - ASSERT_EQUALS(clientResponse.getErrDetailsAt(0)->toStatus().reason(), - response.getErrDetailsAt(0)->toStatus().reason()); - ASSERT_EQUALS(clientResponse.getErrDetailsAt(0)->getIndex(), 0); + ASSERT_EQUALS(clientResponse.getErrDetailsAt(0).getStatus().code(), + response.getErrDetailsAt(0).getStatus().code()); + ASSERT_EQUALS(clientResponse.getErrDetailsAt(0).getStatus().reason(), + response.getErrDetailsAt(0).getStatus().reason()); + ASSERT_EQUALS(clientResponse.getErrDetailsAt(0).getIndex(), 0); } // @@ -1148,7 +1144,7 @@ TEST_F(BatchWriteOpTest, MultiOpFailedTargetOrdered) { ASSERT_EQUALS(clientResponse.getN(), 1); ASSERT(clientResponse.isErrDetailsSet()); ASSERT_EQUALS(clientResponse.sizeErrDetails(), 1u); - ASSERT_EQUALS(clientResponse.getErrDetailsAt(0)->getIndex(), 1); + ASSERT_EQUALS(clientResponse.getErrDetailsAt(0).getIndex(), 1); } // Targeting failure on second op in batch op (unordered) @@ -1200,7 +1196,7 @@ TEST_F(BatchWriteOpTest, MultiOpFailedTargetUnordered) { ASSERT_EQUALS(clientResponse.getN(), 2); ASSERT(clientResponse.isErrDetailsSet()); ASSERT_EQUALS(clientResponse.sizeErrDetails(), 1u); - ASSERT_EQUALS(clientResponse.getErrDetailsAt(0)->getIndex(), 1); + ASSERT_EQUALS(clientResponse.getErrDetailsAt(0).getIndex(), 1); } // Batch failure (ok : 0) reported in a multi-op batch (ordered). Expect this gets translated down @@ -1246,8 +1242,8 @@ TEST_F(BatchWriteOpTest, MultiOpFailedBatchOrdered) { ASSERT_EQUALS(clientResponse.getN(), 1); ASSERT(clientResponse.isErrDetailsSet()); ASSERT_EQUALS(clientResponse.sizeErrDetails(), 1u); - ASSERT_EQUALS(clientResponse.getErrDetailsAt(0)->getIndex(), 1); - ASSERT_EQUALS(clientResponse.getErrDetailsAt(0)->toStatus().code(), response.toStatus().code()); + ASSERT_EQUALS(clientResponse.getErrDetailsAt(0).getIndex(), 1); + ASSERT_EQUALS(clientResponse.getErrDetailsAt(0).getStatus().code(), response.toStatus().code()); } // Batch failure (ok : 0) reported in a multi-op batch (unordered). Expect this gets translated down @@ -1300,10 +1296,10 @@ TEST_F(BatchWriteOpTest, MultiOpFailedBatchUnordered) { ASSERT_EQUALS(clientResponse.getN(), 1); ASSERT(clientResponse.isErrDetailsSet()); ASSERT_EQUALS(clientResponse.sizeErrDetails(), 2u); - ASSERT_EQUALS(clientResponse.getErrDetailsAt(0)->getIndex(), 1); - ASSERT_EQUALS(clientResponse.getErrDetailsAt(0)->toStatus().code(), response.toStatus().code()); - ASSERT_EQUALS(clientResponse.getErrDetailsAt(1)->getIndex(), 2); - ASSERT_EQUALS(clientResponse.getErrDetailsAt(1)->toStatus().code(), response.toStatus().code()); + ASSERT_EQUALS(clientResponse.getErrDetailsAt(0).getIndex(), 1); + ASSERT_EQUALS(clientResponse.getErrDetailsAt(0).getStatus().code(), response.toStatus().code()); + ASSERT_EQUALS(clientResponse.getErrDetailsAt(1).getIndex(), 2); + ASSERT_EQUALS(clientResponse.getErrDetailsAt(1).getStatus().code(), response.toStatus().code()); } // Batch aborted (ordered). Expect this gets translated down into write error for first affected @@ -1333,8 +1329,7 @@ TEST_F(BatchWriteOpTest, MultiOpAbortOrdered) { batchOp.noteBatchResponse(*targeted.begin()->second, response, nullptr); ASSERT(!batchOp.isFinished()); - WriteErrorDetail abortError; - abortError.setStatus({ErrorCodes::UnknownError, "mock abort"}); + write_ops::WriteError abortError(0, {ErrorCodes::UnknownError, "mock abort"}); batchOp.abortBatch(abortError); ASSERT(batchOp.isFinished()); @@ -1345,9 +1340,9 @@ TEST_F(BatchWriteOpTest, MultiOpAbortOrdered) { ASSERT_EQUALS(clientResponse.getN(), 1); ASSERT(clientResponse.isErrDetailsSet()); ASSERT_EQUALS(clientResponse.sizeErrDetails(), 1u); - ASSERT_EQUALS(clientResponse.getErrDetailsAt(0)->getIndex(), 1); - ASSERT_EQUALS(clientResponse.getErrDetailsAt(0)->toStatus().code(), - abortError.toStatus().code()); + ASSERT_EQUALS(clientResponse.getErrDetailsAt(0).getIndex(), 1); + ASSERT_EQUALS(clientResponse.getErrDetailsAt(0).getStatus().code(), + abortError.getStatus().code()); } // Batch aborted (unordered). Expect this gets translated down into write errors for all affected @@ -1372,8 +1367,7 @@ TEST_F(BatchWriteOpTest, MultiOpAbortUnordered) { BatchWriteOp batchOp(_opCtx, request); - WriteErrorDetail abortError; - abortError.setStatus({ErrorCodes::UnknownError, "mock abort"}); + write_ops::WriteError abortError(0, {ErrorCodes::UnknownError, "mock abort"}); batchOp.abortBatch(abortError); ASSERT(batchOp.isFinished()); @@ -1384,12 +1378,12 @@ TEST_F(BatchWriteOpTest, MultiOpAbortUnordered) { ASSERT_EQUALS(clientResponse.getN(), 0); ASSERT(clientResponse.isErrDetailsSet()); ASSERT_EQUALS(clientResponse.sizeErrDetails(), 2u); - ASSERT_EQUALS(clientResponse.getErrDetailsAt(0)->getIndex(), 0); - ASSERT_EQUALS(clientResponse.getErrDetailsAt(0)->toStatus().code(), - abortError.toStatus().code()); - ASSERT_EQUALS(clientResponse.getErrDetailsAt(1)->getIndex(), 1); - ASSERT_EQUALS(clientResponse.getErrDetailsAt(1)->toStatus().code(), - abortError.toStatus().code()); + ASSERT_EQUALS(clientResponse.getErrDetailsAt(0).getIndex(), 0); + ASSERT_EQUALS(clientResponse.getErrDetailsAt(0).getStatus().code(), + abortError.getStatus().code()); + ASSERT_EQUALS(clientResponse.getErrDetailsAt(1).getIndex(), 1); + ASSERT_EQUALS(clientResponse.getErrDetailsAt(1).getStatus().code(), + abortError.getStatus().code()); } // Multi-op targeting test where each op goes to both shards and both return a write concern error @@ -1654,7 +1648,7 @@ TEST_F(BatchWriteOpTransactionTest, ThrowTargetingErrorsInTransaction_Delete) { ASSERT(response.isErrDetailsSet()); ASSERT_GT(response.sizeErrDetails(), 0u); - ASSERT_EQ(ErrorCodes::UnknownError, response.getErrDetailsAt(0)->toStatus().code()); + ASSERT_EQ(ErrorCodes::UnknownError, response.getErrDetailsAt(0).getStatus().code()); } TEST_F(BatchWriteOpTransactionTest, ThrowTargetingErrorsInTransaction_Update) { @@ -1683,7 +1677,7 @@ TEST_F(BatchWriteOpTransactionTest, ThrowTargetingErrorsInTransaction_Update) { ASSERT(response.isErrDetailsSet()); ASSERT_GT(response.sizeErrDetails(), 0u); - ASSERT_EQ(ErrorCodes::UnknownError, response.getErrDetailsAt(0)->toStatus().code()); + ASSERT_EQ(ErrorCodes::UnknownError, response.getErrDetailsAt(0).getStatus().code()); } } // namespace -- cgit v1.2.1