use of com.hazelcast.core.ISemaphore in project hazelcast by hazelcast.
the class ClientSemaphoreTest method testAvailablePermits.
@Test
public void testAvailablePermits() throws Exception {
final ISemaphore semaphore = client.getSemaphore(randomString());
semaphore.init(10);
assertEquals(10, semaphore.availablePermits());
}
use of com.hazelcast.core.ISemaphore in project hazelcast by hazelcast.
the class ClientSemaphoreTest method testSemaphoreNegInit.
@Test(expected = IllegalArgumentException.class)
public void testSemaphoreNegInit() throws Exception {
final ISemaphore semaphore = client.getSemaphore(randomString());
semaphore.init(-1);
}
use of com.hazelcast.core.ISemaphore in project hazelcast by hazelcast.
the class ClientSemaphoreTest method testTryAcquire_whenUnAvailable.
@Test
public void testTryAcquire_whenUnAvailable() throws Exception {
final ISemaphore semaphore = client.getSemaphore(randomString());
semaphore.init(0);
assertFalse(semaphore.tryAcquire());
}
use of com.hazelcast.core.ISemaphore in project hazelcast by hazelcast.
the class ClientSemaphoreTest method testAvailableReducePermits.
@Test
public void testAvailableReducePermits() throws Exception {
final ISemaphore semaphore = client.getSemaphore(randomString());
semaphore.init(10);
semaphore.reducePermits(5);
assertEquals(5, semaphore.availablePermits());
}
use of com.hazelcast.core.ISemaphore in project hazelcast by hazelcast.
the class ClientSemaphoreTest method testAcquire_Threaded.
@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();
sleepSeconds(1);
semaphore.release(2);
assertTrue(latch.await(30, TimeUnit.SECONDS));
assertEquals(1, semaphore.availablePermits());
}
Aggregations