cancel
Showing results for 
Search instead for 
Did you mean: 

ProcessInstance.isEnded() returns false

frauke
Champ in-the-making
Champ in-the-making
How can it be that processInstance.isEnded() does not return true if the process terminated?
What did I do wrong?
This is the process definition:

<process id="testProcess1" name="Test Process">
    <startEvent id="startTest" />
    <sequenceFlow id="flow1" sourceRef="startTest" targetRef="t1" />
    <userTask id="t1" name="T1" />
    <sequenceFlow id="flow2" sourceRef="t1" targetRef="t2" />
    <task id="t2" name="T2"/>
    <sequenceFlow id="flow3" sourceRef="t2" targetRef="ready" />
    <endEvent id="ready" />
</process>
The test fails and the processInstance still holds activity 'T1':

        ProcessInstance processInstance = processEngine.getRuntimeService()
            .startProcessInstanceByKey("testProcess1");
        Task task = processEngine.getTaskService().createTaskQuery()
            .processInstanceId(processInstance.getId())
            .singleResult();
        processEngine.getTaskService().complete(task.getId());
        assertEquals(true, processInstance.isEnded());
Frauke
10 REPLIES 10

falko_menge
Champ in-the-making
Champ in-the-making
Abstract BPMN 2.0 Tasks like T2 are by definition not executable. Could you try turning T2 into a User Task or Service Task?

frauke
Champ in-the-making
Champ in-the-making
Yes, thank you, I changed the task into a service task, but the behaviour is still the same.
The process instance does not "end" and still holds task T1.

frauke
Champ in-the-making
Champ in-the-making
Ok, wait a minute…
I now put a system out message into the service task's behaviour class and that prints its message.
That means, T2 is executed, but still the process instance doesn't end.

No, I did not forget to call performDefaultOutgoingBehavior()   Smiley Wink

frederikherema1
Star Contributor
Star Contributor
Frauke,

A ProcessInstance is actually a snapshot of the ProcessInstance state at the moment (in your case, when processInstance was created and encountered the first wait-state).

To have a fresh state of the instance, query it using
runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult()
In your case the process instance has already ended, the returned processInstance will be null. It is present in the activiti history (if enabled).
historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult()

frauke
Champ in-the-making
Champ in-the-making
Oh great, thank you, Frederik.
So I indeed learned something! (I am quite new at the Activiti business)

Best regards
Frauke

thetoolman
Champ in-the-making
Champ in-the-making
If a process instance is archived to the history, when can you ever get myPI.isEnded() to return true ?

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
you can't.

thetoolman
Champ in-the-making
Champ in-the-making
you can't.

so that method should be called .returnFalseAlways() Smiley Tongue

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
you can't.

so that method should be called .returnFalseAlways() Smiley Tongue

No, certainly not. It should be .neverReturnTrue(). But yes it looks kind of strange. Internally it isn't though since if it is ended it is not in the runttime tables anymore