Package org.menagerie.latches.spi

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


    @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


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

                    throw new RuntimeException(e);
                }
            }
        });

        semaphore.acquire();
        latch.await();
    }

    @Test(timeout = 1000l)
    public void testTwoClientsCanAccessSempahore() throws Exception{
View Full Code Here

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

            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

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

        semaphore.acquire();
        Future<?> errorFuture = testService.submit(new Runnable() {
            @Override
            public void run() {
                try {
                    semaphore.acquire();
                    latch.countDown();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
View Full Code Here

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

            @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

    @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());
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.