use of org.jbpm.services.ejb.timer.EjbSchedulerService in project jbpm by kiegroup.
the class EjbTimerServiceIntegrationTest method testProcessWithTimerOverEJBTimerService.
public void testProcessWithTimerOverEJBTimerService(String delay) 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);
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("x", delay);
ProcessInstance instance = ksession.startProcess("IntermediateCatchEvent", parameters);
assertNotNull(instance);
Thread.sleep(3000);
instance = ksession.getProcessInstance(instance.getId());
assertNull(instance);
assertEquals(1, timerExecution.size());
manager.disposeRuntimeEngine(runtime);
// close manager which will close session maintained by the manager
manager.close();
}
use of org.jbpm.services.ejb.timer.EjbSchedulerService in project jbpm by kiegroup.
the class EjbTimerServiceIntegrationTest method testProcessWithHTDeadlineTimerOverEJBTimerService.
@Test
public void testProcessWithHTDeadlineTimerOverEJBTimerService() throws InterruptedException {
cleanupSingletonSessionId();
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("HumanTaskWithDeadlines.bpmn"), ResourceType.BPMN2).schedulerService(new EjbSchedulerService()).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("htdeadlinetest");
assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
List<TaskSummary> krisTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("krisv", "en-UK");
assertEquals(1, krisTasks.size());
List<TaskSummary> johnTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(0, johnTasks.size());
List<TaskSummary> maryTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("mary", "en-UK");
assertEquals(0, maryTasks.size());
// now wait for 2 seconds for first reassignment
Thread.sleep(3000);
krisTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("krisv", "en-UK");
assertEquals(0, krisTasks.size());
johnTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(1, johnTasks.size());
maryTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("mary", "en-UK");
assertEquals(0, maryTasks.size());
runtime.getTaskService().start(johnTasks.get(0).getId(), "john");
// now wait for 2 more seconds for second reassignment
Thread.sleep(2000);
krisTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("krisv", "en-UK");
assertEquals(0, krisTasks.size());
johnTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(1, johnTasks.size());
maryTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("mary", "en-UK");
assertEquals(0, maryTasks.size());
// now wait for 1 seconds to make sure that reassignment did not happen any more since task was already started
Thread.sleep(3000);
krisTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("krisv", "en-UK");
assertEquals(0, krisTasks.size());
johnTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(0, johnTasks.size());
maryTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("mary", "en-UK");
assertEquals(1, maryTasks.size());
runtime.getTaskService().start(maryTasks.get(0).getId(), "mary");
runtime.getTaskService().complete(maryTasks.get(0).getId(), "mary", null);
// now wait for 2 seconds to make sure that reassignment did not happen any more since task was completed
Thread.sleep(2000);
processInstance = ksession.getProcessInstance(processInstance.getId());
assertNull(processInstance);
// close manager which will close session maintained by the manager
manager.close();
}
use of org.jbpm.services.ejb.timer.EjbSchedulerService 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