Search in sources :

Example 6 with IQueue

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

the class QueueAdvancedTest method testPollNull.

@Test
public void testPollNull() throws Exception {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance[] instances = factory.newInstances();
    HazelcastInstance h1 = instances[0];
    HazelcastInstance h2 = instances[1];
    IQueue q1 = h1.getQueue("default");
    IQueue q2 = h2.getQueue("default");
    for (int i = 0; i < 100; i++) {
        assertNull(q1.poll());
        assertNull(q2.poll());
    }
    assertNull(q1.poll(2, SECONDS));
    assertNull(q2.poll(2, SECONDS));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IQueue(com.hazelcast.core.IQueue) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 7 with IQueue

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

the class TransactionQueueTest method testSingleQueueAtomicity.

@Test
public void testSingleQueueAtomicity() throws ExecutionException, InterruptedException {
    final String name = randomString();
    final int itemCount = 200;
    final HazelcastInstance instance = createHazelcastInstance();
    Future<Integer> f = spawn(new Callable<Integer>() {

        @Override
        public Integer call() throws Exception {
            IQueue<Object> queue = instance.getQueue(name);
            queue.take();
            return queue.size();
        }
    });
    TransactionContext context = instance.newTransactionContext();
    context.beginTransaction();
    TransactionalQueue<Object> queue = context.getQueue(name);
    for (int i = 0; i < itemCount; i++) {
        queue.offer("item-" + i);
    }
    context.commitTransaction();
    int size = f.get();
    assertEquals(itemCount - 1, size);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IQueue(com.hazelcast.core.IQueue) TransactionContext(com.hazelcast.transaction.TransactionContext) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) TransactionException(com.hazelcast.transaction.TransactionException) ExecutionException(java.util.concurrent.ExecutionException) TransactionNotActiveException(com.hazelcast.transaction.TransactionNotActiveException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 8 with IQueue

use of com.hazelcast.core.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.core.IQueue) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 9 with IQueue

use of com.hazelcast.core.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.core.IQueue) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 10 with IQueue

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

Aggregations

IQueue (com.hazelcast.core.IQueue)17 ParallelTest (com.hazelcast.test.annotation.ParallelTest)15 QuickTest (com.hazelcast.test.annotation.QuickTest)15 Test (org.junit.Test)15 TransactionContext (com.hazelcast.transaction.TransactionContext)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)6 TransactionalQueue (com.hazelcast.core.TransactionalQueue)4 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)2 TransactionException (com.hazelcast.transaction.TransactionException)2 TransactionNotActiveException (com.hazelcast.transaction.TransactionNotActiveException)2 ExecutionException (java.util.concurrent.ExecutionException)2 QueueService (com.hazelcast.collection.impl.queue.QueueService)1 IMap (com.hazelcast.core.IMap)1 ExpectedRuntimeException (com.hazelcast.test.ExpectedRuntimeException)1 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)1 NightlyTest (com.hazelcast.test.annotation.NightlyTest)1 TransactionOptions (com.hazelcast.transaction.TransactionOptions)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1