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());
}
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);
}
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);
}
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());
}
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);
}
Aggregations