Package com.hazelcast.core

Examples of com.hazelcast.core.ICountDownLatch


    // ================= countDown =================================================

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

        latch.trySetCount(20);
        for (int i = 19; i >= 0; i--) {
            latch.countDown();
            assertEquals(i, latch.getCount());
        }
    }
View Full Code Here


    }

    @Test
    public void testCountDown_whenReachZero_thenLatchRemoved() {
        HazelcastInstance instance = createHazelcastInstance();
        ICountDownLatch latch = instance.getCountDownLatch(randomString());
        CountDownLatchService service = getNode(instance).getNodeEngine().getService(CountDownLatchService.SERVICE_NAME);

        latch.trySetCount(1);
        assertTrue(service.containsLatch(latch.getName()));
        latch.countDown();
        assertFalse(service.containsLatch(latch.getName()));
    }
View Full Code Here

    // ================= getCount =================================================

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

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

    // ================= destroy =================================================

    @Test
    public void testDestroy() {
        HazelcastInstance instance = createHazelcastInstance();
        ICountDownLatch latch = instance.getCountDownLatch(randomString());
        NodeEngineImpl nodeEngine = getNode(instance).getNodeEngine();
        CountDownLatchService service = nodeEngine.getService(CountDownLatchService.SERVICE_NAME);

        latch.destroy();
        assertFalse(service.containsLatch(latch.getName()));
    }
View Full Code Here

    // ================= await =================================================
    @Test(timeout = 15000)
    public void testAwait() throws InterruptedException {
        HazelcastInstance instance = createHazelcastInstance();
        final ICountDownLatch latch = instance.getCountDownLatch(randomString());
        latch.trySetCount(1);
        TestThread thread = new TestThread() {
            public void doRun() {
                latch.countDown();
            }
        };
        thread.start();
        assertOpenEventually(latch);
    }
View Full Code Here

    }

    @Test(timeout = 15000)
    public void testAwait_withManyThreads() {
        HazelcastInstance instance = createHazelcastInstance();
        final ICountDownLatch latch = instance.getCountDownLatch(randomString());
        final CountDownLatch completedLatch = new CountDownLatch(10);

        latch.trySetCount(1);
        for (int i = 0; i < 10; i++) {
            new TestThread() {
                public void doRun() throws Exception {
                    if (latch.await(1, TimeUnit.MINUTES)) {
                        completedLatch.countDown();
                    }
                }
            }.start();
        }
        latch.countDown();
        assertOpenEventually(completedLatch);
    }
View Full Code Here

    }

    @Test(timeout = 15000)
    public void testAwait_whenTimeOut() throws InterruptedException {
        HazelcastInstance instance = createHazelcastInstance();
        ICountDownLatch latch = instance.getCountDownLatch(randomString());

        latch.trySetCount(1);
        long time = System.currentTimeMillis();
        assertFalse(latch.await(100, TimeUnit.MILLISECONDS));
        long elapsed = System.currentTimeMillis() - time;
        assertTrue(elapsed >= 100);
        assertEquals(1, latch.getCount());
    }
View Full Code Here

    }

    @Test
    public void testAwait_whenInstanceShutdown_thenHazelcastInstanceNotActiveException() throws InterruptedException {
        HazelcastInstance instance = createHazelcastInstance();
        final ICountDownLatch latch = instance.getCountDownLatch(randomString());
        latch.trySetCount(10);

        final TestThread awaitThread = new TestThread() {
            @Override
            public void doRun() throws Exception {
                latch.await(1, TimeUnit.HOURS);
            }
        };
        awaitThread.start();

        // give the awaitthread some time to get in the waiting state
View Full Code Here

    @Test
    public void testCountDownLatch() throws Exception {
        String partitionKey = "hazelcast";
        HazelcastInstance hz = getHazelcastInstance(partitionKey);

        ICountDownLatch countDownLatch = hz.getCountDownLatch("countdownlatch@" + partitionKey);
        countDownLatch.trySetCount(1);
        assertEquals("countdownlatch@" + partitionKey, countDownLatch.getName());
        assertEquals(partitionKey, countDownLatch.getPartitionKey());

        CountDownLatchService service = getNodeEngine(hz).getService(CountDownLatchService.SERVICE_NAME);
        assertTrue(service.containsLatch(countDownLatch.getName()));
    }
View Full Code Here

        assertTrue(l.await(5, TimeUnit.SECONDS));
    }

    @Test(expected = IllegalArgumentException.class)
    public void testTrySetCount_whenArgumentNegative() {
        ICountDownLatch latch = hz.getCountDownLatch(randomString());
        latch.trySetCount(-20);
    }
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.