Search in sources :

Example 31 with DataType

use of com.scalar.db.io.DataType in project scalardb by scalar-labs.

the class DistributedStorageMultiplePartitionKeyIntegrationTestBase method dropTables.

private void dropTables() 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.
    executeInParallel(testCallables.subList(0, testCallables.size() - 1));
    executeInParallel(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 32 with DataType

use of com.scalar.db.io.DataType in project scalardb by scalar-labs.

the class DistributedStorageMultiplePartitionKeyIntegrationTestBase 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 : DataType(com.scalar.db.io.DataType) Test(org.junit.jupiter.api.Test)

Example 33 with DataType

use of com.scalar.db.io.DataType in project scalardb by scalar-labs.

the class DistributedStorageMultiplePartitionKeyIntegrationTestBase method createTables.

private void createTables() throws java.util.concurrent.ExecutionException, InterruptedException {
    List<Callable<Void>> testCallables = new ArrayList<>();
    Map<String, String> options = getCreateOptions();
    for (DataType firstPartitionKeyType : partitionKeyTypes.keySet()) {
        Callable<Void> testCallable = () -> {
            admin.createNamespace(getNamespaceName(firstPartitionKeyType), true, options);
            for (DataType secondPartitionKeyType : partitionKeyTypes.get(firstPartitionKeyType)) {
                createTable(firstPartitionKeyType, secondPartitionKeyType, options);
            }
            return null;
        };
        testCallables.add(testCallable);
    }
    // We firstly execute the first one and then the rest. This is because the first table creation
    // creates the metadata table, and this process can't be handled in multiple threads/processes
    // at the same time.
    executeInParallel(testCallables.subList(0, 1));
    executeInParallel(testCallables.subList(1, testCallables.size()));
}
Also used : ArrayList(java.util.ArrayList) DataType(com.scalar.db.io.DataType) Callable(java.util.concurrent.Callable)

Example 34 with DataType

use of com.scalar.db.io.DataType in project scalardb by scalar-labs.

the class DistributedStorageSecondaryIndexIntegrationTestBase 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) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 35 with DataType

use of com.scalar.db.io.DataType in project scalardb by scalar-labs.

the class DistributedStorageSecondaryIndexIntegrationTestBase 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) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.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