Examples of RCountDownLatch


Examples of org.redisson.core.RCountDownLatch

    public void testAwaitTimeoutFail() throws InterruptedException {
        Redisson redisson = Redisson.create();

        ExecutorService executor = Executors.newFixedThreadPool(2);

        final RCountDownLatch latch = redisson.getCountDownLatch("latch1");
        Assert.assertTrue(latch.trySetCount(1));

        executor.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    Assert.fail();
                }
                latch.countDown();
            }
        });


        executor.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    Assert.assertEquals(1, latch.getCount());
                    boolean res = latch.await(500, TimeUnit.MILLISECONDS);
                    Assert.assertFalse(res);
                } catch (InterruptedException e) {
                    Assert.fail();
                }
            }
View Full Code Here

Examples of org.redisson.core.RCountDownLatch

    }

    @Test
    public void testCountDown() throws InterruptedException {
        Redisson redisson = Redisson.create();
        RCountDownLatch latch = redisson.getCountDownLatch("latch");
        latch.trySetCount(1);
        Assert.assertEquals(1, latch.getCount());
        latch.countDown();
        Assert.assertEquals(0, latch.getCount());
        latch.await();
        latch.countDown();
        Assert.assertEquals(0, latch.getCount());
        latch.await();
        latch.countDown();
        Assert.assertEquals(0, latch.getCount());
        latch.await();

        RCountDownLatch latch1 = redisson.getCountDownLatch("latch1");
        latch1.trySetCount(1);
        latch1.countDown();
        Assert.assertEquals(0, latch.getCount());
        latch1.countDown();
        Assert.assertEquals(0, latch.getCount());
        latch1.await();

        RCountDownLatch latch2 = redisson.getCountDownLatch("latch2");
        latch2.trySetCount(1);
        latch2.countDown();
        latch2.await();
        latch2.await();

        RCountDownLatch latch3 = redisson.getCountDownLatch("latch3");
        Assert.assertEquals(0, latch.getCount());
        latch3.await();

        RCountDownLatch latch4 = redisson.getCountDownLatch("latch4");
        Assert.assertEquals(0, latch.getCount());
        latch4.countDown();
        Assert.assertEquals(0, latch.getCount());
        latch4.await();

        redisson.shutdown();
    }
View Full Code Here

Examples of org.redisson.core.RCountDownLatch

    @Test
    public void testSingleCountDownAwait_SingleInstance() throws InterruptedException {
        final int iterations = Runtime.getRuntime().availableProcessors()*3;

        Redisson redisson = Redisson.create();
        final RCountDownLatch latch = redisson.getCountDownLatch("latch");
        latch.trySetCount(iterations);

        final AtomicInteger counter = new AtomicInteger();
        ExecutorService executor = Executors.newScheduledThreadPool(iterations);
        for (int i = 0; i < iterations; i++) {
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        latch.await();
                        Assert.assertEquals(0, latch.getCount());
                        Assert.assertEquals(iterations, counter.get());
                    } catch (InterruptedException e) {
                        Assert.fail();
                    }
                }
            });
        }

        ExecutorService countDownExecutor = Executors.newFixedThreadPool(iterations);
        for (int i = 0; i < iterations; i++) {
            countDownExecutor.execute(new Runnable() {
                @Override
                public void run() {
                    latch.countDown();
                    counter.incrementAndGet();
                }
            });
        }

View Full Code Here

Examples of org.redisson.core.RCountDownLatch

    public void testAwaitTimeout() throws InterruptedException {
        Redisson redisson = Redisson.create();

        ExecutorService executor = Executors.newFixedThreadPool(2);

        final RCountDownLatch latch = redisson.getCountDownLatch("latch1");
        Assert.assertTrue(latch.trySetCount(1));

        executor.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    Assert.fail();
                }
                latch.countDown();
            }
        });


        executor.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    Assert.assertEquals(1, latch.getCount());
                    boolean res = latch.await(550, TimeUnit.MILLISECONDS);
                    Assert.assertTrue(res);
                } catch (InterruptedException e) {
                    Assert.fail();
                }
            }
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.