Package com.hazelcast.core

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


            int rand = (int) (Math.random() * 5) + 1;

            semaphore.acquire(rand);
            initialPermits -= rand;
            assertEquals(initialPermits, semaphore.availablePermits());
            semaphore.release(rand);
            initialPermits += rand;
            assertEquals(initialPermits, semaphore.availablePermits());

            instances[i].shutdown();

View Full Code Here


            instances[i].shutdown();

            semaphore.acquire(rand);
            initialPermits -= rand;
            assertEquals(initialPermits, semaphore.availablePermits());
            semaphore.release(rand);
            initialPermits += rand;
            assertEquals(initialPermits, semaphore.availablePermits());
        }
    }
View Full Code Here

            }
        };
        thread.start();

        instance2.shutdown();
        semaphore.release();

        HazelcastInstance instance3 = factory.newHazelcastInstance();
        ISemaphore semaphore1 = instance3.getSemaphore("test");
        semaphore1.release();
View Full Code Here

        instance2.shutdown();
        semaphore.release();

        HazelcastInstance instance3 = factory.newHazelcastInstance();
        ISemaphore semaphore1 = instance3.getSemaphore("test");
        semaphore1.release();

        try {
            assertTrue(countDownLatch.await(15, TimeUnit.SECONDS));
        } catch (InterruptedException e) {
            e.printStackTrace();
View Full Code Here

                            sleepMillis((int) (Math.random() * 3));
                            counter.inc();
                        } catch (InterruptedException e) {
                            return;
                        } finally {
                            semaphore.release();
                        }
                    }
                    latch.countDown();
                }
            }.start();
View Full Code Here

        getClient().send(new AcquireRequest(name, 8, 6 * 1000));
        assertEquals(7, s.availablePermits());

        Thread.sleep(2 * 1000);

        s.release(1);

        result = (Boolean) getClient().receive();
        assertTrue(result);
        assertEquals(0, s.availablePermits());

View Full Code Here

        getClient().send(new AvailableRequest(name));
        int result = (Integer) getClient().receive();
        assertEquals(0, result);

        ISemaphore s = getInstance().getSemaphore(name);
        s.release(5);

        getClient().send(new AvailableRequest(name));
        result = (Integer) getClient().receive();
        assertEquals(5, result);
    }
View Full Code Here

        getClient().send(new DrainRequest(name));
        int result = (Integer) getClient().receive();
        assertEquals(10, result);

        s.release(4);

        getClient().send(new DrainRequest(name));
        result = (Integer) getClient().receive();
        assertEquals(4, result);
    }
View Full Code Here

        final ISemaphore semaphore = hz.getSemaphore(randomString());

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

        assertEquals(semaphore.availablePermits(), numberOfPermits);
    }
View Full Code Here

    @Test(timeout = 30000)
    public void testRelease_whenArgumentNegative() {
        final ISemaphore semaphore = hz.getSemaphore(randomString());
        try {
            semaphore.release(-5);
            fail();
        } catch (IllegalArgumentException expected) {
        }
        assertEquals(0, semaphore.availablePermits());
    }
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.