bug #I5HBJC 当有并行子流程的时候,获取当前chainName有bug

This commit is contained in:
everywhere.z
2022-07-16 00:55:42 +08:00
parent 85389a9975
commit 8c5bcd269b
53 changed files with 1230 additions and 19 deletions

View File

@@ -42,16 +42,6 @@ public abstract class Condition implements Executable{
//如果对于子流程来说那这个就是子流程所在的Chain
private String currChainName;
@Override
public void execute(Integer slotIndex) throws Exception {
String currChainName = this.getCurrChainName();
//设置当前ChainName
this.getExecutableList().forEach(executable -> executable.setCurrChainName(currChainName));
executeCondition(slotIndex);
}
protected abstract void executeCondition(Integer slotIndex) throws Exception;
@Override
public ExecuteTypeEnum getExecuteType() {
return ExecuteTypeEnum.CONDITION;

View File

@@ -18,8 +18,9 @@ import com.yomahub.liteflow.flow.element.Executable;
public class FinallyCondition extends Condition {
@Override
public void executeCondition(Integer slotIndex) throws Exception {
public void execute(Integer slotIndex) throws Exception {
for(Executable executableItem : this.getExecutableList()){
executableItem.setCurrChainName(this.getCurrChainName());
executableItem.execute(slotIndex);
}
}

View File

@@ -18,8 +18,9 @@ import com.yomahub.liteflow.flow.element.Executable;
public class PreCondition extends Condition {
@Override
public void executeCondition(Integer slotIndex) throws Exception {
public void execute(Integer slotIndex) throws Exception {
for(Executable executableItem : this.getExecutableList()){
executableItem.setCurrChainName(this.getCurrChainName());
executableItem.execute(slotIndex);
}
}

View File

@@ -26,9 +26,10 @@ public class SwitchCondition extends Condition{
private final Map<String, Executable> targetMap = new HashMap<>();
@Override
public void executeCondition(Integer slotIndex) throws Exception {
public void execute(Integer slotIndex) throws Exception {
if (ListUtil.toList(NodeTypeEnum.SWITCH, NodeTypeEnum.SWITCH_SCRIPT).contains(this.getSwitchNode().getType())){
//先执行switch节点
this.getSwitchNode().setCurrChainName(this.getCurrChainName());
this.getSwitchNode().execute(slotIndex);
//根据switch节点执行出来的结果选择

View File

@@ -21,12 +21,13 @@ public class ThenCondition extends Condition {
}
@Override
public void executeCondition(Integer slotIndex) throws Exception {
public void execute(Integer slotIndex) throws Exception {
for (Executable executableItem : this.getExecutableList()) {
//前置和后置组不执行因为在build的时候会抽出来放在chain里面
if (executableItem instanceof PreCondition || executableItem instanceof FinallyCondition){
continue;
}
executableItem.setCurrChainName(this.getCurrChainName());
executableItem.execute(slotIndex);
}
}

View File

@@ -37,7 +37,7 @@ public class WhenCondition extends Condition {
@Override
public void executeCondition(Integer slotIndex) throws Exception {
public void execute(Integer slotIndex) throws Exception {
executeAsyncCondition(slotIndex);
}
@@ -51,6 +51,8 @@ public class WhenCondition extends Condition {
private void executeAsyncCondition(Integer slotIndex) throws Exception{
Slot slot = DataBus.getSlot(slotIndex);
String currChainName = this.getCurrChainName();
//此方法其实只会初始化一次Executor不会每次都会初始化。Executor是唯一的
ExecutorService parallelExecutor = ExecutorHelper.loadInstance().buildWhenExecutor(this.getThreadExecutorClass());
@@ -78,7 +80,7 @@ public class WhenCondition extends Condition {
}
}).map(executable -> CompletableFutureTimeout.completeOnTimeout(
WhenFutureObj.timeOut(executable.getExecuteName()),
CompletableFuture.supplyAsync(new ParallelSupplier(executable, slotIndex), parallelExecutor),
CompletableFuture.supplyAsync(new ParallelSupplier(executable, currChainName, slotIndex), parallelExecutor),
liteflowConfig.getWhenMaxWaitSeconds(),
TimeUnit.SECONDS
)).collect(Collectors.toList());

View File

@@ -16,16 +16,20 @@ public class ParallelSupplier implements Supplier<WhenFutureObj> {
private final Executable executableItem;
private final String currChainName;
private final Integer slotIndex;
public ParallelSupplier(Executable executableItem, Integer slotIndex) {
public ParallelSupplier(Executable executableItem, String currChainName, Integer slotIndex) {
this.executableItem = executableItem;
this.currChainName = currChainName;
this.slotIndex = slotIndex;
}
@Override
public WhenFutureObj get() {
try {
executableItem.setCurrChainName(currChainName);
executableItem.execute(slotIndex);
return WhenFutureObj.success(executableItem.getExecuteName());
} catch (Exception e){

View File

@@ -0,0 +1,60 @@
package com.yomahub.liteflow.test.getChainName;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.slot.DefaultContext;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
/**
* springboot环境获取ChainName的测试
* @author Bryan.Zhang
*/
@RunWith(SpringRunner.class)
@TestPropertySource(value = "classpath:/getChainName/application.properties")
@SpringBootTest(classes = GetChainNameELDeclSpringbootTest.class)
@EnableAutoConfiguration
@ComponentScan({"com.yomahub.liteflow.test.getChainName.cmp"})
public class GetChainNameELDeclSpringbootTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
@Test
public void testGetChainName1() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
DefaultContext context = response.getFirstContextBean();
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("sub1", context.getData("a"));
Assert.assertEquals("sub2", context.getData("b"));
Assert.assertEquals("sub3", context.getData("c"));
Assert.assertEquals("sub4", context.getData("d"));
}
@Test
public void testGetChainName2() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
DefaultContext context = response.getFirstContextBean();
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("chain2", context.getData("g"));
Assert.assertEquals("sub1", context.getData("a"));
Assert.assertEquals("sub2", context.getData("b"));
Assert.assertEquals("sub3", context.getData("c"));
Assert.assertEquals("sub4", context.getData("d"));
Assert.assertEquals("sub5", context.getData("f"));
Assert.assertEquals("sub5_chain2", context.getData("e"));
Assert.assertEquals("sub6", context.getData("h"));
Assert.assertEquals("sub6", context.getData("j"));
Assert.assertNull(context.getData("k"));
}
}

View File

@@ -0,0 +1,26 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getChainName.cmp;
import com.yomahub.liteflow.annotation.LiteflowCmpDefine;
import com.yomahub.liteflow.annotation.LiteflowMethod;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
import com.yomahub.liteflow.slot.DefaultContext;
import org.springframework.stereotype.Component;
@Component("a")
@LiteflowCmpDefine
public class ACmp{
@LiteflowMethod(LiteFlowMethodEnum.PROCESS)
public void process(NodeComponent bindCmp) {
DefaultContext context = bindCmp.getFirstContextBean();
context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainName());
}
}

View File

@@ -0,0 +1,26 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getChainName.cmp;
import com.yomahub.liteflow.annotation.LiteflowCmpDefine;
import com.yomahub.liteflow.annotation.LiteflowMethod;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
import com.yomahub.liteflow.slot.DefaultContext;
import org.springframework.stereotype.Component;
@Component("b")
@LiteflowCmpDefine
public class BCmp {
@LiteflowMethod(LiteFlowMethodEnum.PROCESS)
public void process(NodeComponent bindCmp) {
DefaultContext context = bindCmp.getFirstContextBean();
context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainName());
}
}

View File

@@ -0,0 +1,26 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getChainName.cmp;
import com.yomahub.liteflow.annotation.LiteflowCmpDefine;
import com.yomahub.liteflow.annotation.LiteflowMethod;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
import com.yomahub.liteflow.slot.DefaultContext;
import org.springframework.stereotype.Component;
@Component("c")
@LiteflowCmpDefine
public class CCmp {
@LiteflowMethod(LiteFlowMethodEnum.PROCESS)
public void process(NodeComponent bindCmp) {
DefaultContext context = bindCmp.getFirstContextBean();
context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainName());
}
}

View File

@@ -0,0 +1,26 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getChainName.cmp;
import com.yomahub.liteflow.annotation.LiteflowCmpDefine;
import com.yomahub.liteflow.annotation.LiteflowMethod;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
import com.yomahub.liteflow.slot.DefaultContext;
import org.springframework.stereotype.Component;
@Component("d")
@LiteflowCmpDefine
public class DCmp {
@LiteflowMethod(LiteFlowMethodEnum.PROCESS)
public void process(NodeComponent bindCmp) {
DefaultContext context = bindCmp.getFirstContextBean();
context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainName());
}
}

View File

@@ -0,0 +1,30 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getChainName.cmp;
import com.yomahub.liteflow.annotation.LiteflowCmpDefine;
import com.yomahub.liteflow.annotation.LiteflowMethod;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
import com.yomahub.liteflow.slot.DefaultContext;
import org.springframework.stereotype.Component;
@Component("e")
@LiteflowCmpDefine
public class ECmp {
@LiteflowMethod(LiteFlowMethodEnum.PROCESS)
public void process(NodeComponent bindCmp) {
DefaultContext context = bindCmp.getFirstContextBean();
if (context.hasData(bindCmp.getNodeId())){
context.setData(bindCmp.getNodeId(), context.getData(bindCmp.getNodeId()) + "_" + bindCmp.getCurrChainName());
}else{
context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainName());
}
}
}

View File

@@ -0,0 +1,26 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getChainName.cmp;
import com.yomahub.liteflow.annotation.LiteflowCmpDefine;
import com.yomahub.liteflow.annotation.LiteflowMethod;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
import com.yomahub.liteflow.slot.DefaultContext;
import org.springframework.stereotype.Component;
@Component("f")
@LiteflowCmpDefine
public class FCmp {
@LiteflowMethod(LiteFlowMethodEnum.PROCESS)
public void process(NodeComponent bindCmp) {
DefaultContext context = bindCmp.getFirstContextBean();
context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainName());
}
}

View File

@@ -0,0 +1,26 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getChainName.cmp;
import com.yomahub.liteflow.annotation.LiteflowCmpDefine;
import com.yomahub.liteflow.annotation.LiteflowMethod;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
import com.yomahub.liteflow.slot.DefaultContext;
import org.springframework.stereotype.Component;
@Component("g")
@LiteflowCmpDefine
public class GCmp {
@LiteflowMethod(LiteFlowMethodEnum.PROCESS)
public void process(NodeComponent bindCmp) {
DefaultContext context = bindCmp.getFirstContextBean();
context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainName());
}
}

View File

@@ -0,0 +1,29 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getChainName.cmp;
import com.yomahub.liteflow.annotation.LiteflowMethod;
import com.yomahub.liteflow.annotation.LiteflowSwitchCmpDefine;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.core.NodeSwitchComponent;
import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
import com.yomahub.liteflow.slot.DefaultContext;
import org.springframework.stereotype.Component;
@Component("h")
@LiteflowSwitchCmpDefine
public class HCmp{
@LiteflowMethod(LiteFlowMethodEnum.PROCESS_SWITCH)
public String processSwitch(NodeComponent bindCmp) throws Exception {
DefaultContext context = bindCmp.getFirstContextBean();
context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainName());
return "j";
}
}

View File

@@ -0,0 +1,26 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getChainName.cmp;
import com.yomahub.liteflow.annotation.LiteflowCmpDefine;
import com.yomahub.liteflow.annotation.LiteflowMethod;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
import com.yomahub.liteflow.slot.DefaultContext;
import org.springframework.stereotype.Component;
@Component("j")
@LiteflowCmpDefine
public class JCmp {
@LiteflowMethod(LiteFlowMethodEnum.PROCESS)
public void process(NodeComponent bindCmp) {
DefaultContext context = bindCmp.getFirstContextBean();
context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainName());
}
}

View File

@@ -0,0 +1,26 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getChainName.cmp;
import com.yomahub.liteflow.annotation.LiteflowCmpDefine;
import com.yomahub.liteflow.annotation.LiteflowMethod;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
import com.yomahub.liteflow.slot.DefaultContext;
import org.springframework.stereotype.Component;
@Component("k")
@LiteflowCmpDefine
public class KCmp {
@LiteflowMethod(LiteFlowMethodEnum.PROCESS)
public void process(NodeComponent bindCmp) {
DefaultContext context = bindCmp.getFirstContextBean();
context.setData(bindCmp.getNodeId(), bindCmp.getCurrChainName());
}
}

View File

@@ -0,0 +1 @@
liteflow.rule-source=getChainName/flow.el.xml

View File

@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<chain name="chain1">
WHEN(sub1, sub2, sub3, sub4);
</chain>
<chain name="sub1">
THEN(a);
</chain>
<chain name="sub2">
THEN(b);
</chain>
<chain name="sub3">
THEN(c);
</chain>
<chain name="sub4">
THEN(d);
</chain>
<chain name="sub5">
THEN(e, f);
</chain>
<chain name="sub6">
SWITCH(h).to(j, k);
</chain>
<chain name="chain2">
THEN(
g,
WHEN(sub1, WHEN(sub2, sub3)),
sub4, sub5, e, sub6
);
</chain>
</flow>

View File

@@ -0,0 +1,56 @@
package com.yomahub.liteflow.test.getChainName;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.slot.DefaultContext;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* nospring环境获取ChainName的测试
* @author Bryan.Zhang
*/
public class GetChainNameELTest extends BaseTest {
private static FlowExecutor flowExecutor;
@BeforeClass
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("getChainName/flow.el.xml");
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
@Test
public void testGetChainName1() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
DefaultContext context = response.getFirstContextBean();
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("sub1", context.getData("a"));
Assert.assertEquals("sub2", context.getData("b"));
Assert.assertEquals("sub3", context.getData("c"));
Assert.assertEquals("sub4", context.getData("d"));
}
@Test
public void testGetChainName2() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
DefaultContext context = response.getFirstContextBean();
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("chain2", context.getData("g"));
Assert.assertEquals("sub1", context.getData("a"));
Assert.assertEquals("sub2", context.getData("b"));
Assert.assertEquals("sub3", context.getData("c"));
Assert.assertEquals("sub4", context.getData("d"));
Assert.assertEquals("sub5", context.getData("f"));
Assert.assertEquals("sub5_chain2", context.getData("e"));
Assert.assertEquals("sub6", context.getData("h"));
Assert.assertEquals("sub6", context.getData("j"));
Assert.assertNull(context.getData("k"));
}
}

View File

@@ -0,0 +1,20 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getChainName.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
public class ACmp extends NodeComponent {
@Override
public void process() {
DefaultContext context = this.getFirstContextBean();
context.setData(this.getNodeId(), this.getCurrChainName());
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getChainName.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
public class BCmp extends NodeComponent {
@Override
public void process() {
DefaultContext context = this.getFirstContextBean();
context.setData(this.getNodeId(), this.getCurrChainName());
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getChainName.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
public class CCmp extends NodeComponent {
@Override
public void process() {
DefaultContext context = this.getFirstContextBean();
context.setData(this.getNodeId(), this.getCurrChainName());
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getChainName.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
public class DCmp extends NodeComponent {
@Override
public void process() {
DefaultContext context = this.getFirstContextBean();
context.setData(this.getNodeId(), this.getCurrChainName());
}
}

View File

@@ -0,0 +1,25 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getChainName.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
public class ECmp extends NodeComponent {
@Override
public void process() {
DefaultContext context = this.getFirstContextBean();
if (context.hasData(this.getNodeId())){
context.setData(this.getNodeId(), context.getData(this.getNodeId()) + "_" + this.getCurrChainName());
}else{
context.setData(this.getNodeId(), this.getCurrChainName());
}
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getChainName.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
public class FCmp extends NodeComponent {
@Override
public void process() {
DefaultContext context = this.getFirstContextBean();
context.setData(this.getNodeId(), this.getCurrChainName());
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getChainName.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
public class GCmp extends NodeComponent {
@Override
public void process() {
DefaultContext context = this.getFirstContextBean();
context.setData(this.getNodeId(), this.getCurrChainName());
}
}

View File

@@ -0,0 +1,22 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getChainName.cmp;
import com.yomahub.liteflow.core.NodeSwitchComponent;
import com.yomahub.liteflow.slot.DefaultContext;
public class HCmp extends NodeSwitchComponent {
@Override
public String processSwitch() throws Exception {
DefaultContext context = this.getFirstContextBean();
context.setData(this.getNodeId(), this.getCurrChainName());
return "j";
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getChainName.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
public class JCmp extends NodeComponent {
@Override
public void process() {
DefaultContext context = this.getFirstContextBean();
context.setData(this.getNodeId(), this.getCurrChainName());
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getChainName.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
public class KCmp extends NodeComponent {
@Override
public void process() {
DefaultContext context = this.getFirstContextBean();
context.setData(this.getNodeId(), this.getCurrChainName());
}
}

View File

@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<nodes>
<node id="a" class="com.yomahub.liteflow.test.getChainName.cmp.ACmp"/>
<node id="b" class="com.yomahub.liteflow.test.getChainName.cmp.BCmp"/>
<node id="c" class="com.yomahub.liteflow.test.getChainName.cmp.CCmp"/>
<node id="d" class="com.yomahub.liteflow.test.getChainName.cmp.DCmp"/>
<node id="e" class="com.yomahub.liteflow.test.getChainName.cmp.ECmp"/>
<node id="f" class="com.yomahub.liteflow.test.getChainName.cmp.FCmp"/>
<node id="g" class="com.yomahub.liteflow.test.getChainName.cmp.GCmp"/>
<node id="h" class="com.yomahub.liteflow.test.getChainName.cmp.HCmp"/>
<node id="j" class="com.yomahub.liteflow.test.getChainName.cmp.JCmp"/>
<node id="k" class="com.yomahub.liteflow.test.getChainName.cmp.KCmp"/>
</nodes>
<chain name="chain1">
WHEN(sub1, sub2, sub3, sub4);
</chain>
<chain name="sub1">
THEN(a);
</chain>
<chain name="sub2">
THEN(b);
</chain>
<chain name="sub3">
THEN(c);
</chain>
<chain name="sub4">
THEN(d);
</chain>
<chain name="sub5">
THEN(e, f);
</chain>
<chain name="sub6">
SWITCH(h).to(j, k);
</chain>
<chain name="chain2">
THEN(
g,
WHEN(sub1, WHEN(sub2, sub3)),
sub4, sub5, e, sub6
);
</chain>
</flow>

View File

@@ -16,7 +16,7 @@ import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
/**
* springboot环境EL常规的例子测试
* springboot环境获取ChainName的测试
* @author Bryan.Zhang
*/
@RunWith(SpringRunner.class)
@@ -29,7 +29,6 @@ public class GetChainNameELSpringbootTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
//最简单的情况
@Test
public void testGetChainName1() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
@@ -41,4 +40,21 @@ public class GetChainNameELSpringbootTest extends BaseTest {
Assert.assertEquals("sub4", context.getData("d"));
}
@Test
public void testGetChainName2() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
DefaultContext context = response.getFirstContextBean();
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("chain2", context.getData("g"));
Assert.assertEquals("sub1", context.getData("a"));
Assert.assertEquals("sub2", context.getData("b"));
Assert.assertEquals("sub3", context.getData("c"));
Assert.assertEquals("sub4", context.getData("d"));
Assert.assertEquals("sub5", context.getData("f"));
Assert.assertEquals("sub5_chain2", context.getData("e"));
Assert.assertEquals("sub6", context.getData("h"));
Assert.assertEquals("sub6", context.getData("j"));
Assert.assertNull(context.getData("k"));
}
}

View File

@@ -0,0 +1,27 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getChainName.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
import org.springframework.stereotype.Component;
@Component("e")
public class ECmp extends NodeComponent {
@Override
public void process() {
DefaultContext context = this.getFirstContextBean();
if (context.hasData(this.getNodeId())){
context.setData(this.getNodeId(), context.getData(this.getNodeId()) + "_" + this.getCurrChainName());
}else{
context.setData(this.getNodeId(), this.getCurrChainName());
}
}
}

View File

@@ -0,0 +1,23 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getChainName.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
import org.springframework.stereotype.Component;
@Component("f")
public class FCmp extends NodeComponent {
@Override
public void process() {
DefaultContext context = this.getFirstContextBean();
context.setData(this.getNodeId(), this.getCurrChainName());
}
}

View File

@@ -0,0 +1,23 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getChainName.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
import org.springframework.stereotype.Component;
@Component("g")
public class GCmp extends NodeComponent {
@Override
public void process() {
DefaultContext context = this.getFirstContextBean();
context.setData(this.getNodeId(), this.getCurrChainName());
}
}

View File

@@ -0,0 +1,24 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getChainName.cmp;
import com.yomahub.liteflow.core.NodeSwitchComponent;
import com.yomahub.liteflow.slot.DefaultContext;
import org.springframework.stereotype.Component;
@Component("h")
public class HCmp extends NodeSwitchComponent {
@Override
public String processSwitch() throws Exception {
DefaultContext context = this.getFirstContextBean();
context.setData(this.getNodeId(), this.getCurrChainName());
return "j";
}
}

View File

@@ -0,0 +1,23 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getChainName.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
import org.springframework.stereotype.Component;
@Component("j")
public class JCmp extends NodeComponent {
@Override
public void process() {
DefaultContext context = this.getFirstContextBean();
context.setData(this.getNodeId(), this.getCurrChainName());
}
}

View File

@@ -0,0 +1,23 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getChainName.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
import org.springframework.stereotype.Component;
@Component("k")
public class KCmp extends NodeComponent {
@Override
public void process() {
DefaultContext context = this.getFirstContextBean();
context.setData(this.getNodeId(), this.getCurrChainName());
}
}

View File

@@ -19,4 +19,20 @@
<chain name="sub4">
THEN(d);
</chain>
<chain name="sub5">
THEN(e, f);
</chain>
<chain name="sub6">
SWITCH(h).to(j, k);
</chain>
<chain name="chain2">
THEN(
g,
WHEN(sub1, WHEN(sub2, sub3)),
sub4, sub5, e, sub6
);
</chain>
</flow>

View File

@@ -0,0 +1,54 @@
package com.yomahub.liteflow.test.getChainName;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.slot.DefaultContext;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
/**
* spring环境获取ChainName的测试
* @author Bryan.Zhang
*/
@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:/getChainName/application.xml")
public class GetChainNameELSpringTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
@Test
public void testGetChainName1() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
DefaultContext context = response.getFirstContextBean();
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("sub1", context.getData("a"));
Assert.assertEquals("sub2", context.getData("b"));
Assert.assertEquals("sub3", context.getData("c"));
Assert.assertEquals("sub4", context.getData("d"));
}
@Test
public void testGetChainName2() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
DefaultContext context = response.getFirstContextBean();
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("chain2", context.getData("g"));
Assert.assertEquals("sub1", context.getData("a"));
Assert.assertEquals("sub2", context.getData("b"));
Assert.assertEquals("sub3", context.getData("c"));
Assert.assertEquals("sub4", context.getData("d"));
Assert.assertEquals("sub5", context.getData("f"));
Assert.assertEquals("sub5_chain2", context.getData("e"));
Assert.assertEquals("sub6", context.getData("h"));
Assert.assertEquals("sub6", context.getData("j"));
Assert.assertNull(context.getData("k"));
}
}

View File

@@ -0,0 +1,22 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getChainName.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
import org.springframework.stereotype.Component;
@Component("a")
public class ACmp extends NodeComponent {
@Override
public void process() {
DefaultContext context = this.getFirstContextBean();
context.setData(this.getNodeId(), this.getCurrChainName());
}
}

View File

@@ -0,0 +1,23 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getChainName.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
import org.springframework.stereotype.Component;
@Component("b")
public class BCmp extends NodeComponent {
@Override
public void process() {
DefaultContext context = this.getFirstContextBean();
context.setData(this.getNodeId(), this.getCurrChainName());
}
}

View File

@@ -0,0 +1,23 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getChainName.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
import org.springframework.stereotype.Component;
@Component("c")
public class CCmp extends NodeComponent {
@Override
public void process() {
DefaultContext context = this.getFirstContextBean();
context.setData(this.getNodeId(), this.getCurrChainName());
}
}

View File

@@ -0,0 +1,23 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getChainName.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
import org.springframework.stereotype.Component;
@Component("d")
public class DCmp extends NodeComponent {
@Override
public void process() {
DefaultContext context = this.getFirstContextBean();
context.setData(this.getNodeId(), this.getCurrChainName());
}
}

View File

@@ -0,0 +1,27 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getChainName.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
import org.springframework.stereotype.Component;
@Component("e")
public class ECmp extends NodeComponent {
@Override
public void process() {
DefaultContext context = this.getFirstContextBean();
if (context.hasData(this.getNodeId())){
context.setData(this.getNodeId(), context.getData(this.getNodeId()) + "_" + this.getCurrChainName());
}else{
context.setData(this.getNodeId(), this.getCurrChainName());
}
}
}

View File

@@ -0,0 +1,23 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getChainName.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
import org.springframework.stereotype.Component;
@Component("f")
public class FCmp extends NodeComponent {
@Override
public void process() {
DefaultContext context = this.getFirstContextBean();
context.setData(this.getNodeId(), this.getCurrChainName());
}
}

View File

@@ -0,0 +1,23 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getChainName.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
import org.springframework.stereotype.Component;
@Component("g")
public class GCmp extends NodeComponent {
@Override
public void process() {
DefaultContext context = this.getFirstContextBean();
context.setData(this.getNodeId(), this.getCurrChainName());
}
}

View File

@@ -0,0 +1,24 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getChainName.cmp;
import com.yomahub.liteflow.core.NodeSwitchComponent;
import com.yomahub.liteflow.slot.DefaultContext;
import org.springframework.stereotype.Component;
@Component("h")
public class HCmp extends NodeSwitchComponent {
@Override
public String processSwitch() throws Exception {
DefaultContext context = this.getFirstContextBean();
context.setData(this.getNodeId(), this.getCurrChainName());
return "j";
}
}

View File

@@ -0,0 +1,23 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getChainName.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
import org.springframework.stereotype.Component;
@Component("j")
public class JCmp extends NodeComponent {
@Override
public void process() {
DefaultContext context = this.getFirstContextBean();
context.setData(this.getNodeId(), this.getCurrChainName());
}
}

View File

@@ -0,0 +1,23 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.getChainName.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
import org.springframework.stereotype.Component;
@Component("k")
public class KCmp extends NodeComponent {
@Override
public void process() {
DefaultContext context = this.getFirstContextBean();
context.setData(this.getNodeId(), this.getCurrChainName());
}
}

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<context:component-scan base-package="com.yomahub.liteflow.test.getChainName.cmp" />
<bean id="springAware" class="com.yomahub.liteflow.spi.spring.SpringAware"/>
<bean class="com.yomahub.liteflow.spring.ComponentScanner"/>
<bean id="liteflowConfig" class="com.yomahub.liteflow.property.LiteflowConfig">
<property name="ruleSource" value="getChainName/flow.el.xml"/>
</bean>
<bean id="flowExecutor" class="com.yomahub.liteflow.core.FlowExecutor">
<constructor-arg name="liteflowConfig" ref="liteflowConfig"/>
</bean>
</beans>

View File

@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<chain name="chain1">
WHEN(sub1, sub2, sub3, sub4);
</chain>
<chain name="sub1">
THEN(a);
</chain>
<chain name="sub2">
THEN(b);
</chain>
<chain name="sub3">
THEN(c);
</chain>
<chain name="sub4">
THEN(d);
</chain>
<chain name="sub5">
THEN(e, f);
</chain>
<chain name="sub6">
SWITCH(h).to(j, k);
</chain>
<chain name="chain2">
THEN(
g,
WHEN(sub1, WHEN(sub2, sub3)),
sub4, sub5, e, sub6
);
</chain>
</flow>