Search in sources :

Example 1 with SchedulableTask

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));
}
Also used : SchedulableTask(com.enonic.xp.impl.scheduler.distributed.SchedulableTask) Test(org.junit.jupiter.api.Test)

Example 2 with SchedulableTask

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());
}
Also used : SchedulableTask(com.enonic.xp.impl.scheduler.distributed.SchedulableTask) Test(org.junit.jupiter.api.Test)

Example 3 with SchedulableTask

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);
}
Also used : SchedulableTask(com.enonic.xp.impl.scheduler.distributed.SchedulableTask) Test(org.junit.jupiter.api.Test)

Example 4 with SchedulableTask

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());
}
Also used : SchedulableTask(com.enonic.xp.impl.scheduler.distributed.SchedulableTask) Test(org.junit.jupiter.api.Test)

Example 5 with SchedulableTask

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);
}
Also used : SchedulableTask(com.enonic.xp.impl.scheduler.distributed.SchedulableTask) Test(org.junit.jupiter.api.Test)

Aggregations

SchedulableTask (com.enonic.xp.impl.scheduler.distributed.SchedulableTask)13 Test (org.junit.jupiter.api.Test)12