use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class PerCaseRuntimeManagerTest method testExecuteReusableSubprocess.
@Test
public void testExecuteReusableSubprocess() {
final Set<Long> ksessionUsed = new HashSet<Long>();
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-CallActivity.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-CallActivitySubProcess.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
listeners.add(new DefaultProcessEventListener() {
@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
ksessionUsed.add(((KieSession) event.getKieRuntime()).getIdentifier());
}
});
return listeners;
}
}).get();
manager = RuntimeManagerFactory.Factory.get().newPerCaseRuntimeManager(environment);
assertNotNull(manager);
// since there is no process instance yet we need to get new session
RuntimeEngine runtime = manager.getRuntimeEngine(CaseContext.get("Case-1"));
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
long ksession1Id = ksession.getIdentifier();
assertTrue(ksession1Id == 2);
ProcessInstance pi1 = ksession.startProcess("ParentProcess");
assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
manager.disposeRuntimeEngine(runtime);
runtime = manager.getRuntimeEngine(CaseContext.get("Case-1"));
ksession = runtime.getKieSession();
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());
String externalId = logs.get(0).getExternalId();
assertEquals(manager.getIdentifier(), externalId);
logs = logService.findProcessInstances("SubProcess");
assertNotNull(logs);
assertEquals(1, logs.size());
externalId = logs.get(0).getExternalId();
assertEquals(manager.getIdentifier(), externalId);
assertEquals(1, ksessionUsed.size());
assertEquals(ksession1Id, ksessionUsed.iterator().next().longValue());
manager.disposeRuntimeEngine(runtime);
manager.close();
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class PerCaseRuntimeManagerTest method testTimerOnPerCaseManager.
@Test(timeout = 10000)
public void testTimerOnPerCaseManager() throws Exception {
final Set<Long> ksessionUsed = new HashSet<Long>();
final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 3);
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("timer")) {
timerExpirations.add(event.getProcessInstance().getId());
ksessionUsed.add(((KieSession) event.getKieRuntime()).getIdentifier());
}
}
});
listeners.add(new DefaultProcessEventListener() {
@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
ksessionUsed.add(((KieSession) event.getKieRuntime()).getIdentifier());
}
});
listeners.add(countDownListener);
return listeners;
}
}).addAsset(ResourceFactory.newClassPathResource("BPMN2-IntermediateCatchEventTimerCycle3.bpmn2"), ResourceType.BPMN2).get();
manager = RuntimeManagerFactory.Factory.get().newPerCaseRuntimeManager(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(CaseContext.get("Case-1"));
KieSession ksession = runtime.getKieSession();
long ksession1Id = ksession.getIdentifier();
ProcessInstance pi1 = ksession.startProcess("IntermediateCatchEvent");
// both processes started
assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
manager.disposeRuntimeEngine(runtime);
// wait a bit for some timers to fire
countDownListener.waitTillCompleted();
runtime = manager.getRuntimeEngine(CaseContext.get("Case-1"));
ksession = runtime.getKieSession();
ksession.abortProcessInstance(pi1.getId());
manager.disposeRuntimeEngine(runtime);
manager.close();
// there should be only one ksession used
assertEquals(1, ksessionUsed.size());
assertEquals(ksession1Id, ksessionUsed.iterator().next().longValue());
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class PerProcessInstanceRuntimeManagerTest method testEventSignalingBetweenProcesses.
@Test
public void testEventSignalingBetweenProcesses() {
final Map<String, Integer> processStates = new HashMap<String, Integer>();
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultInMemoryBuilder().persistence(false).userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("events/throw-an-event.bpmn"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("events/start-on-event.bpmn"), ResourceType.BPMN2).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> listeners = new ArrayList<ProcessEventListener>();
listeners.add(new DefaultProcessEventListener() {
@Override
public void afterProcessCompleted(ProcessCompletedEvent event) {
processStates.put(event.getProcessInstance().getProcessId(), event.getProcessInstance().getState());
}
@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
processStates.put(event.getProcessInstance().getProcessId(), event.getProcessInstance().getState());
}
});
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("com.sample.bpmn.hello");
assertEquals(2, processStates.size());
assertTrue(processStates.containsKey("com.sample.bpmn.hello"));
assertTrue(processStates.containsKey("com.sample.bpmn.Second"));
assertEquals(ProcessInstance.STATE_COMPLETED, processStates.get("com.sample.bpmn.hello").intValue());
assertEquals(ProcessInstance.STATE_COMPLETED, processStates.get("com.sample.bpmn.Second").intValue());
manager.disposeRuntimeEngine(runtime);
manager.close();
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class PerProcessInstanceRuntimeManagerTest method testRestoreTimersAfterManagerClose.
@Test(timeout = 30000)
public void testRestoreTimersAfterManagerClose() throws Exception {
final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 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("timer")) {
timerExpirations.add(event.getProcessInstance().getId());
}
}
});
listeners.add(countDownListener);
return listeners;
}
}).addAsset(ResourceFactory.newClassPathResource("BPMN2-IntermediateCatchEventTimerCycle3.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("IntermediateCatchEvent");
// both processes started
assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
manager.disposeRuntimeEngine(runtime);
// wait a bit for some timers to fire
countDownListener.waitTillCompleted();
((AbstractRuntimeManager) manager).close(true);
int currentNumberOfTriggers = timerExpirations.size();
manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
assertNotNull(manager);
countDownListener.reset(2);
countDownListener.waitTillCompleted();
runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi1.getId()));
runtime.getKieSession().abortProcessInstance(pi1.getId());
manager.disposeRuntimeEngine(runtime);
manager.close();
assertTrue(timerExpirations.size() > currentNumberOfTriggers);
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class PerRequestRuntimeManagerTest method testEventSignalingBetweenProcesses.
@Test
public void testEventSignalingBetweenProcesses() {
final Map<String, Integer> processStates = new HashMap<String, Integer>();
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultInMemoryBuilder().persistence(false).userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("events/throw-an-event.bpmn"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("events/start-on-event.bpmn"), ResourceType.BPMN2).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> listeners = new ArrayList<ProcessEventListener>();
listeners.add(new DefaultProcessEventListener() {
@Override
public void afterProcessCompleted(ProcessCompletedEvent event) {
processStates.put(event.getProcessInstance().getProcessId(), event.getProcessInstance().getState());
}
@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
processStates.put(event.getProcessInstance().getProcessId(), event.getProcessInstance().getState());
}
});
return listeners;
}
}).get();
manager = RuntimeManagerFactory.Factory.get().newPerRequestRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
ksession.startProcess("com.sample.bpmn.hello");
assertEquals(2, processStates.size());
assertTrue(processStates.containsKey("com.sample.bpmn.hello"));
assertTrue(processStates.containsKey("com.sample.bpmn.Second"));
assertEquals(ProcessInstance.STATE_COMPLETED, processStates.get("com.sample.bpmn.hello").intValue());
assertEquals(ProcessInstance.STATE_COMPLETED, processStates.get("com.sample.bpmn.Second").intValue());
manager.disposeRuntimeEngine(runtime);
manager.close();
}
Aggregations