use of com.scalar.db.api.DeleteIfExists in project scalardb by scalar-labs.
the class DeleteStatementHandlerTest method handle_CosmosExceptionWithPreconditionFailed_ShouldThrowNoMutationException.
@Test
public void handle_CosmosExceptionWithPreconditionFailed_ShouldThrowNoMutationException() {
// Arrange
when(container.getScripts()).thenReturn(cosmosScripts);
when(cosmosScripts.getStoredProcedure(anyString())).thenReturn(storedProcedure);
CosmosException toThrow = mock(CosmosException.class);
doThrow(toThrow).when(storedProcedure).execute(anyList(), any(CosmosStoredProcedureRequestOptions.class));
when(toThrow.getSubStatusCode()).thenReturn(CosmosErrorCode.PRECONDITION_FAILED.get());
Delete delete = prepareDelete().withCondition(new DeleteIfExists());
// Act Assert
assertThatThrownBy(() -> handler.handle(delete)).isInstanceOf(NoMutationException.class);
}
use of com.scalar.db.api.DeleteIfExists in project scalardb by scalar-labs.
the class DeleteStatementHandlerTest method handle_DeleteWithConditionCosmosExceptionThrown_ShouldThrowExecutionException.
@Test
public void handle_DeleteWithConditionCosmosExceptionThrown_ShouldThrowExecutionException() {
// Arrange
when(container.getScripts()).thenReturn(cosmosScripts);
when(cosmosScripts.getStoredProcedure(anyString())).thenReturn(storedProcedure);
CosmosException toThrow = mock(CosmosException.class);
doThrow(toThrow).when(storedProcedure).execute(anyList(), any(CosmosStoredProcedureRequestOptions.class));
Delete delete = prepareDelete().withCondition(new DeleteIfExists());
// Act Assert
assertThatThrownBy(() -> handler.handle(delete)).isInstanceOf(ExecutionException.class).hasCause(toThrow);
}
use of com.scalar.db.api.DeleteIfExists in project scalardb by scalar-labs.
the class BatchHandlerTest method handle_TransactionCanceledExceptionWithConditionCheckFailed_ShouldThrowNoMutationException.
@Test
public void handle_TransactionCanceledExceptionWithConditionCheckFailed_ShouldThrowNoMutationException() {
TransactionCanceledException toThrow = TransactionCanceledException.builder().cancellationReasons(CancellationReason.builder().code("ConditionalCheckFailed").build()).build();
doThrow(toThrow).when(client).transactWriteItems(any(TransactWriteItemsRequest.class));
Put put = preparePut().withCondition(new PutIfNotExists());
Delete delete = prepareDelete().withCondition(new DeleteIfExists());
// Act Assert
assertThatThrownBy(() -> handler.handle(Arrays.asList(put, delete))).isInstanceOf(NoMutationException.class);
}
use of com.scalar.db.api.DeleteIfExists in project scalardb by scalar-labs.
the class BatchHandlerTest method handle_TransactionCanceledExceptionWithTransactionConflict_ShouldThrowRetriableExecutionException.
@Test
public void handle_TransactionCanceledExceptionWithTransactionConflict_ShouldThrowRetriableExecutionException() {
TransactionCanceledException toThrow = TransactionCanceledException.builder().cancellationReasons(CancellationReason.builder().code("TransactionConflict").build(), CancellationReason.builder().code("None").build()).build();
doThrow(toThrow).when(client).transactWriteItems(any(TransactWriteItemsRequest.class));
Put put = preparePut().withCondition(new PutIfNotExists());
Delete delete = prepareDelete().withCondition(new DeleteIfExists());
// Act Assert
assertThatThrownBy(() -> handler.handle(Arrays.asList(put, delete))).isInstanceOf(RetriableExecutionException.class);
}
use of com.scalar.db.api.DeleteIfExists in project scalardb by scalar-labs.
the class JdbcDatabaseTest method whenDeleteOperationWithConditionExecutedAndJdbcServiceReturnsFalse_shouldThrowNoMutationException.
@Test
public void whenDeleteOperationWithConditionExecutedAndJdbcServiceReturnsFalse_shouldThrowNoMutationException() throws Exception {
// Arrange
when(jdbcService.delete(any(), any())).thenReturn(false);
// Act Assert
assertThatThrownBy(() -> {
Delete delete = new Delete(new Key("p1", "val1")).withCondition(new DeleteIfExists()).forNamespace(NAMESPACE).forTable(TABLE);
jdbcDatabase.delete(delete);
}).isInstanceOf(NoMutationException.class);
verify(connection).close();
}
Aggregations