添加spring native环境下全新EL表达式测试工程

This commit is contained in:
zendwang 2022-07-10 22:25:59 +08:00
parent ba2349038a
commit e1ef758456
358 changed files with 8852 additions and 0 deletions

View File

@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>liteflow-testcase-el</artifactId>
<groupId>com.yomahub</groupId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>liteflow-testcase-el-springnative</artifactId>
<dependencies>
<dependency>
<groupId>com.yomahub</groupId>
<artifactId>liteflow-spring</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-test</artifactId>
</dependency>
<dependency>
<groupId>com.101tec</groupId>
<artifactId>zkclient</artifactId>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,22 @@
package com.yomahub.liteflow.test;
import com.yomahub.liteflow.flow.FlowBus;
import com.yomahub.liteflow.flow.id.IdGeneratorHelper;
import com.yomahub.liteflow.property.LiteflowConfigGetter;
import com.yomahub.liteflow.spi.holder.SpiFactoryCleaner;
import com.yomahub.liteflow.spring.ComponentScanner;
import com.yomahub.liteflow.thread.ExecutorHelper;
import org.junit.AfterClass;
public class BaseTest {
@AfterClass
public static void cleanScanCache(){
ComponentScanner.cleanCache();
FlowBus.cleanCache();
ExecutorHelper.loadInstance().clearExecutorServiceMap();
SpiFactoryCleaner.clean();
LiteflowConfigGetter.clean();
IdGeneratorHelper.getInstance().clear();
}
}

View File

@ -0,0 +1,31 @@
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.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
/**
* spring环境下规则配置文件通过绝对路径获取
* @author zendwang
* @since 2.8.0
*/
@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:/absoluteConfigPath/application.xml")
public class AbsoluteConfigPathELSpringTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
@Test
public void testAbsoluteConfig(){
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertTrue(response.isSuccess());
}
}

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.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!");
}
}

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.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!");
}
}

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.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!");
}
}

View File

@ -0,0 +1,48 @@
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 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;
/**
* 切面场景单元测试
* @author zendwang
* @since 2.8.0
*/
@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:/aop/application-custom.xml")
public class CustomAOPELSpringTest 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"));
}
}

View File

@ -0,0 +1,72 @@
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 org.junit.AfterClass;
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;
/**
* 切面场景单元测试
* @author zendwang
* @since 2.8.0
*/
@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:/aop/application-global.xml")
public class GlobalAOPELSpringTest 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;
}
}

View File

@ -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"));
}
}

View File

@ -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;
}
}

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.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!");
}
}

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.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!");
}
}

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.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!");
}
}

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.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!");
}
}

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.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!");
}
}

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.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");
}
}

View File

@ -0,0 +1,133 @@
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.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
/**
* 测试隐式调用子流程
* 单元测试
*
* @author ssss
*/
@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:/asyncNode/application.xml")
public class AsyncNodeELSpringTest 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");
DefaultContext context = response.getFirstContextBean();
//因为不记录错误所以最终结果是true
Assert.assertTrue(response.isSuccess());
//因为是并行组所以即便抛错了其他组件也会执行i在流程里配置了2遍i抛错但是也执行了2遍这里验证下
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");
DefaultContext context = response.getFirstContextBean();
//整个并行组是报错的所以最终结果是false
Assert.assertFalse(response.isSuccess());
//因为是并行组所以即便抛错了其他组件也会执行i在流程里配置了2遍i抛错但是也执行了2遍这里验证下
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");
DefaultContext context = response.getFirstContextBean();
//第一个when会抛错所以最终结果是false
Assert.assertFalse(response.isSuccess());
//因为是不同组并行组第一组的when里的i就抛错了所以i就执行了1遍
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");
DefaultContext context = response.getFirstContextBean();
//第二个when会抛错所以最终结果是false
Assert.assertFalse(response.isSuccess());
// 传递了slotIndex则set的size==2
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"));
}
}

View File

@ -0,0 +1,25 @@
package com.yomahub.liteflow.test.asyncNode.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
import com.yomahub.liteflow.slot.Slot;
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!");
}
}

View File

@ -0,0 +1,25 @@
package com.yomahub.liteflow.test.asyncNode.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
import com.yomahub.liteflow.slot.Slot;
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!");
}
}

View File

@ -0,0 +1,25 @@
package com.yomahub.liteflow.test.asyncNode.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
import com.yomahub.liteflow.slot.Slot;
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!");
}
}

