use of com.hazelcast.core.TransactionalQueue in project hazelcast by hazelcast.
the class QueueTestsFrom2X method testQueuePollRollbackSize.
@Test
public void testQueuePollRollbackSize() {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance instance = factory.newHazelcastInstance();
factory.newHazelcastInstance();
TransactionContext context = instance.newTransactionContext();
IQueue<Object> queue = instance.getQueue("testQueuePollRollbackSize");
queue.offer("item1");
queue.offer("item2");
assertEquals(2, queue.size());
context.beginTransaction();
TransactionalQueue txnQ1 = context.getQueue("testQueuePollRollbackSize");
assertEquals("item1", txnQ1.poll());
assertEquals(1, txnQ1.size());
assertEquals(1, queue.size());
context.rollbackTransaction();
assertEquals(2, queue.size());
assertEquals("item1", queue.poll());
assertEquals("item2", queue.poll());
}
use of com.hazelcast.core.TransactionalQueue in project hazelcast by hazelcast.
the class TransactionQueueTest method issue_6259_backupNotRollingBackCorrectly.
// https://github.com/hazelcast/hazelcast/issues/6259
@Test
public void issue_6259_backupNotRollingBackCorrectly() {
HazelcastInstance[] cluster = createHazelcastInstanceFactory(2).newInstances();
HazelcastInstance local = cluster[0];
HazelcastInstance remote = cluster[1];
final String queueName = generateKeyOwnedBy(remote);
// first we add an item
local.executeTransaction(new TransactionalTask<Object>() {
@Override
public Object execute(TransactionalTaskContext context) throws TransactionException {
TransactionalQueue<String> queue = context.getQueue(queueName);
queue.offer("item");
return null;
}
});
// we remove the item and then do a rollback. This causes the local (backup) to become out
// of sync with the remote (primary)
TransactionContext firstCtxt = local.newTransactionContext();
firstCtxt.beginTransaction();
TransactionalQueue<String> queue = firstCtxt.getQueue(queueName);
queue.poll();
firstCtxt.rollbackTransaction();
// we kill the remote. Now the local (which was the backup) is going to become primary
remote.shutdown();
// if we take the item, we should get an error
TransactionContext secondCtxt = local.newTransactionContext();
secondCtxt.beginTransaction();
queue = secondCtxt.getQueue(queueName);
String found = queue.poll();
assertEquals("item", found);
}
use of com.hazelcast.core.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);
}
use of com.hazelcast.core.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);
}
use of com.hazelcast.core.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 (Exception e) {
context.rollbackTransaction();
txnRollbackLatch.countDown();
}
assertOpenEventually(txnRollbackLatch);
assertOpenEventually(memberRemovedLatch);
final IQueue<Object> q = client.getQueue(queueName);
assertNull(q.poll());
assertEquals(0, q.size());
}
Aggregations