Search in sources :

Example 46 with TransactionContext

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

the class TransactionQueueTest method testRollbackQueue.

@Test
public void testRollbackQueue() throws Throwable {
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(4);
    final HazelcastInstance h1 = factory.newHazelcastInstance();
    final TransactionContext transactionContext = h1.newTransactionContext();
    transactionContext.beginTransaction();
    TransactionalQueue<String> queue = transactionContext.getQueue("testq");
    queue.offer("offered-val");
    transactionContext.rollbackTransaction();
    assertNull(h1.getQueue("testq").poll());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionContext(com.hazelcast.transaction.TransactionContext) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 47 with TransactionContext

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

the class TransactionalSetAbstractTest method testSetSizeAfterAdd_withinTxn.

@Test
public void testSetSizeAfterAdd_withinTxn() throws Exception {
    TransactionContext context = local.newTransactionContext();
    context.beginTransaction();
    TransactionalSet<Object> txnSet = context.getSet(setName);
    txnSet.add(ELEMENT);
    context.commitTransaction();
    assertEquals(1, set.size());
}
Also used : TransactionContext(com.hazelcast.transaction.TransactionContext) Test(org.junit.Test)

Example 48 with TransactionContext

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

the class TransactionalSetAbstractTest method testAddDuplicateElement_withinTxn.

@Test
public void testAddDuplicateElement_withinTxn() throws Exception {
    TransactionContext context = local.newTransactionContext();
    context.beginTransaction();
    TransactionalSet<Object> txnSet = context.getSet(setName);
    assertTrue(txnSet.add(ELEMENT));
    assertFalse(txnSet.add(ELEMENT));
    context.commitTransaction();
    assertEquals(1, local.getSet(setName).size());
}
Also used : TransactionContext(com.hazelcast.transaction.TransactionContext) Test(org.junit.Test)

Example 49 with TransactionContext

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

the class TransactionalSetAbstractTest method testRemove_withinTxn.

@Test
public void testRemove_withinTxn() throws Exception {
    set.add(ELEMENT);
    TransactionContext context = local.newTransactionContext();
    context.beginTransaction();
    TransactionalSet<Object> txnSet = context.getSet(setName);
    assertTrue(txnSet.remove(ELEMENT));
    assertFalse(txnSet.remove("NOT_THERE"));
    context.commitTransaction();
    assertEquals(0, set.size());
}
Also used : TransactionContext(com.hazelcast.transaction.TransactionContext) Test(org.junit.Test)

Example 50 with TransactionContext

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

the class TransactionalSetAbstractTest method testAdd_withinTxn.

@Test
public void testAdd_withinTxn() throws Exception {
    TransactionContext context = local.newTransactionContext();
    context.beginTransaction();
    TransactionalSet<Object> txnSet = context.getSet(setName);
    assertTrue(txnSet.add(ELEMENT));
    assertEquals(1, txnSet.size());
    context.commitTransaction();
    assertEquals(1, set.size());
}
Also used : TransactionContext(com.hazelcast.transaction.TransactionContext) Test(org.junit.Test)

Aggregations

TransactionContext (com.hazelcast.transaction.TransactionContext)280 Test (org.junit.Test)209 QuickTest (com.hazelcast.test.annotation.QuickTest)189 ParallelTest (com.hazelcast.test.annotation.ParallelTest)184 HazelcastInstance (com.hazelcast.core.HazelcastInstance)58 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)48 TransactionalMap (com.hazelcast.core.TransactionalMap)33 TransactionException (com.hazelcast.transaction.TransactionException)22 IMap (com.hazelcast.core.IMap)21 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)19 Config (com.hazelcast.config.Config)17 NightlyTest (com.hazelcast.test.annotation.NightlyTest)16 CountDownLatch (java.util.concurrent.CountDownLatch)14 XAException (javax.transaction.xa.XAException)14 TransactionalQueue (com.hazelcast.core.TransactionalQueue)13 TransactionalMultiMap (com.hazelcast.core.TransactionalMultiMap)9 HazelcastXAResource (com.hazelcast.transaction.HazelcastXAResource)9 ExecutionException (java.util.concurrent.ExecutionException)9 ISet (com.hazelcast.core.ISet)8 MultiMap (com.hazelcast.core.MultiMap)8