Search in sources :

Example 51 with NodeLeftCountDownProcessEventListener

use of org.jbpm.test.listener.NodeLeftCountDownProcessEventListener in project jbpm by kiegroup.

the class TimerMigrationManagerTest method testMigrateBoundaryTimerProcessInstance.

@Test(timeout = 10000)
public void testMigrateBoundaryTimerProcessInstance() throws Exception {
    NodeLeftCountDownProcessEventListener countdownListener = new NodeLeftCountDownProcessEventListener("GoodbyeV2", 1);
    createRuntimeManagers("migration/v1/BPMN2-TimerBoundary-v1.bpmn2", "migration/v2/BPMN2-TimerBoundary-v2.bpmn2", countdownListener);
    assertNotNull(managerV1);
    assertNotNull(managerV2);
    RuntimeEngine runtime = managerV1.getRuntimeEngine(EmptyContext.get());
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    ProcessInstance pi1 = ksession.startProcess(BOUNDARY_TIMER_ID_V1);
    assertNotNull(pi1);
    assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
    JPAAuditLogService auditService = new JPAAuditLogService(emf);
    ProcessInstanceLog log = auditService.findProcessInstance(pi1.getId());
    assertNotNull(log);
    assertEquals(BOUNDARY_TIMER_ID_V1, log.getProcessId());
    assertEquals(DEPLOYMENT_ID_V1, log.getExternalId());
    managerV1.disposeRuntimeEngine(runtime);
    MigrationSpec migrationSpec = new MigrationSpec(DEPLOYMENT_ID_V1, pi1.getId(), DEPLOYMENT_ID_V2, BOUNDARY_TIMER_ID_V2);
    MigrationManager migrationManager = new MigrationManager(migrationSpec);
    MigrationReport report = migrationManager.migrate();
    assertNotNull(report);
    assertTrue(report.isSuccessful());
    log = auditService.findProcessInstance(pi1.getId());
    assertNotNull(log);
    assertEquals(BOUNDARY_TIMER_ID_V2, log.getProcessId());
    assertEquals(DEPLOYMENT_ID_V2, log.getExternalId());
    assertEquals(ProcessInstance.STATE_ACTIVE, log.getStatus().intValue());
    // wait till timer fires
    countdownListener.waitTillCompleted();
    log = auditService.findProcessInstance(pi1.getId());
    auditService.dispose();
    assertNotNull(log);
    assertEquals(BOUNDARY_TIMER_ID_V2, log.getProcessId());
    assertEquals(DEPLOYMENT_ID_V2, log.getExternalId());
    assertEquals(ProcessInstance.STATE_COMPLETED, log.getStatus().intValue());
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) ProcessInstanceLog(org.kie.api.runtime.manager.audit.ProcessInstanceLog) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 52 with NodeLeftCountDownProcessEventListener

use of org.jbpm.test.listener.NodeLeftCountDownProcessEventListener in project jbpm by kiegroup.

the class ConcurrentOperationsTest method testExecuteProcessWithAsyncHandler.

@Test(timeout = 10000)
public void testExecuteProcessWithAsyncHandler() throws Exception {
    final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Log", 1);
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addEnvironmentEntry("TRANSACTION_LOCK_ENABLED", true).registerableItemsFactory(new DefaultRegisterableItemsFactory() {

        @Override
        public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
            Map<String, WorkItemHandler> handlers = super.getWorkItemHandlers(runtime);
            handlers.put("Log", new AsyncWorkItemHandler(((RuntimeEngineImpl) runtime).getManager()));
            return handlers;
        }

        @Override
        public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
            List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
            listeners.add(countDownListener);
            return listeners;
        }
    }).addAsset(ResourceFactory.newClassPathResource("BPMN2-CustomTask.bpmn2"), ResourceType.BPMN2).get();
    manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    long sessionId = ksession.getIdentifier();
    assertTrue(sessionId == 1);
    runtime = manager.getRuntimeEngine(EmptyContext.get());
    ksession = runtime.getKieSession();
    assertEquals(sessionId, ksession.getIdentifier());
    UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
    ut.begin();
    ProcessInstance processInstance = ksession.startProcess("customtask");
    logger.debug("Started process, committing...");
    ut.commit();
    countDownListener.waitTillCompleted();
    processInstance = ksession.getProcessInstance(processInstance.getId());
    assertNull(processInstance);
    // dispose session that should not have affect on the session at all
    manager.disposeRuntimeEngine(runtime);
    // close manager which will close session maintained by the manager
    manager.close();
}
Also used : UserTransaction(javax.transaction.UserTransaction) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) DefaultRegisterableItemsFactory(org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) List(java.util.List) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Map(java.util.Map) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 53 with NodeLeftCountDownProcessEventListener

