Search in sources :

Example 26 with TransactionState

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);
}
Also used : TransactionState(com.scalar.db.api.TransactionState) Test(org.junit.jupiter.api.Test)

Example 27 with TransactionState

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);
}
Also used : TransactionState(com.scalar.db.api.TransactionState) Test(org.junit.jupiter.api.Test)

Example 28 with TransactionState

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);
}
Also used : TransactionState(com.scalar.db.api.TransactionState) Test(org.junit.jupiter.api.Test)

Example 29 with TransactionState

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");
}
Also used : TransactionState(com.scalar.db.api.TransactionState)

Example 30 with TransactionState

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);
}
Also used : TransactionState(com.scalar.db.api.TransactionState) Key(com.scalar.db.io.Key) Put(com.scalar.db.api.Put)

Aggregations

TransactionState (com.scalar.db.api.TransactionState)37 Test (org.junit.jupiter.api.Test)16 Test (org.junit.Test)12 Put (com.scalar.db.api.Put)4 Key (com.scalar.db.io.Key)4 State (com.scalar.db.transaction.consensuscommit.Coordinator.State)4 GrpcTransaction (com.scalar.db.transaction.rpc.GrpcTransaction)3 GrpcTwoPhaseCommitTransaction (com.scalar.db.transaction.rpc.GrpcTwoPhaseCommitTransaction)3 IntValue (com.scalar.db.io.IntValue)2 CommitException (com.scalar.db.exception.transaction.CommitException)1