Search in sources :

Example 6 with SchedulableTask

use of com.enonic.xp.impl.scheduler.distributed.SchedulableTask in project xp by enonic.

the class SchedulerExecutorServiceImplTest method clusterAtFixedRate.

@Test
public void clusterAtFixedRate() throws Exception {
    setCluster(0);
    final SchedulableTask task = mockTask("task1");
    service.scheduleAtFixedRate(task, 0, 10, TimeUnit.MILLISECONDS);
    verify(hazelcastExecutorService, times(1)).scheduleAtFixedRate(task, 0, 10, TimeUnit.MILLISECONDS);
}
Also used : SchedulableTask(com.enonic.xp.impl.scheduler.distributed.SchedulableTask) Test(org.junit.jupiter.api.Test)

Example 7 with SchedulableTask

use of com.enonic.xp.impl.scheduler.distributed.SchedulableTask in project xp by enonic.

the class SchedulerExecutorServiceImplTest method clusterTimeout.

@Test
public void clusterTimeout() throws Exception {
    setCluster(6000);
    final SchedulableTask task = mockTask("task1");
    service.unsetClusteredScheduler(clusteredScheduler);
    assertThrows(RuntimeException.class, () -> service.schedule(task, 1, TimeUnit.MILLISECONDS));
}
Also used : SchedulableTask(com.enonic.xp.impl.scheduler.distributed.SchedulableTask) Test(org.junit.jupiter.api.Test)

Example 8 with SchedulableTask

use of com.enonic.xp.impl.scheduler.distributed.SchedulableTask in project xp by enonic.

the class SchedulerExecutorServiceImplTest method localAtFixedRate.

@Test
public void localAtFixedRate() throws Exception {
    setLocal();
    final SchedulableTask task = mockTask("task1");
    service.scheduleAtFixedRate(task, 0, 10, TimeUnit.MILLISECONDS);
    Thread.sleep(50);
    verify(task, atLeast(4)).run();
}
Also used : SchedulableTask(com.enonic.xp.impl.scheduler.distributed.SchedulableTask) Test(org.junit.jupiter.api.Test)

Example 9 with SchedulableTask

use of com.enonic.xp.impl.scheduler.distributed.SchedulableTask in project xp by enonic.

the class SchedulerExecutorServiceImplTest method localDeactivate.

@Test
public void localDeactivate() throws Exception {
    setLocal();
    final SchedulableTask task = mockTask("task1");
    localScheduler.deactivate();
    assertThrows(RejectedExecutionException.class, () -> service.schedule(task, 1, TimeUnit.MILLISECONDS));
}
Also used : SchedulableTask(com.enonic.xp.impl.scheduler.distributed.SchedulableTask) Test(org.junit.jupiter.api.Test)

Example 10 with SchedulableTask

use of com.enonic.xp.impl.scheduler.distributed.SchedulableTask in project xp by enonic.

the class SchedulerExecutorServiceImplTest method localCancelled.

@Test
void localCancelled() throws Exception {
    setLocal();
    final SchedulableTask task = mockTask("task1");
    final ScheduledFuture<?> future = service.scheduleAtFixedRate(task, 100, 10000, TimeUnit.MILLISECONDS);
    future.cancel(true);
    Thread.sleep(200);
    verify(task, never()).run();
}
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