use of com.enonic.xp.impl.scheduler.distributed.SchedulableTask in project xp by enonic.
the class SchedulerExecutorServiceImplTest method localAlreadyScheduled.
@Test
void localAlreadyScheduled() throws Exception {
setLocal();
final SchedulableTask task = mockTask("task1");
service.schedule(task, 1, TimeUnit.HOURS);
assertThrows(IllegalStateException.class, () -> service.schedule(task, 1, TimeUnit.HOURS));
assertThrows(IllegalStateException.class, () -> service.scheduleAtFixedRate(task, 0, 1, TimeUnit.HOURS));
}
use of com.enonic.xp.impl.scheduler.distributed.SchedulableTask in project xp by enonic.
the class SchedulerExecutorServiceImplTest method localDispose.
@Test
public void localDispose() throws Exception {
setLocal();
final SchedulableTask task = mockTask("task1");
final ScheduledFuture<?> future = service.schedule(task, 1, TimeUnit.SECONDS);
assertFalse(future.isDone());
service.dispose(task.getName());
assertTrue(future.isDone());
assertTrue(service.getAllFutures().isEmpty());
assertTrue(service.get(task.getName()).isEmpty());
}
use of com.enonic.xp.impl.scheduler.distributed.SchedulableTask in project xp by enonic.
the class SchedulerExecutorServiceImplTest method clusterSchedule.
@Test
void clusterSchedule() throws Exception {
setCluster(0);
final SchedulableTask task = mockTask("task1");
service.schedule(task, 1, TimeUnit.SECONDS);
verify(hazelcastExecutorService, times(1)).schedule(task, 1, TimeUnit.SECONDS);
}
use of com.enonic.xp.impl.scheduler.distributed.SchedulableTask in project xp by enonic.
the class SchedulerExecutorServiceImplTest method localDisposeAllDone.
@Test
public void localDisposeAllDone() throws Exception {
setLocal();
final SchedulableTask task1 = mockTask("task1");
final SchedulableTask task2 = mockTask("task2");
service.schedule(task1, 0, TimeUnit.MILLISECONDS);
service.scheduleAtFixedRate(task2, 0, 10, TimeUnit.SECONDS);
Thread.sleep(100);
assertEquals(2, service.getAllFutures().size());
assertTrue(service.get("task1").isPresent());
service.disposeAllDone();
assertEquals(1, service.getAllFutures().size());
assertTrue(service.get("task1").isEmpty());
}
use of com.enonic.xp.impl.scheduler.distributed.SchedulableTask in project xp by enonic.
the class SchedulerExecutorServiceImplTest method localExceptionDoesNotFailExecutor.
@Test
public void localExceptionDoesNotFailExecutor() throws Exception {
setLocal();
final SchedulableTask task1 = mockTask("task1");
final SchedulableTask task2 = mockTask("task2");
doThrow(NullPointerException.class).when(task1).run();
ScheduledFuture<?> future = service.schedule(task1, 1, TimeUnit.MILLISECONDS);
assertThrows(ExecutionException.class, future::get);
doThrow(Error.class).when(task2).run();
future = service.schedule(task2, 1, TimeUnit.MILLISECONDS);
assertThrows(ExecutionException.class, future::get);
}
Aggregations