Package org.menagerie.latches.spi

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


    }

    @Test(timeout = 1000l)
    public void testTryAcquire() throws Exception{
        DistributedSemaphore semaphore = new ZkSemaphore(2,basePath,zkSessionManager);
        assertTrue("Semaphore did not acquire!",semaphore.tryAcquire());
    }

    @Test(timeout = 1000l)
    public void testTryAcquireTimesOut() throws Exception{
        final CountDownLatch latch = new CountDownLatch(1);


    @Test(timeout = 1000l)
    public void testTryAcquireTimesOut() throws Exception{
        final CountDownLatch latch = new CountDownLatch(1);
        final DistributedSemaphore semaphore = new ZkSemaphore(1,basePath,zkSessionManager);
        assertTrue("Semaphore did not acquire!",semaphore.tryAcquire());

        Future<Void> errorFuture = testService.submit(new Callable<Void>() {
            @Override
            public Void call() throws Exception {
                semaphore.tryAcquire(500, TimeUnit.MILLISECONDS);

        assertTrue("Semaphore did not acquire!",semaphore.tryAcquire());

        Future<Void> errorFuture = testService.submit(new Callable<Void>() {
            @Override
            public Void call() throws Exception {
                semaphore.tryAcquire(500, TimeUnit.MILLISECONDS);
                latch.countDown();
                return null;
            }
        });

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.