View File

@ -0,0 +1,26 @@
package com.yomahub.liteflow.test.asyncNode.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
import com.yomahub.liteflow.slot.Slot;
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!");
}
}

View File

@ -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 processSwitch() throws Exception {
System.out.println("Ecomp executed!");
return "g";
}
}

View File

@ -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!");
}
}

View File

@ -0,0 +1,27 @@
package com.yomahub.liteflow.test.asyncNode.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
import com.yomahub.liteflow.slot.Slot;
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!");
}
}

View File

@ -0,0 +1,27 @@
package com.yomahub.liteflow.test.asyncNode.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
import com.yomahub.liteflow.slot.Slot;
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!");
}
}

View File

@ -0,0 +1,25 @@
package com.yomahub.liteflow.test.asyncNode.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
import com.yomahub.liteflow.slot.Slot;
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();
}
}

View File

@ -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 processSwitch() throws Exception {
System.out.println("Jcomp executed!");
return "chain3";
}
}

View File

@ -0,0 +1,4 @@
package com.yomahub.liteflow.test.asyncNode.exception;
public class TestException extends Exception{
}

View File

@ -0,0 +1,27 @@
package com.yomahub.liteflow.test.base;
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.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:/base/application.xml")
public class BaseCommonELSpringTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
@Test
public void testBaseCommon(){
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("a==>b==>c==>d", response.getExecuteStepStr());
}
}

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.base.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!");
}
}

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.base.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!");
}
}

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.base.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!");
}
}

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.base.cmp;
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("CCmp executed!");
}
}

View File

@ -0,0 +1,139 @@
package com.yomahub.liteflow.test.builder;
import com.yomahub.liteflow.builder.LiteFlowNodeBuilder;
import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder;
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.ACmp;
import com.yomahub.liteflow.test.builder.cmp1.BCmp;
import com.yomahub.liteflow.test.builder.cmp1.CCmp;
import com.yomahub.liteflow.test.builder.cmp1.DCmp;
import com.yomahub.liteflow.test.builder.cmp1.ECmp;
import com.yomahub.liteflow.test.builder.cmp1.FCmp;
import com.yomahub.liteflow.test.builder.cmp1.GCmp;
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;
//基于builder模式的单元测试
//这里只是最基本的builder模式的测试只是为了验证在spring模式下的正常性
@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:/builder/application1.xml")
public class BuilderELSpringTest1 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());
}
}

View File

@ -0,0 +1,35 @@
package com.yomahub.liteflow.test.builder;
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.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
//基于builder模式的单元测试
//这里测试的是通过spring去扫描但是通过代码去构建chain的用例
@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:/builder/application2.xml")
public class BuilderELSpringTest2 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());
}
}

View File

@ -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(getTag() + "ACmp executed!");
}
}

View File

@ -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!");
}
}

View File

@ -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!");
}
}

View File

@ -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!");
}
}

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.builder.cmp1;
import com.yomahub.liteflow.core.NodeSwitchComponent;
public class ECmp extends NodeSwitchComponent {
@Override
public String processSwitch() throws Exception {
System.out.println("ECmp executed!");
return "chain2";
}
}

View File

@ -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!");
}
}

View File

@ -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!");
}
}

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.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!");
}
}

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.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!");
}
}

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.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!");
}
}

View File

