use of com.hazelcast.transaction.TransactionOptions in project hazelcast by hazelcast.
the class TransactionImpl_TwoPhaseIntegrationTest method prepare_whenMultipleItemsAndDurabilityOne_thenRemoveBackupLog.
@Test
public void prepare_whenMultipleItemsAndDurabilityOne_thenRemoveBackupLog() {
final String txOwner = localNodeEngine.getLocalMember().getUuid();
TransactionOptions options = new TransactionOptions().setTransactionType(TWO_PHASE).setDurability(1);
final TransactionImpl tx = new TransactionImpl(localTxService, localNodeEngine, options, txOwner);
tx.begin();
tx.add(new MockTransactionLogRecord());
tx.add(new MockTransactionLogRecord());
tx.prepare();
assertPrepared(tx);
TxBackupLog log = remoteTxService.txBackupLogs.get(tx.getTxnId());
assertNotNull(log);
cluster[0].shutdown();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertFalse(remoteTxService.txBackupLogs.containsKey(tx.getTxnId()));
}
});
}
use of com.hazelcast.transaction.TransactionOptions in project hazelcast by hazelcast.
the class TransactionImpl_TwoPhaseTest method begin_whenBeginThrowsException.
// =================== begin ==================================================
@Test
public void begin_whenBeginThrowsException() throws Exception {
RuntimeException expectedException = new RuntimeException("example exception");
when(txManagerService.pickBackupLogAddresses(anyInt())).thenThrow(expectedException);
TransactionOptions options = new TransactionOptions().setTransactionType(TWO_PHASE).setDurability(0);
TransactionImpl tx = new TransactionImpl(txManagerService, nodeEngine, options, null);
try {
tx.begin();
fail("Transaction expected to fail");
} catch (Exception e) {
assertEquals(expectedException, e);
}
// other independent transaction in same thread
// should behave identically
tx = new TransactionImpl(txManagerService, nodeEngine, options, "123");
try {
tx.begin();
fail("Transaction expected to fail");
} catch (Exception e) {
assertEquals(expectedException, e);
}
}
use of com.hazelcast.transaction.TransactionOptions in project hazelcast by hazelcast.
the class TransactionImpl_TwoPhaseTest method commit_whenOneTransactionLogRecord_thenCommit.
// there is an optimization for single item transactions so they can commit without preparing
@Test
public void commit_whenOneTransactionLogRecord_thenCommit() {
TransactionOptions options = new TransactionOptions().setTransactionType(TWO_PHASE).setDurability(0);
TransactionImpl tx = new TransactionImpl(txManagerService, nodeEngine, options, "dummy-uuid");
tx.begin();
tx.add(new MockTransactionLogRecord());
tx.commit();
assertEquals(COMMITTED, tx.getState());
}
use of com.hazelcast.transaction.TransactionOptions in project hazelcast by hazelcast.
the class TransactionImpl_TwoPhaseTest method prepare_whenThrowsExceptionDuringPrepare.
// =================== prepare ==================================================
@Test(expected = TransactionException.class)
public void prepare_whenThrowsExceptionDuringPrepare() throws Exception {
TransactionOptions options = new TransactionOptions().setTransactionType(TWO_PHASE).setDurability(0);
TransactionImpl tx = new TransactionImpl(txManagerService, nodeEngine, options, "dummy-uuid");
tx.begin();
tx.add(new MockTransactionLogRecord().failPrepare());
tx.prepare();
}
use of com.hazelcast.transaction.TransactionOptions in project hazelcast by hazelcast.
the class TransactionImpl_TwoPhaseTest method rollback_whenRollingBackCommitFailedTransaction.
@Test
public void rollback_whenRollingBackCommitFailedTransaction() {
TransactionOptions options = new TransactionOptions().setTransactionType(TWO_PHASE).setDurability(0);
TransactionImpl tx = new TransactionImpl(txManagerService, nodeEngine, options, "dummy-uuid");
tx.begin();
tx.add(new MockTransactionLogRecord().failCommit());
try {
tx.commit();
fail();
} catch (TransactionException expected) {
}
tx.rollback();
assertEquals(ROLLED_BACK, tx.getState());
}
Aggregations