use of org.jbpm.test.listener.NodeLeftCountDownProcessEventListener 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.jbpm.test.listener.NodeLeftCountDownProcessEventListener 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.jbpm.test.listener.NodeLeftCountDownProcessEventListener 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.jbpm.test.listener.NodeLeftCountDownProcessEventListener in project jbpm by kiegroup.
the class UnmarshallingOverdueTimersTest method startDisposeAndReloadTimerProcess.
@Test(timeout = 10000)
public void startDisposeAndReloadTimerProcess() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 1);
if (debug) {
String shellVar = "TEST";
String shellVarVal = System.getenv(shellVar);
if (shellVarVal != null) {
debug = false;
}
}
String sessionPropName = "KSESSION_ID";
String sessionPropVal = System.getenv(sessionPropName);
String processPropName = "PROCESS_ID";
String processPropVal = System.getenv(sessionPropName);
if (sessionPropVal == null || debug) {
KieBase kbase = loadKnowledgeBase(bpmn2FileName);
KieSession ksession = createStatefulKnowledgeSession(kbase);
ksession.addEventListener(countDownListener);
// setup parameters
Map<String, Object> params = new HashMap<String, Object>();
params.put("time", seconds + timeUnit);
// note process start time
Calendar cal = GregorianCalendar.getInstance();
// start process
ProcessInstance processInstance = ksession.startProcess("interruptedTimer", params);
long processId = processInstance.getId();
// print info for next test
if (debug) {
processPropVal = Long.toString(processId);
} else {
logger.info("export {}={}", processPropName, processId);
}
// dispose of session
KieSessionConfiguration config = ksession.getSessionConfiguration();
long ksessionId = knowledgeSessionDispose(ksession);
// print info for next test
if (debug) {
sessionPropVal = Long.toString(ksessionId);
} else {
logger.info("export {}={}", sessionPropName, ksessionId);
}
if (!debug) {
cal.add(Calendar.SECOND, (int) seconds);
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
logger.info("Please wait at least {} [{}]", (seconds + timeUnit), sdf.format(cal.getTime()));
}
}
if (sessionPropVal != null || debug) {
// reload session
int ksessionId = Integer.parseInt(sessionPropVal);
KieSession ksession = reloadStatefulKnowledgeSession(bpmn2FileName, ksessionId);
ksession.addEventListener(countDownListener);
long processInstanceId = Integer.parseInt(processPropVal);
logger.debug("! waiting 5 seconds for timer to fire");
countDownListener.waitTillCompleted();
ProcessInstance processInstance = ksession.getProcessInstance(processInstanceId);
if (processInstance != null) {
assertTrue("Process has not terminated.", processInstance.getState() == ProcessInstance.STATE_COMPLETED);
}
}
}
use of org.jbpm.test.listener.NodeLeftCountDownProcessEventListener in project jbpm by kiegroup.
the class AsyncContinuationSupportTest method testAsyncScriptTask.
@Test(timeout = 10000)
public void testAsyncScriptTask() throws Exception {
final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Hello", 1);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-AsyncScriptTask.bpmn2"), ResourceType.BPMN2).addEnvironmentEntry("ExecutorService", executorService).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
Map<String, WorkItemHandler> handlers = super.getWorkItemHandlers(runtime);
handlers.put("async", new SystemOutWorkItemHandler());
return handlers;
}
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
listeners.add(countDownListener);
return listeners;
}
}).get();
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
ProcessInstance processInstance = ksession.startProcess("AsyncScriptTask");
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
long processInstanceId = processInstance.getId();
countDownListener.waitTillCompleted();
processInstance = runtime.getKieSession().getProcessInstance(processInstanceId);
assertNull(processInstance);
List<? extends NodeInstanceLog> logs = runtime.getAuditService().findNodeInstances(processInstanceId);
assertNotNull(logs);
assertEquals(8, logs.size());
}
Aggregations