Search in sources :

Example 11 with IQueue

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

the class MBeanDestroyTest method testQueue.

@Test
public void testQueue() throws Exception {
    IQueue queue = holder.getHz().getQueue("queue");
    queue.size();
    holder.assertMBeanExistEventually("IQueue", queue.getName());
    destroyObjectAndAssert(queue, "IQueue");
}
Also used : IQueue(com.hazelcast.collection.IQueue) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 12 with IQueue

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

the class ClientQueueTest method testTake_whenInterruptedWhileBlocking.

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

Example 13 with IQueue

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

the class AllTest method loadQOperations.

private List<Runnable> loadQOperations() {
    List<Runnable> operations = new ArrayList<Runnable>();
    addOperation(operations, new Runnable() {

        public void run() {
            IQueue q = hazelcast.getQueue("myQ");
            q.offer(new byte[100]);
        }
    }, 10);
    addOperation(operations, new Runnable() {

        public void run() {
            IQueue q = hazelcast.getQueue("myQ");
            try {
                q.offer(new byte[100], 10, TimeUnit.MILLISECONDS);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }, 10);
    addOperation(operations, new Runnable() {

        public void run() {
            IQueue q = hazelcast.getQueue("myQ");
            q.contains(new byte[100]);
        }
    }, 1);
    addOperation(operations, new Runnable() {

        public void run() {
            IQueue q = hazelcast.getQueue("myQ");
            q.isEmpty();
        }
    }, 1);
    addOperation(operations, new Runnable() {

        public void run() {
            IQueue q = hazelcast.getQueue("myQ");
            q.size();
        }
    }, 1);
    addOperation(operations, new Runnable() {

        public void run() {
            IQueue q = hazelcast.getQueue("myQ");
            q.remove(new byte[100]);
        }
    }, 1);
    addOperation(operations, new Runnable() {

        public void run() {
            IQueue q = hazelcast.getQueue("myQ");
            q.remainingCapacity();
        }
    }, 1);
    addOperation(operations, new Runnable() {

        public void run() {
            IQueue q = hazelcast.getQueue("myQ");
            q.poll();
        }
    }, 10);
    addOperation(operations, new Runnable() {

        public void run() {
            IQueue q = hazelcast.getQueue("myQ");
            q.add(new byte[100]);
        }
    }, 10);
    addOperation(operations, new Runnable() {

        public void run() {
            IQueue q = hazelcast.getQueue("myQ");
            try {
                q.take();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }, 10);
    addOperation(operations, new Runnable() {

        public void run() {
            IQueue q = hazelcast.getQueue("myQ");
            List list = new ArrayList();
            for (int i = 0; i < 10; i++) {
                list.add(new byte[100]);
            }
            q.addAll(list);
        }
    }, 1);
    addOperation(operations, new Runnable() {

        public void run() {
            IQueue q = hazelcast.getQueue("myQ");
            List list = new ArrayList();
            q.drainTo(list);
        }
    }, 1);
    return operations;
}
Also used : IQueue(com.hazelcast.collection.IQueue) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 14 with IQueue

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

the class Invocation_BlockingTest method sync_testWaitingWithTimeout.

@Test
public void sync_testWaitingWithTimeout() throws InterruptedException {
    final Config config = new Config().setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), "6000");
    final HazelcastInstance hz = createHazelcastInstance(config);
    final CountDownLatch latch = new CountDownLatch(1);
    final IQueue queue = hz.getQueue(randomName());
    spawn(() -> {
        try {
            queue.poll(10, SECONDS);
            latch.countDown();
        } catch (Exception ignored) {
            ignored.printStackTrace();
        }
    });
    assertTrue("latch failed to open", latch.await(20, SECONDS));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IQueue(com.hazelcast.collection.IQueue) Config(com.hazelcast.config.Config) CountDownLatch(java.util.concurrent.CountDownLatch) TimeoutException(java.util.concurrent.TimeoutException) OperationTimeoutException(com.hazelcast.core.OperationTimeoutException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 15 with IQueue

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

the class Invocation_BlockingTest method sync_testWaitingIndefinitely.

@Test
public void sync_testWaitingIndefinitely() throws InterruptedException {
    final Config config = new Config().setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), "6000");
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    final HazelcastInstance[] instances = factory.newInstances(config);
    // need to warm-up partitions, since waiting for queue backup can take up to 5 seconds
    // and that may cause OperationTimeoutException with "No response for 4000 ms" error
    warmUpPartitions(instances);
    final String name = randomName();
    IQueue queue = instances[0].getQueue(name);
    final CountDownLatch latch = new CountDownLatch(1);
    new Thread(() -> {
        try {
            // because max timeout=6000 we get timeout exception which we should not
            instances[1].getQueue(name).take();
            latch.countDown();
        } catch (Exception ignored) {
            ignored.printStackTrace();
        }
    }).start();
    // wait for enough time which is greater than max-timeout (6000)
    sleepSeconds(10);
    queue.offer("item");
    assertTrue(latch.await(20, SECONDS));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IQueue(com.hazelcast.collection.IQueue) Config(com.hazelcast.config.Config) CountDownLatch(java.util.concurrent.CountDownLatch) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) TimeoutException(java.util.concurrent.TimeoutException) OperationTimeoutException(com.hazelcast.core.OperationTimeoutException) 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