Skip to content

Commit 5b717f8

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

21 files changed

+409
-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.branchGraph";
48+
Map<String, Object> context = new HashMap<String, Object>();
49+
Integer input = 16;
50+
Integer compareNumber = 18;
51+
context.put("input", input);
52+
final ProcessEngine processEngine = ProcessEngineFactory.getProcessEngine();
53+
Map<String, Object> result = processEngine.execute(code, context);
54+
Integer finalResult = (Integer) result.get("finalResult");
55+
assert (finalResult == compareNumber);
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(Integer input) {
8+
Integer 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 Integer process(Integer sqrtResult) {
8+
Integer addNumber = 2;
9+
Integer 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 Integer process(Integer onlineInput) {
8+
Integer addNumber = 2;
9+
Integer 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(Integer 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(Integer result) {
8+
System.out.println("Random process is finished " + result);
9+
}
10+
}
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(Integer result) {
8+
Integer 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 Integer process(Integer result) {
8+
Integer addNumber = 10;
9+
Integer finalResult = result + addNumber;
10+
return finalResult;
11+
}
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.allibaba.compileflow.test.om.branch_graph.calculate;
2+
3+
public class ScaleOp {
4+
public ScaleOp() {
5+
}
6+
7+
public void process(Integer input) {
8+
System.out.printf("%d enter proportion process", input);
9+
}
10+
11+
}
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 Integer process(Integer 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.TypeInfo;
4+
import com.allibaba.compileflow.test.om.branch_graph.common.TypeEnum;
5+
6+
public class TypeCheckOp {
7+
public TypeCheckOp() {
8+
}
9+
10+
public TypeEnum process(TypeInfo typeInfo) {
11+
return typeInfo.getCalculateType();
12+
}
13+
}
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.TypeInfo;
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(TypeInfo typeInfo) {
11+
return typeInfo.getCalculateType();
12+
}
13+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.allibaba.compileflow.test.om.branch_graph.calculate;
2+
3+
import com.allibaba.compileflow.test.om.branch_graph.common.TypeInfo;
4+
import com.allibaba.compileflow.test.om.branch_graph.common.TypeEnum;
5+
6+
public class TypeProcessOp {
7+
public TypeProcessOp() {
8+
}
9+
10+
public TypeInfo process(Integer sqrtResult) {
11+
Integer compareNumber1 = 5;
12+
Integer compareNumber2 = 100;
13+
TypeInfo typeInfo = new TypeInfo();
14+
if (sqrtResult < compareNumber1) {
15+
typeInfo.setCalculateType(TypeEnum.ONLINE_SOLVE);
16+
} else if (sqrtResult > compareNumber2) {
17+
typeInfo.setCalculateType(TypeEnum.OFFLINE_SOLVE);
18+
} else {
19+
typeInfo.setCalculateType(TypeEnum.SCALE_SOLVE);
20+
}
21+
return typeInfo;
22+
}
23+
}
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 TypeReadOp {
6+
public TypeReadOp() {
7+
}
8+
9+
public void process(TypeEnum type) {
10+
if (type == TypeEnum.ONLINE_SOLVE || type == TypeEnum.OFFLINE_SOLVE) {
11+
System.out.println("TypeReadOp is processed");
12+
}
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 offlinePreProcessOp {
4+
public offlinePreProcessOp() {
5+
}
6+
7+
public Integer process(Integer sqrtResult) {
8+
Integer addNumber = 100;
9+
Integer 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 offlineSolveOp {
4+
public offlineSolveOp() {
5+
}
6+
7+
public Integer process(Integer offlineInput) {
8+
Integer addNumber = 200;
9+
Integer rayResult = offlineInput + addNumber;
10+
return rayResult;
11+
}
12+
}
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+
SCALE_SOLVE,
5+
ONLINE_SOLVE,
6+
OFFLINE_SOLVE;
7+
8+
private TypeEnum() {
9+
}
10+
}
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 TypeInfo {
6+
private TypeEnum calculateType;
7+
8+
public TypeInfo() {
9+
}
10+
11+
public void setCalculateType(TypeEnum type) {
12+
calculateType = type;
13+
}
14+
15+
public TypeEnum getCalculateType() {
16+
return calculateType;
17+
}
18+
}

0 commit comments

Comments
 (0)