Parcourir la source

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

bryan31 il y a 3 ans
Parent
commit
105d1fe98f

+ 15 - 6
liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeSpringbootTest.java

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

+ 1 - 0
liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/GCmp.java

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

+ 0 - 3
liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutSpringbootTest.java

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

+ 6 - 0
liteflow-testcase-springboot/src/test/resources/asyncNode/flow.xml

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