@ -0,0 +1,59 @@
package com.yomahub.liteflow.test.cmpRetry;
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.context.annotation.ComponentScan;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
/**
* 测试spring下的节点重试
* @author Bryan.Zhang
* @since 2.5.10
*/
@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:/cmpRetry/application.xml")
@ComponentScan({"com.yomahub.liteflow.test.cmpRetry.cmp"})
public class LiteflowRetryELSpringTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
//全局重试配置测试
@Test
public void testRetry1() {
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("a==>b==>b==>b", response.getExecuteStepStr());
}
//单个组件重试配置测试
@Test
public void testRetry2() {
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
Assert.assertFalse(response.isSuccess());
Assert.assertEquals("c==>c==>c==>c==>c==>c", response.getExecuteStepStr());
}
//单个组件指定异常但抛出的并不是指定异常的场景测试
@Test
public void testRetry3() {
LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg");
Assert.assertFalse(response.isSuccess());
}
//单个组件指定异常重试抛出的是指定异常或者
@Test
public void testRetry4() {
LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg");
Assert.assertFalse(response.isSuccess());
Assert.assertEquals("e==>e==>e==>e==>e==>e", response.getExecuteStepStr());
}
}

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.cmpRetry.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
@LiteflowComponent("a")
public class ACmp extends NodeComponent {
@Override
public void process() {
System.out.println("ACmp executed!");
}
}

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.cmpRetry.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
@LiteflowComponent("b")
public class BCmp extends NodeComponent {
private int flag = 0;
@Override
public void process() {
System.out.println("BCmp executed!");
if (flag < 2){
flag++;
throw new RuntimeException("demo exception");
}
}
}

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.cmpRetry.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.annotation.LiteflowRetry;
import com.yomahub.liteflow.core.NodeComponent;
@LiteflowComponent("c")
@LiteflowRetry(5)
public class CCmp extends NodeComponent {
@Override
public void process() {
System.out.println("CCmp executed!");
throw new RuntimeException("demo exception");
}
}

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.cmpRetry.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.annotation.LiteflowRetry;
import com.yomahub.liteflow.core.NodeComponent;
@LiteflowComponent("d")
@LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class})
public class DCmp extends NodeComponent {
@Override
public void process() {
System.out.println("DCmp executed!");
throw new RuntimeException("demo exception");
}
}

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.cmpRetry.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.annotation.LiteflowRetry;
import com.yomahub.liteflow.core.NodeComponent;
@LiteflowComponent("e")
@LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class})
public class ECmp extends NodeComponent {
@Override
public void process() {
System.out.println("ECmp executed!");
throw new NullPointerException("demo null exception");
}
}

View File

@ -0,0 +1,40 @@
package com.yomahub.liteflow.test.cmpStep;
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.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:/cmpStep/application.xml")
public class CmpStepELSpringTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
@Test
public void testStep1(){
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertFalse(response.isSuccess());
Assert.assertTrue(response.getExecuteSteps().get("a").isSuccess());
Assert.assertTrue(response.getExecuteSteps().get("b").isSuccess());
Assert.assertFalse(response.getExecuteSteps().get("c").isSuccess());
Assert.assertFalse(response.getExecuteSteps().get("d").isSuccess());
Assert.assertTrue(response.getExecuteSteps().get("c").getTimeSpent() >= 2000);
Assert.assertEquals(RuntimeException.class, response.getExecuteSteps().get("c").getException().getClass());
Assert.assertEquals(RuntimeException.class, response.getExecuteSteps().get("d").getException().getClass());
}
@Test
public void testStep2() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("a==>b", response.getExecuteStepStrWithoutTime());
}
}

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.cmpStep.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("a")
public class ACmp extends NodeComponent {
@Override
public void process() throws Exception{
Thread.sleep(5000L);
System.out.println("ACmp executed!");
}
}

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.cmpStep.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!");
}
}

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.cmpStep.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("c")
public class CCmp extends NodeComponent {
@Override
public void process() throws Exception{
System.out.println("CCmp executed!");
Thread.sleep(2000);
throw new RuntimeException("test error c");
}
}

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.cmpStep.cmp;
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("CCmp executed!");
throw new RuntimeException("test error d");
}
}

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.cmpStep.cmp;
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("ECmp executed!");
}
@Override
public boolean isAccess() {
return false;
}
}

View File

@ -0,0 +1,87 @@
package com.yomahub.liteflow.test.component;
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.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.ReflectionUtils;
import javax.annotation.Resource;
/**
* 组件功能点测试
* 单元测试
*
* @author donguo.tao
*/
@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:/component/application.xml")
public class ComponentELSpringTest extends BaseTest {
private static final Logger LOG = LoggerFactory.getLogger(ComponentELSpringTest.class);
@Resource
private FlowExecutor flowExecutor;
//isAccess方法的功能测试
@Test
public void testIsAccess() {
LiteflowResponse response = flowExecutor.execute2Resp("chain1", 101);
Assert.assertTrue(response.isSuccess());
Assert.assertNotNull(response.getSlot().getResponseData());
}
//组件抛错的功能点测试
@Test(expected = ArithmeticException.class)
public void testComponentException() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain2", 0);
Assert.assertFalse(response.isSuccess());
Assert.assertEquals("/ by zero", response.getMessage());
ReflectionUtils.rethrowException(response.getCause());
}
//isContinueOnError方法的功能点测试
@Test
public void testIsContinueOnError() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain3", 0);
Assert.assertTrue(response.isSuccess());
Assert.assertNull(response.getCause());
}
//isEnd方法的功能点测试
@Test
public void testIsEnd() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain4", 10);
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("d",response.getExecuteStepStr());
}
//setIsEnd方法的功能点测试
@Test
public void testSetIsEnd1() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain5", 10);
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("e",response.getExecuteStepStr());
}
//条件组件的功能点测试
@Test
public void testNodeCondComponent() {
LiteflowResponse response = flowExecutor.execute2Resp("chain6", 0);
Assert.assertTrue(response.isSuccess());
}
//测试setIsEnd如果为truecontinueError也为true那不应该continue了
@Test
public void testSetIsEnd2() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain7", 10);
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("g",response.getExecuteStepStr());
}
}

