use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class StorageMultiplePartitionKeyIntegrationTestBase method getAndDelete_ShouldBehaveCorrectly.
@Test
public void getAndDelete_ShouldBehaveCorrectly() throws ExecutionException {
for (DataType firstPartitionKeyType : partitionKeyTypes.keySet()) {
for (DataType secondPartitionKeyType : partitionKeyTypes.get(firstPartitionKeyType)) {
truncateTable(firstPartitionKeyType, secondPartitionKeyType);
List<PartitionKey> partitionKeys = prepareRecords(firstPartitionKeyType, secondPartitionKeyType);
String description = description(firstPartitionKeyType, secondPartitionKeyType);
// for get
for (PartitionKey partitionKey : partitionKeys) {
// Arrange
Get get = prepareGet(firstPartitionKeyType, partitionKey.first, secondPartitionKeyType, partitionKey.second);
// Act
Optional<Result> result = storage.get(get);
// Assert
Assertions.assertThat(result).describedAs(description).isPresent();
Assertions.assertThat(result.get().getValue(FIRST_PARTITION_KEY).isPresent()).describedAs(description).isTrue();
Assertions.assertThat(result.get().getValue(FIRST_PARTITION_KEY).get()).describedAs(description).isEqualTo(partitionKey.first);
Assertions.assertThat(result.get().getValue(SECOND_PARTITION_KEY).isPresent()).describedAs(description).isTrue();
Assertions.assertThat(result.get().getValue(SECOND_PARTITION_KEY).get()).describedAs(description).isEqualTo(partitionKey.second);
Assertions.assertThat(result.get().getValue(COL_NAME).isPresent()).describedAs(description).isTrue();
Assertions.assertThat(result.get().getValue(COL_NAME).get().getAsInt()).describedAs(description).isEqualTo(1);
}
// for delete
for (PartitionKey partitionKey : partitionKeys) {
// Arrange
Delete delete = prepareDelete(firstPartitionKeyType, partitionKey.first, secondPartitionKeyType, partitionKey.second);
// Act
storage.delete(delete);
// Assert
Optional<Result> result = storage.get(prepareGet(firstPartitionKeyType, partitionKey.first, secondPartitionKeyType, partitionKey.second));
Assertions.assertThat(result).describedAs(description).isNotPresent();
}
}
}
}
use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class StorageIntegrationTestBase method mutate_PutAndDeleteGiven_ShouldUpdateAndDeleteRecordsProperly.
@Test
public void mutate_PutAndDeleteGiven_ShouldUpdateAndDeleteRecordsProperly() throws ExecutionException, IOException {
// Arrange
populateRecords();
List<Put> puts = preparePuts();
puts.get(1).withValue(COL_NAME3, Integer.MAX_VALUE);
puts.get(2).withValue(COL_NAME3, Integer.MIN_VALUE);
int pKey = 0;
int cKey = 0;
Delete delete = prepareDelete(pKey, cKey);
Scan scan = new Scan(new Key(COL_NAME1, pKey));
// Act
assertThatCode(() -> storage.mutate(Arrays.asList(delete, puts.get(1), puts.get(2)))).doesNotThrowAnyException();
// Assert
List<Result> results = scanAll(scan);
assertThat(results.size()).isEqualTo(2);
assertThat(results.get(0).getValue(COL_NAME1).isPresent()).isTrue();
assertThat(results.get(0).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0);
assertThat(results.get(0).getValue(COL_NAME3).isPresent()).isTrue();
assertThat(results.get(0).getValue(COL_NAME3).get().getAsInt()).isEqualTo(Integer.MAX_VALUE);
assertThat(results.get(1).getValue(COL_NAME1).isPresent()).isTrue();
assertThat(results.get(1).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0);
assertThat(results.get(1).getValue(COL_NAME3).isPresent()).isTrue();
assertThat(results.get(1).getValue(COL_NAME3).get().getAsInt()).isEqualTo(Integer.MIN_VALUE);
}
use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class StorageIntegrationTestBase method delete_DeleteWithIfGivenWhenSuchRecordExists_ShouldDeleteProperly.
@Test
public void delete_DeleteWithIfGivenWhenSuchRecordExists_ShouldDeleteProperly() throws ExecutionException {
// Arrange
populateRecords();
int pKey = 0;
int cKey = 0;
Key partitionKey = new Key(COL_NAME1, pKey);
Key clusteringKey = new Key(COL_NAME4, cKey);
// Act
Delete delete = prepareDelete(pKey, cKey);
delete.withCondition(new DeleteIf(new ConditionalExpression(COL_NAME2, new TextValue(Integer.toString(pKey)), ConditionalExpression.Operator.EQ)));
assertThatCode(() -> storage.delete(delete)).doesNotThrowAnyException();
// Assert
Optional<Result> actual = storage.get(new Get(partitionKey, clusteringKey));
assertThat(actual.isPresent()).isFalse();
}
use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class StorageIntegrationTestBase method mutate_SingleDeleteWithPartitionKeyAndClusteringKeyGiven_ShouldDeleteSingleRecordProperly.
@Test
public void mutate_SingleDeleteWithPartitionKeyAndClusteringKeyGiven_ShouldDeleteSingleRecordProperly() throws ExecutionException, IOException {
// Arrange
populateRecords();
int pKey = 0;
int cKey = 0;
// Act
Key partitionKey = new Key(COL_NAME1, pKey);
Key clusteringKey = new Key(COL_NAME4, cKey);
Delete delete = new Delete(partitionKey, clusteringKey);
assertThatCode(() -> storage.mutate(Collections.singletonList(delete))).doesNotThrowAnyException();
// Assert
List<Result> actual = scanAll(new Scan(partitionKey));
assertThat(actual.size()).isEqualTo(2);
assertThat(actual.get(0).getValue(COL_NAME1).isPresent()).isTrue();
assertThat(actual.get(0).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0);
assertThat(actual.get(0).getValue(COL_NAME4).isPresent()).isTrue();
assertThat(actual.get(0).getValue(COL_NAME4).get().getAsInt()).isEqualTo(cKey + 1);
assertThat(actual.get(1).getValue(COL_NAME1).isPresent()).isTrue();
assertThat(actual.get(1).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0);
assertThat(actual.get(1).getValue(COL_NAME4).isPresent()).isTrue();
assertThat(actual.get(1).getValue(COL_NAME4).get().getAsInt()).isEqualTo(cKey + 2);
}
use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class StorageIntegrationTestBase method delete_MultipleDeleteWithDifferentConditionsGiven_ShouldDeleteProperly.
@Test
public void delete_MultipleDeleteWithDifferentConditionsGiven_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(COL_NAME2, 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(COL_NAME1, 0)));
assertThat(results.size()).isEqualTo(0);
}
Aggregations