Skip to content

Commit

Permalink
fix a bug of branchGraph cache with test_case
Browse files Browse the repository at this point in the history
  • Loading branch information
lvcangquan.lcq committed Apr 12, 2022
1 parent 9c87a39 commit c291f7e
Show file tree
Hide file tree
Showing 19 changed files with 365 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,8 @@ private List<TransitionNode> buildGatewayFollowingNodes(TransitionNode flowNode)
}

private List<TransitionNode> 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());
}

Expand Down
13 changes: 13 additions & 0 deletions src/test/java/com/allibaba/compileflow/test/ProcessEngineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ public void testProcessEngine() {
System.out.println(processEngine.execute(code, context));
}

@Test
public void testBranchGraph() {
final String code = "bpm.om.branchGraphTest";
Map<String, Object> context = new HashMap<String, Object>();
int input = 16;
int finalResult = -1;
context.put("input", input);
context.put("finalResult", finalResult);
final ProcessEngine processEngine = ProcessEngineFactory.getProcessEngine();
processEngine.execute(code, context);
//todo
}

@Test
public void testProcessEngineBpmn20() {
final String code = "bpmn20.ktv.ktvExample";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.allibaba.compileflow.test.om.branch_graph.calculate;

public class InputCheckOp {
public InputCheckOp() {
}

public Boolean process(int input) {
int compareNumber = 20;
if (input > compareNumber) {
return false;
} else {
return true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.allibaba.compileflow.test.om.branch_graph.calculate;

public class OnlinePreProcessOp {
public OnlinePreProcessOp() {
}

public int process(int sqrtResult) {
int addNumber = 2;
int onlineInput = sqrtResult + addNumber;
return onlineInput;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.allibaba.compileflow.test.om.branch_graph.calculate;

public class OnlineSolveOp {
public OnlineSolveOp() {
}

public int process(int onlineInput) {
int addNumber = 2;
int onlineResult = onlineInput + addNumber;
return onlineResult;
}
}
Original file line number Diff line number Diff line change
@@ -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(int input) {
int compareNumber = 10;
if (input < compareNumber) {
System.out.println("input is smaller than 10");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.allibaba.compileflow.test.om.branch_graph.calculate;

public class RandomOp {
public RandomOp() {
}

public void process(int result) {
System.out.println("Random process is finished");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.allibaba.compileflow.test.om.branch_graph.calculate;

public class RayPreProcessOp {
public RayPreProcessOp () {
}

public int process(int sqrtResult) {
int addNumber = 100;
int rayInput = sqrtResult + addNumber;
return rayInput;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.allibaba.compileflow.test.om.branch_graph.calculate;

public class RaySolveOp {
public RaySolveOp() {
}

public int process(int rayInput) {
int addNumber = 200;
int rayResult = rayInput + addNumber;
return rayResult;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.allibaba.compileflow.test.om.branch_graph.calculate;

public class ResultCheckOp {
public ResultCheckOp() {
}

public Boolean process(int result) {
int compareNumber = 10;
if (result < compareNumber) {
return true;
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.allibaba.compileflow.test.om.branch_graph.calculate;

public class ResultPostProcessOp {
public ResultPostProcessOp() {
}

public int process(int result) {
int addNumber = 10;
int finalResult = result + addNumber;
return finalResult;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.allibaba.compileflow.test.om.branch_graph.calculate;

import com.allibaba.compileflow.test.om.branch_graph.common.RouteInfo;
import com.allibaba.compileflow.test.om.branch_graph.common.TypeEnum;

public class RouteOp {
public RouteOp() {
}

public RouteInfo process(int sqrtResult) {
int compareNumber = 5;
RouteInfo routeInfo = new RouteInfo();
if (sqrtResult < compareNumber) {
routeInfo.setCalculateType(TypeEnum.ONLINE_SOLVE);
} else {
routeInfo.setCalculateType(TypeEnum.RAY_SOLVE);
}
return routeInfo;
}
}
Original file line number Diff line number Diff line change
@@ -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 RouteReadOp {
public RouteReadOp() {
}

public void process(TypeEnum type) {
if (type == TypeEnum.ONLINE_SOLVE || type == TypeEnum.RAY_SOLVE) {
System.out.println("RouteReadOp is processed");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.allibaba.compileflow.test.om.branch_graph.calculate;

public class SqrtProcessOp {
public SqrtProcessOp() {
}

public int process(int input) {
try {
double sqrtResult = Math.sqrt(input);
return (int)sqrtResult;
} catch (Exception e) {
System.out.println("SqrtProcessOp is failed");
return 0;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.allibaba.compileflow.test.om.branch_graph.calculate;

import com.allibaba.compileflow.test.om.branch_graph.common.RouteInfo;
import com.allibaba.compileflow.test.om.branch_graph.common.TypeEnum;

public class TypeOp {
public TypeOp() {
}

public TypeEnum process(RouteInfo routeInfo) {
return routeInfo.getCalculateType();
}
}
Original file line number Diff line number Diff line change
@@ -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 RouteInfo {
private TypeEnum calculateType;

public RouteInfo() {
}

public void setCalculateType(TypeEnum type) {
calculateType = type;
}

public TypeEnum getCalculateType() {
return calculateType;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.allibaba.compileflow.test.om.branch_graph.common;

public enum TypeEnum {
RANDOM,
ONLINE_SOLVE,
RAY_SOLVE;

private TypeEnum() {
}
}
144 changes: 144 additions & 0 deletions src/test/resources/bpm/om/branchGraphTest.bpm
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpm code="bpm.BranchGraphTest.bpm" name="test" type="process" description="This is test demo.">
<var name="num" description="入参" dataType="java.lang.Double" inOutType="param"></var>
<var name="numSqrt" description="开根号结果" dataType="java.lang.Double" inOutType="return"></var>
<autoTask id="1649679494823" name="读取路由" g="125,410,90,50">
<transition to="1649680231918"></transition>
<action type="java">
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.calculate.RouteReadOp" method="process">
<var name="type" description="路由类型" dataType="com.allibaba.compileflow.test.om.branch_graph.common.TypeEnum" contextVarName="typeEnum" inOutType="param"></var>
</actionHandle>
</action>
</autoTask>
<autoTask id="1649681928894" name="Random" g="65,890,90,50">
<transition to="1649681877600"></transition>
<action type="java">
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.calculate.RandomOp" method="process">
<var name="result" description="计算结果" dataType="java.lang.Integer" inOutType="param"></var>
</actionHandle>
</action>
</autoTask>
<autoTask id="1649680235723" name="Online预处理" g="335,620,90,50">
<transition to="1649681645436"></transition>
<action type="java">
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.calculate.OnlinePreProcessOp" method="process">
<var name="sqrtResult" description="平方根" dataType="java.lang.Integer" contextVarName="sqrtResult" inOutType="param"></var>
<var name="onlineInput" description="online输入" dataType="java.lang.Integer" contextVarName="onlineInput" inOutType="return"></var>
</actionHandle>
</action>
</autoTask>
<autoTask id="1649681641648" name="RaySolve" g="125,710,90,50">
<transition to="1649681814271"></transition>
<action type="java">
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.calculate.RaySolveOp" method="process">
<var name="rayInput" description="ray输入" dataType="java.lang.Integer" contextVarName="rayInput" inOutType="param"></var>
<var name="result" description="求解结果" dataType="java.lang.Integer" contextVarName="result" inOutType="return"></var>
</actionHandle>
</action>
</autoTask>
<decision id="1649681345582" name="判断节点" g="125,570,90,50">
<transition to="1649680235723" name="" expression="false"></transition>
<transition to="1649681641648" priority="1" name="" expression="true"></transition>
<action type="java">
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.calculate.TypeOp" method="process">
<var name="routeInfo" description="路由信息" dataType="com.allibaba.compileflow.test.om.branch_graph.common.RouteInfo" contextVarName="routeInfo" inOutType="param"></var>
<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>
</actionHandle>
</action>
</decision>
<autoTask id="1649681645436" name="OnlineSolve" g="335,710,90,50">
<transition to="1649681814271"></transition>
<action type="java">
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.calculate.OnlineSolveOp" method="process">
<var name="onlineInput" description="online输入" dataType="java.lang.Integer" contextVarName="onlineInput" inOutType="param"></var>
<var name="result" description="求解结果" dataType="java.lang.Integer" contextVarName="result" inOutType="return"></var>
</actionHandle>
</action>
</autoTask>
<autoTask id="1649674277421" name="预处理" g="220,35,90,50">
<transition to="1649675887756"></transition>
<action type="java">
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.calculate.PreProcessOp" method="process">
<var name="input" description="input输入" dataType="java.lang.Integer" contextVarName="input" inOutType="param"></var>
</actionHandle>
</action>
</autoTask>
<autoTask id="1649680231918" name="Ray预处理" g="125,490,90,50">
<transition to="1649681345582"></transition>
<action type="java">
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.calculate.RayPreProcessOp" method="process">
<var name="sqrtResult" description="平方根" dataType="java.lang.Integer" contextVarName="sqrtResult" inOutType="param"></var>
<var name="rayInput" description="ray的输入" dataType="java.lang.Integer" contextVarName="rayInput" inOutType="return"></var>
</actionHandle>
</action>
</autoTask>
<autoTask id="1649681877600" name="结果后处理" g="235,890,90,50">
<transition to="11"></transition>
<action type="java">
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.calculate.ResultPostProcessOp" method="process">
<var name="result" description="计算结果" dataType="java.lang.Integer" contextVarName="result" inOutType="param"></var>
<var name="finalResult" description="后处理结果" dataType="java.lang.Integer" contextVarName="finalResult" inOutType="return"></var>
</actionHandle>
</action>
</autoTask>
<autoTask id="1649679497675" name="读取路由" g="335,410,90,50">
<transition to="1649680235723"></transition>
<action type="java">
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.calculate.RouteReadOp" method="process">
<var name="type" description="路由类型" dataType="com.allibaba.compileflow.test.om.branch_graph.common.TypeEnum" contextVarName="typeEnum" inOutType="param"></var>
</actionHandle>
</action>
</autoTask>
<start id="1" name="开始" g="120,45,30,30">
<transition to="1649674277421"></transition>
</start>
<end id="11" name="结束" g="545,480,30,30"></end>
<autoTask id="17" name="计算平方根" g="235,150,88,48">
<transition to="1649677184728"></transition>
<action type="java">
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.calculate.SqrtProcessOp" method="process">
<var name="input" description="input输入" dataType="java.lang.Integer" contextVarName="input" inOutType="param"></var>
<var name="sqrtResult" description="平方根" dataType="java.lang.Integer" contextVarName="sqrtResult" inOutType="return"></var>
</actionHandle>
</action>
</autoTask>
<decision id="1649681814271" name="判断节点" g="230,790,90,50">
<transition to="1649681928894" name="" expression="!resultCheck"></transition>
<transition to="1649681877600" priority="1" name="" expression="resultCheck"></transition>
<action type="java">
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.calculate.ResultCheckOp" method="process">
<var name="result" description="结果" dataType="java.lang.Integer" contextVarName="result" inOutType="param"></var>
<var name="resultCheck" description="结果检查" dataType="java.lang.Boolean" contextVarName="resultCheck" inOutType="return"></var>
</actionHandle>
</action>
</decision>
<autoTask id="1649677184728" name="设置计算路由信息" g="215,235,130,50">
<transition to="1649678893514"></transition>
<action type="java">
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.calculate.RouteOp" method="process">
<var name="sqrtResult" description="平方根" dataType="java.lang.Integer" contextVarName="sqrtResult" inOutType="param"></var>
<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>
</actionHandle>
</action>
</autoTask>
<decision id="1649678893514" name="计算路由" g="235,330,90,50">
<transition to="1649679494823" priority="1" name="isRay" expression="com.allibaba.compileflow.test.om.branch_graph.common.TypeEnum.RAY_SOLVE.equals(typeEnum)"></transition>
<transition to="1649679497675" priority="2" name="isOnline" expression="com.allibaba.compileflow.test.om.branch_graph.common.TypeEnum.ONLINE_SOLVE.equals(typeEnum)"></transition>
<action type="java">
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.calculate.TypeOp" method="process">
<var name="routeInfo" description="路由信息" dataType="com.allibaba.compileflow.test.om.branch_graph.common.RouteInfo" contextVarName="routeInfo" inOutType="param"></var>
<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>
</actionHandle>
</action>
</decision>
<autoTask id="1649675887756" name="输入检查" g="370,85,90,50">
<transition to="11" priority="1" name="" expression="!inputCheck"></transition>
<transition to="17" name="" expression="inputCheck"></transition>
<action type="java">
<actionHandle clazz="com.allibaba.compileflow.test.om.branch_graph.calculate.InputCheckOp" method="process">
<var name="input" description="input输入" dataType="java.lang.Integer" contextVarName="input" inOutType="param"></var>
<var name="inputCheck" description="输入检查" dataType="java.lang.Boolean" contextVarName="inputCheck" inOutType="return"></var>
</actionHandle>
</action>
</autoTask>
</bpm>

0 comments on commit c291f7e

Please sign in to comment.