Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.7.x] [RHPAM-2782] Error boundary event not working as expected with reusable subprocess node. #1612

Merged
merged 1 commit into from
Mar 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,16 @@ public void internalTrigger(final NodeInstance from, String type) {
((ProcessInstanceImpl) processInstance).setParentProcessInstanceId(getProcessInstance().getId());
((ProcessInstanceImpl) processInstance).setSignalCompletion(getSubProcessNode().isWaitForCompletion());

kruntime.startProcessInstance(processInstance.getId());
try {
kruntime.startProcessInstance(processInstance.getId());
} catch (Exception e) {
String faultName = e.getClass().getName();
if (handleError(faultName, processInstance)) {
return;
} else {
throw e;
}
}
if (!getSubProcessNode().isWaitForCompletion()) {
triggerCompleted();
} else if (processInstance.getState() == ProcessInstance.STATE_COMPLETED
Expand Down Expand Up @@ -311,21 +320,9 @@ public void processInstanceCompleted(ProcessInstance processInstance) {
handleOutMappings(processInstance);
if (processInstance.getState() == ProcessInstance.STATE_ABORTED) {
String faultName = processInstance.getOutcome()==null?"":processInstance.getOutcome();
// handle exception as sub process failed with error code
ExceptionScopeInstance exceptionScopeInstance = (ExceptionScopeInstance)
resolveContextInstance(ExceptionScope.EXCEPTION_SCOPE, faultName);
if (exceptionScopeInstance != null) {

exceptionScopeInstance.handleException(faultName, processInstance.getFaultData());
if (getSubProcessNode() != null && !getSubProcessNode().isIndependent() && getSubProcessNode().isAbortParent()){
cancel();
}
return;
} else if (getSubProcessNode() != null && !getSubProcessNode().isIndependent() && getSubProcessNode().isAbortParent()){
((ProcessInstance) getProcessInstance()).setState(ProcessInstance.STATE_ABORTED, faultName);
if (handleError(faultName, processInstance)) {
return;
}

}
// handle dynamic subprocess
if (getNode() == null) {
Expand All @@ -336,6 +333,22 @@ public void processInstanceCompleted(ProcessInstance processInstance) {

}

private boolean handleError(String faultName, ProcessInstance processInstance) {
// handle exception as sub process failed with error code
ExceptionScopeInstance exceptionScopeInstance = (ExceptionScopeInstance) resolveContextInstance(ExceptionScope.EXCEPTION_SCOPE, faultName);
if (exceptionScopeInstance != null) {

exceptionScopeInstance.handleException(faultName, processInstance.getFaultData());
if (getSubProcessNode() != null && !getSubProcessNode().isIndependent() && getSubProcessNode().isAbortParent()) {
cancel();
}
return true;
} else if (getSubProcessNode() != null && !getSubProcessNode().isIndependent() && getSubProcessNode().isAbortParent()) {
((ProcessInstance) getProcessInstance()).setState(ProcessInstance.STATE_ABORTED, faultName);
return true;
}
return false;
}
private void handleOutMappings(ProcessInstance processInstance) {
VariableScopeInstance subProcessVariableScopeInstance = (VariableScopeInstance)
processInstance.getContextInstance(VariableScope.VARIABLE_SCOPE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,26 @@

package org.jbpm.test.functional.subprocess;

import java.util.concurrent.CountDownLatch;

import org.assertj.core.api.Assertions;
import org.jbpm.test.JbpmTestCase;
import org.jbpm.test.listener.IterableProcessEventListener;
import org.junit.Test;
import org.kie.api.command.Command;
import org.kie.api.event.process.DefaultProcessEventListener;
import org.kie.api.event.process.ProcessNodeTriggeredEvent;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.process.WorkItem;
import org.kie.api.runtime.process.WorkItemHandler;
import org.kie.api.runtime.process.WorkItemManager;

import static org.jbpm.test.tools.IterableListenerAssert.*;
import static org.jbpm.test.tools.IterableListenerAssert.assertChangedVariable;
import static org.jbpm.test.tools.IterableListenerAssert.assertLeft;
import static org.jbpm.test.tools.IterableListenerAssert.assertNextNode;
import static org.jbpm.test.tools.IterableListenerAssert.assertProcessCompleted;
import static org.jbpm.test.tools.IterableListenerAssert.assertProcessStarted;
import static org.jbpm.test.tools.IterableListenerAssert.assertTriggered;

public class ReusableSubProcessTest extends JbpmTestCase {

Expand All @@ -36,6 +49,15 @@ public class ReusableSubProcessTest extends JbpmTestCase {
private static final String CALL_ACTIVITY_CHILD_ID =
"org.jbpm.test.functional.subprocess.ReusableSubProcess-child";

private static final String ERROR_HANDLING_MAIN_PROCESS =
"org/jbpm/test/functional/subprocess/ErrorHandlingMainProcess.bpmn";

private static final String ERROR_HALDING_CHILD_PROCESS =
"org/jbpm/test/functional/subprocess/ErrorHandlingSubprocess.bpmn";

private static final String ERROR_HANDLING_MAIN_PROCESS_ID =
"ExceptionHandling.MainProcess";

public ReusableSubProcessTest() {
super(false);
}
Expand Down Expand Up @@ -72,4 +94,37 @@ public void testCallActivity() {
assertProcessCompleted(eventListener, CALL_ACTIVITY_PARENT_ID);
}

class RestWorkItemHandler implements WorkItemHandler {

@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
throw new RuntimeException("failure for rest handler");
}

@Override
public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {

}

}

@Test(timeout = 30000)
public void testErrorHandlingActivity() throws Exception {
KieSession ksession = createKSession(ERROR_HANDLING_MAIN_PROCESS, ERROR_HALDING_CHILD_PROCESS);
final CountDownLatch latch = new CountDownLatch(1);
ksession.addEventListener(new DefaultProcessEventListener() {

@Override
public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
if ("Task".equals(event.getNodeInstance().getNodeName())) {
latch.countDown();
}
}

});
ksession.getWorkItemManager().registerWorkItemHandler("Rest", new RestWorkItemHandler());
ksession.startProcess(ERROR_HANDLING_MAIN_PROCESS_ID);
latch.await();
Assertions.assertThat(latch.getCount()).isEqualTo(0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.omg.org/bpmn20" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:bpsim="http://www.bpsim.org/schemas/1.0" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:drools="http://www.jboss.org/drools" id="_KigS0FylEeqndsSY5Qaz_A" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd http://www.jboss.org/drools drools.xsd http://www.bpsim.org/schemas/1.0 bpsim.xsd http://www.omg.org/spec/DD/20100524/DC DC.xsd http://www.omg.org/spec/DD/20100524/DI DI.xsd " exporter="jBPM Process Modeler" exporterVersion="2.0" targetNamespace="http://www.omg.org/bpmn20">
<bpmn2:itemDefinition id="_exceptionItem" structureRef="java.lang.Exception"/>
<bpmn2:itemDefinition id="__67BBED99-1CDF-409C-8D72-B421A365A713_errorOutputXItem" structureRef="java.lang.Exception"/>
<bpmn2:error id="org.jbpm.workflow.instance.WorkflowRuntimeException" errorCode="org.jbpm.workflow.instance.WorkflowRuntimeException"/>
<bpmn2:process id="ExceptionHandling.MainProcess" drools:packageName="com" drools:version="1.0" drools:adHoc="false" name="MainProcess" isExecutable="true">
<bpmn2:property id="exception" itemSubjectRef="_exceptionItem" name="exception"/>
<bpmn2:sequenceFlow id="_C07D8B6A-00CC-4D2D-8CB9-9DA356343D90" sourceRef="_28DDE487-2DE6-4D0B-B026-8D04E2C0C268" targetRef="_97690ECE-27B9-4495-BC8A-0D26DAC10D03">
<bpmn2:extensionElements>
<drools:metaData name="isAutoConnection.source">
<drools:metaValue><![CDATA[true]]></drools:metaValue>
</drools:metaData>
<drools:metaData name="isAutoConnection.target">
<drools:metaValue><![CDATA[true]]></drools:metaValue>
</drools:metaData>
</bpmn2:extensionElements>
</bpmn2:sequenceFlow>
<bpmn2:sequenceFlow id="_C8633717-CD20-4DD8-B6EB-C65604CAAA60" sourceRef="_67BBED99-1CDF-409C-8D72-B421A365A713" targetRef="_BC6847D7-36B3-4623-A1DC-2507A5BAB9DB">
<bpmn2:extensionElements>
<drools:metaData name="isAutoConnection.source">
<drools:metaValue><![CDATA[true]]></drools:metaValue>
</drools:metaData>
<drools:metaData name="isAutoConnection.target">
<drools:metaValue><![CDATA[true]]></drools:metaValue>
</drools:metaData>
</bpmn2:extensionElements>
</bpmn2:sequenceFlow>
<bpmn2:sequenceFlow id="_6EB287C3-2C58-4DD8-AB61-E994840C8046" sourceRef="_BC6847D7-36B3-4623-A1DC-2507A5BAB9DB" targetRef="_4D3B51DC-09A5-4BCB-AC02-6344CEB7DE34">
<bpmn2:extensionElements>
<drools:metaData name="isAutoConnection.source">
<drools:metaValue><![CDATA[true]]></drools:metaValue>
</drools:metaData>
<drools:metaData name="isAutoConnection.target">
<drools:metaValue><![CDATA[true]]></drools:metaValue>
</drools:metaData>
</bpmn2:extensionElements>
</bpmn2:sequenceFlow>
<bpmn2:sequenceFlow id="_C6163BA9-B8D0-46CF-8BCF-E0A58BAD1848" sourceRef="_F7B358F5-2EF0-4AD8-A39E-7CB447FD0ECD" targetRef="_28DDE487-2DE6-4D0B-B026-8D04E2C0C268">
<bpmn2:extensionElements>
<drools:metaData name="isAutoConnection.source">
<drools:metaValue><![CDATA[true]]></drools:metaValue>
</drools:metaData>
<drools:metaData name="isAutoConnection.target">
<drools:metaValue><![CDATA[true]]></drools:metaValue>
</drools:metaData>
</bpmn2:extensionElements>
</bpmn2:sequenceFlow>
<bpmn2:endEvent id="_97690ECE-27B9-4495-BC8A-0D26DAC10D03">
<bpmn2:incoming>_C07D8B6A-00CC-4D2D-8CB9-9DA356343D90</bpmn2:incoming>
</bpmn2:endEvent>
<bpmn2:callActivity id="_28DDE487-2DE6-4D0B-B026-8D04E2C0C268" drools:independent="false" drools:waitForCompletion="true" name="Sub-process" calledElement="Project2_ExceptionHandling.Subprocess">
<bpmn2:extensionElements>
<drools:metaData name="elementname">
<drools:metaValue><![CDATA[Sub-process]]></drools:metaValue>
</drools:metaData>
<drools:metaData name="customAbortParent">
<drools:metaValue><![CDATA[false]]></drools:metaValue>
</drools:metaData>
</bpmn2:extensionElements>
<bpmn2:incoming>_C6163BA9-B8D0-46CF-8BCF-E0A58BAD1848</bpmn2:incoming>
<bpmn2:outgoing>_C07D8B6A-00CC-4D2D-8CB9-9DA356343D90</bpmn2:outgoing>
</bpmn2:callActivity>
<bpmn2:scriptTask id="_BC6847D7-36B3-4623-A1DC-2507A5BAB9DB" name="Task" scriptFormat="http://www.java.com/java">
<bpmn2:extensionElements>
<drools:metaData name="elementname">
<drools:metaValue><![CDATA[Task]]></drools:metaValue>
</drools:metaData>
</bpmn2:extensionElements>
<bpmn2:incoming>_C8633717-CD20-4DD8-B6EB-C65604CAAA60</bpmn2:incoming>
<bpmn2:outgoing>_6EB287C3-2C58-4DD8-AB61-E994840C8046</bpmn2:outgoing>
<bpmn2:script><![CDATA[System.out.println("Exception:");]]></bpmn2:script>
</bpmn2:scriptTask>
<bpmn2:endEvent id="_4D3B51DC-09A5-4BCB-AC02-6344CEB7DE34">
<bpmn2:incoming>_6EB287C3-2C58-4DD8-AB61-E994840C8046</bpmn2:incoming>
</bpmn2:endEvent>
<bpmn2:startEvent id="_F7B358F5-2EF0-4AD8-A39E-7CB447FD0ECD">
<bpmn2:outgoing>_C6163BA9-B8D0-46CF-8BCF-E0A58BAD1848</bpmn2:outgoing>
</bpmn2:startEvent>
<bpmn2:boundaryEvent id="_67BBED99-1CDF-409C-8D72-B421A365A713" drools:boundaryca="true" drools:dockerinfo="8.0^73.0|" attachedToRef="_28DDE487-2DE6-4D0B-B026-8D04E2C0C268">
<bpmn2:outgoing>_C8633717-CD20-4DD8-B6EB-C65604CAAA60</bpmn2:outgoing>
<bpmn2:dataOutput id="_67BBED99-1CDF-409C-8D72-B421A365A713_errorOutputX" drools:dtype="org.jbpm.workflow.instance.WorkflowRuntimeException" itemSubjectRef="__67BBED99-1CDF-409C-8D72-B421A365A713_errorOutputXItem" name="error"/>
<bpmn2:dataOutputAssociation id="_KigS0lylEeqndsSY5Qaz_A">
<bpmn2:sourceRef>_67BBED99-1CDF-409C-8D72-B421A365A713_errorOutputX</bpmn2:sourceRef>
<bpmn2:targetRef>exception</bpmn2:targetRef>
</bpmn2:dataOutputAssociation>
<bpmn2:outputSet id="_KigS0VylEeqndsSY5Qaz_A">
<bpmn2:dataOutputRefs>_67BBED99-1CDF-409C-8D72-B421A365A713_errorOutputX</bpmn2:dataOutputRefs>
</bpmn2:outputSet>
<bpmn2:errorEventDefinition id="_KigS01ylEeqndsSY5Qaz_A" drools:erefname="org.jbpm.workflow.instance.WorkflowRuntimeException" errorRef="org.jbpm.workflow.instance.WorkflowRuntimeException"/>
</bpmn2:boundaryEvent>
</bpmn2:process>
<bpmndi:BPMNDiagram id="_KigS1FylEeqndsSY5Qaz_A">
<bpmndi:BPMNPlane id="_KigS1VylEeqndsSY5Qaz_A" bpmnElement="Project2_ExceptionHandling.MainProcess">
<bpmndi:BPMNShape id="shape__F7B358F5-2EF0-4AD8-A39E-7CB447FD0ECD" bpmnElement="_F7B358F5-2EF0-4AD8-A39E-7CB447FD0ECD">
<dc:Bounds height="56.0" width="56.0" x="145.0" y="50.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="shape__4D3B51DC-09A5-4BCB-AC02-6344CEB7DE34" bpmnElement="_4D3B51DC-09A5-4BCB-AC02-6344CEB7DE34">
<dc:Bounds height="56.0" width="56.00003" x="479.71347" y="231.5"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="shape__BC6847D7-36B3-4623-A1DC-2507A5BAB9DB" bpmnElement="_BC6847D7-36B3-4623-A1DC-2507A5BAB9DB">
<dc:Bounds height="102.0" width="153.99998" x="245.71349" y="208.5"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="shape__28DDE487-2DE6-4D0B-B026-8D04E2C0C268" bpmnElement="_28DDE487-2DE6-4D0B-B026-8D04E2C0C268">
<dc:Bounds height="101.0" width="153.0" x="281.5" y="27.5"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="shape__97690ECE-27B9-4495-BC8A-0D26DAC10D03" bpmnElement="_97690ECE-27B9-4495-BC8A-0D26DAC10D03">
<dc:Bounds height="56.0" width="56.0" x="514.0" y="50.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="shape__67BBED99-1CDF-409C-8D72-B421A365A713" bpmnElement="_67BBED99-1CDF-409C-8D72-B421A365A713">
<dc:Bounds height="56.0" width="56.0" x="289.5" y="100.5"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="edge_shape__F7B358F5-2EF0-4AD8-A39E-7CB447FD0ECD_to_shape__28DDE487-2DE6-4D0B-B026-8D04E2C0C268" bpmnElement="_C6163BA9-B8D0-46CF-8BCF-E0A58BAD1848">
<di:waypoint xsi:type="dc:Point" x="201.0" y="78.0"/>
<di:waypoint xsi:type="dc:Point" x="281.5" y="78.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="edge_shape__BC6847D7-36B3-4623-A1DC-2507A5BAB9DB_to_shape__4D3B51DC-09A5-4BCB-AC02-6344CEB7DE34" bpmnElement="_6EB287C3-2C58-4DD8-AB61-E994840C8046">
<di:waypoint xsi:type="dc:Point" x="399.71347" y="259.5"/>
<di:waypoint xsi:type="dc:Point" x="479.71347" y="259.5"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="edge_shape__67BBED99-1CDF-409C-8D72-B421A365A713_to_shape__BC6847D7-36B3-4623-A1DC-2507A5BAB9DB" bpmnElement="_C8633717-CD20-4DD8-B6EB-C65604CAAA60">
<di:waypoint xsi:type="dc:Point" x="345.5" y="128.5"/>
<di:waypoint xsi:type="dc:Point" x="245.71349" y="259.5"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="edge_shape__28DDE487-2DE6-4D0B-B026-8D04E2C0C268_to_shape__97690ECE-27B9-4495-BC8A-0D26DAC10D03" bpmnElement="_C07D8B6A-00CC-4D2D-8CB9-9DA356343D90">
<di:waypoint xsi:type="dc:Point" x="434.5" y="78.0"/>
<di:waypoint xsi:type="dc:Point" x="514.0" y="78.0"/>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
<bpmn2:relationship id="_KigS1lylEeqndsSY5Qaz_A" type="BPSimData">
<bpmn2:extensionElements>
<bpsim:BPSimData>
<bpsim:Scenario xsi:type="bpsim:Scenario" id="default" name="Simulationscenario">
<bpsim:ScenarioParameters xsi:type="bpsim:ScenarioParameters"/>
<bpsim:ElementParameters xsi:type="bpsim:ElementParameters" elementRef="_F7B358F5-2EF0-4AD8-A39E-7CB447FD0ECD" id="_KigS11ylEeqndsSY5Qaz_A">
<bpsim:TimeParameters xsi:type="bpsim:TimeParameters">
<bpsim:ProcessingTime xsi:type="bpsim:Parameter">
<bpsim:NormalDistribution mean="0.0" standardDeviation="0.0"/>
</bpsim:ProcessingTime>
</bpsim:TimeParameters>
</bpsim:ElementParameters>
<bpsim:ElementParameters xsi:type="bpsim:ElementParameters" elementRef="_BC6847D7-36B3-4623-A1DC-2507A5BAB9DB" id="_KigS2FylEeqndsSY5Qaz_A">
<bpsim:TimeParameters xsi:type="bpsim:TimeParameters">
<bpsim:ProcessingTime xsi:type="bpsim:Parameter">
<bpsim:NormalDistribution mean="0.0" standardDeviation="0.0"/>
</bpsim:ProcessingTime>
</bpsim:TimeParameters>
<bpsim:ResourceParameters xsi:type="bpsim:ResourceParameters">
<bpsim:Availability xsi:type="bpsim:Parameter">
<bpsim:FloatingParameter value="0.0"/>
</bpsim:Availability>
<bpsim:Quantity xsi:type="bpsim:Parameter">
<bpsim:FloatingParameter value="0.0"/>
</bpsim:Quantity>
</bpsim:ResourceParameters>
<bpsim:CostParameters xsi:type="bpsim:CostParameters">
<bpsim:UnitCost xsi:type="bpsim:Parameter">
<bpsim:FloatingParameter value="0.0"/>
</bpsim:UnitCost>
</bpsim:CostParameters>
</bpsim:ElementParameters>
<bpsim:ElementParameters xsi:type="bpsim:ElementParameters" elementRef="_28DDE487-2DE6-4D0B-B026-8D04E2C0C268" id="_KigS2VylEeqndsSY5Qaz_A">
<bpsim:TimeParameters xsi:type="bpsim:TimeParameters">
<bpsim:ProcessingTime xsi:type="bpsim:Parameter">
<bpsim:NormalDistribution mean="0.0" standardDeviation="0.0"/>
</bpsim:ProcessingTime>
</bpsim:TimeParameters>
<bpsim:ResourceParameters xsi:type="bpsim:ResourceParameters">
<bpsim:Availability xsi:type="bpsim:Parameter">
<bpsim:FloatingParameter value="0.0"/>
</bpsim:Availability>
<bpsim:Quantity xsi:type="bpsim:Parameter">
<bpsim:FloatingParameter value="0.0"/>
</bpsim:Quantity>
</bpsim:ResourceParameters>
<bpsim:CostParameters xsi:type="bpsim:CostParameters">
<bpsim:UnitCost xsi:type="bpsim:Parameter">
<bpsim:FloatingParameter value="0.0"/>
</bpsim:UnitCost>
</bpsim:CostParameters>
</bpsim:ElementParameters>
</bpsim:Scenario>
</bpsim:BPSimData>
</bpmn2:extensionElements>
<bpmn2:source>_KigS0FylEeqndsSY5Qaz_A</bpmn2:source>
<bpmn2:target>_KigS0FylEeqndsSY5Qaz_A</bpmn2:target>
</bpmn2:relationship>
</bpmn2:definitions>