From 5b717f87172d044545e9830b355dad477183388d Mon Sep 17 00:00:00 2001 From: "lvcangquan.lcq" Date: Wed, 23 Mar 2022 16:56:21 +0800 Subject: [PATCH] fix a bug of branchGraph cache with test_case --- scripts/bash-buddy | 2 +- .../runtime/impl/AbstractProcessRuntime.java | 3 +- .../compileflow/test/ProcessEngineTest.java | 13 ++ .../branch_graph/calculate/InputCheckOp.java | 15 ++ .../calculate/OnlinePreProcessOp.java | 12 ++ .../branch_graph/calculate/OnlineSolveOp.java | 12 ++ .../branch_graph/calculate/PreProcessOp.java | 15 ++ .../om/branch_graph/calculate/RandomOp.java | 10 ++ .../branch_graph/calculate/ResultCheckOp.java | 14 ++ .../calculate/ResultPostProcessOp.java | 12 ++ .../om/branch_graph/calculate/ScaleOp.java | 11 ++ .../branch_graph/calculate/SqrtProcessOp.java | 16 ++ .../branch_graph/calculate/TypeCheckOp.java | 13 ++ .../om/branch_graph/calculate/TypeOp.java | 13 ++ .../branch_graph/calculate/TypeProcessOp.java | 23 +++ .../om/branch_graph/calculate/TypeReadOp.java | 14 ++ .../calculate/offlinePreProcessOp.java | 12 ++ .../calculate/offlineSolveOp.java | 12 ++ .../test/om/branch_graph/common/TypeEnum.java | 10 ++ .../test/om/branch_graph/common/TypeInfo.java | 18 ++ src/test/resources/bpm/om/branchGraph.bpm | 161 ++++++++++++++++++ 21 files changed, 409 insertions(+), 2 deletions(-) create mode 100644 src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/InputCheckOp.java create mode 100644 src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/OnlinePreProcessOp.java create mode 100644 src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/OnlineSolveOp.java create mode 100644 src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/PreProcessOp.java create mode 100644 src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/RandomOp.java create mode 100644 src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/ResultCheckOp.java create mode 100644 src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/ResultPostProcessOp.java create mode 100644 src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/ScaleOp.java create mode 100644 src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/SqrtProcessOp.java create mode 100644 src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/TypeCheckOp.java create mode 100644 src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/TypeOp.java create mode 100644 src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/TypeProcessOp.java create mode 100644 src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/TypeReadOp.java create mode 100644 src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/offlinePreProcessOp.java create mode 100644 src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/offlineSolveOp.java create mode 100644 src/test/java/com/allibaba/compileflow/test/om/branch_graph/common/TypeEnum.java create mode 100644 src/test/java/com/allibaba/compileflow/test/om/branch_graph/common/TypeInfo.java create mode 100644 src/test/resources/bpm/om/branchGraph.bpm diff --git a/scripts/bash-buddy b/scripts/bash-buddy index 1c0efce..bb6ef88 160000 --- a/scripts/bash-buddy +++ b/scripts/bash-buddy @@ -1 +1 @@ -Subproject commit 1c0efce486be6ce182f9c19cdf6977b23edd8c27 +Subproject commit bb6ef887d5f81b982a2c8739a8909f65758b9984 diff --git a/src/main/java/com/alibaba/compileflow/engine/runtime/impl/AbstractProcessRuntime.java b/src/main/java/com/alibaba/compileflow/engine/runtime/impl/AbstractProcessRuntime.java index 02fb41a..68987ff 100644 --- a/src/main/java/com/alibaba/compileflow/engine/runtime/impl/AbstractProcessRuntime.java +++ b/src/main/java/com/alibaba/compileflow/engine/runtime/impl/AbstractProcessRuntime.java @@ -539,7 +539,8 @@ private List buildGatewayFollowingNodes(TransitionNode flowNode) } private List buildBranchNodes(TransitionNode branchNode) { - if (branchGraph.containsKey(branchNode.getId())) { + if (branchGraph.containsKey(branchNode.getId()) && + !branchNode.getIncomingNodes().stream().anyMatch(incomingNode -> incomingNode instanceof GatewayElement)) { return branchGraph.get(branchNode.getId()); } diff --git a/src/test/java/com/allibaba/compileflow/test/ProcessEngineTest.java b/src/test/java/com/allibaba/compileflow/test/ProcessEngineTest.java index 7be8615..0047c65 100644 --- a/src/test/java/com/allibaba/compileflow/test/ProcessEngineTest.java +++ b/src/test/java/com/allibaba/compileflow/test/ProcessEngineTest.java @@ -42,6 +42,19 @@ public void testProcessEngine() { System.out.println(processEngine.execute(code, context)); } + @Test + public void testBranchGraph() { + final String code = "bpm.om.branchGraph"; + Map context = new HashMap(); + Integer input = 16; + Integer compareNumber = 18; + context.put("input", input); + final ProcessEngine processEngine = ProcessEngineFactory.getProcessEngine(); + Map result = processEngine.execute(code, context); + Integer finalResult = (Integer) result.get("finalResult"); + assert (finalResult == compareNumber); + } + @Test public void testProcessEngineBpmn20() { final String code = "bpmn20.ktv.ktvExample"; diff --git a/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/InputCheckOp.java b/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/InputCheckOp.java new file mode 100644 index 0000000..c15c56e --- /dev/null +++ b/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/InputCheckOp.java @@ -0,0 +1,15 @@ +package com.allibaba.compileflow.test.om.branch_graph.calculate; + +public class InputCheckOp { + public InputCheckOp() { + } + + public Boolean process(Integer input) { + Integer compareNumber = 20; + if (input > compareNumber) { + return false; + } else { + return true; + } + } +} diff --git a/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/OnlinePreProcessOp.java b/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/OnlinePreProcessOp.java new file mode 100644 index 0000000..5867bc6 --- /dev/null +++ b/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/OnlinePreProcessOp.java @@ -0,0 +1,12 @@ +package com.allibaba.compileflow.test.om.branch_graph.calculate; + +public class OnlinePreProcessOp { + public OnlinePreProcessOp() { + } + + public Integer process(Integer sqrtResult) { + Integer addNumber = 2; + Integer onlineInput = sqrtResult + addNumber; + return onlineInput; + } +} diff --git a/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/OnlineSolveOp.java b/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/OnlineSolveOp.java new file mode 100644 index 0000000..ea60973 --- /dev/null +++ b/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/OnlineSolveOp.java @@ -0,0 +1,12 @@ +package com.allibaba.compileflow.test.om.branch_graph.calculate; + +public class OnlineSolveOp { + public OnlineSolveOp() { + } + + public Integer process(Integer onlineInput) { + Integer addNumber = 2; + Integer onlineResult = onlineInput + addNumber; + return onlineResult; + } +} diff --git a/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/PreProcessOp.java b/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/PreProcessOp.java new file mode 100644 index 0000000..e54f35d --- /dev/null +++ b/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/PreProcessOp.java @@ -0,0 +1,15 @@ +package com.allibaba.compileflow.test.om.branch_graph.calculate; + +import java.math.BigInteger; + +public class PreProcessOp { + public PreProcessOp() { + } + + public void process(Integer input) { + int compareNumber = 10; + if (input < compareNumber) { + System.out.println("input is smaller than 10"); + } + } +} diff --git a/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/RandomOp.java b/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/RandomOp.java new file mode 100644 index 0000000..d21b57d --- /dev/null +++ b/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/RandomOp.java @@ -0,0 +1,10 @@ +package com.allibaba.compileflow.test.om.branch_graph.calculate; + +public class RandomOp { + public RandomOp() { + } + + public void process(Integer result) { + System.out.println("Random process is finished " + result); + } +} diff --git a/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/ResultCheckOp.java b/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/ResultCheckOp.java new file mode 100644 index 0000000..10efa17 --- /dev/null +++ b/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/ResultCheckOp.java @@ -0,0 +1,14 @@ +package com.allibaba.compileflow.test.om.branch_graph.calculate; + +public class ResultCheckOp { + public ResultCheckOp() { + } + + public Boolean process(Integer result) { + Integer compareNumber = 10; + if (result < compareNumber) { + return true; + } + return false; + } +} diff --git a/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/ResultPostProcessOp.java b/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/ResultPostProcessOp.java new file mode 100644 index 0000000..fc69143 --- /dev/null +++ b/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/ResultPostProcessOp.java @@ -0,0 +1,12 @@ +package com.allibaba.compileflow.test.om.branch_graph.calculate; + +public class ResultPostProcessOp { + public ResultPostProcessOp() { + } + + public Integer process(Integer result) { + Integer addNumber = 10; + Integer finalResult = result + addNumber; + return finalResult; + } +} diff --git a/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/ScaleOp.java b/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/ScaleOp.java new file mode 100644 index 0000000..85a76b4 --- /dev/null +++ b/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/ScaleOp.java @@ -0,0 +1,11 @@ +package com.allibaba.compileflow.test.om.branch_graph.calculate; + +public class ScaleOp { + public ScaleOp() { + } + + public void process(Integer input) { + System.out.printf("%d enter proportion process", input); + } + +} diff --git a/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/SqrtProcessOp.java b/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/SqrtProcessOp.java new file mode 100644 index 0000000..bf40ab8 --- /dev/null +++ b/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/SqrtProcessOp.java @@ -0,0 +1,16 @@ +package com.allibaba.compileflow.test.om.branch_graph.calculate; + +public class SqrtProcessOp { + public SqrtProcessOp() { + } + + public Integer process(Integer input) { + try { + double sqrtResult = Math.sqrt(input); + return (int)sqrtResult; + } catch (Exception e) { + System.out.println("SqrtProcessOp is failed"); + return 0; + } + } +} diff --git a/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/TypeCheckOp.java b/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/TypeCheckOp.java new file mode 100644 index 0000000..b000657 --- /dev/null +++ b/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/TypeCheckOp.java @@ -0,0 +1,13 @@ +package com.allibaba.compileflow.test.om.branch_graph.calculate; + +import com.allibaba.compileflow.test.om.branch_graph.common.TypeInfo; +import com.allibaba.compileflow.test.om.branch_graph.common.TypeEnum; + +public class TypeCheckOp { + public TypeCheckOp() { + } + + public TypeEnum process(TypeInfo typeInfo) { + return typeInfo.getCalculateType(); + } +} diff --git a/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/TypeOp.java b/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/TypeOp.java new file mode 100644 index 0000000..517f717 --- /dev/null +++ b/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/TypeOp.java @@ -0,0 +1,13 @@ +package com.allibaba.compileflow.test.om.branch_graph.calculate; + +import com.allibaba.compileflow.test.om.branch_graph.common.TypeInfo; +import com.allibaba.compileflow.test.om.branch_graph.common.TypeEnum; + +public class TypeOp { + public TypeOp() { + } + + public TypeEnum process(TypeInfo typeInfo) { + return typeInfo.getCalculateType(); + } +} diff --git a/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/TypeProcessOp.java b/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/TypeProcessOp.java new file mode 100644 index 0000000..85831a3 --- /dev/null +++ b/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/TypeProcessOp.java @@ -0,0 +1,23 @@ +package com.allibaba.compileflow.test.om.branch_graph.calculate; + +import com.allibaba.compileflow.test.om.branch_graph.common.TypeInfo; +import com.allibaba.compileflow.test.om.branch_graph.common.TypeEnum; + +public class TypeProcessOp { + public TypeProcessOp() { + } + + public TypeInfo process(Integer sqrtResult) { + Integer compareNumber1 = 5; + Integer compareNumber2 = 100; + TypeInfo typeInfo = new TypeInfo(); + if (sqrtResult < compareNumber1) { + typeInfo.setCalculateType(TypeEnum.ONLINE_SOLVE); + } else if (sqrtResult > compareNumber2) { + typeInfo.setCalculateType(TypeEnum.OFFLINE_SOLVE); + } else { + typeInfo.setCalculateType(TypeEnum.SCALE_SOLVE); + } + return typeInfo; + } +} diff --git a/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/TypeReadOp.java b/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/TypeReadOp.java new file mode 100644 index 0000000..cb7f666 --- /dev/null +++ b/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/TypeReadOp.java @@ -0,0 +1,14 @@ +package com.allibaba.compileflow.test.om.branch_graph.calculate; + +import com.allibaba.compileflow.test.om.branch_graph.common.TypeEnum; + +public class TypeReadOp { + public TypeReadOp() { + } + + public void process(TypeEnum type) { + if (type == TypeEnum.ONLINE_SOLVE || type == TypeEnum.OFFLINE_SOLVE) { + System.out.println("TypeReadOp is processed"); + } + } +} diff --git a/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/offlinePreProcessOp.java b/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/offlinePreProcessOp.java new file mode 100644 index 0000000..9bdf83f --- /dev/null +++ b/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/offlinePreProcessOp.java @@ -0,0 +1,12 @@ +package com.allibaba.compileflow.test.om.branch_graph.calculate; + +public class offlinePreProcessOp { + public offlinePreProcessOp() { + } + + public Integer process(Integer sqrtResult) { + Integer addNumber = 100; + Integer rayInput = sqrtResult + addNumber; + return rayInput; + } +} diff --git a/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/offlineSolveOp.java b/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/offlineSolveOp.java new file mode 100644 index 0000000..4c53764 --- /dev/null +++ b/src/test/java/com/allibaba/compileflow/test/om/branch_graph/calculate/offlineSolveOp.java @@ -0,0 +1,12 @@ +package com.allibaba.compileflow.test.om.branch_graph.calculate; + +public class offlineSolveOp { + public offlineSolveOp() { + } + + public Integer process(Integer offlineInput) { + Integer addNumber = 200; + Integer rayResult = offlineInput + addNumber; + return rayResult; + } +} diff --git a/src/test/java/com/allibaba/compileflow/test/om/branch_graph/common/TypeEnum.java b/src/test/java/com/allibaba/compileflow/test/om/branch_graph/common/TypeEnum.java new file mode 100644 index 0000000..21c9d3d --- /dev/null +++ b/src/test/java/com/allibaba/compileflow/test/om/branch_graph/common/TypeEnum.java @@ -0,0 +1,10 @@ +package com.allibaba.compileflow.test.om.branch_graph.common; + +public enum TypeEnum { + SCALE_SOLVE, + ONLINE_SOLVE, + OFFLINE_SOLVE; + + private TypeEnum() { + } +} diff --git a/src/test/java/com/allibaba/compileflow/test/om/branch_graph/common/TypeInfo.java b/src/test/java/com/allibaba/compileflow/test/om/branch_graph/common/TypeInfo.java new file mode 100644 index 0000000..43dd0a8 --- /dev/null +++ b/src/test/java/com/allibaba/compileflow/test/om/branch_graph/common/TypeInfo.java @@ -0,0 +1,18 @@ +package com.allibaba.compileflow.test.om.branch_graph.common; + +import com.allibaba.compileflow.test.om.branch_graph.common.TypeEnum; + +public class TypeInfo { + private TypeEnum calculateType; + + public TypeInfo() { + } + + public void setCalculateType(TypeEnum type) { + calculateType = type; + } + + public TypeEnum getCalculateType() { + return calculateType; + } +} diff --git a/src/test/resources/bpm/om/branchGraph.bpm b/src/test/resources/bpm/om/branchGraph.bpm new file mode 100644 index 0000000..ac5c5ad --- /dev/null +++ b/src/test/resources/bpm/om/branchGraph.bpm @@ -0,0 +1,161 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +