Search in sources :

Example 6 with RuntimeEnvironment

use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.

the class AsyncContinuationSupportTest method testAsyncSubProcess.

@Test(timeout = 10000)
public void testAsyncSubProcess() throws Exception {
    final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Hello", 1);
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-AsyncSubProcess.bpmn2"), ResourceType.BPMN2).addEnvironmentEntry("ExecutorService", executorService).registerableItemsFactory(new DefaultRegisterableItemsFactory() {

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

        @Override
        public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
            List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
            listeners.add(countDownListener);
            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> params = new HashMap<String, Object>();
    ProcessInstance processInstance = ksession.startProcess("AsyncSubProcess", params);
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    long processInstanceId = processInstance.getId();
    countDownListener.waitTillCompleted();
    processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
    assertNull(processInstance);
    List<? extends NodeInstanceLog> logs = runtime.getAuditService().findNodeInstances(processInstanceId);
    assertNotNull(logs);
    assertEquals(18, logs.size());
}
Also used : DefaultRegisterableItemsFactory(org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) HashMap(java.util.HashMap) NodeTriggeredCountDownProcessEventListener(org.jbpm.test.listener.NodeTriggeredCountDownProcessEventListener) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AbstractExecutorBaseTest(org.jbpm.test.util.AbstractExecutorBaseTest) Test(org.junit.Test)

Example 7 with RuntimeEnvironment

use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.

the class AsyncContinuationSupportTest method testSubProcessWithAsyncNodes.

@Test(timeout = 10000)
public void testSubProcessWithAsyncNodes() throws Exception {
    final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("EndProcess", 1);
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-SubProcessAsyncNodes.bpmn2"), ResourceType.BPMN2).addEnvironmentEntry("ExecutorService", executorService).registerableItemsFactory(new DefaultRegisterableItemsFactory() {

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

        @Override
        public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
            List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
            listeners.add(countDownListener);
            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> params = new HashMap<String, Object>();
    ProcessInstance processInstance = ksession.startProcess("SubProcess", params);
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    long processInstanceId = processInstance.getId();
    countDownListener.waitTillCompleted();
    processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
    assertNull(processInstance);
    List<? extends NodeInstanceLog> logs = runtime.getAuditService().findNodeInstances(processInstanceId);
    assertNotNull(logs);
    assertEquals(18, logs.size());
}
Also used : DefaultRegisterableItemsFactory(org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) HashMap(java.util.HashMap) NodeTriggeredCountDownProcessEventListener(org.jbpm.test.listener.NodeTriggeredCountDownProcessEventListener) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AbstractExecutorBaseTest(org.jbpm.test.util.AbstractExecutorBaseTest) Test(org.junit.Test)

Example 8 with RuntimeEnvironment

use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.

the class AsyncContinuationSupportTest method testAsyncModeWithSignalEventSubProcess.

@Test(timeout = 10000)
public void testAsyncModeWithSignalEventSubProcess() throws Exception {
    CountDownAsyncJobListener initialJob = new CountDownAsyncJobListener(1);
    ((ExecutorServiceImpl) executorService).addAsyncJobListener(initialJob);
    final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("SubprocessEnd", 1);
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("ProbAsync.bpmn2"), ResourceType.BPMN2).addEnvironmentEntry("ExecutorService", executorService).addEnvironmentEntry("AsyncMode", "true").registerableItemsFactory(new DefaultRegisterableItemsFactory() {

        @Override
        public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
            Map<String, WorkItemHandler> handlers = super.getWorkItemHandlers(runtime);
            return handlers;
        }

        @Override
        public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
            List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
            listeners.add(countDownListener);
            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> params = new HashMap<>();
    params.put("timer1", "20s");
    params.put("timer2", "10s");
    ProcessInstance processInstance = ksession.startProcess("ProbAsync", params);
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    long processInstanceId = processInstance.getId();
    initialJob.waitTillCompleted();
    List<TaskSummary> tasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertEquals(1, tasks.size());
    runtime.getKieSession().signalEvent("startSignal", null, processInstanceId);
    countDownListener.waitTillCompleted();
    processInstance = runtime.getKieSession().getProcessInstance(processInstanceId);
    assertNull(processInstance);
}
Also used : DefaultRegisterableItemsFactory(org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) ExecutorServiceImpl(org.jbpm.executor.impl.ExecutorServiceImpl) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) HashMap(java.util.HashMap) NodeTriggeredCountDownProcessEventListener(org.jbpm.test.listener.NodeTriggeredCountDownProcessEventListener) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) CountDownAsyncJobListener(org.jbpm.executor.test.CountDownAsyncJobListener) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AbstractExecutorBaseTest(org.jbpm.test.util.AbstractExecutorBaseTest) Test(org.junit.Test)

Example 9 with RuntimeEnvironment

use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.

the class AsyncContinuationSupportTest method testAsyncAndSyncServiceTasks.

