use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method stats.
@Test
public void stats() throws Exception {
double delay = 2.0;
HazelcastInstance[] instances = createClusterWithCount(2);
Object key = generateKeyOwnedBy(instances[1]);
IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
IScheduledFuture<Double> future = executorService.scheduleOnKeyOwner(new PlainCallableTask(), key, (int) delay, SECONDS);
future.get();
ScheduledTaskStatistics stats = future.getStats();
assertEquals(1, stats.getTotalRuns());
assertEquals(0, stats.getLastRunDuration(SECONDS));
assertEquals(0, stats.getTotalRunTime(SECONDS));
assertNotEquals(0, stats.getLastIdleTime(SECONDS));
assertNotEquals(0, stats.getTotalIdleTime(SECONDS));
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method scheduleOnMember_getDelay.
@Test
public void scheduleOnMember_getDelay() {
int delay = 20;
String taskName = "Test";
HazelcastInstance[] instances = createClusterWithCount(2);
Member localMember = instances[0].getCluster().getLocalMember();
IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
IScheduledFuture<Double> first = executorService.scheduleOnMember(named(taskName, new PlainCallableTask()), localMember, delay, MINUTES);
assertEquals(19, first.getDelay(MINUTES));
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method scheduledAtFixedRate_does_not_generate_statistics_when_stats_disabled.
@Test
public void scheduledAtFixedRate_does_not_generate_statistics_when_stats_disabled() {
// run task
Config config = smallInstanceConfig();
config.getScheduledExecutorConfig(ANY_EXECUTOR_NAME).setStatisticsEnabled(false);
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);
assertTrueAllTheTime(() -> {
// collect metrics
Map<String, List<Long>> metrics = collectMetrics(SCHEDULED_EXECUTOR_PREFIX, instances);
// check results
assertTrue("No metrics collection expected but " + metrics, metrics.isEmpty());
}, 5);
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method schedule_thenCancelAndGet.
@Test(expected = CancellationException.class)
public void schedule_thenCancelAndGet() throws Exception {
int delay = 1;
String taskName = "Test";
HazelcastInstance[] instances = createClusterWithCount(2);
IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
IScheduledFuture<Double> first = executorService.schedule(named(taskName, new PlainCallableTask()), delay, MINUTES);
first.cancel(false);
first.get();
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method scheduled_executor_does_not_collect_statistics_when_stats_disabled.
@Test
public void scheduled_executor_does_not_collect_statistics_when_stats_disabled() throws Exception {
// run task
Config config = smallInstanceConfig();
config.getScheduledExecutorConfig(ANY_EXECUTOR_NAME).setStatisticsEnabled(false);
HazelcastInstance[] instances = createClusterWithCount(2, config);
IScheduledExecutorService s = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
Map<Member, IScheduledFuture<Double>> futureMap = s.scheduleOnAllMembers(new OneSecondSleepingTask(), 0, SECONDS);
Set<Map.Entry<Member, IScheduledFuture<Double>>> entries = futureMap.entrySet();
for (Map.Entry<Member, IScheduledFuture<Double>> entry : entries) {
entry.getValue().get();
}
assertTrueAllTheTime(() -> {
// collect metrics
Map<String, List<Long>> metrics = collectMetrics(SCHEDULED_EXECUTOR_PREFIX, instances);
// check results
assertTrue("No metrics collection expected but " + metrics, metrics.isEmpty());
}, 5);
}
Aggregations