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