use of com.hazelcast.core.ILock in project hazelcast by hazelcast.
the class ConditionAbstractTest method testSignalAll_whenMultipleConditions.
@Test(timeout = 60000)
public void testSignalAll_whenMultipleConditions() throws InterruptedException {
ILock lock = callerInstance.getLock(newName());
ICondition condition0 = lock.newCondition(newName());
ICondition condition1 = lock.newCondition(newName());
CountDownLatch allAwaited = new CountDownLatch(2);
CountDownLatch allSignalled = new CountDownLatch(10);
startThreadWaitingOnCondition(lock, condition0, allAwaited, allSignalled);
startThreadWaitingOnCondition(lock, condition1, allAwaited, allSignalled);
assertOpenEventually("All threads should have been reached await", allAwaited);
signalAll(lock, condition0);
assertCountEventually("Condition has not been signalled", 9, allSignalled, THIRTY_SECONDS);
}
use of com.hazelcast.core.ILock in project hazelcast by hazelcast.
the class ConditionAbstractTest method testSignalWithSingleWaiter.
@Test(timeout = 60000)
public void testSignalWithSingleWaiter() throws InterruptedException {
String lockName = newName();
String conditionName = newName();
final ILock lock = callerInstance.getLock(lockName);
final ICondition condition = lock.newCondition(conditionName);
final AtomicInteger count = new AtomicInteger(0);
final CountDownLatch threadLockedTheLock = new CountDownLatch(1);
Thread t = new Thread(new Runnable() {
public void run() {
try {
lock.lock();
if (lock.isLockedByCurrentThread()) {
count.incrementAndGet();
}
threadLockedTheLock.countDown();
condition.await();
if (lock.isLockedByCurrentThread()) {
count.incrementAndGet();
}
} catch (InterruptedException ignored) {
} finally {
lock.unlock();
}
}
});
t.start();
threadLockedTheLock.await();
assertUnlockedEventually(lock, THIRTY_SECONDS);
signal(lock, condition);
assertAtomicEventually("Locks was not always locked by the expected thread", 2, count, THIRTY_SECONDS);
}
Aggregations