Search in sources :

Example 1 with ProcessInstanceLog

use of org.kie.api.runtime.manager.audit.ProcessInstanceLog in project jbpm by kiegroup.

the class PerProcessInstanceRuntimeManagerTest method testErrorThrowOfChildProcessOnParent.

@Test
public void testErrorThrowOfChildProcessOnParent() {
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("reusable-subprocess/ParentError.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("reusable-subprocess/ChildError.bpmn2"), ResourceType.BPMN2).get();
    manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    ksession.startProcess("ParentError");
    List<? extends ProcessInstanceLog> processInstanceLogs = runtime.getAuditService().findProcessInstances();
    assertEquals(2, processInstanceLogs.size());
    for (ProcessInstanceLog log : processInstanceLogs) {
        if (log.getProcessId().equals("ParentError")) {
            assertEquals(ProcessInstance.STATE_COMPLETED, log.getStatus().intValue());
        } else if (log.getProcessId().equals("ChildError")) {
            assertEquals(ProcessInstance.STATE_ABORTED, log.getStatus().intValue());
        }
    }
    manager.disposeRuntimeEngine(runtime);
    manager.close();
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) KieSession(org.kie.api.runtime.KieSession) ProcessInstanceLog(org.kie.api.runtime.manager.audit.ProcessInstanceLog) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Example 2 with ProcessInstanceLog

use of org.kie.api.runtime.manager.audit.ProcessInstanceLog in project jbpm by kiegroup.

the class PerRequestRuntimeManagerTest method testSignalEventViaRuntimeManager.

@Test
public void testSignalEventViaRuntimeManager() {
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2IntermediateThrowEventScope.bpmn2"), ResourceType.BPMN2).get();
    manager = RuntimeManagerFactory.Factory.get().newPerRequestRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine runtime1 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession1 = runtime1.getKieSession();
    assertNotNull(ksession1);
    ProcessInstance processInstance = ksession1.startProcess("intermediate-event-scope");
    manager.disposeRuntimeEngine(runtime1);
    RuntimeEngine runtime2 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession2 = runtime2.getKieSession();
    assertNotNull(ksession2);
    ProcessInstance processInstance2 = ksession2.startProcess("intermediate-event-scope");
    manager.disposeRuntimeEngine(runtime2);
    runtime1 = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
    List<Long> tasks1 = runtime1.getTaskService().getTasksByProcessInstanceId(processInstance.getId());
    assertNotNull(tasks1);
    assertEquals(1, tasks1.size());
    runtime2 = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance2.getId()));
    List<Long> tasks2 = runtime1.getTaskService().getTasksByProcessInstanceId(processInstance2.getId());
    assertNotNull(tasks2);
    assertEquals(1, tasks2.size());
    Object data = "some data";
    runtime1.getTaskService().claim(tasks1.get(0), "john");
    runtime1.getTaskService().start(tasks1.get(0), "john");
    runtime1.getTaskService().complete(tasks1.get(0), "john", Collections.singletonMap("_output", data));
    manager.disposeRuntimeEngine(runtime1);
    manager.disposeRuntimeEngine(runtime2);
    runtime2 = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance2.getId()));
    AuditService auditService = runtime2.getAuditService();
    ProcessInstanceLog pi1Log = auditService.findProcessInstance(processInstance.getId());
    assertNotNull(pi1Log);
    assertEquals(ProcessInstance.STATE_COMPLETED, pi1Log.getStatus().intValue());
    ProcessInstanceLog pi2Log = auditService.findProcessInstance(processInstance2.getId());
    assertNotNull(pi2Log);
    assertEquals(ProcessInstance.STATE_ACTIVE, pi2Log.getStatus().intValue());
    List<? extends NodeInstanceLog> nLogs = auditService.findNodeInstances(processInstance2.getId(), "_527AF0A7-D741-4062-9953-A05E51479C80");
    assertNotNull(nLogs);
    assertEquals(2, nLogs.size());
    auditService.dispose();
    // dispose session that should not have affect on the session at all
    manager.disposeRuntimeEngine(runtime1);
    manager.disposeRuntimeEngine(runtime2);
    // close manager which will close session maintained by the manager
    manager.close();
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AuditService(org.kie.api.runtime.manager.audit.AuditService) ProcessInstanceLog(org.kie.api.runtime.manager.audit.ProcessInstanceLog) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 3 with ProcessInstanceLog

