Search in sources :

Example 1 with IQueue

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

the class HazelcastQueueThroughputTest method main.

public static void main(String[] args) throws InterruptedException {
    final HazelcastInstance hz = Hazelcast.newHazelcastInstance();
    final IQueue[] ring = new IQueue[QUEUE_RING_SIZE];
    for (int q = 0; q < QUEUE_RING_SIZE; ++q) ring[q] = hz.getQueue("test" + q);
    final long start = System.currentTimeMillis();
    long lastLap = start;
    Thread t = new Thread() {

        long lastLap = start;

        @Override
        public void run() {
            int senderQueueIndex = 0;
            System.out.println((System.currentTimeMillis() - lastLap) + " Start receiving msgs");
            for (int i = 1; i < TOTAL + 1; ++i) {
                try {
                    if (senderQueueIndex >= QUEUE_RING_SIZE)
                        senderQueueIndex = 0;
                    Object msg = ring[senderQueueIndex++].take();
                    if (i % LAP == 0) {
                        final long lapTime = System.currentTimeMillis() - lastLap;
                        System.out.printf("<- messages %d/%d = %dms (%f msg/sec)\n", i, TOTAL, lapTime, ((float) LAP * 1000 / lapTime));
                        lastLap = System.currentTimeMillis();
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    };
    t.start();
    int receiverQueueIndex = 0;
    System.out.println((System.currentTimeMillis() - lastLap) + " Start sending msgs");
    for (int i = 1; i < TOTAL + 1; ++i) {
        if (receiverQueueIndex >= QUEUE_RING_SIZE)
            receiverQueueIndex = 0;
        ring[receiverQueueIndex++].offer(i);
        if (i % LAP == 0) {
            final long lapTime = System.currentTimeMillis() - lastLap;
            System.out.printf("-> messages %d/%d = %dms (%f msg/sec)\n", i, TOTAL, lapTime, ((float) LAP * 1000 / lapTime));
            lastLap = System.currentTimeMillis();
        }
    }
    System.out.println((System.currentTimeMillis() - start) + " Finished sending msgs");
    t.join();
    System.out.println((System.currentTimeMillis() - start) + " Test finished");
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IQueue(com.hazelcast.core.IQueue)

Example 2 with IQueue

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

Example 3 with IQueue

use of com.hazelcast.core.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.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)

Example 4 with IQueue

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

the class PartitionControlledIdTest method testQueue.

@Test
public void testQueue() throws Exception {
    String partitionKey = "hazelcast";
    HazelcastInstance hz = getHazelcastInstance(partitionKey);
    IQueue queue = hz.getQueue("queue@" + partitionKey);
    queue.add("");
    assertEquals("queue@" + partitionKey, queue.getName());
    assertEquals(partitionKey, queue.getPartitionKey());
    QueueService service = getNodeEngine(hz).getService(QueueService.SERVICE_NAME);
    assertTrue(service.containsQueue(queue.getName()));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IQueue(com.hazelcast.core.IQueue) QueueService(com.hazelcast.collection.impl.queue.QueueService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with IQueue

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

the class HazelcastOSGiInstanceTest method getQueueCalledSuccessfullyOverOSGiInstance.

@Test
public void getQueueCalledSuccessfullyOverOSGiInstance() {
    IQueue mockQueue = mock(IQueue.class);
    HazelcastInstance mockHazelcastInstance = mock(HazelcastInstance.class);
    HazelcastOSGiInstance hazelcastOSGiInstance = HazelcastOSGiTestUtil.createHazelcastOSGiInstance(mockHazelcastInstance);
    when(mockHazelcastInstance.getQueue("my-queue")).thenReturn(mockQueue);
    assertEquals(mockQueue, hazelcastOSGiInstance.getQueue("my-queue"));
    verify(mockHazelcastInstance).getQueue("my-queue");
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IQueue(com.hazelcast.core.IQueue) 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