use of com.scalar.db.api.ConditionalExpression in project scalardb by scalar-labs.
the class StorageWithReservedKeywordIntegrationTestBase method delete_WithReservedKeywordAndMultipleDeleteWithDifferentConditionsGiven_ShouldDeleteProperly.
@Test
public void delete_WithReservedKeywordAndMultipleDeleteWithDifferentConditionsGiven_ShouldDeleteProperly() throws IOException, ExecutionException {
// Arrange
List<Put> puts = preparePuts();
List<Delete> deletes = prepareDeletes();
storage.mutate(Arrays.asList(puts.get(0), puts.get(1), puts.get(2)));
deletes.get(0).withCondition(new DeleteIfExists());
deletes.get(1).withCondition(new DeleteIf(new ConditionalExpression(columnName2, new TextValue("1"), ConditionalExpression.Operator.EQ)));
// Act
assertThatCode(() -> storage.delete(Arrays.asList(deletes.get(0), deletes.get(1), deletes.get(2)))).doesNotThrowAnyException();
// Assert
List<Result> results = scanAll(new Scan(new Key(columnName1, 0)));
assertThat(results.size()).isEqualTo(0);
}
use of com.scalar.db.api.ConditionalExpression in project scalardb by scalar-labs.
the class DeleteStatementHandlerTest method prepare_DeleteOperationWithIfGiven_ShouldCallAccept.
@Test
public void prepare_DeleteOperationWithIfGiven_ShouldCallAccept() {
// Arrange
configureBehavior(null);
del = prepareDeleteWithClusteringKey();
DeleteIf deleteIf = spy(new DeleteIf(new ConditionalExpression(ANY_NAME_4, new IntValue(ANY_INT_2), Operator.EQ)));
del.withCondition(deleteIf);
// Act
handler.prepare(del);
// Assert
verify(deleteIf).accept(any(ConditionSetter.class));
}
use of com.scalar.db.api.ConditionalExpression in project scalardb by scalar-labs.
the class DeleteStatementHandlerTest method prepare_DeleteOperationWithIfGiven_ShouldPrepareProperQuery.
@Test
public void prepare_DeleteOperationWithIfGiven_ShouldPrepareProperQuery() {
// Arrange
String expected = Joiner.on(" ").skipNulls().join(new String[] { "DELETE", "FROM", ANY_NAMESPACE_NAME + "." + ANY_TABLE_NAME, "WHERE", ANY_NAME_1 + "=?", "AND", ANY_NAME_2 + "=?", "IF", ANY_NAME_3 + "=?", "AND", ANY_NAME_4 + "=?;" });
configureBehavior(expected);
del = prepareDeleteWithClusteringKey();
del.withCondition(new DeleteIf(new ConditionalExpression(ANY_NAME_3, new IntValue(ANY_INT_1), Operator.EQ), new ConditionalExpression(ANY_NAME_4, new TextValue(ANY_TEXT_3), Operator.EQ)));
// Act
handler.prepare(del);
// Assert
verify(session).prepare(expected);
}
use of com.scalar.db.api.ConditionalExpression in project scalardb by scalar-labs.
the class DeleteStatementHandlerTest method bind_DeleteOperationWithIfGiven_ShouldBindProperly.
@Test
public void bind_DeleteOperationWithIfGiven_ShouldBindProperly() {
// Arrange
configureBehavior(null);
del = prepareDeleteWithClusteringKey();
del.withCondition(new DeleteIf(new ConditionalExpression(ANY_NAME_3, new IntValue(ANY_INT_1), Operator.EQ), new ConditionalExpression(ANY_NAME_4, new TextValue(ANY_TEXT_3), Operator.EQ)));
// Act
handler.bind(prepared, del);
// Assert
verify(bound).setString(0, ANY_TEXT_1);
verify(bound).setString(1, ANY_TEXT_2);
verify(bound).setInt(2, ANY_INT_1);
verify(bound).setString(3, ANY_TEXT_3);
}
use of com.scalar.db.api.ConditionalExpression in project scalardb by scalar-labs.
the class UpdateStatementHandlerTest method setConsistency_PutOperationWithIfGiven_ShouldPrepareWithQuorumAndSerial.
@Test
public void setConsistency_PutOperationWithIfGiven_ShouldPrepareWithQuorumAndSerial() {
// Arrange
configureBehavior(null);
put = preparePutWithClusteringKey();
put.withCondition(new PutIf(new ConditionalExpression(ANY_NAME_4, new IntValue(ANY_INT_2), Operator.EQ))).withConsistency(Consistency.EVENTUAL);
// Act
handler.setConsistency(bound, put);
// Assert
verify(bound).setConsistencyLevel(ConsistencyLevel.QUORUM);
verify(bound).setSerialConsistencyLevel(ConsistencyLevel.SERIAL);
}
Aggregations