Search in sources :

Example 16 with TransactionOptions

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

the class TransactionImpl_TwoPhaseIntegrationTest method commit_whenMultipleItemsAndDurabilityZero_thenNoBackupLog.

@Test
public void commit_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.commit();
    assertCommitted(tx);
    assertNoBackupLogOnRemote(tx);
    record1.assertPrepareCalled().assertCommitCalled().assertRollbackNotCalled();
    record2.assertPrepareCalled().assertCommitCalled().assertRollbackNotCalled();
}
Also used : TransactionOptions(com.hazelcast.transaction.TransactionOptions) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 17 with TransactionOptions

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

the class TransactionImpl_TwoPhaseIntegrationTest method prepare_whenMultipleItemsAndDurabilityOne_thenBackupLog.

@Test
public void prepare_whenMultipleItemsAndDurabilityOne_thenBackupLog() {
    TransactionOptions options = new TransactionOptions().setTransactionType(TWO_PHASE).setDurability(1);
    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();
    assertPrepared(tx);
    TxBackupLog log = remoteTxService.txBackupLogs.get(tx.getTxnId());
    assertNotNull(log);
    assertEquals(COMMITTING, log.state);
    record1.assertPrepareCalled().assertCommitNotCalled().assertRollbackNotCalled();
    record2.assertPrepareCalled().assertCommitNotCalled().assertRollbackNotCalled();
}
Also used : TransactionOptions(com.hazelcast.transaction.TransactionOptions) TxBackupLog(com.hazelcast.transaction.impl.TransactionManagerServiceImpl.TxBackupLog) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 18 with TransactionOptions

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

the class TransactionImpl_TwoPhaseIntegrationTest method rollback_whenMultipleItemsAndDurabilityOne_thenBackupLog.

@Test
public void rollback_whenMultipleItemsAndDurabilityOne_thenBackupLog() {
    TransactionOptions options = new TransactionOptions().setTransactionType(TWO_PHASE).setDurability(1);
    final 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);
    // it can take some time because the transaction doesn't sync on purging the backups.
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertNoBackupLogOnRemote(tx);
        }
    });
    record1.assertPrepareCalled().assertCommitNotCalled().assertRollbackCalled();
    record2.assertPrepareCalled().assertCommitNotCalled().assertRollbackCalled();
}
Also used : TransactionOptions(com.hazelcast.transaction.TransactionOptions) AssertTask(com.hazelcast.test.AssertTask) TransactionException(com.hazelcast.transaction.TransactionException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 19 with TransactionOptions

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

the class TransactionImpl_TwoPhaseIntegrationTest method commit_whenMultipleItemsAndDurabilityOne_thenBackupLog.

@Test
public void commit_whenMultipleItemsAndDurabilityOne_thenBackupLog() {
    TransactionOptions options = new TransactionOptions().setTransactionType(TWO_PHASE).setDurability(1);
    final 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.commit();
    assertCommitted(tx);
    // it can take some time because the transaction doesn't sync on purging the backups.
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertNoBackupLogOnRemote(tx);
        }
    });
    record1.assertPrepareCalled().assertCommitCalled().assertRollbackNotCalled();
    record2.assertPrepareCalled().assertCommitCalled().assertRollbackNotCalled();
}
Also used : TransactionOptions(com.hazelcast.transaction.TransactionOptions) AssertTask(com.hazelcast.test.AssertTask) TransactionException(com.hazelcast.transaction.TransactionException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 20 with TransactionOptions

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

the class TransactionImpl_TwoPhaseIntegrationTest method rollback_whenSingleItemAndDurabilityOne_thenNoBackupLog.

// =================== rollback ===========================================
@Test
public void rollback_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.rollback();
    assertRolledBack(tx);
    assertNoBackupLogOnRemote(tx);
    record.assertPrepareCalled().assertCommitNotCalled().assertRollbackCalled();
}
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