Search in sources :

Example 1 with CronAdjuster

use of org.openhab.core.scheduler.CronAdjuster in project openhab-core by openhab.

the class CronAdjusterTest method testCronExpression.

@ParameterizedTest
@MethodSource("arguments")
@Timeout(value = 2, unit = TimeUnit.SECONDS)
public void testCronExpression(String in, String cron, String[] outs) {
    final CronAdjuster cronAdjuster = new CronAdjuster(cron);
    Temporal ldt = LocalDateTime.parse(in);
    for (final String out : outs) {
        ldt = ldt.with(cronAdjuster);
        assertThat("CronAdjuster did return expected next cron string for expression: " + cron, ldt.toString(), equalTo(out));
    }
}
Also used : CronAdjuster(org.openhab.core.scheduler.CronAdjuster) Temporal(java.time.temporal.Temporal) Timeout(org.junit.jupiter.api.Timeout) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 2 with CronAdjuster

use of org.openhab.core.scheduler.CronAdjuster 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);
    }
}
Also used : CronAdjuster(org.openhab.core.scheduler.CronAdjuster) SchedulerRunnable(org.openhab.core.scheduler.SchedulerRunnable)

Aggregations

CronAdjuster (org.openhab.core.scheduler.CronAdjuster)2 Temporal (java.time.temporal.Temporal)1 Timeout (org.junit.jupiter.api.Timeout)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1 SchedulerRunnable (org.openhab.core.scheduler.SchedulerRunnable)1