use of com.scalar.db.api.Result 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.Result 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.Result 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);
}
use of com.scalar.db.api.Result in project scalardb by scalar-labs.
the class StorageIntegrationTestBase method scan_ScanLargeData_ShouldRetrieveExpectedValues.
@Test
public void scan_ScanLargeData_ShouldRetrieveExpectedValues() throws ExecutionException, IOException {
// Arrange
Key partitionKey = new Key(COL_NAME1, 1);
for (int i = 0; i < 345; i++) {
Key clusteringKey = new Key(COL_NAME4, i);
storage.put(new Put(partitionKey, clusteringKey));
}
Scan scan = new Scan(partitionKey);
// Act
List<Result> results = scanAll(scan);
// Assert
assertThat(results.size()).isEqualTo(345);
for (int i = 0; i < 345; i++) {
assertThat(results.get(i).getValue(COL_NAME1).isPresent()).isTrue();
assertThat(results.get(i).getValue(COL_NAME1).get().getAsInt()).isEqualTo(1);
assertThat(results.get(i).getValue(COL_NAME4).isPresent()).isTrue();
assertThat(results.get(i).getValue(COL_NAME4).get().getAsInt()).isEqualTo(i);
}
}
use of com.scalar.db.api.Result in project scalardb by scalar-labs.
the class StorageIntegrationTestBase method put_MultiplePutWithIfNotExistsGivenWhenOneExists_ShouldThrowNoMutationException.
@Test
public void put_MultiplePutWithIfNotExistsGivenWhenOneExists_ShouldThrowNoMutationException() throws IOException, ExecutionException {
// Arrange
int pKey = 0;
int cKey = 0;
List<Put> puts = preparePuts();
assertThatCode(() -> storage.put(puts.get(0))).doesNotThrowAnyException();
puts.get(0).withCondition(new PutIfNotExists());
puts.get(1).withCondition(new PutIfNotExists());
puts.get(2).withCondition(new PutIfNotExists());
Scan scan = new Scan(new Key(COL_NAME1, pKey));
// Act
assertThatThrownBy(() -> storage.put(Arrays.asList(puts.get(0), puts.get(1), puts.get(2)))).isInstanceOf(NoMutationException.class);
// Assert
List<Result> results = scanAll(scan);
assertThat(results.size()).isEqualTo(1);
assertThat(results.get(0).getValue(COL_NAME4)).isEqualTo(Optional.of(new IntValue(COL_NAME4, pKey + cKey)));
}
Aggregations