use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class StartEventTest method testTimerStartCron.
@Test(timeout = 15000)
public void testTimerStartCron() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("StartProcess", 5);
KieBase kbase = createKnowledgeBase("BPMN2-TimerStartCron.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.addEventListener(countDownListener);
final List<Long> list = new ArrayList<Long>();
ksession.addEventListener(new DefaultProcessEventListener() {
public void afterProcessStarted(ProcessStartedEvent event) {
list.add(event.getProcessInstance().getId());
}
});
// Timer in the process takes 1s, so after 5 seconds, there should be 5 process IDs in the list.
countDownListener.waitTillCompleted();
assertThat(getNumberOfProcessInstances("Minimal")).isEqualTo(5);
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class StartEventTest method testTimerStartDateISO.
@Test(timeout = 10000)
public void testTimerStartDateISO() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("StartProcess", 1);
byte[] content = IoUtils.readBytesFromInputStream(this.getClass().getResourceAsStream("/BPMN2-TimerStartDate.bpmn2"));
String processContent = new String(content, "UTF-8");
OffsetDateTime plusTwoSeconds = OffsetDateTime.now().plusSeconds(2);
processContent = processContent.replaceFirst("#\\{date\\}", plusTwoSeconds.toString());
Resource resource = ResourceFactory.newReaderResource(new StringReader(processContent));
resource.setSourcePath("/BPMN2-TimerStartDate.bpmn2");
resource.setTargetPath("/BPMN2-TimerStartDate.bpmn2");
KieBase kbase = createKnowledgeBaseFromResources(resource);
ksession = createKnowledgeSession(kbase);
ksession.addEventListener(countDownListener);
final List<Long> list = new ArrayList<Long>();
ksession.addEventListener(new DefaultProcessEventListener() {
public void beforeProcessStarted(ProcessStartedEvent event) {
list.add(event.getProcessInstance().getId());
}
});
assertThat(list.size()).isEqualTo(0);
countDownListener.waitTillCompleted();
assertThat(list.size()).isEqualTo(1);
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class TimerCycleOnBinaryPackageTest method testStartTimerCycleFromDisc.
@Test(timeout = 20000)
public void testStartTimerCycleFromDisc() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("start", 2);
KieBase kbase = createKnowledgeBaseFromDisc("BPMN2-StartTimerCycle.bpmn2");
try {
StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
ksession.addEventListener(countDownListener);
assertEquals(0, getNumberOfProcessInstances("defaultPackage.TimerProcess"));
long sessionId = ksession.getIdentifier();
Environment env = ksession.getEnvironment();
final List<Long> list = new ArrayList<Long>();
ksession.addEventListener(new DefaultProcessEventListener() {
public void beforeProcessStarted(ProcessStartedEvent event) {
list.add(event.getProcessInstance().getId());
}
});
((SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner()).getKieSession().addEventListener(new TriggerRulesEventListener(ksession));
countDownListener.waitTillCompleted();
assertEquals(2, getNumberOfProcessInstances("defaultPackage.TimerProcess"));
logger.info("dispose");
ksession.dispose();
countDownListener = new NodeLeftCountDownProcessEventListener("start", 2);
ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(sessionId, kbase, null, env);
ksession.addEventListener(countDownListener);
AuditLoggerFactory.newInstance(Type.JPA, ksession, null);
final List<Long> list2 = new ArrayList<Long>();
ksession.addEventListener(new DefaultProcessEventListener() {
public void beforeProcessStarted(ProcessStartedEvent event) {
list2.add(event.getProcessInstance().getId());
}
});
((SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner()).getKieSession().addEventListener(new TriggerRulesEventListener(ksession));
countDownListener.waitTillCompleted();
assertEquals(4, getNumberOfProcessInstances("defaultPackage.TimerProcess"));
abortProcessInstances(ksession);
ksession.dispose();
} finally {
ksession = createKnowledgeSession(kbase);
abortProcessInstances(ksession);
ksession.dispose();
}
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class GlobalQuartzDBTimerServiceTest method testContinueTimer.
@Test(timeout = 20000)
public void testContinueTimer() throws Exception {
// JBPM-4443
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 2);
// prepare listener to assert results
final List<Long> timerExporations = new ArrayList<Long>();
ProcessEventListener listener = new DefaultProcessEventListener() {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
if (event.getNodeInstance().getNodeName().equals("timer")) {
timerExporations.add(event.getProcessInstance().getId());
}
}
};
// No special configuration for TimerService in order to test RuntimeManager default
environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycle4.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new TestRegisterableItemsFactory(listener, countDownListener)).get();
manager = getManager(environment, true);
RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession = runtime.getKieSession();
ProcessInstance processInstance = ksession.startProcess("IntermediateCatchEvent");
manager.disposeRuntimeEngine(runtime);
countDownListener.waitTillCompleted();
manager.close();
countDownListener.reset(1);
// ---- restart ----
environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycle4.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new TestRegisterableItemsFactory(listener)).get();
manager = getManager(environment, true);
manager.disposeRuntimeEngine(runtime);
countDownListener.waitTillCompleted(3000);
assertEquals(2, timerExporations.size());
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class GlobalQuartzDBTimerServiceTest method testContinueGlobalTestService.
/**
* Test that illustrates that jobs are persisted and survives server restart
* and as soon as GlobalTimerService is active jobs are fired
* NOTE: this test is disabled by default as it requires real db (not in memory)
* and test to be executed separately each with new jvm process
*/
@Test
@Ignore
public void testContinueGlobalTestService() throws Exception {
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycle2.bpmn2"), ResourceType.BPMN2).addConfiguration("drools.timerService", "org.jbpm.process.core.timer.impl.RegisteredTimerServiceDelegate").get();
RuntimeManager manger = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
// build GlobalTimerService instance
TimerService globalTs = new GlobalTimerService(manger, globalScheduler);
// and register it in the registry under 'default' key
TimerServiceRegistry.getInstance().registerTimerService("default", globalTs);
// prepare listener to assert results
final List<Long> timerExporations = new ArrayList<Long>();
ProcessEventListener listener = new DefaultProcessEventListener() {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
if (event.getNodeInstance().getNodeName().equals("timer")) {
timerExporations.add(event.getProcessInstance().getId());
}
}
};
Thread.sleep(5000);
}
Aggregations