Search in sources :

Example 71 with Delete

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

the class RollbackMutationComposerTest method add_GetAndPreparedResultGivenAndBeforeResultNotGiven_ShouldComposeDelete.

@Test
public void add_GetAndPreparedResultGivenAndBeforeResultNotGiven_ShouldComposeDelete() throws ExecutionException {
    // Arrange
    composer = new RollbackMutationComposer(ANY_ID_2, storage, tableMetadataManager, mutations);
    TransactionResult result = prepareInitialResult(ANY_ID_2, TransactionState.PREPARED);
    Get get = prepareGet();
    // Act
    composer.add(get, result);
    // Assert
    Delete actual = (Delete) mutations.get(0);
    Delete expected = new Delete(get.getPartitionKey(), get.getClusteringKey().orElse(null)).forNamespace(get.forNamespace().get()).forTable(get.forTable().get());
    expected.withConsistency(Consistency.LINEARIZABLE);
    expected.withCondition(new DeleteIf(new ConditionalExpression(ID, toIdValue(ANY_ID_2), Operator.EQ), new ConditionalExpression(STATE, toStateValue(TransactionState.PREPARED), Operator.EQ)));
    assertThat(actual).isEqualTo(expected);
}
Also used : Delete(com.scalar.db.api.Delete) Get(com.scalar.db.api.Get) ConditionalExpression(com.scalar.db.api.ConditionalExpression) DeleteIf(com.scalar.db.api.DeleteIf) Test(org.junit.jupiter.api.Test)

Example 72 with Delete

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

the class SnapshotTest method get_KeyGivenContainedInReadSetAndDeleteSet_ShouldReturnEmpty.

@Test
public void get_KeyGivenContainedInReadSetAndDeleteSet_ShouldReturnEmpty() throws CrudException {
    // Arrange
    snapshot = prepareSnapshot(Isolation.SNAPSHOT);
    Snapshot.Key key = new Snapshot.Key(prepareGet());
    TransactionResult result = prepareResult(ANY_ID);
    snapshot.put(key, Optional.of(result));
    Delete delete = prepareDelete();
    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 73 with Delete

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

the class SnapshotTest method put_PutGivenAfterDelete_ShouldThrowIllegalArgumentException.

@Test
public void put_PutGivenAfterDelete_ShouldThrowIllegalArgumentException() {
    // Arrange
    snapshot = prepareSnapshot(Isolation.SNAPSHOT);
    Delete delete = prepareDelete();
    Snapshot.Key deleteKey = new Snapshot.Key(prepareDelete());
    snapshot.put(deleteKey, delete);
    Put put = preparePut();
    Snapshot.Key putKey = new Snapshot.Key(preparePut());
    // Act Assert
    assertThatThrownBy(() -> snapshot.put(putKey, put)).isInstanceOf(IllegalArgumentException.class);
}
Also used : Delete(com.scalar.db.api.Delete) Key(com.scalar.db.io.Key) Put(com.scalar.db.api.Put) Test(org.junit.jupiter.api.Test)

Example 74 with Delete

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

the class SnapshotTest method to_RollbackMutationComposerGiven_ShouldCallComposerProperly.

@Test
public void to_RollbackMutationComposerGiven_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);
    configureBehavior();
    // Act
    snapshot.to(rollbackComposer);
    // Assert
    verify(rollbackComposer).add(put, result);
    verify(rollbackComposer).add(delete, result);
}
Also used : Delete(com.scalar.db.api.Delete) Put(com.scalar.db.api.Put) Test(org.junit.jupiter.api.Test)

Example 75 with Delete

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

the class SnapshotTest 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);
    return new Delete(partitionKey, clusteringKey).withConsistency(Consistency.LINEARIZABLE).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME);
}
Also used : Delete(com.scalar.db.api.Delete) Key(com.scalar.db.io.Key)

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