use of com.hazelcast.test.TestThread in project hazelcast by hazelcast.
the class CountDownLatchAbstractTest method testAwait.
@Test(timeout = 15000)
public void testAwait() throws InterruptedException {
latch.trySetCount(1);
TestThread thread = new TestThread() {
public void doRun() {
latch.countDown();
}
};
thread.start();
assertOpenEventually(latch);
}
use of com.hazelcast.test.TestThread in project hazelcast by hazelcast.
the class ConditionAbstractTest method startThreadWaitingOnCondition.
private TestThread startThreadWaitingOnCondition(final ILock lock, final ICondition condition, final CountDownLatch awaited, final CountDownLatch signalled) {
TestThread t = new TestThread() {
public void doRun() throws Exception {
try {
lock.lock();
awaited.countDown();
condition.await();
signalled.countDown();
} finally {
lock.unlock();
}
}
};
t.start();
return t;
}
use of com.hazelcast.test.TestThread in project hazelcast by hazelcast.
the class QueueAdvancedTest method testPutInterruption.
@Test
public void testPutInterruption() {
Config config = new Config().setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), "10000");
config.getQueueConfig("default").setMaxSize(1);
HazelcastInstance instance = createHazelcastInstance(config);
final IQueue<String> queue = instance.getQueue(randomName());
assertTrue("Expected queue.offer() to succeed", queue.offer("item"));
final CountDownLatch putLatch = new CountDownLatch(1);
TestThread thread = new TestThread() {
@Override
public void doRun() throws Throwable {
putLatch.countDown();
queue.put("item");
}
};
thread.start();
assertOpenEventually(putLatch);
thread.interrupt();
thread.assertFailsEventually(InterruptedException.class);
}
use of com.hazelcast.test.TestThread in project hazelcast by hazelcast.
the class QueueAdvancedTest method testTakeInterruption.
@Test
public void testTakeInterruption() {
Config config = new Config().setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), "10000");
HazelcastInstance instance = createHazelcastInstance(config);
final IQueue<Thread> queue = instance.getQueue(randomName());
final CountDownLatch takeLatch = new CountDownLatch(1);
TestThread thread = new TestThread() {
@Override
public void doRun() throws Throwable {
takeLatch.countDown();
queue.take();
}
};
thread.start();
assertOpenEventually(takeLatch);
thread.interrupt();
thread.assertFailsEventually(InterruptedException.class);
}
use of com.hazelcast.test.TestThread in project hazelcast by hazelcast.
the class CountDownLatchAbstractTest method testAwait_withManyThreads.
@Test(timeout = 15000)
public void testAwait_withManyThreads() {
final CountDownLatch completedLatch = new CountDownLatch(10);
latch.trySetCount(1);
for (int i = 0; i < 10; i++) {
new TestThread() {
public void doRun() throws Exception {
if (latch.await(1, TimeUnit.MINUTES)) {
completedLatch.countDown();
}
}
}.start();
}
latch.countDown();
assertOpenEventually(completedLatch);
}
Aggregations