View File

@ -0,0 +1,26 @@
package com.yomahub.liteflow.test.component.cmp1;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
import java.util.Objects;
@Component("a")
public class ACmp extends NodeComponent {
@Override
public void process() {
System.out.println("AComp executed!");
this.getSlot().setResponseData("AComp executed!");
}
@Override
public boolean isAccess() {
Integer requestData = this.getRequestData();
if (Objects.nonNull(requestData) && requestData > 100){
return true;
}
System.out.println("AComp isAccess false.");
return false;
}
}

View File

@ -0,0 +1,29 @@
package com.yomahub.liteflow.test.component.cmp1;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
import java.util.Objects;
@Component("b")
public class BCmp extends NodeComponent {
@Override
public void process() {
System.out.println("BComp executed!");
Integer requestData = this.getRequestData();
Integer divisor = 130;
Integer result = divisor / requestData;
this.getSlot().setResponseData(result);
}
@Override
public boolean isAccess() {
Integer requestData = this.getRequestData();
if (Objects.nonNull(requestData)){
return true;
}
return false;
}
}

View File

@ -0,0 +1,29 @@
package com.yomahub.liteflow.test.component.cmp1;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
import java.util.Objects;
@Component("c")
public class CCmp extends NodeComponent {
@Override
public void process() {
System.out.println("CComp executed!");
Integer requestData = this.getRequestData();
Integer divisor = 130;
Integer result = divisor / requestData;
this.getSlot().setResponseData(result);
System.out.println("responseData="+Integer.parseInt(this.getSlot().getResponseData()));
}
@Override
public boolean isContinueOnError() {
Integer requestData = this.getRequestData();
if (Objects.nonNull(requestData)){
return true;
}
return false;
}
}

View File

@ -0,0 +1,26 @@
package com.yomahub.liteflow.test.component.cmp1;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
import java.util.Objects;
@Component("d")
public class DCmp extends NodeComponent {
@Override
public void process() throws Exception {
System.out.println("DComp executed!");
}
@Override
public boolean isEnd() {
//组件的process执行完之后才会执行isEnd
Object requestData = this.getSlot().getResponseData();
if (Objects.isNull(requestData)){
System.out.println("DComp flow isEnd, because of responseData is null.");
return true;
}
return false;
}
}

View File

@ -0,0 +1,24 @@
package com.yomahub.liteflow.test.component.cmp1;
import com.alibaba.fastjson.JSON;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
import java.util.Objects;
@Component("e")
public class ECmp extends NodeComponent {
@Override
public void process() throws Exception {
System.out.println("EComp executed!");
Object responseData = this.getSlot().getResponseData();
if (Objects.isNull(responseData)){
System.out.println("EComp responseData flow must be set end .");
//执行到某个条件时手动结束流程
this.setIsEnd(true);
}
System.out.println("EComp responseData responseData=" + JSON.toJSONString(responseData));
}
}

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.component.cmp1;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("g")
public class GCmp extends NodeComponent {
@Override
public void process() {
System.out.println("GCmp executed!");
this.setIsEnd(true);
}
@Override
public boolean isContinueOnError() {
return true;
}
}

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.component.cmp1;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("h")
public class HCmp extends NodeComponent {
@Override
public void process() {
System.out.println("HCmp executed!");
}
}

View File

