对异步线程的测试用例进行了重写

This commit is contained in:
bryan31
2021-11-09 22:15:05 +08:00
parent 50980a45a1
commit 105d1fe98f
4 changed files with 22 additions and 9 deletions

View File

@@ -38,14 +38,14 @@ public class AsyncNodeSpringbootTest extends BaseTest {
* 验证了默认参数情况下 when可以加载执行
* **/
@Test
public void testBaseConditionFlow1() {
public void testAsyncFlow1() {
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "it's a base request");
Assert.assertTrue(response.isSuccess());
System.out.println(response.getSlot().printStep());
}
@Test
public void testBaseConditionFlow2() {
public void testAsyncFlow2() {
LiteflowResponse<DefaultSlot> 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",
@@ -55,7 +55,7 @@ public class AsyncNodeSpringbootTest extends BaseTest {
//相同group的并行组会合并并且errorResume根据第一个when来这里第一个when配置了不抛错
@Test
public void testBaseErrorResumeConditionFlow4() {
public void testAsyncFlow4() {
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain4", "it's a base request");
//因为不记录错误所以最终结果是true
Assert.assertTrue(response.isSuccess());
@@ -68,7 +68,7 @@ public class AsyncNodeSpringbootTest extends BaseTest {
//相同group的并行组会合并并且errorResume根据第一个when来这里第一个when配置了会抛错
@Test
public void testBaseErrorResumeConditionFlow5() throws Exception {
public void testAsyncFlow5() throws Exception {
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain5", "it's a base request");
//整个并行组是报错的所以最终结果是false
Assert.assertFalse(response.isSuccess());
@@ -81,7 +81,7 @@ public class AsyncNodeSpringbootTest extends BaseTest {
//不同group的并行组不会合并第一个when的errorResume是false会抛错那第二个when就不会执行
@Test
public void testBaseErrorResumeConditionFlow6() throws Exception {
public void testAsyncFlow6() throws Exception {
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain6", "it's a base request");
//第一个when会抛错所以最终结果是false
Assert.assertFalse(response.isSuccess());
@@ -94,7 +94,7 @@ public class AsyncNodeSpringbootTest extends BaseTest {
//不同group的并行组不会合并第一个when的errorResume是true不会报错那第二个when还会继续执行但是第二个when的errorResume是false所以第二个when会报错
@Test
public void testBaseErrorResumeConditionFlow7() throws Exception {
public void testAsyncFlow7() throws Exception {
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain7", "it's a base request");
//第二个when会抛错所以最终结果是false
Assert.assertFalse(response.isSuccess());
@@ -104,4 +104,13 @@ public class AsyncNodeSpringbootTest extends BaseTest {
//第一个when会报错所以最终response的cause里应该会有TestException
Assert.assertEquals(TestException.class, response.getCause().getClass());
}
//d g h并行配置了any=true其中d耗时3秒g耗时1秒其他都不设耗时
//最终执行效果应该是h先返回然后执行abc,最后gd
//这里要注意的是由于step是先加入所以step的打印顺序并不是这样的。但是实际执行是正确的
@Test
public void testAsyncFlow8() throws Exception {
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain8", "it's a base request");
Assert.assertTrue(response.isSuccess());
}
}

View File

@@ -9,6 +9,7 @@ public class GCmp extends NodeComponent {
@Override
public void process() throws Exception {
Thread.sleep(1000);
System.out.println("Gcomp executed!");
}
}

View File

@@ -1,11 +1,8 @@
package com.yomahub.liteflow.test.whenTimeOut;
import cn.hutool.core.io.resource.ResourceUtil;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.enums.FlowParserTypeEnum;
import com.yomahub.liteflow.flow.FlowBus;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.Assert;
import org.junit.Test;

View File

@@ -37,4 +37,10 @@
<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">
<when value="d,g,h" any="true"/> <!-- a b c 串联执行-->
<then value="a,b,c"/> <!-- d g h 并联执行,任意一个执行完毕即结束-->
</chain>
</flow>