Search in sources :

Example 41 with TransactionOptions

use of com.hazelcast.transaction.TransactionOptions in project hazelcast by hazelcast.

the class TransactionImpl_TwoPhaseIntegrationTest method commit_whenPrepareSkippedButCommitRunsIntoConflict.

@Test
public void commit_whenPrepareSkippedButCommitRunsIntoConflict() {
    TransactionOptions options = new TransactionOptions().setTransactionType(TWO_PHASE).setDurability(1);
    TransactionImpl tx = new TransactionImpl(localTxService, localNodeEngine, options, txOwner);
    tx.begin();
    MockTransactionLogRecord record = new MockTransactionLogRecord().failCommit();
    tx.add(record);
    try {
        tx.commit();
        fail();
    } catch (TransactionException expected) {
    }
    assertCommitFailed(tx);
    assertNoBackupLogOnRemote(tx);
    record.assertPrepareNotCalled().assertCommitCalled().assertRollbackNotCalled();
}
Also used : TransactionException(com.hazelcast.transaction.TransactionException) TransactionOptions(com.hazelcast.transaction.TransactionOptions) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 42 with TransactionOptions

use of com.hazelcast.transaction.TransactionOptions in project hazelcast by hazelcast.

the class TransactionImpl_TwoPhaseIntegrationTest method commit_whenSingleItemAndDurabilityOne_thenNoBackupLog.

// =================== commit ===========================================
@Test
public void commit_whenSingleItemAndDurabilityOne_thenNoBackupLog() {
    TransactionOptions options = new TransactionOptions().setTransactionType(TWO_PHASE).setDurability(1);
    TransactionImpl tx = new TransactionImpl(localTxService, localNodeEngine, options, txOwner);
    tx.begin();
    MockTransactionLogRecord record = new MockTransactionLogRecord();
    tx.add(record);
    tx.prepare();
    tx.commit();
    assertCommitted(tx);
    assertNoBackupLogOnRemote(tx);
    record.assertPrepareCalled().assertCommitCalled().assertRollbackNotCalled();
}
Also used : TransactionOptions(com.hazelcast.transaction.TransactionOptions) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 43 with TransactionOptions

use of com.hazelcast.transaction.TransactionOptions in project hazelcast by hazelcast.

the class TransactionImpl_TwoPhaseTest method commit_whenThrowsExceptionDuringCommit.

@Test
public void commit_whenThrowsExceptionDuringCommit() 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().failCommit());
    tx.prepare();
    try {
        tx.commit();
        fail();
    } catch (TransactionException expected) {
    }
    assertEquals(COMMIT_FAILED, tx.getState());
}
Also used : TransactionException(com.hazelcast.transaction.TransactionException) TransactionOptions(com.hazelcast.transaction.TransactionOptions) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 44 with TransactionOptions

use of com.hazelcast.transaction.TransactionOptions in project hazelcast by hazelcast.

the class TransactionImpl_TwoPhaseTest method rollback_whenFailureDuringRollback.

@Test
public void rollback_whenFailureDuringRollback() {
    TransactionOptions options = new TransactionOptions().setTransactionType(TWO_PHASE).setDurability(0);
    TransactionImpl tx = new TransactionImpl(txManagerService, nodeEngine, options, "dummy-uuid");
    tx.begin();
    tx.add(new MockTransactionLogRecord().failRollback());
    tx.rollback();
}
Also used : TransactionOptions(com.hazelcast.transaction.TransactionOptions) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 45 with TransactionOptions

use of com.hazelcast.transaction.TransactionOptions in project hazelcast by hazelcast.

the class TransactionImpl_TwoPhaseTest method commit_whenNotActive.

// =================== commit ==================================================
@Test(expected = IllegalStateException.class)
public void commit_whenNotActive() {
    TransactionOptions options = new TransactionOptions().setTransactionType(TWO_PHASE).setDurability(0);
    TransactionImpl tx = new TransactionImpl(txManagerService, nodeEngine, options, "dummy-uuid");
    tx.begin();
    tx.rollback();
    tx.commit();
}
Also used : 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