use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.
the class PerProcessInstanceRuntimeManagerTest method testSignalStartMultipleProcesses.
@Test
public void testSignalStartMultipleProcesses() {
// independent = true
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-SignalMultipleProcessesMain.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-SignalMultipleProcessesOne.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-SignalMultipleProcessesTwo.bpmn2"), ResourceType.BPMN2).get();
manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(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 == 2);
Map<String, Object> inputParams = new HashMap<String, Object>();
inputParams.put("processInput", "MyCoolParam");
ksession.startProcess("main-process", inputParams);
AuditService auditService = runtime.getAuditService();
List<? extends ProcessInstanceLog> processInstanceLogs = auditService.findProcessInstances();
assertEquals(3, processInstanceLogs.size());
manager.close();
}
use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.
the class PerProcessInstanceRuntimeManagerTest method testExecuteCompleteWorkItemOnInvalidSessionWithPersistence.
@Test
public void testExecuteCompleteWorkItemOnInvalidSessionWithPersistence() {
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTask.bpmn2"), ResourceType.BPMN2).get();
manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
assertNotNull(manager);
// ksession for process instance #1
// 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 == 2);
// ksession for process instance #2
// since there is no process instance yet we need to get new session
RuntimeEngine runtime2 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession2 = runtime2.getKieSession();
assertNotNull(ksession2);
long ksession2Id = ksession2.getIdentifier();
assertTrue(ksession2Id == 3);
ProcessInstance pi1 = ksession.startProcess("UserTask");
ProcessInstance pi2 = ksession2.startProcess("UserTask");
// both processes started
assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
assertEquals(ProcessInstance.STATE_ACTIVE, pi2.getState());
runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi1.getId()));
ksession = runtime.getKieSession();
assertEquals(ksession1Id, ksession.getIdentifier());
ksession.getWorkItemManager().completeWorkItem(1, null);
manager.disposeRuntimeEngine(runtime);
// since process is completed now session should not be there any more
try {
manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi1.getId())).getKieSession();
fail("Session for this (" + pi1.getId() + ") process instance is no more accessible");
} catch (RuntimeException e) {
}
try {
ksession.getWorkItemManager().completeWorkItem(2, null);
fail("Invalid session was used for (" + pi2.getId() + ") process instance");
} catch (RuntimeException e) {
}
manager.close();
}
use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.
the class PerProcessInstanceRuntimeManagerTest method testTimersOnMultiInstanceSubprocess.
@Test(timeout = 20000)
public void testTimersOnMultiInstanceSubprocess() throws Exception {
final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("MIDelayTimer", 2);
final List<Long> timerExpirations = new ArrayList<Long>();
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
listeners.add(new DefaultProcessEventListener() {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
if (event.getNodeInstance().getNodeName().equals("MIDebugScript")) {
timerExpirations.add(event.getProcessInstance().getId());
}
}
});
listeners.add(countDownListener);
return listeners;
}
}).addAsset(ResourceFactory.newClassPathResource("BPMN2-MultiInstanceProcess.bpmn2"), ResourceType.BPMN2).get();
manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
assertNotNull(manager);
// ksession for process instance #1
// since there is no process instance yet we need to get new session
RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession = runtime.getKieSession();
ProcessInstance pi1 = ksession.startProcess("defaultPackage.MultiInstanceProcess");
// both processes started
assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
manager.disposeRuntimeEngine(runtime);
// wait a bit for some timers to fire
countDownListener.waitTillCompleted();
// now make sure nothing else is triggered
countDownListener.reset(4);
countDownListener.waitTillCompleted(3000);
assertEquals(2, timerExpirations.size());
runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi1.getId()));
ksession = runtime.getKieSession();
pi1 = ksession.getProcessInstance(pi1.getId());
assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
ksession.abortProcessInstance(pi1.getId());
manager.disposeRuntimeEngine(runtime);
manager.close();
}
use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.
the class PerProcessInstanceRuntimeManagerTest method testCreationOfSessionWithCustomTaskListener.
@Test
public void testCreationOfSessionWithCustomTaskListener() {
final List<Long> addedTasks = new ArrayList<Long>();
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultInMemoryBuilder().userGroupCallback(userGroupCallback).entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTask.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public List<TaskLifeCycleEventListener> getTaskListeners() {
List<TaskLifeCycleEventListener> listeners = super.getTaskListeners();
listeners.add(new DefaultTaskEventListener() {
@Override
public void afterTaskAddedEvent(TaskEvent event) {
addedTasks.add(event.getTask().getId());
}
});
return listeners;
}
}).get();
manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
assertNotNull(manager);
// ksession for process instance #1
// 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);
// FIXME quick hack to overcome problems with same pi ids when not using persistence
ksession.startProcess("ScriptTask");
// ksession for process instance #2
// since there is no process instance yet we need to get new session
RuntimeEngine runtime2 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession2 = runtime2.getKieSession();
assertNotNull(ksession2);
long ksession2Id = ksession2.getIdentifier();
assertTrue(ksession2Id == 2);
ProcessInstance pi1 = ksession.startProcess("UserTask");
ProcessInstance pi2 = ksession2.startProcess("UserTask");
// both processes started
assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
assertEquals(ProcessInstance.STATE_ACTIVE, pi2.getState());
runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi1.getId()));
ksession = runtime.getKieSession();
assertEquals(ksession1Id, ksession.getIdentifier());
runtime2 = manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi2.getId()));
ksession2 = runtime2.getKieSession();
assertEquals(ksession2Id, ksession2.getIdentifier());
assertEquals(2, addedTasks.size());
manager.close();
}
use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.
the class PerProcessInstanceRuntimeManagerTest method testReusableSubprocessWithWaitForCompletionFalse.
@Test(timeout = 10000)
public void testReusableSubprocessWithWaitForCompletionFalse() throws Exception {
final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("SLATimer", 1);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("reusable-subprocess/parentprocess.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("reusable-subprocess/subprocess.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
listeners.add(countDownListener);
return listeners;
}
}).get();
manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
ksession.startProcess("Project01360830.parentprocess");
countDownListener.waitTillCompleted();
manager.disposeRuntimeEngine(runtime);
manager.close();
}
Aggregations