Examples of ZkSemaphore


Examples of org.menagerie.latches.spi.ZkSemaphore

    public final static DistributedCyclicBarrier newCyclicBarrier(long size, ZkSessionManager zkSessionManager, String barrierNode, List<ACL> privileges, boolean tolerateFailures) {
        return new ZkCyclicBarrier(size, zkSessionManager, barrierNode, privileges, tolerateFailures);
    }

    public final static DistributedSemaphore newSemaphore(int numPermits, String baseNode, ZkSessionManager zkSessionManager, List<ACL> privileges) {
        return new ZkSemaphore(numPermits, baseNode, zkSessionManager, privileges);
    }
View Full Code Here

Examples of org.menagerie.latches.spi.ZkSemaphore

    public final static DistributedSemaphore newSemaphore(int numPermits, String baseNode, ZkSessionManager zkSessionManager, List<ACL> privileges) {
        return new ZkSemaphore(numPermits, baseNode, zkSessionManager, privileges);
    }

    public final static DistributedSemaphore newSemaphore(int numPermits, String baseNode, ZkSessionManager zkSessionManager) {
        return new ZkSemaphore(numPermits, baseNode, zkSessionManager);
    }
View Full Code Here

Examples of org.menagerie.latches.spi.ZkSemaphore

    }

    @Test(timeout = 1000l)
    public void testAcquireSucceedsOneThread() throws Exception{
        int numPermits = 1;
        DistributedSemaphore semaphore = new ZkSemaphore(numPermits, basePath,zkSessionManager);

        semaphore.acquire();

        //check that the available permits are zero
        assertEquals("semaphore does not report fewer permits!",numPermits-1,semaphore.availablePermits());
        semaphore.release();
        assertEquals("semaphore does not report releasing a permit!",numPermits,semaphore.availablePermits());
    }
View Full Code Here

