Package com.hazelcast.core

Examples of com.hazelcast.core.ICountDownLatch


    @ClientCompatibleTest
    public void testSimpleUsage() throws InterruptedException {
        final int k = 5;
        TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(k);
        final HazelcastInstance[] instances = factory.newInstances();
        ICountDownLatch latch = instances[0].getCountDownLatch("test");
        latch.trySetCount(k - 1);
        assertEquals(k - 1, latch.getCount());

        new Thread() {
            public void run() {
                for (int i = 1; i < k; i++) {
                    try {
                        sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    final ICountDownLatch l = instances[i].getCountDownLatch("test");
                    l.countDown();
                    assertEquals(k - 1 - i, l.getCount());
                }
            }
        }.start();

        assertTrue(latch.await(5000, TimeUnit.MILLISECONDS));
View Full Code Here


    @ClientCompatibleTest
    public void testLatchDestroyed() throws Exception {
        TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
        HazelcastInstance hz1 = factory.newHazelcastInstance();
        HazelcastInstance hz2 = factory.newHazelcastInstance();
        final ICountDownLatch latch = hz1.getCountDownLatch("test");
        latch.trySetCount(2);

        new TestThread() {
            public void doRun() throws Exception {
                sleep(1000);
                latch.destroy();
            }
        }.start();

        hz2.getCountDownLatch("test").await(5, TimeUnit.SECONDS);
    }
View Full Code Here

        TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(5);
        HazelcastInstance hz1 = factory.newHazelcastInstance();
        HazelcastInstance hz2 = factory.newHazelcastInstance();
        warmUpPartitions(hz2, hz1);

        ICountDownLatch latch1 = hz1.getCountDownLatch("test");
        latch1.trySetCount(10);
        Thread.sleep(500);

        ICountDownLatch latch2 = hz2.getCountDownLatch("test");
        assertEquals(10, latch2.getCount());
        latch2.countDown();
        assertEquals(9, latch1.getCount());
        hz1.shutdown();
        assertEquals(9, latch2.getCount());

        HazelcastInstance hz3 = factory.newHazelcastInstance();
        warmUpPartitions(hz3);
        ICountDownLatch latch3 = hz3.getCountDownLatch("test");
        latch3.countDown();
        assertEquals(8, latch3.getCount());

        hz2.shutdown();
        latch3.countDown();
        assertEquals(7, latch3.getCount());

        HazelcastInstance hz4 = factory.newHazelcastInstance();
        HazelcastInstance hz5 = factory.newHazelcastInstance();
        warmUpPartitions(hz5, hz4);
        Thread.sleep(250);

        hz3.shutdown();
        ICountDownLatch latch4 = hz4.getCountDownLatch("test");
        assertEquals(7, latch4.getCount());

        ICountDownLatch latch5 = hz5.getCountDownLatch("test");
        latch5.countDown();
        assertEquals(6, latch5.getCount());
        latch5.countDown();
        assertEquals(5, latch4.getCount());
        assertEquals(5, latch5.getCount());
    }
View Full Code Here

        assertTrue(result);
    }

    @Test
    public void testCountDown() throws IOException {
        ICountDownLatch countDownLatch = getCountDownLatch();
        countDownLatch.trySetCount(1);
        final SimpleClient client = getClient();
        client.send(new CountDownRequest(name));
        client.receive();

        assertEquals(0, countDownLatch.getCount());
    }
View Full Code Here

        Config config = newConfig();
        HazelcastInstance h1 = Hazelcast.newHazelcastInstance(config);
        HazelcastInstance h2 = Hazelcast.newHazelcastInstance(config);
        HazelcastInstance h3 = Hazelcast.newHazelcastInstance(config);
        final String name = generateKeyOwnedBy(h3);
        ICountDownLatch countDownLatch = h3.getCountDownLatch(name);
        countDownLatch.trySetCount(5);

        TestMemberShipListener memberShipListener = new TestMemberShipListener(2);
        h3.getCluster().addMembershipListener(memberShipListener);
        TestLifeCycleListener lifeCycleListener = new TestLifeCycleListener(1);
        h3.getLifecycleService().addLifecycleListener(lifeCycleListener);

        countDownLatch.countDown();

        closeConnectionBetween(h1, h3);
        closeConnectionBetween(h2, h3);

        assertOpenEventually(memberShipListener.latch);
        assertClusterSizeEventually(2, h1);
        assertClusterSizeEventually(2, h2);
        assertClusterSizeEventually(1, h3);

        ICountDownLatch countDownLatch1 = h1.getCountDownLatch(name);
        countDownLatch1.countDown();

        countDownLatch.countDown();
        countDownLatch.countDown();

        assertOpenEventually(lifeCycleListener.latch);
        assertClusterSizeEventually(3, h1);
        assertClusterSizeEventually(3, h2);
        assertClusterSizeEventually(3, h3);

        ICountDownLatch countDownLatchTest = h3.getCountDownLatch(name);
        assertEquals(3, countDownLatchTest.getCount());
    }
View Full Code Here

    // ================= trySetCount =================================================

    @Test(expected = IllegalArgumentException.class)
    public void testTrySetCount_whenArgumentNegative() {
        HazelcastInstance instance = createHazelcastInstance();
        ICountDownLatch latch = instance.getCountDownLatch("latch");
        latch.trySetCount(-20);
    }
View Full Code Here

    }

    @Test
    public void testTrySetCount_whenCountIsZero() {
        HazelcastInstance instance = createHazelcastInstance();
        ICountDownLatch latch = instance.getCountDownLatch(randomString());

        assertTrue(latch.trySetCount(40));
        assertEquals(40, latch.getCount());
    }
View Full Code Here

    }

    @Test
    public void testTrySetCount_whenCountIsNotZero() {
        HazelcastInstance instance = createHazelcastInstance();
        ICountDownLatch latch = instance.getCountDownLatch(randomString());
        latch.trySetCount(10);
        assertFalse(latch.trySetCount(20));
        assertFalse(latch.trySetCount(0));
        assertEquals(10, latch.getCount());
    }
View Full Code Here

    }

    @Test
    public void testTrySetCount_whenPositive() {
        HazelcastInstance instance = createHazelcastInstance();
        ICountDownLatch latch = instance.getCountDownLatch(randomString());

        latch.trySetCount(10);
        assertFalse(latch.trySetCount(20));
        assertEquals(10, latch.getCount());
    }
View Full Code Here

    }

    @Test
    public void testTrySetCount_whenAlreadySet() {
        HazelcastInstance instance = createHazelcastInstance();
        ICountDownLatch latch = instance.getCountDownLatch(randomString());

        latch.trySetCount(10);
        assertFalse(latch.trySetCount(20));
        assertFalse(latch.trySetCount(100));
        assertFalse(latch.trySetCount(0));
        assertEquals(10, latch.getCount());
    }
View Full Code Here

TOP

Related Classes of com.hazelcast.core.ICountDownLatch

Copyright © 2018 www.massapicom. 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.