Search in sources :

Example 36 with Scan

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

the class StorageWithReservedKeywordIntegrationTestBase method put_WithReservedKeywordAndMultiplePutGiven_ShouldStoreProperly.

@Test
public void put_WithReservedKeywordAndMultiplePutGiven_ShouldStoreProperly() throws IOException, ExecutionException {
    // Arrange
    int pKey = 0;
    int cKey = 0;
    List<Put> puts = preparePuts();
    Scan scan = new Scan(new Key(columnName1, pKey));
    // Act
    assertThatCode(() -> storage.put(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(columnName1).isPresent()).isTrue();
    assertThat(results.get(0).getValue(columnName1).get().getAsInt()).isEqualTo(0);
    assertThat(results.get(0).getValue(columnName4).isPresent()).isTrue();
    assertThat(results.get(0).getValue(columnName4).get().getAsInt()).isEqualTo(pKey + cKey);
    assertThat(results.get(1).getValue(columnName1).isPresent()).isTrue();
    assertThat(results.get(1).getValue(columnName1).get().getAsInt()).isEqualTo(0);
    assertThat(results.get(1).getValue(columnName4).isPresent()).isTrue();
    assertThat(results.get(1).getValue(columnName4).get().getAsInt()).isEqualTo(pKey + cKey + 1);
    assertThat(results.get(2).getValue(columnName1).isPresent()).isTrue();
    assertThat(results.get(2).getValue(columnName1).get().getAsInt()).isEqualTo(0);
    assertThat(results.get(2).getValue(columnName4).isPresent()).isTrue();
    assertThat(results.get(2).getValue(columnName4).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 37 with Scan

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

the class StorageWithReservedKeywordIntegrationTestBase method scan_ScanWithReservedKeywordAndProjectionsGiven_ShouldRetrieveSpecifiedValues.

@Test
public void scan_ScanWithReservedKeywordAndProjectionsGiven_ShouldRetrieveSpecifiedValues() throws IOException, ExecutionException {
    // Arrange
    populateRecords();
    int pKey = 0;
    // Act
    Scan scan = new Scan(new Key(columnName1, pKey)).withProjection(columnName1).withProjection(columnName2).withProjection(columnName3);
    List<Result> actual = scanAll(scan);
    // Assert
    assertThat(actual.size()).isEqualTo(3);
    assertThat(actual.get(0).getValue(columnName1).isPresent()).isTrue();
    assertThat(actual.get(0).getValue(columnName1).get().getAsInt()).isEqualTo(0);
    assertThat(actual.get(0).getValue(columnName4).isPresent()).isTrue();
    assertThat(actual.get(0).getValue(columnName4).get().getAsInt()).isEqualTo(0);
    assertThat(actual.get(1).getValue(columnName1).isPresent()).isTrue();
    assertThat(actual.get(1).getValue(columnName1).get().getAsInt()).isEqualTo(0);
    assertThat(actual.get(1).getValue(columnName4).isPresent()).isTrue();
    assertThat(actual.get(1).getValue(columnName4).get().getAsInt()).isEqualTo(1);
    assertThat(actual.get(2).getValue(columnName1).isPresent()).isTrue();
    assertThat(actual.get(2).getValue(columnName1).get().getAsInt()).isEqualTo(0);
    assertThat(actual.get(2).getValue(columnName4).isPresent()).isTrue();
    assertThat(actual.get(2).getValue(columnName4).get().getAsInt()).isEqualTo(2);
    actual.forEach(a -> {
        assertThat(a.getValue(columnName1).isPresent()).isTrue();
        assertThat(a.getValue(columnName2).isPresent()).isTrue();
        assertThat(a.getValue(columnName3).isPresent()).isTrue();
        // since it's clustering key
        assertThat(a.getValue(columnName4).isPresent()).isTrue();
        assertThat(a.getValue(columnName5).isPresent()).isFalse();
    });
}
Also used : Scan(com.scalar.db.api.Scan) Key(com.scalar.db.io.Key) Result(com.scalar.db.api.Result) Test(org.junit.Test)

Example 38 with Scan

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

the class ConsensusCommitIntegrationTestBase method scan_DeleteCalledBefore_ShouldReturnEmpty.

@Test
public void scan_DeleteCalledBefore_ShouldReturnEmpty() throws CommitException, UnknownTransactionStatusException, CrudException {
    // Arrange
    ConsensusCommit transaction = manager.start();
    transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1));
    transaction.commit();
    // Act
    ConsensusCommit transaction1 = manager.start();
    Scan scan = prepareScan(0, 0, 0, namespace1, TABLE_1);
    List<Result> resultBefore = transaction1.scan(scan);
    transaction1.delete(prepareDelete(0, 0, namespace1, TABLE_1));
    List<Result> resultAfter = transaction1.scan(scan);
    assertThatCode(transaction1::commit).doesNotThrowAnyException();
    // Assert
    assertThat(resultBefore.size()).isEqualTo(1);
    assertThat(resultAfter.size()).isEqualTo(0);
}
Also used : Scan(com.scalar.db.api.Scan) Result(com.scalar.db.api.Result) Test(org.junit.Test)

Example 39 with Scan

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

the class ConsensusCommitIntegrationTestBase method scan_ScanGivenForPreparedWhenCoordinatorStateNotExistAndExpired_ShouldAbortTransaction.

@Test
public void scan_ScanGivenForPreparedWhenCoordinatorStateNotExistAndExpired_ShouldAbortTransaction() throws ExecutionException, CoordinatorException, CrudException {
    Scan scan = prepareScan(0, 0, 0, namespace1, TABLE_1);
    selection_SelectionGivenForPreparedWhenCoordinatorStateNotExistAndExpired_ShouldAbortTransaction(scan);
}
Also used : Scan(com.scalar.db.api.Scan) Test(org.junit.Test)

Example 40 with Scan

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

the class TwoPhaseConsensusCommitIntegrationTest method scan_DeleteGivenBefore_ShouldScan.

@Test
public void scan_DeleteGivenBefore_ShouldScan() throws TransactionException {
    // Arrange
    TwoPhaseConsensusCommit transaction = manager.start();
    transaction.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 1));
    transaction.put(preparePut(0, 1, TABLE_1).withValue(BALANCE, 1));
    transaction.prepare();
    transaction.commit();
    // Act
    TwoPhaseConsensusCommit transaction1 = manager.start();
    transaction1.delete(prepareDelete(0, 0, TABLE_1));
    Scan scan = prepareScan(0, 0, 1, TABLE_1);
    List<Result> results = transaction1.scan(scan);
    assertThatCode(() -> {
        transaction1.prepare();
        transaction1.commit();
    }).doesNotThrowAnyException();
    // Assert
    assertThat(results.size()).isEqualTo(1);
}
Also used : Scan(com.scalar.db.api.Scan) Result(com.scalar.db.api.Result) Test(org.junit.Test)

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