@ -0,0 +1,22 @@
package com.yomahub.liteflow.test.component.cmp2;
import com.yomahub.liteflow.core.NodeSwitchComponent;
import org.springframework.stereotype.Component;
import java.util.Objects;
@Component("f")
public class FSwitchCmp extends NodeSwitchComponent {
@Override
public String processSwitch() {
Integer requestData = this.getRequestData();
if (Objects.isNull(requestData)){
return "d";
} else if(requestData == 0){
return "c";
} else {
return "b";
}
}
}

View File

@ -0,0 +1,45 @@
package com.yomahub.liteflow.test.config;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
/**
* spring环境下参数单元测试
* @author zendwang
* @since 2.5.0
*/
@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:/config/application-local.xml")
public class LiteflowConfigELSpringTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
@Autowired
private ApplicationContext context;
@Test
public void testConfig() throws Exception {
LiteflowConfig config = context.getBean(LiteflowConfig.class);
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("config/flow.el.json", config.getRuleSource());
Assert.assertEquals(15, config.getWhenMaxWaitSeconds().intValue());
Assert.assertEquals(200, config.getQueueLimit().intValue());
Assert.assertEquals(300000L, config.getDelay().longValue());
Assert.assertEquals(300000L, config.getPeriod().longValue());
Assert.assertFalse(config.getEnableLog());
// Assert.assertEquals(Runtime.getRuntime().availableProcessors() * 2, config.getWhenMaxWorkers().longValue());
Assert.assertEquals(512, config.getWhenQueueLimit().longValue());
}
}

View File

@ -0,0 +1,38 @@
package com.yomahub.liteflow.test.config;
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.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
/**
* spring环境下 rule-source 参数支持通配符支持模式匹配
* @author zendwang
* @since 2.5.0
*/
@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:/config/local-rule-source-pattern-match.xml")
public class LocalRuleSourcePatternMatchELSpringTest extends BaseTest {
@Resource
private FlowExecutor executor;
/**
* 匹配的文件
* config/springgroup0/flow0.json
* config/springgroup1/flow0.json
*/
@Test
public void testLocalJsonRuleSourcePatternMatch() {
LiteflowResponse response0 = executor.execute2Resp("chain1", "arg");
Assert.assertEquals("a==>b==>c", response0.getExecuteStepStr());
LiteflowResponse response1 = executor.execute2Resp("chain3", "arg");
Assert.assertEquals("a==>c==>f==>g", response1.getExecuteStepStr());
}
}

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.config.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!");
}
}

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.config.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!");
}
}

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.config.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!");
}
}

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.config.cmp;
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("DCmp executed!");
}
}

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.config.cmp;
import com.yomahub.liteflow.core.NodeSwitchComponent;
import org.springframework.stereotype.Component;
@Component("e")
public class ECmp extends NodeSwitchComponent {
@Override
public String processSwitch() throws Exception {
return "g";
}
}

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.config.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("f")
public class FCmp extends NodeComponent {
@Override
public void process() {
System.out.println("FCmp executed!");
}
}

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.config.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("g")
public class GCmp extends NodeComponent {
@Override
public void process() {
System.out.println("GCmp executed!");
}
}

View File

@ -0,0 +1,37 @@
package com.yomahub.liteflow.test.customNodes;
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.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
/**
* spring环境下自定义声明节点的测试
* @author Bryan.Zhang
* @since 2.6.4
*/
@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:/customNodes/application.xml")
public class CustomNodesELSpringTest extends BaseTest {
private final Logger log = LoggerFactory.getLogger(this.getClass());
@Resource
private FlowExecutor flowExecutor;
@Test
public void testCustomNodes() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertTrue(response.isSuccess());
response = flowExecutor.execute2Resp("chain2", "arg");
Assert.assertTrue(response.isSuccess());
}
}

View File

@ -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.customNodes.cmp;
import com.yomahub.liteflow.core.NodeComponent;
public class ACmp extends NodeComponent {
@Override
public void process() {
System.out.println("ACmp executed!");
}
}

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.customNodes.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.test.customNodes.domain.DemoDomain;
import javax.annotation.Resource;
public class BCmp extends NodeComponent {
@Resource
private DemoDomain demoDomain;
@Override
public void process() {
demoDomain.sayHi();
System.out.println("BCmp executed!");
}
}

View File

@ -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.customNodes.cmp;
import com.yomahub.liteflow.core.NodeComponent;
public class CCmp extends NodeComponent {
@Override
public void process() {
System.out.println("CCmp executed!");
}
}

View File

