Search in sources :

Example 21 with TransactionOptions

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()));
        }
    });
}
Also used : TransactionOptions(com.hazelcast.transaction.TransactionOptions) AssertTask(com.hazelcast.test.AssertTask) TxBackupLog(com.hazelcast.transaction.impl.TransactionManagerServiceImpl.TxBackupLog) TransactionException(com.hazelcast.transaction.TransactionException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 22 with TransactionOptions

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);
    }
}
Also used : TransactionOptions(com.hazelcast.transaction.TransactionOptions) TransactionException(com.hazelcast.transaction.TransactionException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 23 with TransactionOptions

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());
}
Also used : TransactionOptions(com.hazelcast.transaction.TransactionOptions) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 24 with TransactionOptions

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();
}
Also used : TransactionOptions(com.hazelcast.transaction.TransactionOptions) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 25 with TransactionOptions

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());
}
Also used : TransactionException(com.hazelcast.transaction.TransactionException) TransactionOptions(com.hazelcast.transaction.TransactionOptions) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

TransactionOptions (com.hazelcast.transaction.TransactionOptions)47 QuickTest (com.hazelcast.test.annotation.QuickTest)36 Test (org.junit.Test)36 TransactionException (com.hazelcast.transaction.TransactionException)18 HazelcastInstance (com.hazelcast.core.HazelcastInstance)15 ParallelTest (com.hazelcast.test.annotation.ParallelTest)14 AssertTask (com.hazelcast.test.AssertTask)9 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)9 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)7 TransactionManagerServiceImpl (com.hazelcast.transaction.impl.TransactionManagerServiceImpl)7 ExecutionException (java.util.concurrent.ExecutionException)7 TargetNotMemberException (com.hazelcast.spi.exception.TargetNotMemberException)6 TransactionContext (com.hazelcast.transaction.TransactionContext)6 Config (com.hazelcast.config.Config)3 NightlyTest (com.hazelcast.test.annotation.NightlyTest)3 MapStoreConfig (com.hazelcast.config.MapStoreConfig)2 TransactionalMap (com.hazelcast.core.TransactionalMap)2 MemberImpl (com.hazelcast.instance.MemberImpl)2 ILogger (com.hazelcast.logging.ILogger)2 Address (com.hazelcast.nio.Address)2