Search in sources :

Example 21 with Scan

use of com.scalar.db.api.Scan in project scalardb by scalar-labs.

the class StorageIntegrationTestBase method mutate_MultiplePutGiven_ShouldStoreProperly.

@Test
public void mutate_MultiplePutGiven_ShouldStoreProperly() throws ExecutionException, IOException {
    // Arrange
    int pKey = 0;
    int cKey = 0;
    List<Put> puts = preparePuts();
    Scan scan = new Scan(new Key(COL_NAME1, pKey));
    // Act
    assertThatCode(() -> storage.mutate(Arrays.asList(puts.get(0), puts.get(1), puts.get(2)))).doesNotThrowAnyException();
    // Assert
    List<Result> results = scanAll(scan);
    assertThat(results.size()).isEqualTo(3);
    assertThat(results.get(0).getValue(COL_NAME1).isPresent()).isTrue();
    assertThat(results.get(0).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0);
    assertThat(results.get(0).getValue(COL_NAME4).isPresent()).isTrue();
    assertThat(results.get(0).getValue(COL_NAME4).get().getAsInt()).isEqualTo(pKey + cKey);
    assertThat(results.get(1).getValue(COL_NAME1).isPresent()).isTrue();
    assertThat(results.get(1).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0);
    assertThat(results.get(1).getValue(COL_NAME4).isPresent()).isTrue();
    assertThat(results.get(1).getValue(COL_NAME4).get().getAsInt()).isEqualTo(pKey + cKey + 1);
    assertThat(results.get(2).getValue(COL_NAME1).isPresent()).isTrue();
    assertThat(results.get(2).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0);
    assertThat(results.get(2).getValue(COL_NAME4).isPresent()).isTrue();
    assertThat(results.get(2).getValue(COL_NAME4).get().getAsInt()).isEqualTo(pKey + cKey + 2);
}
Also used : Scan(com.scalar.db.api.Scan) Put(com.scalar.db.api.Put) Key(com.scalar.db.io.Key) Result(com.scalar.db.api.Result) Test(org.junit.Test)

Example 22 with Scan

use of com.scalar.db.api.Scan 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 23 with Scan

use of com.scalar.db.api.Scan 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)

Example 24 with Scan

use of com.scalar.db.api.Scan in project scalardb by scalar-labs.

the class StorageSecondaryIndexIntegrationTestBase 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);
    }
}
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 25 with Scan

use of com.scalar.db.api.Scan in project scalardb by scalar-labs.

the class StorageSingleClusteringKeyScanIntegrationTestBase method scan_WithClusteringKeyEndRange_ShouldReturnProperResult.

private void scan_WithClusteringKeyEndRange_ShouldReturnProperResult(List<Value<?>> clusteringKeyValues, DataType clusteringKeyType, Order clusteringOrder, boolean endInclusive, OrderingType orderingType, boolean withLimit) throws ExecutionException, IOException {
    // Arrange
    Value<?> endClusteringKeyValue;
    if (clusteringKeyType == DataType.BOOLEAN) {
        endClusteringKeyValue = clusteringKeyValues.get(1);
    } else {
        endClusteringKeyValue = clusteringKeyValues.get(14);
    }
    List<Value<?>> expected = getExpected(clusteringKeyValues, null, null, endClusteringKeyValue, endInclusive, orderingType);
    int limit = getLimit(withLimit, expected);
    if (limit > 0) {
        expected = expected.subList(0, limit);
    }
    Scan scan = getScan(clusteringKeyType, clusteringOrder, null, null, endClusteringKeyValue, endInclusive, orderingType, limit);
    // Act
    List<Result> actual = scanAll(scan);
    // Assert
    assertScanResult(actual, expected, description(clusteringKeyType, clusteringOrder, null, endInclusive, orderingType, withLimit));
}
Also used : Value(com.scalar.db.io.Value) Scan(com.scalar.db.api.Scan) Result(com.scalar.db.api.Result)

Aggregations

Scan (com.scalar.db.api.Scan)241 Key (com.scalar.db.io.Key)137 Test (org.junit.jupiter.api.Test)125 Result (com.scalar.db.api.Result)105 Test (org.junit.Test)72 Put (com.scalar.db.api.Put)37 HashMap (java.util.HashMap)32 QueryRequest (software.amazon.awssdk.services.dynamodb.model.QueryRequest)32 AttributeValue (software.amazon.awssdk.services.dynamodb.model.AttributeValue)31 ByteBuffer (java.nio.ByteBuffer)27 KeyBytesEncoder (com.scalar.db.storage.dynamo.bytes.KeyBytesEncoder)26 Scanner (com.scalar.db.api.Scanner)17 CosmosQueryRequestOptions (com.azure.cosmos.models.CosmosQueryRequestOptions)14 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)13 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)13 PartitionKey (com.azure.cosmos.models.PartitionKey)11 ArrayList (java.util.ArrayList)11 Delete (com.scalar.db.api.Delete)9 Value (com.scalar.db.io.Value)8 ConditionalExpression (com.scalar.db.api.ConditionalExpression)7