use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method scheduleOnMemberWithRepetition.
@Test
public void scheduleOnMemberWithRepetition() {
HazelcastInstance[] instances = createClusterWithCount(4);
IScheduledExecutorService s = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
ICountDownLatch latch = instances[0].getCPSubsystem().getCountDownLatch("latch");
latch.trySetCount(4);
Map<Member, IScheduledFuture<Object>> futures = s.scheduleOnAllMembersAtFixedRate(new ICountdownLatchRunnableTask("latch"), 0, 3, SECONDS);
assertOpenEventually(latch);
assertEquals(0, latch.getCount());
assertEquals(4, futures.size());
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method stats_whenMemberOwned.
@Test
public void stats_whenMemberOwned() throws Exception {
double delay = 2.0;
HazelcastInstance[] instances = createClusterWithCount(2);
Member localMember = instances[0].getCluster().getLocalMember();
IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
IScheduledFuture<Double> future = executorService.scheduleOnMember(new PlainCallableTask(), localMember, (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 managedContext_whenLocalExecution.
@Test
public void managedContext_whenLocalExecution() {
HazelcastInstance instance = createHazelcastInstance();
IScheduledExecutorService s = instance.getScheduledExecutorService(ANY_EXECUTOR_NAME);
s.schedule(new PlainCallableTask(), 0, SECONDS);
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method schedule_partitionAware_runnable.
@Test
public void schedule_partitionAware_runnable() {
int delay = 1;
String completionLatchName = "completionLatch";
HazelcastInstance[] instances = createClusterWithCount(2);
ICountDownLatch completionLatch = instances[0].getCPSubsystem().getCountDownLatch(completionLatchName);
completionLatch.trySetCount(1);
IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
Runnable task = new PlainPartitionAwareRunnableTask(completionLatchName);
IScheduledFuture first = executorService.schedule(task, delay, SECONDS);
assertOpenEventually(completionLatch);
ScheduledTaskHandler handler = first.getHandler();
int expectedPartition = getPartitionIdFromPartitionAwareTask(instances[0], (PartitionAware) task);
assertEquals(expectedPartition, handler.getPartitionId());
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method capacity_whenPositiveLimit_afterDisposing_andReplicaPartitionPromotion.
/**
* Make sure disposal of SUSPENDED tasks doesn't release permits
*/
@Test
public void capacity_whenPositiveLimit_afterDisposing_andReplicaPartitionPromotion() throws ExecutionException, InterruptedException {
String schedulerName = ANY_EXECUTOR_NAME;
ScheduledExecutorConfig sec = new ScheduledExecutorConfig().setName(schedulerName).setDurability(1).setPoolSize(1).setCapacity(1).setCapacityPolicy(ScheduledExecutorConfig.CapacityPolicy.PER_PARTITION);
Config config = new Config().addScheduledExecutorConfig(sec);
HazelcastInstance[] instances = createClusterWithCount(2, config);
IScheduledExecutorService service = instances[0].getScheduledExecutorService(schedulerName);
String key = generateKeyOwnedBy(instances[0]);
int keyOwner = getNodeEngineImpl(instances[0]).getPartitionService().getPartitionId(key);
IScheduledFuture future = service.scheduleOnKeyOwner(new PlainCallableTask(), key, 0, TimeUnit.SECONDS);
future.get();
assertCapacityReached(service, key, "Maximum capacity (1) of tasks reached " + "for partition (" + keyOwner + ") and scheduled executor (" + schedulerName + ").");
instances[0].getLifecycleService().shutdown();
waitAllForSafeState(instances[1]);
// Re-assign service & future
service = instances[1].getScheduledExecutorService(schedulerName);
future = service.getScheduledFuture(future.getHandler());
assertCapacityReached(service, key, "Maximum capacity (1) of tasks reached " + "for partition (" + keyOwner + ") and scheduled executor (" + schedulerName + ").");
future.dispose();
service.scheduleOnKeyOwner(new PlainCallableTask(), key, 0, TimeUnit.SECONDS);
assertCapacityReached(service, key, "Maximum capacity (1) of tasks reached " + "for partition (" + keyOwner + ") and scheduled executor (" + schedulerName + ").");
}
Aggregations