Search in sources :

Example 6 with ExpirationTime

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());
}
Also used : ExpirationTime(org.kie.kogito.jobs.ExpirationTime) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 7 with ExpirationTime

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());
}
Also used : ZonedDateTime(java.time.ZonedDateTime) ExpirationTime(org.kie.kogito.jobs.ExpirationTime) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 8 with ExpirationTime

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());
}
Also used : ExpirationTime(org.kie.kogito.jobs.ExpirationTime) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 9 with ExpirationTime

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()));
}
Also used : ExpirationTime(org.kie.kogito.jobs.ExpirationTime) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 10 with ExpirationTime

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());
}
Also used : ExpirationTime(org.kie.kogito.jobs.ExpirationTime) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Aggregations

ExpirationTime (org.kie.kogito.jobs.ExpirationTime)11 Map (java.util.Map)8 Test (org.junit.jupiter.api.Test)8 ZonedDateTime (java.time.ZonedDateTime)3 KogitoNodeInstance (org.kie.kogito.internal.process.runtime.KogitoNodeInstance)2 ExactExpirationTime (org.kie.kogito.jobs.ExactExpirationTime)2 JobsService (org.kie.kogito.jobs.JobsService)2 ProcessInstanceJobDescription (org.kie.kogito.jobs.ProcessInstanceJobDescription)2 ChronoUnit (java.time.temporal.ChronoUnit)1 Date (java.util.Date)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 InternalProcessRuntime (org.jbpm.process.instance.InternalProcessRuntime)1 ASYNC_WAITING (org.jbpm.ruleflow.core.Metadata.ASYNC_WAITING)1 NodeImpl (org.jbpm.workflow.core.impl.NodeImpl)1 NodeInstanceContainer (org.jbpm.workflow.instance.NodeInstanceContainer)1 EventNodeInstance (org.jbpm.workflow.instance.node.EventNodeInstance)1 Node (org.kie.api.definition.process.Node)1 NodeInstance (org.kie.api.runtime.process.NodeInstance)1 KogitoEventListener (org.kie.kogito.internal.process.event.KogitoEventListener)1