use of com.scalar.db.io.Key in project scalardb by scalar-labs.
the class StorageIntegrationTestBase method scan_ScanWithEndInclusiveRangeGiven_ShouldRetrieveResultsOfGivenRange.
@Test
public void scan_ScanWithEndInclusiveRangeGiven_ShouldRetrieveResultsOfGivenRange() throws IOException, ExecutionException {
// Arrange
populateRecords();
int pKey = 0;
// Act
Scan scan = new Scan(new Key(COL_NAME1, pKey)).withStart(new Key(COL_NAME4, 0), false).withEnd(new Key(COL_NAME4, 2), true);
List<Result> actual = scanAll(scan);
// verify
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(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(2);
}
use of com.scalar.db.io.Key in project scalardb by scalar-labs.
the class StorageIntegrationTestBase method scan_ScanLargeDataWithOrdering_ShouldRetrieveExpectedValues.
@Test
public void scan_ScanLargeDataWithOrdering_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).withOrdering(new Ordering(COL_NAME4, Order.ASC));
// Act
List<Result> results = new ArrayList<>();
try (Scanner scanner = storage.scan(scan)) {
Iterator<Result> iterator = scanner.iterator();
for (int i = 0; i < 234; i++) {
results.add(iterator.next());
}
}
// Assert
assertThat(results.size()).isEqualTo(234);
for (int i = 0; i < 234; i++) {
assertThat(results.get(i).getPartitionKey().isPresent()).isTrue();
assertThat(results.get(i).getClusteringKey().isPresent()).isTrue();
assertThat(results.get(i).getPartitionKey().get().get().get(0).getAsInt()).isEqualTo(1);
assertThat(results.get(i).getClusteringKey().get().get().get(0).getAsInt()).isEqualTo(i);
}
}
use of com.scalar.db.io.Key in project scalardb by scalar-labs.
the class StorageIntegrationTestBase method scan_ScanWithProjectionsGiven_ShouldRetrieveSpecifiedValues.
@Test
public void scan_ScanWithProjectionsGiven_ShouldRetrieveSpecifiedValues() throws IOException, ExecutionException {
// Arrange
populateRecords();
int pKey = 0;
// Act
Scan scan = new Scan(new Key(COL_NAME1, pKey)).withProjection(COL_NAME1).withProjection(COL_NAME2).withProjection(COL_NAME3);
List<Result> actual = scanAll(scan);
// Assert
assertThat(actual.size()).isEqualTo(3);
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(0);
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(1);
assertThat(actual.get(2).getValue(COL_NAME1).isPresent()).isTrue();
assertThat(actual.get(2).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0);
assertThat(actual.get(2).getValue(COL_NAME4).isPresent()).isTrue();
assertThat(actual.get(2).getValue(COL_NAME4).get().getAsInt()).isEqualTo(2);
actual.forEach(a -> {
assertThat(a.getValue(COL_NAME1).isPresent()).isTrue();
assertThat(a.getValue(COL_NAME2).isPresent()).isTrue();
assertThat(a.getValue(COL_NAME3).isPresent()).isTrue();
// since it's clustering key
assertThat(a.getValue(COL_NAME4).isPresent()).isTrue();
assertThat(a.getValue(COL_NAME5).isPresent()).isFalse();
});
}
use of com.scalar.db.io.Key in project scalardb by scalar-labs.
the class StorageIntegrationTestBase method put_IncorrectPutGiven_ShouldThrowIllegalArgumentException.
@Test
public void put_IncorrectPutGiven_ShouldThrowIllegalArgumentException() {
// Arrange
int pKey = 0;
int cKey = 0;
Key partitionKey = new Key(COL_NAME1, pKey);
Put put = new Put(partitionKey).withValue(COL_NAME4, cKey);
// Act Assert
assertThatCode(() -> storage.put(put)).isInstanceOf(IllegalArgumentException.class);
}
use of com.scalar.db.io.Key in project scalardb by scalar-labs.
the class StorageIntegrationTestBase method delete_DeleteWithIfExistsGivenWhenSuchRecordExists_ShouldDeleteProperly.
@Test
public void delete_DeleteWithIfExistsGivenWhenSuchRecordExists_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 DeleteIfExists());
assertThatCode(() -> storage.delete(delete)).doesNotThrowAnyException();
// Assert
Optional<Result> actual = storage.get(new Get(partitionKey, clusteringKey));
assertThat(actual.isPresent()).isFalse();
}
Aggregations