use of org.kie.api.event.process.ProcessEventListener in project jbpm by kiegroup.
the class PerCaseRuntimeManagerTest method testTimerStartWithDeactivate.
@Test(timeout = 10000)
public void testTimerStartWithDeactivate() {
final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Hello", 1);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-TimerStart.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().newPerCaseRuntimeManager(environment);
assertNotNull(manager);
countDownListener.waitTillCompleted();
RuntimeEngine runtime1 = manager.getRuntimeEngine(CaseContext.get("Case-1"));
List<? extends ProcessInstanceLog> logs = runtime1.getAuditService().findProcessInstances();
assertEquals(1, logs.size());
manager.disposeRuntimeEngine(runtime1);
((InternalRuntimeManager) manager).deactivate();
countDownListener.reset(1);
countDownListener.waitTillCompleted(2000);
runtime1 = manager.getRuntimeEngine(CaseContext.get("Case-1"));
logs = runtime1.getAuditService().findProcessInstances();
assertEquals(1, logs.size());
manager.disposeRuntimeEngine(runtime1);
((InternalRuntimeManager) manager).activate();
countDownListener.reset(1);
countDownListener.waitTillCompleted();
runtime1 = manager.getRuntimeEngine(CaseContext.get("Case-1"));
logs = runtime1.getAuditService().findProcessInstances();
assertEquals(2, logs.size());
manager.disposeRuntimeEngine(runtime1);
}
use of org.kie.api.event.process.ProcessEventListener 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.ProcessEventListener 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();
}
use of org.kie.api.event.process.ProcessEventListener in project jbpm by kiegroup.
the class SingletonRuntimeManagerTest 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().newSingletonRuntimeManager(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.ProcessEventListener in project jbpm by kiegroup.
the class EjbTimerServiceIntegrationTest method testProcessWithTimerOverEJBTimerServiceCancelTimer.
@Test
public void testProcessWithTimerOverEJBTimerServiceCancelTimer() throws InterruptedException {
cleanupSingletonSessionId();
final List<String> timerExecution = new ArrayList<String>();
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-TimerTask.bpmn2"), ResourceType.BPMN2).schedulerService(new EjbSchedulerService()).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
listeners.add(new DefaultProcessEventListener() {
@Override
public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {
if (event.getNodeInstance().getNodeName().equals("Event")) {
timerExecution.add(event.getNodeInstance().getNodeName());
}
}
});
return listeners;
}
}).get();
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
ProcessInstance instance = ksession.startProcess("IntermediateCatchEvent");
assertNotNull(instance);
ksession.abortProcessInstance(instance.getId());
instance = ksession.getProcessInstance(instance.getId());
assertNull(instance);
Thread.sleep(3000);
assertEquals(0, timerExecution.size());
manager.disposeRuntimeEngine(runtime);
// close manager which will close session maintained by the manager
manager.close();
}
Aggregations