Search in sources :

Example 1 with DataType

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);
}
Also used : Order(com.scalar.db.api.Scan.Ordering.Order) ArrayList(java.util.ArrayList) DataType(com.scalar.db.io.DataType) Callable(java.util.concurrent.Callable)

Example 2 with DataType

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()));
}
Also used : ArrayList(java.util.ArrayList) DataType(com.scalar.db.io.DataType) Callable(java.util.concurrent.Callable)

Example 3 with DataType

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();
            }
        }
    }
}
Also used : Delete(com.scalar.db.api.Delete) Get(com.scalar.db.api.Get) DataType(com.scalar.db.io.DataType) Result(com.scalar.db.api.Result) Test(org.junit.Test)

Example 4 with DataType

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);
    }
}
Also used : DataType(com.scalar.db.io.DataType) Scan(com.scalar.db.api.Scan) Key(com.scalar.db.io.Key) Result(com.scalar.db.api.Result) Test(org.junit.Test)

Example 5 with DataType

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);
        }
    }
}
Also used : DataType(com.scalar.db.io.DataType) Scan(com.scalar.db.api.Scan) Key(com.scalar.db.io.Key) Result(com.scalar.db.api.Result) Test(org.junit.Test)

Aggregations

DataType (com.scalar.db.io.DataType)52 Order (com.scalar.db.api.Scan.Ordering.Order)30 Value (com.scalar.db.io.Value)18 Test (org.junit.jupiter.api.Test)16 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)12 Callable (java.util.concurrent.Callable)12 Key (com.scalar.db.io.Key)6 Result (com.scalar.db.api.Result)5 Scan (com.scalar.db.api.Scan)3 Delete (com.scalar.db.api.Delete)2 Get (com.scalar.db.api.Get)2 TableMetadata (com.scalar.db.api.TableMetadata)2 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 Ordering (com.scalar.db.api.Scan.Ordering)1 ExecutionException (com.scalar.db.exception.storage.ExecutionException)1 BigIntValue (com.scalar.db.io.BigIntValue)1 BlobValue (com.scalar.db.io.BlobValue)1