Search in sources :

Example 1 with TransactionalQueue

use of com.hazelcast.transaction.TransactionalQueue 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 (TransactionException 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.transaction.TransactionalQueue) TransactionException(com.hazelcast.transaction.TransactionException) TransactionContext(com.hazelcast.transaction.TransactionContext) MembershipEvent(com.hazelcast.cluster.MembershipEvent) MembershipAdapter(com.hazelcast.cluster.MembershipAdapter) CountDownLatch(java.util.concurrent.CountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with TransactionalQueue

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

the class TransactionalQueuePeekMessageTask method innerCall.

@Override
protected Object innerCall() throws Exception {
    final TransactionContext context = endpoint.getTransactionContext(parameters.txnId);
    final TransactionalQueue queue = context.getQueue(parameters.name);
    Object item = queue.peek(parameters.timeout, TimeUnit.MILLISECONDS);
    return serializationService.toData(item);
}
Also used : TransactionalQueue(com.hazelcast.transaction.TransactionalQueue) TransactionContext(com.hazelcast.transaction.TransactionContext)

Example 3 with TransactionalQueue

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

the class TransactionalQueueOfferMessageTask method innerCall.

@Override
protected Object innerCall() throws Exception {
    final TransactionContext context = endpoint.getTransactionContext(parameters.txnId);
    final TransactionalQueue queue = context.getQueue(parameters.name);
    return queue.offer(parameters.item, parameters.timeout, TimeUnit.MILLISECONDS);
}
Also used : TransactionalQueue(com.hazelcast.transaction.TransactionalQueue) TransactionContext(com.hazelcast.transaction.TransactionContext)

Example 4 with TransactionalQueue

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

the class TransactionsWithWriteBehind_whenNoCoalescingQueueIsFullTest method rollback_successful_when_prepare_step_throws_exception_when_two_phase.

@Test
public void rollback_successful_when_prepare_step_throws_exception_when_two_phase() {
    String mapName = "map";
    String queueName = "queue";
    long maxWbqCapacity = 100;
    Config config = getConfig(mapName, maxWbqCapacity);
    HazelcastInstance node = createHazelcastInstance(config);
    TransactionContext context = newTransactionContext(node, TWO_PHASE);
    try {
        context.beginTransaction();
        TransactionalQueue queue = context.getQueue(queueName);
        queue.offer(1);
        queue.offer(2);
        queue.offer(3);
        TransactionalMap map = context.getMap(mapName);
        for (int i = 0; i < 1000; i++) {
            map.put("item-" + i, "value");
        }
        context.commitTransaction();
    } catch (TransactionException e) {
        context.rollbackTransaction();
    }
    assertEquals(0, node.getQueue(queueName).size());
    assertEquals(0, node.getMap(mapName).size());
}
Also used : TransactionalMap(com.hazelcast.transaction.TransactionalMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionalQueue(com.hazelcast.transaction.TransactionalQueue) TransactionException(com.hazelcast.transaction.TransactionException) Config(com.hazelcast.config.Config) TransactionContext(com.hazelcast.transaction.TransactionContext) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with TransactionalQueue

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

the class TransactionalQueuePollMessageTask method innerCall.

@Override
protected Object innerCall() throws Exception {
    final TransactionContext context = endpoint.getTransactionContext(parameters.txnId);
    final TransactionalQueue queue = context.getQueue(parameters.name);
    Object item = queue.poll(parameters.timeout, TimeUnit.MILLISECONDS);
    return serializationService.toData(item);
}
Also used : TransactionalQueue(com.hazelcast.transaction.TransactionalQueue) TransactionContext(com.hazelcast.transaction.TransactionContext)

Aggregations

TransactionContext (com.hazelcast.transaction.TransactionContext)13 TransactionalQueue (com.hazelcast.transaction.TransactionalQueue)13 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)8 QuickTest (com.hazelcast.test.annotation.QuickTest)8 Test (org.junit.Test)8 IQueue (com.hazelcast.collection.IQueue)5 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)4 TransactionException (com.hazelcast.transaction.TransactionException)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 MembershipAdapter (com.hazelcast.cluster.MembershipAdapter)2 MembershipEvent (com.hazelcast.cluster.MembershipEvent)2 Config (com.hazelcast.config.Config)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 ItemEvent (com.hazelcast.collection.ItemEvent)1 ItemListener (com.hazelcast.collection.ItemListener)1 QueueService (com.hazelcast.collection.impl.queue.QueueService)1 VersionedObject (com.hazelcast.collection.impl.queue.model.VersionedObject)1 VersionedObjectComparator (com.hazelcast.collection.impl.queue.model.VersionedObjectComparator)1 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)1 Accessors.getNode (com.hazelcast.test.Accessors.getNode)1