Package com.hazelcast.core

Examples of com.hazelcast.core.ISemaphore


        assertTrue(semaphore.tryAcquire(1, TimeUnit.MILLISECONDS));
    }

    @Test
    public void testTryAcquire_whenUnAvailableWithTimeOut() throws Exception {
        final ISemaphore semaphore = client.getSemaphore(randomString());
        semaphore.init(0);
        assertFalse(semaphore.tryAcquire(1, TimeUnit.MILLISECONDS));
    }
View Full Code Here


        assertFalse(semaphore.tryAcquire(1, TimeUnit.MILLISECONDS));
    }

    @Test
    public void testTryAcquireMultiPermits_whenAvailable() throws Exception {
        final ISemaphore semaphore = client.getSemaphore(randomString());
        semaphore.init(10);
        assertTrue(semaphore.tryAcquire(5));
    }
View Full Code Here

        assertTrue(semaphore.tryAcquire(5));
    }

    @Test
    public void testTryAcquireMultiPermits_whenUnAvailable() throws Exception {
        final ISemaphore semaphore = client.getSemaphore(randomString());
        semaphore.init(5);
        assertFalse(semaphore.tryAcquire(10));
    }
View Full Code Here

        assertFalse(semaphore.tryAcquire(10));
    }

    @Test
    public void testTryAcquireMultiPermits_whenAvailableWithTimeOut() throws Exception {
        final ISemaphore semaphore = client.getSemaphore(randomString());
        semaphore.init(10);
        assertTrue(semaphore.tryAcquire(5, 1, TimeUnit.MILLISECONDS));
    }
View Full Code Here

        assertTrue(semaphore.tryAcquire(5, 1, TimeUnit.MILLISECONDS));
    }

    @Test
    public void testTryAcquireMultiPermits_whenUnAvailableWithTimeOut() throws Exception {
        final ISemaphore semaphore = client.getSemaphore(randomString());
        semaphore.init(5);
        assertFalse(semaphore.tryAcquire(10, 1, TimeUnit.MILLISECONDS));
    }
View Full Code Here

        assertFalse(semaphore.tryAcquire(10, 1, TimeUnit.MILLISECONDS));
    }

    @Test
    public void testTryAcquire_afterRelease() throws Exception {
        final ISemaphore semaphore = client.getSemaphore(randomString());
        semaphore.init(0);
        semaphore.release();
        assertTrue(semaphore.tryAcquire());
    }
View Full Code Here

        assertTrue(semaphore.tryAcquire());
    }

    @Test
    public void testMulitReleaseTryAcquire() throws Exception {
        final ISemaphore semaphore = client.getSemaphore(randomString());
        semaphore.init(0);
        semaphore.release(5);
        assertTrue(semaphore.tryAcquire(5));
    }
View Full Code Here

        assertTrue(semaphore.tryAcquire(5));
    }

    @Test
    public void testAcquire_Threaded() throws Exception {
        final ISemaphore semaphore = client.getSemaphore(randomString());
        semaphore.init(0);

        final CountDownLatch latch = new CountDownLatch(1);
        new Thread(){
            public void run() {
                try {
                    semaphore.acquire();
                    latch.countDown();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }.start();
        Thread.sleep(1000);
        semaphore.release(2);

        assertTrue(latch.await(5, TimeUnit.SECONDS));
        assertEquals(1, semaphore.availablePermits());
    }
View Full Code Here

        assertEquals(1, semaphore.availablePermits());
    }

    @Test
    public void tryAcquire_Threaded() throws Exception {
        final ISemaphore semaphore = client.getSemaphore(randomString());
        semaphore.init(0);

        final CountDownLatch latch = new CountDownLatch(1);
        new Thread(){
            public void run() {
                try {
                    if(semaphore.tryAcquire(1, 5, TimeUnit.SECONDS)){
                        latch.countDown();
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }.start();

        semaphore.release(2);
        assertTrue(latch.await(5, TimeUnit.SECONDS));
        assertEquals(1, semaphore.availablePermits());
    }
View Full Code Here

    public void concurrent_trySemaphoreWithTimeOutTest() {
        concurrent_trySemaphoreTest(true);
    }

    public void concurrent_trySemaphoreTest(final boolean tryWithTimeOut) {
        final ISemaphore semaphore = client.getSemaphore(randomString());
        semaphore.init(1);
        final AtomicInteger upTotal = new AtomicInteger(0);
        final AtomicInteger downTotal = new AtomicInteger(0);

        final SemaphoreTestThread threads[] = new SemaphoreTestThread[8];
        for(int i=0; i<threads.length; i++){
View Full Code Here

TOP

Related Classes of com.hazelcast.core.ISemaphore

Copyright © 2018 www.massapicom. 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.