Skip to content

Commit 7479aa4

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

File tree

12 files changed

+274
-1
lines changed

12 files changed

+274
-1
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

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: 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: 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: 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: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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="spring-bean">
16+
<actionHandle></actionHandle>
17+
</action>
18+
</autoTask>
19+
<autoTask id="1649680235723" name="Online预处理" g="335,620,90,50">
20+
<transition to="1649681645436"></transition>
21+
<action type="java">
22+
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.calculate.OnlinePreProcessOp" method="process">
23+
<var name="sqrtResult" description="平方根" dataType="java.lang.Integer" contextVarName="sqrtResult" inOutType="param"></var>
24+
<var name="onlineInput" description="online输入" dataType="java.lang.Integer" contextVarName="onlineInput" inOutType="return"></var>
25+
</actionHandle>
26+
</action>
27+
</autoTask>
28+
<autoTask id="1649681641648" name="RaySolve" g="125,710,90,50">
29+
<transition to="1649681814271"></transition>
30+
<action type="spring-bean">
31+
<actionHandle></actionHandle>
32+
</action>
33+
</autoTask>
34+
<decision id="1649681345582" name="判断节点" g="125,570,90,50">
35+
<transition to="1649680235723" name="" expression="false"></transition>
36+
<transition to="1649681641648" priority="1" name="" expression="true"></transition>
37+
<action type="java">
38+
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.calculate.TypeOp" method="process">
39+
<var name="routeInfo" description="路由信息" dataType="com.allibaba.compileflow.test.om.branch_graph.common.RouteInfo" contextVarName="routeInfo" inOutType="param"></var>
40+
<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>
41+
</actionHandle>
42+
</action>
43+
</decision>
44+
<autoTask id="1649681645436" name="OnlineSolve" g="335,710,90,50">
45+
<transition to="1649681814271"></transition>
46+
<action type="spring-bean">
47+
<actionHandle></actionHandle>
48+
</action>
49+
</autoTask>
50+
<autoTask id="1649674277421" name="预处理" g="220,35,90,50">
51+
<transition to="1649675887756"></transition>
52+
<action type="java">
53+
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.PreProcessOp" method="process">
54+
<var name="input" description="input输入" dataType="java.lang.Integer" contextVarName="input" inOutType="param"></var>
55+
</actionHandle>
56+
</action>
57+
</autoTask>
58+
<autoTask id="1649680231918" name="Ray预处理" g="125,490,90,50">
59+
<transition to="1649681345582"></transition>
60+
<action type="java">
61+
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.calculate.RayPreProcessOp" method="process">
62+
<var name="sqrtResult" description="平方根" dataType="java.lang.Integer" contextVarName="sqrtResult" inOutType="param"></var>
63+
<var name="rayInput" description="ray的输入" dataType="java.lang.Integer" contextVarName="rayInput" inOutType="return"></var>
64+
</actionHandle>
65+
</action>
66+
</autoTask>
67+
<autoTask id="1649681877600" name="结果后处理" g="235,890,90,50">
68+
<transition to="11"></transition>
69+
<action type="spring-bean">
70+
<actionHandle></actionHandle>
71+
</action>
72+
</autoTask>
73+
<autoTask id="1649679497675" name="读取路由" g="335,410,90,50">
74+
<transition to="1649680235723"></transition>
75+
<action type="java">
76+
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.calculate.RouteReadOp" method="process">
77+
<var name="type" description="路由类型" dataType="com.allibaba.compileflow.test.om.branch_graph.common.TypeEnum" contextVarName="typeEnum" inOutType="param"></var>
78+
</actionHandle>
79+
</action>
80+
</autoTask>
81+
<start id="1" name="开始" g="120,45,30,30">
82+
<transition to="1649674277421"></transition>
83+
</start>
84+
<end id="11" name="结束" g="545,480,30,30"></end>
85+
<autoTask id="17" name="计算平方根" g="235,150,88,48">
86+
<transition to="1649677184728"></transition>
87+
<action type="java">
88+
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.SqrtProcessOp" method="process">
89+
<var name="input" description="输入" dataType="java.lang.Integer" contextVarName="input" inOutType="param"></var>
90+
<var name="sqrtResult" description="平方根" dataType="java.lang.Integer" contextVarName="sqrtResult" inOutType="return"></var>
91+
</actionHandle>
92+
</action>
93+
</autoTask>
94+
<decision id="1649681814271" name="判断节点" g="230,790,90,50">
95+
<transition to="1649681928894" name="" expression="!resultCheck"></transition>
96+
<transition to="1649681877600" priority="1" name="" expression="resultCheck"></transition>
97+
</decision>
98+
<autoTask id="1649677184728" name="设置计算路由信息" g="215,235,130,50">
99+
<transition to="1649678893514"></transition>
100+
<action type="java">
101+
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.RouteOp" method="process">
102+
<var name="sqrtResult" description="平方根" dataType="java.lang.Integer" contextVarName="sqrtResult" inOutType="param"></var>
103+
<var name="routeInfo" description="路由信息" dataType="com.allibaba.compileflow.test.om.branch_graph.RouteInfo" contextVarName="RouteInfo" inOutType="return"></var>
104+
</actionHandle>
105+
</action>
106+
</autoTask>
107+
<decision id="1649678893514" name="计算路由" g="235,330,90,50">
108+
<transition to="1649679494823" priority="1" name="isRay" expression="com.allibaba.compileflow.test.om.branch_graph.common.TypeEnum.RAY_SOLVE.equals(typeEnum)"></transition>
109+
<transition to="1649679497675" priority="2" name="isOnline" expression="com.allibaba.compileflow.test.om.branch_graph.common.TypeEnum.ONLINE_SOLVE.equals(typeEnum)"></transition>
110+
<action type="java">
111+
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.calculate.TypeOp" method="process">
112+
<var name="routeInfo" description="路由信息" dataType="com.allibaba.compileflow.test.om.branch_graph.common.RouteInfo" contextVarName="routeInfo" inOutType="param"></var>
113+
<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>
114+
</actionHandle>
115+
</action>
116+
</decision>
117+
<autoTask id="1649675887756" name="输入检查" g="370,85,90,50">
118+
<transition to="11" priority="1" name="" expression="!inputCheck"></transition>
119+
<transition to="17" name="" expression="inputCheck"></transition>
120+
<action type="java">
121+
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.InputCheckOp" method="process">
122+
<var name="input" description="输入" dataType="java.lang.Integer" contextVarName="input" inOutType="param"></var>
123+
<var name="inputCheck" description="输入检查" dataType="java.lang.Boolean" contextVarName="inputCheck" inOutType="return"></var>
124+
</actionHandle>
125+
</action>
126+
</autoTask>
127+
</bpm>

0 commit comments

Comments
 (0)