use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.
the class PerRequestRuntimeManagerTest method testMultiplePerRequestManagerFromSingleThread.
@Test
public void testMultiplePerRequestManagerFromSingleThread() {
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-IntermediateCatchEventSignalWithRef.bpmn2"), ResourceType.BPMN2).get();
manager = RuntimeManagerFactory.Factory.get().newPerRequestRuntimeManager(environment, "first");
assertNotNull(manager);
RuntimeEnvironment environment2 = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTask.bpmn2"), ResourceType.BPMN2).get();
RuntimeManager manager2 = RuntimeManagerFactory.Factory.get().newPerRequestRuntimeManager(environment2, "second");
assertNotNull(manager2);
// start first process instance with first manager
RuntimeEngine runtime1 = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession1 = runtime1.getKieSession();
assertNotNull(ksession1);
ProcessInstance processInstance = ksession1.startProcess("IntermediateCatchEventWithRef");
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
// start another process instance of the same process just owned by another manager
RuntimeEngine runtime2 = manager2.getRuntimeEngine(EmptyContext.get());
KieSession ksession2 = runtime2.getKieSession();
assertNotNull(ksession2);
ProcessInstance processInstance2 = ksession2.startProcess("UserTask");
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance2.getState());
manager.disposeRuntimeEngine(runtime1);
manager.disposeRuntimeEngine(runtime2);
// close manager which will close session maintained by the manager
manager.close();
manager2.close();
}
use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.
the class PerRequestRuntimeManagerTest method testExecuteReusableSubprocess.
@Test
public void testExecuteReusableSubprocess() {
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addEnvironmentEntry("RuntimeEngineEagerInit", "true").addAsset(ResourceFactory.newClassPathResource("BPMN2-CallActivity.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-CallActivitySubProcess.bpmn2"), ResourceType.BPMN2).get();
manager = RuntimeManagerFactory.Factory.get().newPerRequestRuntimeManager(environment);
assertNotNull(manager);
// since there is no process instance yet we need to get new session
RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
long ksession1Id = ksession.getIdentifier();
assertTrue(ksession1Id == 1);
ProcessInstance pi1 = ksession.startProcess("ParentProcess");
assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
ksession.getWorkItemManager().completeWorkItem(1, null);
AuditService logService = runtime.getAuditService();
List<? extends ProcessInstanceLog> logs = logService.findActiveProcessInstances("ParentProcess");
assertNotNull(logs);
assertEquals(0, logs.size());
logs = logService.findActiveProcessInstances("SubProcess");
assertNotNull(logs);
assertEquals(0, logs.size());
logs = logService.findProcessInstances("ParentProcess");
assertNotNull(logs);
assertEquals(1, logs.size());
logs = logService.findProcessInstances("SubProcess");
assertNotNull(logs);
assertEquals(1, logs.size());
manager.disposeRuntimeEngine(runtime);
manager.close();
}
use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.
the class PerRequestRuntimeManagerTest method testCreationOfRuntimeManagerWithinTransaction.
@Test
public void testCreationOfRuntimeManagerWithinTransaction() throws Exception {
System.setProperty("jbpm.tm.jndi.lookup", "java:comp/UserTransaction");
UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
ut.begin();
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2).get();
manager = RuntimeManagerFactory.Factory.get().newPerRequestRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
ksession.startProcess("ScriptTask");
ut.commit();
System.clearProperty("jbpm.tm.jndi.lookup");
}
use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.
the class PerRequestRuntimeManagerTest method testSignalEventWithDeactivate.
@Test
public void testSignalEventWithDeactivate() {
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("events/start-on-event.bpmn"), ResourceType.BPMN2).get();
manager = RuntimeManagerFactory.Factory.get().newPerRequestRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine runtime1 = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession1 = runtime1.getKieSession();
ksession1.signalEvent("SampleEvent", null);
List<? extends ProcessInstanceLog> logs = runtime1.getAuditService().findProcessInstances();
assertEquals(1, logs.size());
manager.disposeRuntimeEngine(runtime1);
((InternalRuntimeManager) manager).deactivate();
runtime1 = manager.getRuntimeEngine(EmptyContext.get());
ksession1 = runtime1.getKieSession();
ksession1.signalEvent("SampleEvent", null);
logs = runtime1.getAuditService().findProcessInstances();
assertEquals(1, logs.size());
manager.disposeRuntimeEngine(runtime1);
((InternalRuntimeManager) manager).activate();
runtime1 = manager.getRuntimeEngine(EmptyContext.get());
ksession1 = runtime1.getKieSession();
ksession1.signalEvent("SampleEvent", null);
logs = runtime1.getAuditService().findProcessInstances();
assertEquals(2, logs.size());
manager.disposeRuntimeEngine(runtime1);
}
use of org.kie.api.runtime.manager.RuntimeEnvironment 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();
}
Aggregations