use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class StorageWithReservedKeywordIntegrationTestBase method delete_WithReservedKeywordAndDeleteWithPartitionKeyAndClusteringKeyGiven_ShouldDeleteSingleRecordProperly.
@Test
public void delete_WithReservedKeywordAndDeleteWithPartitionKeyAndClusteringKeyGiven_ShouldDeleteSingleRecordProperly() throws IOException, ExecutionException {
// Arrange
populateRecords();
int pKey = 0;
int cKey = 0;
Key partitionKey = new Key(columnName1, pKey);
// Act
Delete delete = prepareDelete(pKey, cKey);
assertThatCode(() -> storage.delete(delete)).doesNotThrowAnyException();
// Assert
List<Result> results = scanAll(new Scan(partitionKey));
assertThat(results.size()).isEqualTo(2);
assertThat(results.get(0).getValue(columnName1).isPresent()).isTrue();
assertThat(results.get(0).getValue(columnName1).get().getAsInt()).isEqualTo(0);
assertThat(results.get(0).getValue(columnName4).isPresent()).isTrue();
assertThat(results.get(0).getValue(columnName4).get().getAsInt()).isEqualTo(cKey + 1);
assertThat(results.get(1).getValue(columnName1).isPresent()).isTrue();
assertThat(results.get(1).getValue(columnName1).get().getAsInt()).isEqualTo(0);
assertThat(results.get(1).getValue(columnName4).isPresent()).isTrue();
assertThat(results.get(1).getValue(columnName4).get().getAsInt()).isEqualTo(cKey + 2);
}
use of com.scalar.db.api.Delete 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.Delete in project scalardb by scalar-labs.
the class StorageWithReservedKeywordIntegrationTestBase method prepareDeletes.
private List<Delete> prepareDeletes() {
List<Delete> deletes = new ArrayList<>();
IntStream.range(0, 5).forEach(i -> IntStream.range(0, 3).forEach(j -> {
Key partitionKey = new Key(columnName1, i);
Key clusteringKey = new Key(columnName4, j);
Delete delete = new Delete(partitionKey, clusteringKey);
deletes.add(delete);
}));
return deletes;
}
use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class ConsensusCommitIntegrationTestBase method commit_DeleteGivenForNonExisting_ShouldThrowIllegalArgumentException.
@Test
public void commit_DeleteGivenForNonExisting_ShouldThrowIllegalArgumentException() throws CrudException {
// Arrange
Get get = prepareGet(0, 0, namespace1, TABLE_1);
Delete delete = prepareDelete(0, 0, namespace1, TABLE_1);
ConsensusCommit transaction = manager.start();
// Act Assert
transaction.get(get);
transaction.delete(delete);
assertThatCode(transaction::commit).isInstanceOf(CommitException.class).hasCauseInstanceOf(IllegalArgumentException.class);
}
use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class ConsensusCommitIntegrationTestBase method commit_DeleteGivenForExistingAfterRead_ShouldDeleteRecord.
@Test
public void commit_DeleteGivenForExistingAfterRead_ShouldDeleteRecord() throws CommitException, UnknownTransactionStatusException, CrudException {
// Arrange
populateRecords(namespace1, TABLE_1);
Get get = prepareGet(0, 0, namespace1, TABLE_1);
Delete delete = prepareDelete(0, 0, namespace1, TABLE_1);
ConsensusCommit transaction = manager.start();
// Act
Optional<Result> result = transaction.get(get);
transaction.delete(delete);
transaction.commit();
// Assert
assertThat(result.isPresent()).isTrue();
ConsensusCommit another = manager.start();
assertThat(another.get(get).isPresent()).isFalse();
}
Aggregations