use of com.scalar.db.io.Key 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.io.Key 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.io.Key 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)));
}
use of com.scalar.db.io.Key in project scalardb by scalar-labs.
the class StorageIntegrationTestBase 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(COL_NAME1, i);
Key clusteringKey = new Key(COL_NAME4, j);
Delete delete = new Delete(partitionKey, clusteringKey);
deletes.add(delete);
}));
return deletes;
}
use of com.scalar.db.io.Key in project scalardb by scalar-labs.
the class StorageIntegrationTestBase method prepareDelete.
private Delete prepareDelete(int pKey, int cKey) {
Key partitionKey = new Key(COL_NAME1, pKey);
Key clusteringKey = new Key(COL_NAME4, cKey);
return new Delete(partitionKey, clusteringKey);
}
Aggregations