Search in sources :

Example 26 with ProcessNodeLeftEvent

use of org.kie.api.event.process.ProcessNodeLeftEvent in project jbpm by kiegroup.

the class GlobalQuartzDBTimerServiceTest method testContinueTimer.

@Test(timeout = 20000)
public void testContinueTimer() throws Exception {
    // JBPM-4443
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 2);
    // 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());
            }
        }
    };
    // No special configuration for TimerService in order to test RuntimeManager default
    environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycle4.bpmn2"), ResourceType.BPMN2).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");
    manager.disposeRuntimeEngine(runtime);
    countDownListener.waitTillCompleted();
    manager.close();
    countDownListener.reset(1);
    // ---- restart ----
    environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycle4.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new TestRegisterableItemsFactory(listener)).get();
    manager = getManager(environment, true);
    manager.disposeRuntimeEngine(runtime);
    countDownListener.waitTillCompleted(3000);
    assertEquals(2, timerExporations.size());
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) ArrayList(java.util.ArrayList) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) Test(org.junit.Test)

Example 27 with ProcessNodeLeftEvent

use of org.kie.api.event.process.ProcessNodeLeftEvent in project jbpm by kiegroup.

the class GlobalQuartzDBTimerServiceTest method testContinueGlobalTestService.

/**
 * Test that illustrates that jobs are persisted and survives server restart
 * and as soon as GlobalTimerService is active jobs are fired
 * NOTE: this test is disabled by default as it requires real db (not in memory)
 * and test to be executed separately each with new jvm process
 */
@Test
@Ignore
public void testContinueGlobalTestService() throws Exception {
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycle2.bpmn2"), ResourceType.BPMN2).addConfiguration("drools.timerService", "org.jbpm.process.core.timer.impl.RegisteredTimerServiceDelegate").get();
    RuntimeManager manger = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
    // build GlobalTimerService instance
    TimerService globalTs = new GlobalTimerService(manger, globalScheduler);
    // and register it in the registry under 'default' key
    TimerServiceRegistry.getInstance().registerTimerService("default", globalTs);
    // 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());
            }
        }
    };
    Thread.sleep(5000);
}
Also used : RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) AbstractRuntimeManager(org.jbpm.runtime.manager.impl.AbstractRuntimeManager) ArrayList(java.util.ArrayList) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) GlobalTimerService(org.jbpm.process.core.timer.impl.GlobalTimerService) TimerService(org.drools.core.time.TimerService) GlobalTimerService(org.jbpm.process.core.timer.impl.GlobalTimerService) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 28 with ProcessNodeLeftEvent

use of org.kie.api.event.process.ProcessNodeLeftEvent 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);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) ArrayList(java.util.ArrayList) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) TransactionalThreadPoolSchedulerService(org.jbpm.test.functional.timer.addon.TransactionalThreadPoolSchedulerService) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) SessionNotFoundException(org.kie.internal.runtime.manager.SessionNotFoundException) Test(org.junit.Test)

Example 29 with ProcessNodeLeftEvent

use of org.kie.api.event.process.ProcessNodeLeftEvent 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);
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) 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) KieSession(org.kie.api.runtime.KieSession) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) SessionNotFoundException(org.kie.internal.runtime.manager.SessionNotFoundException) Test(org.junit.Test)

Example 30 with ProcessNodeLeftEvent

use of org.kie.api.event.process.ProcessNodeLeftEvent 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());
}
Also used : Status(org.kie.api.task.model.Status) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) HashMap(java.util.HashMap) JBossUserGroupCallbackImpl(org.jbpm.services.task.identity.JBossUserGroupCallbackImpl) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ArrayList(java.util.ArrayList) Properties(java.util.Properties) UserGroupCallback(org.kie.api.task.UserGroupCallback) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) TaskSummary(org.kie.api.task.model.TaskSummary) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) KieSession(org.kie.api.runtime.KieSession) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) Test(org.junit.Test)

Aggregations

ProcessNodeLeftEvent (org.kie.api.event.process.ProcessNodeLeftEvent)32 ArrayList (java.util.ArrayList)29 Test (org.junit.Test)29 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)27 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)25 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)24 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)20 KieSession (org.kie.api.runtime.KieSession)15 KieBase (org.kie.api.KieBase)12 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)12 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)8 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)8 WorkflowProcessInstance (org.jbpm.workflow.instance.WorkflowProcessInstance)8 ProcessStartedEvent (org.kie.api.event.process.ProcessStartedEvent)8 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)7 WorkItem (org.kie.api.runtime.process.WorkItem)7 ProcessCompletedEvent (org.kie.api.event.process.ProcessCompletedEvent)6 ProcessNodeTriggeredEvent (org.kie.api.event.process.ProcessNodeTriggeredEvent)6 ProcessVariableChangedEvent (org.kie.api.event.process.ProcessVariableChangedEvent)6 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)5