use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method schedule_withStatefulRunnable.
@Test
public void schedule_withStatefulRunnable() {
HazelcastInstance[] instances = createClusterWithCount(4);
IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
ICountDownLatch latch = instances[0].getCPSubsystem().getCountDownLatch("latch");
latch.trySetCount(1);
executorService.schedule(new StatefulRunnableTask("latch", "runC", "loadC"), 2, SECONDS);
assertOpenEventually(latch);
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method scheduleRandomPartitions_getAllScheduled.
@Test
public void scheduleRandomPartitions_getAllScheduled() throws Exception {
HazelcastInstance[] instances = createClusterWithCount(2);
IScheduledExecutorService s = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
int expectedTotal = 11;
IScheduledFuture[] futures = new IScheduledFuture[expectedTotal];
for (int i = 0; i < expectedTotal; i++) {
futures[i] = s.schedule(new PlainCallableTask(i), 0, SECONDS);
}
assertEquals(expectedTotal, countScheduledTasksOn(s), 0);
// dispose 1 task
futures[0].dispose();
// recount
assertEquals(expectedTotal - 1, countScheduledTasksOn(s), 0);
// verify all tasks
for (int i = 1; i < expectedTotal; i++) {
assertEquals(25.0 + i, futures[i].get());
}
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method scheduleOnKeyOwner_getDelay.
@Test
public void scheduleOnKeyOwner_getDelay() {
int delay = 20;
String taskName = "Test";
HazelcastInstance[] instances = createClusterWithCount(2);
Object key = generateKeyOwnedBy(instances[1]);
IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
IScheduledFuture<Double> first = executorService.scheduleOnKeyOwner(named(taskName, new PlainCallableTask()), key, delay, MINUTES);
assertEquals(19, first.getDelay(MINUTES));
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method schedule_getDelay.
@Test
public void schedule_getDelay() {
int delay = 20;
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);
assertEquals(19, first.getDelay(MINUTES));
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method schedule_withMapChanges_durable.
@Test
public void schedule_withMapChanges_durable() {
HazelcastInstance[] instances = createClusterWithCount(2);
IMap<String, Integer> map = instances[1].getMap("map");
map.put("foo", 1);
Object key = generateKeyOwnedBy(instances[0]);
ICountDownLatch startedLatch = instances[1].getCPSubsystem().getCountDownLatch("startedLatch");
ICountDownLatch finishedLatch = instances[1].getCPSubsystem().getCountDownLatch("finishedLatch");
ICountDownLatch waitAfterStartLatch = instances[1].getCPSubsystem().getCountDownLatch("waitAfterStartLatch");
startedLatch.trySetCount(1);
finishedLatch.trySetCount(1);
waitAfterStartLatch.trySetCount(1);
IAtomicLong runEntryCounter = instances[1].getCPSubsystem().getAtomicLong("runEntryCounterName");
IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
executorService.scheduleOnKeyOwner(new ICountdownLatchMapIncrementCallableTask("map", "runEntryCounterName", "startedLatch", "finishedLatch", "waitAfterStartLatch"), key, 0, SECONDS);
assertOpenEventually(startedLatch);
instances[0].getLifecycleService().shutdown();
waitAfterStartLatch.countDown();
assertOpenEventually(finishedLatch);
assertEquals(2, (int) map.get("foo"));
assertEquals(2, runEntryCounter.get());
}
Aggregations