Search in sources :

Example 26 with DefaultProcessEventListener

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

the class PerProcessInstanceRuntimeManagerTest method testTimersOnMultiInstanceSubprocess.

@Test(timeout = 20000)
public void testTimersOnMultiInstanceSubprocess() throws Exception {
    final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("MIDelayTimer", 2);
    final List<Long> timerExpirations = new ArrayList<Long>();
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).registerableItemsFactory(new DefaultRegisterableItemsFactory() {

        @Override
        public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
            List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
            listeners.add(new DefaultProcessEventListener() {

                @Override
                public void afterNodeLeft(ProcessNodeLeftEvent event) {
                    if (event.getNodeInstance().getNodeName().equals("MIDebugScript")) {
                        timerExpirations.add(event.getProcessInstance().getId());
                    }
                }
            });
            listeners.add(countDownListener);
            return listeners;
        }
    }).addAsset(ResourceFactory.newClassPathResource("BPMN2-MultiInstanceProcess.bpmn2"), ResourceType.BPMN2).get();
    manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
    assertNotNull(manager);
    // ksession for process instance #1
    // since there is no process instance yet we need to get new session
    RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession = runtime.getKieSession();
    ProcessInstance pi1 = ksession.startProcess("defaultPackage.MultiInstanceProcess");
    // both processes started
    assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
    manager.disposeRuntimeEngine(runtime);
    // wait a bit for some timers to fire
    countDownListener.waitTillCompleted();
    // now make sure nothing else is triggered
    countDownListener.reset(4);
    countDownListener.waitTillCompleted(3000);
    assertEquals(2, timerExpirations.size());
    runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi1.getId()));
    ksession = runtime.getKieSession();
    pi1 = ksession.getProcessInstance(pi1.getId());
    assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
    ksession.abortProcessInstance(pi1.getId());
    manager.disposeRuntimeEngine(runtime);
    manager.close();
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) ArrayList(java.util.ArrayList) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) List(java.util.List) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Example 27 with DefaultProcessEventListener

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

the class ExecutionErrorHandlingRuntimeManagerTest method testDataBaseFailureInMemoryStorage.

@Test
public void testDataBaseFailureInMemoryStorage() {
    RuntimeEngine runtime1 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession1 = runtime1.getKieSession();
    assertNotNull(ksession1);
    ksession1.addEventListener(new DefaultProcessEventListener() {

        @Override
        public void afterProcessStarted(ProcessStartedEvent event) {
            pds.close();
        }
    });
    try {
        ksession1.startProcess("UserTaskWithRollback");
        fail("Start process should fail due to data base error");
    } catch (Throwable e) {
    // expected
    }
    int expectedErrors = 1;
    try {
        manager.disposeRuntimeEngine(runtime1);
    } catch (Exception e) {
        // expected to fail for some strategies due to data source being down
        expectedErrors++;
    }
    ExecutionErrorManager errorManager = ((AbstractRuntimeManager) manager).getExecutionErrorManager();
    ExecutionErrorStorage storage = errorManager.getStorage();
    List<ExecutionError> errors = storage.list(0, 10);
    assertNotNull(errors);
    assertEquals(expectedErrors, errors.size());
    assertExecutionError(errors.get(0), "DB", "UserTaskWithRollback", "Hello");
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) ExecutionError(org.kie.internal.runtime.error.ExecutionError) AbstractRuntimeManager(org.jbpm.runtime.manager.impl.AbstractRuntimeManager) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) TaskExecutionException(org.jbpm.services.task.exception.TaskExecutionException) ExecutionErrorManager(org.kie.internal.runtime.error.ExecutionErrorManager) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ExecutionErrorStorage(org.kie.internal.runtime.error.ExecutionErrorStorage) KieSession(org.kie.api.runtime.KieSession) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Example 28 with DefaultProcessEventListener

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

the class AsyncEndSignalTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    executorService = ExecutorServiceFactory.newExecutorService(getEmf());
    executorService.setInterval(1);
    executorService.init();
    addEnvironmentEntry("ExecutorService", executorService);
    addWorkItemHandler("SyncError", new FirstErrorWorkItemHandler());
    addProcessEventListener(new DefaultProcessEventListener() {

        @Override
        public void afterProcessCompleted(ProcessCompletedEvent event) {
            synchronized (LOCK) {
                LOCK.notifyAll();
            }
        }
    });
}
Also used : FirstErrorWorkItemHandler(org.jbpm.test.wih.FirstErrorWorkItemHandler) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ProcessCompletedEvent(org.kie.api.event.process.ProcessCompletedEvent) Before(org.junit.Before)

Example 29 with DefaultProcessEventListener

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

the class AsyncIntermediateCatchSignalTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    executorService = ExecutorServiceFactory.newExecutorService(getEmf());
    executorService.setInterval(0);
    executorService.setThreadPoolSize(3);
    addEnvironmentEntry("ExecutorService", executorService);
    addWorkItemHandler("SyncError", new FirstErrorWorkItemHandler());
    addProcessEventListener(new DefaultProcessEventListener() {

        @Override
        public void afterProcessCompleted(ProcessCompletedEvent event) {
            latch.countDown();
        }
    });
    executorService.init();
}
Also used : FirstErrorWorkItemHandler(org.jbpm.test.wih.FirstErrorWorkItemHandler) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ProcessCompletedEvent(org.kie.api.event.process.ProcessCompletedEvent) Before(org.junit.Before)

Example 30 with DefaultProcessEventListener

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

the class AsyncThreadContinuationTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    executorService = ExecutorServiceFactory.newExecutorService(getEmf());
    executorService.setInterval(1);
    executorService.init();
    addEnvironmentEntry("ExecutorService", executorService);
    addWorkItemHandler("SyncError", new FirstErrorWorkItemHandler());
    addProcessEventListener(new DefaultProcessEventListener() {

        @Override
        public void afterProcessCompleted(ProcessCompletedEvent event) {
            System.out.println(event.getProcessInstance().getProcessId());
            if (event.getProcessInstance().getProcessId().equals(PROCESS_ATC)) {
                synchronized (LOCK_ATC) {
                    LOCK_ATC.notifyAll();
                }
            } else if (event.getProcessInstance().getProcessId().equals(PROCESS_IT)) {
                synchronized (LOCK_IT) {
                    LOCK_IT.notifyAll();
                }
            }
        }
    });
}
Also used : FirstErrorWorkItemHandler(org.jbpm.test.wih.FirstErrorWorkItemHandler) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ProcessCompletedEvent(org.kie.api.event.process.ProcessCompletedEvent) Before(org.junit.Before)

Aggregations

DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)98 Test (org.junit.Test)87 ArrayList (java.util.ArrayList)69 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)59 KieBase (org.kie.api.KieBase)57 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)48 ProcessStartedEvent (org.kie.api.event.process.ProcessStartedEvent)48 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)40 KieSession (org.kie.api.runtime.KieSession)38 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)30 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)27 WorkItem (org.kie.api.runtime.process.WorkItem)27 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)26 ProcessNodeLeftEvent (org.kie.api.event.process.ProcessNodeLeftEvent)25 HashMap (java.util.HashMap)24 ProcessNodeTriggeredEvent (org.kie.api.event.process.ProcessNodeTriggeredEvent)19 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)16 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)11 WorkflowProcessInstance (org.jbpm.workflow.instance.WorkflowProcessInstance)9 ProcessCompletedEvent (org.kie.api.event.process.ProcessCompletedEvent)7