use of org.openhab.core.scheduler.SchedulerRunnable in project openhab-core by openhab.
the class CronSchedulerImpl method schedule.
@Override
public ScheduledCompletableFuture<@Nullable Void> schedule(CronJob job, Map<String, Object> config, String cronExpression) {
final CronAdjuster cronAdjuster = new CronAdjuster(cronExpression);
final SchedulerRunnable runnable = () -> job.run(config);
if (cronAdjuster.isReboot()) {
return scheduler.at(runnable, Instant.ofEpochMilli(1));
} else {
return scheduler.schedule(runnable, cronAdjuster);
}
}
use of org.openhab.core.scheduler.SchedulerRunnable in project openhab-core by openhab.
the class SchedulerImplTest method testScheduleException.
@Test
@Timeout(value = 1, unit = TimeUnit.SECONDS)
public void testScheduleException() throws InterruptedException {
Semaphore s = new Semaphore(0);
TestSchedulerWithCounter temporalAdjuster = new TestSchedulerWithCounter();
SchedulerRunnable runnable = () -> {
// Pass a exception not very likely thrown by the scheduler it self to avoid missing real exceptions.
throw new FileNotFoundException("testBeforeTimeoutException");
};
ScheduledCompletableFuture<@Nullable Void> schedule = scheduler.schedule(runnable, temporalAdjuster);
schedule.getPromise().exceptionally(e -> {
if (e instanceof FileNotFoundException) {
s.release();
}
return null;
});
s.acquire(1);
// wait a little longer to see if not more are scheduled.
Thread.sleep(300);
assertEquals(0, s.availablePermits(), "Scheduler should not have released more after cancel");
assertEquals(0, temporalAdjuster.getCount(), "Scheduler should have run 0 time");
}
Aggregations