Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.flowable.engine.impl.persistence.entity.ExecutionEntity;
import org.flowable.engine.impl.test.PluggableFlowableTestCase;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.engine.runtime.Execution;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.engine.test.Deployment;
import org.flowable.job.api.Job;
Expand Down Expand Up @@ -706,6 +707,86 @@ public void testCallActivityAsyncCompleteRealExecutor() {
assertThat(runtimeService.createProcessInstanceQuery().count()).isZero();
}

@Test
@Deployment(resources = {
"org/flowable/engine/test/api/event/CallActivityTest.testCallActivityCompletionConditionException.bpmn20.xml",
"org/flowable/engine/test/api/event/CallActivityTest.testCallActivityAsyncComplete_subprocess.bpmn20.xml"
})
@DisabledIfSystemProperty(named = "disableWhen", matches = "cockroachdb")
public void testCallActivityWithCompletionConditionException() {
testCallActivityWithCompletionConditionExceptionRealExecutor();
}

@Test
@Deployment(resources = {
"org/flowable/engine/test/api/event/CallActivityTest.testCallActivityAsyncCompleteCompletionConditionException.bpmn20.xml",
"org/flowable/engine/test/api/event/CallActivityTest.testCallActivityAsyncComplete_subprocess.bpmn20.xml"
})
@DisabledIfSystemProperty(named = "disableWhen", matches = "cockroachdb")
public void testCallActivityAsyncCompleteWithCompletionConditionException() {
testCallActivityWithCompletionConditionExceptionRealExecutor();
}

private void testCallActivityWithCompletionConditionExceptionRealExecutor() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testCompletionConditionException");
waitForJobExecutorOnCondition(20000L, 200L, () -> numberOfDeadLetterJobsWithException() == 3);
assertThat(runtimeService.createProcessInstanceQuery().count()).isEqualTo(4);

verifyFailingSubProcesses(processInstance);

// fix context
Execution multiInstanceRootExecution = runtimeService.createExecutionQuery()
.rootProcessInstanceId(processInstance.getId())
.variableExists("nrOfCompletedInstances")
.singleResult();
runtimeService.setVariableLocal(multiInstanceRootExecution.getId(), "approved", false);

// and retry
if ((Integer) runtimeService.getVariable(multiInstanceRootExecution.getId(), "nrOfCompletedInstances") > 0) {
// When flowable:completeAsync="true" the nrOfCompletedInstances is increased in case of failure too.
// We have to reset the nrOfCompletedInstances to 0, so that all jobs created from moveDeadLetterJobToExecutableJob are executed.
// Without this reset the process gets completed during the execution of the first job.
// The remaining activities are not executed. One test fails because of missing end time on the historic activities.
// This behavior can be observed independent of our fix.
// It was introduced by commit 65f81864904a2aa565adfa2a350a459d3bb0a893 Improve parallel multi instance leave to avoid optimistic locking exceptions
runtimeService.setVariableLocal(multiInstanceRootExecution.getId(), "nrOfCompletedInstances", 0);
}
List<Job> deadLetterJobs = managementService.createDeadLetterJobQuery().withException().list();
deadLetterJobs.forEach(job -> managementService.moveDeadLetterJobToExecutableJob(job.getId(), 2));

waitForJobExecutorToProcessAllJobsAndExecutableTimerJobs(20000L, 200L);
assertThat(managementService.createDeadLetterJobQuery().withException().count()).isZero();
}

private long numberOfDeadLetterJobsWithException() {
return managementService.createDeadLetterJobQuery().withException().count();
}

