use of com.scalar.db.io.Key in project scalardb by scalar-labs.
the class DistributedStorageWithReservedKeywordIntegrationTestBase method prepareGet.
private Get prepareGet(int pKey, int cKey) {
Key partitionKey = new Key(columnName1, pKey);
Key clusteringKey = new Key(columnName4, cKey);
return new Get(partitionKey, clusteringKey);
}
use of com.scalar.db.io.Key in project scalardb by scalar-labs.
the class DistributedStorageWithReservedKeywordIntegrationTestBase method delete_WithReservedKeywordAndDeleteWithIfGivenWhenSuchRecordExists_ShouldDeleteProperly.
@Test
public void delete_WithReservedKeywordAndDeleteWithIfGivenWhenSuchRecordExists_ShouldDeleteProperly() throws ExecutionException {
// Arrange
populateRecords();
int pKey = 0;
int cKey = 0;
Key partitionKey = new Key(columnName1, pKey);
Key clusteringKey = new Key(columnName4, cKey);
// Act
Delete delete = prepareDelete(pKey, cKey);
delete.withCondition(new DeleteIf(new ConditionalExpression(columnName2, 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 DistributedStorageWithReservedKeywordIntegrationTestBase method put_WithReservedKeywordAndMultiplePutGiven_ShouldStoreProperly.
@Test
public void put_WithReservedKeywordAndMultiplePutGiven_ShouldStoreProperly() throws IOException, ExecutionException {
// Arrange
int pKey = 0;
int cKey = 0;
List<Put> puts = preparePuts();
Scan scan = new Scan(new Key(columnName1, pKey));
// Act
assertThatCode(() -> storage.put(Arrays.asList(puts.get(0), puts.get(1), puts.get(2)))).doesNotThrowAnyException();
// Assert
List<Result> results = scanAll(scan);
assertThat(results.size()).isEqualTo(3);
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(pKey + cKey);
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(pKey + cKey + 1);
assertThat(results.get(2).getValue(columnName1).isPresent()).isTrue();
assertThat(results.get(2).getValue(columnName1).get().getAsInt()).isEqualTo(0);
assertThat(results.get(2).getValue(columnName4).isPresent()).isTrue();
assertThat(results.get(2).getValue(columnName4).get().getAsInt()).isEqualTo(pKey + cKey + 2);
}
use of com.scalar.db.io.Key in project scalardb by scalar-labs.
the class DistributedStorageWithReservedKeywordIntegrationTestBase method scan_WithReservedKeywordAndClusteringKeyRange_ShouldReturnProperResult.
@Test
public void scan_WithReservedKeywordAndClusteringKeyRange_ShouldReturnProperResult() throws ExecutionException, IOException {
// Arrange
populateRecords();
Scan scan = new Scan(new Key(columnName1, 1)).withStart(new Key(columnName4, 1), false).withEnd(new Key(columnName4, 3), false).withOrdering(new Ordering(columnName4, Order.DESC)).forNamespace(namespace).forTable(tableName);
List<Integer> expected = ImmutableList.of(2);
// Act
List<Result> actual = scanAll(scan);
// Assert
assertThat(actual.size()).isEqualTo(1);
assertThat(actual.get(0).getValue(columnName4).isPresent()).isTrue();
assertThat(actual.get(0).getValue(columnName4).get().getAsInt()).isEqualTo(expected.get(0));
}
use of com.scalar.db.io.Key in project scalardb by scalar-labs.
the class DistributedStorageAdminIntegrationTestBase method truncateTable_ShouldTruncateProperly.
@Test
public void truncateTable_ShouldTruncateProperly() throws ExecutionException, IOException {
// Arrange
Key partitionKey = new Key(COL_NAME2, "aaa", COL_NAME1, 1);
Key clusteringKey = new Key(COL_NAME4, 2, COL_NAME3, "bbb");
storage.put(new Put(partitionKey, clusteringKey).withValue(COL_NAME5, 3).withValue(COL_NAME6, "ccc").withValue(COL_NAME7, 4L).withValue(COL_NAME8, 1.0f).withValue(COL_NAME9, 1.0d).withValue(COL_NAME10, true).withValue(COL_NAME11, "ddd".getBytes(StandardCharsets.UTF_8)).forNamespace(namespace1).forTable(TABLE1));
// Act
admin.truncateTable(namespace1, TABLE1);
// Assert
Scanner scanner = storage.scan(new Scan(partitionKey).forNamespace(namespace1).forTable(TABLE1));
assertThat(scanner.all()).isEmpty();
scanner.close();
}
Aggregations