Search in sources :

Example 26 with Key

use of com.scalar.db.io.Key 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 27 with Key

use of com.scalar.db.io.Key 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 28 with Key

use of com.scalar.db.io.Key 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 29 with Key

use of com.scalar.db.io.Key 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 30 with Key

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

the class AdminIntegrationTestBase method truncateTable_ShouldTruncateProperly.

@Test
public void truncateTable_ShouldTruncateProperly() throws ExecutionException, IOException {
    // Arrange
    Key partitionKey = new Key(COL_NAME2, "aaa", COL_NAME1, 1);
    Key clusteringKey = new Key(COL_NAME4, 2, COL_NAME3, "bbb");
    storage.put(new Put(partitionKey, clusteringKey).withValue(COL_NAME5, 3).withValue(COL_NAME6, "ccc").withValue(COL_NAME7, 4L).withValue(COL_NAME8, 1.0f).withValue(COL_NAME9, 1.0d).withValue(COL_NAME10, true).withValue(COL_NAME11, "ddd".getBytes(StandardCharsets.UTF_8)).forNamespace(namespace1).forTable(TABLE1));
    // Act
    admin.truncateTable(namespace1, TABLE1);
    // Assert
    Scanner scanner = storage.scan(new Scan(partitionKey).forNamespace(namespace1).forTable(TABLE1));
    assertThat(scanner.all()).isEmpty();
    scanner.close();
}
Also used : Scanner(com.scalar.db.api.Scanner) Scan(com.scalar.db.api.Scan) Key(com.scalar.db.io.Key) Put(com.scalar.db.api.Put) Test(org.junit.Test)

Aggregations

Key (com.scalar.db.io.Key)603 Test (org.junit.jupiter.api.Test)391 Put (com.scalar.db.api.Put)211 Scan (com.scalar.db.api.Scan)145 Get (com.scalar.db.api.Get)134 Delete (com.scalar.db.api.Delete)118 Result (com.scalar.db.api.Result)94 Test (org.junit.Test)90 TextValue (com.scalar.db.io.TextValue)88 IntValue (com.scalar.db.io.IntValue)81 BooleanValue (com.scalar.db.io.BooleanValue)51 HashMap (java.util.HashMap)42 ExpectedResult (com.scalar.db.util.TestUtils.ExpectedResult)40 ArrayList (java.util.ArrayList)39 Value (com.scalar.db.io.Value)38 DoubleValue (com.scalar.db.io.DoubleValue)35 AttributeValue (software.amazon.awssdk.services.dynamodb.model.AttributeValue)31 QueryRequest (software.amazon.awssdk.services.dynamodb.model.QueryRequest)29 KeyBytesEncoder (com.scalar.db.storage.dynamo.bytes.KeyBytesEncoder)27 ByteBuffer (java.nio.ByteBuffer)27