use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method capacity_whenNoLimit_perNode.
@Test
public void capacity_whenNoLimit_perNode() {
String schedulerName = ANY_EXECUTOR_NAME;
ScheduledExecutorConfig sec = new ScheduledExecutorConfig().setName(schedulerName).setDurability(1).setPoolSize(1).setCapacity(0);
Config config = new Config().addScheduledExecutorConfig(sec);
HazelcastInstance[] instances = createClusterWithCount(1, config);
IScheduledExecutorService service = instances[0].getScheduledExecutorService(schedulerName);
String keyOwner = "hitSamePartitionToCheckCapacity";
for (int i = 0; i < 101; i++) {
service.scheduleOnKeyOwner(new PlainCallableTask(), keyOwner, 0, TimeUnit.SECONDS);
}
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method getErroneous.
@Test
public void getErroneous() throws Exception {
int delay = 2;
String taskName = "Test";
String completionLatchName = "completionLatch";
HazelcastInstance[] instances = createClusterWithCount(2);
String key = generateKeyOwnedBy(instances[1]);
IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
ICountDownLatch latch = instances[1].getCPSubsystem().getCountDownLatch(completionLatchName);
latch.trySetCount(1);
IScheduledFuture<Double> future = executorService.scheduleOnKeyOwner(named(taskName, new ErroneousCallableTask(completionLatchName)), key, delay, SECONDS);
assertOpenEventually(latch);
expected.expect(ExecutionException.class);
expected.expectCause(new RootCauseMatcher(IllegalStateException.class, "Erroneous task"));
future.get();
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method schedule_andCancel.
@Test
public void schedule_andCancel() {
HazelcastInstance[] instances = createClusterWithCount(2);
ICountDownLatch latch = instances[0].getCPSubsystem().getCountDownLatch("latch");
latch.trySetCount(1);
IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
IScheduledFuture future = executorService.scheduleAtFixedRate(new ICountdownLatchRunnableTask("latch"), 1, 1, SECONDS);
sleepSeconds(5);
assertFalse(future.isCancelled());
assertFalse(future.isDone());
future.cancel(false);
assertTrue(future.isCancelled());
assertTrue(future.isDone());
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method scheduleOnMember_testMemberLostEvent.
@Test
public void scheduleOnMember_testMemberLostEvent() {
int delay = 1;
HazelcastInstance[] instances = createClusterWithCount(2);
Member member = instances[1].getCluster().getLocalMember();
IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
final IScheduledFuture future = executorService.scheduleOnMember(new PlainCallableTask(), member, delay, SECONDS);
instances[1].getLifecycleService().terminate();
assertTrueEventually(() -> {
try {
future.get(0, SECONDS);
fail();
} catch (IllegalStateException ex) {
System.err.println(ex.getMessage());
assertEquals(format("Member with address: %s, holding this scheduled task is not part of this cluster.", future.getHandler().getUuid()), ex.getMessage());
} catch (TimeoutException ex) {
ignore(ex);
}
});
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method capacity_whenPositiveLimit_perNode_afterDisposing_andReplicaPartitionPromotion.
@Test
public void capacity_whenPositiveLimit_perNode_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_NODE);
Config config = new Config().addScheduledExecutorConfig(sec);
HazelcastInstance[] instances = createClusterWithCount(2, config);
IScheduledExecutorService service = instances[0].getScheduledExecutorService(schedulerName);
String key = generateKeyOwnedBy(instances[0]);
IScheduledFuture future = service.scheduleOnKeyOwner(new PlainCallableTask(), key, 0, TimeUnit.SECONDS);
future.get();
assertCapacityReached(service, key, "Maximum capacity (1) of tasks reached for this " + "member 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 this " + "member and scheduled executor (" + schedulerName + ").");
future.dispose();
service.scheduleOnKeyOwner(new PlainCallableTask(), key, 0, TimeUnit.SECONDS);
assertCapacityReached(service, key, "Maximum capacity (1) of tasks reached for this " + "member and scheduled executor (" + schedulerName + ").");
}
Aggregations