use of com.scalar.db.api.TransactionState in project scalardb by scalar-labs.
the class TwoPhaseConsensusCommitManagerTest method abort_CommitHandlerReturnsAborted_ShouldReturnTheState.
@Test
public void abort_CommitHandlerReturnsAborted_ShouldReturnTheState() throws UnknownTransactionStatusException {
// Arrange
TransactionState expected = TransactionState.ABORTED;
when(commit.abort(ANY_TX_ID)).thenReturn(expected);
// Act
TransactionState actual = manager.abort(ANY_TX_ID);
// Assert
assertThat(actual).isEqualTo(expected);
}
use of com.scalar.db.api.TransactionState in project scalardb by scalar-labs.
the class TwoPhaseConsensusCommitManagerTest 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 TwoPhaseConsensusCommitManagerTest method abort_CommitHandlerReturnsCommitted_ShouldReturnTheState.
@Test
public void abort_CommitHandlerReturnsCommitted_ShouldReturnTheState() throws UnknownTransactionStatusException {
// Arrange
TransactionState expected = TransactionState.COMMITTED;
when(commit.abort(ANY_TX_ID)).thenReturn(expected);
// Act
TransactionState actual = manager.abort(ANY_TX_ID);
// Assert
assertThat(actual).isEqualTo(expected);
}
use of com.scalar.db.api.TransactionState in project scalardb by scalar-labs.
the class TwoPhaseCommitTransactionService method getState.
@Override
public void getState(GetTransactionStateRequest request, StreamObserver<GetTransactionStateResponse> responseObserver) {
execute(() -> {
TransactionState state = manager.getState(request.getTransactionId());
responseObserver.onNext(GetTransactionStateResponse.newBuilder().setState(ProtoUtils.toTransactionState(state)).build());
responseObserver.onCompleted();
}, responseObserver, "get_state");
}
use of com.scalar.db.api.TransactionState in project scalardb by scalar-labs.
the class ConsensusCommitSpecificIntegrationTestBase 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);
}
Aggregations