use of com.scalar.db.transaction.rpc.GrpcTwoPhaseCommitTransaction in project scalardb by scalar-labs.
the class TwoPhaseCommitTransactionServiceWithTwoPhaseConsensusCommitIntegrationTest method getState_forFailedTransaction_ShouldReturnAbortedState.
@Test
public void getState_forFailedTransaction_ShouldReturnAbortedState() throws TransactionException {
// Arrange
GrpcTwoPhaseCommitTransaction transaction1 = manager.start();
transaction1.get(prepareGet(0, 0, TABLE_1));
transaction1.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 1));
GrpcTwoPhaseCommitTransaction 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.transaction.rpc.GrpcTwoPhaseCommitTransaction in project scalardb by scalar-labs.
the class TwoPhaseCommitTransactionServiceWithTwoPhaseConsensusCommitIntegrationTest method prepare_DeleteGivenForNonExisting_ShouldThrowPreparationException.
@Test
public void prepare_DeleteGivenForNonExisting_ShouldThrowPreparationException() throws TransactionException {
// Arrange
GrpcTwoPhaseCommitTransaction transaction = manager.start();
transaction.get(prepareGet(0, 0, TABLE_1));
transaction.delete(prepareDelete(0, 0, TABLE_1));
// Act
Throwable throwable = catchThrowable(transaction::prepare);
transaction.rollback();
// Assert
assertThat(throwable).isInstanceOf(PreparationException.class);
}
use of com.scalar.db.transaction.rpc.GrpcTwoPhaseCommitTransaction in project scalardb by scalar-labs.
the class TwoPhaseCommitTransactionServiceWithTwoPhaseConsensusCommitIntegrationTest method deleteAndCommit_DeleteGivenInBetweenTransactions_ShouldProduceSerializableResults.
@Test
public void deleteAndCommit_DeleteGivenInBetweenTransactions_ShouldProduceSerializableResults() throws TransactionException {
// Arrange
GrpcTwoPhaseCommitTransaction transaction = manager.start();
transaction.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 2));
transaction.prepare();
transaction.commit();
// Act
GrpcTwoPhaseCommitTransaction transaction1 = manager.start();
transaction1.get(prepareGet(0, 0, TABLE_1));
transaction1.delete(prepareDelete(0, 0, TABLE_1));
GrpcTwoPhaseCommitTransaction transaction2 = manager.start();
transaction2.get(prepareGet(0, 0, TABLE_1));
transaction2.delete(prepareDelete(0, 0, TABLE_1));
transaction2.prepare();
transaction2.commit();
GrpcTwoPhaseCommitTransaction transaction3 = manager.start();
Optional<Result> result = transaction3.get(prepareGet(0, 0, TABLE_1));
assertThat(result).isNotPresent();
int balance3 = 0;
transaction3.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, balance3 + 1));
transaction3.prepare();
transaction3.commit();
assertThatThrownBy(transaction1::prepare).isInstanceOf(PreparationException.class);
transaction1.rollback();
// Assert
transaction = manager.start();
result = transaction.get(prepareGet(0, 0, TABLE_1));
assertThat(result).isPresent();
assertThat(getBalance(result.get())).isEqualTo(1);
transaction.prepare();
transaction.commit();
}
use of com.scalar.db.transaction.rpc.GrpcTwoPhaseCommitTransaction in project scalardb by scalar-labs.
the class TwoPhaseCommitTransactionServiceWithTwoPhaseConsensusCommitIntegrationTest method get_CalledTwiceAndAnotherTransactionCommitsInBetween_ShouldReturnFromSnapshotInSecondTime.
@Test
public void get_CalledTwiceAndAnotherTransactionCommitsInBetween_ShouldReturnFromSnapshotInSecondTime() throws TransactionException {
// Arrange
GrpcTwoPhaseCommitTransaction transaction = manager.start();
// Act
Optional<Result> result1 = transaction.get(prepareGet(0, 0, TABLE_1));
populate(TABLE_1);
Optional<Result> result2 = transaction.get(prepareGet(0, 0, TABLE_1));
transaction.prepare();
transaction.commit();
// Assert
assertThat(result1).isEqualTo(result2);
}
use of com.scalar.db.transaction.rpc.GrpcTwoPhaseCommitTransaction in project scalardb by scalar-labs.
the class TwoPhaseCommitTransactionServiceWithTwoPhaseConsensusCommitIntegrationTest method commit_DeleteGivenForExistingAfterRead_ShouldDeleteRecord.
@Test
public void commit_DeleteGivenForExistingAfterRead_ShouldDeleteRecord() throws TransactionException {
// Arrange
populate(TABLE_1);
GrpcTwoPhaseCommitTransaction transaction = manager.start();
// Act
Optional<Result> result = transaction.get(prepareGet(0, 0, TABLE_1));
transaction.delete(prepareDelete(0, 0, TABLE_1));
transaction.prepare();
transaction.commit();
// Assert
assertThat(result.isPresent()).isTrue();
GrpcTwoPhaseCommitTransaction another = manager.start();
result = another.get(prepareGet(0, 0, TABLE_1));
another.prepare();
another.commit();
assertThat(result.isPresent()).isFalse();
}
Aggregations