Search in sources :

Example 1 with DoNothingWorkItemHandler

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"));
}
Also used : WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) DoNothingWorkItemHandler(org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler) CountDownAsyncJobListener(org.jbpm.executor.test.CountDownAsyncJobListener) DefaultRegisterableItemsFactory(org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) DoNothingWorkItemHandler(org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Date(java.util.Date) Test(org.junit.Test) AbstractExecutorBaseTest(org.jbpm.test.util.AbstractExecutorBaseTest)

Example 2 with DoNothingWorkItemHandler

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());
}
Also used : KieBase(org.kie.api.KieBase) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) DoNothingWorkItemHandler(org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Test(org.junit.Test)

Example 3 with DoNothingWorkItemHandler

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();
}
Also used : RegistryContext(org.drools.core.command.impl.RegistryContext) ProcessPersistenceContext(org.jbpm.persistence.api.ProcessPersistenceContext) Context(org.kie.api.runtime.Context) DoNothingWorkItemHandler(org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler) SingleSessionCommandService(org.drools.core.command.SingleSessionCommandService) CommandBasedStatefulKnowledgeSession(org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession) ProcessPersistenceContext(org.jbpm.persistence.api.ProcessPersistenceContext) InternalKnowledgeRuntime(org.drools.core.common.InternalKnowledgeRuntime) KieBase(org.kie.api.KieBase) EntityManagerFactory(javax.persistence.EntityManagerFactory) Environment(org.kie.api.runtime.Environment) ExecutableCommand(org.drools.core.command.impl.ExecutableCommand) List(java.util.List) ArrayList(java.util.ArrayList) ProcessPersistenceContextManager(org.jbpm.persistence.api.ProcessPersistenceContextManager) Test(org.junit.Test) RequirePersistence(org.jbpm.bpmn2.test.RequirePersistence)

Example 4 with DoNothingWorkItemHandler

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);
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) KieBase(org.kie.api.KieBase) DoNothingWorkItemHandler(org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Test(org.junit.Test)

Example 5 with DoNothingWorkItemHandler

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());
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) KieBase(org.kie.api.KieBase) DoNothingWorkItemHandler(org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Test(org.junit.Test)

Aggregations

DoNothingWorkItemHandler (org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler)40 Test (org.junit.Test)39 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)36 KieBase (org.kie.api.KieBase)34 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)30 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)21 KieSession (org.kie.api.runtime.KieSession)12 HashMap (java.util.HashMap)6 RequirePersistence (org.jbpm.bpmn2.test.RequirePersistence)6 CommandBasedStatefulKnowledgeSession (org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession)4 Person (org.jbpm.bpmn2.objects.Person)4 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)4 ArrayList (java.util.ArrayList)3 DefaultRegisterableItemsFactory (org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory)3 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)3 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)3 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)3 StatefulKnowledgeSession (org.kie.internal.runtime.StatefulKnowledgeSession)3 Reader (java.io.Reader)2 StringReader (java.io.StringReader)2