Examples of org.menagerie.latches.spi.ZkSemaphore

    }

    @Test(timeout = 1000l)
    public void testTwoThreadsCanAccessSempahore() throws Exception{
        final CountDownLatch latch = new CountDownLatch(1);
        final DistributedSemaphore semaphore = new ZkSemaphore(2,basePath,zkSessionManager);

        testService.submit(new Runnable() {
            @Override
            public void run() {
                try {
                    semaphore.acquire();
                    latch.countDown();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });

        semaphore.acquire();
        latch.await();
    }
View Full Code Here

Examples of org.menagerie.latches.spi.ZkSemaphore

    }

    @Test(timeout = 1000l)
    public void testTwoClientsCanAccessSempahore() throws Exception{
        final CountDownLatch latch = new CountDownLatch(1);
        final DistributedSemaphore semaphore = new ZkSemaphore(2,basePath,zkSessionManager);

        semaphore.acquire();
        Future<Void> errorFuture = testService.submit(new Callable<Void>() {
            @Override
            public Void call() throws Exception {
                ZooKeeper zk = newZooKeeper();
                try {

                    DistributedSemaphore semaphore2 = new ZkSemaphore(2, basePath, new BaseZkSessionManager(zk));
                    semaphore2.acquire();
                    latch.countDown();
                } finally {
                    zk.close();
                }
                return null;
View Full Code Here

Examples of org.menagerie.latches.spi.ZkSemaphore


    @Test(timeout = 1500l)
    public void testRunOutOfPermitsTwoThreads() throws Exception{
        final CountDownLatch latch = new CountDownLatch(1);
        final DistributedSemaphore semaphore = new ZkSemaphore(1,basePath,zkSessionManager);
        semaphore.acquire();
        Future<?> errorFuture = testService.submit(new Runnable() {
            @Override
            public void run() {
                try {
                    semaphore.acquire();
                    latch.countDown();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });

        boolean timedOut = !latch.await(500, TimeUnit.MILLISECONDS);
        assertTrue("Semaphore improperly acquired a permit!",timedOut);

        semaphore.release();
        boolean noTimeOut = latch.await(500, TimeUnit.MILLISECONDS);
        assertTrue("Semaphore did not release a permit for another party!",noTimeOut);
        errorFuture.get();
    }
View Full Code Here

Examples of org.menagerie.latches.spi.ZkSemaphore

    }

    @Test(timeout = 1500l)
    public void testRunOutOfPermitsTwoClients() throws Exception{
        final CountDownLatch latch = new CountDownLatch(1);
        final DistributedSemaphore semaphore = new ZkSemaphore(1,basePath,zkSessionManager);
        semaphore.acquire();
        Future<Void> errorFuture = testService.submit(new Callable<Void>() {
            @Override
            public Void call() throws Exception {
                ZooKeeper zk = newZooKeeper();
                try {
                    DistributedSemaphore semaphore2 = new ZkSemaphore(1, basePath, new BaseZkSessionManager(zk));
                    semaphore2.acquire();
                    latch.countDown();
                } finally {
                    zk.close();
                }
                return null;
View Full Code Here

Examples of org.menagerie.latches.spi.ZkSemaphore

        errorFuture.get();
    }

    @Test(timeout = 1000l)
    public void testAcquireMultiplePermits() throws Exception{
        DistributedSemaphore semaphore = new ZkSemaphore(2,basePath,zkSessionManager);

        semaphore.acquire(2);
        assertEquals("Incorrect number of permits reported!",0,semaphore.availablePermits());

        semaphore.release();
        assertEquals("Incorrect number of permits reported",1,semaphore.availablePermits());

        semaphore.release();
        assertEquals("Incorrect number of permits reported",2,semaphore.availablePermits());
    }
View Full Code Here

Examples of org.menagerie.latches.spi.ZkSemaphore

    }

    @Test(timeout = 2000l)
    public void testAcquireMultiplePermitsBlocksUntilAvailableTwoThreads() throws Exception{
        final CountDownLatch latch = new CountDownLatch(1);
        final DistributedSemaphore semaphore = new ZkSemaphore(2,basePath,zkSessionManager);

        semaphore.acquire(2);
        assertEquals("Incorrect number of permits reported!",0,semaphore.availablePermits());
        Future<Void> errorFuture = testService.submit(new Callable<Void>() {
            @Override
            public Void call() throws Exception {
                semaphore.acquire(2);
                latch.countDown();
                return null;
            }
        });

        boolean timedOut1 = !latch.await(500, TimeUnit.MILLISECONDS);
        assertTrue("multiple permits were incorrectly acquired",timedOut1);
        semaphore.release();

        boolean timedOut2 = !latch.await(500, TimeUnit.MILLISECONDS);
        assertTrue("multiple permits were incorrectly acquired",timedOut2);

        semaphore.release();
        boolean timedOut3 = latch.await(500,TimeUnit.MILLISECONDS);
        assertTrue("multiple permits were incorrectly released",timedOut3);
        errorFuture.get();
    }
View Full Code Here

Examples of org.menagerie.latches.spi.ZkSemaphore

    }

    @Test(timeout = 2000l)
    public void testAcquireMultiplePermitsBlocksUntilAvailableTwoClients() throws Exception{
        final CountDownLatch latch = new CountDownLatch(1);
        final DistributedSemaphore semaphore = new ZkSemaphore(2,basePath,zkSessionManager);

        semaphore.acquire();
        semaphore.acquire();
        assertEquals("Incorrect number of permits reported!",0,semaphore.availablePermits());
        Future<Void> errorFuture = testService.submit(new Callable<Void>() {
            @Override
            public Void call() throws Exception {
                ZooKeeper zk = newZooKeeper();
                try {
                    DistributedSemaphore semaphore2 = new ZkSemaphore(2, basePath, new BaseZkSessionManager(zk));
                    semaphore2.acquire(2);
                    latch.countDown();
                } finally {
                    zk.close();
                }
                return null;
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.