use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method getScheduled_whenTaskImplementingNamedTask.
@Test
public void getScheduled_whenTaskImplementingNamedTask() {
int delay = 1;
String taskName = NamedCallable.NAME;
NamedCallable task = new NamedCallable();
HazelcastInstance[] instances = createClusterWithCount(2);
IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
IScheduledFuture<Boolean> first = executorService.schedule(task, delay, SECONDS);
ScheduledTaskHandler handler = first.getHandler();
IScheduledFuture<Double> copy = executorService.getScheduledFuture(handler);
assertEquals(first.getHandler(), copy.getHandler());
assertEquals(copy.getHandler().getTaskName(), taskName);
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method handlerTaskAndSchedulerNames_withRunnable.
@Test
public void handlerTaskAndSchedulerNames_withRunnable() {
int delay = 0;
String schedulerName = ANY_EXECUTOR_NAME;
String taskName = "TestRunnable";
HazelcastInstance[] instances = createClusterWithCount(2);
ICountDownLatch latch = instances[0].getCPSubsystem().getCountDownLatch("latch");
latch.trySetCount(1);
IScheduledExecutorService executorService = instances[0].getScheduledExecutorService(schedulerName);
IScheduledFuture future = executorService.schedule(named(taskName, new ICountdownLatchRunnableTask("latch")), delay, SECONDS);
assertOpenEventually(latch);
ScheduledTaskHandler handler = future.getHandler();
assertEquals(schedulerName, handler.getSchedulerName());
assertEquals(taskName, handler.getTaskName());
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method cancelledAndDone_durable.
@Test
public void cancelledAndDone_durable() {
HazelcastInstance[] instances = createClusterWithCount(3);
Object key = generateKeyOwnedBy(instances[1]);
ICountDownLatch latch = instances[0].getCPSubsystem().getCountDownLatch("latch");
latch.trySetCount(1);
IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
IScheduledFuture future = executorService.scheduleOnKeyOwnerAtFixedRate(new ICountdownLatchRunnableTask("latch"), key, 0, 1, SECONDS);
assertOpenEventually(latch);
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.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method scheduleOnKeyOwner_withNotPeriodicRunnable.
@Test
public void scheduleOnKeyOwner_withNotPeriodicRunnable() throws Exception {
HazelcastInstance[] instances = createClusterWithCount(2);
String key = generateKeyOwnedBy(instances[0]);
IScheduledExecutorService s = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
ICountDownLatch latch = instances[0].getCPSubsystem().getCountDownLatch("latch");
latch.trySetCount(1);
s.scheduleOnKeyOwner(new ICountdownLatchRunnableTask("latch"), key, 2, SECONDS).get();
assertEquals(0, latch.getCount());
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method scheduledAtFixedRate_generates_statistics_when_stats_enabled.
@Test
public void scheduledAtFixedRate_generates_statistics_when_stats_enabled() {
// run task
Config config = smallInstanceConfig();
config.getScheduledExecutorConfig(ANY_EXECUTOR_NAME).setStatisticsEnabled(true);
long now = System.currentTimeMillis();
HazelcastInstance[] instances = createClusterWithCount(1, config);
IScheduledExecutorService s = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
CountDownLatch progress = new CountDownLatch(3);
Semaphore suspend = new Semaphore(0);
s.scheduleAtFixedRate(new CountableRunTask(progress, suspend), 1, 1, SECONDS);
assertOpenEventually(progress);
try {
assertTrueEventually(() -> {
// collect metrics
Map<String, List<Long>> metrics = collectMetrics(SCHEDULED_EXECUTOR_PREFIX, instances);
// check results
assertMetricsCollected(metrics, 0, 0, 3, 2, 0, now, 0);
});
} finally {
suspend.release();
}
}
Aggregations