Examples of IQueue


Examples of com.hazelcast.core.IQueue

        qConfig.addItemListenerConfig(itemListenerConfig);
        cfg.addQueueConfig(qConfig);

        TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
        HazelcastInstance node1 = factory.newHazelcastInstance(cfg);
        IQueue queue = node1.getQueue(Qname);
        for (int i = 0; i < totalQput / 2; i++) {
            queue.put(i);
        }

        HazelcastInstance node2 = factory.newHazelcastInstance(cfg);

        for (int i = 0; i < totalQput / 4; i++) {
            queue.put(i);
        }

        assertTrue(simpleItemListener.added.await(3, TimeUnit.SECONDS));
    }
View Full Code Here

Examples of com.hazelcast.core.IQueue

        final String name = randomString();
        HazelcastInstance instance = createHazelcastInstance();
        final CountDownLatch latch = new CountDownLatch(20);
        final AtomicBoolean notCalled = new AtomicBoolean(true);

        IQueue queue = instance.getQueue(name);
        TestItemListener listener = new TestItemListener(latch, notCalled);
        final String id = queue.addItemListener(listener, true);
        for (int i = 0; i < 10; i++) {
            queue.offer("item" + i);
        }
        for (int i = 0; i < 10; i++) {
            queue.poll();
        }

        assertTrue(latch.await(5, TimeUnit.SECONDS));
        queue.removeItemListener(id);
        queue.offer("item-a");
        queue.poll();
        assertTrue(notCalled.get());
    }
View Full Code Here

Examples of com.hazelcast.core.IQueue

    public void testOffer() throws Exception {
        TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
        final HazelcastInstance[] instances = factory.newInstances();
        HazelcastInstance h1 = instances[0];
        HazelcastInstance h2 = instances[1];
        final IQueue q1 = h1.getQueue("default");
        final IQueue q2 = h2.getQueue("default");
        for (int i = 0; i < 100; i++) {
            assertTrue(q1.offer("item" + i, 100, TimeUnit.SECONDS));
            assertTrue(q2.offer("item" + i, 100, TimeUnit.SECONDS));
        }
        assertEquals("item0", q1.peek());
        assertEquals("item0", q2.peek());
        for (int i = 0; i < 100; i++) {
            assertEquals("item" + i, q1.poll());
            assertEquals("item" + i, q2.poll());
        }
    }
View Full Code Here

