Search in sources :

Example 21 with TransactionContext

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

the class ClientTransactionalMapQuorumTest method testTxValuesWithPredicateSucceedsWhenQuorumSizeMet.

@Test
public void testTxValuesWithPredicateSucceedsWhenQuorumSizeMet() {
    TransactionContext transaction = getTransactionFromMajority();
    TransactionalMap<Object, Object> map = getMap(transaction);
    map.values(TruePredicate.INSTANCE);
    transaction.commitTransaction();
}
Also used : TransactionContext(com.hazelcast.transaction.TransactionContext) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 22 with TransactionContext

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

the class ClientTxnSetTest method testSetSizeAfterAddingDuplicateElement_withinTxn.

@Test
public void testSetSizeAfterAddingDuplicateElement_withinTxn() throws Exception {
    final String element = "item1";
    final String setName = randomString();
    final ISet set = client.getSet(setName);
    set.add(element);
    final TransactionContext context = client.newTransactionContext();
    context.beginTransaction();
    final TransactionalSet<Object> txnSet = context.getSet(setName);
    txnSet.add(element);
    context.commitTransaction();
    assertEquals(1, set.size());
}
Also used : TransactionContext(com.hazelcast.transaction.TransactionContext) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) ISet(com.hazelcast.core.ISet) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 23 with TransactionContext

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

the class ClientTxnTest method testTxnRollbackOnServerCrash.

@Test
public void testTxnRollbackOnServerCrash() throws Exception {
    final String queueName = randomString();
    final TransactionContext context = client.newTransactionContext();
    CountDownLatch txnRollbackLatch = new CountDownLatch(1);
    final CountDownLatch memberRemovedLatch = new CountDownLatch(1);
    context.beginTransaction();
    final TransactionalQueue queue = context.getQueue(queueName);
    queue.offer(randomString());
    client.getCluster().addMembershipListener(new MembershipAdapter() {

        @Override
        public void memberRemoved(MembershipEvent membershipEvent) {
            memberRemovedLatch.countDown();
        }
    });
    server.getLifecycleService().terminate();
    try {
        context.commitTransaction();
        fail("commit should throw exception !");
    } catch (Exception e) {
        context.rollbackTransaction();
        txnRollbackLatch.countDown();
    }
    assertOpenEventually(txnRollbackLatch);
    assertOpenEventually(memberRemovedLatch);
    final IQueue<Object> q = client.getQueue(queueName);
    assertNull(q.poll());
    assertEquals(0, q.size());
}
Also used : TransactionalQueue(com.hazelcast.core.TransactionalQueue) TransactionContext(com.hazelcast.transaction.TransactionContext) MembershipEvent(com.hazelcast.core.MembershipEvent) MembershipAdapter(com.hazelcast.core.MembershipAdapter) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 24 with TransactionContext

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

the class ClientXACompatibilityTest method testGetXAResource_TransactionProxy.

@Test(expected = UnsupportedOperationException.class)
public void testGetXAResource_TransactionProxy() throws Exception {
    xaResource.start(xid, TMNOFLAGS);
    TransactionContext transactionContext = xaResource.getTransactionContext();
    transactionContext.getXaResource();
}
Also used : TransactionContext(com.hazelcast.transaction.TransactionContext) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 25 with TransactionContext

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

the class ClientXACompatibilityTest method testPrepare_AlreadyPreparedTransaction.

@Test(expected = TransactionNotActiveException.class)
public void testPrepare_AlreadyPreparedTransaction() throws Exception {
    xaResource.start(xid, TMNOFLAGS);
    TransactionContext context = xaResource.getTransactionContext();
    TransactionalMap<Object, Object> map = context.getMap("map");
    map.put("key", "val");
    xaResource.end(xid, TMSUCCESS);
    xaResource.prepare(xid);
    xaResource.prepare(xid);
}
Also used : TransactionContext(com.hazelcast.transaction.TransactionContext) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

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