use of com.hazelcast.core.ICountDownLatch in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method cancelledAndDone_durable.
@Test()
public void cancelledAndDone_durable() throws ExecutionException, InterruptedException {
HazelcastInstance[] instances = createClusterWithCount(3);
Object key = generateKeyOwnedBy(instances[1]);
ICountDownLatch latch = instances[0].getCountDownLatch("latch");
latch.trySetCount(1);
IScheduledExecutorService executorService = getScheduledExecutor(instances, "s");
IScheduledFuture future = executorService.scheduleOnKeyOwnerAtFixedRate(new ICountdownLatchRunnableTask("latch"), key, 0, 1, SECONDS);
latch.await(10, SECONDS);
assertFalse(future.isCancelled());
assertFalse(future.isDone());
future.cancel(false);
assertTrue(future.isCancelled());
assertTrue(future.isDone());
instances[1].getLifecycleService().shutdown();
assertTrue(future.isCancelled());
assertTrue(future.isDone());
}
use of com.hazelcast.core.ICountDownLatch in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method handlerTaskAndSchedulerNames_withRunnable.
@Test
public void handlerTaskAndSchedulerNames_withRunnable() throws ExecutionException, InterruptedException {
int delay = 0;
String schedulerName = "s";
String taskName = "TestRunnable";
HazelcastInstance[] instances = createClusterWithCount(2);
ICountDownLatch latch = instances[0].getCountDownLatch("latch");
latch.trySetCount(1);
IScheduledExecutorService executorService = instances[0].getScheduledExecutorService(schedulerName);
IScheduledFuture future = executorService.schedule(named(taskName, new ICountdownLatchRunnableTask("latch")), delay, SECONDS);
latch.await(10, SECONDS);
ScheduledTaskHandler handler = future.getHandler();
assertEquals(schedulerName, handler.getSchedulerName());
assertEquals(taskName, handler.getTaskName());
}
use of com.hazelcast.core.ICountDownLatch in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method getErroneous_durable.
@Test
public void getErroneous_durable() throws InterruptedException, ExecutionException {
int delay = 2;
String taskName = "Test";
String completionLatchName = "completionLatch";
HazelcastInstance[] instances = createClusterWithCount(2);
String key = generateKeyOwnedBy(instances[1]);
IScheduledExecutorService executorService = getScheduledExecutor(instances, "s");
ICountDownLatch latch = instances[1].getCountDownLatch(completionLatchName);
latch.trySetCount(1);
IScheduledFuture<Double> future = executorService.scheduleOnKeyOwner(named(taskName, new ErroneousCallableTask(completionLatchName)), key, delay, SECONDS);
latch.await(10, SECONDS);
instances[1].getLifecycleService().shutdown();
Thread.sleep(2000);
expected.expect(ExecutionException.class);
expected.expectCause(new RootCauseMatcher(IllegalStateException.class, "Erroneous task"));
future.get();
}
use of com.hazelcast.core.ICountDownLatch in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method scheduleOnKeyOwner_withNotPeriodicRunable.
@Test
public void scheduleOnKeyOwner_withNotPeriodicRunable() throws ExecutionException, InterruptedException {
HazelcastInstance[] instances = createClusterWithCount(2);
String key = generateKeyOwnedBy(instances[0]);
IScheduledExecutorService s = getScheduledExecutor(instances, "s");
ICountDownLatch latch = instances[0].getCountDownLatch("latch");
latch.trySetCount(1);
s.scheduleOnKeyOwner(new ICountdownLatchRunnableTask("latch"), key, 2, SECONDS).get();
assertEquals(0, latch.getCount());
}
use of com.hazelcast.core.ICountDownLatch in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method scheduleOnMemberWithRepetition.
@Test
public void scheduleOnMemberWithRepetition() throws InterruptedException {
HazelcastInstance[] instances = createClusterWithCount(4);
IScheduledExecutorService s = getScheduledExecutor(instances, "s");
ICountDownLatch latch = instances[0].getCountDownLatch("latch");
latch.trySetCount(4);
Map<Member, IScheduledFuture<?>> futures = s.scheduleOnAllMembersAtFixedRate(new ICountdownLatchRunnableTask("latch"), 0, 3, SECONDS);
latch.await(10, SECONDS);
assertEquals(0, latch.getCount());
assertEquals(4, futures.size());
}
Aggregations