use of org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler in project jbpm by kiegroup.
the class CleanupLogCommandWithProcessTest method testRunProcessWithAsyncHandlerDontDeleteActive.
@Test
public void testRunProcessWithAsyncHandlerDontDeleteActive() throws Exception {
CountDownAsyncJobListener countDownListener = configureListener(1);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.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 DoNothingWorkItemHandler());
return handlers;
}
}).get();
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
assertEquals(0, getProcessLogSize("ScriptTask"));
assertEquals(0, getNodeInstanceLogSize("ScriptTask"));
assertEquals(0, getTaskLogSize("ScriptTask"));
assertEquals(0, getVariableLogSize("ScriptTask"));
Date startDate = new Date();
ProcessInstance processInstance = ksession.startProcess("ScriptTask");
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
assertEquals(1, getProcessLogSize("ScriptTask"));
assertEquals(5, getNodeInstanceLogSize("ScriptTask"));
assertEquals(0, getTaskLogSize("ScriptTask"));
assertEquals(0, getVariableLogSize("ScriptTask"));
scheduleLogCleanup(false, true, false, startDate, "ScriptTask", "yyyy-MM-dd", manager.getIdentifier());
countDownListener.waitTillCompleted();
System.out.println("Aborting process instance " + processInstance.getId());
processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
assertNotNull(processInstance);
assertEquals(1, getProcessLogSize("ScriptTask"));
assertEquals(5, getNodeInstanceLogSize("ScriptTask"));
assertEquals(0, getTaskLogSize("ScriptTask"));
assertEquals(0, getVariableLogSize("ScriptTask"));
runtime.getKieSession().abortProcessInstance(processInstance.getId());
processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
assertNull(processInstance);
assertEquals(1, getProcessLogSize("ScriptTask"));
assertEquals(6, getNodeInstanceLogSize("ScriptTask"));
assertEquals(0, getTaskLogSize("ScriptTask"));
assertEquals(0, getVariableLogSize("ScriptTask"));
// and start another one to keep it active while cleanup happens
processInstance = ksession.startProcess("ScriptTask");
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
assertEquals(2, getProcessLogSize("ScriptTask"));
assertEquals(11, getNodeInstanceLogSize("ScriptTask"));
assertEquals(0, getTaskLogSize("ScriptTask"));
assertEquals(0, getVariableLogSize("ScriptTask"));
Thread.sleep(1000);
scheduleLogCleanup(false, false, false, new Date(), "ScriptTask", "yyyy-MM-dd HH:mm:ss", manager.getIdentifier());
countDownListener.reset(1);
countDownListener.waitTillCompleted();
assertEquals(1, getProcessLogSize("ScriptTask"));
assertEquals(5, getNodeInstanceLogSize("ScriptTask"));
assertEquals(0, getTaskLogSize("ScriptTask"));
assertEquals(0, getVariableLogSize("ScriptTask"));
}
use of org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler in project jbpm by kiegroup.
the class IntermediateEventTest method testEventBasedSplitAfter.
@Test
public void testEventBasedSplitAfter() throws Exception {
// signaling the other alternative after one has been selected should
// have no effect
KieBase kbase = createKnowledgeBase("BPMN2-EventBasedSplit.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.getWorkItemManager().registerWorkItemHandler("Email1", new SystemOutWorkItemHandler());
ksession.getWorkItemManager().registerWorkItemHandler("Email2", new DoNothingWorkItemHandler());
// Yes
ProcessInstance processInstance = ksession.startProcess("com.sample.test");
assertProcessInstanceActive(processInstance);
ksession = restoreSession(ksession, true);
ksession.getWorkItemManager().registerWorkItemHandler("Email1", new SystemOutWorkItemHandler());
ksession.getWorkItemManager().registerWorkItemHandler("Email2", new DoNothingWorkItemHandler());
ksession.signalEvent("Yes", "YesValue", processInstance.getId());
assertProcessInstanceActive(processInstance);
ksession = restoreSession(ksession, true);
ksession.getWorkItemManager().registerWorkItemHandler("Email1", new SystemOutWorkItemHandler());
ksession.getWorkItemManager().registerWorkItemHandler("Email2", new DoNothingWorkItemHandler());
// No
ksession.signalEvent("No", "NoValue", processInstance.getId());
}
use of org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler in project jbpm by kiegroup.
the class IntermediateEventTest method testEventTypesLifeCycle.
@Test
@RequirePersistence
public void testEventTypesLifeCycle() throws Exception {
// JBPM-4246
KieBase kbase = createKnowledgeBase("BPMN2-IntermediateCatchSignalBetweenUserTasks.bpmn2");
EntityManagerFactory separateEmf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");
Environment env = createEnvironment(separateEmf);
ksession = createKnowledgeSession(kbase, null, env);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new DoNothingWorkItemHandler());
ksession.startProcess("BPMN2-IntermediateCatchSignalBetweenUserTasks");
int signalListSize = ksession.execute(new ExecutableCommand<Integer>() {
public Integer execute(Context context) {
SingleSessionCommandService commandService = (SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner();
InternalKnowledgeRuntime kruntime = (InternalKnowledgeRuntime) commandService.getKieSession();
ProcessPersistenceContextManager contextManager = (ProcessPersistenceContextManager) kruntime.getEnvironment().get(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER);
ProcessPersistenceContext pcontext = contextManager.getProcessPersistenceContext();
List<Long> processInstancesToSignalList = pcontext.getProcessInstancesWaitingForEvent("MySignal");
return processInstancesToSignalList.size();
}
});
// Process instance is not waiting for signal
assertThat(signalListSize).isEqualTo(0);
ksession.getWorkItemManager().completeWorkItem(1, null);
signalListSize = ksession.execute(new ExecutableCommand<Integer>() {
public Integer execute(Context context) {
SingleSessionCommandService commandService = (SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner();
InternalKnowledgeRuntime kruntime = (InternalKnowledgeRuntime) commandService.getKieSession();
ProcessPersistenceContextManager contextManager = (ProcessPersistenceContextManager) kruntime.getEnvironment().get(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER);
ProcessPersistenceContext pcontext = contextManager.getProcessPersistenceContext();
List<Long> processInstancesToSignalList = pcontext.getProcessInstancesWaitingForEvent("MySignal");
return processInstancesToSignalList.size();
}
});
// Process instance is waiting for signal now
assertThat(signalListSize).isEqualTo(1);
ksession.signalEvent("MySignal", null);
signalListSize = ksession.execute(new ExecutableCommand<Integer>() {
public Integer execute(Context context) {
SingleSessionCommandService commandService = (SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner();
InternalKnowledgeRuntime kruntime = (InternalKnowledgeRuntime) commandService.getKieSession();
ProcessPersistenceContextManager contextManager = (ProcessPersistenceContextManager) kruntime.getEnvironment().get(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER);
ProcessPersistenceContext pcontext = contextManager.getProcessPersistenceContext();
List<Long> processInstancesToSignalList = pcontext.getProcessInstancesWaitingForEvent("MySignal");
return processInstancesToSignalList.size();
}
});
// Process instance is not waiting for signal
assertThat(signalListSize).isEqualTo(0);
ksession.getWorkItemManager().completeWorkItem(2, null);
ksession.dispose();
ksession = null;
separateEmf.close();
}
use of org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler in project jbpm by kiegroup.
the class IntermediateEventTest method testTimerBoundaryEventInterrupting.
@Test(timeout = 10000)
public void testTimerBoundaryEventInterrupting() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("TimerEvent", 1);
KieBase kbase = createKnowledgeBase("BPMN2-TimerBoundaryEventInterrupting.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.getWorkItemManager().registerWorkItemHandler("MyTask", new DoNothingWorkItemHandler());
ksession.addEventListener(countDownListener);
ProcessInstance processInstance = ksession.startProcess("TimerBoundaryEvent");
assertProcessInstanceActive(processInstance);
countDownListener.waitTillCompleted();
ksession = restoreSession(ksession, true);
logger.debug("Firing timer");
assertProcessInstanceFinished(processInstance, ksession);
}
use of org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler in project jbpm by kiegroup.
the class IntermediateEventTest method testIntermediateCatchEventTimerCycleISO.
@Test(timeout = 10000)
public void testIntermediateCatchEventTimerCycleISO() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 5);
KieBase kbase = createKnowledgeBase("BPMN2-IntermediateCatchEventTimerCycleISO.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new DoNothingWorkItemHandler());
ksession.addEventListener(countDownListener);
ProcessInstance processInstance = ksession.startProcess("IntermediateCatchEvent");
assertProcessInstanceActive(processInstance);
countDownListener.waitTillCompleted();
assertProcessInstanceActive(processInstance);
ksession.abortProcessInstance(processInstance.getId());
}
Aggregations