use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class DeleteStatementHandlerTest method prepareDelete.
private Delete prepareDelete() {
Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1);
Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2);
id = ANY_TEXT_1 + ":" + ANY_TEXT_2;
cosmosPartitionKey = new PartitionKey(ANY_TEXT_1);
return new Delete(partitionKey, clusteringKey).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME);
}
use of com.scalar.db.api.Delete 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.Delete in project scalardb by scalar-labs.
the class DeleteStatementHandlerTest method handle_DeleteWithoutConditionsGiven_ShouldCallDeleteItem.
@Test
public void handle_DeleteWithoutConditionsGiven_ShouldCallDeleteItem() {
// Arrange
when(container.deleteItem(anyString(), any(PartitionKey.class), any(CosmosItemRequestOptions.class))).thenReturn(response);
Delete delete = prepareDelete();
// Act Assert
assertThatCode(() -> handler.handle(delete)).doesNotThrowAnyException();
// Assert
verify(container).deleteItem(eq(id), eq(cosmosPartitionKey), any(CosmosItemRequestOptions.class));
}
use of com.scalar.db.api.Delete 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.Delete 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);
}
Aggregations