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 25, 2022
1 parent 9c87a39 commit 5b717f8
Show file tree
Hide file tree
Showing 21 changed files with 409 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.branchGraph";
Map<String, Object> context = new HashMap<String, Object>();
Integer input = 16;
Integer compareNumber = 18;
context.put("input", input);
final ProcessEngine processEngine = ProcessEngineFactory.getProcessEngine();
Map<String, Object> result = processEngine.execute(code, context);
Integer finalResult = (Integer) result.get("finalResult");
assert (finalResult == compareNumber);
}

@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(Integer input) {
Integer 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 Integer process(Integer sqrtResult) {
Integer addNumber = 2;
Integer 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 Integer process(Integer onlineInput) {
Integer addNumber = 2;
Integer 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(Integer 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(Integer result) {
System.out.println("Random process is finished " + result);
}
}
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(Integer result) {
Integer 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 Integer process(Integer result) {
Integer addNumber = 10;
Integer finalResult = result + addNumber;
return finalResult;
}
}
Original file line number Diff line number Diff line change
@@ -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);
}

}
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 Integer process(Integer 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.TypeInfo;
import com.allibaba.compileflow.test.om.branch_graph.common.TypeEnum;

public class TypeCheckOp {
public TypeCheckOp() {
}

public TypeEnum process(TypeInfo typeInfo) {
return typeInfo.getCalculateType();
}
}
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.TypeInfo;
import com.allibaba.compileflow.test.om.branch_graph.common.TypeEnum;

public class TypeOp {
public TypeOp() {
}

public TypeEnum process(TypeInfo typeInfo) {
return typeInfo.getCalculateType();
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
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 TypeReadOp {
public TypeReadOp() {
}

public void process(TypeEnum type) {
if (type == TypeEnum.ONLINE_SOLVE || type == TypeEnum.OFFLINE_SOLVE) {
System.out.println("TypeReadOp is processed");
}
}
}
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 offlinePreProcessOp {
public offlinePreProcessOp() {
}

public Integer process(Integer sqrtResult) {
Integer addNumber = 100;
Integer 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 offlineSolveOp {
public offlineSolveOp() {
}

public Integer process(Integer offlineInput) {
Integer addNumber = 200;
Integer rayResult = offlineInput + addNumber;
return rayResult;
}
}
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 {
SCALE_SOLVE,
ONLINE_SOLVE,
OFFLINE_SOLVE;

private TypeEnum() {
}
}
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 TypeInfo {
private TypeEnum calculateType;

public TypeInfo() {
}

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

public TypeEnum getCalculateType() {
return calculateType;
}
}

0 comments on commit 5b717f8

Please sign in to comment.