use of com.hazelcast.transaction.TransactionalQueue in project hazelcast by hazelcast.
the class TransactionalQueueTakeMessageTask 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.take();
return serializationService.toData(item);
}
use of com.hazelcast.transaction.TransactionalQueue in project hazelcast by hazelcast.
the class TransactionalQueueSizeMessageTask method innerCall.
@Override
protected Object innerCall() throws Exception {
final TransactionContext context = endpoint.getTransactionContext(parameters.txnId);
final TransactionalQueue queue = context.getQueue(parameters.name);
return queue.size();
}
use of com.hazelcast.transaction.TransactionalQueue in project hazelcast by hazelcast.
the class ClientTxnQueueTest method testTransactionalQueueGetsOfferedItems_whenBlockedOnPoll.
@Test
public void testTransactionalQueueGetsOfferedItems_whenBlockedOnPoll() throws InterruptedException {
final String item = "offered1";
final String queueName = randomString();
final IQueue queue1 = client.getQueue(queueName);
final CountDownLatch justBeforeBlocked = new CountDownLatch(1);
new Thread() {
public void run() {
try {
justBeforeBlocked.await();
sleepSeconds(1);
queue1.offer(item);
} catch (InterruptedException e) {
fail("failed" + e);
}
}
}.start();
final TransactionContext context = client.newTransactionContext();
context.beginTransaction();
TransactionalQueue txnQueue1 = context.getQueue(queueName);
justBeforeBlocked.countDown();
Object result = txnQueue1.poll(5, TimeUnit.SECONDS);
assertEquals("TransactionalQueue while blocked in pol should get item offered from client queue", item, result);
context.commitTransaction();
}
use of com.hazelcast.transaction.TransactionalQueue in project hazelcast by hazelcast.
the class ClientTxnQueueTest method testTransactionalPeek.
@Test
public void testTransactionalPeek() {
final String item = "offered";
final String queunName = randomString();
final IQueue queue = client.getQueue(queunName);
final TransactionContext context = client.newTransactionContext();
context.beginTransaction();
TransactionalQueue txnQueue = context.getQueue(queunName);
txnQueue.offer(item);
assertEquals(item, txnQueue.peek());
assertEquals(item, txnQueue.peek());
context.commitTransaction();
}
use of com.hazelcast.transaction.TransactionalQueue in project hazelcast by hazelcast.
the class ClientTxnQueueTest method testTransactionalOfferPoll.
@Test
public void testTransactionalOfferPoll() {
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);
assertEquals(item, txnQueue.poll());
context.commitTransaction();
}
Aggregations