use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class MultiStorageTest method whenDeleteDataFromTable1_DataShouldBeDeletedFromStorage1.
@Test
public void whenDeleteDataFromTable1_DataShouldBeDeletedFromStorage1() throws ExecutionException {
// Arrange
String namespace = NAMESPACE1;
String table = TABLE1;
Key partitionKey = new Key(COL_NAME1, 1);
Key clusteringKey = new Key(COL_NAME2, 2);
Delete delete = new Delete(partitionKey, clusteringKey).forNamespace(namespace).forTable(table);
// Act
multiStorage.delete(delete);
// Assert
verify(storage1).delete(any(Delete.class));
}
use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class MultiStorageTest method whenDeleteDataFromTable3_DataShouldBeDeletedFromDefaultStorage.
@Test
public void whenDeleteDataFromTable3_DataShouldBeDeletedFromDefaultStorage() throws ExecutionException {
// Arrange
String namespace = NAMESPACE1;
String table = TABLE3;
Key partitionKey = new Key(COL_NAME1, 1);
Key clusteringKey = new Key(COL_NAME2, 2);
Delete delete = new Delete(partitionKey, clusteringKey).forNamespace(namespace).forTable(table);
// Act
multiStorage.delete(delete);
// Assert
verify(storage3).delete(any(Delete.class));
}
use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class DeleteStatementHandlerTest method handle_DeleteWithoutClusteringKeyGiven_ShouldCallDeleteItem.
@Test
public void handle_DeleteWithoutClusteringKeyGiven_ShouldCallDeleteItem() {
// Arrange
when(metadata.getClusteringKeyNames()).thenReturn(new LinkedHashSet<>(Collections.singletonList(ANY_NAME_2)));
when(client.deleteItem(any(DeleteItemRequest.class))).thenReturn(response);
Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1);
Delete delete = new Delete(partitionKey).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME);
DynamoMutation dynamoMutation = new DynamoMutation(delete, metadata);
// Act Assert
assertThatCode(() -> handler.handle(delete)).doesNotThrowAnyException();
// Assert
ArgumentCaptor<DeleteItemRequest> captor = ArgumentCaptor.forClass(DeleteItemRequest.class);
verify(client).deleteItem(captor.capture());
DeleteItemRequest actualRequest = captor.getValue();
assertThat(actualRequest.key()).isEqualTo(dynamoMutation.getKeyMap());
assertThat(actualRequest.conditionExpression()).isNull();
}
use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class DeleteStatementHandlerTest method prepareDelete.
private Delete prepareDelete() {
Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1);
Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2);
return new Delete(partitionKey, clusteringKey).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME);
}
use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class DeleteStatementHandlerTest method handle_DeleteWithConditionsGiven_ShouldCallDeleteItem.
@Test
public void handle_DeleteWithConditionsGiven_ShouldCallDeleteItem() {
// Arrange
when(metadata.getClusteringKeyNames()).thenReturn(new LinkedHashSet<>(Collections.singletonList(ANY_NAME_2)));
when(client.deleteItem(any(DeleteItemRequest.class))).thenReturn(response);
Delete delete = prepareDelete().withCondition(new DeleteIfExists());
DynamoMutation dynamoMutation = new DynamoMutation(delete, metadata);
// Act Assert
assertThatCode(() -> handler.handle(delete)).doesNotThrowAnyException();
// Assert
ArgumentCaptor<DeleteItemRequest> captor = ArgumentCaptor.forClass(DeleteItemRequest.class);
verify(client).deleteItem(captor.capture());
DeleteItemRequest actualRequest = captor.getValue();
assertThat(actualRequest.key()).isEqualTo(dynamoMutation.getKeyMap());
assertThat(actualRequest.conditionExpression()).isEqualTo(dynamoMutation.getIfExistsCondition());
}
Aggregations