Search in sources :

Example 1 with TransactionState

use of com.scalar.db.api.TransactionState in project scalardb by scalar-labs.

the class ConsensusCommitIntegrationTestBase method getState_forFailedTransaction_ShouldReturnAbortedState.

@Test
public void getState_forFailedTransaction_ShouldReturnAbortedState() throws CommitException, UnknownTransactionStatusException, CrudException {
    // Arrange
    ConsensusCommit transaction1 = manager.start();
    transaction1.get(prepareGet(0, 0, namespace1, TABLE_1));
    transaction1.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1));
    ConsensusCommit transaction2 = manager.start();
    transaction2.get(prepareGet(0, 0, namespace1, TABLE_1));
    transaction2.put(preparePut(0, 0, namespace1, 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);
}
Also used : TransactionState(com.scalar.db.api.TransactionState) Test(org.junit.Test)

Example 2 with TransactionState

use of com.scalar.db.api.TransactionState in project scalardb by scalar-labs.

the class TwoPhaseConsensusCommitIntegrationTest method getState_forSuccessfulTransaction_ShouldReturnCommittedState.

@Test
public void getState_forSuccessfulTransaction_ShouldReturnCommittedState() throws TransactionException {
    // Arrange
    TwoPhaseConsensusCommit 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);
}
Also used : TransactionState(com.scalar.db.api.TransactionState) Test(org.junit.Test)

Example 3 with TransactionState

use of com.scalar.db.api.TransactionState in project scalardb by scalar-labs.

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

Example 4 with TransactionState

use of com.scalar.db.api.TransactionState in project scalardb by scalar-labs.

the class ConsensusCommitIntegrationTestBase method abort_forOngoingTransaction_ShouldAbortCorrectly.

@Test
public void abort_forOngoingTransaction_ShouldAbortCorrectly() throws 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));
    // Act
    manager.abort(transaction.getId());
    assertThatCode(transaction::commit).isInstanceOf(CommitException.class);
    // Assert
    TransactionState state = manager.getState(transaction.getId());
    assertThat(state).isEqualTo(TransactionState.ABORTED);
}
Also used : TransactionState(com.scalar.db.api.TransactionState) Test(org.junit.Test)

Example 5 with TransactionState

use of com.scalar.db.api.TransactionState in project scalardb by scalar-labs.

the class DistributedTransactionServiceWithConsensusCommitIntegrationTest method abort_forOngoingTransaction_ShouldAbortCorrectly.

@Test
public void abort_forOngoingTransaction_ShouldAbortCorrectly() throws TransactionException {
    // Arrange
    GrpcTransaction 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());
    assertThatCode(transaction::commit).isInstanceOf(CommitException.class);
    // Assert
    TransactionState state = manager.getState(transaction.getId());
    assertThat(state).isEqualTo(TransactionState.ABORTED);
}
Also used : TransactionState(com.scalar.db.api.TransactionState) GrpcTransaction(com.scalar.db.transaction.rpc.GrpcTransaction) Test(org.junit.Test)

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