Package com.hazelcast.core

Examples of com.hazelcast.core.ISemaphore.acquire()


            @Override
            public void run() {
                try {
                    semaphore.acquire(6);
                    assertEquals(5, semaphore.availablePermits());
                    semaphore.acquire(6);
                    assertEquals(5, semaphore.availablePermits());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
View Full Code Here


    @Test(timeout = 30000)
    public void testMultipleRelease_whenBlockedAcquireThreads() throws InterruptedException {
        final ISemaphore semaphore = hz.getSemaphore(randomString());
        int numberOfPermits = 10;
        semaphore.init(numberOfPermits);
        semaphore.acquire(numberOfPermits);
        CountDownLatch latch1 = new CountDownLatch(1);
        Thread thread1 = new BlockAcquireThread(semaphore, latch1);
        thread1.start();

        semaphore.release();
View Full Code Here

    public void testDrain() throws InterruptedException {
        final ISemaphore semaphore = hz.getSemaphore(randomString());
        int numberOfPermits = 20;

        assertTrue(semaphore.init(numberOfPermits));
        semaphore.acquire(5);
        int drainedPermits = semaphore.drainPermits();
        assertEquals(drainedPermits, numberOfPermits - 5);
        assertEquals(semaphore.availablePermits(), 0);
    }
View Full Code Here

    @Test(timeout = 30000)
    public void testTryAcquire_whenNotEnoughPermits() throws InterruptedException {
        final ISemaphore semaphore = hz.getSemaphore(randomString());
        int numberOfPermits = 10;
        semaphore.init(numberOfPermits);
        semaphore.acquire(10);
        boolean result = semaphore.tryAcquire(1);

        assertFalse(result);
        assertEquals(0, semaphore.availablePermits());
    }
View Full Code Here

        final CountDownLatch latch = new CountDownLatch(1);
        new Thread(){
            public void run() {
                try {
                    semaphore.acquire();
                    latch.countDown();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
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.