@ -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.customNodes.cmp;
import com.yomahub.liteflow.core.NodeComponent;
public class DCmp extends NodeComponent {
@Override
public void process() {
System.out.println("DCmp executed!");
}
}

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.customNodes.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.test.customNodes.domain.DemoDomain;
import javax.annotation.Resource;
public class ECmp extends NodeComponent {
@Resource
private DemoDomain demoDomain;
@Override
public void process() {
demoDomain.sayHi();
System.out.println("ECmp executed!");
}
}

View File

@ -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.customNodes.cmp;
import com.yomahub.liteflow.core.NodeComponent;
public class FCmp extends NodeComponent {
@Override
public void process() {
System.out.println("FCmp executed!");
}
}

View File

@ -0,0 +1,11 @@
package com.yomahub.liteflow.test.customNodes.domain;
import org.springframework.stereotype.Component;
@Component
public class DemoDomain {
public void sayHi(){
System.out.println("hi");
}
}

View File

@ -0,0 +1,25 @@
package com.yomahub.liteflow.test.customWhenThreadPool;
import cn.hutool.core.util.ObjectUtil;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.spi.holder.ContextAwareHolder;
import com.yomahub.liteflow.thread.ExecutorBuilder;
import java.util.concurrent.ExecutorService;
public class CustomThreadExecutor1 implements ExecutorBuilder {
@Override
public ExecutorService buildExecutor() {
LiteflowConfig liteflowConfig = ContextAwareHolder.loadContextAware().getBean(LiteflowConfig.class);
//只有在非spring的场景下liteflowConfig才会为null
if (ObjectUtil.isNull(liteflowConfig)) {
liteflowConfig = new LiteflowConfig();
}
return buildDefaultExecutor(
liteflowConfig.getWhenMaxWorkers(),
liteflowConfig.getWhenMaxWorkers(),
liteflowConfig.getWhenQueueLimit(),
"customer-when-1-thead-");
}
}

View File

@ -0,0 +1,24 @@
package com.yomahub.liteflow.test.customWhenThreadPool;
import cn.hutool.core.util.ObjectUtil;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.spi.holder.ContextAwareHolder;
import com.yomahub.liteflow.thread.ExecutorBuilder;
import java.util.concurrent.ExecutorService;
public class CustomThreadExecutor2 implements ExecutorBuilder {
@Override
public ExecutorService buildExecutor() {
LiteflowConfig liteflowConfig = ContextAwareHolder.loadContextAware().getBean(LiteflowConfig.class);
//只有在非spring的场景下liteflowConfig才会为null
if (ObjectUtil.isNull(liteflowConfig)) {
liteflowConfig = new LiteflowConfig();
}
return buildDefaultExecutor(
liteflowConfig.getWhenMaxWorkers(),
liteflowConfig.getWhenMaxWorkers(),
liteflowConfig.getWhenQueueLimit(),
"customer-when-2-thead-");
}
}

View File

@ -0,0 +1,24 @@
package com.yomahub.liteflow.test.customWhenThreadPool;
import cn.hutool.core.util.ObjectUtil;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.spi.holder.ContextAwareHolder;
import com.yomahub.liteflow.thread.ExecutorBuilder;
import java.util.concurrent.ExecutorService;
public class CustomThreadExecutor3 implements ExecutorBuilder {
@Override
public ExecutorService buildExecutor() {
LiteflowConfig liteflowConfig = ContextAwareHolder.loadContextAware().getBean(LiteflowConfig.class);
//只有在非spring的场景下liteflowConfig才会为null
if (ObjectUtil.isNull(liteflowConfig)) {
liteflowConfig = new LiteflowConfig();
}
return buildDefaultExecutor(
liteflowConfig.getWhenMaxWorkers(),
liteflowConfig.getWhenMaxWorkers(),
liteflowConfig.getWhenQueueLimit(),
"customer-when-3-thead-");
}
}

View File

