use of com.scalar.db.api.Get in project scalardb by scalar-labs.
the class ConsensusCommitIntegrationTestBase method get_GetGivenForDeletedWhenCoordinatorStateCommitted_ShouldRollforward.
@Test
public void get_GetGivenForDeletedWhenCoordinatorStateCommitted_ShouldRollforward() throws ExecutionException, CoordinatorException, CrudException {
Get get = prepareGet(0, 0, namespace1, TABLE_1);
selection_SelectionGivenForDeletedWhenCoordinatorStateCommitted_ShouldRollforward(get);
}
use of com.scalar.db.api.Get in project scalardb by scalar-labs.
the class ConsensusCommitIntegrationTestBase method get_GetGivenForDeletedWhenCoordinatorStateAborted_ShouldRollback.
@Test
public void get_GetGivenForDeletedWhenCoordinatorStateAborted_ShouldRollback() throws ExecutionException, CoordinatorException, CrudException {
Get get = prepareGet(0, 0, namespace1, TABLE_1);
selection_SelectionGivenForDeletedWhenCoordinatorStateAborted_ShouldRollback(get);
}
use of com.scalar.db.api.Get in project scalardb by scalar-labs.
the class ConsensusCommitIntegrationTestBase method commit_WriteSkewOnExistingRecordsWithSerializableWithExtraRead_OneShouldCommitTheOtherShouldThrowCommitConflictException.
private void commit_WriteSkewOnExistingRecordsWithSerializableWithExtraRead_OneShouldCommitTheOtherShouldThrowCommitConflictException(String namespace1, String table1, String namespace2, String table2) throws CommitException, UnknownTransactionStatusException, CrudException {
// Arrange
List<Put> puts = Arrays.asList(preparePut(0, 0, namespace1, table1).withValue(BALANCE, 1), preparePut(0, 1, namespace2, table2).withValue(BALANCE, 1));
ConsensusCommit transaction = manager.start(Isolation.SERIALIZABLE, SerializableStrategy.EXTRA_READ);
transaction.put(puts);
transaction.commit();
// Act
ConsensusCommit transaction1 = manager.start(Isolation.SERIALIZABLE, SerializableStrategy.EXTRA_READ);
ConsensusCommit transaction2 = manager.start(Isolation.SERIALIZABLE, SerializableStrategy.EXTRA_READ);
Get get1_1 = prepareGet(0, 1, namespace2, table2);
Optional<Result> result1 = transaction1.get(get1_1);
assertThat(result1).isPresent();
int current1 = getBalance(result1.get());
Get get1_2 = prepareGet(0, 0, namespace1, table1);
transaction1.get(get1_2);
Get get2_1 = prepareGet(0, 0, namespace1, table1);
Optional<Result> result2 = transaction2.get(get2_1);
assertThat(result2).isPresent();
int current2 = getBalance(result2.get());
Get get2_2 = prepareGet(0, 1, namespace2, table2);
transaction2.get(get2_2);
Put put1 = preparePut(0, 0, namespace1, table1).withValue(BALANCE, current1 + 1);
transaction1.put(put1);
Put put2 = preparePut(0, 1, namespace2, table2).withValue(BALANCE, current2 + 1);
transaction2.put(put2);
transaction1.commit();
Throwable thrown = catchThrowable(transaction2::commit);
// Assert
transaction = manager.start(Isolation.SERIALIZABLE, SerializableStrategy.EXTRA_READ);
result1 = transaction.get(get1_1);
assertThat(result1).isPresent();
assertThat(getBalance(result1.get())).isEqualTo(1);
result2 = transaction.get(get2_1);
assertThat(result2).isPresent();
assertThat(getBalance(result2.get())).isEqualTo(2);
assertThat(thrown).isInstanceOf(CommitConflictException.class);
}
use of com.scalar.db.api.Get in project scalardb by scalar-labs.
the class ConsensusCommitIntegrationTestBase method get_GetGivenForPreparedWhenCoordinatorStateCommitted_ShouldRollforward.
@Test
public void get_GetGivenForPreparedWhenCoordinatorStateCommitted_ShouldRollforward() throws ExecutionException, CoordinatorException, CrudException {
Get get = prepareGet(0, 0, namespace1, TABLE_1);
selection_SelectionGivenForPreparedWhenCoordinatorStateCommitted_ShouldRollforward(get);
}
use of com.scalar.db.api.Get in project scalardb by scalar-labs.
the class ConsensusCommitIntegrationTestBase method prepareGet.
private Get prepareGet(int id, int type, String namespace, String table) {
Key partitionKey = new Key(ACCOUNT_ID, id);
Key clusteringKey = new Key(ACCOUNT_TYPE, type);
return new Get(partitionKey, clusteringKey).forNamespace(namespace).forTable(table).withConsistency(Consistency.LINEARIZABLE);
}
Aggregations