use of org.kie.kogito.jobs.ExpirationTime in project kogito-runtimes by kiegroup.
the class DeadlineHelperTest method testLargeRepetition.
@Test
public void testLargeRepetition() {
Collection<DeadlineInfo<Map<String, Object>>> deadlines = DeadlineHelper.parseDeadlines("[subject:more than 1 year]@[R/P1Y3WT1H]");
assertEquals(1, deadlines.size());
DeadlineInfo<Map<String, Object>> deadlineInfo = deadlines.iterator().next();
assertEquals("more than 1 year", deadlineInfo.getNotification().get("subject"));
Collection<ScheduleInfo> scheduling = deadlineInfo.getScheduleInfo();
assertEquals(1, scheduling.size());
ScheduleInfo scheduleInfo = scheduling.iterator().next();
assertEquals(DeadlineHelper.getDuration(Period.ofYears(1).plus(Period.ofWeeks(3)), Duration.ofHours(1)), scheduleInfo.getDuration());
assertEquals(-1, scheduleInfo.getNumRepetitions());
assertNull(scheduleInfo.getEndDate());
assertNull(scheduleInfo.getStartDate());
ExpirationTime time = DeadlineHelper.getExpirationTime(scheduleInfo);
assertEquals(DeadlineHelper.getDuration(Period.ofYears(1).plus(Period.ofWeeks(3)), Duration.ofHours(1)).toMillis(), time.repeatInterval());
assertEquals(-1, time.repeatLimit());
}
use of org.kie.kogito.jobs.ExpirationTime in project kogito-runtimes by kiegroup.
the class DeadlineHelperTest method testRepetitionWithEndDate.
@Test
public void testRepetitionWithEndDate() {
ZonedDateTime future = ZonedDateTime.now().plus(Duration.ofMinutes(2)).plus(Duration.ofSeconds(2));
Collection<DeadlineInfo<Map<String, Object>>> deadlines = DeadlineHelper.parseDeadlines("[subject:5secs]@[R/PT5S/" + future.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME) + "]");
assertEquals(1, deadlines.size());
DeadlineInfo<Map<String, Object>> deadlineInfo = deadlines.iterator().next();
assertEquals("5secs", deadlineInfo.getNotification().get("subject"));
Collection<ScheduleInfo> scheduling = deadlineInfo.getScheduleInfo();
assertEquals(1, scheduling.size());
ScheduleInfo scheduleInfo = scheduling.iterator().next();
assertEquals(Duration.ofSeconds(5), scheduleInfo.getDuration());
assertEquals(-1, scheduleInfo.getNumRepetitions());
assertEqualsDate(future, scheduleInfo.getEndDate());
assertNull(scheduleInfo.getStartDate());
ExpirationTime time = DeadlineHelper.getExpirationTime(scheduleInfo);
assertEquals(5000L, time.repeatInterval());
assertEquals(24, time.repeatLimit());
assertTrue(ZonedDateTime.now().plus(Duration.ofSeconds(5)).isAfter(time.get()), "Date is " + time.get());
}
use of org.kie.kogito.jobs.ExpirationTime in project kogito-runtimes by kiegroup.
the class DeadlineHelperTest method testExactDate.
@Test
public void testExactDate() {
Collection<DeadlineInfo<Map<String, Object>>> deadlines = DeadlineHelper.parseDeadlines("[subject:exact date]@[2021-03-18T18:55:01+01:00]");
assertEquals(1, deadlines.size());
DeadlineInfo<Map<String, Object>> deadlineInfo = deadlines.iterator().next();
assertEquals("exact date", deadlineInfo.getNotification().get("subject"));
Collection<ScheduleInfo> scheduling = deadlineInfo.getScheduleInfo();
assertEquals(1, scheduling.size());
ScheduleInfo scheduleInfo = scheduling.iterator().next();
assertNull(scheduleInfo.getDuration());
assertEquals(0, scheduleInfo.getNumRepetitions());
assertEquals(ZonedDateTime.parse("2021-03-18T18:55:01+01:00"), scheduleInfo.getEndDate());
assertNull(scheduleInfo.getStartDate());
ExpirationTime time = DeadlineHelper.getExpirationTime(scheduleInfo);
assertNull(time.repeatInterval());
assertEquals(0, time.repeatLimit());
assertEqualsDate(ZonedDateTime.parse("2021-03-18T18:55:01+01:00"), time.get());
}
use of org.kie.kogito.jobs.ExpirationTime in project kogito-runtimes by kiegroup.
the class DeadlineHelperTest method testRepetition.
@Test
public void testRepetition() {
Collection<DeadlineInfo<Map<String, Object>>> deadlines = DeadlineHelper.parseDeadlines("[subject:5secs|body:NotCompleted repeated notification every 5secs]@[R/PT5S]");
assertEquals(1, deadlines.size());
DeadlineInfo<Map<String, Object>> deadlineInfo = deadlines.iterator().next();
assertEquals("5secs", deadlineInfo.getNotification().get("subject"));
assertEquals("NotCompleted repeated notification every 5secs", deadlineInfo.getNotification().get("body"));
Collection<ScheduleInfo> scheduling = deadlineInfo.getScheduleInfo();
assertEquals(1, scheduling.size());
ScheduleInfo scheduleInfo = scheduling.iterator().next();
assertEquals(Duration.ofSeconds(5), scheduleInfo.getDuration());
assertEquals(-1, scheduleInfo.getNumRepetitions());
assertNull(scheduleInfo.getEndDate());
assertNull(scheduleInfo.getStartDate());
ExpirationTime time = DeadlineHelper.getExpirationTime(scheduleInfo);
assertEquals(5000L, time.repeatInterval());
assertEquals(-1, time.repeatLimit());
assertTrue(ZonedDateTime.now().plus(Duration.ofSeconds(5)).isAfter(time.get()));
}
use of org.kie.kogito.jobs.ExpirationTime in project kogito-runtimes by kiegroup.
the class DeadlineHelperTest method testRepetitionStartEndDate.
@Test
public void testRepetitionStartEndDate() {
Collection<DeadlineInfo<Map<String, Object>>> deadlines = DeadlineHelper.parseDeadlines("[subject:5secs]@[R1/2021-03-18T18:55:01+01:00/2021-03-18T18:55:06+01:00]");
assertEquals(1, deadlines.size());
DeadlineInfo<Map<String, Object>> deadlineInfo = deadlines.iterator().next();
assertEquals("5secs", deadlineInfo.getNotification().get("subject"));
Collection<ScheduleInfo> scheduling = deadlineInfo.getScheduleInfo();
assertEquals(1, scheduling.size());
ScheduleInfo scheduleInfo = scheduling.iterator().next();
assertEquals(1, scheduleInfo.getNumRepetitions());
assertEquals(ZonedDateTime.parse("2021-03-18T18:55:01+01:00"), scheduleInfo.getStartDate());
assertEquals(ZonedDateTime.parse("2021-03-18T18:55:06+01:00"), scheduleInfo.getEndDate());
assertNull(scheduleInfo.getDuration());
ExpirationTime time = DeadlineHelper.getExpirationTime(scheduleInfo);
assertEquals(5000L, time.repeatInterval());
assertEquals(1, time.repeatLimit());
assertEqualsDate(ZonedDateTime.parse("2021-03-18T18:55:01+01:00"), time.get());
}
Aggregations