Search in sources :

Example 1 with IQueue

use of com.hazelcast.collection.IQueue in project hazelcast by hazelcast.

the class ClientQueueTest method testPoll_whenInterruptedWhileBlocking.

@Test(expected = InterruptedException.class)
public void testPoll_whenInterruptedWhileBlocking() throws InterruptedException {
    IQueue queue = client.getQueue(randomString());
    interruptCurrentThread(2000);
    queue.poll(1, TimeUnit.MINUTES);
}
Also used : IQueue(com.hazelcast.collection.IQueue) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with IQueue

use of com.hazelcast.collection.IQueue in project hazelcast by hazelcast.

the class ClientTxnQueueTest method testTransactionalOfferRoleBack.

@Test
public void testTransactionalOfferRoleBack() {
    final String name = randomString();
    final IQueue queue = client.getQueue(name);
    final TransactionContext context = client.newTransactionContext();
    context.beginTransaction();
    TransactionalQueue<String> qTxn = context.getQueue(name);
    qTxn.offer("ITEM");
    context.rollbackTransaction();
    assertEquals(0, queue.size());
}
Also used : IQueue(com.hazelcast.collection.IQueue) TransactionContext(com.hazelcast.transaction.TransactionContext) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with IQueue

use of com.hazelcast.collection.IQueue in project hazelcast by hazelcast.

the class Invocation_BlockingTest method sync_whenInterruptionDuringBlockingOp.

@Test
public void sync_whenInterruptionDuringBlockingOp() throws InterruptedException {
    HazelcastInstance hz = createHazelcastInstance();
    final IQueue queue = hz.getQueue(randomName());
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicBoolean interruptedFlag = new AtomicBoolean(false);
    final OpThread thread = new OpThread("Queue-Poll-Thread", latch, interruptedFlag) {

        protected void doOp() throws InterruptedException {
            assertNotNull(queue.poll(1, TimeUnit.MINUTES));
        }
    };
    thread.start();
    Thread.sleep(5000);
    thread.interrupt();
    queue.offer("item");
    assertTrue(latch.await(1, TimeUnit.MINUTES));
    if (thread.isInterruptionCaught()) {
        assertFalse("Thread interrupted flag should not be set!", interruptedFlag.get());
        assertFalse("Queue should not be empty!", queue.isEmpty());
    } else {
        assertTrue("Thread interrupted flag should be set! " + thread, interruptedFlag.get());
        assertTrue("Queue should be empty!", queue.isEmpty());
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IQueue(com.hazelcast.collection.IQueue) CountDownLatch(java.util.concurrent.CountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with IQueue

use of com.hazelcast.collection.IQueue 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();
}
Also used : TransactionalQueue(com.hazelcast.transaction.TransactionalQueue) IQueue(com.hazelcast.collection.IQueue) TransactionContext(com.hazelcast.transaction.TransactionContext) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) CountDownLatch(java.util.concurrent.CountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with IQueue

use of com.hazelcast.collection.IQueue 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();
}
Also used : TransactionalQueue(com.hazelcast.transaction.TransactionalQueue) IQueue(com.hazelcast.collection.IQueue) TransactionContext(com.hazelcast.transaction.TransactionContext) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

IQueue (com.hazelcast.collection.IQueue)17 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)16 QuickTest (com.hazelcast.test.annotation.QuickTest)16 Test (org.junit.Test)16 TransactionContext (com.hazelcast.transaction.TransactionContext)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)6 TransactionalQueue (com.hazelcast.transaction.TransactionalQueue)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 Config (com.hazelcast.config.Config)4 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)3 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)2 OperationTimeoutException (com.hazelcast.core.OperationTimeoutException)2 TransactionException (com.hazelcast.transaction.TransactionException)2 TransactionNotActiveException (com.hazelcast.transaction.TransactionNotActiveException)2 TransactionOptions (com.hazelcast.transaction.TransactionOptions)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeoutException (java.util.concurrent.TimeoutException)2 Member (com.hazelcast.cluster.Member)1 ItemEvent (com.hazelcast.collection.ItemEvent)1