use of com.scalar.db.api.Get in project scalardb by scalar-labs.
the class JdbcTransactionIntegrationTest method get_GetGivenForNonExisting_ShouldReturnEmpty.
@Test
public void get_GetGivenForNonExisting_ShouldReturnEmpty() throws TransactionException {
// Arrange
populateRecords();
JdbcTransaction transaction = manager.start();
Get get = prepareGet(0, 4, NAMESPACE, TABLE);
// Act
Optional<Result> result = transaction.get(get);
transaction.commit();
// Assert
assertThat(result.isPresent()).isFalse();
}
use of com.scalar.db.api.Get in project scalardb by scalar-labs.
the class ConsensusCommitIntegrationTestBase method prepareTransfer.
private ConsensusCommit prepareTransfer(int fromId, String fromNamespace, String fromTable, int toId, String toNamespace, String toTable, int amount) throws CrudException {
boolean differentTables = toNamespace.equals(fromNamespace) || !toTable.equals(fromTable);
ConsensusCommit transaction = manager.start();
List<Get> fromGets = prepareGets(fromNamespace, fromTable);
List<Get> toGets = differentTables ? prepareGets(toNamespace, toTable) : fromGets;
Optional<Result> fromResult = transaction.get(fromGets.get(fromId));
assertThat(fromResult).isPresent();
IntValue fromBalance = new IntValue(BALANCE, getBalance(fromResult.get()) - amount);
Optional<Result> toResult = transaction.get(toGets.get(toId));
assertThat(toResult).isPresent();
IntValue toBalance = new IntValue(BALANCE, getBalance(toResult.get()) + amount);
List<Put> fromPuts = preparePuts(fromNamespace, fromTable);
List<Put> toPuts = differentTables ? preparePuts(toNamespace, toTable) : fromPuts;
fromPuts.get(fromId).withValue(fromBalance);
toPuts.get(toId).withValue(toBalance);
transaction.put(fromPuts.get(fromId));
transaction.put(toPuts.get(toId));
return transaction;
}
use of com.scalar.db.api.Get in project scalardb by scalar-labs.
the class ConsensusCommitIntegrationTestBase method get_CalledTwice_ShouldReturnFromSnapshotInSecondTime.
@Test
public void get_CalledTwice_ShouldReturnFromSnapshotInSecondTime() throws CrudException, ExecutionException, CommitException, UnknownTransactionStatusException {
// Arrange
populateRecords(namespace1, TABLE_1);
ConsensusCommit transaction = manager.start();
Get get = prepareGet(0, 0, namespace1, TABLE_1);
// Act
Optional<Result> result1 = transaction.get(get);
Optional<Result> result2 = transaction.get(get);
// Assert
verify(storage).get(any(Get.class));
assertThat(result1).isEqualTo(result2);
}
use of com.scalar.db.api.Get in project scalardb by scalar-labs.
the class ConsensusCommitIntegrationTestBase method get_GetGivenForPreparedWhenCoordinatorStateAbortedAndRolledBackByAnother_ShouldRollbackProperly.
@Test
public void get_GetGivenForPreparedWhenCoordinatorStateAbortedAndRolledBackByAnother_ShouldRollbackProperly() throws ExecutionException, CoordinatorException, CrudException {
Get get = prepareGet(0, 0, namespace1, TABLE_1);
selection_SelectionGivenForPreparedWhenCoordinatorStateAbortedAndRolledBackByAnother_ShouldRollbackProperly(get);
}
use of com.scalar.db.api.Get in project scalardb by scalar-labs.
the class ConsensusCommitIntegrationTestBase method get_GetGivenForNonExisting_ShouldReturnEmpty.
@Test
public void get_GetGivenForNonExisting_ShouldReturnEmpty() throws CrudException, CommitException, UnknownTransactionStatusException {
// Arrange
populateRecords(namespace1, TABLE_1);
ConsensusCommit transaction = manager.start();
Get get = prepareGet(0, 4, namespace1, TABLE_1);
// Act
Optional<Result> result = transaction.get(get);
// Assert
assertThat(result.isPresent()).isFalse();
}
Aggregations