Package com.hazelcast.core

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


        semaphore.release();

        assertTrueEventually(new AssertTask() {
            @Override
            public void run() throws Exception {
                assertEquals(0, semaphore.availablePermits());
            }
        });
    }

    @Test(timeout = 30000)
View Full Code Here


        final ISemaphore semaphore = hz.getSemaphore(randomString());
        int numberOfPermits = 20;

        assertTrue(semaphore.init(numberOfPermits));
        for (int i = 0; i < numberOfPermits; i += 5) {
            assertEquals(numberOfPermits - i, semaphore.availablePermits());
            semaphore.acquire(5);
        }
        assertEquals(semaphore.availablePermits(), 0);
    }
View Full Code Here

        assertTrue(semaphore.init(numberOfPermits));
        for (int i = 0; i < numberOfPermits; i += 5) {
            assertEquals(numberOfPermits - i, semaphore.availablePermits());
            semaphore.acquire(5);
        }
        assertEquals(semaphore.availablePermits(), 0);
    }

    @Test(timeout = 30000)
    public void testMultipleAcquire_whenNegative() throws InterruptedException {
        final ISemaphore semaphore = hz.getSemaphore(randomString());
View Full Code Here

                semaphore.acquire(-5);
                fail();
            }
        } catch (IllegalArgumentException expected) {
        }
        assertEquals(10, semaphore.availablePermits());

    }

    @Test(timeout = 30000)
    public void testMultipleAcquire_whenNotEnoughPermits() throws InterruptedException {
View Full Code Here

        final Thread thread = new Thread() {
            @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

            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

        assertTrueAllTheTime(new AssertTask() {
            @Override
            public void run() throws Exception {
                assertTrue(thread.isAlive());
                assertEquals(5, semaphore.availablePermits());
            }
        }, 5);
    }

    @Test(timeout = 30000)
View Full Code Here

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

        for (int i = 0; i < numberOfPermits; i += 5) {
            assertEquals(i, semaphore.availablePermits());
            semaphore.release(5);
        }
        assertEquals(semaphore.availablePermits(), numberOfPermits);
    }
View Full Code Here

        for (int i = 0; i < numberOfPermits; i += 5) {
            assertEquals(i, semaphore.availablePermits());
            semaphore.release(5);
        }
        assertEquals(semaphore.availablePermits(), numberOfPermits);
    }

    @Test(timeout = 30000)
    public void testMultipleRelease_whenNegative() throws InterruptedException {
        final ISemaphore semaphore = hz.getSemaphore(randomString());
View Full Code Here

            semaphore.release(-5);
            fail();

        } catch (IllegalArgumentException expected) {
        }
        assertEquals(0, semaphore.availablePermits());
    }

    @Repeat(10)
    @Test(timeout = 30000)
    public void testMultipleRelease_whenBlockedAcquireThreads() throws InterruptedException {
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.