Search in sources :

Example 16 with KogitoProcessEventListener

use of org.kie.kogito.internal.process.event.KogitoProcessEventListener in project kogito-runtimes by kiegroup.

the class SLAComplianceTest method testSLAonUserTaskViolated.

@Test
public void testSLAonUserTaskViolated() throws Exception {
    CountDownLatch latch = new CountDownLatch(1);
    final KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() {

        @Override
        public void afterSLAViolated(SLAViolatedEvent event) {
            latch.countDown();
        }
    };
    kruntime = createKogitoProcessRuntime("BPMN2-UserTaskWithSLAOnTask.bpmn2");
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    kruntime.getProcessEventManager().addEventListener(listener);
    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(10, TimeUnit.SECONDS);
    assertTrue(slaViolated, "SLA was not violated while it is expected");
    processInstance = kruntime.getProcessInstance(processInstance.getStringId());
    assertEquals(KogitoProcessInstance.STATE_ACTIVE, processInstance.getState());
    int slaCompliance = getSLAComplianceForProcessInstance(processInstance);
    assertEquals(KogitoProcessInstance.SLA_NA, slaCompliance);
    Collection<KogitoNodeInstance> active = ((KogitoWorkflowProcessInstance) processInstance).getKogitoNodeInstances();
    assertEquals(1, active.size());
    KogitoNodeInstance userTaskNode = active.iterator().next();
    slaCompliance = getSLAComplianceForNodeInstance(processInstance.getStringId(), (org.jbpm.workflow.instance.NodeInstance) userTaskNode, 0);
    assertEquals(KogitoProcessInstance.SLA_VIOLATED, slaCompliance);
    kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null);
    assertProcessInstanceFinished(processInstance, kruntime);
    slaCompliance = getSLAComplianceForProcessInstance(processInstance);
    assertEquals(KogitoProcessInstance.SLA_NA, slaCompliance);
    slaCompliance = getSLAComplianceForNodeInstance(processInstance.getStringId(), (org.jbpm.workflow.instance.NodeInstance) userTaskNode, 1);
    assertEquals(KogitoProcessInstance.SLA_VIOLATED, slaCompliance);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) SLAViolatedEvent(org.kie.api.event.process.SLAViolatedEvent) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) CountDownLatch(java.util.concurrent.CountDownLatch) KogitoWorkflowProcessInstance(org.kie.kogito.internal.process.runtime.KogitoWorkflowProcessInstance) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) KogitoProcessEventListener(org.kie.kogito.internal.process.event.KogitoProcessEventListener) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) Test(org.junit.jupiter.api.Test)

Example 17 with KogitoProcessEventListener

use of org.kie.kogito.internal.process.event.KogitoProcessEventListener in project kogito-runtimes by kiegroup.

the class SLAComplianceTest method testSLAonProcessViolatedExternalTracking.

@Test
public void testSLAonProcessViolatedExternalTracking() 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");
    // simulate external tracking of sla
    kruntime.signalEvent("slaViolation", null, processInstance.getStringId());
    slaViolated = latch.await(10, TimeUnit.SECONDS);
    assertTrue(slaViolated, "SLA was not violated while it is expected");
    processInstance = kruntime.getProcessInstance(processInstance.getStringId());
    assertEquals(KogitoProcessInstance.STATE_ACTIVE, processInstance.getState());
    int slaCompliance = getSLAComplianceForProcessInstance(processInstance);
    assertEquals(KogitoProcessInstance.SLA_VIOLATED, slaCompliance);
    kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null);
    assertProcessInstanceFinished(processInstance, kruntime);
    slaCompliance = getSLAComplianceForProcessInstance(processInstance);
    assertEquals(KogitoProcessInstance.SLA_VIOLATED, slaCompliance);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) KogitoProcessEventListener(org.kie.kogito.internal.process.event.KogitoProcessEventListener) SLAViolatedEvent(org.kie.api.event.process.SLAViolatedEvent) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 18 with KogitoProcessEventListener

use of org.kie.kogito.internal.process.event.KogitoProcessEventListener in project kogito-runtimes by kiegroup.

the class SLAComplianceTest method testSLAonProcessViolated.

@Test
public void testSLAonProcessViolated() 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);
    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(10, TimeUnit.SECONDS);
    assertTrue(slaViolated, "SLA was not violated while it is expected");
    processInstance = kruntime.getProcessInstance(processInstance.getStringId());
    assertEquals(KogitoProcessInstance.STATE_ACTIVE, processInstance.getState());
    int slaCompliance = getSLAComplianceForProcessInstance(processInstance);
    assertEquals(KogitoProcessInstance.SLA_VIOLATED, slaCompliance);
    kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null);
    assertProcessInstanceFinished(processInstance, kruntime);
    slaCompliance = getSLAComplianceForProcessInstance(processInstance);
    assertEquals(KogitoProcessInstance.SLA_VIOLATED, slaCompliance);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) KogitoProcessEventListener(org.kie.kogito.internal.process.event.KogitoProcessEventListener) SLAViolatedEvent(org.kie.api.event.process.SLAViolatedEvent) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 19 with KogitoProcessEventListener