use of org.jbpm.test.listener.NodeLeftCountDownProcessEventListener in project jbpm by kiegroup.

the class AsyncTaskCallbackTest method testTaskCallback.

@Test(timeout = 30000)
public void testTaskCallback() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Continue", 1);
    addProcessEventListener(countDownListener);
    KieSession ksession = createKSession(ASYNC_EXECUTOR_CALLBACK, ASYNC_DATA_EXECUTOR);
    WorkItemManager wim = ksession.getWorkItemManager();
    wim.registerWorkItemHandler("async", new AsyncWorkItemHandler(getExecutorService()));
    Map<String, Object> pm = new HashMap<String, Object>();
    pm.put("_command", CALLBACK_COMMAND);
    ProcessInstance pi = ksession.startProcess(ASYNC_EXECUTOR_CALLBACK_ID, pm);
    // Wait for the job to be picked up and processed. The job will send
    // the 'Continue' signal on OK or Fail. We expect OK.
    countDownListener.waitTillCompleted();
    ProcessInstance processInstance = ksession.getProcessInstance(pi.getId());
    assertNull(processInstance);
    // Make sure the user registered callback was executed (a.k.a the "continue" signal was received by the process)
    assertNodeTriggered(pi.getId(), "Process async", "Continue");
    assertProcessInstanceCompleted(pi.getId());
    // Make sure the job was processed by the job executor (a.k.a the _user property was set)
    List<VariableInstanceLog> varLogList = auditLogService.findVariableInstances(pi.getId(), "_user");
    assertEquals(1, varLogList.size());
    VariableInstanceLog userVarLog = varLogList.get(0);
    assertEquals("[Name=john after command execution, age=25]", userVarLog.getValue());
}
Also used : VariableInstanceLog(org.jbpm.process.audit.VariableInstanceLog) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) HashMap(java.util.HashMap) AsyncWorkItemHandler(org.jbpm.executor.impl.wih.AsyncWorkItemHandler) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) Test(org.junit.Test)

Example 54 with NodeLeftCountDownProcessEventListener

use of org.jbpm.test.listener.NodeLeftCountDownProcessEventListener in project jbpm by kiegroup.

the class AsyncThreadContinuationTest method testRepeatIntermediateTimerAfterException.

@Test(timeout = 10000)
public void testRepeatIntermediateTimerAfterException() {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("MySignal", 1, true);
    KieSession ksession = createKSession(BPMN_IT);
    ksession.addEventListener(countDownListener);
    ProcessInstance pi = ksession.startProcess(PROCESS_IT);
    long pid = pi.getId();
    countDownListener.waitTillCompleted();
    pi = ksession.getProcessInstance(pid);
    Assertions.assertThat(pi).isNotNull();
    ksession.abortProcessInstance(pid);
    pi = ksession.getProcessInstance(pid);
    Assertions.assertThat(pi).isNull();
    ProcessInstanceLog log = getLogService().findProcessInstance(pid);
    Assertions.assertThat(log.getStatus()).isEqualTo(ProcessInstance.STATE_ABORTED);
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) ProcessInstanceLog(org.kie.api.runtime.manager.audit.ProcessInstanceLog) Test(org.junit.Test)

Example 55 with NodeLeftCountDownProcessEventListener

use of org.jbpm.test.listener.NodeLeftCountDownProcessEventListener in project jbpm by kiegroup.

the class CountDownListenerFactory method get.

public static NodeLeftCountDownProcessEventListener get(String id, String nodeName, int threads) {
    if (listeners.containsKey(id)) {
        return listeners.get(id);
    }
    NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener(nodeName, threads);
    listeners.put(id, listener);
    return listener;
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)

Aggregations

NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)132 Test (org.junit.Test)127 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)101 KieSession (org.kie.api.runtime.KieSession)66 KieBase (org.kie.api.KieBase)61 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)58 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)46 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)42 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)42 HashMap (java.util.HashMap)40 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)39 ArrayList (java.util.ArrayList)35 DefaultRegisterableItemsFactory (org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory)30 AbstractExecutorBaseTest (org.jbpm.test.util.AbstractExecutorBaseTest)28 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)26 ProcessStartedEvent (org.kie.api.event.process.ProcessStartedEvent)23 DoNothingWorkItemHandler (org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler)20 SystemOutWorkItemHandler (org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler)19 NodeTriggeredCountDownProcessEventListener (org.jbpm.test.listener.NodeTriggeredCountDownProcessEventListener)19 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)18