Merge branch 'v2.5.0-SNAPSHOT' of https://gitee.com/dromara/liteFlow into v2.5.0-SNAPSHOT

This commit is contained in:
bryan31
2021-04-08 10:47:06 +08:00
14 changed files with 307 additions and 18 deletions

View File

@@ -0,0 +1,109 @@
package com.yomahub.liteflow.test.condition;
import com.google.common.collect.Lists;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.entity.data.Slot;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.ReflectionUtils;
import javax.annotation.Resource;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* 测试隐式调用子流程
* 单元测试
*
* @author ssss
*/
@RunWith(SpringRunner.class)
@TestPropertySource(value = "classpath:/condition/application-condition.properties")
@SpringBootTest(classes = BaseConditionFlowTest.class)
@EnableAutoConfiguration
@ComponentScan({"com.yomahub.liteflow.test.condition.cmp1"})
public class BaseConditionFlowTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
public static final List<String> RUN_TIME_SLOT = Lists.newArrayList();
//正常 then,when,多chain可以执行
@Test
public void testBaseConditionFlow() throws Exception {
LiteflowResponse<Slot> response = flowExecutor.execute("chain1", "it's a base request");
Assert.assertTrue(response.isSuccess());
System.out.println(response.getData().printStep());
}
//正常 when 多个并联 合并 errorMessage参照上一组配置 导致error异常 都可以继续执行
@Test
public void testBaseErrorResumeConditionFlow4() throws Exception {
LiteflowResponse<Slot> response = flowExecutor.execute("chain4", "it's a base request");
Assert.assertTrue(response.isSuccess());
// 传递了slotIndex则set的size==2
Assert.assertEquals(2, RUN_TIME_SLOT.size());
// set中第一次设置的requestId和response中的requestId一致
Assert.assertTrue(RUN_TIME_SLOT.contains(response.getData().getRequestId()));
}
//正常 when 多个并联 合并 errorMessage参照上一组配置 导致error异常 直接第一组error 就拦截
@Test
public void testBaseErrorResumeConditionFlow5() throws Exception {
LiteflowResponse<Slot> response = flowExecutor.execute("chain5", "it's a base request");
System.out.println(response.isSuccess());
System.out.println(response.getData().printStep());
Assert.assertFalse(response.isSuccess());
// 传递了slotIndex则set的size==2
Assert.assertEquals(2, RUN_TIME_SLOT.size());
// set中第一次设置的requestId和response中的requestId一致
Assert.assertTrue(RUN_TIME_SLOT.contains(response.getData().getRequestId()));
}
@Test
public void testBaseErrorResumeConditionFlow6() throws Exception {
LiteflowResponse<Slot> response = flowExecutor.execute("chain6", "it's a base request");
System.out.println(response.isSuccess());
System.out.println(response.getData().printStep());
Assert.assertFalse(response.isSuccess());
// 传递了slotIndex则set的size==1
Assert.assertEquals(1, RUN_TIME_SLOT.size());
// set中第一次设置的requestId和response中的requestId一致
Assert.assertTrue(RUN_TIME_SLOT.contains(response.getData().getRequestId()));
ReflectionUtils.rethrowException(response.getCause());
}
@Test
public void testBaseErrorResumeConditionFlow7() throws Exception {
LiteflowResponse<Slot> response = flowExecutor.execute("chain7", "it's a base request");
System.out.println(response.isSuccess());
System.out.println(response.getData().printStep());
Assert.assertFalse(response.isSuccess());
// 传递了slotIndex则set的size==2
Assert.assertEquals(2, BaseConditionFlowTest.RUN_TIME_SLOT.size());
// set中第一次设置的requestId和response中的requestId一致
Assert.assertTrue(RUN_TIME_SLOT.contains(response.getData().getRequestId()));
}
@Test
public void testBaseErrorResumeConditionFlow8() throws Exception {
LiteflowResponse<Slot> response = flowExecutor.execute("chain8", "it's a base request");
System.out.println(response.isSuccess());
System.out.println(response.getData().printStep());
Assert.assertFalse(response.isSuccess());
// 传递了slotIndex则set的size==2
Assert.assertEquals(2, BaseConditionFlowTest.RUN_TIME_SLOT.size());
// set中第一次设置的requestId和response中的requestId一致
Assert.assertTrue(RUN_TIME_SLOT.contains(response.getData().getRequestId()));
}
}

View File

@@ -0,0 +1,13 @@
package com.yomahub.liteflow.test.condition.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,13 @@
package com.yomahub.liteflow.test.condition.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,13 @@
package com.yomahub.liteflow.test.condition.cmp1;
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("Ccomp executed!");
}
}

View File

@@ -0,0 +1,13 @@
package com.yomahub.liteflow.test.condition.cmp1;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("d")
public class DCmp extends NodeComponent {
@Override
public void process() throws Exception {
System.out.println("Dcomp executed!");
}
}

View File

@@ -0,0 +1,16 @@
package com.yomahub.liteflow.test.condition.cmp1;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.core.NodeCondComponent;
import org.springframework.stereotype.Component;
@Component("e")
public class ECmp extends NodeCondComponent {
@Override
public String processCond() throws Exception {
System.out.println("Ecomp executed!");
return "g";
}
}

View File

@@ -0,0 +1,14 @@
package com.yomahub.liteflow.test.condition.cmp1;
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,14 @@
package com.yomahub.liteflow.test.condition.cmp1;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("g")
public class GCmp extends NodeComponent {
@Override
public void process() throws Exception {
System.out.println("Gcomp executed!");
}
}

View File

@@ -0,0 +1,14 @@
package com.yomahub.liteflow.test.condition.cmp1;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("h")
public class HCmp extends NodeComponent {
@Override
public void process() throws Exception {
System.out.println("Hcomp executed!");
}
}

