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);
}
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);
}
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);
}
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();
}
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);
}
Aggregations