use of com.hazelcast.core.ICountDownLatch in project hazelcast by hazelcast.
the class CountDownLatchAdvancedTest method testSimpleUsage.
@Test
public void testSimpleUsage() throws InterruptedException {
final int k = 5;
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(k);
final HazelcastInstance[] instances = factory.newInstances();
ICountDownLatch latch = instances[0].getCountDownLatch("test");
latch.trySetCount(k - 1);
assertEquals(k - 1, latch.getCount());
new Thread() {
public void run() {
for (int i = 1; i < k; i++) {
try {
sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
final ICountDownLatch l = instances[i].getCountDownLatch("test");
l.countDown();
assertEquals(k - 1 - i, l.getCount());
}
}
}.start();
assertTrue(latch.await(5000, TimeUnit.MILLISECONDS));
assertEquals(0, latch.getCount());
}
use of com.hazelcast.core.ICountDownLatch in project hazelcast by hazelcast.
the class CountDownLatchAdvancedTest method testDestroy.
@Test
public void testDestroy() {
HazelcastInstance instance = createHazelcastInstance();
ICountDownLatch latch = instance.getCountDownLatch(randomString());
NodeEngineImpl nodeEngine = getNode(instance).getNodeEngine();
CountDownLatchService service = nodeEngine.getService(CountDownLatchService.SERVICE_NAME);
latch.destroy();
assertFalse(service.containsLatch(latch.getName()));
}
use of com.hazelcast.core.ICountDownLatch in project hazelcast by hazelcast.
the class CountDownLatchAdvancedTest method testAwait_whenInstanceShutdown_thenHazelcastInstanceNotActiveException.
@Test
public void testAwait_whenInstanceShutdown_thenHazelcastInstanceNotActiveException() throws InterruptedException {
HazelcastInstance instance = createHazelcastInstance();
final ICountDownLatch latch = instance.getCountDownLatch(randomString());
latch.trySetCount(10);
final TestThread awaitThread = new TestThread() {
@Override
public void doRun() throws Exception {
latch.await(1, TimeUnit.HOURS);
}
};
awaitThread.start();
// give the awaitthread some time to get in the waiting state
sleepSeconds(5);
instance.shutdown();
awaitThread.assertFailsEventually(HazelcastInstanceNotActiveException.class);
}
use of com.hazelcast.core.ICountDownLatch in project hazelcast by hazelcast.
the class CountDownLatchAdvancedTest method testLatchDestroyed.
@Test(expected = DistributedObjectDestroyedException.class)
public void testLatchDestroyed() throws Exception {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance hz1 = factory.newHazelcastInstance();
HazelcastInstance hz2 = factory.newHazelcastInstance();
final ICountDownLatch latch = hz1.getCountDownLatch("test");
latch.trySetCount(2);
new TestThread() {
public void doRun() throws Exception {
sleep(1000);
latch.destroy();
}
}.start();
hz2.getCountDownLatch("test").await(5, TimeUnit.SECONDS);
}
use of com.hazelcast.core.ICountDownLatch in project hazelcast by hazelcast.
the class MBeanDestroyTest method testCountDownLatch.
@Test
public void testCountDownLatch() throws Exception {
ICountDownLatch countDownLatch = holder.getHz().getCountDownLatch("semaphore");
countDownLatch.getCount();
holder.assertMBeanExistEventually("ICountDownLatch", countDownLatch.getName());
destroyObjectAndAssert(countDownLatch, "ICountDownLatch");
}
Aggregations