Search in sources :

Example 76 with Delete

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

the class SnapshotTest method get_KeyGivenContainedInDeleteSet_ShouldReturnEmpty.

@Test
public void get_KeyGivenContainedInDeleteSet_ShouldReturnEmpty() throws CrudException {
    // Arrange
    snapshot = prepareSnapshot(Isolation.SNAPSHOT);
    Delete delete = prepareDelete();
    Snapshot.Key key = new Snapshot.Key(delete);
    snapshot.put(key, delete);
    // Act
    Optional<TransactionResult> actual = snapshot.get(key);
    // Assert
    assertThat(actual).isNotPresent();
}
Also used : Delete(com.scalar.db.api.Delete) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 77 with Delete

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

the class SnapshotTest method put_DeleteGiven_ShouldHoldWhatsGivenInDeleteSet.

@Test
public void put_DeleteGiven_ShouldHoldWhatsGivenInDeleteSet() {
    // Arrange
    snapshot = prepareSnapshot(Isolation.SNAPSHOT);
    Delete delete = prepareDelete();
    Snapshot.Key key = new Snapshot.Key(delete);
    // Act
    snapshot.put(key, delete);
    // Assert
    assertThat(deleteSet.get(key)).isEqualTo(delete);
}
Also used : Delete(com.scalar.db.api.Delete) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 78 with Delete

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

the class SnapshotTest method to_CommitMutationComposerGiven_ShouldCallComposerProperly.

@Test
public void to_CommitMutationComposerGiven_ShouldCallComposerProperly() throws CommitConflictException, ExecutionException {
    // Arrange
    snapshot = prepareSnapshot(Isolation.SNAPSHOT);
    Put put = preparePut();
    Delete delete = prepareAnotherDelete();
    TransactionResult result = prepareResult(ANY_ID);
    snapshot.put(new Snapshot.Key(prepareGet()), Optional.of(result));
    snapshot.put(new Snapshot.Key(prepareAnotherGet()), Optional.of(result));
    snapshot.put(new Snapshot.Key(put), put);
    snapshot.put(new Snapshot.Key(delete), delete);
    // Act
    snapshot.to(commitComposer);
    // Assert
    verify(commitComposer).add(put, result);
    verify(commitComposer).add(delete, result);
}
Also used : Delete(com.scalar.db.api.Delete) Put(com.scalar.db.api.Put) Test(org.junit.jupiter.api.Test)

Example 79 with Delete

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

the class SnapshotTest method to_RollbackMutationComposerGivenAndSerializableWithExtraWriteIsolationSet_ShouldCallComposerProperly.

@Test
public void to_RollbackMutationComposerGivenAndSerializableWithExtraWriteIsolationSet_ShouldCallComposerProperly() throws CommitConflictException, ExecutionException {
    // Arrange
    snapshot = prepareSnapshot(Isolation.SERIALIZABLE, SerializableStrategy.EXTRA_WRITE);
    Put put = preparePut();
    Delete delete = prepareAnotherDelete();
    TransactionResult result = prepareResult(ANY_ID);
    snapshot.put(new Snapshot.Key(prepareGet()), Optional.of(result));
    snapshot.put(new Snapshot.Key(prepareAnotherGet()), Optional.of(result));
    snapshot.put(new Snapshot.Key(put), put);
    snapshot.put(new Snapshot.Key(delete), delete);
    configureBehavior();
    // Act
    snapshot.to(rollbackComposer);
    // Assert
    // no effect on RollbackMutationComposer
    verify(rollbackComposer).add(put, result);
    verify(rollbackComposer).add(delete, result);
    verify(snapshot).toSerializableWithExtraWrite(rollbackComposer);
}
Also used : Delete(com.scalar.db.api.Delete) Put(com.scalar.db.api.Put) Test(org.junit.jupiter.api.Test)

Example 80 with Delete

use of com.scalar.db.api.Delete 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);
}
Also used : Delete(com.scalar.db.api.Delete) CosmosStoredProcedureRequestOptions(com.azure.cosmos.models.CosmosStoredProcedureRequestOptions) CosmosException(com.azure.cosmos.CosmosException) DeleteIfExists(com.scalar.db.api.DeleteIfExists) 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