Skip to content

Commit c291f7e

Browse files
author
lvcangquan.lcq
committed
fix a bug of branchGraph cache with test_case
1 parent 9c87a39 commit c291f7e

19 files changed

+365
-2
lines changed

src/main/java/com/alibaba/compileflow/engine/runtime/impl/AbstractProcessRuntime.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,8 @@ private List<TransitionNode> buildGatewayFollowingNodes(TransitionNode flowNode)
539539
}
540540

541541
private List<TransitionNode> buildBranchNodes(TransitionNode branchNode) {
542-
if (branchGraph.containsKey(branchNode.getId())) {
542+
if (branchGraph.containsKey(branchNode.getId()) &&
543+
!branchNode.getIncomingNodes().stream().anyMatch(incomingNode -> incomingNode instanceof GatewayElement)) {
543544
return branchGraph.get(branchNode.getId());
544545
}
545546

src/test/java/com/allibaba/compileflow/test/ProcessEngineTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ public void testProcessEngine() {
4242
System.out.println(processEngine.execute(code, context));
4343
}
4444

45+
@Test
46+
public void testBranchGraph() {
47+
final String code = "bpm.om.branchGraphTest";
48+
Map<String, Object> context = new HashMap<String, Object>();
49+
int input = 16;
50+
int finalResult = -1;
51+
context.put("input", input);
52+
context.put("finalResult", finalResult);
53+
final ProcessEngine processEngine = ProcessEngineFactory.getProcessEngine();
54+
processEngine.execute(code, context);
55+
//todo
56+
}
57+
4558
@Test
4659
public void testProcessEngineBpmn20() {
4760
final String code = "bpmn20.ktv.ktvExample";
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.allibaba.compileflow.test.om.branch_graph.calculate;
2+
3+
public class InputCheckOp {
4+
public InputCheckOp() {
5+
}
6+
7+
public Boolean process(int input) {
8+
int compareNumber = 20;
9+
if (input > compareNumber) {
10+
return false;
11+
} else {
12+
return true;
13+
}
14+
}
15+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.allibaba.compileflow.test.om.branch_graph.calculate;
2+
3+
public class OnlinePreProcessOp {
4+
public OnlinePreProcessOp() {
5+
}
6+
7+
public int process(int sqrtResult) {
8+
int addNumber = 2;
9+
int onlineInput = sqrtResult + addNumber;
10+
return onlineInput;
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.allibaba.compileflow.test.om.branch_graph.calculate;
2+
3+
public class OnlineSolveOp {
4+
public OnlineSolveOp() {
5+
}
6+
7+
public int process(int onlineInput) {
8+
int addNumber = 2;
9+
int onlineResult = onlineInput + addNumber;
10+
return onlineResult;
11+
}
12+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.allibaba.compileflow.test.om.branch_graph.calculate;
2+
3+
import java.math.BigInteger;
4+
5+
public class PreProcessOp {
6+
public PreProcessOp() {
7+
}
8+
9+
public void process(int input) {
10+
int compareNumber = 10;
11+
if (input < compareNumber) {
12+
System.out.println("input is smaller than 10");
13+
}
14+
}
15+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.allibaba.compileflow.test.om.branch_graph.calculate;
2+
3+
public class RandomOp {
4+
public RandomOp() {
5+
}
6+
7+
public void process(int result) {
8+
System.out.println("Random process is finished");
9+
}
10+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.allibaba.compileflow.test.om.branch_graph.calculate;
2+
3+
public class RayPreProcessOp {
4+
public RayPreProcessOp () {
5+
}
6+
7+
public int process(int sqrtResult) {
8+
int addNumber = 100;
9+
int rayInput = sqrtResult + addNumber;
10+
return rayInput;
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.allibaba.compileflow.test.om.branch_graph.calculate;
2+
3+
public class RaySolveOp {
4+
public RaySolveOp() {
5+
}
6+
7+
public int process(int rayInput) {
8+
int addNumber = 200;
9+
int rayResult = rayInput + addNumber;
10+
return rayResult;
11+
}
12+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.allibaba.compileflow.test.om.branch_graph.calculate;
2+
3+
public class ResultCheckOp {
4+
public ResultCheckOp() {
5+
}
6+
7+
public Boolean process(int result) {
8+
int compareNumber = 10;
9+
if (result < compareNumber) {
10+
return true;
11+
}
12+
return false;
13+
}
14+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.allibaba.compileflow.test.om.branch_graph.calculate;
2+
3+
public class ResultPostProcessOp {
4+
public ResultPostProcessOp() {
5+
}
6+
7+
public int process(int result) {
8+
int addNumber = 10;
9+
int finalResult = result + addNumber;
10+
return finalResult;
11+
}
12+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.allibaba.compileflow.test.om.branch_graph.calculate;
2+
3+
import com.allibaba.compileflow.test.om.branch_graph.common.RouteInfo;
4+
import com.allibaba.compileflow.test.om.branch_graph.common.TypeEnum;
5+
6+
public class RouteOp {
7+
public RouteOp() {
8+
}
9+
10+
public RouteInfo process(int sqrtResult) {
11+
int compareNumber = 5;
12+
RouteInfo routeInfo = new RouteInfo();
13+
if (sqrtResult < compareNumber) {
14+
routeInfo.setCalculateType(TypeEnum.ONLINE_SOLVE);
15+
} else {
16+
routeInfo.setCalculateType(TypeEnum.RAY_SOLVE);
17+
}
18+
return routeInfo;
19+
}
20+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.allibaba.compileflow.test.om.branch_graph.calculate;
2+
3+
import com.allibaba.compileflow.test.om.branch_graph.common.TypeEnum;
4+
5+
public class RouteReadOp {
6+
public RouteReadOp() {
7+
}
8+
9+
public void process(TypeEnum type) {
10+
if (type == TypeEnum.ONLINE_SOLVE || type == TypeEnum.RAY_SOLVE) {
11+
System.out.println("RouteReadOp is processed");
12+
}
13+
}
14+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.allibaba.compileflow.test.om.branch_graph.calculate;
2+
3+
public class SqrtProcessOp {
4+
public SqrtProcessOp() {
5+
}
6+
7+
public int process(int input) {
8+
try {
9+
double sqrtResult = Math.sqrt(input);
10+
return (int)sqrtResult;
11+
} catch (Exception e) {
12+
System.out.println("SqrtProcessOp is failed");
13+
return 0;
14+
}
15+
}
16+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.allibaba.compileflow.test.om.branch_graph.calculate;
2+
3+
import com.allibaba.compileflow.test.om.branch_graph.common.RouteInfo;
4+
import com.allibaba.compileflow.test.om.branch_graph.common.TypeEnum;
5+
6+
public class TypeOp {
7+
public TypeOp() {
8+
}
9+
10+
public TypeEnum process(RouteInfo routeInfo) {
11+
return routeInfo.getCalculateType();
12+
}
13+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.allibaba.compileflow.test.om.branch_graph.common;
2+
3+
import com.allibaba.compileflow.test.om.branch_graph.common.TypeEnum;
4+
5+
public class RouteInfo {
6+
private TypeEnum calculateType;
7+
8+
public RouteInfo() {
9+
}
10+
11+
public void setCalculateType(TypeEnum type) {
12+
calculateType = type;
13+
}
14+
15+
public TypeEnum getCalculateType() {
16+
return calculateType;
17+
}
18+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.allibaba.compileflow.test.om.branch_graph.common;
2+
3+
public enum TypeEnum {
4+
RANDOM,
5+
ONLINE_SOLVE,
6+
RAY_SOLVE;
7+
8+
private TypeEnum() {
9+
}
10+
}
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<bpm code="bpm.BranchGraphTest.bpm" name="test" type="process" description="This is test demo.">
3+
<var name="num" description="入参" dataType="java.lang.Double" inOutType="param"></var>
4+
<var name="numSqrt" description="开根号结果" dataType="java.lang.Double" inOutType="return"></var>
5+
<autoTask id="1649679494823" name="读取路由" g="125,410,90,50">
6+
<transition to="1649680231918"></transition>
7+
<action type="java">
8+
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.calculate.RouteReadOp" method="process">
9+
<var name="type" description="路由类型" dataType="com.allibaba.compileflow.test.om.branch_graph.common.TypeEnum" contextVarName="typeEnum" inOutType="param"></var>
10+
</actionHandle>
11+
</action>
12+
</autoTask>
13+
<autoTask id="1649681928894" name="Random" g="65,890,90,50">
14+
<transition to="1649681877600"></transition>
15+
<action type="java">
16+
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.calculate.RandomOp" method="process">
17+
<var name="result" description="计算结果" dataType="java.lang.Integer" inOutType="param"></var>
18+
</actionHandle>
19+
</action>
20+
</autoTask>
21+
<autoTask id="1649680235723" name="Online预处理" g="335,620,90,50">
22+
<transition to="1649681645436"></transition>
23+
<action type="java">
24+
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.calculate.OnlinePreProcessOp" method="process">
25+
<var name="sqrtResult" description="平方根" dataType="java.lang.Integer" contextVarName="sqrtResult" inOutType="param"></var>
26+
<var name="onlineInput" description="online输入" dataType="java.lang.Integer" contextVarName="onlineInput" inOutType="return"></var>
27+
</actionHandle>
28+
</action>
29+
</autoTask>
30+
<autoTask id="1649681641648" name="RaySolve" g="125,710,90,50">
31+
<transition to="1649681814271"></transition>
32+
<action type="java">
33+
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.calculate.RaySolveOp" method="process">
34+
<var name="rayInput" description="ray输入" dataType="java.lang.Integer" contextVarName="rayInput" inOutType="param"></var>
35+
<var name="result" description="求解结果" dataType="java.lang.Integer" contextVarName="result" inOutType="return"></var>
36+
</actionHandle>
37+
</action>
38+
</autoTask>
39+
<decision id="1649681345582" name="判断节点" g="125,570,90,50">
40+
<transition to="1649680235723" name="" expression="false"></transition>
41+
<transition to="1649681641648" priority="1" name="" expression="true"></transition>
42+
<action type="java">
43+
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.calculate.TypeOp" method="process">
44+
<var name="routeInfo" description="路由信息" dataType="com.allibaba.compileflow.test.om.branch_graph.common.RouteInfo" contextVarName="routeInfo" inOutType="param"></var>
45+
<var name="com.allibaba.compileflow.test.om.branch_graph.common.TypeEnum" description="计算路由" dataType="com.allibaba.compileflow.test.om.branch_graph.common.TypeEnum" contextVarName="typeEnum" inOutType="return"></var>
46+
</actionHandle>
47+
</action>
48+
</decision>
49+
<autoTask id="1649681645436" name="OnlineSolve" g="335,710,90,50">
50+
<transition to="1649681814271"></transition>
51+
<action type="java">
52+
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.calculate.OnlineSolveOp" method="process">
53+
<var name="onlineInput" description="online输入" dataType="java.lang.Integer" contextVarName="onlineInput" inOutType="param"></var>
54+
<var name="result" description="求解结果" dataType="java.lang.Integer" contextVarName="result" inOutType="return"></var>
55+
</actionHandle>
56+
</action>
57+
</autoTask>
58+
<autoTask id="1649674277421" name="预处理" g="220,35,90,50">
59+
<transition to="1649675887756"></transition>
60+
<action type="java">
61+
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.calculate.PreProcessOp" method="process">
62+
<var name="input" description="input输入" dataType="java.lang.Integer" contextVarName="input" inOutType="param"></var>
63+
</actionHandle>
64+
</action>
65+
</autoTask>
66+
<autoTask id="1649680231918" name="Ray预处理" g="125,490,90,50">
67+
<transition to="1649681345582"></transition>
68+
<action type="java">
69+
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.calculate.RayPreProcessOp" method="process">
70+
<var name="sqrtResult" description="平方根" dataType="java.lang.Integer" contextVarName="sqrtResult" inOutType="param"></var>
71+
<var name="rayInput" description="ray的输入" dataType="java.lang.Integer" contextVarName="rayInput" inOutType="return"></var>
72+
</actionHandle>
73+
</action>
74+
</autoTask>
75+
<autoTask id="1649681877600" name="结果后处理" g="235,890,90,50">
76+
<transition to="11"></transition>
77+
<action type="java">
78+
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.calculate.ResultPostProcessOp" method="process">
79+
<var name="result" description="计算结果" dataType="java.lang.Integer" contextVarName="result" inOutType="param"></var>
80+
<var name="finalResult" description="后处理结果" dataType="java.lang.Integer" contextVarName="finalResult" inOutType="return"></var>
81+
</actionHandle>
82+
</action>
83+
</autoTask>
84+
<autoTask id="1649679497675" name="读取路由" g="335,410,90,50">
85+
<transition to="1649680235723"></transition>
86+
<action type="java">
87+
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.calculate.RouteReadOp" method="process">
88+
<var name="type" description="路由类型" dataType="com.allibaba.compileflow.test.om.branch_graph.common.TypeEnum" contextVarName="typeEnum" inOutType="param"></var>
89+
</actionHandle>
90+
</action>
91+
</autoTask>
92+
<start id="1" name="开始" g="120,45,30,30">
93+
<transition to="1649674277421"></transition>
94+
</start>
95+
<end id="11" name="结束" g="545,480,30,30"></end>
96+
<autoTask id="17" name="计算平方根" g="235,150,88,48">
97+
<transition to="1649677184728"></transition>
98+
<action type="java">
99+
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.calculate.SqrtProcessOp" method="process">
100+
<var name="input" description="input输入" dataType="java.lang.Integer" contextVarName="input" inOutType="param"></var>
101+
<var name="sqrtResult" description="平方根" dataType="java.lang.Integer" contextVarName="sqrtResult" inOutType="return"></var>
102+
</actionHandle>
103+
</action>
104+
</autoTask>
105+
<decision id="1649681814271" name="判断节点" g="230,790,90,50">
106+
<transition to="1649681928894" name="" expression="!resultCheck"></transition>
107+
<transition to="1649681877600" priority="1" name="" expression="resultCheck"></transition>
108+
<action type="java">
109+
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.calculate.ResultCheckOp" method="process">
110+
<var name="result" description="结果" dataType="java.lang.Integer" contextVarName="result" inOutType="param"></var>
111+
<var name="resultCheck" description="结果检查" dataType="java.lang.Boolean" contextVarName="resultCheck" inOutType="return"></var>
112+
</actionHandle>
113+
</action>
114+
</decision>
115+
<autoTask id="1649677184728" name="设置计算路由信息" g="215,235,130,50">
116+
<transition to="1649678893514"></transition>
117+
<action type="java">
118+
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.calculate.RouteOp" method="process">
119+
<var name="sqrtResult" description="平方根" dataType="java.lang.Integer" contextVarName="sqrtResult" inOutType="param"></var>
120+
<var name="com.allibaba.compileflow.test.om.branch_graph.common.RouteInfo" description="路由信息" dataType="com.allibaba.compileflow.test.om.branch_graph.common.RouteInfo" contextVarName="routeInfo" inOutType="return"></var>
121+
</actionHandle>
122+
</action>
123+
</autoTask>
124+
<decision id="1649678893514" name="计算路由" g="235,330,90,50">
125+
<transition to="1649679494823" priority="1" name="isRay" expression="com.allibaba.compileflow.test.om.branch_graph.common.TypeEnum.RAY_SOLVE.equals(typeEnum)"></transition>
126+
<transition to="1649679497675" priority="2" name="isOnline" expression="com.allibaba.compileflow.test.om.branch_graph.common.TypeEnum.ONLINE_SOLVE.equals(typeEnum)"></transition>
127+
<action type="java">
128+
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.calculate.TypeOp" method="process">
129+
<var name="routeInfo" description="路由信息" dataType="com.allibaba.compileflow.test.om.branch_graph.common.RouteInfo" contextVarName="routeInfo" inOutType="param"></var>
130+
<var name="com.allibaba.compileflow.test.om.branch_graph.common.TypeEnum" description="计算路由" dataType="com.allibaba.compileflow.test.om.branch_graph.common.TypeEnum" contextVarName="typeEnum" inOutType="return"></var>
131+
</actionHandle>
132+
</action>
133+
</decision>
134+
<autoTask id="1649675887756" name="输入检查" g="370,85,90,50">
135+
<transition to="11" priority="1" name="" expression="!inputCheck"></transition>
136+
<transition to="17" name="" expression="inputCheck"></transition>
137+
<action type="java">
138+
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.calculate.InputCheckOp" method="process">
139+
<var name="input" description="input输入" dataType="java.lang.Integer" contextVarName="input" inOutType="param"></var>
140+
<var name="inputCheck" description="输入检查" dataType="java.lang.Boolean" contextVarName="inputCheck" inOutType="return"></var>
141+
</actionHandle>
142+
</action>
143+
</autoTask>
144+
</bpm>

0 commit comments

Comments
 (0)