use of com.hazelcast.core.ICondition in project hazelcast by hazelcast.
the class ConditionAbstractTest method testSignal_whenOwnedByOtherThread.
@Test(timeout = 60000, expected = IllegalMonitorStateException.class)
public void testSignal_whenOwnedByOtherThread() throws InterruptedException {
final ILock lock = callerInstance.getLock(newName());
final ICondition condition = lock.newCondition(newName());
releaseLockInSeparateThread(lock);
condition.signal();
}
use of com.hazelcast.core.ICondition in project hazelcast by hazelcast.
the class ProducerConsumerConditionStressTest method test.
@Test
public void test() {
HazelcastInstance[] instances = createHazelcastInstanceFactory(INSTANCE_COUNT).newInstances();
HazelcastInstance hz = instances[0];
ILock lock = hz.getLock(randomString());
ICondition condition = lock.newCondition(randomString());
ConsumerThread[] consumers = new ConsumerThread[CONSUMER_COUNT];
for (int k = 0; k < consumers.length; k++) {
ConsumerThread thread = new ConsumerThread(k, lock, condition);
thread.start();
consumers[k] = thread;
}
ProducerThread[] producers = new ProducerThread[PRODUCER_COUNT];
for (int k = 0; k < producers.length; k++) {
ProducerThread thread = new ProducerThread(k, lock, condition);
thread.start();
producers[k] = thread;
}
assertJoinable(600, producers);
assertJoinable(600, consumers);
for (TestThread consumer : consumers) {
assertNull(consumer.throwable);
}
for (TestThread producer : producers) {
assertNull(producer.throwable);
}
}
use of com.hazelcast.core.ICondition in project hazelcast by hazelcast.
the class ConditionAbstractTest method testSignalWithMultipleWaiters.
//if there are multiple waiters, then only 1 waiter should be notified.
@Test(timeout = 60000)
public void testSignalWithMultipleWaiters() throws InterruptedException {
ILock lock = callerInstance.getLock(newName());
ICondition condition = lock.newCondition(newName());
CountDownLatch allAwaited = new CountDownLatch(3);
CountDownLatch allSignalled = new CountDownLatch(10);
startThreadWaitingOnCondition(lock, condition, allAwaited, allSignalled);
startThreadWaitingOnCondition(lock, condition, allAwaited, allSignalled);
startThreadWaitingOnCondition(lock, condition, allAwaited, allSignalled);
assertOpenEventually("All threads should have been reached await", allAwaited);
signal(lock, condition);
assertCountEventually("Condition has not been signalled", 9, allSignalled, THIRTY_SECONDS);
assertFalse(lock.isLocked());
}
use of com.hazelcast.core.ICondition in project hazelcast by hazelcast.
the class ConditionAbstractTest method testAwait_whenOwnedByOtherThread.
@Test(timeout = 60000, expected = IllegalMonitorStateException.class)
public void testAwait_whenOwnedByOtherThread() throws InterruptedException {
final ILock lock = callerInstance.getLock(newName());
final ICondition condition = lock.newCondition(newName());
releaseLockInSeparateThread(lock);
condition.await();
}
use of com.hazelcast.core.ICondition in project hazelcast by hazelcast.
the class ConditionAdvancedTest method testShutDownNode_whenOtherWaitingOnConditionAwait.
@Test(timeout = 60000, expected = HazelcastInstanceNotActiveException.class)
public void testShutDownNode_whenOtherWaitingOnConditionAwait() throws InterruptedException {
final TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
final HazelcastInstance instance = nodeFactory.newHazelcastInstance();
nodeFactory.newHazelcastInstance();
final String name = randomString();
final ILock lock = instance.getLock(name);
final ICondition condition = lock.newCondition("condition");
final CountDownLatch latch = new CountDownLatch(1);
new Thread(new Runnable() {
public void run() {
try {
latch.await(1, TimeUnit.MINUTES);
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
instance.shutdown();
}
}).start();
lock.lock();
try {
latch.countDown();
condition.await();
} catch (InterruptedException e) {
}
lock.unlock();
}
Aggregations