Package org.menagerie.latches.spi

Examples of org.menagerie.latches.spi.ZkSemaphore.availablePermits()


        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());
    }

    @Test(timeout = 1000l)
View Full Code Here


        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());
    }

    @Test(timeout = 1000l)
    public void testTwoThreadsCanAccessSempahore() throws Exception{
        final CountDownLatch latch = new CountDownLatch(1);
View Full Code Here

    @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();
View Full Code Here

        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

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

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

    @Test(timeout = 2000l)
    public void testAcquireMultiplePermitsBlocksUntilAvailableTwoThreads() throws Exception{
        final CountDownLatch latch = new CountDownLatch(1);
View Full Code Here

    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();
View Full Code Here

        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 {
View Full Code Here

    public void testReleaseMultiplePermits() throws Exception{
        DistributedSemaphore semaphore = new ZkSemaphore(2,basePath,zkSessionManager);

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

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

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

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

    @Test(timeout = 1000l)
    public void testTryAcquire() throws Exception{
        DistributedSemaphore semaphore = new ZkSemaphore(2,basePath,zkSessionManager);
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.