@Test(timeout = 10000)
public void testAsyncAndSyncServiceTasks() throws Exception {
    final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Async Service", 3);
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-AsyncServiceTask.bpmn2"), ResourceType.BPMN2).addEnvironmentEntry("ExecutorService", executorService).registerableItemsFactory(new DefaultRegisterableItemsFactory() {

        @Override
        public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
            Map<String, WorkItemHandler> handlers = super.getWorkItemHandlers(runtime);
            handlers.put("async", new SystemOutWorkItemHandler());
            handlers.put("Service Task", new ServiceTaskHandler());
            return handlers;
        }

        @Override
        public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
            List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
            listeners.add(countDownListener);
            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> params = new HashMap<String, Object>();
    params.put("name", "john");
    ProcessInstance processInstance = ksession.startProcess("async-cont.async-service-task", params);
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    long processInstanceId = processInstance.getId();
    countDownListener.waitTillCompleted();
    processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
    assertNull(processInstance);
    List<? extends NodeInstanceLog> logs = runtime.getAuditService().findNodeInstances(processInstanceId);
    assertNotNull(logs);
    assertEquals(14, logs.size());
}
Also used : DefaultRegisterableItemsFactory(org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) HashMap(java.util.HashMap) NodeTriggeredCountDownProcessEventListener(org.jbpm.test.listener.NodeTriggeredCountDownProcessEventListener) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) ServiceTaskHandler(org.jbpm.bpmn2.handler.ServiceTaskHandler) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AbstractExecutorBaseTest(org.jbpm.test.util.AbstractExecutorBaseTest) Test(org.junit.Test)

Example 10 with RuntimeEnvironment

use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.

the class AsyncContinuationSupportTest method testAsyncModeWithServiceTask.

@Test(timeout = 10000)
public void testAsyncModeWithServiceTask() throws Exception {
    final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("EndProcess", 1);
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-ServiceProcess.bpmn2"), ResourceType.BPMN2).addEnvironmentEntry("ExecutorService", executorService).addEnvironmentEntry("AsyncMode", "true").registerableItemsFactory(new DefaultRegisterableItemsFactory() {

        @Override
        public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
            Map<String, WorkItemHandler> handlers = super.getWorkItemHandlers(runtime);
            handlers.put("Service Task", new ServiceTaskHandler());
            return handlers;
        }

        @Override
        public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
            List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
            listeners.add(countDownListener);
            return listeners;
        }
    }).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("ServiceProcess");
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    long processInstanceId = processInstance.getId();
    countDownListener.waitTillCompleted();
    processInstance = runtime.getKieSession().getProcessInstance(processInstanceId);
    assertNull(processInstance);
    List<? extends NodeInstanceLog> logs = runtime.getAuditService().findNodeInstances(processInstanceId);
    assertNotNull(logs);
    assertEquals(6, logs.size());
    waitForAllJobsToComplete();
    List<RequestInfo> completed = executorService.getCompletedRequests(new QueryContext());
    // there should be 2 completed commands (for service task and end node)
    assertEquals(2, completed.size());
    Set<String> commands = completed.stream().map(RequestInfo::getCommandName).collect(Collectors.toSet());
    assertEquals(1, commands.size());
    assertEquals(AsyncSignalEventCommand.class.getName(), commands.iterator().next());
}
Also used : DefaultRegisterableItemsFactory(org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) NodeTriggeredCountDownProcessEventListener(org.jbpm.test.listener.NodeTriggeredCountDownProcessEventListener) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) QueryContext(org.kie.api.runtime.query.QueryContext) RequestInfo(org.kie.api.executor.RequestInfo) AsyncSignalEventCommand(org.jbpm.process.core.async.AsyncSignalEventCommand) WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) ServiceTaskHandler(org.jbpm.bpmn2.handler.ServiceTaskHandler) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AbstractExecutorBaseTest(org.jbpm.test.util.AbstractExecutorBaseTest) Test(org.junit.Test)

Aggregations

RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)177 Test (org.junit.Test)163 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)148 KieSession (org.kie.api.runtime.KieSession)127 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)107 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)101 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)51 AbstractExecutorBaseTest (org.jbpm.test.util.AbstractExecutorBaseTest)49 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)48 HashMap (java.util.HashMap)47 DefaultRegisterableItemsFactory (org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory)42 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)38 ArrayList (java.util.ArrayList)21 TaskSummary (org.kie.api.task.model.TaskSummary)21 NodeTriggeredCountDownProcessEventListener (org.jbpm.test.listener.NodeTriggeredCountDownProcessEventListener)20 AuditService (org.kie.api.runtime.manager.audit.AuditService)20 CountDownAsyncJobListener (org.jbpm.executor.test.CountDownAsyncJobListener)19 SystemOutWorkItemHandler (org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler)19 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)19 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)17