use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method schedule_withNegativeDelay.
@Test
public void schedule_withNegativeDelay() throws Exception {
int delay = -2;
double expectedResult = 25.0;
HazelcastInstance[] instances = createClusterWithCount(2);
IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
IScheduledFuture<Double> future = executorService.schedule(new PlainCallableTask(), delay, SECONDS);
double result = future.get();
assertEquals(expectedResult, result, 0);
assertTrue(future.isDone());
assertFalse(future.isCancelled());
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method scheduleOnMember.
@Test
public void scheduleOnMember() throws Exception {
int delay = 1;
HazelcastInstance[] instances = createClusterWithCount(2);
IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
MemberImpl member = getNodeEngineImpl(instances[0]).getLocalMember();
IScheduledFuture<Double> future = executorService.scheduleOnMember(new PlainCallableTask(), member, delay, SECONDS);
assertTrue(future.getHandler().isAssignedToMember());
assertEquals(25.0, future.get(), 0);
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method capacity_whenAutoDisposable_Callable.
@Test
public void capacity_whenAutoDisposable_Callable() throws Exception {
String schedulerName = ANY_EXECUTOR_NAME;
int capacity = 10;
ScheduledExecutorConfig sec = new ScheduledExecutorConfig().setName(schedulerName).setDurability(1).setPoolSize(1).setCapacity(capacity);
Config config = new Config().addScheduledExecutorConfig(sec);
HazelcastInstance[] instances = createClusterWithCount(1, config);
IScheduledExecutorService service = instances[0].getScheduledExecutorService(schedulerName);
String keyOwner = "hitSamePartitionToCheckCapacity";
List<IScheduledFuture<Double>> futures = new ArrayList<>();
for (int i = 0; i < capacity; i++) {
Callable<Double> command = autoDisposable(new PlainCallableTask());
IScheduledFuture<Double> future = service.scheduleOnKeyOwner(command, keyOwner, 0, SECONDS);
futures.add(future);
}
futures.forEach(this::assertTaskHasBeenDestroyedEventually);
for (int i = 0; i < capacity; i++) {
service.scheduleOnKeyOwner(autoDisposable(new PlainCallableTask()), keyOwner, 0, TimeUnit.SECONDS);
}
// no exceptions thrown
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method schedule_thenCancelInterrupted.
@Test(expected = UnsupportedOperationException.class)
public void schedule_thenCancelInterrupted() {
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(true);
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method scheduled_executor_collects_statistics_when_stats_enabled.
@Test
public void scheduled_executor_collects_statistics_when_stats_enabled() throws Exception {
// run task
Config config = smallInstanceConfig();
config.getScheduledExecutorConfig(ANY_EXECUTOR_NAME).setStatisticsEnabled(true);
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();
}
assertTrueEventually(() -> {
// collect metrics
Map<String, List<Long>> metrics = collectMetrics(SCHEDULED_EXECUTOR_PREFIX, instances);
// check results
assertMetricsCollected(metrics, 1000, 0, 1, 1, 0, 1, 0);
});
}
Aggregations