use of com.scalar.db.api.TransactionState in project scalardb by scalar-labs.
the class DistributedTransactionServiceWithConsensusCommitIntegrationTest method getState_forFailedTransaction_ShouldReturnAbortedState.
@Test
public void getState_forFailedTransaction_ShouldReturnAbortedState() throws TransactionException {
// Arrange
GrpcTransaction transaction1 = manager.start();
transaction1.get(prepareGet(0, 0, TABLE_1));
transaction1.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 1));
GrpcTransaction transaction2 = manager.start();
transaction2.get(prepareGet(0, 0, TABLE_1));
transaction2.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 1));
transaction2.commit();
assertThatCode(transaction1::commit).isInstanceOf(CommitException.class);
// Act
TransactionState state = manager.getState(transaction1.getId());
// Assert
assertThat(state).isEqualTo(TransactionState.ABORTED);
}
use of com.scalar.db.api.TransactionState in project scalardb by scalar-labs.
the class TwoPhaseCommitTransactionServiceWithTwoPhaseConsensusCommitIntegrationTest method getState_forSuccessfulTransaction_ShouldReturnCommittedState.
@Test
public void getState_forSuccessfulTransaction_ShouldReturnCommittedState() throws TransactionException {
// Arrange
GrpcTwoPhaseCommitTransaction transaction = manager.start();
transaction.get(prepareGet(0, 0, TABLE_1));
transaction.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 1));
transaction.prepare();
transaction.commit();
// Act
TransactionState state = manager.getState(transaction.getId());
// Assert
assertThat(state).isEqualTo(TransactionState.COMMITTED);
}
Aggregations