use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method capacity_whenPositiveLimit_pendingTask_andFirstPromotionFails.
@Test
public void capacity_whenPositiveLimit_pendingTask_andFirstPromotionFails() {
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);
config.setProperty(PARTITION_COUNT.getName(), "3");
TestHazelcastInstanceFactory hazelcastInstanceFactory = createHazelcastInstanceFactory();
HazelcastInstance[] instances = hazelcastInstanceFactory.newInstances(config, 3);
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, 1, TimeUnit.HOURS);
future.getStats();
assertCapacityReached(service, key, "Maximum capacity (1) of tasks reached " + "for partition (" + keyOwner + ") and scheduled executor (" + schedulerName + ").");
// Fail promotion
DistributedScheduledExecutorService.FAIL_MIGRATIONS.set(true);
instances[0].getLifecycleService().terminate();
waitAllForSafeState(instances);
service = instances[1].getScheduledExecutorService(schedulerName);
assertCapacityReached(service, key, "Maximum capacity (1) of tasks reached " + "for partition (" + keyOwner + ") and scheduled executor (" + schedulerName + ").");
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method capacity_whenPositiveLimit.
@Test
public void capacity_whenPositiveLimit() {
String schedulerName = ANY_EXECUTOR_NAME;
ScheduledExecutorConfig sec = new ScheduledExecutorConfig().setName(schedulerName).setDurability(1).setPoolSize(1).setCapacity(10).setCapacityPolicy(ScheduledExecutorConfig.CapacityPolicy.PER_PARTITION);
Config config = new Config().addScheduledExecutorConfig(sec);
HazelcastInstance[] instances = createClusterWithCount(1, config);
IScheduledExecutorService service = instances[0].getScheduledExecutorService(schedulerName);
String key = "hitSamePartitionToCheckCapacity";
int keyOwner = getNodeEngineImpl(instances[0]).getPartitionService().getPartitionId(key);
List<IScheduledFuture> futures = new ArrayList<>();
for (int i = 0; i < 10; i++) {
futures.add(service.scheduleOnKeyOwner(new PlainCallableTask(), key, 0, TimeUnit.SECONDS));
}
assertCapacityReached(service, key, "Maximum capacity (10) of tasks reached " + "for partition (" + keyOwner + ") and scheduled executor (" + schedulerName + ").");
// Dispose all
for (IScheduledFuture future : futures) {
future.dispose();
}
// Re-schedule to verify capacity
for (int i = 0; i < 10; i++) {
service.scheduleOnKeyOwner(new PlainCallableTask(), key, 0, TimeUnit.SECONDS);
}
assertCapacityReached(service, key, "Maximum capacity (10) of tasks reached " + "for partition (" + keyOwner + ") and scheduled executor (" + schedulerName + ").");
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method schedule_thenDisposeThenGet.
@Test(expected = StaleTaskException.class)
public void schedule_thenDisposeThenGet() 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, SECONDS);
first.dispose();
first.get();
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method schedule_compareTo.
@Test(expected = UnsupportedOperationException.class)
public void schedule_compareTo() {
HazelcastInstance[] instances = createClusterWithCount(2);
IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
IScheduledFuture<Double> first = executorService.schedule(new PlainCallableTask(), 1, MINUTES);
IScheduledFuture<Double> second = executorService.schedule(new PlainCallableTask(), 2, MINUTES);
assertEquals(-1, first.compareTo(second));
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method schedule_thenGetWithTimeout.
@Test(expected = TimeoutException.class)
public void schedule_thenGetWithTimeout() throws Exception {
int delay = 5;
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.get(2, TimeUnit.SECONDS);
}
Aggregations