Search in sources :

Example 1 with EjbSchedulerService

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();
}
Also used : DefaultRegisterableItemsFactory(org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) EjbSchedulerService(org.jbpm.services.ejb.timer.EjbSchedulerService) HashMap(java.util.HashMap) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ArrayList(java.util.ArrayList) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ProcessNodeTriggeredEvent(org.kie.api.event.process.ProcessNodeTriggeredEvent) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance)

Example 2 with EjbSchedulerService

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();
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) EjbSchedulerService(org.jbpm.services.ejb.timer.EjbSchedulerService) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 3 with EjbSchedulerService

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();
}
Also used : DefaultRegisterableItemsFactory(org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) EjbSchedulerService(org.jbpm.services.ejb.timer.EjbSchedulerService) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ArrayList(java.util.ArrayList) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ProcessNodeTriggeredEvent(org.kie.api.event.process.ProcessNodeTriggeredEvent) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Aggregations

EjbSchedulerService (org.jbpm.services.ejb.timer.EjbSchedulerService)3 KieSession (org.kie.api.runtime.KieSession)3 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)3 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)3 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)3 ArrayList (java.util.ArrayList)2 DefaultRegisterableItemsFactory (org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory)2 Test (org.junit.Test)2 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)2 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)2 ProcessNodeTriggeredEvent (org.kie.api.event.process.ProcessNodeTriggeredEvent)2 HashMap (java.util.HashMap)1 TaskSummary (org.kie.api.task.model.TaskSummary)1