use of com.scalar.db.io.Key in project scalardb by scalar-labs.
the class StorageIntegrationTestBase method put_PutWithoutValuesGiven_ShouldStoreProperly.
@Test
public void put_PutWithoutValuesGiven_ShouldStoreProperly() throws ExecutionException {
// Arrange
Key partitionKey = new Key(COL_NAME1, 0);
Key clusteringKey = new Key(COL_NAME4, 0);
// Act
assertThatCode(() -> storage.put(new Put(partitionKey, clusteringKey))).doesNotThrowAnyException();
// Assert
Optional<Result> result = storage.get(new Get(partitionKey, clusteringKey));
assertThat(result).isPresent();
}
use of com.scalar.db.io.Key in project scalardb by scalar-labs.
the class StorageIntegrationTestBase method preparePuts.
private List<Put> preparePuts() {
List<Put> puts = 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);
Put put = new Put(partitionKey, clusteringKey).withValue(COL_NAME2, Integer.toString(i + j)).withValue(COL_NAME3, i + j).withValue(COL_NAME5, j % 2 == 0);
puts.add(put);
}));
return puts;
}
use of com.scalar.db.io.Key in project scalardb by scalar-labs.
the class StorageIntegrationTestBase method mutate_SinglePutGiven_ShouldStoreProperly.
@Test
public void mutate_SinglePutGiven_ShouldStoreProperly() throws ExecutionException {
// Arrange
int pKey = 0;
int cKey = 0;
List<Put> puts = preparePuts();
Key partitionKey = new Key(COL_NAME1, pKey);
Key clusteringKey = new Key(COL_NAME4, cKey);
Get get = new Get(partitionKey, clusteringKey);
// Act
storage.mutate(Collections.singletonList(puts.get(pKey * 2 + cKey)));
// Assert
Optional<Result> actual = storage.get(get);
assertThat(actual.isPresent()).isTrue();
assertThat(actual.get().getValue(COL_NAME1)).isEqualTo(Optional.of(new IntValue(COL_NAME1, pKey)));
assertThat(actual.get().getValue(COL_NAME2)).isEqualTo(Optional.of(new TextValue(COL_NAME2, Integer.toString(pKey + cKey))));
assertThat(actual.get().getValue(COL_NAME3)).isEqualTo(Optional.of(new IntValue(COL_NAME3, pKey + cKey)));
assertThat(actual.get().getValue(COL_NAME4)).isEqualTo(Optional.of(new IntValue(COL_NAME4, cKey)));
assertThat(actual.get().getValue(COL_NAME5)).isEqualTo(Optional.of(new BooleanValue(COL_NAME5, cKey % 2 == 0)));
}
use of com.scalar.db.io.Key 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.io.Key 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);
}
Aggregations