use of com.hazelcast.transaction.TransactionalQueue in project hazelcast by hazelcast.
the class ClientTxnQueueTest method testQueueSizeAfterTxnOfferPoll.
@Test
public void testQueueSizeAfterTxnOfferPoll() {
final String item = "offered";
final String queueName = randomString();
final IQueue queue = client.getQueue(queueName);
final TransactionContext context = client.newTransactionContext();
context.beginTransaction();
TransactionalQueue txnQueue = context.getQueue(queueName);
txnQueue.offer(item);
txnQueue.poll();
context.commitTransaction();
assertEquals(0, queue.size());
}
use of com.hazelcast.transaction.TransactionalQueue in project hazelcast by hazelcast.
the class ClientTxnTest method testTxnRollback.
@Test
public void testTxnRollback() throws Exception {
final String queueName = randomString();
final TransactionContext context = client.newTransactionContext();
CountDownLatch txnRollbackLatch = new CountDownLatch(1);
final CountDownLatch memberRemovedLatch = new CountDownLatch(1);
client.getCluster().addMembershipListener(new MembershipAdapter() {
@Override
public void memberRemoved(MembershipEvent membershipEvent) {
memberRemovedLatch.countDown();
}
});
try {
context.beginTransaction();
assertNotNull(context.getTxnId());
final TransactionalQueue queue = context.getQueue(queueName);
queue.offer(randomString());
server.shutdown();
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());
}
use of com.hazelcast.transaction.TransactionalQueue in project hazelcast by hazelcast.
the class TransactionQueueTest method testListener_withOffer.
@Test
public void testListener_withOffer() {
HazelcastInstance hz = createHazelcastInstance();
String name = randomName();
IQueue<VersionedObject<String>> queue = hz.getQueue(name);
EventCountingItemListener listener = new EventCountingItemListener();
queue.addItemListener(listener, true);
hz.executeTransaction((TransactionalTask<Object>) ctx -> {
TransactionalQueue<VersionedObject<Object>> queue1 = ctx.getQueue(name);
return queue1.offer(new VersionedObject<>("item"));
});
assertTrueEventually(() -> assertEquals(1, listener.adds.get()));
}
Aggregations