Examples of com.hazelcast.core.IQueue

        final HazelcastInstance[] instances = factory.newInstances(config);
        final HazelcastInstance h1 = instances[0];
        final HazelcastInstance h2 = instances[1];
        warmUpPartitions(h1, h2);

        final IQueue q1 = h1.getQueue("default");
        final IQueue q2 = h2.getQueue("default");

        final CountDownLatch startLatch = new CountDownLatch(1);
        new Thread(new Runnable() {
            public void run() {
                try {
                    assertTrue(startLatch.await(10, TimeUnit.SECONDS)); // fail shutdown if await fails.
                    Thread.sleep(5000);
                    h2.getLifecycleService().terminate();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();

        new Thread(new Runnable() {
            public void run() {
                try {
                    startLatch.countDown();
                    final Object o = q2.take();
                    fail("Should not be able to take: " + o);
                } catch (HazelcastInstanceNotActiveException ignored) {
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
View Full Code Here

Examples of com.hazelcast.core.IQueue

        final HazelcastInstance[] instances = factory.newInstances();
        final HazelcastInstance h1 = instances[0];
        final HazelcastInstance h2 = instances[1];
        warmUpPartitions(h2, h1);

        final IQueue q1 = h1.getQueue("default");
        final IQueue q2 = h2.getQueue("default");
        for (int i = 0; i < 40; i++) {
            assertTrue(q1.offer("item" + i, 100, TimeUnit.SECONDS));
        }
        h1.getLifecycleService().shutdown();
        for (int i = 40; i < 100; i++) {
            assertTrue(q2.offer("item" + i, 100, TimeUnit.SECONDS));
        }
        for (int i = 0; i < 100; i++) {
            assertEquals("item" + i, q2.poll());
        }
    }
View Full Code Here

Examples of com.hazelcast.core.IQueue

    public void testPollNull() throws Exception {
        TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
        final HazelcastInstance[] instances = factory.newInstances();
        final HazelcastInstance h1 = instances[0];
        final HazelcastInstance h2 = instances[1];
        final IQueue q1 = h1.getQueue("default");
        final IQueue q2 = h2.getQueue("default");
        for (int i = 0; i < 100; i++) {
            assertNull(q1.poll());
            assertNull(q2.poll());
        }
        assertNull(q1.poll(2, TimeUnit.SECONDS));
        assertNull(q2.poll(2, TimeUnit.SECONDS));
    }
View Full Code Here

Examples of com.hazelcast.core.IQueue

    public void testTake() throws Exception {
        TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
        final HazelcastInstance[] instances = factory.newInstances();
        final HazelcastInstance h1 = instances[0];
        final HazelcastInstance h2 = instances[1];
        final IQueue q1 = h1.getQueue("default");
        final IQueue q2 = h2.getQueue("default");
        final CountDownLatch offerLatch = new CountDownLatch(2 * 100);
        new Thread(new Runnable() {
            public void run() {
                try {
                    Thread.sleep(3000);
                    for (int i = 0; i < 100; i++) {
                        if (q1.offer("item")) {
                            offerLatch.countDown();
                        }
                        if (q2.offer("item")) {
                            offerLatch.countDown();
                        }
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();

        assertOpenEventually(offerLatch);

        final ExecutorService es = Executors.newFixedThreadPool(50);
        final CountDownLatch latch = new CountDownLatch(200);
        for (int i = 0; i < 100; i++) {
            es.execute(new Runnable() {
                public void run() {
                    try {
                        if ("item".equals(q1.take())) {
                            latch.countDown();
                        }
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            });
            es.execute(new Runnable() {
                public void run() {
                    try {
                        if ("item".equals(q2.take())) {
                            latch.countDown();
                        }
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
View Full Code Here

Examples of com.hazelcast.core.IQueue

    public void testPollLong() throws Exception {
        TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
        final HazelcastInstance[] instances = factory.newInstances();
        final HazelcastInstance h1 = instances[0];
        final HazelcastInstance h2 = instances[1];
        final IQueue q1 = h1.getQueue("default");
        final IQueue q2 = h2.getQueue("default");
        final CountDownLatch offerLatch = new CountDownLatch(2 * 100);
        Thread.sleep(1000);
        new Thread(new Runnable() {
            public void run() {
                for (int i = 0; i < 100; i++) {
                    if (q1.offer("item")) {
                        offerLatch.countDown();
                    }
                    if (q2.offer("item")) {
                        offerLatch.countDown();
                    }
                }
            }
        }).start();
        assertOpenEventually(offerLatch);
        final ExecutorService es = Executors.newFixedThreadPool(50);
        final CountDownLatch latch = new CountDownLatch(200);
        Thread.sleep(3000);
        for (int i = 0; i < 100; i++) {
            es.execute(new Runnable() {
                public void run() {
                    try {
                        if ("item".equals(q1.poll(5, TimeUnit.SECONDS))) {
                            latch.countDown();
                        }
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            });
            es.execute(new Runnable() {
                public void run() {
                    try {
                        if ("item".equals(q2.poll(5, TimeUnit.SECONDS))) {
                            latch.countDown();
                        }
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
View Full Code Here

Examples of com.hazelcast.core.IQueue

        config.getQueueConfig("default").setMaxSize(200);
        TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
        final HazelcastInstance[] instances = factory.newInstances(config);
        final HazelcastInstance h1 = instances[0];
        final HazelcastInstance h2 = instances[1];
        final IQueue q1 = h1.getQueue("default");
        final IQueue q2 = h2.getQueue("default");
        for (int i = 0; i < 100; i++) {
            assertTrue(q1.offer("item" + i, 100, TimeUnit.SECONDS));
            assertTrue(q2.offer("item" + i, 100, TimeUnit.SECONDS));
        }
        assertFalse(q1.offer("item"));
        assertFalse(q2.offer("item"));
        assertFalse(q1.offer("item", 2, TimeUnit.SECONDS));
        assertFalse(q2.offer("item", 2, TimeUnit.SECONDS));
        final CountDownLatch pollLatch = new CountDownLatch(200);
        new Thread(new Runnable() {
            public void run() {
                try {
                    Thread.sleep(3000);
                    for (int i = 0; i < 100; i++) {
                        if (("item" + i).equals(q1.poll(2, TimeUnit.SECONDS))) {
                            pollLatch.countDown();
                        }
                        if (("item" + i).equals(q2.poll(2, TimeUnit.SECONDS))) {
                            pollLatch.countDown();
                        }
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
        assertOpenEventually(pollLatch);
        final ExecutorService es = Executors.newFixedThreadPool(50);
        final CountDownLatch latch = new CountDownLatch(200);
        for (int i = 0; i < 100; i++) {
            es.execute(new Runnable() {
                public void run() {
                    try {
                        if (q1.offer("item", 30, TimeUnit.SECONDS)) {
                            latch.countDown();
                        }
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            });
            es.execute(new Runnable() {
                public void run() {
                    try {
                        if (q2.offer("item", 30, TimeUnit.SECONDS)) {
                            latch.countDown();
                        }
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
View Full Code Here

Examples of com.hazelcast.core.IQueue

    public void testQueueAfterShutdown() throws Exception {
        TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
        final HazelcastInstance[] instances = factory.newInstances();
        final HazelcastInstance h1 = instances[0];
        final HazelcastInstance h2 = instances[1];
        IQueue q1 = h1.getQueue("default");
        IQueue q2 = h2.getQueue("default");
        q2.offer("item");
        assertEquals(1, q1.size());
        assertEquals(1, q2.size());
        assertEquals("item", q1.take());
        assertEquals(0, q1.size());
        assertEquals(0, q2.size());
        h1.getLifecycleService().shutdown();
        assertEquals(0, q2.size());
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.