Package org.menagerie.latches.spi

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


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


        });

        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

        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

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

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

            }
        });

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

        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

        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{
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.