use of com.scalar.db.api.Get in project scalardb by scalar-labs.
the class CrudHandlerTest method get_KeyNeitherExistsInSnapshotNorInStorage_ShouldReturnEmpty.
@Test
public void get_KeyNeitherExistsInSnapshotNorInStorage_ShouldReturnEmpty() throws CrudException, ExecutionException {
// Arrange
Get get = prepareGet();
when(snapshot.get(new Snapshot.Key(get))).thenReturn(Optional.empty());
when(storage.get(get)).thenReturn(Optional.empty());
// Act
Optional<Result> result = handler.get(get);
// Assert
assertThat(result.isPresent()).isFalse();
}
use of com.scalar.db.api.Get in project scalardb by scalar-labs.
the class CrudHandlerTest method prepareGet.
private Get prepareGet() {
Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1);
Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2);
return new Get(partitionKey, clusteringKey).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME);
}
use of com.scalar.db.api.Get in project scalardb by scalar-labs.
the class CrudHandlerTest method scan_GetCalledAfterScan_ShouldReturnFromSnapshot.
@Test
public void scan_GetCalledAfterScan_ShouldReturnFromSnapshot() throws ExecutionException, CrudException {
// Arrange
Scan scan = prepareScan();
result = prepareResult(TransactionState.COMMITTED);
doNothing().when(snapshot).put(any(Snapshot.Key.class), ArgumentMatchers.<Optional<TransactionResult>>any());
when(scanner.iterator()).thenReturn(Collections.singletonList(result).iterator());
when(storage.scan(scan)).thenReturn(scanner);
Snapshot.Key key = new Snapshot.Key(scan, result);
when(snapshot.get(scan)).thenReturn(Optional.empty());
when(snapshot.containsKeyInReadSet(key)).thenReturn(false).thenReturn(true);
when(snapshot.get(key)).thenReturn(Optional.of((TransactionResult) result));
// Act
List<Result> results = handler.scan(scan);
Optional<Result> result = handler.get(prepareGet());
// Assert
verify(storage, never()).get(any(Get.class));
assertThat(results.get(0)).isEqualTo(result.get());
}
use of com.scalar.db.api.Get in project scalardb by scalar-labs.
the class CrudHandlerTest method get_KeyNotExistsInSnapshotAndRecordInStorageCommitted_ShouldReturnFromStorageAndUpdateSnapshot.
@Test
public void get_KeyNotExistsInSnapshotAndRecordInStorageCommitted_ShouldReturnFromStorageAndUpdateSnapshot() throws CrudException, ExecutionException {
// Arrange
Get get = prepareGet();
Optional<Result> expected = Optional.of(prepareResult(TransactionState.COMMITTED));
Snapshot.Key key = new Snapshot.Key(get);
when(snapshot.containsKeyInReadSet(key)).thenReturn(false);
doNothing().when(snapshot).put(any(Snapshot.Key.class), ArgumentMatchers.<Optional<TransactionResult>>any());
when(storage.get(get)).thenReturn(expected);
when(snapshot.get(key)).thenReturn(expected.map(e -> (TransactionResult) e));
// Act
Optional<Result> result = handler.get(get);
// Assert
assertThat(result).isEqualTo(Optional.of(new FilteredResult(expected.get(), Collections.emptyList(), TABLE_METADATA)));
verify(storage).get(get);
verify(snapshot).put(key, Optional.of((TransactionResult) expected.get()));
}
use of com.scalar.db.api.Get in project scalardb by scalar-labs.
the class RollbackMutationComposerTest method add_GetAndDeletedResultByThisGiven_ShouldComposePut.
@Test
public void add_GetAndDeletedResultByThisGiven_ShouldComposePut() throws ExecutionException {
// Arrange
composer = new RollbackMutationComposer(ANY_ID_2, storage, tableMetadataManager, mutations);
TransactionResult result = prepareResult(TransactionState.DELETED);
Get get = prepareGet();
// Act
composer.add(get, result);
// Assert
Put actual = (Put) mutations.get(0);
Put expected = new Put(get.getPartitionKey(), get.getClusteringKey().orElse(null)).forNamespace(get.forNamespace().get()).forTable(get.forTable().get());
expected.withConsistency(Consistency.LINEARIZABLE);
expected.withCondition(new PutIf(new ConditionalExpression(ID, toIdValue(ANY_ID_2), Operator.EQ), new ConditionalExpression(STATE, toStateValue(TransactionState.DELETED), Operator.EQ)));
expected.withValues(extractAfterValues(prepareInitialResult(ANY_ID_1, TransactionState.COMMITTED)));
assertThat(actual).isEqualTo(expected);
}
Aggregations