use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class GlobalTimerServiceBaseTest method testInterediateTimerWithHTBeforeWithGlobalTestService.
@Test(timeout = 20000)
public void testInterediateTimerWithHTBeforeWithGlobalTestService() 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());
}
}
};
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/IntermediateCatchEventTimerCycleWithHT2.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);
// 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(1, tasks.size());
for (TaskSummary task : tasks) {
runtime.getTaskService().start(task.getId(), "john");
runtime.getTaskService().complete(task.getId(), "john", null);
}
// dispose session to force session to be reloaded on timer expiration
manager.disposeRuntimeEngine(runtime);
// now wait for 1 second for first timer to trigger
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);
manager.disposeRuntimeEngine(runtime);
assertEquals(3, timerExporations.size());
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class GlobalTimerServiceVolumeTest method setup.
@Before
public void setup() {
Properties properties = new Properties();
properties.setProperty("mary", "HR");
properties.setProperty("john", "HR");
userGroupCallback = new JBossUserGroupCallbackImpl(properties);
System.setProperty("org.quartz.properties", "quartz-db.properties");
testCreateQuartzSchema();
globalScheduler = new QuartzSchedulerService();
emf = Persistence.createEntityManagerFactory("org.jbpm.test.persistence");
countDownListener = new NodeLeftCountDownProcessEventListener("timer", numberOfProcesses);
// 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());
}
}
};
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycleWithHT3.bpmn2"), ResourceType.BPMN2).schedulerService(globalScheduler).registerableItemsFactory(new TestRegisterableItemsFactory(listener, countDownListener)).get();
if ("processinstance".equals(strategy)) {
manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment, "first");
} else if ("request".equals(strategy)) {
manager = RuntimeManagerFactory.Factory.get().newPerRequestRuntimeManager(environment, "first");
} else if ("case".equals(strategy)) {
manager = RuntimeManagerFactory.Factory.get().newPerCaseRuntimeManager(environment, "first");
} else {
throw new RuntimeException("Unknow type of runtime strategy");
}
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class MultipleTimerServicesTest method testGlobalTimerServiceOnIndependentManager.
public void testGlobalTimerServiceOnIndependentManager() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 3);
NodeLeftCountDownProcessEventListener countDownListener2 = new NodeLeftCountDownProcessEventListener("timer", 3);
// prepare listener to assert results
final List<Long> timerExporations = new ArrayList<Long>();
ProcessEventListener listenerM1 = new DefaultProcessEventListener() {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
if (event.getNodeInstance().getNodeName().equals("timer")) {
logger.debug("On manager 1");
timerExporations.add(event.getProcessInstance().getId());
}
}
};
final List<Long> timerExporations2 = new ArrayList<Long>();
ProcessEventListener listenerM2 = new DefaultProcessEventListener() {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
if (event.getNodeInstance().getNodeName().equals("timer")) {
logger.debug("On manager 2");
timerExporations2.add(event.getProcessInstance().getId());
}
}
};
environmentM1 = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycle3.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new TestRegisterableItemsFactory(listenerM1, countDownListener)).schedulerService(globalScheduler1).get();
environmentM2 = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf2).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycle3.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new TestRegisterableItemsFactory(listenerM2, countDownListener2)).schedulerService(globalScheduler2).get();
managerM1 = getManager(environmentM1, "one");
RuntimeEngine runtimeM1 = managerM1.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksessionM1 = runtimeM1.getKieSession();
managerM2 = getManager(environmentM2, "two");
RuntimeEngine runtimeM2 = managerM2.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksessionM2 = runtimeM2.getKieSession();
ProcessInstance processInstanceM1 = ksessionM1.startProcess("IntermediateCatchEvent");
assertTrue(processInstanceM1.getState() == ProcessInstance.STATE_ACTIVE);
ProcessInstance processInstanceM2 = ksessionM2.startProcess("IntermediateCatchEvent");
assertTrue(processInstanceM2.getState() == ProcessInstance.STATE_ACTIVE);
// now wait for 1 second for first timer to trigger
countDownListener.waitTillCompleted(2000);
countDownListener2.waitTillCompleted(2000);
// dispose session to force session to be reloaded on timer expiration
managerM1.disposeRuntimeEngine(runtimeM1);
managerM2.disposeRuntimeEngine(runtimeM2);
countDownListener.waitTillCompleted();
countDownListener2.waitTillCompleted();
countDownListener.reset(1);
countDownListener2.reset(1);
try {
runtimeM1 = managerM1.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceM1.getId()));
ksessionM1 = runtimeM1.getKieSession();
processInstanceM1 = ksessionM1.getProcessInstance(processInstanceM1.getId());
assertNull(processInstanceM1);
} catch (SessionNotFoundException e) {
// expected in PerProcessInstance manager
}
try {
runtimeM2 = managerM2.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceM2.getId()));
ksessionM2 = runtimeM2.getKieSession();
processInstanceM2 = ksessionM2.getProcessInstance(processInstanceM2.getId());
assertNull(processInstanceM2);
} catch (SessionNotFoundException e) {
// expected in PerProcessInstance manager
}
// let's wait to ensure no more timers are expired and triggered
countDownListener.waitTillCompleted(3000);
countDownListener2.waitTillCompleted(3000);
managerM1.disposeRuntimeEngine(runtimeM1);
managerM2.disposeRuntimeEngine(runtimeM2);
assertEquals(3, timerExporations.size());
assertEquals(3, timerExporations2.size());
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class TimerUpdateTest method updateTimerLongerDelayTest.
@Test(timeout = 30000)
public void updateTimerLongerDelayTest() {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener(TIMER_NAME, 1);
// delay is set for 5s
setProcessScenario(TIMER_FILE);
kieSession.addEventListener(countDownListener);
final List<Long> list = new ArrayList<Long>();
kieSession.addEventListener(new DefaultProcessEventListener() {
@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
list.add(event.getProcessInstance().getId());
}
});
Assertions.assertThat(list).isEmpty();
long id = kieSession.startProcess(PROCESS_NAME).getId();
long startTime = System.currentTimeMillis();
Assertions.assertThat(list).isNotEmpty();
// set delay to 8s
kieSession.execute(new UpdateTimerCommand(id, TIMER_NAME, 8));
countDownListener.waitTillCompleted();
Assertions.assertThat(timerHasFired()).isTrue();
long firedTime = timerFiredTime();
long timeDifference = Math.abs(firedTime - startTime - 8000);
logger.info("Start time: " + startTime + ", fired time: " + firedTime + ", difference: " + (firedTime - startTime));
Assertions.assertThat(timeDifference).isLessThan(500);
Assertions.assertThat(kieSession.getProcessInstance(id)).isNull();
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class TimerUpdateTest method updateTimerSubprocessLongerDelayTest.
@Test(timeout = 30000)
public void updateTimerSubprocessLongerDelayTest() {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener(TIMER_SUBPROCESS_NAME, 1);
// delay is set for 5s
setProcessScenario(TIMER_SUBPROCESS_FILE);
kieSession.addEventListener(countDownListener);
final List<Long> list = new ArrayList<Long>();
kieSession.addEventListener(new DefaultProcessEventListener() {
@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
list.add(event.getProcessInstance().getId());
}
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
if (TIMER_SUBPROCESS_NAME.equals(event.getNodeInstance().getNodeName())) {
System.setProperty(TIMER_FIRED_TEXT, "");
System.setProperty(TIMER_FIRED_TIME_PROP, String.valueOf(System.currentTimeMillis()));
}
}
});
Assertions.assertThat(list).isEmpty();
long id = kieSession.startProcess(PROCESS_SUBPROCESS_NAME).getId();
long startTime = System.currentTimeMillis();
Assertions.assertThat(list).isNotEmpty();
// set delay to 8s
kieSession.execute(new UpdateTimerCommand(id, TIMER_SUBPROCESS_NAME, 8));
countDownListener.waitTillCompleted();
Assertions.assertThat(timerHasFired()).isTrue();
long firedTime = timerFiredTime();
long timeDifference = Math.abs(firedTime - startTime - 8000);
logger.info("Start time: " + startTime + ", fired time: " + firedTime + ", difference: " + (firedTime - startTime));
Assertions.assertThat(timeDifference).isLessThan(500);
Assertions.assertThat(kieSession.getProcessInstance(id)).isNull();
}
Aggregations