Search in sources :

Example 91 with Scan

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

the class RollbackMutationComposerTest method add_ScanAndPreparedResultByThisGivenAndBeforeResultNotGiven_ShouldComposeDelete.

@Test
public void add_ScanAndPreparedResultByThisGivenAndBeforeResultNotGiven_ShouldComposeDelete() throws ExecutionException {
    // Arrange
    composer = new RollbackMutationComposer(ANY_ID_2, storage, tableMetadataManager, mutations);
    TransactionResult result = prepareInitialResult(ANY_ID_2, TransactionState.PREPARED);
    Scan scan = prepareScan();
    // Act
    composer.add(scan, result);
    // Assert
    Delete actual = (Delete) mutations.get(0);
    Delete expected = new Delete(scan.getPartitionKey(), result.getClusteringKey().orElse(null)).forNamespace(scan.forNamespace().get()).forTable(scan.forTable().get());
    expected.withConsistency(Consistency.LINEARIZABLE);
    expected.withCondition(new DeleteIf(new ConditionalExpression(ID, toIdValue(ANY_ID_2), Operator.EQ), new ConditionalExpression(STATE, toStateValue(TransactionState.PREPARED), Operator.EQ)));
    assertThat(actual).isEqualTo(expected);
}
Also used : Delete(com.scalar.db.api.Delete) ConditionalExpression(com.scalar.db.api.ConditionalExpression) Scan(com.scalar.db.api.Scan) DeleteIf(com.scalar.db.api.DeleteIf) Test(org.junit.jupiter.api.Test)

Example 92 with Scan

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

the class RollbackMutationComposerTest method add_ScanAndPreparedResultByThisGiven_ShouldComposePut.

@Test
public void add_ScanAndPreparedResultByThisGiven_ShouldComposePut() throws ExecutionException {
    // Arrange
    composer = new RollbackMutationComposer(ANY_ID_2, storage, tableMetadataManager, mutations);
    TransactionResult result = prepareResult(TransactionState.PREPARED);
    Scan scan = prepareScan();
    // Act
    composer.add(scan, result);
    // Assert
    Put actual = (Put) mutations.get(0);
    Put expected = new Put(scan.getPartitionKey(), result.getClusteringKey().orElse(null)).forNamespace(scan.forNamespace().get()).forTable(scan.forTable().get());
    expected.withConsistency(Consistency.LINEARIZABLE);
    expected.withCondition(new PutIf(new ConditionalExpression(ID, toIdValue(ANY_ID_2), Operator.EQ), new ConditionalExpression(STATE, toStateValue(TransactionState.PREPARED), Operator.EQ)));
    expected.withValues(extractAfterValues(prepareInitialResult(ANY_ID_1, TransactionState.COMMITTED)));
    assertThat(actual).isEqualTo(expected);
}
Also used : PutIf(com.scalar.db.api.PutIf) ConditionalExpression(com.scalar.db.api.ConditionalExpression) Scan(com.scalar.db.api.Scan) Put(com.scalar.db.api.Put) Test(org.junit.jupiter.api.Test)

Example 93 with Scan

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

the class SnapshotTest method prepareScan.

private Scan prepareScan() {
    Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1);
    Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2);
    return new Scan(partitionKey).withStart(clusteringKey).withConsistency(Consistency.LINEARIZABLE).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME);
}
Also used : Scan(com.scalar.db.api.Scan) Key(com.scalar.db.io.Key)

Example 94 with Scan

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

the class SnapshotTest method get_ScanWithRangeGivenAndPutInWriteSetOverlappedWithScan_ShouldThrowIllegalArgumentException.

@Test
public void get_ScanWithRangeGivenAndPutInWriteSetOverlappedWithScan_ShouldThrowIllegalArgumentException() {
    // Arrange
    snapshot = prepareSnapshot(Isolation.SNAPSHOT);
    // "text2"
    Put put = preparePut();
    Snapshot.Key putKey = new Snapshot.Key(put);
    snapshot.put(putKey, put);
    Scan scan1 = prepareScan().withStart(new Key(ANY_NAME_2, ANY_TEXT_1), true).withEnd(new Key(ANY_NAME_2, ANY_TEXT_3), true);
    Scan scan2 = prepareScan().withStart(new Key(ANY_NAME_2, ANY_TEXT_2), true).withEnd(new Key(ANY_NAME_2, ANY_TEXT_3), true);
    Scan scan3 = prepareScan().withStart(new Key(ANY_NAME_2, ANY_TEXT_1), true).withEnd(new Key(ANY_NAME_2, ANY_TEXT_2), true);
    Scan scan4 = prepareScan().withStart(new Key(ANY_NAME_2, ANY_TEXT_2), false).withEnd(new Key(ANY_NAME_2, ANY_TEXT_3), true);
    Scan scan5 = prepareScan().withStart(new Key(ANY_NAME_2, ANY_TEXT_1), true).withEnd(new Key(ANY_NAME_2, ANY_TEXT_2), false);
    // Act Assert
    Throwable thrown1 = catchThrowable(() -> snapshot.get(scan1));
    Throwable thrown2 = catchThrowable(() -> snapshot.get(scan2));
    Throwable thrown3 = catchThrowable(() -> snapshot.get(scan3));
    Throwable thrown4 = catchThrowable(() -> snapshot.get(scan4));
    Throwable thrown5 = catchThrowable(() -> snapshot.get(scan5));
    // Assert
    assertThat(thrown1).isInstanceOf(IllegalArgumentException.class);
    assertThat(thrown2).isInstanceOf(IllegalArgumentException.class);
    assertThat(thrown3).isInstanceOf(IllegalArgumentException.class);
    assertThat(thrown4).doesNotThrowAnyException();
    assertThat(thrown5).doesNotThrowAnyException();
}
Also used : Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Scan(com.scalar.db.api.Scan) Put(com.scalar.db.api.Put) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.Test)

Example 95 with Scan

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

the class SnapshotTest method get_ScanWithNoRangeGivenAndPutInWriteSetOverlappedWithScan_ShouldThrowIllegalArgumentException.

@Test
public void get_ScanWithNoRangeGivenAndPutInWriteSetOverlappedWithScan_ShouldThrowIllegalArgumentException() {
    // Arrange
    snapshot = prepareSnapshot(Isolation.SNAPSHOT);
    // "text2"
    Put put = preparePut();
    Snapshot.Key putKey = new Snapshot.Key(put);
    snapshot.put(putKey, put);
    Scan scan = new Scan(new Key(ANY_NAME_1, ANY_TEXT_1)).withConsistency(Consistency.LINEARIZABLE).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME);
    // Act Assert
    Throwable thrown = catchThrowable(() -> snapshot.get(scan));
    // Assert
    assertThat(thrown).isInstanceOf(IllegalArgumentException.class);
}
Also used : Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Scan(com.scalar.db.api.Scan) Put(com.scalar.db.api.Put) Key(com.scalar.db.io.Key) Test(org.junit.jupiter.api.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