use of com.scalar.db.api.ConditionalExpression in project scalardb by scalar-labs.
the class RollbackMutationComposerTest method add_GetAndDeletedResultByThisGiven_ShouldComposePut.
@Test
public void add_GetAndDeletedResultByThisGiven_ShouldComposePut() throws ExecutionException {
// Arrange
composer = new RollbackMutationComposer(ANY_ID_2, storage, tableMetadataManager, mutations);
TransactionResult result = prepareResult(TransactionState.DELETED);
Get get = prepareGet();
// 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_2), Operator.EQ), new ConditionalExpression(STATE, toStateValue(TransactionState.DELETED), Operator.EQ)));
expected.withValues(extractAfterValues(prepareInitialResult(ANY_ID_1, TransactionState.COMMITTED)));
assertThat(actual).isEqualTo(expected);
}
use of com.scalar.db.api.ConditionalExpression in project scalardb by scalar-labs.
the class RollbackMutationComposerTest method add_GetAndPreparedResultByThisGiven_ShouldComposePut.
@Test
public void add_GetAndPreparedResultByThisGiven_ShouldComposePut() throws ExecutionException {
// Arrange
composer = new RollbackMutationComposer(ANY_ID_2, storage, tableMetadataManager, mutations);
TransactionResult result = prepareResult(TransactionState.PREPARED);
when(storage.get(any(Get.class))).thenReturn(Optional.of(result));
Get get = prepareGet();
// 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_2), Operator.EQ), new ConditionalExpression(STATE, toStateValue(TransactionState.PREPARED), Operator.EQ)));
expected.withValues(extractAfterValues(prepareInitialResult(ANY_ID_1, TransactionState.COMMITTED)));
assertThat(actual).isEqualTo(expected);
}
use of com.scalar.db.api.ConditionalExpression in project scalardb by scalar-labs.
the class RollbackMutationComposerTest method add_ScanAndDeletedResultByThisGiven_ShouldComposePut.
@Test
public void add_ScanAndDeletedResultByThisGiven_ShouldComposePut() throws ExecutionException {
// Arrange
composer = new RollbackMutationComposer(ANY_ID_2, storage, tableMetadataManager, mutations);
TransactionResult result = prepareResult(TransactionState.DELETED);
Scan scan = prepareScan();
// Act
composer.add(scan, result);
// Assert
Put actual = (Put) mutations.get(0);
Put expected = new Put(scan.getPartitionKey(), result.getClusteringKey().orElse(null)).forNamespace(scan.forNamespace().get()).forTable(scan.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(prepareInitialResult(ANY_ID_1, TransactionState.COMMITTED)));
assertThat(actual).isEqualTo(expected);
}
use of com.scalar.db.api.ConditionalExpression in project scalardb by scalar-labs.
the class RollbackMutationComposerTest method add_ScanAndPreparedResultByThisGivenAndBeforeResultNotGiven_ShouldComposeDelete.
@Test
public void add_ScanAndPreparedResultByThisGivenAndBeforeResultNotGiven_ShouldComposeDelete() throws ExecutionException {
// Arrange
composer = new RollbackMutationComposer(ANY_ID_2, storage, tableMetadataManager, mutations);
TransactionResult result = prepareInitialResult(ANY_ID_2, TransactionState.PREPARED);
Scan scan = prepareScan();
// Act
composer.add(scan, result);
// Assert
Delete actual = (Delete) mutations.get(0);
Delete expected = new Delete(scan.getPartitionKey(), result.getClusteringKey().orElse(null)).forNamespace(scan.forNamespace().get()).forTable(scan.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);
}
use of com.scalar.db.api.ConditionalExpression in project scalardb by scalar-labs.
the class RollbackMutationComposerTest method add_ScanAndPreparedResultByThisGiven_ShouldComposePut.
@Test
public void add_ScanAndPreparedResultByThisGiven_ShouldComposePut() throws ExecutionException {
// Arrange
composer = new RollbackMutationComposer(ANY_ID_2, storage, tableMetadataManager, mutations);
TransactionResult result = prepareResult(TransactionState.PREPARED);
Scan scan = prepareScan();
// Act
composer.add(scan, result);
// Assert
Put actual = (Put) mutations.get(0);
Put expected = new Put(scan.getPartitionKey(), result.getClusteringKey().orElse(null)).forNamespace(scan.forNamespace().get()).forTable(scan.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(prepareInitialResult(ANY_ID_1, TransactionState.COMMITTED)));
assertThat(actual).isEqualTo(expected);
}
Aggregations