use of com.scalar.db.api.TransactionState in project scalardb by scalar-labs.
the class ConsensusCommitIntegrationTestBase method populatePreparedRecordAndCoordinatorStateRecord.
private void populatePreparedRecordAndCoordinatorStateRecord(DistributedStorage storage, String namespace, String table, TransactionState recordState, long preparedAt, TransactionState coordinatorState) throws ExecutionException, CoordinatorException {
Key partitionKey = new Key(ACCOUNT_ID, 0);
Key clusteringKey = new Key(ACCOUNT_TYPE, 0);
Put put = new Put(partitionKey, clusteringKey).forNamespace(namespace).forTable(table).withValue(BALANCE, INITIAL_BALANCE).withValue(Attribute.toIdValue(ANY_ID_2)).withValue(Attribute.toStateValue(recordState)).withValue(Attribute.toVersionValue(2)).withValue(Attribute.toPreparedAtValue(preparedAt)).withValue(Attribute.toBeforeIdValue(ANY_ID_1)).withValue(Attribute.toBeforeStateValue(TransactionState.COMMITTED)).withValue(Attribute.toBeforeVersionValue(1)).withValue(Attribute.toBeforePreparedAtValue(1)).withValue(Attribute.toBeforeCommittedAtValue(1));
storage.put(put);
if (coordinatorState == null) {
return;
}
Coordinator.State state = new Coordinator.State(ANY_ID_2, coordinatorState);
coordinator.putState(state);
}
use of com.scalar.db.api.TransactionState in project scalardb by scalar-labs.
the class ConsensusCommitIntegrationTestBase method getState_forSuccessfulTransaction_ShouldReturnCommittedState.
@Test
public void getState_forSuccessfulTransaction_ShouldReturnCommittedState() throws CommitException, UnknownTransactionStatusException, CrudException {
// Arrange
ConsensusCommit transaction = manager.start();
transaction.get(prepareGet(0, 0, namespace1, TABLE_1));
transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1));
transaction.commit();
// Act
TransactionState state = manager.getState(transaction.getId());
// Assert
assertThat(state).isEqualTo(TransactionState.COMMITTED);
}
use of com.scalar.db.api.TransactionState in project scalardb by scalar-labs.
the class TwoPhaseConsensusCommitIntegrationTest method abort_forOngoingTransaction_ShouldAbortCorrectly.
@Test
public void abort_forOngoingTransaction_ShouldAbortCorrectly() throws TransactionException {
// Arrange
TwoPhaseConsensusCommit transaction = manager.start();
transaction.get(prepareGet(0, 0, TABLE_1));
transaction.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 1));
// Act
manager.abort(transaction.getId());
transaction.prepare();
assertThatCode(transaction::commit).isInstanceOf(CommitException.class);
transaction.rollback();
// Assert
TransactionState state = manager.getState(transaction.getId());
assertThat(state).isEqualTo(TransactionState.ABORTED);
}
use of com.scalar.db.api.TransactionState in project scalardb by scalar-labs.
the class TwoPhaseConsensusCommitIntegrationTest method populatePreparedRecordAndCoordinatorStateRecord.
private void populatePreparedRecordAndCoordinatorStateRecord(String table, TransactionState recordState, long preparedAt, TransactionState coordinatorState) throws ExecutionException, CoordinatorException {
Key partitionKey = new Key(new IntValue(ACCOUNT_ID, 0));
Key clusteringKey = new Key(new IntValue(ACCOUNT_TYPE, 0));
Put put = new Put(partitionKey, clusteringKey).forNamespace(NAMESPACE).forTable(table).withValue(new IntValue(BALANCE, INITIAL_BALANCE)).withValue(Attribute.toIdValue(ANY_ID_2)).withValue(Attribute.toStateValue(recordState)).withValue(Attribute.toVersionValue(2)).withValue(Attribute.toPreparedAtValue(preparedAt)).withValue(Attribute.toBeforeIdValue(ANY_ID_1)).withValue(Attribute.toBeforeStateValue(TransactionState.COMMITTED)).withValue(Attribute.toBeforeVersionValue(1)).withValue(Attribute.toBeforePreparedAtValue(1)).withValue(Attribute.toBeforeCommittedAtValue(1));
storage.put(put);
if (coordinatorState == null) {
return;
}
State state = new State(ANY_ID_2, coordinatorState);
coordinator.putState(state);
}
use of com.scalar.db.api.TransactionState in project scalardb by scalar-labs.
the class DistributedTransactionServiceWithConsensusCommitIntegrationTest method getState_forSuccessfulTransaction_ShouldReturnCommittedState.
@Test
public void getState_forSuccessfulTransaction_ShouldReturnCommittedState() throws TransactionException {
// Arrange
GrpcTransaction transaction = manager.start();
transaction.get(prepareGet(0, 0, TABLE_1));
transaction.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 1));
transaction.commit();
// Act
TransactionState state = manager.getState(transaction.getId());
// Assert
assertThat(state).isEqualTo(TransactionState.COMMITTED);
}
Aggregations