From bb3638d58382eda1857c1a2c4fdf1421e35d2c60 Mon Sep 17 00:00:00 2001 From: "meng.li" <53835420> Date: Thu, 8 Apr 2021 11:49:06 +0800 Subject: [PATCH] =?UTF-8?q?-=20[x]=20when=20condition=E4=B8=8B=E7=9A=84?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B=E6=B1=A0=E5=8A=9F=E8=83=BD=E6=B5=8B=E8=AF=95?= =?UTF-8?q?(=E5=9F=BA=E4=BA=8Espringboot=E7=8E=AF=E5=A2=83)=20=20=20-=20[x?= =?UTF-8?q?]=20=E7=BA=BF=E7=A8=8B=E6=B1=A0=E7=9A=84=E5=9F=BA=E6=9C=AC?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E7=82=B9=E6=B5=8B=E8=AF=95=20=20=20-=20[x]?= =?UTF-8?q?=20=E7=BA=BF=E7=A8=8B=E6=B1=A0=E6=BB=A1=E4=BA=86=E6=83=85?= =?UTF-8?q?=E5=86=B5=E4=B8=8B=E5=9F=BA=E4=BA=8EerrorResume=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E7=9A=84=E5=8A=9F=E8=83=BD=E7=82=B9=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=20-=20[x]=20when=E5=B9=B6=E8=A1=8C=E7=BB=84=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E6=B5=8B=E8=AF=95(=E5=9F=BA=E4=BA=8Espringboot=E7=8E=AF?= =?UTF-8?q?=E5=A2=83)=20=20=20-=20[x]=20=E9=BB=98=E8=AE=A4=E4=B8=8D?= =?UTF-8?q?=E9=85=8D=E5=8F=82=E6=95=B0=E6=83=85=E5=86=B5=E4=B8=8B=E5=B9=B6?= =?UTF-8?q?=E8=A1=8C=E7=BB=84=E7=9A=84=E5=8A=9F=E8=83=BD=E7=82=B9=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=20=20=20-=20[x]=20=E9=85=8D=E7=BD=AE=E7=9B=B8?= =?UTF-8?q?=E5=90=8C=E5=B9=B6=E8=A1=8C=E7=BB=84=E6=83=85=E5=86=B5=E4=B8=8B?= =?UTF-8?q?=E7=9A=84=E5=8A=9F=E8=83=BD=E7=82=B9=E6=B5=8B=E8=AF=95=20=20=20?= =?UTF-8?q?-=20[x]=20=E9=85=8D=E7=BD=AE=E4=B8=8D=E5=90=8C=E5=B9=B6?= =?UTF-8?q?=E8=A1=8C=E7=BB=84=E6=83=85=E5=86=B5=E4=B8=8B=E7=9A=84=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E7=82=B9=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 测试用例提交 --- .../test/condition/BaseConditionFlowTest.java | 56 +++++++++++++------ .../liteflow/test/condition/cmp1/DCmp.java | 1 + .../src/test/resources/condition/flow.xml | 8 +-- 3 files changed, 40 insertions(+), 25 deletions(-) diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/BaseConditionFlowTest.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/BaseConditionFlowTest.java index 06a79ed15..d4986d7aa 100644 --- a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/BaseConditionFlowTest.java +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/BaseConditionFlowTest.java @@ -4,6 +4,8 @@ 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.exception.FlowSystemException; +import com.yomahub.liteflow.exception.WhenExecuteException; import com.yomahub.liteflow.test.BaseTest; import org.junit.Assert; import org.junit.Test; @@ -35,9 +37,13 @@ public class BaseConditionFlowTest extends BaseTest { @Resource private FlowExecutor flowExecutor; - public static final List RUN_TIME_SLOT = Lists.newArrayList(); + public static List RUN_TIME_SLOT = Lists.newArrayList(); - //正常 then,when,多chain可以执行 + /***** + * 标准chain 嵌套选择 嵌套子chain进行执行 + * 验证了when情况下 多个node是并行执行 + * 验证了默认参数情况下 when可以加载执行 + * **/ @Test public void testBaseConditionFlow() throws Exception { LiteflowResponse response = flowExecutor.execute("chain1", "it's a base request"); @@ -45,20 +51,31 @@ public class BaseConditionFlowTest extends BaseTest { System.out.println(response.getData().printStep()); } - //正常 when 多个并联 合并 errorMessage参照上一组配置 导致error异常 都可以继续执行 + /***** + * 标准chain + * 验证多层when 相同组 会合并node + * 验证多层when errorResume 合并 并参照最上层 errorResume配置 + * **/ @Test public void testBaseErrorResumeConditionFlow4() throws Exception { + RUN_TIME_SLOT.clear(); LiteflowResponse 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 就拦截 + /***** + * 标准chain + * 验证多层when 相同组 会合并node + * 验证多层when errorResume 合并 并参照最上层 errorResume配置 + * **/ @Test public void testBaseErrorResumeConditionFlow5() throws Exception { + RUN_TIME_SLOT.clear(); LiteflowResponse response = flowExecutor.execute("chain5", "it's a base request"); System.out.println(response.isSuccess()); System.out.println(response.getData().printStep()); @@ -67,10 +84,17 @@ public class BaseConditionFlowTest extends BaseTest { Assert.assertEquals(2, RUN_TIME_SLOT.size()); // set中第一次设置的requestId和response中的requestId一致 Assert.assertTrue(RUN_TIME_SLOT.contains(response.getData().getRequestId())); + } - @Test + /***** + * 标准chain + * 验证多层when 不同组 不会合并node + * 验证多层when errorResume 不同组 配置分开配置 + * **/ + @Test(expected = WhenExecuteException.class) public void testBaseErrorResumeConditionFlow6() throws Exception { + RUN_TIME_SLOT.clear(); LiteflowResponse response = flowExecutor.execute("chain6", "it's a base request"); System.out.println(response.isSuccess()); System.out.println(response.getData().printStep()); @@ -80,11 +104,17 @@ public class BaseConditionFlowTest extends BaseTest { // set中第一次设置的requestId和response中的requestId一致 Assert.assertTrue(RUN_TIME_SLOT.contains(response.getData().getRequestId())); ReflectionUtils.rethrowException(response.getCause()); + } - - @Test + /***** + * 标准chain + * 验证多层when 不同组 不会合并node + * 验证多层when errorResume 不同组 配置分开配置 + * **/ + @Test(expected = WhenExecuteException.class) public void testBaseErrorResumeConditionFlow7() throws Exception { + RUN_TIME_SLOT.clear(); LiteflowResponse response = flowExecutor.execute("chain7", "it's a base request"); System.out.println(response.isSuccess()); System.out.println(response.getData().printStep()); @@ -93,17 +123,7 @@ public class BaseConditionFlowTest extends BaseTest { Assert.assertEquals(2, BaseConditionFlowTest.RUN_TIME_SLOT.size()); // set中第一次设置的requestId和response中的requestId一致 Assert.assertTrue(RUN_TIME_SLOT.contains(response.getData().getRequestId())); - } + ReflectionUtils.rethrowException(response.getCause()); - @Test - public void testBaseErrorResumeConditionFlow8() throws Exception { - LiteflowResponse 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())); } } diff --git a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/cmp1/DCmp.java b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/cmp1/DCmp.java index 53a188b7b..40a607222 100644 --- a/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/cmp1/DCmp.java +++ b/liteflow-spring-boot-starter/src/test/java/com/yomahub/liteflow/test/condition/cmp1/DCmp.java @@ -8,6 +8,7 @@ import org.springframework.stereotype.Component; public class DCmp extends NodeComponent { @Override public void process() throws Exception { + Thread.sleep(3000); System.out.println("Dcomp executed!"); } } diff --git a/liteflow-spring-boot-starter/src/test/resources/condition/flow.xml b/liteflow-spring-boot-starter/src/test/resources/condition/flow.xml index e87f8d409..895b23dff 100644 --- a/liteflow-spring-boot-starter/src/test/resources/condition/flow.xml +++ b/liteflow-spring-boot-starter/src/test/resources/condition/flow.xml @@ -3,7 +3,6 @@ - @@ -13,7 +12,7 @@ - + @@ -40,10 +39,5 @@ - - - - - \ No newline at end of file