use of org.kie.api.runtime.manager.audit.ProcessInstanceLog in project jbpm by kiegroup.

the class SignalScopedToRuntimeManagerTest method testSignalEventScopedToOwningRuntimeManager.

private void testSignalEventScopedToOwningRuntimeManager() {
    // start first process instance with first manager
    RuntimeEngine runtime1 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession1 = runtime1.getKieSession();
    assertNotNull(ksession1);
    ProcessInstance processInstance = ksession1.startProcess("IntermediateCatchEventWithRef");
    manager.disposeRuntimeEngine(runtime1);
    // start another process instance of the same process just owned by another manager
    RuntimeEngine runtime2 = manager2.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession2 = runtime2.getKieSession();
    assertNotNull(ksession2);
    ProcessInstance processInstance2 = ksession2.startProcess("IntermediateCatchEventWithRef");
    manager2.disposeRuntimeEngine(runtime2);
    // then signal via first manager, should only signal instances owned by that manager
    runtime1 = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
    ksession1 = runtime1.getKieSession();
    ksession1.signalEvent("Signal1", "first");
    manager.disposeRuntimeEngine(runtime1);
    JPAAuditLogService auditService = new JPAAuditLogService(emf);
    // process instance 1 should be completed by signal
    ProcessInstanceLog pi1Log = auditService.findProcessInstance(processInstance.getId());
    assertNotNull(pi1Log);
    assertEquals(ProcessInstance.STATE_COMPLETED, pi1Log.getStatus().intValue());
    // process instance 2 should still be active
    ProcessInstanceLog pi2Log = auditService.findProcessInstance(processInstance2.getId());
    assertNotNull(pi2Log);
    assertEquals(ProcessInstance.STATE_ACTIVE, pi2Log.getStatus().intValue());
    // then signal via second manager, should only signal instances owned by that manager
    runtime2 = manager2.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance2.getId()));
    ksession2 = runtime2.getKieSession();
    ksession2.signalEvent("Signal1", "second");
    manager2.disposeRuntimeEngine(runtime2);
    pi2Log = auditService.findProcessInstance(processInstance2.getId());
    assertNotNull(pi2Log);
    assertEquals(ProcessInstance.STATE_COMPLETED, pi2Log.getStatus().intValue());
    auditService.dispose();
    // close manager which will close session maintained by the manager
    manager.close();
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) ProcessInstanceLog(org.kie.api.runtime.manager.audit.ProcessInstanceLog)

Example 4 with ProcessInstanceLog

use of org.kie.api.runtime.manager.audit.ProcessInstanceLog in project jbpm by kiegroup.

the class SingletonRuntimeManagerTest method testSignalEventViaRuntimeManager.

