use of com.hazelcast.core.ISemaphore in project hazelcast by hazelcast.
the class ClientSemaphoreTest method testTryAcquireMultiPermits_whenAvailable.
@Test
public void testTryAcquireMultiPermits_whenAvailable() throws Exception {
final ISemaphore semaphore = client.getSemaphore(randomString());
semaphore.init(10);
assertTrue(semaphore.tryAcquire(5));
}
use of com.hazelcast.core.ISemaphore in project hazelcast by hazelcast.
the class ClientSemaphoreTest method testSemaphoreInit.
@Test
public void testSemaphoreInit() throws Exception {
final ISemaphore semaphore = client.getSemaphore(randomString());
assertTrue(semaphore.init(10));
}
use of com.hazelcast.core.ISemaphore in project hazelcast by hazelcast.
the class ClientSemaphoreTest method testTryAcquireMultiPermits_whenAvailableWithTimeOut.
@Test
public void testTryAcquireMultiPermits_whenAvailableWithTimeOut() throws Exception {
final ISemaphore semaphore = client.getSemaphore(randomString());
semaphore.init(10);
assertTrue(semaphore.tryAcquire(5, 1, TimeUnit.MILLISECONDS));
}
use of com.hazelcast.core.ISemaphore in project hazelcast by hazelcast.
the class ClientSemaphoreTest method testAvailablePermits_AfterDrainPermits.
@Test
public void testAvailablePermits_AfterDrainPermits() throws Exception {
final ISemaphore semaphore = client.getSemaphore(randomString());
semaphore.init(10);
semaphore.drainPermits();
assertEquals(0, semaphore.availablePermits());
}
use of com.hazelcast.core.ISemaphore in project hazelcast by hazelcast.
the class ClientSemaphoreTest method tryAcquire_Threaded.
@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(30, TimeUnit.SECONDS));
assertEquals(1, semaphore.availablePermits());
}
Aggregations