Examples of IQueue


Examples of com.hazelcast.core.IQueue

    public void testQueueAfterShutdown2() 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");
        q1.offer("item");
        assertEquals(1, q1.size());
        assertEquals(1, q2.size());
        assertEquals("item", q2.take());
        assertEquals(0, q1.size());
        assertEquals(0, q2.size());
        h2.getLifecycleService().shutdown();
        assertEquals(0, q1.size());
    }
View Full Code Here

Examples of com.hazelcast.core.IQueue

        assertEquals(ItemEventType.ADDED, result.getEventType());
    }

    @Test
    public void testClear() throws Exception {
        IQueue q = getQueue();
        q.offer("item1");
        q.offer("item2");
        q.offer("item3");

        final SimpleClient client = getClient();
        client.send(new ClearRequest(queueName));
        Object result = client.receive();
        assertTrue((Boolean) result);
        assertEquals(0, q.size());
    }
View Full Code Here

Examples of com.hazelcast.core.IQueue

        assertEquals(0, q.size());
    }

    @Test
    public void testCompareAndRemove() throws IOException {
        IQueue q = getQueue();
        q.offer("item1");
        q.offer("item2");
        q.offer("item3");
        q.offer("item4");
        q.offer("item5");

        List<Data> list = new ArrayList<Data>();
        list.add(ss.toData("item1"));
        list.add(ss.toData("item2"));

        final SimpleClient client = getClient();
        client.send(new CompareAndRemoveRequest(queueName, list, true));
        Boolean result = (Boolean) client.receive();
        assertTrue(result);
        assertEquals(2, q.size());

        client.send(new CompareAndRemoveRequest(queueName, list, false));
        result = (Boolean) client.receive();
        assertTrue(result);
        assertEquals(0, q.size());
    }
View Full Code Here

Examples of com.hazelcast.core.IQueue

        assertEquals(0, q.size());
    }

    @Test
    public void testContains() throws IOException {
        IQueue q = getQueue();
        q.offer("item1");
        q.offer("item2");
        q.offer("item3");
        q.offer("item4");
        q.offer("item5");

        List<Data> list = new ArrayList<Data>();
        list.add(ss.toData("item1"));
        list.add(ss.toData("item2"));
View Full Code Here

Examples of com.hazelcast.core.IQueue

        assertFalse(result);
    }

    @Test
    public void testDrain() throws IOException {
        IQueue q = getQueue();
        q.offer("item1");
        q.offer("item2");
        q.offer("item3");
        q.offer("item4");
        q.offer("item5");

        final SimpleClient client = getClient();
        client.send(new DrainRequest(queueName, 1));
        PortableCollection result = (PortableCollection) client.receive();
        Collection<Data> coll = result.getCollection();
        assertEquals(1, coll.size());
        assertEquals("item1", ss.toObject(coll.iterator().next()));
        assertEquals(4, q.size());
    }
View Full Code Here

Examples of com.hazelcast.core.IQueue

        assertEquals(4, q.size());
    }

    @Test
    public void testIterator() throws IOException {
        IQueue q = getQueue();
        q.offer("item1");
        q.offer("item2");
        q.offer("item3");
        q.offer("item4");
        q.offer("item5");

        final SimpleClient client = getClient();
        client.send(new IteratorRequest(queueName));
        PortableCollection result = (PortableCollection) client.receive();
        Collection<Data> coll = result.getCollection();
View Full Code Here

Examples of com.hazelcast.core.IQueue

        }
    }

    @Test
    public void testOffer() throws IOException, InterruptedException {
        final IQueue q = getQueue();

        final SimpleClient client = getClient();
        client.send(new OfferRequest(queueName, ss.toData("item1")));
        Object result = client.receive();
        assertTrue((Boolean) result);
        Object item = q.peek();
        assertEquals(item, "item1");

        q.offer("item2");
        q.offer("item3");
        q.offer("item4");
        q.offer("item5");
        q.offer("item6");

        final CountDownLatch latch = new CountDownLatch(1);
        new Thread() {
            public void run() {
                try {
                    latch.await(30, TimeUnit.SECONDS);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                q.poll();
            }
        }.start();

        client.send(new OfferRequest(queueName, 500, ss.toData("item7")));
        result = client.receive();
View Full Code Here

Examples of com.hazelcast.core.IQueue

        assertTrue((Boolean) result);
    }

    @Test
    public void testPeek() throws IOException {
        IQueue q = getQueue();

        final SimpleClient client = getClient();
        client.send(new PeekRequest(queueName));
        Object result = client.receive();
        assertNull(result);

        q.offer("item1");
        client.send(new PeekRequest(queueName));
        result = client.receive();
        assertEquals("item1", result);
        assertEquals(1, q.size());
    }
View Full Code Here

Examples of com.hazelcast.core.IQueue

        assertEquals(1, q.size());
    }

    @Test
    public void testPoll() throws IOException {
        final IQueue q = getQueue();
        final SimpleClient client = getClient();
        client.send(new PollRequest(queueName));
        Object result = client.receive();
        assertNull(result);

        q.offer("item1");
        client.send(new PollRequest(queueName));
        result = client.receive();
        assertEquals("item1", result);
        assertEquals(0, q.size());

        new Thread() {
            public void run() {
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                q.offer("item2");
            }
        }.start();
        client.send(new PollRequest(queueName, 10 * 1000));
        result = client.receive();
        assertEquals("item2", result);
        assertEquals(0, q.size());
    }
View Full Code Here

Examples of com.hazelcast.core.IQueue

    }

    @Test
    public void testRemove() throws IOException {

        final IQueue q = getQueue();
        q.offer("item1");
        q.offer("item2");
        q.offer("item3");

        final SimpleClient client = getClient();
        client.send(new RemoveRequest(queueName, ss.toData("item2")));
        Boolean result = (Boolean) client.receive();
        assertTrue(result);
        assertEquals(2, q.size());

        client.send(new RemoveRequest(queueName, ss.toData("item2")));
        result = (Boolean) client.receive();
        assertFalse(result);
        assertEquals(2, q.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.