use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceSlowTest method scheduleRandomPartitions_getAllScheduled_durable.
@Test
public void scheduleRandomPartitions_getAllScheduled_durable() throws Exception {
ScheduledExecutorConfig scheduledExecutorConfig = new ScheduledExecutorConfig().setName("s").setDurability(2);
Config config = new Config().setProperty("hazelcast.partition.count", "10").addScheduledExecutorConfig(scheduledExecutorConfig);
HazelcastInstance[] instances = createClusterWithCount(4, config);
IScheduledExecutorService s = getScheduledExecutor(instances, "s");
int expectedTotal = 11;
IScheduledFuture[] futures = new IScheduledFuture[expectedTotal];
for (int i = 0; i < expectedTotal; i++) {
futures[i] = s.schedule(new PlainCallableTask(i), 0, SECONDS);
}
instances[1].shutdown();
assertEquals(expectedTotal, countScheduledTasksOn(s), 0);
// verify all tasks
for (int i = 0; i < expectedTotal; i++) {
assertEquals(25.0 + i, futures[i].get());
}
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceSlowTest method stats_longRunningTask_durable.
@Test
public void stats_longRunningTask_durable() throws Exception {
HazelcastInstance[] instances = createClusterWithCount(4);
String key = generateKeyOwnedBy(instances[1]);
ICountDownLatch firstLatch = instances[0].getCPSubsystem().getCountDownLatch("firstLatch");
firstLatch.trySetCount(2);
ICountDownLatch lastLatch = instances[0].getCPSubsystem().getCountDownLatch("lastLatch");
lastLatch.trySetCount(6);
IScheduledExecutorService executorService = getScheduledExecutor(instances, "s");
IScheduledFuture future = executorService.scheduleOnKeyOwnerAtFixedRate(new ICountdownLatchRunnableTask("firstLatch", "lastLatch"), key, 0, 10, SECONDS);
firstLatch.await(12, SECONDS);
instances[1].getLifecycleService().shutdown();
lastLatch.await(70, SECONDS);
// wait for run-cycle to finish before cancelling, in order for stats to get updated
sleepSeconds(4);
future.cancel(false);
ScheduledTaskStatistics stats = future.getStats();
assertEquals(6, stats.getTotalRuns(), 1);
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceSlowTest method reschedulingAfterMigration_whenCurrentNodePreviouslyOwnedTask.
@Test
public void reschedulingAfterMigration_whenCurrentNodePreviouslyOwnedTask() {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
Config config = new Config();
config.addScheduledExecutorConfig(new ScheduledExecutorConfig("scheduler").setCapacity(1000));
HazelcastInstance first = factory.newHazelcastInstance(config);
int tasksCount = 1000;
final IScheduledExecutorService scheduler = first.getScheduledExecutorService("scheduler");
for (int i = 1; i <= tasksCount; i++) {
scheduler.scheduleAtFixedRate(named(valueOf(i), new EchoTask()), 5, 10, SECONDS);
}
assertTrueEventually(new AllTasksRunningWithinNumOfNodes(scheduler, 1));
// start a second member
HazelcastInstance second = factory.newHazelcastInstance();
waitAllForSafeState(first, second);
assertTrueEventually(new AllTasksRunningWithinNumOfNodes(scheduler, 2));
// kill the second member, tasks should now get rescheduled back in first member
second.getLifecycleService().terminate();
waitAllForSafeState(first);
assertTrueEventually(new AllTasksRunningWithinNumOfNodes(scheduler, 1));
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceSlowTest method schedule_withStatefulRunnable_durable.
@Test
public void schedule_withStatefulRunnable_durable() throws Exception {
HazelcastInstance[] instances = createClusterWithCount(4);
IScheduledExecutorService executorService = getScheduledExecutor(instances, "s");
int waitStateSyncPeriodToAvoidPassiveState = 2000;
String key = generateKeyOwnedBy(instances[1]);
ICountDownLatch latch = instances[0].getCPSubsystem().getCountDownLatch("latch");
IAtomicLong runC = instances[0].getCPSubsystem().getAtomicLong("runC");
IAtomicLong loadC = instances[0].getCPSubsystem().getAtomicLong("loadC");
latch.trySetCount(1);
IScheduledFuture future = executorService.scheduleOnKeyOwnerAtFixedRate(new StatefulRunnableTask("latch", "runC", "loadC"), key, 10, 10, SECONDS);
// wait for task to get scheduled and start
latch.await(11, SECONDS);
Thread.sleep(waitStateSyncPeriodToAvoidPassiveState);
instances[1].getLifecycleService().shutdown();
// reset latch - task should be running on a replica now
latch.trySetCount(7);
latch.await(70, SECONDS);
future.cancel(false);
assertEquals(getPartitionService(instances[0]).getPartitionId(key), future.getHandler().getPartitionId());
assertEquals(8, runC.get(), 1);
assertEquals(1, loadC.get());
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method scheduleOnKeyOwner_whenAutoDisposable_thenGet.
@Test
public void scheduleOnKeyOwner_whenAutoDisposable_thenGet() throws Exception {
HazelcastInstance[] instances = createClusterWithCount(2);
IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
String key = generateKeyOwnedBy(instances[1]);
IScheduledFuture<Double> future = executorService.scheduleOnKeyOwner(autoDisposable(new PlainCallableTask()), key, 1, SECONDS);
assertTaskHasBeenDestroyedEventually(future);
}
Aggregations