private void verifyFailingSubProcesses(ProcessInstance processInstance) {
assertThat(processInstance.isSuspended()).isFalse();

List<Job> deadLetterJobs = managementService.createDeadLetterJobQuery().withException().list();
List<Execution> subProcessExecutions = runtimeService.createExecutionQuery()
.rootProcessInstanceId(processInstance.getId())
.onlySubProcessExecutions()
.list();
assertThat(deadLetterJobs.size()).isEqualTo(subProcessExecutions.size());

List<String> subProcessInstanceIds = subProcessExecutions.stream().map(Execution::getProcessInstanceId).collect(Collectors.toList());

deadLetterJobs.forEach(job -> {
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(job.getProcessDefinitionId())
.singleResult();
assertThat(processDefinition.getKey()).isEqualTo("subProcess");

assertThat(job.getProcessInstanceId()).isNotEqualTo(processInstance.getId());
assertThat(job.getProcessInstanceId()).isIn(subProcessInstanceIds);

Execution subProcessChildExecution = runtimeService.createExecutionQuery().executionId(job.getExecutionId()).singleResult();
assertThat(subProcessChildExecution.getProcessInstanceId()).isIn(subProcessInstanceIds);
});
}

@Test
@Deployment(resources = {
"org/flowable/engine/test/api/event/CallActivityTest.testCallActivityWithEventSubprocessParent.bpmn20.xml",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?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:flowable="http://flowable.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.flowable.org/processdef">
<process id="testCompletionConditionException" name="testCompletionConditionException" isExecutable="true">
<startEvent id="startEvent1"></startEvent>
<sequenceFlow id="sid-F95A3131-6138-4FBE-8086-650EF86B3C5B" sourceRef="startEvent1" targetRef="sid-D3B6597E-43DD-4A7B-B416-053F7155076D"></sequenceFlow>
<serviceTask id="sid-D3B6597E-43DD-4A7B-B416-053F7155076D" name="A" flowable:async="true" flowable:exclusive="true" flowable:expression="${1+1}"></serviceTask>
<callActivity id="sid-534B747F-2966-4822-A22E-9159149B8449" name="Call activity" flowable:async="true" calledElement="subProcess" flowable:calledElementType="key" flowable:completeAsync="true">
<multiInstanceLoopCharacteristics isSequential="false">
<loopCardinality>3</loopCardinality>
<completionCondition>#{execution.getVariable('approved')}</completionCondition>
</multiInstanceLoopCharacteristics>
</callActivity>
<sequenceFlow id="sid-41FA373E-2256-41DC-90A6-F1120B67AF13" sourceRef="sid-D3B6597E-43DD-4A7B-B416-053F7155076D" targetRef="sid-534B747F-2966-4822-A22E-9159149B8449"></sequenceFlow>
<endEvent id="sid-56E35F84-B248-4DDC-BF86-A7845B745774"></endEvent>
<sequenceFlow id="sid-73CF809D-1602-43BB-930F-59F720E0005D" sourceRef="sid-534B747F-2966-4822-A22E-9159149B8449" targetRef="sid-56E35F84-B248-4DDC-BF86-A7845B745774"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_testAsyncComplete">
<bpmndi:BPMNPlane bpmnElement="testAsyncComplete" id="BPMNPlane_testAsyncComplete">
<bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1">
<omgdc:Bounds height="30.0" width="30.0" x="100.0" y="225.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-D3B6597E-43DD-4A7B-B416-053F7155076D" id="BPMNShape_sid-D3B6597E-43DD-4A7B-B416-053F7155076D">
<omgdc:Bounds height="80.0" width="100.0" x="210.0" y="200.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-534B747F-2966-4822-A22E-9159149B8449" id="BPMNShape_sid-534B747F-2966-4822-A22E-9159149B8449">
<omgdc:Bounds height="80.0" width="100.0" x="390.0" y="200.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-56E35F84-B248-4DDC-BF86-A7845B745774" id="BPMNShape_sid-56E35F84-B248-4DDC-BF86-A7845B745774">
<omgdc:Bounds height="28.0" width="28.0" x="535.0" y="226.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="sid-73CF809D-1602-43BB-930F-59F720E0005D" id="BPMNEdge_sid-73CF809D-1602-43BB-930F-59F720E0005D">
<omgdi:waypoint x="489.95000000000005" y="240.0"></omgdi:waypoint>
<omgdi:waypoint x="535.0" y="240.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-41FA373E-2256-41DC-90A6-F1120B67AF13" id="BPMNEdge_sid-41FA373E-2256-41DC-90A6-F1120B67AF13">
<omgdi:waypoint x="309.95000000000005" y="240.0"></omgdi:waypoint>
<omgdi:waypoint x="389.99999999997226" y="240.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-F95A3131-6138-4FBE-8086-650EF86B3C5B" id="BPMNEdge_sid-F95A3131-6138-4FBE-8086-650EF86B3C5B">
<omgdi:waypoint x="129.94999913076796" y="240.0"></omgdi:waypoint>
<omgdi:waypoint x="210.0" y="240.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?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:flowable="http://flowable.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.flowable.org/processdef">
<process id="testCompletionConditionException" name="testCompletionConditionException" isExecutable="true">
<startEvent id="startEvent1"></startEvent>
<sequenceFlow id="sid-F95A3131-6138-4FBE-8086-650EF86B3C5B" sourceRef="startEvent1" targetRef="sid-D3B6597E-43DD-4A7B-B416-053F7155076D"></sequenceFlow>
<serviceTask id="sid-D3B6597E-43DD-4A7B-B416-053F7155076D" name="A" flowable:async="true" flowable:exclusive="true" flowable:expression="${1+1}"></serviceTask>
<callActivity id="sid-534B747F-2966-4822-A22E-9159149B8449" name="Call activity" flowable:async="true" calledElement="subProcess" flowable:calledElementType="key">
<multiInstanceLoopCharacteristics isSequential="false">
<loopCardinality>3</loopCardinality>
<completionCondition>#{execution.getVariable('approved')}</completionCondition>
</multiInstanceLoopCharacteristics>
</callActivity>
<sequenceFlow id="sid-41FA373E-2256-41DC-90A6-F1120B67AF13" sourceRef="sid-D3B6597E-43DD-4A7B-B416-053F7155076D" targetRef="sid-534B747F-2966-4822-A22E-9159149B8449"></sequenceFlow>
<endEvent id="sid-56E35F84-B248-4DDC-BF86-A7845B745774"></endEvent>
<sequenceFlow id="sid-73CF809D-1602-43BB-930F-59F720E0005D" sourceRef="sid-534B747F-2966-4822-A22E-9159149B8449" targetRef="sid-56E35F84-B248-4DDC-BF86-A7845B745774"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_testAsyncComplete">
<bpmndi:BPMNPlane bpmnElement="testAsyncComplete" id="BPMNPlane_testAsyncComplete">
<bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1">
<omgdc:Bounds height="30.0" width="30.0" x="100.0" y="225.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-D3B6597E-43DD-4A7B-B416-053F7155076D" id="BPMNShape_sid-D3B6597E-43DD-4A7B-B416-053F7155076D">
<omgdc:Bounds height="80.0" width="100.0" x="210.0" y="200.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-534B747F-2966-4822-A22E-9159149B8449" id="BPMNShape_sid-534B747F-2966-4822-A22E-9159149B8449">
<omgdc:Bounds height="80.0" width="100.0" x="390.0" y="200.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-56E35F84-B248-4DDC-BF86-A7845B745774" id="BPMNShape_sid-56E35F84-B248-4DDC-BF86-A7845B745774">
<omgdc:Bounds height="28.0" width="28.0" x="535.0" y="226.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="sid-73CF809D-1602-43BB-930F-59F720E0005D" id="BPMNEdge_sid-73CF809D-1602-43BB-930F-59F720E0005D">
<omgdi:waypoint x="489.95000000000005" y="240.0"></omgdi:waypoint>
<omgdi:waypoint x="535.0" y="240.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-41FA373E-2256-41DC-90A6-F1120B67AF13" id="BPMNEdge_sid-41FA373E-2256-41DC-90A6-F1120B67AF13">
<omgdi:waypoint x="309.95000000000005" y="240.0"></omgdi:waypoint>
<omgdi:waypoint x="389.99999999997226" y="240.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-F95A3131-6138-4FBE-8086-650EF86B3C5B" id="BPMNEdge_sid-F95A3131-6138-4FBE-8086-650EF86B3C5B">
<omgdi:waypoint x="129.94999913076796" y="240.0"></omgdi:waypoint>
<omgdi:waypoint x="210.0" y="240.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,13 @@ protected static void populateEventWithCurrentContext(FlowableEngineEventImpl ev
if (persistedObject instanceof Job) {
Job jobObject = (Job) persistedObject;
if (jobObject.getScopeType() == null) {
event.setExecutionId(jobObject.getExecutionId());
event.setProcessInstanceId(jobObject.getProcessInstanceId());
if ("async-complete-call-actiivty".equals(jobObject.getJobHandlerType())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to use the public static variable AsyncCompleteCallActivityJobHandler.TYPE instead of a literal string? At least it would hide the incorrect spelling of activity 😄

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to use the public static variable AsyncCompleteCallActivityJobHandler.TYPE instead of a literal string? At least it would hide the incorrect spelling of activity 😄

Hi @dbmalkovsky, thanks for your feedback. The typo in existing flowable code is quite unfortunate... excellent intention to cover it...
However, the change here is in FlowableJobEventBuilder which is located in maven module flowable-job-service, from here the AsyncCompleteCallActivityJobHandler class (and its constant) is not reachable as it is located in flowable-engine without dependency in that direction.

event.setExecutionId(jobObject.getJobHandlerConfiguration());
event.setProcessInstanceId(jobObject.getJobHandlerConfiguration());
} else {
event.setExecutionId(jobObject.getExecutionId());
event.setProcessInstanceId(jobObject.getProcessInstanceId());
}
event.setProcessDefinitionId(jobObject.getProcessDefinitionId());
} else {
event.setScopeType(jobObject.getScopeType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,14 @@ public JobEntity createExecutableJobFromOtherJob(AbstractRuntimeJobEntity job) {
protected JobEntity createExecutableJobFromOtherJob(AbstractRuntimeJobEntity job, boolean lockJob) {
JobEntity executableJob = jobServiceConfiguration.getJobEntityManager().create();
copyJobInfo(executableJob, job);
if (job instanceof DeadLetterJobEntity && "async-complete-call-actiivty".equals(job.getJobHandlerType())) {
String[] jobHandlerConfiguration = job.getJobHandlerConfiguration().split("::");
if (jobHandlerConfiguration.length == 2) {
executableJob.setProcessInstanceId(jobHandlerConfiguration[0]);
executableJob.setExecutionId(jobHandlerConfiguration[1]);
executableJob.setJobHandlerConfiguration(job.getExecutionId());
}
}

if (lockJob) {
GregorianCalendar gregorianCalendar = new GregorianCalendar();
Expand Down Expand Up @@ -765,6 +773,11 @@ public SuspendedJobEntity createSuspendedJobFromOtherJob(AbstractRuntimeJobEntit
public DeadLetterJobEntity createDeadLetterJobFromOtherJob(AbstractRuntimeJobEntity otherJob) {
DeadLetterJobEntity deadLetterJob = jobServiceConfiguration.getDeadLetterJobEntityManager().create();
copyJobInfo(deadLetterJob, otherJob);
if ("async-complete-call-actiivty".equals(otherJob.getJobHandlerType())) {
deadLetterJob.setExecutionId(otherJob.getJobHandlerConfiguration());
deadLetterJob.setProcessInstanceId(otherJob.getJobHandlerConfiguration());
deadLetterJob.setJobHandlerConfiguration(otherJob.getProcessInstanceId() + "::" + otherJob.getExecutionId());
}
sendMoveToDeadletterEvent(otherJob);
return deadLetterJob;
}
Expand Down