use of com.scalar.db.api.DeleteIfExists in project scalardb by scalar-labs.
the class OperationCheckerTest method whenCheckingDeleteOperationWithoutAnyClusteringKey_shouldThrowIllegalArgumentException.
@Test
public void whenCheckingDeleteOperationWithoutAnyClusteringKey_shouldThrowIllegalArgumentException() {
// Arrange
Key partitionKey = new Key(PKEY1, 1, PKEY2, "val1");
Key clusteringKey = null;
MutationCondition condition = new DeleteIfExists();
Delete delete = new Delete(partitionKey, clusteringKey).withCondition(condition).forNamespace(NAMESPACE).forTable(TABLE_NAME);
// Act Assert
assertThatThrownBy(() -> operationChecker.check(delete)).isInstanceOf(IllegalArgumentException.class);
}
use of com.scalar.db.api.DeleteIfExists in project scalardb by scalar-labs.
the class OperationCheckerTest method whenCheckingPutOperationWithDeleteIfExistsCondition_shouldThrowIllegalArgumentException.
@Test
public void whenCheckingPutOperationWithDeleteIfExistsCondition_shouldThrowIllegalArgumentException() {
// Arrange
Key partitionKey = new Key(PKEY1, 1, PKEY2, "val1");
Key clusteringKey = new Key(CKEY1, 2, CKEY2, "val1");
List<Value<?>> values = Arrays.asList(new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true));
MutationCondition condition = new DeleteIfExists();
Put put = new Put(partitionKey, clusteringKey).withValues(values).withCondition(condition).forNamespace(NAMESPACE).forTable(TABLE_NAME);
// Act Assert
assertThatThrownBy(() -> operationChecker.check(put)).isInstanceOf(IllegalArgumentException.class);
}
use of com.scalar.db.api.DeleteIfExists in project scalardb by scalar-labs.
the class DeleteStatementHandlerTest method prepare_DeleteOperationWithIfExistsGiven_ShouldCallAccept.
@Test
public void prepare_DeleteOperationWithIfExistsGiven_ShouldCallAccept() {
// Arrange
configureBehavior(null);
del = prepareDeleteWithClusteringKey();
DeleteIfExists deleteIfExists = spy(new DeleteIfExists());
del.withCondition(deleteIfExists);
// Act
handler.prepare(del);
// Assert
verify(deleteIfExists).accept(any(ConditionSetter.class));
}
use of com.scalar.db.api.DeleteIfExists in project scalardb by scalar-labs.
the class DeleteStatementHandlerTest method prepare_DeleteOperationWithIfExistsGiven_ShouldPrepareProperQuery.
@Test
public void prepare_DeleteOperationWithIfExistsGiven_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 EXISTS;" });
configureBehavior(expected);
del = prepareDeleteWithClusteringKey();
del.withCondition(new DeleteIfExists());
// Act
handler.prepare(del);
// Assert
verify(session).prepare(expected);
}
use of com.scalar.db.api.DeleteIfExists in project scalardb by scalar-labs.
the class BatchHandlerTest method handle_MultipleMutationsGiven_ShouldCallTransactWriteItems.
@Test
public void handle_MultipleMutationsGiven_ShouldCallTransactWriteItems() {
// Arrange
when(client.transactWriteItems(any(TransactWriteItemsRequest.class))).thenReturn(transactWriteResponse);
Put put1 = preparePut();
Put put2 = preparePut().withCondition(new PutIfNotExists());
Delete delete1 = prepareDelete();
Delete delete2 = prepareDelete().withCondition(new DeleteIfExists());
DynamoMutation dynamoMutation1 = new DynamoMutation(put1, metadata);
DynamoMutation dynamoMutation2 = new DynamoMutation(put2, metadata);
DynamoMutation dynamoMutation3 = new DynamoMutation(delete1, metadata);
DynamoMutation dynamoMutation4 = new DynamoMutation(delete2, metadata);
// Act Assert
assertThatCode(() -> handler.handle(Arrays.asList(put1, put2, delete1, delete2))).doesNotThrowAnyException();
// Assert
ArgumentCaptor<TransactWriteItemsRequest> captor = ArgumentCaptor.forClass(TransactWriteItemsRequest.class);
verify(client).transactWriteItems(captor.capture());
List<TransactWriteItem> items = captor.getValue().transactItems();
assertThat(items.size()).isEqualTo(4);
assertThat(items.get(0).update().key()).isEqualTo(dynamoMutation1.getKeyMap());
assertThat(items.get(0).update().expressionAttributeNames()).isEqualTo(dynamoMutation1.getColumnMapWithKey());
assertThat(items.get(0).update().expressionAttributeValues()).isEqualTo(dynamoMutation1.getValueBindMapWithKey());
assertThat(items.get(0).update().conditionExpression()).isNull();
assertThat(items.get(1).update().key()).isEqualTo(dynamoMutation2.getKeyMap());
assertThat(items.get(1).update().expressionAttributeNames()).isEqualTo(dynamoMutation2.getColumnMapWithKey());
assertThat(items.get(1).update().expressionAttributeValues()).isEqualTo(dynamoMutation2.getValueBindMapWithKey());
assertThat(items.get(1).update().conditionExpression()).isEqualTo(dynamoMutation2.getIfNotExistsCondition());
assertThat(items.get(2).delete().key()).isEqualTo(dynamoMutation3.getKeyMap());
assertThat(items.get(2).delete().conditionExpression()).isNull();
assertThat(items.get(3).delete().key()).isEqualTo(dynamoMutation4.getKeyMap());
assertThat(items.get(3).delete().conditionExpression()).isEqualTo(dynamoMutation4.getIfExistsCondition());
}
Aggregations