use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class GlobalQuartzDBTimerServiceTest method testTimerStartManagerClose.
@Test(timeout = 20000)
public void testTimerStartManagerClose() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("StartProcess", 3);
QuartzSchedulerService additionalCopy = new QuartzSchedulerService();
additionalCopy.initScheduler(null);
// prepare listener to assert results
final List<Long> timerExporations = new ArrayList<Long>();
ProcessEventListener listener = new DefaultProcessEventListener() {
@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
timerExporations.add(event.getProcessInstance().getId());
}
};
environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/TimerStart2.bpmn2"), ResourceType.BPMN2).schedulerService(globalScheduler).registerableItemsFactory(new TestRegisterableItemsFactory(listener, countDownListener)).get();
manager = getManager(environment, false);
RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession = runtime.getKieSession();
assertEquals(0, timerExporations.size());
countDownListener.waitTillCompleted();
manager.disposeRuntimeEngine(runtime);
int atDispose = timerExporations.size();
assertTrue(atDispose > 0);
((AbstractRuntimeManager) manager).close(true);
countDownListener.reset(1);
countDownListener.waitTillCompleted(3000);
assertEquals(atDispose, timerExporations.size());
additionalCopy.shutdown();
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class GlobalThreadPoolTimerServiceTest method testInterediateTimerWithGlobalTestServiceWithinTransaction.
@Test(timeout = 20000)
public void testInterediateTimerWithGlobalTestServiceWithinTransaction() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 3);
globalScheduler = new TransactionalThreadPoolSchedulerService(3);
// 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());
}
}
};
environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycle3.bpmn2"), ResourceType.BPMN2).schedulerService(globalScheduler).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");
assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
// now wait for 1 second for first timer to trigger
countDownListener.waitTillCompleted(2000);
// dispose session to force session to be reloaded on timer expiration
manager.disposeRuntimeEngine(runtime);
countDownListener.waitTillCompleted();
countDownListener.reset(1);
try {
runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
ksession = runtime.getKieSession();
processInstance = ksession.getProcessInstance(processInstance.getId());
assertNull(processInstance);
} catch (SessionNotFoundException e) {
// expected for PerProcessInstanceManagers since process instance is completed
}
// let's wait to ensure no more timers are expired and triggered
countDownListener.waitTillCompleted(3000);
assertEquals(3, timerExporations.size());
manager.disposeRuntimeEngine(runtime);
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class GlobalTimerServiceBaseTest method testInterediateTimerWithGlobalTestService.
@Test(timeout = 20000)
public void testInterediateTimerWithGlobalTestService() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 3);
// 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());
}
}
};
environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycle3.bpmn2"), ResourceType.BPMN2).schedulerService(globalScheduler).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");
assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
// now wait for 1 second for first timer to trigger
Thread.sleep(1500);
// dispose session to force session to be reloaded on timer expiration
manager.disposeRuntimeEngine(runtime);
Thread.sleep(2000);
try {
runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
ksession = runtime.getKieSession();
processInstance = ksession.getProcessInstance(processInstance.getId());
assertNull(processInstance);
} catch (SessionNotFoundException e) {
// expected for PerProcessInstanceManagers since process instance is completed
}
// let's wait to ensure no more timers are expired and triggered
countDownListener.waitTillCompleted();
assertEquals(3, timerExporations.size());
manager.disposeRuntimeEngine(runtime);
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class GlobalTimerServiceBaseTest method testTimerStart.
@Test(timeout = 20000)
public void testTimerStart() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("StartProcess", 5);
// prepare listener to assert results
final List<Long> timerExporations = new ArrayList<Long>();
ProcessEventListener listener = new DefaultProcessEventListener() {
@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
timerExporations.add(event.getProcessInstance().getId());
}
};
environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/TimerStart2.bpmn2"), ResourceType.BPMN2).schedulerService(globalScheduler).registerableItemsFactory(new TestRegisterableItemsFactory(listener, countDownListener)).get();
manager = getManager(environment, false);
RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession = runtime.getKieSession();
assertEquals(0, timerExporations.size());
countDownListener.waitTillCompleted();
manager.disposeRuntimeEngine(runtime);
assertEquals(5, timerExporations.size());
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class GlobalTimerServiceBaseTest method testInterediateTimerWithHTAfterWithGlobalTestService.
@Test(timeout = 20000)
public void testInterediateTimerWithHTAfterWithGlobalTestService() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 3);
// prepare listener to assert results
final List<Long> timerExpirations = new ArrayList<Long>();
ProcessEventListener listener = new DefaultProcessEventListener() {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
if (event.getNodeInstance().getNodeName().equals("timer")) {
timerExpirations.add(event.getProcessInstance().getId());
}
}
};
Properties properties = new Properties();
properties.setProperty("mary", "HR");
properties.setProperty("john", "HR");
UserGroupCallback userGroupCallback = new JBossUserGroupCallbackImpl(properties);
environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycleWithHT.bpmn2"), ResourceType.BPMN2).schedulerService(globalScheduler).registerableItemsFactory(new TestRegisterableItemsFactory(listener, countDownListener)).userGroupCallback(userGroupCallback).get();
manager = getManager(environment, true);
RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession = runtime.getKieSession();
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "R3/PT1S");
ProcessInstance processInstance = ksession.startProcess("IntermediateCatchEvent", params);
assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
logger.debug("Disposed after start");
// dispose session to force session to be reloaded on timer expiration
manager.disposeRuntimeEngine(runtime);
countDownListener.waitTillCompleted();
countDownListener.reset(1);
runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
ksession = runtime.getKieSession();
// get tasks
List<Status> statuses = new ArrayList<Status>();
statuses.add(Status.Reserved);
List<TaskSummary> tasks = runtime.getTaskService().getTasksAssignedAsPotentialOwnerByStatus("john", statuses, "en-UK");
assertNotNull(tasks);
assertEquals(3, tasks.size());
for (TaskSummary task : tasks) {
runtime.getTaskService().start(task.getId(), "john");
runtime.getTaskService().complete(task.getId(), "john", null);
}
processInstance = ksession.getProcessInstance(processInstance.getId());
assertNull(processInstance);
// let's wait to ensure no more timers are expired and triggered
countDownListener.waitTillCompleted(3000);
manager.disposeRuntimeEngine(runtime);
assertEquals(3, timerExpirations.size());
}
Aggregations