View File

@@ -0,0 +1,19 @@
package com.yomahub.liteflow.test.condition.cmp1;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.test.condition.BaseConditionFlowTest;
import org.springframework.stereotype.Component;
@Component("i")
public class ICmp extends NodeComponent {
@Override
public void process() throws Exception {
BaseConditionFlowTest.RUN_TIME_SLOT.add(this.getSlot().getRequestId());
System.out.println(BaseConditionFlowTest.RUN_TIME_SLOT.size());
System.out.println("Icomp executed! throw Exception!");
throw new RuntimeException("主动抛出异常");
}
}

View File

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

View File

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

View File

@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<!-- base test -->
<chain name="chain1">
<then value="a,b,c"/> <!-- a b c 串联执行-->
<then value="c"/>
<when value="d,e(f|g)"/> <!-- e d 并联执行-->
<then value="chain2"/>
</chain>
<chain name="chain2">
<then value="b,a"/>
<then value="chain3"/>
</chain>
<chain name="chain3">
<then value="f,g,h"/>
</chain>
<chain name="chain4">
<then value="a,b,c"/> <!-- a b c 串联执行-->
<when value="d,i" errorResume="true"/> <!-- d i 并联执行-->
<when value="g,i,h" errorResume="false"/><!-- 此时 g i h 与 d i并联执行 并且默认异常不抛出-->
</chain>
<chain name="chain5">
<then value="a,b,c"/> <!-- a b c 串联执行-->
<when value="d,i" errorResume="false"/> <!-- d i 并联执行-->
<when value="g,i,h" errorResume="true"/><!-- 此时 g i h 与 d i并联执行 并且默认异常抛出-->
</chain>
<chain name="chain6">
<then value="a,b,c"/> <!-- a b c 串联执行-->
<when value="d,i" errorResume="false" group="1"/> <!-- d i 并联执行-->
<when value="g,i,h" errorResume="true" group="2"/><!-- 此时 g i h 与 d i并联执行 并且默认异常抛出-->
</chain>
<chain name="chain7">
<then value="a,b,c"/> <!-- a b c 串联执行-->
<when value="d,i" errorResume="true" group="1"/> <!-- d i 并联执行-->
<when value="g,i,h" errorResume="false" group="2"/><!-- 此时 g i h 与 d i并联执行 并且默认异常抛出-->
</chain>
<chain name="chain8">
<then value="a,b,c"/> <!-- a b c 串联执行-->
<when value="d,i" errorResume="true" group="1"/> <!-- d i 并联执行-->
<when value="g,i,h" errorResume="false" group="2"/><!-- 此时 g i h 与 d i并联执行 并且默认异常抛出-->
</chain>
<!-- base test -->
</flow>

View File

@@ -35,7 +35,7 @@
- [x] Json方式在springboot环境下测试
- [x] Yml方式在无spring环境下测试
- [x] Yml方式在spring环境下测试
- [x] Yml方式在springboot环境下测试
- [] Yml方式在springboot环境下测试
- [ ] 参数测试(只测到参数是不是被总的LiteFlowConfig加载到即可)
- [ ] 非spring环境下的参数测试必要参数测试非必须参数的默认值测试。
@@ -44,16 +44,16 @@
- [ ] zk配置源的功能测试(zk请自己本地安装提供)
- [ ] spring环境下的zk配置源功能测试
- [ ] springboot环境下的zk配置源功能测试
- [ ] 自定义源的功能测试
- [ ] spring环境下的自定义配置源功能测试
- [ ] springboot环境下的自定义配置源功能测试
- [ ] 组件功能点测试(基于springboot环境即可)
- [ ] isAccess方法的功能测试
- [ ] 组件抛错的功能点测试
- [ ] isContinueOnError方法的功能点测试
- [ ] isEnd方法和this.setIsEnd(true)的功能点测试
- [ ] 条件组件功能点测试(基于springboot环境)
- [ ] 条件组件的功能点测试
- [x] 自定义源的功能测试
- [x] spring环境下的自定义配置源功能测试
- [x] springboot环境下的自定义配置源功能测试
- [x] 组件功能点测试(基于springboot环境即可)
- [x] isAccess方法的功能测试
- [x] 组件抛错的功能点测试
- [x] isContinueOnError方法的功能点测试
- [x] isEnd方法和this.setIsEnd(true)的功能点测试
- [x] 条件组件功能点测试(基于springboot环境)
- [x] 条件组件的功能点测试
- [x] 显式子流程测试(基于springboot环境)
- [x] 子流程功能点测试,是否能进入子流程
- [x] 多个子流程是否能串联衔接
@@ -62,11 +62,11 @@
- [x] 隐式子流程测试(基于springboot环境)
- [x] 隐式子流程的功能点测试
- [x] 多个隐式子流程是否能共享同一个上下文
- [ ] when condition下的线程池功能测试(基于springboot环境)
- [ ] 线程池的基本功能点测试
- [ ] 线程池满了情况下基于errorResume参数的功能点测试
- [ ] when并行组功能测试(基于springboot环境)
- [ ] 默认不配参数情况下并行组的功能点测试
- [ ] 配置相同并行组情况下的功能点测试
- [ ] 配置不同并行组情况下的功能点测试
- [x] when condition下的线程池功能测试(基于springboot环境)
- [x] 线程池的基本功能点测试
- [x] 线程池满了情况下基于errorResume参数的功能点测试
- [x] when并行组功能测试(基于springboot环境)
- [x] 默认不配参数情况下并行组的功能点测试
- [x] 配置相同并行组情况下的功能点测试
- [x] 配置不同并行组情况下的功能点测试