Search in sources :

Example 56 with Delete

use of com.scalar.db.api.Delete in project scalardb by scalar-labs.

the class DeleteStatementHandlerTest method handle_DynamoDbExceptionWithConditionalCheckFailed_ShouldThrowNoMutationException.

@Test
public void handle_DynamoDbExceptionWithConditionalCheckFailed_ShouldThrowNoMutationException() {
    // Arrange
    when(metadata.getClusteringKeyNames()).thenReturn(new LinkedHashSet<>(Collections.singletonList(ANY_NAME_2)));
    when(client.deleteItem(any(DeleteItemRequest.class))).thenReturn(response);
    ConditionalCheckFailedException toThrow = mock(ConditionalCheckFailedException.class);
    doThrow(toThrow).when(client).deleteItem(any(DeleteItemRequest.class));
    Delete delete = prepareDelete().withCondition(new DeleteIfExists());
    // Act Assert
    assertThatThrownBy(() -> handler.handle(delete)).isInstanceOf(NoMutationException.class);
}
Also used : Delete(com.scalar.db.api.Delete) DeleteItemRequest(software.amazon.awssdk.services.dynamodb.model.DeleteItemRequest) ConditionalCheckFailedException(software.amazon.awssdk.services.dynamodb.model.ConditionalCheckFailedException) DeleteIfExists(com.scalar.db.api.DeleteIfExists) Test(org.junit.jupiter.api.Test)

Example 57 with Delete

use of com.scalar.db.api.Delete in project scalardb by scalar-labs.

the class GrpcStorageTest method mutate_StubThrowInternalError_ShouldThrowExecutionException.

@Test
public void mutate_StubThrowInternalError_ShouldThrowExecutionException() {
    // Arrange
    Key partitionKey = new Key("col1", 1);
    List<Mutation> mutations = Arrays.asList(new Put(partitionKey), new Delete(partitionKey));
    when(blockingStub.mutate(any())).thenThrow(Status.INTERNAL.asRuntimeException());
    // Act
    assertThatThrownBy(() -> storage.mutate(mutations)).isInstanceOf(ExecutionException.class);
}
Also used : Delete(com.scalar.db.api.Delete) Mutation(com.scalar.db.api.Mutation) Key(com.scalar.db.io.Key) Put(com.scalar.db.api.Put) Test(org.junit.jupiter.api.Test)

Example 58 with Delete

use of com.scalar.db.api.Delete in project scalardb by scalar-labs.

the class GrpcStorageTest method mutate_isCalledWithProperArguments_StubShouldBeCalledProperly.

@Test
public void mutate_isCalledWithProperArguments_StubShouldBeCalledProperly() throws ExecutionException {
    // Arrange
    Key partitionKey = new Key("col1", 1);
    List<Mutation> mutations = Arrays.asList(new Put(partitionKey), new Delete(partitionKey));
    // Act
    storage.mutate(mutations);
    // Assert
    verify(blockingStub).mutate(any());
}
Also used : Delete(com.scalar.db.api.Delete) Mutation(com.scalar.db.api.Mutation) Key(com.scalar.db.io.Key) Put(com.scalar.db.api.Put) Test(org.junit.jupiter.api.Test)

Example 59 with Delete

use of com.scalar.db.api.Delete in project scalardb by scalar-labs.

the class GrpcStorageTest method deletes_StubThrowInvalidArgumentError_ShouldThrowIllegalArgumentException.

@Test
public void deletes_StubThrowInvalidArgumentError_ShouldThrowIllegalArgumentException() {
    // Arrange
    Key partitionKey1 = new Key("col1", 1);
    Key partitionKey2 = new Key("col1", 2);
    List<Delete> deletes = Arrays.asList(new Delete(partitionKey2), new Delete(partitionKey1));
    when(blockingStub.mutate(any())).thenThrow(Status.INVALID_ARGUMENT.asRuntimeException());
    // Act Assert
    assertThatThrownBy(() -> storage.delete(deletes)).isInstanceOf(IllegalArgumentException.class);
}
Also used : Delete(com.scalar.db.api.Delete) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 60 with Delete

use of com.scalar.db.api.Delete in project scalardb by scalar-labs.

the class GrpcStorageTest method delete_StubThrowInternalError_ShouldThrowExecutionException.

@Test
public void delete_StubThrowInternalError_ShouldThrowExecutionException() {
    // Arrange
    Key partitionKey = new Key("col1", 1);
    Delete delete = new Delete(partitionKey);
    when(blockingStub.mutate(any())).thenThrow(Status.INTERNAL.asRuntimeException());
    // Act
    assertThatThrownBy(() -> storage.delete(delete)).isInstanceOf(ExecutionException.class);
}
Also used : Delete(com.scalar.db.api.Delete) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Aggregations

Delete (com.scalar.db.api.Delete)174 Key (com.scalar.db.io.Key)112 Test (org.junit.jupiter.api.Test)111 Put (com.scalar.db.api.Put)59 Get (com.scalar.db.api.Get)29 Result (com.scalar.db.api.Result)29 Test (org.junit.Test)25 DeleteIfExists (com.scalar.db.api.DeleteIfExists)24 ConditionalExpression (com.scalar.db.api.ConditionalExpression)16 DeleteIf (com.scalar.db.api.DeleteIf)15 Mutation (com.scalar.db.api.Mutation)14 MutationCondition (com.scalar.db.api.MutationCondition)11 Scan (com.scalar.db.api.Scan)11 PutIfNotExists (com.scalar.db.api.PutIfNotExists)10 TextValue (com.scalar.db.io.TextValue)10 ExecutionException (com.scalar.db.exception.storage.ExecutionException)8 CosmosStoredProcedureRequestOptions (com.azure.cosmos.models.CosmosStoredProcedureRequestOptions)6 GrpcTransaction (com.scalar.db.transaction.rpc.GrpcTransaction)6 DeleteItemRequest (software.amazon.awssdk.services.dynamodb.model.DeleteItemRequest)6 PartitionKey (com.azure.cosmos.models.PartitionKey)5