mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-06-10 03:07:32 +08:00
feature #I5CW7I 【版本特性】构造全新的EL规则表达式
This commit is contained in:
@@ -83,13 +83,6 @@ public class LiteFlowNodeBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
// 设置节点组件的class
|
||||
public LiteFlowNodeBuilder setNodeComponentClazz(Class<? extends NodeComponent> nodeComponentClass) {
|
||||
assert nodeComponentClass != null;
|
||||
setClazz(nodeComponentClass.getName());
|
||||
return this;
|
||||
}
|
||||
|
||||
public LiteFlowNodeBuilder setType(NodeTypeEnum type) {
|
||||
this.node.setType(type);
|
||||
return this;
|
||||
|
||||
@@ -88,9 +88,17 @@ public class LiteFlowChainELBuilder {
|
||||
public LiteFlowChainELBuilder setEL(String elStr) {
|
||||
List<String> errorList = new ArrayList<>();
|
||||
try{
|
||||
//往上下文里放入所有的node,使得el表达式可以直接引用到nodeId
|
||||
DefaultContext<String, Object> context = new DefaultContext<>();
|
||||
|
||||
//往上下文里放入所有的node,使得el表达式可以直接引用到nodeId
|
||||
FlowBus.getNodeMap().keySet().forEach(nodeId -> context.put(nodeId, FlowBus.copyNode(nodeId)));
|
||||
|
||||
//往上下文里放入所有的chain,是的el表达式可以直接引用到chain
|
||||
FlowBus.getChainMap().values().forEach(chain -> context.put(chain.getChainName(), chain));
|
||||
|
||||
//解析el成为一个Condition
|
||||
//为什么这里只是一个Condition,而不是一个List<Condition>呢
|
||||
//这里无论多复杂的,外面必定有一个最外层的Condition,所以这里只有一个,内部可以嵌套很多层,这点和以前的不太一样
|
||||
Condition condition = (Condition) expressRunner.execute(elStr, context, errorList, false, true);
|
||||
|
||||
//从condition的第一层嵌套结构里拿出Pre和Finally节点
|
||||
|
||||
@@ -205,6 +205,10 @@ public class FlowBus {
|
||||
return nodeMap;
|
||||
}
|
||||
|
||||
public static Map<String, Chain> getChainMap(){
|
||||
return chainMap;
|
||||
}
|
||||
|
||||
public static void cleanCache() {
|
||||
chainMap.clear();
|
||||
nodeMap.clear();
|
||||
|
||||
@@ -10,6 +10,7 @@ package com.yomahub.liteflow.spring;
|
||||
|
||||
import com.yomahub.liteflow.aop.ICmpAroundAspect;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.flow.FlowBus;
|
||||
import com.yomahub.liteflow.property.LiteflowConfig;
|
||||
import com.yomahub.liteflow.util.LOGOPrinter;
|
||||
import com.yomahub.liteflow.util.LiteFlowProxyUtil;
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.yomahub.liteflow.test.absoluteConfigPath;
|
||||
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
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环境下异步线程超时日志打印测试
|
||||
* @author Bryan.Zhang
|
||||
* @since 2.6.4
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@TestPropertySource(value = "classpath:/absoluteConfigPath/application.properties")
|
||||
@SpringBootTest(classes = AbsoluteConfigPathELSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan({"com.yomahub.liteflow.test.absoluteConfigPath.cmp"})
|
||||
public class AbsoluteConfigPathELSpringbootTest extends BaseTest {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
@Test
|
||||
public void testAbsoluteConfig() throws Exception{
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
}
|
||||
}
|
||||
@@ -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.absoluteConfigPath.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("a")
|
||||
public class ACmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("ACmp executed!");
|
||||
}
|
||||
}
|
||||
@@ -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.absoluteConfigPath.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("b")
|
||||
public class BCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("BCmp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.absoluteConfigPath.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("c")
|
||||
public class CCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("CCmp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.yomahub.liteflow.test.aop;
|
||||
|
||||
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 com.yomahub.liteflow.test.aop.aspect.CustomAspect;
|
||||
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.context.annotation.Import;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 切面场景单元测试
|
||||
* @author Bryan.Zhang
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@TestPropertySource(value = "classpath:/aop/application.properties")
|
||||
@SpringBootTest(classes = CustomAOPELSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
@Import(CustomAspect.class)
|
||||
@ComponentScan({"com.yomahub.liteflow.test.aop.cmp1","com.yomahub.liteflow.test.aop.cmp2"})
|
||||
public class CustomAOPELSpringbootTest extends BaseTest {
|
||||
|
||||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
//测试自定义AOP,串行场景
|
||||
@Test
|
||||
public void testCustomAopS() {
|
||||
LiteflowResponse response= flowExecutor.execute2Resp("chain1", "it's a request");
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("before_after", context.getData("a"));
|
||||
Assert.assertEquals("before_after", context.getData("b"));
|
||||
Assert.assertEquals("before_after", context.getData("c"));
|
||||
}
|
||||
|
||||
//测试自定义AOP,并行场景
|
||||
@Test
|
||||
public void testCustomAopP() {
|
||||
LiteflowResponse response= flowExecutor.execute2Resp("chain2", "it's a request");
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("before_after", context.getData("a"));
|
||||
Assert.assertEquals("before_after", context.getData("b"));
|
||||
Assert.assertEquals("before_after", context.getData("c"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.yomahub.liteflow.test.aop;
|
||||
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.spring.ComponentScanner;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import com.yomahub.liteflow.test.aop.aspect.CmpAspect;
|
||||
import org.junit.AfterClass;
|
||||
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.context.annotation.Import;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 切面场景单元测试
|
||||
* @author Bryan.Zhang
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@TestPropertySource(value = "classpath:/aop/application.properties")
|
||||
@SpringBootTest(classes = GlobalAOPELSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
@Import(CmpAspect.class)
|
||||
@ComponentScan({"com.yomahub.liteflow.test.aop.cmp1","com.yomahub.liteflow.test.aop.cmp2"})
|
||||
public class GlobalAOPELSpringbootTest extends BaseTest {
|
||||
|
||||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
//测试全局AOP,串行场景
|
||||
@Test
|
||||
public void testGlobalAopS() {
|
||||
LiteflowResponse response= flowExecutor.execute2Resp("chain1", "it's a request");
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("before_after", context.getData("a"));
|
||||
Assert.assertEquals("before_after", context.getData("b"));
|
||||
Assert.assertEquals("before_after", context.getData("c"));
|
||||
Assert.assertEquals("before_after", context.getData("d"));
|
||||
Assert.assertEquals("before_after", context.getData("e"));
|
||||
}
|
||||
|
||||
//测试全局AOP,并行场景
|
||||
@Test
|
||||
public void testGlobalAopP() {
|
||||
LiteflowResponse response= flowExecutor.execute2Resp("chain2", "it's a request");
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("before_after", context.getData("a"));
|
||||
Assert.assertEquals("before_after", context.getData("b"));
|
||||
Assert.assertEquals("before_after", context.getData("c"));
|
||||
Assert.assertEquals("before_after", context.getData("d"));
|
||||
Assert.assertEquals("before_after", context.getData("e"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGlobalAopException() {
|
||||
LiteflowResponse response= flowExecutor.execute2Resp("chain3", "it's a request");
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Assert.assertFalse(response.isSuccess());
|
||||
Assert.assertEquals("before_after", context.getData("a"));
|
||||
Assert.assertEquals("before_after", context.getData("b"));
|
||||
Assert.assertEquals("before_after", context.getData("c"));
|
||||
Assert.assertEquals("before_after", context.getData("f"));
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanScanCache(){
|
||||
BaseTest.cleanScanCache();
|
||||
ComponentScanner.cmpAroundAspect = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.yomahub.liteflow.test.aop.aspect;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.yomahub.liteflow.aop.ICmpAroundAspect;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.slot.Slot;
|
||||
|
||||
public class CmpAspect implements ICmpAroundAspect {
|
||||
@Override
|
||||
public void beforeProcess(String nodeId, Slot slot) {
|
||||
DefaultContext context = slot.getFirstContextBean();
|
||||
context.setData(nodeId, "before");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterProcess(String nodeId, Slot slot) {
|
||||
DefaultContext context = slot.getFirstContextBean();
|
||||
context.setData(nodeId, StrUtil.format("{}_{}", context.getData(nodeId), "after"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.yomahub.liteflow.test.aop.aspect;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
|
||||
@Aspect
|
||||
public class CustomAspect {
|
||||
|
||||
@Pointcut("execution(* com.yomahub.liteflow.test.aop.cmp1.*.process())")
|
||||
public void cut() {
|
||||
}
|
||||
|
||||
@Around("cut()")
|
||||
public Object around(ProceedingJoinPoint jp) throws Throwable {
|
||||
NodeComponent cmp = (NodeComponent) jp.getThis();
|
||||
DefaultContext context = cmp.getFirstContextBean();
|
||||
context.setData(cmp.getNodeId(), "before");
|
||||
Object returnObj = jp.proceed();
|
||||
context.setData(cmp.getNodeId(), StrUtil.format("{}_{}", context.getData(cmp.getNodeId()), "after"));
|
||||
return returnObj;
|
||||
}
|
||||
}
|
||||
@@ -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.aop.cmp1;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("a")
|
||||
public class ACmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("Acomp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.aop.cmp1;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("b")
|
||||
public class BCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("Bcomp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.aop.cmp1;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("c")
|
||||
public class CCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("Ccomp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.aop.cmp2;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("d")
|
||||
public class DCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("Dcomp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.aop.cmp2;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("e")
|
||||
public class ECmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("Ecomp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.aop.cmp2;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("f")
|
||||
public class FCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
throw new RuntimeException("test error");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
package com.yomahub.liteflow.test.asyncNode;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
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 com.yomahub.liteflow.test.asyncNode.exception.TestException;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 测试隐式调用子流程
|
||||
* 单元测试
|
||||
*
|
||||
* @author ssss
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@TestPropertySource(value = "classpath:/asyncNode/application.properties")
|
||||
@SpringBootTest(classes = AsyncNodeELSpringbootTest.class)
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan({"com.yomahub.liteflow.test.asyncNode.cmp"})
|
||||
public class AsyncNodeELSpringbootTest extends BaseTest {
|
||||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
/*****
|
||||
* 标准chain 嵌套选择 嵌套子chain进行执行
|
||||
* 验证了when情况下 多个node是并行执行
|
||||
* 验证了默认参数情况下 when可以加载执行
|
||||
* **/
|
||||
@Test
|
||||
public void testAsyncFlow1() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a base request");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
System.out.println(response.getExecuteStepStr());
|
||||
}
|
||||
|
||||
//这个和test1有点类似,只不过进一步验证了步骤
|
||||
@Test
|
||||
public void testAsyncFlow2() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "it's a base request");
|
||||
Assert.assertTrue(ListUtil.toList("b==>j==>g==>f==>h","b==>j==>g==>h==>f",
|
||||
"b==>j==>h==>g==>f","b==>j==>h==>f==>g",
|
||||
"b==>j==>f==>h==>g","b==>j==>f==>g==>h"
|
||||
).contains(response.getExecuteStepStr()));
|
||||
}
|
||||
|
||||
//测试errorResume,默认的errorResume为false,这里测试默认的
|
||||
@Test
|
||||
public void testAsyncFlow3_1() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain3-1", "it's a base request");
|
||||
Assert.assertFalse(response.isSuccess());
|
||||
Assert.assertEquals(response.getSlot().getException().getClass(), TestException.class);
|
||||
}
|
||||
|
||||
//测试errorResume,默认的errorResume为false,这里设置为true
|
||||
@Test
|
||||
public void testAsyncFlow3_2() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain3-2", "it's a base request");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
}
|
||||
|
||||
//相同group的并行组,会合并,并且errorResume根据第一个when来,这里第一个when配置了不抛错
|
||||
@Test
|
||||
public void testAsyncFlow4() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain4", "it's a base request");
|
||||
//因为不记录错误,所以最终结果是true
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
//因为是并行组,所以即便抛错了,其他组件也会执行,i在流程里配置了2遍,i抛错,但是也执行了2遍,这里验证下
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Integer count = context.getData("count");
|
||||
Assert.assertEquals(new Integer(2), count);
|
||||
//因为配置了不抛错,所以response里的cause应该为null
|
||||
Assert.assertNull(response.getCause());
|
||||
}
|
||||
|
||||
//相同group的并行组,会合并,并且errorResume根据第一个when来,这里第一个when配置了会抛错
|
||||
@Test
|
||||
public void testAsyncFlow5() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain5", "it's a base request");
|
||||
//整个并行组是报错的,所以最终结果是false
|
||||
Assert.assertFalse(response.isSuccess());
|
||||
//因为是并行组,所以即便抛错了,其他组件也会执行,i在流程里配置了2遍,i抛错,但是也执行了2遍,这里验证下
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Integer count = context.getData("count");
|
||||
Assert.assertEquals(new Integer(2), count);
|
||||
//因为第一个when配置了会报错,所以response里的cause里应该会有TestException
|
||||
Assert.assertEquals(TestException.class, response.getCause().getClass());
|
||||
}
|
||||
|
||||
//不同group的并行组,不会合并,第一个when的errorResume是false,会抛错,那第二个when就不会执行
|
||||
@Test
|
||||
public void testAsyncFlow6() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain6", "it's a base request");
|
||||
//第一个when会抛错,所以最终结果是false
|
||||
Assert.assertFalse(response.isSuccess());
|
||||
//因为是不同组并行组,第一组的when里的i就抛错了,所以i就执行了1遍
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Integer count = context.getData("count");
|
||||
Assert.assertEquals(new Integer(1), count);
|
||||
//第一个when会报错,所以最终response的cause里应该会有TestException
|
||||
Assert.assertEquals(TestException.class, response.getCause().getClass());
|
||||
}
|
||||
|
||||
//不同group的并行组,不会合并,第一个when的errorResume是true,不会报错,那第二个when还会继续执行,但是第二个when的errorResume是false,所以第二个when会报错
|
||||
@Test
|
||||
public void testAsyncFlow7() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain7", "it's a base request");
|
||||
//第二个when会抛错,所以最终结果是false
|
||||
Assert.assertFalse(response.isSuccess());
|
||||
// 传递了slotIndex,则set的size==2
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Integer count = context.getData("count");
|
||||
Assert.assertEquals(new Integer(2), count);
|
||||
//第一个when会报错,所以最终response的cause里应该会有TestException
|
||||
Assert.assertEquals(TestException.class, response.getCause().getClass());
|
||||
}
|
||||
|
||||
//测试任意异步一个执行完即继续的场景
|
||||
//d g h并行,配置了any=true,其中d耗时1秒,g耗时0.5秒,其他都不设耗时
|
||||
//最终执行效果应该是h先返回,然后执行abc,最后gd
|
||||
//这里要注意的是,由于step是先加入,所以step的打印顺序并不是这样的。但是实际执行是正确的
|
||||
@Test
|
||||
public void testAsyncFlow8() throws Exception {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain8", "it's a base request");
|
||||
DefaultContext context = response.getFirstContextBean();
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertTrue(context.getData("check").toString().startsWith("habc"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.yomahub.liteflow.test.asyncNode.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();
|
||||
synchronized (NodeComponent.class){
|
||||
if (context.hasData("check")){
|
||||
String str = context.getData("check");
|
||||
str += this.getNodeId();
|
||||
context.setData("check", str);
|
||||
}else{
|
||||
context.setData("check", this.getNodeId());
|
||||
}
|
||||
}
|
||||
System.out.println("Acomp executed!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.yomahub.liteflow.test.asyncNode.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();
|
||||
synchronized (NodeComponent.class){
|
||||
if (context.hasData("check")){
|
||||
String str = context.getData("check");
|
||||
str += this.getNodeId();
|
||||
context.setData("check", str);
|
||||
}else{
|
||||
context.setData("check", this.getNodeId());
|
||||
}
|
||||
}
|
||||
System.out.println("Bcomp executed!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.yomahub.liteflow.test.asyncNode.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() throws Exception {
|
||||
DefaultContext context = this.getFirstContextBean();
|
||||
synchronized (NodeComponent.class){
|
||||
if (context.hasData("check")){
|
||||
String str = context.getData("check");
|
||||
str += this.getNodeId();
|
||||
context.setData("check", str);
|
||||
}else{
|
||||
context.setData("check", this.getNodeId());
|
||||
}
|
||||
}
|
||||
System.out.println("Ccomp executed!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.yomahub.liteflow.test.asyncNode.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() throws Exception {
|
||||
Thread.sleep(1000);
|
||||
DefaultContext context = this.getFirstContextBean();
|
||||
synchronized (NodeComponent.class){
|
||||
if (context.hasData("check")){
|
||||
String str = context.getData("check");
|
||||
str += this.getNodeId();
|
||||
context.setData("check", str);
|
||||
}else{
|
||||
context.setData("check", this.getNodeId());
|
||||
}
|
||||
}
|
||||
System.out.println("Dcomp executed!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.yomahub.liteflow.test.asyncNode.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeSwitchComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
@Component("e")
|
||||
public class ECmp extends NodeSwitchComponent {
|
||||
|
||||
@Override
|
||||
public String processCond() throws Exception {
|
||||
System.out.println("Ecomp executed!");
|
||||
return "g";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.yomahub.liteflow.test.asyncNode.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
@Component("f")
|
||||
public class FCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() throws Exception {
|
||||
System.out.println("Fcomp executed!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.yomahub.liteflow.test.asyncNode.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() throws Exception {
|
||||
Thread.sleep(500);
|
||||
DefaultContext context = this.getFirstContextBean();
|
||||
synchronized (NodeComponent.class){
|
||||
if (context.hasData("check")){
|
||||
String str = context.getData("check");
|
||||
str += this.getNodeId();
|
||||
context.setData("check", str);
|
||||
}else{
|
||||
context.setData("check", this.getNodeId());
|
||||
}
|
||||
}
|
||||
System.out.println("Gcomp executed!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.yomahub.liteflow.test.asyncNode.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
@Component("h")
|
||||
public class HCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() throws Exception {
|
||||
DefaultContext context = this.getFirstContextBean();
|
||||
synchronized (NodeComponent.class){
|
||||
if (context.hasData("check")){
|
||||
String str = context.getData("check");
|
||||
str += this.getNodeId();
|
||||
context.setData("check", str);
|
||||
}else{
|
||||
context.setData("check", this.getNodeId());
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Hcomp executed!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.yomahub.liteflow.test.asyncNode.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import com.yomahub.liteflow.test.asyncNode.exception.TestException;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
@Component("i")
|
||||
public class ICmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() throws Exception {
|
||||
DefaultContext context = this.getFirstContextBean();
|
||||
if (context.hasData("count")){
|
||||
Integer count = context.getData("count");
|
||||
context.setData("count", ++count);
|
||||
} else{
|
||||
context.setData("count", 1);
|
||||
}
|
||||
System.out.println("Icomp executed! throw Exception!");
|
||||
throw new TestException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.yomahub.liteflow.test.asyncNode.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeSwitchComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
@Component("j")
|
||||
public class JCmp extends NodeSwitchComponent {
|
||||
|
||||
@Override
|
||||
public String processCond() throws Exception {
|
||||
System.out.println("Jcomp executed!");
|
||||
return "chain3";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.yomahub.liteflow.test.asyncNode.exception;
|
||||
|
||||
public class TestException extends Exception{
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
package com.yomahub.liteflow.test.builder;
|
||||
|
||||
import com.yomahub.liteflow.builder.LiteFlowChainBuilder;
|
||||
import com.yomahub.liteflow.builder.LiteFlowConditionBuilder;
|
||||
import com.yomahub.liteflow.builder.LiteFlowNodeBuilder;
|
||||
import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder;
|
||||
import com.yomahub.liteflow.builder.entity.ExecutableEntity;
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.enums.NodeTypeEnum;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import com.yomahub.liteflow.test.builder.cmp1.*;
|
||||
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.test.context.junit4.SpringRunner;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
//基于builder模式的单元测试
|
||||
//这里只是最基本的builder模式的测试,只是为了验证在springboot模式下的正常性
|
||||
//更详细的builder模式测试用例会单独拉testcase去做
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = BuilderELSpringbootTest1.class)
|
||||
@EnableAutoConfiguration
|
||||
public class BuilderELSpringbootTest1 extends BaseTest {
|
||||
|
||||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
//基于普通组件的builder模式测试
|
||||
@Test
|
||||
public void testBuilder() throws Exception {
|
||||
LiteFlowNodeBuilder.createNode().setId("a")
|
||||
.setName("组件A")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setClazz("com.yomahub.liteflow.test.builder.cmp1.ACmp")
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("b")
|
||||
.setName("组件B")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setClazz("com.yomahub.liteflow.test.builder.cmp1.BCmp")
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("c")
|
||||
.setName("组件C")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setClazz("com.yomahub.liteflow.test.builder.cmp1.CCmp")
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("d")
|
||||
.setName("组件D")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setClazz("com.yomahub.liteflow.test.builder.cmp1.DCmp")
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("e")
|
||||
.setName("组件E")
|
||||
.setType(NodeTypeEnum.SWITCH)
|
||||
.setClazz("com.yomahub.liteflow.test.builder.cmp1.ECmp")
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("f")
|
||||
.setName("组件F")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setClazz("com.yomahub.liteflow.test.builder.cmp1.FCmp")
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("g")
|
||||
.setName("组件G")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setClazz("com.yomahub.liteflow.test.builder.cmp1.GCmp")
|
||||
.build();
|
||||
|
||||
|
||||
LiteFlowChainELBuilder.createChain().setChainName("chain2").setEL(
|
||||
"THEN(c, d)"
|
||||
).build();
|
||||
|
||||
LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL(
|
||||
"THEN(a, b, WHEN(SWITCH(e).to(f, g, chain2)))"
|
||||
).build();
|
||||
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("a[组件A]==>b[组件B]==>e[组件E]==>c[组件C]==>d[组件D]", response.getExecuteStepStr());
|
||||
}
|
||||
|
||||
//基于普通组件的builder模式测试
|
||||
@Test
|
||||
public void testBuilderForClassAndCode() throws Exception {
|
||||
LiteFlowNodeBuilder.createNode().setId("a")
|
||||
.setName("组件A")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setClazz(ACmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("b")
|
||||
.setName("组件B")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setClazz(BCmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("c")
|
||||
.setName("组件C")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setClazz(CCmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("d")
|
||||
.setName("组件D")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setClazz(DCmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("e")
|
||||
.setName("组件E")
|
||||
.setType(NodeTypeEnum.SWITCH)
|
||||
.setClazz(ECmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("f")
|
||||
.setName("组件F")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setClazz(FCmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("g")
|
||||
.setName("组件G")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setClazz(GCmp.class)
|
||||
.build();
|
||||
|
||||
|
||||
LiteFlowChainELBuilder.createChain().setChainName("chain2").setEL(
|
||||
"THEN(c, d)"
|
||||
).build();
|
||||
|
||||
LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL(
|
||||
"THEN(a, b, WHEN(SWITCH(e).to(f, g, chain2)))"
|
||||
).build();
|
||||
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("a[组件A]==>b[组件B]==>e[组件E]==>c[组件C]==>d[组件D]", response.getExecuteStepStr());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.yomahub.liteflow.test.builder;
|
||||
|
||||
import com.yomahub.liteflow.builder.LiteFlowChainBuilder;
|
||||
import com.yomahub.liteflow.builder.LiteFlowConditionBuilder;
|
||||
import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder;
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
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.junit4.SpringRunner;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
//基于builder模式的单元测试
|
||||
//这里测试的是通过spring去扫描,但是通过代码去构建chain的用例
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = BuilderELSpringbootTest2.class)
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan({"com.yomahub.liteflow.test.builder.cmp2"})
|
||||
public class BuilderELSpringbootTest2 extends BaseTest {
|
||||
|
||||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
//通过spring去扫描组件,通过代码去构建chain
|
||||
@Test
|
||||
public void testBuilder() throws Exception {
|
||||
LiteFlowChainELBuilder.createChain().setChainName("chain1").setEL(
|
||||
"THEN(h, i, j)"
|
||||
).build();
|
||||
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain1");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals("h==>i==>j", response.getExecuteStepStr());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.test.builder.cmp1;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
||||
public class ACmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("ACmp executed!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.test.builder.cmp1;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
||||
public class BCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("BCmp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.test.builder.cmp1;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
||||
public class CCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("CCmp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.test.builder.cmp1;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
||||
public class DCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("DCmp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.builder.cmp1;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeSwitchComponent;
|
||||
|
||||
public class ECmp extends NodeSwitchComponent {
|
||||
|
||||
@Override
|
||||
public String processCond() throws Exception {
|
||||
System.out.println("ECmp executed!");
|
||||
return "chain2";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.test.builder.cmp1;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
||||
public class FCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("FCmp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.test.builder.cmp1;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
||||
public class GCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("GCmp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.builder.cmp2;
|
||||
|
||||
import com.yomahub.liteflow.annotation.LiteflowComponent;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
||||
@LiteflowComponent("h")
|
||||
public class HCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("HCmp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.builder.cmp2;
|
||||
|
||||
import com.yomahub.liteflow.annotation.LiteflowComponent;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
||||
@LiteflowComponent("i")
|
||||
public class ICmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("ICmp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.builder.cmp2;
|
||||
|
||||
import com.yomahub.liteflow.annotation.LiteflowComponent;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
||||
@LiteflowComponent("j")
|
||||
public class JCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("JCmp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
liteflow.rule-source=/usr/local/flow.el.xml
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--这里只是内容,在这个测试用例中这个文件请移到/usr/local/flow.xml中-->
|
||||
<flow>
|
||||
<chain name="chain1">
|
||||
WHEN(a,b,c)
|
||||
</chain>
|
||||
</flow>
|
||||
@@ -0,0 +1 @@
|
||||
liteflow.rule-source=aop/flow.el.xml
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<flow>
|
||||
<chain name="chain1">
|
||||
THEN(a,b,c,d,e)
|
||||
</chain>
|
||||
|
||||
<chain name="chain2">
|
||||
THEN(a,b,c,WHEN(d,e))
|
||||
</chain>
|
||||
|
||||
<chain name="chain3">
|
||||
THEN(a,b,c,f)
|
||||
</chain>
|
||||
</flow>
|
||||
@@ -0,0 +1 @@
|
||||
liteflow.rule-source=asyncNode/flow.el.xml
|
||||
@@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<flow>
|
||||
<!-- base test -->
|
||||
<chain name="chain1">
|
||||
THEN(
|
||||
a,b,c,
|
||||
WHEN(d, SWITCH(e).to(f,g)),
|
||||
chain2
|
||||
)
|
||||
</chain>
|
||||
|
||||
|
||||
<chain name="chain2">
|
||||
THEN(b, SWITCH(j).to(a, chain3))
|
||||
</chain>
|
||||
|
||||
<chain name="chain3">
|
||||
WHEN(g, f, h)
|
||||
</chain>
|
||||
|
||||
<chain name="chain3-1">
|
||||
THEN(WHEN(f, g, i), WHEN(h))
|
||||
</chain>
|
||||
|
||||
<chain name="chain3-2">
|
||||
THEN(WHEN(f, g, i).ignoreError(true), WHEN(h))
|
||||
</chain>
|
||||
|
||||
<chain name="chain4">
|
||||
THEN(a, b, c, WHEN(d, i, g, i, h).ignoreError(true))
|
||||
</chain>
|
||||
|
||||
<chain name="chain5">
|
||||
THEN(a, b, c, WHEN(d, i, g, i, h))
|
||||
</chain>
|
||||
|
||||
<chain name="chain6">
|
||||
THEN(a, b, c, WHEN(d, i), WHEN(g, i, h).ignoreError(true))
|
||||
</chain>
|
||||
|
||||
<chain name="chain7">
|
||||
THEN(a, b, c, WHEN(d, i).ignoreError(true), WHEN(g, i, h))
|
||||
</chain>
|
||||
|
||||
<chain name="chain8">
|
||||
THEN(WHEN(d, g, h).any(true), THEN(a, b, c))
|
||||
</chain>
|
||||
|
||||
</flow>
|
||||
@@ -96,37 +96,37 @@ public class BuilderTest extends BaseTest {
|
||||
LiteFlowNodeBuilder.createNode().setId("a")
|
||||
.setName("组件A")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setNodeComponentClazz(ACmp.class)
|
||||
.setClazz(ACmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("b")
|
||||
.setName("组件B")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setNodeComponentClazz(BCmp.class)
|
||||
.setClazz(BCmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("c")
|
||||
.setName("组件C")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setNodeComponentClazz(CCmp.class)
|
||||
.setClazz(CCmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("d")
|
||||
.setName("组件D")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setNodeComponentClazz(DCmp.class)
|
||||
.setClazz(DCmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("e")
|
||||
.setName("组件E")
|
||||
.setType(NodeTypeEnum.SWITCH)
|
||||
.setNodeComponentClazz(ECmp.class)
|
||||
.setClazz(ECmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("f")
|
||||
.setName("组件F")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setNodeComponentClazz(FCmp.class)
|
||||
.setClazz(FCmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("g")
|
||||
.setName("组件G")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setNodeComponentClazz(GCmp.class)
|
||||
.setClazz(GCmp.class)
|
||||
.build();
|
||||
|
||||
LiteFlowChainBuilder.createChain().setChainName("chain2").setCondition(
|
||||
@@ -153,37 +153,37 @@ public class BuilderTest extends BaseTest {
|
||||
LiteFlowNodeBuilder.createNode().setId("a")
|
||||
.setName("组件A")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setNodeComponentClazz(ACmp.class)
|
||||
.setClazz(ACmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("b")
|
||||
.setName("组件B")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setNodeComponentClazz(BCmp.class)
|
||||
.setClazz(BCmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("c")
|
||||
.setName("组件C")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setNodeComponentClazz(CCmp.class)
|
||||
.setClazz(CCmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("d")
|
||||
.setName("组件D")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setNodeComponentClazz(DCmp.class)
|
||||
.setClazz(DCmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("e")
|
||||
.setName("组件E")
|
||||
.setType(NodeTypeEnum.SWITCH)
|
||||
.setNodeComponentClazz(ECmp.class)
|
||||
.setClazz(ECmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("f")
|
||||
.setName("组件F")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setNodeComponentClazz(FCmp.class)
|
||||
.setClazz(FCmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("g")
|
||||
.setName("组件G")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setNodeComponentClazz(GCmp.class)
|
||||
.setClazz(GCmp.class)
|
||||
.build();
|
||||
|
||||
|
||||
|
||||
@@ -97,37 +97,37 @@ public class BuilderSpringbootTest1 extends BaseTest {
|
||||
LiteFlowNodeBuilder.createNode().setId("a")
|
||||
.setName("组件A")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setNodeComponentClazz(ACmp.class)
|
||||
.setClazz(ACmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("b")
|
||||
.setName("组件B")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setNodeComponentClazz(BCmp.class)
|
||||
.setClazz(BCmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("c")
|
||||
.setName("组件C")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setNodeComponentClazz(CCmp.class)
|
||||
.setClazz(CCmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("d")
|
||||
.setName("组件D")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setNodeComponentClazz(DCmp.class)
|
||||
.setClazz(DCmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("e")
|
||||
.setName("组件E")
|
||||
.setType(NodeTypeEnum.SWITCH)
|
||||
.setNodeComponentClazz(ECmp.class)
|
||||
.setClazz(ECmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("f")
|
||||
.setName("组件F")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setNodeComponentClazz(FCmp.class)
|
||||
.setClazz(FCmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("g")
|
||||
.setName("组件G")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setNodeComponentClazz(GCmp.class)
|
||||
.setClazz(GCmp.class)
|
||||
.build();
|
||||
|
||||
|
||||
@@ -156,37 +156,37 @@ public class BuilderSpringbootTest1 extends BaseTest {
|
||||
LiteFlowNodeBuilder.createNode().setId("a")
|
||||
.setName("组件A")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setNodeComponentClazz(ACmp.class)
|
||||
.setClazz(ACmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("b")
|
||||
.setName("组件B")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setNodeComponentClazz(BCmp.class)
|
||||
.setClazz(BCmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("c")
|
||||
.setName("组件C")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setNodeComponentClazz(CCmp.class)
|
||||
.setClazz(CCmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("d")
|
||||
.setName("组件D")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setNodeComponentClazz(DCmp.class)
|
||||
.setClazz(DCmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("e")
|
||||
.setName("组件E")
|
||||
.setType(NodeTypeEnum.SWITCH)
|
||||
.setNodeComponentClazz(ECmp.class)
|
||||
.setClazz(ECmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("f")
|
||||
.setName("组件F")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setNodeComponentClazz(FCmp.class)
|
||||
.setClazz(FCmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("g")
|
||||
.setName("组件G")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setNodeComponentClazz(GCmp.class)
|
||||
.setClazz(GCmp.class)
|
||||
.build();
|
||||
|
||||
|
||||
|
||||
@@ -91,37 +91,37 @@ public class BuilderSpringTest1 extends BaseTest {
|
||||
LiteFlowNodeBuilder.createNode().setId("a")
|
||||
.setName("组件A")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setNodeComponentClazz(ACmp.class)
|
||||
.setClazz(ACmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("b")
|
||||
.setName("组件B")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setNodeComponentClazz(BCmp.class)
|
||||
.setClazz(BCmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("c")
|
||||
.setName("组件C")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setNodeComponentClazz(CCmp.class)
|
||||
.setClazz(CCmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("d")
|
||||
.setName("组件D")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setNodeComponentClazz(DCmp.class)
|
||||
.setClazz(DCmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("e")
|
||||
.setName("组件E")
|
||||
.setType(NodeTypeEnum.SWITCH)
|
||||
.setNodeComponentClazz(ECmp.class)
|
||||
.setClazz(ECmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("f")
|
||||
.setName("组件F")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setNodeComponentClazz(FCmp.class)
|
||||
.setClazz(FCmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("g")
|
||||
.setName("组件G")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setNodeComponentClazz(GCmp.class)
|
||||
.setClazz(GCmp.class)
|
||||
.build();
|
||||
|
||||
|
||||
@@ -148,37 +148,37 @@ public class BuilderSpringTest1 extends BaseTest {
|
||||
LiteFlowNodeBuilder.createNode().setId("a")
|
||||
.setName("组件A")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setNodeComponentClazz(ACmp.class)
|
||||
.setClazz(ACmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("b")
|
||||
.setName("组件B")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setNodeComponentClazz(BCmp.class)
|
||||
.setClazz(BCmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("c")
|
||||
.setName("组件C")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setNodeComponentClazz(CCmp.class)
|
||||
.setClazz(CCmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("d")
|
||||
.setName("组件D")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setNodeComponentClazz(DCmp.class)
|
||||
.setClazz(DCmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("e")
|
||||
.setName("组件E")
|
||||
.setType(NodeTypeEnum.SWITCH)
|
||||
.setNodeComponentClazz(ECmp.class)
|
||||
.setClazz(ECmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("f")
|
||||
.setName("组件F")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setNodeComponentClazz(FCmp.class)
|
||||
.setClazz(FCmp.class)
|
||||
.build();
|
||||
LiteFlowNodeBuilder.createNode().setId("g")
|
||||
.setName("组件G")
|
||||
.setType(NodeTypeEnum.COMMON)
|
||||
.setNodeComponentClazz(GCmp.class)
|
||||
.setClazz(GCmp.class)
|
||||
.build();
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user