Search in sources :

Example 6 with Result

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);
}
Also used : ArrayList(java.util.ArrayList) Result(com.scalar.db.api.Result)

Example 7 with Result

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));
}
Also used : Scan(com.scalar.db.api.Scan) Result(com.scalar.db.api.Result)

Example 8 with Result

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));
}
Also used : Scan(com.scalar.db.api.Scan) Result(com.scalar.db.api.Result)

Example 9 with Result

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();
            }
        }
    }
}
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 10 with Result

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

Aggregations

Result (com.scalar.db.api.Result)324 Test (org.junit.Test)158 Get (com.scalar.db.api.Get)132 Scan (com.scalar.db.api.Scan)106 Put (com.scalar.db.api.Put)101 Key (com.scalar.db.io.Key)85 Test (org.junit.jupiter.api.Test)83 GrpcTransaction (com.scalar.db.transaction.rpc.GrpcTransaction)39 IntValue (com.scalar.db.io.IntValue)36 GrpcTwoPhaseCommitTransaction (com.scalar.db.transaction.rpc.GrpcTwoPhaseCommitTransaction)32 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)29 Delete (com.scalar.db.api.Delete)28 TextValue (com.scalar.db.io.TextValue)24 Value (com.scalar.db.io.Value)19 BigIntValue (com.scalar.db.io.BigIntValue)16 Scanner (com.scalar.db.api.Scanner)15 ArrayList (java.util.ArrayList)14 BooleanValue (com.scalar.db.io.BooleanValue)11 ConditionalExpression (com.scalar.db.api.ConditionalExpression)10 ScanAll (com.scalar.db.api.ScanAll)9