@Test
public void testSignalEventViaRuntimeManager() {
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2IntermediateThrowEventScope.bpmn2"), ResourceType.BPMN2).get();
    manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine runtime1 = manager.getRuntimeEngine(EmptyContext.get());
    KieSession ksession1 = runtime1.getKieSession();
    assertNotNull(ksession1);
    ProcessInstance processInstance = ksession1.startProcess("intermediate-event-scope");
    RuntimeEngine runtime2 = manager.getRuntimeEngine(EmptyContext.get());
    KieSession ksession2 = runtime2.getKieSession();
    assertNotNull(ksession2);
    ProcessInstance processInstance2 = ksession2.startProcess("intermediate-event-scope");
    List<Long> tasks1 = runtime1.getTaskService().getTasksByProcessInstanceId(processInstance.getId());
    assertNotNull(tasks1);
    assertEquals(1, tasks1.size());
    List<Long> tasks2 = runtime1.getTaskService().getTasksByProcessInstanceId(processInstance2.getId());
    assertNotNull(tasks2);
    assertEquals(1, tasks2.size());
    Object data = "some data";
    runtime1.getTaskService().claim(tasks1.get(0), "john");
    runtime1.getTaskService().start(tasks1.get(0), "john");
    runtime1.getTaskService().complete(tasks1.get(0), "john", Collections.singletonMap("_output", data));
    AuditService auditService = runtime1.getAuditService();
    ProcessInstanceLog pi1Log = auditService.findProcessInstance(processInstance.getId());
    assertNotNull(pi1Log);
    assertEquals(ProcessInstance.STATE_COMPLETED, pi1Log.getStatus().intValue());
    ProcessInstanceLog pi2Log = auditService.findProcessInstance(processInstance2.getId());
    assertNotNull(pi2Log);
    assertEquals(ProcessInstance.STATE_ACTIVE, pi2Log.getStatus().intValue());
    List<? extends NodeInstanceLog> nLogs = auditService.findNodeInstances(processInstance2.getId(), "_527AF0A7-D741-4062-9953-A05E51479C80");
    assertNotNull(nLogs);
    assertEquals(2, nLogs.size());
    auditService.dispose();
    // dispose session that should not have affect on the session at all
    manager.disposeRuntimeEngine(runtime1);
    manager.disposeRuntimeEngine(runtime2);
    // close manager which will close session maintained by the manager
    manager.close();
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AuditService(org.kie.api.runtime.manager.audit.AuditService) ProcessInstanceLog(org.kie.api.runtime.manager.audit.ProcessInstanceLog) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 5 with ProcessInstanceLog

use of org.kie.api.runtime.manager.audit.ProcessInstanceLog in project jbpm by kiegroup.

the class TimerInitFailureRuntimeManagerTest method testPerCaseRuntimeManager.

@Test(timeout = 10000)
@BMScript(value = "byteman-scripts/failOnRuntimeManagerInitRules.btm")
public void testPerCaseRuntimeManager() throws Exception {
    final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Intermediate Catch Event 1", 1);
    RuntimeEnvironment environment = createEnvironment(countDownListener);
    manager = RuntimeManagerFactory.Factory.get().newPerCaseRuntimeManager(environment, "first");
    assertNotNull(manager);
    RuntimeEngine runtime = manager.getRuntimeEngine(CaseContext.get("CASE-001"));
    KieSession ksession = runtime.getKieSession();
    // start a new process instance
    Map<String, Object> params = new HashMap<>();
    ProcessInstance pi = ksession.startProcess("TimerInitFailure", params);
    assertEquals(ProcessInstance.STATE_ACTIVE, pi.getState());
    manager.disposeRuntimeEngine(runtime);
    countDownListener.waitTillCompleted();
    // User access
    runtime = manager.getRuntimeEngine(CaseContext.get("CASE-001"));
    runtime.getKieSession();
    TaskService taskService = runtime.getTaskService();
    List<TaskSummary> list = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertEquals(1, list.size());
    long taskId = list.get(0).getId();
    taskService.start(taskId, "john");
    taskService.complete(taskId, "john", null);
    manager.disposeRuntimeEngine(runtime);
    runtime = manager.getRuntimeEngine(CaseContext.get("CASE-001"));
    AuditService auditService = runtime.getAuditService();
    ProcessInstanceLog log = auditService.findProcessInstance(pi.getId());
    assertEquals(ProcessInstance.STATE_COMPLETED, log.getStatus().intValue());
    auditService.dispose();
    manager.disposeRuntimeEngine(runtime);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) HashMap(java.util.HashMap) TaskService(org.kie.api.task.TaskService) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AuditService(org.kie.api.runtime.manager.audit.AuditService) ProcessInstanceLog(org.kie.api.runtime.manager.audit.ProcessInstanceLog) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) BMScript(org.jboss.byteman.contrib.bmunit.BMScript)

Aggregations

ProcessInstanceLog (org.kie.api.runtime.manager.audit.ProcessInstanceLog)30 Test (org.junit.Test)24 KieSession (org.kie.api.runtime.KieSession)23 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)19 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)16 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)12 JPAAuditLogService (org.jbpm.process.audit.JPAAuditLogService)11 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)7 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)6 AuditService (org.kie.api.runtime.manager.audit.AuditService)5 TaskSummary (org.kie.api.task.model.TaskSummary)5 TaskService (org.kie.api.task.TaskService)4 BZ (qa.tools.ikeeper.annotation.BZ)3 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Task (org.kie.api.task.model.Task)2 ProcessInstanceLogDeleteBuilder (org.kie.internal.runtime.manager.audit.query.ProcessInstanceLogDeleteBuilder)2 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1