use of org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler 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());
}
use of org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler in project jbpm by kiegroup.
the class AsyncContinuationSupportTest method testNoAsyncServiceAvailableScriptTask.
@Test
public void testNoAsyncServiceAvailableScriptTask() throws Exception {
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-AsyncScriptTask.bpmn2"), ResourceType.BPMN2).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;
}
}).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("AsyncScriptTask");
long processInstanceId = processInstance.getId();
processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
assertNull(processInstance);
List<? extends NodeInstanceLog> logs = runtime.getAuditService().findNodeInstances(processInstanceId);
assertNotNull(logs);
assertEquals(8, logs.size());
}
use of org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler in project jbpm by kiegroup.
the class AsyncContinuationSupportTest method testAsyncModeWithScriptTask.
@Test(timeout = 10000)
public void testAsyncModeWithScriptTask() throws Exception {
final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("EndProcess", 1);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.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("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);
ProcessInstance processInstance = ksession.startProcess("ScriptTask");
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(8, logs.size());
waitForAllJobsToComplete();
List<RequestInfo> completed = executorService.getCompletedRequests(new QueryContext());
// there should 3 completed commands (for script, for task and end node)
assertEquals(3, completed.size());
Set<String> commands = completed.stream().map(RequestInfo::getCommandName).collect(Collectors.toSet());
assertEquals(1, commands.size());
assertEquals(AsyncSignalEventCommand.class.getName(), commands.iterator().next());
}
use of org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler in project jbpm by kiegroup.
the class AsyncContinuationSupportTest method testAsyncModeWithAsyncScriptTask.
@Test(timeout = 10000)
public void testAsyncModeWithAsyncScriptTask() throws Exception {
final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("EndProcess", 1);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-AsyncScriptTask.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("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);
ProcessInstance processInstance = ksession.startProcess("AsyncScriptTask");
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(8, logs.size());
waitForAllJobsToComplete();
List<RequestInfo> completed = executorService.getCompletedRequests(new QueryContext());
// there should 3 completed commands (for script, for task and end node)
assertEquals(3, completed.size());
Set<String> commands = completed.stream().map(RequestInfo::getCommandName).collect(Collectors.toSet());
assertEquals(1, commands.size());
assertEquals(AsyncSignalEventCommand.class.getName(), commands.iterator().next());
}
use of org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler in project jbpm by kiegroup.
the class PersistentStatefulSessionTest method testPersistenceWorkItems3.
@Test
public void testPersistenceWorkItems3() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(new ClassPathResource("WorkItemsProcess.rf"), ResourceType.DRF);
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
ksession.getWorkItemManager().registerWorkItemHandler("MyWork", new SystemOutWorkItemHandler());
ProcessInstance processInstance = ksession.startProcess("org.drools.test.TestProcess");
ksession.insert("TestString");
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
Aggregations