use of com.scalar.db.io.Key in project scalardb by scalar-labs.
the class DistributedStorageIntegrationTestBase 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).withBlobValue(COL_NAME6, new byte[5000]));
}
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 DistributedStorageSecondaryIndexIntegrationTestBase method scan_WithMinSecondaryIndexValue_ShouldReturnProperResult.
@Test
public void scan_WithMinSecondaryIndexValue_ShouldReturnProperResult() throws ExecutionException, IOException {
for (DataType secondaryIndexType : secondaryIndexTypes) {
truncateTable(secondaryIndexType);
// Arrange
Value<?> secondaryIndexValue = getMinValue(INDEX_COL_NAME, secondaryIndexType);
prepareRecords(secondaryIndexType, secondaryIndexValue);
Scan scan = new Scan(new Key(secondaryIndexValue)).forNamespace(namespace).forTable(getTableName(secondaryIndexType));
// Act
List<Result> results = scanAll(scan);
// Assert
assertResults(results, secondaryIndexValue);
}
}
use of com.scalar.db.io.Key in project scalardb by scalar-labs.
the class DistributedStorageWithReservedKeywordIntegrationTestBase method delete_WithReservedKeywordAndDeleteWithPartitionKeyAndClusteringKeyGiven_ShouldDeleteSingleRecordProperly.
@Test
public void delete_WithReservedKeywordAndDeleteWithPartitionKeyAndClusteringKeyGiven_ShouldDeleteSingleRecordProperly() throws IOException, ExecutionException {
// Arrange
populateRecords();
int pKey = 0;
int cKey = 0;
Key partitionKey = new Key(columnName1, pKey);
// Act
Delete delete = prepareDelete(pKey, cKey);
assertThatCode(() -> storage.delete(delete)).doesNotThrowAnyException();
// Assert
List<Result> results = scanAll(new Scan(partitionKey));
assertThat(results.size()).isEqualTo(2);
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(cKey + 1);
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(cKey + 2);
}
use of com.scalar.db.io.Key in project scalardb by scalar-labs.
the class DistributedStorageWithReservedKeywordIntegrationTestBase method scan_WithReservedKeywordAndScanGivenForIndexedColumn_ShouldScan.
@Test
public void scan_WithReservedKeywordAndScanGivenForIndexedColumn_ShouldScan() throws ExecutionException, IOException {
// Arrange
populateRecords();
int c3 = 3;
Scan scan = new Scan(new Key(columnName3, c3));
// Act
List<Result> actual = scanAll(scan);
// Assert
// (1,2), (2,1), (3,0)
assertThat(actual.size()).isEqualTo(3);
List<List<Integer>> expectedValues = new ArrayList<>(Arrays.asList(Arrays.asList(1, 2), Arrays.asList(2, 1), Arrays.asList(3, 0)));
for (Result result : actual) {
assertThat(result.getValue(columnName1).isPresent()).isTrue();
assertThat(result.getValue(columnName4).isPresent()).isTrue();
int col1Val = result.getValue(columnName1).get().getAsInt();
int col4Val = result.getValue(columnName4).get().getAsInt();
List<Integer> col1AndCol4 = Arrays.asList(col1Val, col4Val);
assertThat(expectedValues).contains(col1AndCol4);
expectedValues.remove(col1AndCol4);
}
assertThat(expectedValues).isEmpty();
}
use of com.scalar.db.io.Key in project scalardb by scalar-labs.
the class DistributedStorageWithReservedKeywordIntegrationTestBase 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(columnName1, i);
Key clusteringKey = new Key(columnName4, j);
Delete delete = new Delete(partitionKey, clusteringKey);
deletes.add(delete);
}));
return deletes;
}
Aggregations