use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method getScheduled_whenTaskDecoratedWithNamedTask.
@Test
public void getScheduled_whenTaskDecoratedWithNamedTask() {
int delay = 1;
String taskName = "Test";
PlainCallableTask task = new PlainCallableTask();
HazelcastInstance[] instances = createClusterWithCount(2);
IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
IScheduledFuture<Double> first = executorService.schedule(named(taskName, task), delay, SECONDS);
ScheduledTaskHandler handler = first.getHandler();
IScheduledFuture<Double> copy = executorService.getScheduledFuture(handler);
assertEquals(first.getHandler(), copy.getHandler());
assertEquals(copy.getHandler().getTaskName(), taskName);
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method schedule_duplicate.
@Test(expected = DuplicateTaskException.class)
public void schedule_duplicate() {
int delay = 1;
String taskName = "Test";
HazelcastInstance[] instances = createClusterWithCount(2);
IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
executorService.schedule(named(taskName, new PlainCallableTask()), delay, SECONDS);
executorService.schedule(named(taskName, new PlainCallableTask()), delay, SECONDS);
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method capacity_whenAutoDisposable_Runnable.
@Test
public void capacity_whenAutoDisposable_Runnable() 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++) {
Runnable command = autoDisposable(new PlainRunnableTask());
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 PlainRunnableTask()), keyOwner, 0, TimeUnit.SECONDS);
}
// no exceptions thrown
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method scheduleOnAllMembers_getAllScheduled.
@Test
public void scheduleOnAllMembers_getAllScheduled() throws Exception {
HazelcastInstance[] instances = createClusterWithCount(3);
IScheduledExecutorService s = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
s.scheduleOnAllMembers(new PlainCallableTask(), 0, SECONDS);
Set<Member> members = instances[0].getCluster().getMembers();
Map<Member, List<IScheduledFuture<Double>>> allScheduled = s.getAllScheduledFutures();
assertEquals(members.size(), allScheduled.size());
for (Member member : members) {
assertEquals(1, allScheduled.get(member).size());
assertEquals(25.0, allScheduled.get(member).get(0).get(), 0);
}
}
use of com.hazelcast.scheduledexecutor.IScheduledExecutorService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method scheduleOnKeyOwner_thenGet.
@Test
public void scheduleOnKeyOwner_thenGet() throws Exception {
HazelcastInstance[] instances = createClusterWithCount(2);
IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
String key = generateKeyOwnedBy(instances[1]);
IScheduledFuture<Double> future = executorService.scheduleOnKeyOwner(new PlainCallableTask(), key, 2, SECONDS);
assertEquals(25.0, future.get(), 0.0);
}
Aggregations