use of com.scalar.db.io.DataType in project scalardb by scalar-labs.
the class StorageMultipleClusteringKeyScanIntegrationTestBase method execute.
private void execute(TestForSecondClusteringKeyScan test) throws java.util.concurrent.ExecutionException, InterruptedException {
List<Callable<Void>> testCallables = new ArrayList<>();
for (DataType firstClusteringKeyType : clusteringKeyTypes.keySet()) {
for (DataType secondClusteringKeyType : clusteringKeyTypes.get(firstClusteringKeyType)) {
for (Order firstClusteringOrder : Order.values()) {
for (Order secondClusteringOrder : Order.values()) {
testCallables.add(() -> {
truncateTable(firstClusteringKeyType, firstClusteringOrder, secondClusteringKeyType, secondClusteringOrder);
List<ClusteringKey> clusteringKeys = prepareRecords(firstClusteringKeyType, firstClusteringOrder, secondClusteringKeyType, secondClusteringOrder);
test.execute(clusteringKeys, firstClusteringKeyType, firstClusteringOrder, secondClusteringKeyType, secondClusteringOrder);
return null;
});
}
}
}
}
execute(testCallables);
}
use of com.scalar.db.io.DataType in project scalardb by scalar-labs.
the class StorageMultiplePartitionKeyIntegrationTestBase method deleteTables.
private static void deleteTables() throws java.util.concurrent.ExecutionException, InterruptedException {
List<Callable<Void>> testCallables = new ArrayList<>();
for (DataType firstPartitionKeyType : partitionKeyTypes.keySet()) {
Callable<Void> testCallable = () -> {
for (DataType secondPartitionKeyType : partitionKeyTypes.get(firstPartitionKeyType)) {
admin.dropTable(getNamespaceName(firstPartitionKeyType), getTableName(firstPartitionKeyType, secondPartitionKeyType));
}
admin.dropNamespace(getNamespaceName(firstPartitionKeyType));
return null;
};
testCallables.add(testCallable);
}
// We firstly execute the callables without the last one. And then we execute the last one. This
// is because the last table deletion deletes the metadata table, and this process can't be
// handled in multiple threads/processes at the same time.
execute(testCallables.subList(0, testCallables.size() - 1));
execute(testCallables.subList(testCallables.size() - 1, testCallables.size()));
}
use of com.scalar.db.io.DataType 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.io.DataType in project scalardb by scalar-labs.
the class StorageSecondaryIndexIntegrationTestBase method scan_WithMaxSecondaryIndexValue_ShouldReturnProperResult.
@Test
public void scan_WithMaxSecondaryIndexValue_ShouldReturnProperResult() throws ExecutionException, IOException {
for (DataType secondaryIndexType : secondaryIndexTypes) {
truncateTable(secondaryIndexType);
// Arrange
Value<?> secondaryIndexValue = getMaxValue(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.DataType in project scalardb by scalar-labs.
the class StorageSecondaryIndexIntegrationTestBase method scan_WithRandomSecondaryIndexValue_ShouldReturnProperResult.
@Test
public void scan_WithRandomSecondaryIndexValue_ShouldReturnProperResult() throws ExecutionException, IOException {
RANDOM.setSeed(seed);
for (DataType secondaryIndexType : secondaryIndexTypes) {
truncateTable(secondaryIndexType);
for (int i = 0; i < ATTEMPT_COUNT; i++) {
// Arrange
Value<?> secondaryIndexValue = getRandomValue(RANDOM, 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);
}
}
}
Aggregations