Search in sources :

Example 36 with ScanAll

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

the class OperationCheckerTest method whenCheckingScanAllOperationWithInvalidProjections_shouldThrowIllegalArgumentException.

@Test
public void whenCheckingScanAllOperationWithInvalidProjections_shouldThrowIllegalArgumentException() {
    // Arrange
    List<String> projections = Arrays.asList(COL1, COL2, "v4");
    int limit = 10;
    ScanAll scanAll = new ScanAll().withProjections(projections).withLimit(limit).forNamespace(NAMESPACE).forTable(TABLE_NAME);
    // Act Assert
    assertThatThrownBy(() -> operationChecker.check(scanAll)).isInstanceOf(IllegalArgumentException.class);
}
Also used : ScanAll(com.scalar.db.api.ScanAll) Test(org.junit.jupiter.api.Test)

Example 37 with ScanAll

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

the class ProtoUtils method toScan.

public static Scan toScan(com.scalar.db.rpc.Scan scan, TableMetadata metadata) {
    Scan ret;
    if (scan.hasPartitionKey()) {
        ret = new Scan(toKey(scan.getPartitionKey(), metadata));
        if (scan.hasStartClusteringKey()) {
            ret.withStart(toKey(scan.getStartClusteringKey(), metadata), scan.getStartInclusive());
        }
        if (scan.hasEndClusteringKey()) {
            ret.withEnd(toKey(scan.getEndClusteringKey(), metadata), scan.getEndInclusive());
        }
        scan.getOrderingList().forEach(o -> ret.withOrdering(toOrdering(o)));
    } else {
        ret = new ScanAll();
    }
    ret.withLimit(scan.getLimit());
    if (!scan.getNamespace().isEmpty()) {
        ret.forNamespace(scan.getNamespace());
    }
    if (!scan.getTable().isEmpty()) {
        ret.forTable(scan.getTable());
    }
    ret.withConsistency(toConsistency(scan.getConsistency()));
    ret.withProjections(scan.getProjectionList());
    return ret;
}
Also used : Scan(com.scalar.db.api.Scan) ScanAll(com.scalar.db.api.ScanAll)

Example 38 with ScanAll

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

the class ConsensusCommitSpecificIntegrationTestBase method scanAll_ScanAllGivenForCommittedRecord_ShouldReturnRecord.

@Test
public void scanAll_ScanAllGivenForCommittedRecord_ShouldReturnRecord() throws CrudException, CommitException, UnknownTransactionStatusException {
    // Arrange
    populateRecords(namespace1, TABLE_1);
    ConsensusCommit transaction = manager.start();
    ScanAll scanAll = prepareScanAll(namespace1, TABLE_1).withLimit(1);
    // Act
    List<Result> results = transaction.scan(scanAll);
    // Assert
    assertThat(results.size()).isEqualTo(1);
    Assertions.assertThat(((TransactionResult) ((FilteredResult) results.get(0)).getOriginalResult()).getState()).isEqualTo(TransactionState.COMMITTED);
}
Also used : ScanAll(com.scalar.db.api.ScanAll) Result(com.scalar.db.api.Result) Test(org.junit.jupiter.api.Test)

Example 39 with ScanAll

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

the class ConsensusCommitSpecificIntegrationTestBase method scanAll_DeleteCalledBefore_ShouldReturnEmpty.

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

Example 40 with ScanAll

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

the class ConsensusCommitSpecificIntegrationTestBase method scanAll_DeleteGivenBefore_ShouldScanAll.

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

Aggregations

ScanAll (com.scalar.db.api.ScanAll)52 Test (org.junit.jupiter.api.Test)43 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)10 Result (com.scalar.db.api.Result)9 CosmosQueryRequestOptions (com.azure.cosmos.models.CosmosQueryRequestOptions)8 Put (com.scalar.db.api.Put)4 HashMap (java.util.HashMap)4 Scan (com.scalar.db.api.Scan)3 TableMetadata (com.scalar.db.api.TableMetadata)3 Key (com.scalar.db.io.Key)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)3 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)3 ScanRequest (software.amazon.awssdk.services.dynamodb.model.ScanRequest)3 SelectQuery (com.scalar.db.storage.jdbc.query.SelectQuery)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 List (java.util.List)2 Nonnull (javax.annotation.Nonnull)2 ResultSet (com.datastax.driver.core.ResultSet)1 Select (com.datastax.driver.core.querybuilder.Select)1