AnsweredAssumed Answered

Potential Asynch Multi Instance Call Activity Bug

Question asked by rallen1 on May 12, 2015
Latest reply on May 21, 2015 by martin.grofcik
Hello,

I have noticed a potential bug or misunderstanding when spawning workflows. When an embedded subprocess spawns multiple workflows via call activity, and an initial task in the child workflow is set to Asynchronous, Activiti seems fail all children after the first one.

I created a unit test demonstrating it.

MyUnitTest.java:


package org.activiti;

import static org.junit.Assert.assertNotNull;

import org.activiti.engine.HistoryService;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.test.ActivitiRule;
import org.activiti.engine.test.Deployment;
import org.junit.Rule;
import org.junit.Test;

public class MyUnitTest {
   
   @Rule
   public ActivitiRule activitiRule = new ActivitiRule();
   
   @Test
   @Deployment(resources = {"org/activiti/test/parent.bpmn", "org/activiti/test/child.bpmn"})
   public void test_subprocess() throws Exception {
      ProcessInstance processInstance = activitiRule.getRuntimeService().startProcessInstanceByKey("parent");
      Thread.sleep(5000);

      HistoryService historyService = activitiRule.getHistoryService();
      HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
      System.out.println("process instance end time: " + historicProcessInstance.getEndTime());
      
      assertNotNull(historicProcessInstance.getEndTime());
      assertNotNull(processInstance);
   }

}


parent.bpmn:


<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <message id="parentStart" name="parentStart"></message>
  <process id="parent" name="Parent Process" isExecutable="true">
    <startEvent id="messagestartevent1" name="Parent Start">
      <messageEventDefinition messageRef="parentStart"></messageEventDefinition>
    </startEvent>
    <subProcess id="subprocess1" name="Sub Process">
      <multiInstanceLoopCharacteristics isSequential="false">
        <loopCardinality>2</loopCardinality>
      </multiInstanceLoopCharacteristics>
      <callActivity id="callactivity1" name="child" calledElement="child"></callActivity>
      <endEvent id="endevent2" name="End"></endEvent>
      <sequenceFlow id="flow4" sourceRef="callactivity1" targetRef="endevent2"></sequenceFlow>
      <startEvent id="startevent1" name="Start"></startEvent>
      <sequenceFlow id="flow5" sourceRef="startevent1" targetRef="callactivity1"></sequenceFlow>
    </subProcess>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow3" sourceRef="subprocess1" targetRef="endevent1"></sequenceFlow>
    <scriptTask id="scripttask1" name="Script Task" scriptFormat="groovy" activiti:autoStoreVariables="false">
      <script>println "parent"</script>
    </scriptTask>
    <sequenceFlow id="flow6" sourceRef="messagestartevent1" targetRef="scripttask1"></sequenceFlow>
    <sequenceFlow id="flow7" sourceRef="scripttask1" targetRef="subprocess1"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_parent">
    <bpmndi:BPMNPlane bpmnElement="parent" id="BPMNPlane_parent">
      <bpmndi:BPMNShape bpmnElement="messagestartevent1" id="BPMNShape_messagestartevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="80.0" y="360.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="subprocess1" id="BPMNShape_subprocess1">
        <omgdc:Bounds height="206.0" width="311.0" x="350.0" y="275.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="callactivity1" id="BPMNShape_callactivity1">
        <omgdc:Bounds height="55.0" width="105.0" x="450.0" y="353.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent2" id="BPMNShape_endevent2">
        <omgdc:Bounds height="35.0" width="35.0" x="600.0" y="363.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="370.0" y="363.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="730.0" y="360.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="scripttask1" id="BPMNShape_scripttask1">
        <omgdc:Bounds height="55.0" width="105.0" x="180.0" y="350.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
        <omgdi:waypoint x="555.0" y="380.0"></omgdi:waypoint>
        <omgdi:waypoint x="600.0" y="380.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
        <omgdi:waypoint x="405.0" y="380.0"></omgdi:waypoint>
        <omgdi:waypoint x="450.0" y="380.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
        <omgdi:waypoint x="661.0" y="378.0"></omgdi:waypoint>
        <omgdi:waypoint x="730.0" y="377.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">
        <omgdi:waypoint x="115.0" y="377.0"></omgdi:waypoint>
        <omgdi:waypoint x="180.0" y="377.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7">
        <omgdi:waypoint x="285.0" y="377.0"></omgdi:waypoint>
        <omgdi:waypoint x="350.0" y="378.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>


child.bpmn

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <message id="childStart" name="childStart"></message>
  <process id="child" name="Child Process" isExecutable="true">
    <startEvent id="messagestartevent1" name="Child Start">
      <messageEventDefinition messageRef="childStart"></messageEventDefinition>
    </startEvent>
    <endEvent id="endevent1" name="End"></endEvent>
    <scriptTask id="scripttask1" name="Script Task" activiti:async="true" scriptFormat="groovy" activiti:autoStoreVariables="false">
      <script>println "child"</script>
    </scriptTask>
    <sequenceFlow id="flow1" sourceRef="messagestartevent1" targetRef="scripttask1"></sequenceFlow>
    <sequenceFlow id="flow2" sourceRef="scripttask1" targetRef="endevent1"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_child">
    <bpmndi:BPMNPlane bpmnElement="child" id="BPMNPlane_child">
      <bpmndi:BPMNShape bpmnElement="messagestartevent1" id="BPMNShape_messagestartevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="90.0" y="353.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="330.0" y="353.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="scripttask1" id="BPMNShape_scripttask1">
        <omgdc:Bounds height="55.0" width="105.0" x="176.0" y="343.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="125.0" y="370.0"></omgdi:waypoint>
        <omgdi:waypoint x="176.0" y="370.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="281.0" y="370.0"></omgdi:waypoint>
        <omgdi:waypoint x="330.0" y="370.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>


Any help is greatly appreciated. Thanks.

Outcomes