use of com.hazelcast.cp.ICountDownLatch in project hazelcast by hazelcast.
the class ScheduledExecutorServiceSlowTest method cancelUninterruptedTask_waitUntilRunCompleted_killMember_checkStatusIsCancelled.
@Test
public void cancelUninterruptedTask_waitUntilRunCompleted_killMember_checkStatusIsCancelled() throws Exception {
HazelcastInstance[] instances = createClusterWithCount(2);
String key = generateKeyOwnedBy(instances[1]);
String runFinishedLatchName = "runFinishedLatch";
ICountDownLatch latch = instances[0].getCPSubsystem().getCountDownLatch(runFinishedLatchName);
latch.trySetCount(1);
IScheduledExecutorService executorService = getScheduledExecutor(instances, "s");
IScheduledFuture future = executorService.scheduleOnKeyOwnerAtFixedRate(new HotLoopBusyTask(runFinishedLatchName), key, 0, 1, SECONDS);
assertFalse(future.isCancelled());
assertFalse(future.isDone());
future.cancel(false);
assertTrue(future.isCancelled());
assertTrue(future.isDone());
// wait till the task is actually done, since even though we cancelled the task is current task is still running
latch.await(60, SECONDS);
// make sure SyncState goes through
sleepSeconds(10);
instances[1].getLifecycleService().terminate();
// check once more that the task status is consistent
assertTrue(future.isCancelled());
assertTrue(future.isDone());
}
use of com.hazelcast.cp.ICountDownLatch in project hazelcast by hazelcast.
the class ScheduledExecutorServiceSlowTest method schedulePeriodicTask_withMultipleSchedulers_atRandomPartitions_thenGetAllScheduled.
@Test
public void schedulePeriodicTask_withMultipleSchedulers_atRandomPartitions_thenGetAllScheduled() throws Exception {
String runsCounterName = "runs";
HazelcastInstance[] instances = createClusterWithCount(3);
ICountDownLatch runsLatch = instances[0].getCPSubsystem().getCountDownLatch(runsCounterName);
int numOfSchedulers = 10;
int numOfTasks = 10;
int expectedTotal = numOfSchedulers * numOfTasks;
runsLatch.trySetCount(expectedTotal);
for (int i = 0; i < numOfSchedulers; i++) {
IScheduledExecutorService s = getScheduledExecutor(instances, "scheduler_" + i);
String key = generateKeyOwnedBy(instances[1]);
for (int k = 0; k < numOfTasks; k++) {
s.scheduleOnKeyOwnerAtFixedRate(new ICountdownLatchRunnableTask(runsCounterName), key, 0, 2, SECONDS);
}
}
runsLatch.await(10, SECONDS);
int actualTotal = 0;
for (int i = 0; i < numOfSchedulers; i++) {
actualTotal += countScheduledTasksOn(getScheduledExecutor(instances, "scheduler_" + i));
}
assertEquals(expectedTotal, actualTotal, 0);
}
Aggregations