use of com.hazelcast.core.ICountDownLatch in project hazelcast by hazelcast.
the class ScheduledExecutorServiceSlowTest method stats_longRunningTask_durable.
@Test
public void stats_longRunningTask_durable() throws ExecutionException, InterruptedException {
HazelcastInstance[] instances = createClusterWithCount(4);
String key = generateKeyOwnedBy(instances[1]);
ICountDownLatch latch = instances[0].getCountDownLatch("latch");
latch.trySetCount(6);
IScheduledExecutorService executorService = getScheduledExecutor(instances, "s");
IScheduledFuture future = executorService.scheduleOnKeyOwnerAtFixedRate(new ICountdownLatchRunnableTask("latch"), key, 0, 10, SECONDS);
Thread.sleep(12000);
instances[1].getLifecycleService().shutdown();
latch.await(70, SECONDS);
// Wait for run-cycle to finish before cancelling, in order for stats to get updated.
sleepSeconds(4);
future.cancel(false);
ScheduledTaskStatistics stats = future.getStats();
assertEquals(6, stats.getTotalRuns());
}
use of com.hazelcast.core.ICountDownLatch in project hazelcast by hazelcast.
the class ScheduledExecutorServiceSlowTest method schedule_withLongSleepingCallable_blockingOnGet.
@Test
public void schedule_withLongSleepingCallable_blockingOnGet() throws ExecutionException, InterruptedException {
int delay = 0;
double expectedResult = 169.4;
HazelcastInstance[] instances = createClusterWithCount(2);
ICountDownLatch runsCountLatch = instances[0].getCountDownLatch("runsCountLatchName");
runsCountLatch.trySetCount(1);
IScheduledExecutorService executorService = getScheduledExecutor(instances, "s");
IScheduledFuture<Double> future = executorService.schedule(new ICountdownLatchCallableTask("runsCountLatchName", 15000), delay, SECONDS);
double result = future.get();
assertEquals(expectedResult, result, 0);
assertEquals(true, future.isDone());
assertEquals(false, future.isCancelled());
}
use of com.hazelcast.core.ICountDownLatch in project hazelcast by hazelcast.
the class ScheduledExecutorServiceSlowTest method schedulePeriodicTask_withMultipleSchedulers_atRandomPartitions_thenGetAllScheduled.
@Test
public void schedulePeriodicTask_withMultipleSchedulers_atRandomPartitions_thenGetAllScheduled() throws ExecutionException, InterruptedException {
String runsCounterName = "runs";
HazelcastInstance[] instances = createClusterWithCount(3);
ICountDownLatch runsLatch = instances[0].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);
}
use of com.hazelcast.core.ICountDownLatch in project hazelcast by hazelcast.
the class ScheduledExecutorServiceSlowTest method stats_manyRepetitionsTask.
@Test
public void stats_manyRepetitionsTask() throws ExecutionException, InterruptedException {
HazelcastInstance[] instances = createClusterWithCount(4);
ICountDownLatch latch = instances[0].getCountDownLatch("latch");
latch.trySetCount(6);
IScheduledExecutorService executorService = getScheduledExecutor(instances, "s");
IScheduledFuture future = executorService.scheduleAtFixedRate(new ICountdownLatchRunnableTask("latch"), 0, 10, SECONDS);
latch.await(120, SECONDS);
// Wait for run-cycle to finish before cancelling, in order for stats to get updated.
sleepSeconds(4);
future.cancel(false);
ScheduledTaskStatistics stats = future.getStats();
assertEquals(6, stats.getTotalRuns());
}
use of com.hazelcast.core.ICountDownLatch in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method schedule_andCancel_onMember.
@Test()
public void schedule_andCancel_onMember() throws ExecutionException, InterruptedException {
HazelcastInstance[] instances = createClusterWithCount(2);
ICountDownLatch latch = instances[0].getCountDownLatch("latch");
latch.trySetCount(1);
IScheduledExecutorService executorService = getScheduledExecutor(instances, "s");
IScheduledFuture future = executorService.scheduleOnMemberAtFixedRate(new ICountdownLatchRunnableTask("latch"), instances[0].getCluster().getLocalMember(), 1, 1, SECONDS);
Thread.sleep(5000);
assertFalse(future.isCancelled());
assertFalse(future.isDone());
future.cancel(false);
assertTrue(future.isCancelled());
assertTrue(future.isDone());
}
Aggregations