Hi,I've noticed an issue that has creeped in in 5.17; it presents itself when trying to execute an async service task for a second time during a process. I've created the following test case:
public class AsyncProcessTest {
@Rule
public ActivitiRule activitiRule = new ActivitiRule("test.activiti.cfg.xml");
@Test
@Deployment(resources = {"AsyncFailProcess.bpmn20.xml"})
public void retryTakesProcessBackToUserTask() throws Exception {
ProcessInstance process = activitiRule.getRuntimeService().startProcessInstanceByKey("async_process");
completeAsyncJobs();
assertThat(process.getActivityId(), is("usertask1"));
TaskService taskService = activitiRule.getTaskService();
String taskId = taskService.createTaskQuery().executionId(process.getProcessInstanceId())
.singleResult().getId();
Map<String, Object> variables = new HashMap<>();
variables.put("action", "retry");
taskService.complete(taskId, variables);
completeAsyncJobs();
assertThat(process.getActivityId(), is("usertask1"));
}
private void completeAsyncJobs() {
//Complete async jobs
ManagementService managementService = activitiRule.getManagementService();
List<Job> jobs = managementService.createJobQuery().list();
for (Job job : jobs) {
managementService.executeJob(job.getId());
}
}
}
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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">
<process id="async_process" name="Async Process" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<serviceTask id="servicetask1" name="Async Service Task" activiti:async="true" activiti:class="com.asyncexample.NothingServiceTask"></serviceTask>
<userTask id="usertask1" name="User Task"></userTask>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="servicetask1"></sequenceFlow>
<sequenceFlow id="flow2" sourceRef="servicetask1" targetRef="usertask1"></sequenceFlow>
<sequenceFlow id="flow3" sourceRef="usertask1" targetRef="endevent1">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${action=="complete"}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="flow4" name="Retry" sourceRef="usertask1" targetRef="servicetask1">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${action=="retry"}]]></conditionExpression>
</sequenceFlow>
</process>
</definitions>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
<property name="jdbcUrl" value="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000" />
<property name="jdbcDriver" value="org.h2.Driver" />
<property name="jdbcUsername" value="sa" />
<property name="jdbcPassword" value="" />
<!– I've tried multiple combinations of these… –>
<!–<property name="jobExecutorActivate" value="false" />–>
<!–<property name="jobExecutorEnabled" value="false" />–>
<!–<property name="asyncExecutorEnabled" value="false" />–>
<!–<property name="asyncExecutorActivate" value="false" />–>
<property name="databaseSchemaUpdate" value="true" />
</bean>
</beans>
public class NothingServiceTask implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) throws Exception {
System.out.println("I do nothing");
}
}
If I take out the activiti:async="true" from the service task or revert to 5.16, this test passes. N.B. This is not just an issue in the tests, this also manifests itself in regular production code. Please advise if the usage of this has changed or whether I should report a bug.