use of org.kie.kogito.internal.process.event.KogitoProcessEventListener in project kogito-runtimes by kiegroup.
the class SLAComplianceTest method testSLAonProcessViolatedNoTracking.
@Test
public void testSLAonProcessViolatedNoTracking() throws Exception {
CountDownLatch latch = new CountDownLatch(1);
final KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() {
@Override
public void afterSLAViolated(SLAViolatedEvent event) {
latch.countDown();
}
};
kruntime = createKogitoProcessRuntime("BPMN2-UserTaskWithSLA.bpmn2");
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
kruntime.getProcessEventManager().addEventListener(listener);
kruntime.getKieRuntime().getEnvironment().set("SLATimerMode", "false");
KogitoProcessInstance processInstance = kruntime.startProcess("UserTask");
assertEquals(KogitoProcessInstance.STATE_ACTIVE, processInstance.getState());
KogitoWorkItem workItem = workItemHandler.getWorkItem();
assertNotNull(workItem);
assertEquals("john", workItem.getParameter("ActorId"));
boolean slaViolated = latch.await(5, TimeUnit.SECONDS);
assertFalse(slaViolated, "SLA should not violated by timer");
processInstance = kruntime.getProcessInstance(processInstance.getStringId());
assertEquals(KogitoProcessInstance.STATE_ACTIVE, processInstance.getState());
int slaCompliance = getSLAComplianceForProcessInstance(processInstance);
assertEquals(KogitoProcessInstance.SLA_PENDING, slaCompliance);
kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null);
assertProcessInstanceFinished(processInstance, kruntime);
slaCompliance = getSLAComplianceForProcessInstance(processInstance);
assertEquals(KogitoProcessInstance.SLA_VIOLATED, slaCompliance);
}
use of org.kie.kogito.internal.process.event.KogitoProcessEventListener in project kogito-runtimes by kiegroup.
the class ErrorEventTest method testEventSubprocessErrorWithOutErrorCode.
@Test
public void testEventSubprocessErrorWithOutErrorCode() throws Exception {
kruntime = createKogitoProcessRuntime("subprocess/EventSubprocessErrorHandlingWithOutErrorCode.bpmn2");
final List<String> executednodes = new ArrayList<>();
KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
if (event.getNodeInstance().getNodeName().equals("Script2")) {
executednodes.add(((KogitoNodeInstance) event.getNodeInstance()).getStringId());
}
}
};
kruntime.getProcessEventManager().addEventListener(listener);
KogitoProcessInstance processInstance = kruntime.startProcess("order-fulfillment-bpm.ccc");
assertProcessInstanceFinished(processInstance, kruntime);
assertNodeTriggered(processInstance.getStringId(), "start", "Script1", "starterror", "Script2", "end2", "eventsubprocess");
assertProcessVarValue(processInstance, "CapturedException", "java.lang.RuntimeException: XXX");
assertEquals(1, executednodes.size());
}
use of org.kie.kogito.internal.process.event.KogitoProcessEventListener in project kogito-runtimes by kiegroup.
the class IntermediateEventTest method runTestEventSubprocessSignal.
public void runTestEventSubprocessSignal(String processFile, String[] completedNodes) throws Exception {
kruntime = createKogitoProcessRuntime(processFile);
final List<String> executednodes = new ArrayList<>();
KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
if (event.getNodeInstance().getNodeName().equals("sub-script")) {
executednodes.add(((KogitoNodeInstance) event.getNodeInstance()).getStringId());
}
}
};
kruntime.getProcessEventManager().addEventListener(listener);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
KogitoProcessInstance processInstance = kruntime.startProcess("BPMN2-EventSubprocessSignal");
assertProcessInstanceActive(processInstance);
kruntime.getProcessEventManager().addEventListener(listener);
Set<EventDescription<?>> eventDescriptions = processInstance.getEventDescriptions();
assertThat(eventDescriptions).hasSize(2).extracting("event").contains("MySignal", "workItemCompleted");
assertThat(eventDescriptions).extracting("eventType").contains("signal", "workItem");
assertThat(eventDescriptions).extracting("processInstanceId").contains(processInstance.getStringId());
kruntime.signalEvent("MySignal", null, processInstance.getStringId());
assertProcessInstanceActive(processInstance);
kruntime.signalEvent("MySignal", null);
assertProcessInstanceActive(processInstance);
kruntime.signalEvent("MySignal", null);
assertProcessInstanceActive(processInstance);
kruntime.signalEvent("MySignal", null);
assertProcessInstanceActive(processInstance);
KogitoWorkItem workItem = workItemHandler.getWorkItem();
assertThat(workItem).isNotNull();
kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null);
assertProcessInstanceFinished(processInstance, kruntime);
assertNodeTriggered(processInstance.getStringId(), completedNodes);
assertThat(executednodes.size()).isEqualTo(4);
}
use of org.kie.kogito.internal.process.event.KogitoProcessEventListener in project kogito-runtimes by kiegroup.
the class IntermediateEventTest method testEventSubprocessMessage.
@Test
public void testEventSubprocessMessage() throws Exception {
kruntime = createKogitoProcessRuntime("BPMN2-EventSubprocessMessage.bpmn2");
final List<String> executednodes = new ArrayList<>();
KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
if (event.getNodeInstance().getNodeName().equals("Script Task 1")) {
executednodes.add(((KogitoNodeInstance) event.getNodeInstance()).getStringId());
}
}
};
kruntime.getProcessEventManager().addEventListener(listener);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
KogitoProcessInstance processInstance = kruntime.startProcess("BPMN2-EventSubprocessMessage");
assertProcessInstanceActive(processInstance);
Set<EventDescription<?>> eventDescriptions = processInstance.getEventDescriptions();
assertThat(eventDescriptions).hasSize(2).extracting("event").contains("Message-HelloMessage", "workItemCompleted");
assertThat(eventDescriptions).extracting("eventType").contains("signal", "workItem");
assertThat(eventDescriptions).extracting("processInstanceId").contains(processInstance.getStringId());
kruntime.getProcessEventManager().addEventListener(listener);
kruntime.signalEvent("Message-HelloMessage", null, processInstance.getStringId());
kruntime.signalEvent("Message-HelloMessage", null);
kruntime.signalEvent("Message-HelloMessage", null);
kruntime.signalEvent("Message-HelloMessage", null);
kruntime.getProcessInstance(processInstance.getStringId());
kruntime.getProcessInstance(processInstance.getStringId());
kruntime.getProcessInstance(processInstance.getStringId());
kruntime.getProcessInstance(processInstance.getStringId());
KogitoWorkItem workItem = workItemHandler.getWorkItem();
assertThat(workItem).isNotNull();
kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null);
assertProcessInstanceFinished(processInstance, kruntime);
assertNodeTriggered(processInstance.getStringId(), "start", "User Task 1", "end", "Sub Process 1", "start-sub", "Script Task 1", "end-sub");
assertThat(executednodes.size()).isEqualTo(4);
}
use of org.kie.kogito.internal.process.event.KogitoProcessEventListener in project kogito-runtimes by kiegroup.
the class KogitoProcessEventSupportImpl method fireTaskNotification.
private void fireTaskNotification(KogitoProcessInstance instance, HumanTaskWorkItem workItem, Map<String, Object> notification, DeadlineType type, KieRuntime kruntime) {
final HumanTaskDeadlineEvent event = new HumanTaskDeadlineEventImpl(instance, workItem, notification, type, kruntime);
unitOfWorkManager.currentUnitOfWork().intercept(WorkUnit.create(event, e -> notifyAllListeners(event, KogitoProcessEventListener::onHumanTaskDeadline)));
}
Aggregations