use of com.scalar.db.api.ConditionalExpression in project scalardb by scalar-labs.
the class RollbackMutationComposerTest method add_PutAndResultFromSnapshotGivenAndPreparedResultGivenFromStorage_ShouldComposePut.
@Test
public void add_PutAndResultFromSnapshotGivenAndPreparedResultGivenFromStorage_ShouldComposePut() throws ExecutionException {
// Arrange
composer = new RollbackMutationComposer(ANY_ID_2, storage, tableMetadataManager, mutations);
TransactionResult resultInSnapshot = prepareInitialResult(ANY_ID_1, TransactionState.COMMITTED);
TransactionResult result = prepareResult(TransactionState.PREPARED);
when(storage.get(any(Get.class))).thenReturn(Optional.of(result));
Put put = preparePut();
// Act
composer.add(put, resultInSnapshot);
// Assert
Put actual = (Put) mutations.get(0);
Put expected = new Put(put.getPartitionKey(), put.getClusteringKey().orElse(null)).forNamespace(put.forNamespace().get()).forTable(put.forTable().get());
expected.withConsistency(Consistency.LINEARIZABLE);
expected.withCondition(new PutIf(new ConditionalExpression(ID, toIdValue(ANY_ID_2), Operator.EQ), new ConditionalExpression(STATE, toStateValue(TransactionState.PREPARED), Operator.EQ)));
expected.withValues(extractAfterValues(resultInSnapshot));
assertThat(actual).isEqualTo(expected);
verify(storage).get(any(Get.class));
}
use of com.scalar.db.api.ConditionalExpression in project scalardb by scalar-labs.
the class RollbackMutationComposerTest method add_PutAndResultFromSnapshotGivenAndDeletedResultGivenFromStorage_ShouldComposePut.
@Test
public void add_PutAndResultFromSnapshotGivenAndDeletedResultGivenFromStorage_ShouldComposePut() throws ExecutionException {
// Arrange
composer = new RollbackMutationComposer(ANY_ID_2, storage, tableMetadataManager, mutations);
TransactionResult resultInSnapshot = prepareInitialResult(ANY_ID_1, TransactionState.COMMITTED);
TransactionResult result = prepareResult(TransactionState.DELETED);
when(storage.get(any(Get.class))).thenReturn(Optional.of(result));
Put put = preparePut();
// Act
composer.add(put, resultInSnapshot);
// Assert
Put actual = (Put) mutations.get(0);
Put expected = new Put(put.getPartitionKey(), put.getClusteringKey().orElse(null)).forNamespace(put.forNamespace().get()).forTable(put.forTable().get());
expected.withConsistency(Consistency.LINEARIZABLE);
expected.withCondition(new PutIf(new ConditionalExpression(ID, toIdValue(ANY_ID_2), Operator.EQ), new ConditionalExpression(STATE, toStateValue(TransactionState.DELETED), Operator.EQ)));
expected.withValues(extractAfterValues(resultInSnapshot));
assertThat(actual).isEqualTo(expected);
verify(storage).get(any(Get.class));
}
use of com.scalar.db.api.ConditionalExpression in project scalardb by scalar-labs.
the class CommitMutationComposerTest method add_SelectionAndPreparedResultGiven_ShouldComposePutForRollforward.
@Test
public void add_SelectionAndPreparedResultGiven_ShouldComposePutForRollforward() {
// Arrange
Get get = prepareGet();
TransactionResult result = prepareResult(TransactionState.PREPARED);
// Act
composer.add(get, result);
// Assert
Put actual = (Put) mutations.get(0);
Put expected = new Put(get.getPartitionKey(), get.getClusteringKey().orElse(null)).forNamespace(get.forNamespace().get()).forTable(get.forTable().get());
expected.withConsistency(Consistency.LINEARIZABLE);
expected.withCondition(new PutIf(new ConditionalExpression(ID, toIdValue(ANY_ID), Operator.EQ), new ConditionalExpression(STATE, toStateValue(TransactionState.PREPARED), Operator.EQ)));
expected.withValue(Attribute.toCommittedAtValue(ANY_TIME_2));
expected.withValue(Attribute.toStateValue(TransactionState.COMMITTED));
assertThat(actual).isEqualTo(expected);
}
use of com.scalar.db.api.ConditionalExpression in project scalardb by scalar-labs.
the class CommitMutationComposerTest method add_DeleteGiven_ShouldComposeDeleteWithDeleteIfCondition.
@Test
public void add_DeleteGiven_ShouldComposeDeleteWithDeleteIfCondition() {
// Arrange
Delete delete = prepareDelete();
// Act
// result is not used, so it's set null
composer.add(delete, null);
// Assert
Delete actual = (Delete) mutations.get(0);
delete.withConsistency(Consistency.LINEARIZABLE);
delete.withCondition(new DeleteIf(new ConditionalExpression(ID, toIdValue(ANY_ID), Operator.EQ), new ConditionalExpression(STATE, toStateValue(TransactionState.DELETED), Operator.EQ)));
assertThat(actual).isEqualTo(delete);
}
use of com.scalar.db.api.ConditionalExpression in project scalardb by scalar-labs.
the class CommitMutationComposerTest method add_SelectionAndDeletedResultGiven_ShouldComposePutForRollforward.
@Test
public void add_SelectionAndDeletedResultGiven_ShouldComposePutForRollforward() {
// Arrange
Get get = prepareGet();
TransactionResult result = prepareResult(TransactionState.DELETED);
// 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), Operator.EQ), new ConditionalExpression(STATE, toStateValue(TransactionState.DELETED), Operator.EQ)));
assertThat(actual).isEqualTo(expected);
}
Aggregations