use of com.scalar.db.api.DeleteIf 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.DeleteIf 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);
}
use of com.scalar.db.api.DeleteIf in project scalardb by scalar-labs.
the class JdbcServiceTest method whenDeleteOperationWithDeleteIfConditionFails_shouldReturnFalseAndCallQueryBuilder.
@Test
public void whenDeleteOperationWithDeleteIfConditionFails_shouldReturnFalseAndCallQueryBuilder() throws Exception {
// Arrange
when(queryBuilder.deleteFrom(any(), any(), any())).thenReturn(deleteQueryBuilder);
when(deleteQueryBuilder.where(any(), any(), any())).thenReturn(deleteQueryBuilder);
when(deleteQueryBuilder.build()).thenReturn(deleteQuery);
when(connection.prepareStatement(any())).thenReturn(preparedStatement);
when(preparedStatement.executeUpdate()).thenReturn(0);
// Act
Delete delete = new Delete(new Key("p1", "val1")).withCondition(new DeleteIf(new ConditionalExpression("v1", new TextValue("val2"), ConditionalExpression.Operator.EQ))).forNamespace(NAMESPACE).forTable(TABLE);
boolean ret = jdbcService.delete(delete, connection);
// Assert
assertThat(ret).isFalse();
verify(operationChecker).check(any(Delete.class));
verify(queryBuilder).deleteFrom(any(), any(), any());
}
use of com.scalar.db.api.DeleteIf 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.DeleteIf 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