use of com.hazelcast.core.ICondition in project hazelcast by hazelcast.
the class LegacyClientConditionTest method testDestroyLockWhenOtherWaitingOnConditionAwait.
@Test(expected = DistributedObjectDestroyedException.class)
public void testDestroyLockWhenOtherWaitingOnConditionAwait() {
final ILock lock = client.getLock("testDestroyLockWhenOtherWaitingOnConditionAwait");
final ICondition condition = lock.newCondition("condition");
final CountDownLatch latch = new CountDownLatch(1);
new Thread(new Runnable() {
public void run() {
try {
latch.await(30, TimeUnit.SECONDS);
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
lock.destroy();
}
}).start();
lock.lock();
try {
latch.countDown();
condition.await();
} catch (InterruptedException e) {
}
lock.unlock();
}
use of com.hazelcast.core.ICondition in project hazelcast by hazelcast.
the class LegacyClientConditionTest method testLockConditionSimpleUsage.
@Test
public void testLockConditionSimpleUsage() throws InterruptedException {
final String name = randomString();
final ILock lock = client.getLock(name);
final ICondition condition = lock.newCondition(randomString());
final AtomicInteger count = new AtomicInteger(0);
final CountDownLatch threadGetTheLock = new CountDownLatch(1);
Thread t = new Thread(new Runnable() {
public void run() {
lock.lock();
threadGetTheLock.countDown();
try {
if (lock.isLockedByCurrentThread()) {
count.incrementAndGet();
}
condition.await();
if (lock.isLockedByCurrentThread()) {
count.incrementAndGet();
}
} catch (InterruptedException ignored) {
} finally {
lock.unlock();
}
}
});
t.start();
assertOpenEventually(threadGetTheLock);
lock.lock();
assertEquals(true, lock.isLocked());
condition.signal();
lock.unlock();
t.join();
assertEquals(2, count.get());
}
use of com.hazelcast.core.ICondition in project hazelcast by hazelcast.
the class LegacyClientConditionTest method testIllegalConditionUsageSignalToNonAwaiter.
@Test(expected = IllegalMonitorStateException.class)
public void testIllegalConditionUsageSignalToNonAwaiter() {
final ICondition condition = lock.newCondition("condition");
condition.signal();
}
use of com.hazelcast.core.ICondition in project hazelcast by hazelcast.
the class LegacyClientConditionTest method testConditionUsage.
@Test
public void testConditionUsage() throws InterruptedException {
lock.lock();
final ICondition condition = lock.newCondition("condition");
condition.await(1, TimeUnit.SECONDS);
lock.unlock();
}
use of com.hazelcast.core.ICondition in project hazelcast by hazelcast.
the class LegacyClientConditionTest method testAwaitNanos_remainingTime.
@Test
public void testAwaitNanos_remainingTime() throws InterruptedException {
ICondition condition = lock.newCondition("condition");
lock.lock();
try {
long timeout = 1000L;
long remainingTimeout = condition.awaitNanos(timeout);
assertTrue("Remaining timeout should be <= 0, but it's = " + remainingTimeout, remainingTimeout <= 0);
} finally {
lock.unlock();
}
}
Aggregations