use of com.scalar.db.api.Result in project scalardb by scalar-labs.
the class StorageMultipleClusteringKeyScanIntegrationTestBase method assertScanResult.
private void assertScanResult(List<Result> actualResults, List<ClusteringKey> expected, String description) {
List<ClusteringKey> actual = new ArrayList<>();
for (Result actualResult : actualResults) {
assertThat(actualResult.getValue(FIRST_CLUSTERING_KEY).isPresent()).isTrue();
assertThat(actualResult.getValue(SECOND_CLUSTERING_KEY).isPresent()).isTrue();
actual.add(new ClusteringKey(actualResult.getValue(FIRST_CLUSTERING_KEY).get(), actualResult.getValue(SECOND_CLUSTERING_KEY).get()));
}
assertThat(actual).describedAs(description).isEqualTo(expected);
}
use of com.scalar.db.api.Result in project scalardb by scalar-labs.
the class StorageMultipleClusteringKeyScanIntegrationTestBase method scan_WithFirstClusteringKeyStartRange_ShouldReturnProperResult.
private void scan_WithFirstClusteringKeyStartRange_ShouldReturnProperResult(List<ClusteringKey> clusteringKeys, DataType firstClusteringKeyType, Order firstClusteringOrder, boolean startInclusive, OrderingType orderingType, boolean withLimit) throws ExecutionException, IOException {
// Arrange
ClusteringKey startClusteringKey;
if (firstClusteringKeyType == DataType.BOOLEAN) {
startClusteringKey = new ClusteringKey(clusteringKeys.get(getFirstClusteringKeyIndex(0, DataType.INT)).first);
} else {
startClusteringKey = new ClusteringKey(clusteringKeys.get(getFirstClusteringKeyIndex(1, DataType.INT)).first);
}
List<ClusteringKey> expected = getExpected(clusteringKeys, startClusteringKey, startInclusive, null, null, orderingType);
int limit = getLimit(withLimit, expected);
if (limit > 0) {
expected = expected.subList(0, limit);
}
Scan scan = getScan(firstClusteringKeyType, firstClusteringOrder, DataType.INT, Order.ASC, startClusteringKey, startInclusive, null, null, orderingType, limit);
// Act
List<Result> actual = scanAll(scan);
// Assert
assertScanResult(actual, expected, description(firstClusteringKeyType, firstClusteringOrder, null, null, startInclusive, null, orderingType, withLimit));
}
use of com.scalar.db.api.Result in project scalardb by scalar-labs.
the class StorageMultipleClusteringKeyScanIntegrationTestBase method scan_WithFirstClusteringKeyRangeWithMinAndMaxValue_ShouldReturnProperResult.
private void scan_WithFirstClusteringKeyRangeWithMinAndMaxValue_ShouldReturnProperResult(List<ClusteringKey> clusteringKeys, DataType firstClusteringKeyType, Order firstClusteringOrder, boolean startInclusive, boolean endInclusive, OrderingType orderingType, boolean withLimit) throws ExecutionException, IOException {
// Arrange
ClusteringKey startClusteringKey = new ClusteringKey(getMinValue(FIRST_CLUSTERING_KEY, firstClusteringKeyType));
ClusteringKey endClusteringKey = new ClusteringKey(getMaxValue(FIRST_CLUSTERING_KEY, firstClusteringKeyType));
List<ClusteringKey> expected = getExpected(clusteringKeys, startClusteringKey, startInclusive, endClusteringKey, endInclusive, orderingType);
int limit = getLimit(withLimit, expected);
if (limit > 0) {
expected = expected.subList(0, limit);
}
Scan scan = getScan(firstClusteringKeyType, firstClusteringOrder, DataType.INT, Order.ASC, startClusteringKey, startInclusive, endClusteringKey, endInclusive, orderingType, limit);
// Act
List<Result> actual = scanAll(scan);
// Assert
assertScanResult(actual, expected, description(firstClusteringKeyType, firstClusteringOrder, null, null, startInclusive, endInclusive, orderingType, withLimit));
}
use of com.scalar.db.api.Result in project scalardb by scalar-labs.
the class StorageMultiplePartitionKeyIntegrationTestBase method getAndDelete_ShouldBehaveCorrectly.
@Test
public void getAndDelete_ShouldBehaveCorrectly() throws ExecutionException {
for (DataType firstPartitionKeyType : partitionKeyTypes.keySet()) {
for (DataType secondPartitionKeyType : partitionKeyTypes.get(firstPartitionKeyType)) {
truncateTable(firstPartitionKeyType, secondPartitionKeyType);
List<PartitionKey> partitionKeys = prepareRecords(firstPartitionKeyType, secondPartitionKeyType);
String description = description(firstPartitionKeyType, secondPartitionKeyType);
// for get
for (PartitionKey partitionKey : partitionKeys) {
// Arrange
Get get = prepareGet(firstPartitionKeyType, partitionKey.first, secondPartitionKeyType, partitionKey.second);
// Act
Optional<Result> result = storage.get(get);
// Assert
Assertions.assertThat(result).describedAs(description).isPresent();
Assertions.assertThat(result.get().getValue(FIRST_PARTITION_KEY).isPresent()).describedAs(description).isTrue();
Assertions.assertThat(result.get().getValue(FIRST_PARTITION_KEY).get()).describedAs(description).isEqualTo(partitionKey.first);
Assertions.assertThat(result.get().getValue(SECOND_PARTITION_KEY).isPresent()).describedAs(description).isTrue();
Assertions.assertThat(result.get().getValue(SECOND_PARTITION_KEY).get()).describedAs(description).isEqualTo(partitionKey.second);
Assertions.assertThat(result.get().getValue(COL_NAME).isPresent()).describedAs(description).isTrue();
Assertions.assertThat(result.get().getValue(COL_NAME).get().getAsInt()).describedAs(description).isEqualTo(1);
}
// for delete
for (PartitionKey partitionKey : partitionKeys) {
// Arrange
Delete delete = prepareDelete(firstPartitionKeyType, partitionKey.first, secondPartitionKeyType, partitionKey.second);
// Act
storage.delete(delete);
// Assert
Optional<Result> result = storage.get(prepareGet(firstPartitionKeyType, partitionKey.first, secondPartitionKeyType, partitionKey.second));
Assertions.assertThat(result).describedAs(description).isNotPresent();
}
}
}
}
use of com.scalar.db.api.Result in project scalardb by scalar-labs.
the class StorageIntegrationTestBase method scan_ScanWithLimitGiven_ShouldReturnGivenNumberOfResults.
@Test
public void scan_ScanWithLimitGiven_ShouldReturnGivenNumberOfResults() throws IOException, ExecutionException {
// setup
List<Put> puts = preparePuts();
storage.mutate(Arrays.asList(puts.get(0), puts.get(1), puts.get(2)));
Scan scan = new Scan(new Key(COL_NAME1, 0)).withOrdering(new Scan.Ordering(COL_NAME4, Scan.Ordering.Order.DESC)).withLimit(1);
// exercise
List<Result> actual = scanAll(scan);
// verify
assertThat(actual.size()).isEqualTo(1);
assertThat(actual.get(0).getValue(COL_NAME4)).isEqualTo(Optional.of(new IntValue(COL_NAME4, 2)));
}
Aggregations