use of org.kie.kogito.internal.process.event.KogitoProcessEventListener in project kogito-runtimes by kiegroup.

the class SLAComplianceTest method testSLAonCatchEventViolated.

@Test
public void testSLAonCatchEventViolated() throws Exception {
    CountDownLatch latch = new CountDownLatch(1);
    final KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() {

        @Override
        public void afterSLAViolated(SLAViolatedEvent event) {
            latch.countDown();
        }
    };
    kruntime = createKogitoProcessRuntime("BPMN2-IntermediateCatchEventSignalWithSLAOnEvent.bpmn2");
    kruntime.getProcessEventManager().addEventListener(listener);
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", new SystemOutWorkItemHandler());
    KogitoProcessInstance processInstance = kruntime.startProcess("IntermediateCatchEvent");
    assertEquals(KogitoProcessInstance.STATE_ACTIVE, processInstance.getState());
    boolean slaViolated = latch.await(5, TimeUnit.SECONDS);
    assertTrue(slaViolated, "SLA should be violated by timer");
    processInstance = kruntime.getProcessInstance(processInstance.getStringId());
    assertEquals(KogitoProcessInstance.STATE_ACTIVE, processInstance.getState());
    Collection<KogitoNodeInstance> active = ((KogitoWorkflowProcessInstance) processInstance).getKogitoNodeInstances();
    assertEquals(1, active.size());
    KogitoNodeInstance eventNode = active.iterator().next();
    kruntime.signalEvent("MyMessage", null, processInstance.getStringId());
    assertProcessInstanceFinished(processInstance, kruntime);
    int slaCompliance = getSLAComplianceForProcessInstance(processInstance);
    assertEquals(KogitoProcessInstance.SLA_NA, slaCompliance);
    slaCompliance = getSLAComplianceForNodeInstance(processInstance.getStringId(), (org.jbpm.workflow.instance.NodeInstance) eventNode, 0);
    assertEquals(KogitoProcessInstance.SLA_VIOLATED, slaCompliance);
    slaCompliance = getSLAComplianceForNodeInstance(processInstance.getStringId(), (org.jbpm.workflow.instance.NodeInstance) eventNode, 1);
    assertEquals(KogitoProcessInstance.SLA_VIOLATED, slaCompliance);
}
Also used : SLAViolatedEvent(org.kie.api.event.process.SLAViolatedEvent) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) CountDownLatch(java.util.concurrent.CountDownLatch) KogitoWorkflowProcessInstance(org.kie.kogito.internal.process.runtime.KogitoWorkflowProcessInstance) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) KogitoProcessEventListener(org.kie.kogito.internal.process.event.KogitoProcessEventListener) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) Test(org.junit.jupiter.api.Test)

Example 20 with KogitoProcessEventListener

use of org.kie.kogito.internal.process.event.KogitoProcessEventListener in project kogito-runtimes by kiegroup.

the class IntermediateEventTest method testEventSubprocessConditional.

@Test
public void testEventSubprocessConditional() throws Exception {
    kruntime = createKogitoProcessRuntime("BPMN2-EventSubprocessConditional.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-EventSubprocessConditional");
    assertProcessInstanceActive(processInstance);
    Person person = new Person();
    person.setName("john");
    kruntime.getKieSession().insert(person);
    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(1);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) ArrayList(java.util.ArrayList) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) KogitoProcessEventListener(org.kie.kogito.internal.process.event.KogitoProcessEventListener) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) InternalKogitoWorkItem(org.kie.kogito.process.workitems.InternalKogitoWorkItem) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) Person(org.jbpm.bpmn2.objects.Person) Test(org.junit.jupiter.api.Test)

Aggregations

KogitoProcessEventListener (org.kie.kogito.internal.process.event.KogitoProcessEventListener)23 Test (org.junit.jupiter.api.Test)21 KogitoProcessInstance (org.kie.kogito.internal.process.runtime.KogitoProcessInstance)21 DefaultKogitoProcessEventListener (org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener)20 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)14 KogitoWorkItem (org.kie.kogito.internal.process.runtime.KogitoWorkItem)14 ProcessNodeLeftEvent (org.kie.api.event.process.ProcessNodeLeftEvent)13 ArrayList (java.util.ArrayList)11 SLAViolatedEvent (org.kie.api.event.process.SLAViolatedEvent)9 CountDownLatch (java.util.concurrent.CountDownLatch)8 KogitoNodeInstance (org.kie.kogito.internal.process.runtime.KogitoNodeInstance)5 KogitoWorkflowProcessInstance (org.kie.kogito.internal.process.runtime.KogitoWorkflowProcessInstance)4 InternalKogitoWorkItem (org.kie.kogito.process.workitems.InternalKogitoWorkItem)4 SignalEvent (org.kie.api.event.process.SignalEvent)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 SystemOutWorkItemHandler (org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler)2 Application (org.kie.kogito.Application)2 EventDescription (org.kie.kogito.process.EventDescription)2 ProcessConfig (org.kie.kogito.process.ProcessConfig)2