use of com.scalar.db.api.TransactionState in project scalardb by scalar-labs.
the class DistributedTransactionService method abort.
@Override
public void abort(com.scalar.db.rpc.AbortRequest request, StreamObserver<AbortResponse> responseObserver) {
execute(() -> {
TransactionState state = manager.abort(request.getTransactionId());
responseObserver.onNext(AbortResponse.newBuilder().setState(ProtoUtils.toTransactionState(state)).build());
responseObserver.onCompleted();
}, responseObserver, "abort");
}
use of com.scalar.db.api.TransactionState in project scalardb by scalar-labs.
the class ConsensusCommitManagerTest method abort_CommitHandlerThrowsUnknownTransactionStatusException_ShouldReturnUnknown.
@Test
public void abort_CommitHandlerThrowsUnknownTransactionStatusException_ShouldReturnUnknown() throws UnknownTransactionStatusException {
// Arrange
when(commit.abort(ANY_TX_ID)).thenThrow(UnknownTransactionStatusException.class);
// Act
TransactionState actual = manager.abort(ANY_TX_ID);
// Assert
assertThat(actual).isEqualTo(TransactionState.UNKNOWN);
}
use of com.scalar.db.api.TransactionState in project scalardb by scalar-labs.
the class ConsensusCommitManagerTest method check_CoordinatorExceptionThrown_ReturnUnknown.
@Test
public void check_CoordinatorExceptionThrown_ReturnUnknown() throws CoordinatorException {
// Arrange
CoordinatorException toThrow = mock(CoordinatorException.class);
when(coordinator.getState(ANY_TX_ID)).thenThrow(toThrow);
// Act
TransactionState actual = manager.getState(ANY_TX_ID);
// Assert
assertThat(actual).isEqualTo(TransactionState.UNKNOWN);
}
use of com.scalar.db.api.TransactionState in project scalardb by scalar-labs.
the class TwoPhaseConsensusCommitSpecificIntegrationTestBase method getState_forFailedTransaction_ShouldReturnAbortedState.
@Test
public void getState_forFailedTransaction_ShouldReturnAbortedState() throws TransactionException {
// Arrange
TwoPhaseConsensusCommit transaction1 = manager.start();
transaction1.get(prepareGet(0, 0, TABLE_1));
transaction1.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 1));
TwoPhaseConsensusCommit transaction2 = manager.start();
transaction2.get(prepareGet(0, 0, TABLE_1));
transaction2.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 1));
transaction2.prepare();
transaction2.commit();
assertThatCode(transaction1::prepare).isInstanceOf(PreparationException.class);
transaction1.rollback();
// 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 TwoPhaseConsensusCommitSpecificIntegrationTestBase 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);
}
Aggregations