@ -0,0 +1,69 @@
package com.yomahub.liteflow.test.customWhenThreadPool;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
/**
* spring环境下异步线程超时日志打印测试
*
* @author Bryan.Zhang
* @since 2.6.4
*/
@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:/customWhenThreadPool/application.xml")
public class CustomWhenThreadPoolELSpringTest extends BaseTest {
private final Logger log = LoggerFactory.getLogger(this.getClass());
@Resource
private FlowExecutor flowExecutor;
/**
* 测试全局线程池配置
*/
@Test
public void testGlobalThreadPool() {
LiteflowResponse response = flowExecutor.execute2Resp("chain", "arg");
DefaultContext context = response.getFirstContextBean();
Assert.assertTrue(response.isSuccess());
Assert.assertTrue(context.getData("threadName").toString().startsWith("lf-when-thead"));
}
/**
* 测试全局和when上自定义线程池-优先以when上为准
*/
@Test
public void testGlobalAndCustomWhenThreadPool() {
LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg");
DefaultContext context = response1.getFirstContextBean();
Assert.assertTrue(response1.isSuccess());
Assert.assertTrue(context.getData("threadName").toString().startsWith("customer-when-1-thead"));
}
/**
* when配置的线程池可以共用
*/
@Test
public void testCustomWhenThreadPool() {
// 使用when - thread1
testGlobalAndCustomWhenThreadPool();
// chain配置同一个thead1
LiteflowResponse response2 = flowExecutor.execute2Resp("chain2", "arg");
DefaultContext context = response2.getFirstContextBean();
Assert.assertTrue(response2.isSuccess());
Assert.assertTrue(context.getData("threadName").toString().startsWith("customer-when-1-thead"));
}
}

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.customWhenThreadPool.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!");
}
}

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.customWhenThreadPool.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("threadName", Thread.currentThread().getName());
System.out.println("BCmp executed!");
}
}

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.customWhenThreadPool.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("threadName", Thread.currentThread().getName());
System.out.println("CCmp executed!");
}
}

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.customWhenThreadPool.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("threadName", Thread.currentThread().getName());
System.out.println("DCmp executed!");
}
}

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.customWhenThreadPool.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();
context.setData("threadName", Thread.currentThread().getName());
System.out.println("ECmp executed!");
}
}

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.customWhenThreadPool.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("threadName", Thread.currentThread().getName());
System.out.println("FCmp executed!");
}
}

View File

@ -0,0 +1,28 @@
package com.yomahub.liteflow.test.emptyflow;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.test.BaseTest;
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;
/**
* 切面场景单元测试
* @author Bryan.Zhang
*/
@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:/emptyFlow/application.xml")
public class EmptyFlowELSpringTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
//测试空flow的情况下liteflow是否能正常启动
@Test
public void testEmptyFlow() {
//不做任何事为的是能正常启动
}
}

View File

@ -0,0 +1,41 @@
package com.yomahub.liteflow.test.enable;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.property.LiteflowConfigGetter;
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环境下enable参数
*
* @author qjwyss
* @since 2.6.0
*/
@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:/enable/application-local.xml")
public class LiteflowEnableELSpringTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
@Test
public void testEnable() throws Exception {
LiteflowConfig config = LiteflowConfigGetter.get();
Boolean enable = config.getEnable();
if (enable) {
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertTrue(response.isSuccess());
return;
}
Assert.assertFalse(enable);
}
}

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.enable.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!");
}
}

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.enable.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!");
}
}

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.enable.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!");
}
}

View File

@ -0,0 +1,52 @@
package com.yomahub.liteflow.test.event;
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;
@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:/event/application.xml")
public class EventELSpringTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
//测试组件成功事件
@Test
public void testEvent1() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
DefaultContext context = response.getFirstContextBean();
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("abc", context.getData("test"));
}
//测试组件失败事件
@Test
public void testEvent2() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
DefaultContext context = response.getFirstContextBean();
Assert.assertFalse(response.isSuccess());
Assert.assertEquals(NullPointerException.class, response.getCause().getClass());
Assert.assertEquals("ab", context.getData("test"));
Assert.assertEquals("error:d", context.getData("error"));
}
//测试组件失败事件本身抛出异常
@Test
public void testEvent3() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg");
DefaultContext context = response.getFirstContextBean();
Assert.assertFalse(response.isSuccess());
Assert.assertEquals(NullPointerException.class, response.getCause().getClass());
Assert.assertEquals("a", context.getData("test"));
Assert.assertEquals("error:e", context.getData("error"));
}
}

View File

@ -0,0 +1,31 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.event.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("test","");
System.out.println("ACmp executed!");
}
@Override
public void onSuccess() throws Exception {
DefaultContext context = this.getFirstContextBean();
String str = context.getData("test");
str += this.getNodeId();
context.setData("test", str);
}
}

Some files were not shown because too many files have changed in this diff Show More