use of com.scalar.db.api.Get in project scalardb by scalar-labs.
the class RollbackMutationComposerTest 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).withConsistency(Consistency.LINEARIZABLE).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME);
}
use of com.scalar.db.api.Get in project scalardb by scalar-labs.
the class RollbackMutationComposerTest method add_PutAndNullResultGivenAndEmptyResultGivenFromStorage_ShouldDoNothing.
@Test
public void add_PutAndNullResultGivenAndEmptyResultGivenFromStorage_ShouldDoNothing() throws ExecutionException {
// Arrange
composer = new RollbackMutationComposer(ANY_ID_2, storage, tableMetadataManager, mutations);
when(storage.get(any(Get.class))).thenReturn(Optional.empty());
Put put = preparePut();
// Act
composer.add(put, null);
// Assert
assertThat(mutations.size()).isEqualTo(0);
verify(storage).get(any(Get.class));
}
use of com.scalar.db.api.Get in project scalardb by scalar-labs.
the class RollbackMutationComposerTest method add_GetAndPreparedResultByThisGiven_ShouldComposePut.
@Test
public void add_GetAndPreparedResultByThisGiven_ShouldComposePut() throws ExecutionException {
// Arrange
composer = new RollbackMutationComposer(ANY_ID_2, storage, tableMetadataManager, mutations);
TransactionResult result = prepareResult(TransactionState.PREPARED);
when(storage.get(any(Get.class))).thenReturn(Optional.of(result));
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.PREPARED), Operator.EQ)));
expected.withValues(extractAfterValues(prepareInitialResult(ANY_ID_1, TransactionState.COMMITTED)));
assertThat(actual).isEqualTo(expected);
}
use of com.scalar.db.api.Get in project scalardb by scalar-labs.
the class RollbackMutationComposerTest method add_GetAndPreparedResultGivenAndBeforeResultNotGiven_ShouldComposeDelete.
@Test
public void add_GetAndPreparedResultGivenAndBeforeResultNotGiven_ShouldComposeDelete() throws ExecutionException {
// Arrange
composer = new RollbackMutationComposer(ANY_ID_2, storage, tableMetadataManager, mutations);
TransactionResult result = prepareInitialResult(ANY_ID_2, TransactionState.PREPARED);
Get get = prepareGet();
// Act
composer.add(get, result);
// Assert
Delete actual = (Delete) mutations.get(0);
Delete expected = new Delete(get.getPartitionKey(), get.getClusteringKey().orElse(null)).forNamespace(get.forNamespace().get()).forTable(get.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.Get in project scalardb by scalar-labs.
the class SnapshotKeyTest method compareTo_SameOperationExceptWithoutClusteringKeyGivenInConstructor_ShouldReturnPositive.
@Test
public void compareTo_SameOperationExceptWithoutClusteringKeyGivenInConstructor_ShouldReturnPositive() {
// Arrange
Get one = prepareGet();
Snapshot.Key key = new Snapshot.Key(one);
Get another = prepareGetWithoutClusteringKey();
// Act
int res = key.compareTo(new Snapshot.Key(another));
// Assert
assertThat(res).isGreaterThan(0);
}
Aggregations