Search in sources :

Example 56 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 57 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 58 with TransactionOptions

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

the class TransactionImpl_TwoPhaseIntegrationTest method rollback_whenMultipleItemsAndDurabilityZero_thenNoBackupLog.

@Test
public void rollback_whenMultipleItemsAndDurabilityZero_thenNoBackupLog() {
    TransactionOptions options = new TransactionOptions().setTransactionType(TWO_PHASE).setDurability(0);
    TransactionImpl tx = new TransactionImpl(localTxService, localNodeEngine, options, txOwner);
    tx.begin();
    MockTransactionLogRecord record1 = new MockTransactionLogRecord();
    tx.add(record1);
    MockTransactionLogRecord record2 = new MockTransactionLogRecord();
    tx.add(record2);
    tx.prepare();
    tx.rollback();
    assertRolledBack(tx);
    assertNoBackupLogOnRemote(tx);
    record1.assertPrepareCalled().assertCommitNotCalled().assertRollbackCalled();
    record2.assertPrepareCalled().assertCommitNotCalled().assertRollbackCalled();
}
Also used : TransactionOptions(com.hazelcast.transaction.TransactionOptions) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 59 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, UUID.randomUUID());
    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 60 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, UUID.randomUUID());
    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)64 Test (org.junit.Test)41 QuickTest (com.hazelcast.test.annotation.QuickTest)33 HazelcastInstance (com.hazelcast.core.HazelcastInstance)20 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)19 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)13 TransactionException (com.hazelcast.transaction.TransactionException)13 TransactionContext (com.hazelcast.transaction.TransactionContext)10 Parameters (org.junit.runners.Parameterized.Parameters)10 TransactionManagerServiceImpl (com.hazelcast.transaction.impl.TransactionManagerServiceImpl)9 SlowTest (com.hazelcast.test.annotation.SlowTest)8 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)5 Config (com.hazelcast.config.Config)4 AssertTask (com.hazelcast.test.AssertTask)4 NightlyTest (com.hazelcast.test.annotation.NightlyTest)3 TransactionalMap (com.hazelcast.transaction.TransactionalMap)3 Address (com.hazelcast.cluster.Address)2 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)2 MapStoreConfig (com.hazelcast.config.MapStoreConfig)2 ILogger (com.hazelcast.logging.ILogger)2