diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/FallbackCmp.java b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/FallbackCmp.java index caf9deed6..a1e9ae2bd 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/FallbackCmp.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/FallbackCmp.java @@ -11,17 +11,13 @@ import java.lang.annotation.Target; /** * 降级组件 + * * @author DaleLee + * @since 2.11.1 */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited public @interface FallbackCmp { - - /** - * 节点类型 - * @return NodeTypeEnum - */ - NodeTypeEnum type() default NodeTypeEnum.COMMON; } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/NodeOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/NodeOperator.java index 7f7849b53..16e3ae0e8 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/NodeOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/NodeOperator.java @@ -12,7 +12,8 @@ import com.yomahub.liteflow.property.LiteflowConfigGetter; /** * EL规则中的node的操作符 * - * @author Bryan.Zhang,DaleLee + * @author Bryan.Zhang + * @author DaleLee * @since 2.8.3 */ public class NodeOperator extends BaseOperator { diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/FallbackCmpNotFoundException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/FallbackCmpNotFoundException.java index de930dfee..5a1eca0b2 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/FallbackCmpNotFoundException.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/FallbackCmpNotFoundException.java @@ -4,6 +4,7 @@ package com.yomahub.liteflow.exception; * 没有找到降级组件异常 * * @author DaleLee + * @since 2.11.1 */ public class FallbackCmpNotFoundException extends RuntimeException { diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/FlowBus.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/FlowBus.java index b77f564db..db3c0e654 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/FlowBus.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/FlowBus.java @@ -294,9 +294,6 @@ public class FlowBus { } NodeTypeEnum nodeType = node.getType(); - if (nodeType == null) { - nodeType = fallbackCmp.type(); - } fallbackNodeMap.put(nodeType, node); } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/FallbackNodeProxy.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/FallbackNodeProxy.java index e4f7cb370..e19119c93 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/FallbackNodeProxy.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/FallbackNodeProxy.java @@ -21,7 +21,7 @@ import com.yomahub.liteflow.slot.Slot; * 降级组件代理 * * @author DaleLee - * @since + * @since 2.11.1 */ public class FallbackNodeProxy extends Node { diff --git a/liteflow-solon-plugin/src/main/resources/META-INF/liteflow-default.properties b/liteflow-solon-plugin/src/main/resources/META-INF/liteflow-default.properties index 35a41afd5..c1fda2e94 100644 --- a/liteflow-solon-plugin/src/main/resources/META-INF/liteflow-default.properties +++ b/liteflow-solon-plugin/src/main/resources/META-INF/liteflow-default.properties @@ -13,8 +13,8 @@ liteflow.retry-count=0 liteflow.support-multiple-type=false liteflow.node-executor-class=com.yomahub.liteflow.flow.executor.DefaultNodeExecutor liteflow.print-execution-log=true -liteflow.substitute-cmp-class= liteflow.monitor.enable-log=false liteflow.monitor.queue-limit=200 liteflow.monitor.delay=300000 liteflow.monitor.period=300000 +liteflow.fallback-cmp-enable=false diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/FallbackELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/FallbackELDeclSpringbootTest.java new file mode 100644 index 000000000..2f9f592ed --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/FallbackELDeclSpringbootTest.java @@ -0,0 +1,225 @@ +package com.yomahub.liteflow.test.fallback; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +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 javax.annotation.Resource; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; + +/** + * SpringBoot 降级组件测试 + * + * @author DaleLee + * @since 2.11.1 + */ +@TestPropertySource(value = "classpath:/fallback/application.properties") +@SpringBootTest(classes = FallbackELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.fallback.cmp"}) +public class FallbackELDeclSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testThen1() { + LiteflowResponse response = flowExecutor.execute2Resp("then1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("a==>c", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testThen2() { + LiteflowResponse response = flowExecutor.execute2Resp("then2", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("c==>c==>c", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testWhen1() { + LiteflowResponse response = flowExecutor.execute2Resp("when1", "arg"); + Assertions.assertTrue(response.isSuccess()); + String executeStepStr = response.getExecuteStepStrWithoutTime(); + Assertions.assertTrue("b==>c".equals(executeStepStr) || "c==>b".equals(executeStepStr)); + } + + @Test + public void testIf1() { + LiteflowResponse response = flowExecutor.execute2Resp("if1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("ifn2", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testIf2() { + LiteflowResponse response = flowExecutor.execute2Resp("if2", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("ifn1==>c", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testFor1() { + LiteflowResponse response = flowExecutor.execute2Resp("for1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("for1==>a==>a==>a", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testFor2() { + LiteflowResponse response = flowExecutor.execute2Resp("for2", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("LOOP_3==>c==>c==>c", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testWhile1() { + LiteflowResponse response = flowExecutor.execute2Resp("while1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("wn2", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testWhile2() { + LiteflowResponse response = flowExecutor.execute2Resp("while2", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("wn1==>c==>wn1==>c==>wn1==>c==>wn1", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testIterator1() { + LiteflowResponse response = flowExecutor.execute2Resp("iterator1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("itn2", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testIterator2() { + LiteflowResponse response = flowExecutor.execute2Resp("iterator2", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("itn1==>c==>c==>c", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testBreak1() { + LiteflowResponse response = flowExecutor.execute2Resp("break1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("LOOP_3==>a==>bn1", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testBreak2() { + LiteflowResponse response = flowExecutor.execute2Resp("break2", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("wn1==>a==>bn1", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testBreak3() { + LiteflowResponse response = flowExecutor.execute2Resp("break3", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("itn1==>a==>bn1", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testSwitch1() { + LiteflowResponse response = flowExecutor.execute2Resp("switch1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("swn2==>b", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testSwitch2() { + LiteflowResponse response = flowExecutor.execute2Resp("switch2", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("swn1==>a", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testAnd1() { + LiteflowResponse response = flowExecutor.execute2Resp("and1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("ifn2", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testOr1() { + LiteflowResponse response = flowExecutor.execute2Resp("or1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("ifn2==>ifn1==>a", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testNot1() { + LiteflowResponse response = flowExecutor.execute2Resp("not1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("ifn2==>a", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testCatch1() { + LiteflowResponse response = flowExecutor.execute2Resp("catch1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("a==>d==>c", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testMulti1() { + LiteflowResponse response = flowExecutor.execute2Resp("multi1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("a==>c==>ifn2", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testMulti2() { + LiteflowResponse response = flowExecutor.execute2Resp("multi2", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("ifn2==>ifn1==>a==>c", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testMulti3() { + LiteflowResponse response = flowExecutor.execute2Resp("multi3", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("for1==>b==>c==>b==>c==>b==>c", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testConcurrent1() { + LiteflowResponse response = flowExecutor.execute2Resp("concurrent1", "arg"); + Assertions.assertTrue(response.isSuccess()); + String stepStr = response.getExecuteStepStrWithoutTime(); + Assertions.assertTrue("c==>ifn2".equals(stepStr) || "ifn2==>c".equals(stepStr)); + } + + @Test + public void testConcurrent2() { + LiteflowResponse response = flowExecutor.execute2Resp("concurrent2", "arg"); + Assertions.assertTrue(response.isSuccess()); + String stepStr = response.getExecuteStepStrWithoutTime(); + Assertions.assertTrue("c==>ifn2".equals(stepStr) || "ifn2==>c".equals(stepStr)); + } + + @Test + public void testConcurrent3() throws ExecutionException, InterruptedException { + // 执行多条 chain + Future future1 = flowExecutor.execute2Future("concurrent1", "arg", new Object()); + Future future2 = flowExecutor.execute2Future("concurrent2", "arg", new Object()); + Thread.sleep(1000); + LiteflowResponse response1 = future1.get(); + LiteflowResponse response2 = future2.get(); + Assertions.assertTrue(response1.isSuccess()); + String stepStr1 = response1.getExecuteStepStrWithoutTime(); + Assertions.assertTrue("c==>ifn2".equals(stepStr1) || "ifn2==>c".equals(stepStr1)); + Assertions.assertTrue(response2.isSuccess()); + String stepStr2 = response2.getExecuteStepStrWithoutTime(); + Assertions.assertTrue("c==>ifn2".equals(stepStr2) || "ifn2==>c".equals(stepStr2)); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/ACmp.java new file mode 100644 index 000000000..913035fd4 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/ACmp.java @@ -0,0 +1,16 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("a") +public class ACmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BCmp.java new file mode 100644 index 000000000..af597c5b4 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BCmp.java @@ -0,0 +1,16 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("b") +public class BCmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BreakCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BreakCmp.java new file mode 100644 index 000000000..fcbd8e7eb --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BreakCmp.java @@ -0,0 +1,20 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.FallbackCmp; +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.enums.NodeTypeEnum; + +@LiteflowComponent("bn1") +@LiteflowCmpDefine(NodeTypeEnum.BREAK) +@FallbackCmp +public class BreakCmp { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BREAK) + public boolean processBreak(NodeComponent bindCmp) throws Exception { + return true; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/CCmp.java new file mode 100644 index 000000000..e74168e37 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/CCmp.java @@ -0,0 +1,18 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.FallbackCmp; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("c") +@FallbackCmp +public class CCmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/DCmp.java new file mode 100644 index 000000000..23107e654 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/DCmp.java @@ -0,0 +1,15 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("d") +public class DCmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + throw new RuntimeException("component[d]"); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/ForCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/ForCmp.java new file mode 100644 index 000000000..99596035d --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/ForCmp.java @@ -0,0 +1,20 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.FallbackCmp; +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.enums.NodeTypeEnum; + +@LiteflowComponent("for1") +@LiteflowCmpDefine(NodeTypeEnum.FOR) +@FallbackCmp +public class ForCmp { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_FOR) + public int processFor(NodeComponent bindCmp) throws Exception { + return 3; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp1.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp1.java new file mode 100644 index 000000000..bd1c6f51e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp1.java @@ -0,0 +1,18 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.enums.NodeTypeEnum; + +@LiteflowComponent("ifn1") +@LiteflowCmpDefine(NodeTypeEnum.IF) +public class IfCmp1 { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_IF) + public boolean processIf(NodeComponent bindCmp) throws Exception { + return true; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp2.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp2.java new file mode 100644 index 000000000..5af938e89 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp2.java @@ -0,0 +1,20 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.FallbackCmp; +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.enums.NodeTypeEnum; + +@LiteflowComponent("ifn2") +@LiteflowCmpDefine(NodeTypeEnum.IF) +@FallbackCmp +public class IfCmp2 { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_IF) + public boolean processIf(NodeComponent bindCmp) throws Exception { + return false; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IteratorCmp1.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IteratorCmp1.java new file mode 100644 index 000000000..1ee36ed1d --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IteratorCmp1.java @@ -0,0 +1,21 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.enums.NodeTypeEnum; + +import java.util.Arrays; +import java.util.Iterator; + +@LiteflowComponent("itn1") +@LiteflowCmpDefine(NodeTypeEnum.ITERATOR) +public class IteratorCmp1 { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_ITERATOR) + public Iterator processIterator(NodeComponent bindCmp) throws Exception { + return Arrays.asList("a", "b", "c").iterator(); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IteratorCmp2.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IteratorCmp2.java new file mode 100644 index 000000000..eab745bb8 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IteratorCmp2.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.FallbackCmp; +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.enums.NodeTypeEnum; + +import java.util.Collections; +import java.util.Iterator; + +@LiteflowComponent("itn2") +@LiteflowCmpDefine(NodeTypeEnum.ITERATOR) +@FallbackCmp +public class IteratorCmp2 { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_ITERATOR) + public Iterator processIterator(NodeComponent bindCmp) throws Exception { + return Collections.emptyIterator(); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/SwitchCmp1.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/SwitchCmp1.java new file mode 100644 index 000000000..46948f736 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/SwitchCmp1.java @@ -0,0 +1,18 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.enums.NodeTypeEnum; + +@LiteflowComponent("swn1") +@LiteflowCmpDefine(NodeTypeEnum.SWITCH) +public class SwitchCmp1 { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH) + public String processSwitch(NodeComponent bindCmp) throws Exception { + return "a"; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/SwitchCmp2.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/SwitchCmp2.java new file mode 100644 index 000000000..7da7c7100 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/SwitchCmp2.java @@ -0,0 +1,20 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.FallbackCmp; +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.enums.NodeTypeEnum; + +@LiteflowComponent("swn2") +@LiteflowCmpDefine(NodeTypeEnum.SWITCH) +@FallbackCmp +public class SwitchCmp2 { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH) + public String processSwitch(NodeComponent bindCmp) throws Exception { + return "b"; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp1.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp1.java new file mode 100644 index 000000000..0d65cfb12 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp1.java @@ -0,0 +1,31 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.enums.NodeTypeEnum; + +import java.util.HashSet; +import java.util.Set; + +@LiteflowComponent("wn1") +@LiteflowCmpDefine(NodeTypeEnum.WHILE) +public class WhileCmp1 { + private int count = 0; + + // 执行过的 chain + Set executedChain = new HashSet<>(); + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_WHILE) + public boolean processWhile(NodeComponent bindCmp) throws Exception { + // 判断是否切换了 chain + if (!executedChain.contains(bindCmp.getCurrChainId())) { + count = 0; + executedChain.add(bindCmp.getCurrChainId()); + } + count++; + return count <= 3; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp2.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp2.java new file mode 100644 index 000000000..a9bef49b7 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp2.java @@ -0,0 +1,20 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.FallbackCmp; +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.enums.NodeTypeEnum; + +@LiteflowComponent("wn2") +@LiteflowCmpDefine(NodeTypeEnum.WHILE) +@FallbackCmp +public class WhileCmp2 { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_WHILE) + public boolean processWhile(NodeComponent bindCmp) throws Exception { + return false; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/fallback/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/fallback/application.properties new file mode 100644 index 000000000..b6a1da886 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/fallback/application.properties @@ -0,0 +1,2 @@ +liteflow.rule-source=fallback/flow.el.xml +liteflow.fallback-cmp-enable=true \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/fallback/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/fallback/flow.el.xml new file mode 100644 index 000000000..9647a51d6 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/fallback/flow.el.xml @@ -0,0 +1,136 @@ + + + + + THEN(a, node("x")); + + + + THEN(PRE(node("x1")), node("x2"), FINALLY(node("x3"))); + + + + + WHEN(b, node("x")); + + + + + IF(node("x"), a) + + + + + IF(ifn1, node("x")) + + + + + FOR(node("x")).DO(a); + + + + + FOR(3).DO(node("x")); + + + + + WHILE(node("x")).DO(a) + + + + + WHILE(wn1).DO(node("x")) + + + + + ITERATOR(node("x")).DO(a) + + + + + ITERATOR(itn1).DO(node("x")) + + + + + FOR(3).DO(a).BREAK(node("x")); + + + + WHILE(wn1).DO(a).BREAK(node("x")); + + + + ITERATOR(itn1).DO(a).BREAK(node("x")); + + + + + SWITCH(node("x")).to(a,b); + + + + + SWITCH(swn1).to(node("x"),a); + + + + + IF(AND(node("x"),ifn1), a); + + + + + IF(OR(node("x"),ifn1), a); + + + + + IF(NOT(node("x")), a); + + + + + CATCH(THEN(a, d)).DO(node("x")) + + + + + THEN( + a, + node("x1"), + IF(node("x2"), b) + ); + + + + IF( + OR(node("x1"), ifn1), + THEN(a, node("x2")) + ); + + + + FOR(node("x1")).DO( + THEN(b, node("x2")) + ); + + + + + WHEN( + THEN(node("x1")), + IF(node("x2"), b) + ).maxWaitSeconds(10000); + + + + WHEN( + node("x1"), + IF(node("x2"), b) + ).maxWaitSeconds(10000); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/FallbackTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/FallbackTest.java new file mode 100644 index 000000000..3ffb7dbc3 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/FallbackTest.java @@ -0,0 +1,225 @@ +package com.yomahub.liteflow.test.fallback; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.core.FlowExecutorHolder; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; + +/** + * 非 Spring 环境下组件降级测试 + * + * @author DaleLee + * @since 2.11.1 + */ +public class FallbackTest extends BaseTest { + private static FlowExecutor flowExecutor; + + @BeforeAll + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("fallback/flow.el.xml"); + config.setFallbackCmpEnable(true); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } + + @Test + public void testThen1() { + LiteflowResponse response = flowExecutor.execute2Resp("then1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("a==>c", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testThen2() { + LiteflowResponse response = flowExecutor.execute2Resp("then2", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("c==>c==>c", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testWhen1() { + LiteflowResponse response = flowExecutor.execute2Resp("when1", "arg"); + Assertions.assertTrue(response.isSuccess()); + String executeStepStr = response.getExecuteStepStrWithoutTime(); + Assertions.assertTrue("b==>c".equals(executeStepStr) || "c==>b".equals(executeStepStr)); + } + + @Test + public void testIf1() { + LiteflowResponse response = flowExecutor.execute2Resp("if1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("ifn2", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testIf2() { + LiteflowResponse response = flowExecutor.execute2Resp("if2", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("ifn1==>c", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testFor1() { + LiteflowResponse response = flowExecutor.execute2Resp("for1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("for1==>a==>a==>a", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testFor2() { + LiteflowResponse response = flowExecutor.execute2Resp("for2", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("LOOP_3==>c==>c==>c", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testWhile1() { + LiteflowResponse response = flowExecutor.execute2Resp("while1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("wn2", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testWhile2() { + LiteflowResponse response = flowExecutor.execute2Resp("while2", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("wn1==>c==>wn1==>c==>wn1==>c==>wn1", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testIterator1() { + LiteflowResponse response = flowExecutor.execute2Resp("iterator1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("itn2", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testIterator2() { + LiteflowResponse response = flowExecutor.execute2Resp("iterator2", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("itn1==>c==>c==>c", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testBreak1() { + LiteflowResponse response = flowExecutor.execute2Resp("break1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("LOOP_3==>a==>bn1", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testBreak2() { + LiteflowResponse response = flowExecutor.execute2Resp("break2", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("wn1==>a==>bn1", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testBreak3() { + LiteflowResponse response = flowExecutor.execute2Resp("break3", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("itn1==>a==>bn1", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testSwitch1() { + LiteflowResponse response = flowExecutor.execute2Resp("switch1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("swn2==>b", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testSwitch2() { + LiteflowResponse response = flowExecutor.execute2Resp("switch2", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("swn1==>a", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testAnd1() { + LiteflowResponse response = flowExecutor.execute2Resp("and1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("ifn2", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testOr1() { + LiteflowResponse response = flowExecutor.execute2Resp("or1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("ifn2==>ifn1==>a", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testNot1() { + LiteflowResponse response = flowExecutor.execute2Resp("not1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("ifn2==>a", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testCatch1() { + LiteflowResponse response = flowExecutor.execute2Resp("catch1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("a==>d==>c", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testMulti1() { + LiteflowResponse response = flowExecutor.execute2Resp("multi1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("a==>c==>ifn2", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testMulti2() { + LiteflowResponse response = flowExecutor.execute2Resp("multi2", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("ifn2==>ifn1==>a==>c", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testMulti3() { + LiteflowResponse response = flowExecutor.execute2Resp("multi3", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("for1==>b==>c==>b==>c==>b==>c", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testConcurrent1() { + LiteflowResponse response = flowExecutor.execute2Resp("concurrent1", "arg"); + Assertions.assertTrue(response.isSuccess()); + String stepStr = response.getExecuteStepStrWithoutTime(); + Assertions.assertTrue("c==>ifn2".equals(stepStr) || "ifn2==>c".equals(stepStr)); + } + + @Test + public void testConcurrent2() { + LiteflowResponse response = flowExecutor.execute2Resp("concurrent2", "arg"); + Assertions.assertTrue(response.isSuccess()); + String stepStr = response.getExecuteStepStrWithoutTime(); + Assertions.assertTrue("c==>ifn2".equals(stepStr) || "ifn2==>c".equals(stepStr)); + } + + @Test + public void testConcurrent3() throws ExecutionException, InterruptedException { + // 执行多条 chain + Future future1 = flowExecutor.execute2Future("concurrent1", "arg", new Object()); + Future future2 = flowExecutor.execute2Future("concurrent2", "arg", new Object()); + Thread.sleep(1000); + LiteflowResponse response1 = future1.get(); + LiteflowResponse response2 = future2.get(); + Assertions.assertTrue(response1.isSuccess()); + String stepStr1 = response1.getExecuteStepStrWithoutTime(); + Assertions.assertTrue("c==>ifn2".equals(stepStr1) || "ifn2==>c".equals(stepStr1)); + Assertions.assertTrue(response2.isSuccess()); + String stepStr2 = response2.getExecuteStepStrWithoutTime(); + Assertions.assertTrue("c==>ifn2".equals(stepStr2) || "ifn2==>c".equals(stepStr2)); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/ACmp.java new file mode 100644 index 000000000..ed6d7fe76 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/ACmp.java @@ -0,0 +1,12 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.core.NodeComponent; + +public class ACmp extends NodeComponent { + + @Override + public void process() { + System.out.println("ACmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BCmp.java new file mode 100644 index 000000000..82b029643 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BCmp.java @@ -0,0 +1,12 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.core.NodeComponent; + +public class BCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BreakCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BreakCmp.java new file mode 100644 index 000000000..155bdfae6 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BreakCmp.java @@ -0,0 +1,13 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.FallbackCmp; +import com.yomahub.liteflow.core.NodeBreakComponent; + +@FallbackCmp +public class BreakCmp extends NodeBreakComponent { + + @Override + public boolean processBreak() throws Exception { + return true; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/CCmp.java new file mode 100644 index 000000000..8e1915878 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/CCmp.java @@ -0,0 +1,14 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.FallbackCmp; +import com.yomahub.liteflow.core.NodeComponent; + +@FallbackCmp +public class CCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/DCmp.java new file mode 100644 index 000000000..94c0eaabb --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/DCmp.java @@ -0,0 +1,11 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.core.NodeComponent; + +public class DCmp extends NodeComponent { + + @Override + public void process() throws Exception { + throw new RuntimeException("component[d]"); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/ForCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/ForCmp.java new file mode 100644 index 000000000..0a69a7638 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/ForCmp.java @@ -0,0 +1,13 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.FallbackCmp; +import com.yomahub.liteflow.core.NodeForComponent; + +@FallbackCmp +public class ForCmp extends NodeForComponent { + + @Override + public int processFor() throws Exception { + return 3; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp1.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp1.java new file mode 100644 index 000000000..5437cc8fe --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp1.java @@ -0,0 +1,11 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.core.NodeIfComponent; + +public class IfCmp1 extends NodeIfComponent { + + @Override + public boolean processIf() throws Exception { + return true; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp2.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp2.java new file mode 100644 index 000000000..67187c399 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp2.java @@ -0,0 +1,13 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.FallbackCmp; +import com.yomahub.liteflow.core.NodeIfComponent; + +@FallbackCmp +public class IfCmp2 extends NodeIfComponent { + + @Override + public boolean processIf() throws Exception { + return false; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IteratorCmp1.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IteratorCmp1.java new file mode 100644 index 000000000..b6a5a7336 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IteratorCmp1.java @@ -0,0 +1,14 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.core.NodeIteratorComponent; + +import java.util.Arrays; +import java.util.Iterator; + +public class IteratorCmp1 extends NodeIteratorComponent { + + @Override + public Iterator processIterator() throws Exception { + return Arrays.asList("a", "b", "c").iterator(); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IteratorCmp2.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IteratorCmp2.java new file mode 100644 index 000000000..1a6456da9 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IteratorCmp2.java @@ -0,0 +1,16 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.FallbackCmp; +import com.yomahub.liteflow.core.NodeIteratorComponent; + +import java.util.Collections; +import java.util.Iterator; + +@FallbackCmp +public class IteratorCmp2 extends NodeIteratorComponent { + + @Override + public Iterator processIterator() throws Exception { + return Collections.emptyIterator(); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/SwitchCmp1.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/SwitchCmp1.java new file mode 100644 index 000000000..6fa17eacc --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/SwitchCmp1.java @@ -0,0 +1,11 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.core.NodeSwitchComponent; + +public class SwitchCmp1 extends NodeSwitchComponent { + + @Override + public String processSwitch() throws Exception { + return "a"; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/SwitchCmp2.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/SwitchCmp2.java new file mode 100644 index 000000000..78b10c31b --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/SwitchCmp2.java @@ -0,0 +1,13 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.FallbackCmp; +import com.yomahub.liteflow.core.NodeSwitchComponent; + +@FallbackCmp +public class SwitchCmp2 extends NodeSwitchComponent { + + @Override + public String processSwitch() throws Exception { + return "b"; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp1.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp1.java new file mode 100644 index 000000000..d525911ba --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp1.java @@ -0,0 +1,24 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.core.NodeWhileComponent; + +import java.util.HashSet; +import java.util.Set; + +public class WhileCmp1 extends NodeWhileComponent { + private int count = 0; + + // 执行过的 chain + Set executedChain = new HashSet<>(); + + @Override + public boolean processWhile() throws Exception { + // 判断是否切换了 chain + if (!executedChain.contains(this.getCurrChainId())) { + count = 0; + executedChain.add(this.getCurrChainId()); + } + count++; + return count <= 3; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp2.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp2.java new file mode 100644 index 000000000..531a77d7e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp2.java @@ -0,0 +1,13 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.FallbackCmp; +import com.yomahub.liteflow.core.NodeWhileComponent; + +@FallbackCmp +public class WhileCmp2 extends NodeWhileComponent { + + @Override + public boolean processWhile() throws Exception { + return false; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/fallback/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/fallback/flow.el.xml new file mode 100644 index 000000000..24eba9db2 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/fallback/flow.el.xml @@ -0,0 +1,153 @@ + + + + + + + + + + + + + + + + + + + + + + THEN(a, node("x")); + + + + THEN(PRE(node("x1")), node("x2"), FINALLY(node("x3"))); + + + + + WHEN(b, node("x")); + + + + + IF(node("x"), a) + + + + + IF(ifn1, node("x")) + + + + + FOR(node("x")).DO(a); + + + + + FOR(3).DO(node("x")); + + + + + WHILE(node("x")).DO(a) + + + + + WHILE(wn1).DO(node("x")) + + + + + ITERATOR(node("x")).DO(a) + + + + + ITERATOR(itn1).DO(node("x")) + + + + + FOR(3).DO(a).BREAK(node("x")); + + + + WHILE(wn1).DO(a).BREAK(node("x")); + + + + ITERATOR(itn1).DO(a).BREAK(node("x")); + + + + + SWITCH(node("x")).to(a,b); + + + + + SWITCH(swn1).to(node("x"),a); + + + + + IF(AND(node("x"),ifn1), a); + + + + + IF(OR(node("x"),ifn1), a); + + + + + IF(NOT(node("x")), a); + + + + + CATCH(THEN(a, d)).DO(node("x")) + + + + + THEN( + a, + node("x1"), + IF(node("x2"), b) + ); + + + + IF( + OR(node("x1"), ifn1), + THEN(a, node("x2")) + ); + + + + FOR(node("x1")).DO( + THEN(b, node("x2")) + ); + + + + + WHEN( + THEN(node("x1")), + IF(node("x2"), b) + ).maxWaitSeconds(10000); + + + + WHEN( + node("x1"), + IF(node("x2"), b) + ).maxWaitSeconds(10000); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/FallbackELSolonTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/FallbackELSolonTest.java new file mode 100644 index 000000000..db1603212 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/FallbackELSolonTest.java @@ -0,0 +1,222 @@ +package com.yomahub.liteflow.test.fallback; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.noear.solon.annotation.Inject; +import org.noear.solon.test.SolonJUnit5Extension; +import org.noear.solon.test.annotation.TestPropertySource; + +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; + +/** + * Solon 降级组件测试 + * + * @author DaleLee + * @since 2.11.1 + */ +@ExtendWith(SolonJUnit5Extension.class) +@TestPropertySource("classpath:/fallback/application.properties") +public class FallbackELSolonTest extends BaseTest { + + @Inject + private FlowExecutor flowExecutor; + + @Test + public void testThen1() { + LiteflowResponse response = flowExecutor.execute2Resp("then1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("a==>c", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testThen2() { + LiteflowResponse response = flowExecutor.execute2Resp("then2", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("c==>c==>c", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testWhen1() { + LiteflowResponse response = flowExecutor.execute2Resp("when1", "arg"); + Assertions.assertTrue(response.isSuccess()); + String executeStepStr = response.getExecuteStepStrWithoutTime(); + Assertions.assertTrue("b==>c".equals(executeStepStr) || "c==>b".equals(executeStepStr)); + } + + @Test + public void testIf1() { + LiteflowResponse response = flowExecutor.execute2Resp("if1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("ifn2", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testIf2() { + LiteflowResponse response = flowExecutor.execute2Resp("if2", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("ifn1==>c", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testFor1() { + LiteflowResponse response = flowExecutor.execute2Resp("for1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("for1==>a==>a==>a", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testFor2() { + LiteflowResponse response = flowExecutor.execute2Resp("for2", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("LOOP_3==>c==>c==>c", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testWhile1() { + LiteflowResponse response = flowExecutor.execute2Resp("while1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("wn2", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testWhile2() { + LiteflowResponse response = flowExecutor.execute2Resp("while2", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("wn1==>c==>wn1==>c==>wn1==>c==>wn1", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testIterator1() { + LiteflowResponse response = flowExecutor.execute2Resp("iterator1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("itn2", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testIterator2() { + LiteflowResponse response = flowExecutor.execute2Resp("iterator2", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("itn1==>c==>c==>c", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testBreak1() { + LiteflowResponse response = flowExecutor.execute2Resp("break1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("LOOP_3==>a==>bn1", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testBreak2() { + LiteflowResponse response = flowExecutor.execute2Resp("break2", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("wn1==>a==>bn1", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testBreak3() { + LiteflowResponse response = flowExecutor.execute2Resp("break3", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("itn1==>a==>bn1", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testSwitch1() { + LiteflowResponse response = flowExecutor.execute2Resp("switch1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("swn2==>b", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testSwitch2() { + LiteflowResponse response = flowExecutor.execute2Resp("switch2", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("swn1==>a", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testAnd1() { + LiteflowResponse response = flowExecutor.execute2Resp("and1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("ifn2", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testOr1() { + LiteflowResponse response = flowExecutor.execute2Resp("or1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("ifn2==>ifn1==>a", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testNot1() { + LiteflowResponse response = flowExecutor.execute2Resp("not1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("ifn2==>a", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testCatch1() { + LiteflowResponse response = flowExecutor.execute2Resp("catch1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("a==>d==>c", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testMulti1() { + LiteflowResponse response = flowExecutor.execute2Resp("multi1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("a==>c==>ifn2", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testMulti2() { + LiteflowResponse response = flowExecutor.execute2Resp("multi2", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("ifn2==>ifn1==>a==>c", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testMulti3() { + LiteflowResponse response = flowExecutor.execute2Resp("multi3", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("for1==>b==>c==>b==>c==>b==>c", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testConcurrent1() { + LiteflowResponse response = flowExecutor.execute2Resp("concurrent1", "arg"); + Assertions.assertTrue(response.isSuccess()); + String stepStr = response.getExecuteStepStrWithoutTime(); + Assertions.assertTrue("c==>ifn2".equals(stepStr) || "ifn2==>c".equals(stepStr)); + } + + @Test + public void testConcurrent2() { + LiteflowResponse response = flowExecutor.execute2Resp("concurrent2", "arg"); + Assertions.assertTrue(response.isSuccess()); + String stepStr = response.getExecuteStepStrWithoutTime(); + Assertions.assertTrue("c==>ifn2".equals(stepStr) || "ifn2==>c".equals(stepStr)); + } + + @Test + public void testConcurrent3() throws ExecutionException, InterruptedException { + // 执行多条 chain + Future future1 = flowExecutor.execute2Future("concurrent1", "arg", new Object()); + Future future2 = flowExecutor.execute2Future("concurrent2", "arg", new Object()); + Thread.sleep(1000); + LiteflowResponse response1 = future1.get(); + LiteflowResponse response2 = future2.get(); + Assertions.assertTrue(response1.isSuccess()); + String stepStr1 = response1.getExecuteStepStrWithoutTime(); + Assertions.assertTrue("c==>ifn2".equals(stepStr1) || "ifn2==>c".equals(stepStr1)); + Assertions.assertTrue(response2.isSuccess()); + String stepStr2 = response2.getExecuteStepStrWithoutTime(); + Assertions.assertTrue("c==>ifn2".equals(stepStr2) || "ifn2==>c".equals(stepStr2)); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/ACmp.java new file mode 100644 index 000000000..8a6739027 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/ACmp.java @@ -0,0 +1,14 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent("a") +public class ACmp extends NodeComponent { + + @Override + public void process() { + System.out.println("ACmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BCmp.java new file mode 100644 index 000000000..632bd78be --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BCmp.java @@ -0,0 +1,14 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent("b") +public class BCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BreakCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BreakCmp.java new file mode 100644 index 000000000..32813ffe3 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BreakCmp.java @@ -0,0 +1,15 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.FallbackCmp; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeBreakComponent; + +@LiteflowComponent("bn1") +@FallbackCmp +public class BreakCmp extends NodeBreakComponent { + + @Override + public boolean processBreak() throws Exception { + return true; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/CCmp.java new file mode 100644 index 000000000..54d0799b5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/CCmp.java @@ -0,0 +1,16 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.FallbackCmp; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent("c") +@FallbackCmp +public class CCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/DCmp.java new file mode 100644 index 000000000..5d7fd18ee --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/DCmp.java @@ -0,0 +1,13 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent("d") +public class DCmp extends NodeComponent { + + @Override + public void process() throws Exception { + throw new RuntimeException("component[d]"); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/ForCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/ForCmp.java new file mode 100644 index 000000000..2607f8acc --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/ForCmp.java @@ -0,0 +1,15 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.FallbackCmp; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeForComponent; + +@LiteflowComponent("for1") +@FallbackCmp +public class ForCmp extends NodeForComponent { + + @Override + public int processFor() throws Exception { + return 3; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp1.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp1.java new file mode 100644 index 000000000..62b47dec1 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp1.java @@ -0,0 +1,13 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeIfComponent; + +@LiteflowComponent("ifn1") +public class IfCmp1 extends NodeIfComponent { + + @Override + public boolean processIf() throws Exception { + return true; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp2.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp2.java new file mode 100644 index 000000000..c5b20fcd8 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp2.java @@ -0,0 +1,15 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.FallbackCmp; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeIfComponent; + +@LiteflowComponent("ifn2") +@FallbackCmp +public class IfCmp2 extends NodeIfComponent { + + @Override + public boolean processIf() throws Exception { + return false; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IteratorCmp1.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IteratorCmp1.java new file mode 100644 index 000000000..b63cb7c71 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IteratorCmp1.java @@ -0,0 +1,16 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeIteratorComponent; + +import java.util.Arrays; +import java.util.Iterator; + +@LiteflowComponent("itn1") +public class IteratorCmp1 extends NodeIteratorComponent { + + @Override + public Iterator processIterator() throws Exception { + return Arrays.asList("a", "b", "c").iterator(); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IteratorCmp2.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IteratorCmp2.java new file mode 100644 index 000000000..c45f19034 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IteratorCmp2.java @@ -0,0 +1,18 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.FallbackCmp; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeIteratorComponent; + +import java.util.Collections; +import java.util.Iterator; + +@LiteflowComponent("itn2") +@FallbackCmp +public class IteratorCmp2 extends NodeIteratorComponent { + + @Override + public Iterator processIterator() throws Exception { + return Collections.emptyIterator(); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/SwitchCmp1.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/SwitchCmp1.java new file mode 100644 index 000000000..1cb3fe1c3 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/SwitchCmp1.java @@ -0,0 +1,13 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeSwitchComponent; + +@LiteflowComponent("swn1") +public class SwitchCmp1 extends NodeSwitchComponent { + + @Override + public String processSwitch() throws Exception { + return "a"; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/SwitchCmp2.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/SwitchCmp2.java new file mode 100644 index 000000000..28b1edcfd --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/SwitchCmp2.java @@ -0,0 +1,15 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.FallbackCmp; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeSwitchComponent; + +@LiteflowComponent("swn2") +@FallbackCmp +public class SwitchCmp2 extends NodeSwitchComponent { + + @Override + public String processSwitch() throws Exception { + return "b"; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp1.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp1.java new file mode 100644 index 000000000..6769480c6 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp1.java @@ -0,0 +1,26 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeWhileComponent; + +import java.util.HashSet; +import java.util.Set; + +@LiteflowComponent("wn1") +public class WhileCmp1 extends NodeWhileComponent { + private int count = 0; + + // 执行过的 chain + Set executedChain = new HashSet<>(); + + @Override + public boolean processWhile() throws Exception { + // 判断是否切换了 chain + if (!executedChain.contains(this.getCurrChainId())) { + count = 0; + executedChain.add(this.getCurrChainId()); + } + count++; + return count <= 3; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp2.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp2.java new file mode 100644 index 000000000..b198faa0e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp2.java @@ -0,0 +1,15 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.FallbackCmp; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeWhileComponent; + +@LiteflowComponent("wn2") +@FallbackCmp +public class WhileCmp2 extends NodeWhileComponent { + + @Override + public boolean processWhile() throws Exception { + return false; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/fallback/application.properties b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/fallback/application.properties new file mode 100644 index 000000000..b6a1da886 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/fallback/application.properties @@ -0,0 +1,2 @@ +liteflow.rule-source=fallback/flow.el.xml +liteflow.fallback-cmp-enable=true \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/fallback/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/fallback/flow.el.xml new file mode 100644 index 000000000..9647a51d6 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/fallback/flow.el.xml @@ -0,0 +1,136 @@ + + + + + THEN(a, node("x")); + + + + THEN(PRE(node("x1")), node("x2"), FINALLY(node("x3"))); + + + + + WHEN(b, node("x")); + + + + + IF(node("x"), a) + + + + + IF(ifn1, node("x")) + + + + + FOR(node("x")).DO(a); + + + + + FOR(3).DO(node("x")); + + + + + WHILE(node("x")).DO(a) + + + + + WHILE(wn1).DO(node("x")) + + + + + ITERATOR(node("x")).DO(a) + + + + + ITERATOR(itn1).DO(node("x")) + + + + + FOR(3).DO(a).BREAK(node("x")); + + + + WHILE(wn1).DO(a).BREAK(node("x")); + + + + ITERATOR(itn1).DO(a).BREAK(node("x")); + + + + + SWITCH(node("x")).to(a,b); + + + + + SWITCH(swn1).to(node("x"),a); + + + + + IF(AND(node("x"),ifn1), a); + + + + + IF(OR(node("x"),ifn1), a); + + + + + IF(NOT(node("x")), a); + + + + + CATCH(THEN(a, d)).DO(node("x")) + + + + + THEN( + a, + node("x1"), + IF(node("x2"), b) + ); + + + + IF( + OR(node("x1"), ifn1), + THEN(a, node("x2")) + ); + + + + FOR(node("x1")).DO( + THEN(b, node("x2")) + ); + + + + + WHEN( + THEN(node("x1")), + IF(node("x2"), b) + ).maxWaitSeconds(10000); + + + + WHEN( + node("x1"), + IF(node("x2"), b) + ).maxWaitSeconds(10000); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/fallback/FallbackSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/fallback/FallbackELSpringbootTest.java similarity index 98% rename from liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/fallback/FallbackSpringbootTest.java rename to liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/fallback/FallbackELSpringbootTest.java index 39a801fd7..dfa7f1ab1 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/fallback/FallbackSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/fallback/FallbackELSpringbootTest.java @@ -2,6 +2,7 @@ package com.yomahub.liteflow.test.fallback; import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -17,12 +18,13 @@ import java.util.concurrent.Future; * SpringBoot 降级组件测试 * * @author DaleLee + * @since 2.11.1 */ @TestPropertySource(value = "classpath:/fallback/application.properties") -@SpringBootTest(classes = FallbackSpringbootTest.class) +@SpringBootTest(classes = FallbackELSpringbootTest.class) @EnableAutoConfiguration @ComponentScan({"com.yomahub.liteflow.test.fallback.cmp"}) -public class FallbackSpringbootTest { +public class FallbackELSpringbootTest extends BaseTest { @Resource private FlowExecutor flowExecutor; diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/FallbackELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/FallbackELSpringTest.java new file mode 100644 index 000000000..a6552f9fd --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/FallbackELSpringTest.java @@ -0,0 +1,221 @@ +package com.yomahub.liteflow.test.fallback; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import javax.annotation.Resource; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; + +/** + * Spring 降级组件测试 + * + * @author DaleLee + */ +@ExtendWith(SpringExtension.class) +@ContextConfiguration("classpath:/fallback/application.xml") +public class FallbackELSpringTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testThen1() { + LiteflowResponse response = flowExecutor.execute2Resp("then1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("a==>c", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testThen2() { + LiteflowResponse response = flowExecutor.execute2Resp("then2", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("c==>c==>c", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testWhen1() { + LiteflowResponse response = flowExecutor.execute2Resp("when1", "arg"); + Assertions.assertTrue(response.isSuccess()); + String executeStepStr = response.getExecuteStepStrWithoutTime(); + Assertions.assertTrue("b==>c".equals(executeStepStr) || "c==>b".equals(executeStepStr)); + } + + @Test + public void testIf1() { + LiteflowResponse response = flowExecutor.execute2Resp("if1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("ifn2", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testIf2() { + LiteflowResponse response = flowExecutor.execute2Resp("if2", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("ifn1==>c", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testFor1() { + LiteflowResponse response = flowExecutor.execute2Resp("for1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("for1==>a==>a==>a", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testFor2() { + LiteflowResponse response = flowExecutor.execute2Resp("for2", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("LOOP_3==>c==>c==>c", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testWhile1() { + LiteflowResponse response = flowExecutor.execute2Resp("while1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("wn2", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testWhile2() { + LiteflowResponse response = flowExecutor.execute2Resp("while2", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("wn1==>c==>wn1==>c==>wn1==>c==>wn1", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testIterator1() { + LiteflowResponse response = flowExecutor.execute2Resp("iterator1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("itn2", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testIterator2() { + LiteflowResponse response = flowExecutor.execute2Resp("iterator2", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("itn1==>c==>c==>c", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testBreak1() { + LiteflowResponse response = flowExecutor.execute2Resp("break1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("LOOP_3==>a==>bn1", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testBreak2() { + LiteflowResponse response = flowExecutor.execute2Resp("break2", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("wn1==>a==>bn1", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testBreak3() { + LiteflowResponse response = flowExecutor.execute2Resp("break3", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("itn1==>a==>bn1", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testSwitch1() { + LiteflowResponse response = flowExecutor.execute2Resp("switch1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("swn2==>b", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testSwitch2() { + LiteflowResponse response = flowExecutor.execute2Resp("switch2", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("swn1==>a", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testAnd1() { + LiteflowResponse response = flowExecutor.execute2Resp("and1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("ifn2", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testOr1() { + LiteflowResponse response = flowExecutor.execute2Resp("or1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("ifn2==>ifn1==>a", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testNot1() { + LiteflowResponse response = flowExecutor.execute2Resp("not1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("ifn2==>a", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testCatch1() { + LiteflowResponse response = flowExecutor.execute2Resp("catch1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("a==>d==>c", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testMulti1() { + LiteflowResponse response = flowExecutor.execute2Resp("multi1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("a==>c==>ifn2", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testMulti2() { + LiteflowResponse response = flowExecutor.execute2Resp("multi2", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("ifn2==>ifn1==>a==>c", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testMulti3() { + LiteflowResponse response = flowExecutor.execute2Resp("multi3", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("for1==>b==>c==>b==>c==>b==>c", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testConcurrent1() { + LiteflowResponse response = flowExecutor.execute2Resp("concurrent1", "arg"); + Assertions.assertTrue(response.isSuccess()); + String stepStr = response.getExecuteStepStrWithoutTime(); + Assertions.assertTrue("c==>ifn2".equals(stepStr) || "ifn2==>c".equals(stepStr)); + } + + @Test + public void testConcurrent2() { + LiteflowResponse response = flowExecutor.execute2Resp("concurrent2", "arg"); + Assertions.assertTrue(response.isSuccess()); + String stepStr = response.getExecuteStepStrWithoutTime(); + Assertions.assertTrue("c==>ifn2".equals(stepStr) || "ifn2==>c".equals(stepStr)); + } + + @Test + public void testConcurrent3() throws ExecutionException, InterruptedException { + // 执行多条 chain + Future future1 = flowExecutor.execute2Future("concurrent1", "arg", new Object()); + Future future2 = flowExecutor.execute2Future("concurrent2", "arg", new Object()); + Thread.sleep(1000); + LiteflowResponse response1 = future1.get(); + LiteflowResponse response2 = future2.get(); + Assertions.assertTrue(response1.isSuccess()); + String stepStr1 = response1.getExecuteStepStrWithoutTime(); + Assertions.assertTrue("c==>ifn2".equals(stepStr1) || "ifn2==>c".equals(stepStr1)); + Assertions.assertTrue(response2.isSuccess()); + String stepStr2 = response2.getExecuteStepStrWithoutTime(); + Assertions.assertTrue("c==>ifn2".equals(stepStr2) || "ifn2==>c".equals(stepStr2)); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/ACmp.java new file mode 100644 index 000000000..8a6739027 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/ACmp.java @@ -0,0 +1,14 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent("a") +public class ACmp extends NodeComponent { + + @Override + public void process() { + System.out.println("ACmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BCmp.java new file mode 100644 index 000000000..632bd78be --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BCmp.java @@ -0,0 +1,14 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent("b") +public class BCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BreakCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BreakCmp.java new file mode 100644 index 000000000..32813ffe3 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/BreakCmp.java @@ -0,0 +1,15 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.FallbackCmp; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeBreakComponent; + +@LiteflowComponent("bn1") +@FallbackCmp +public class BreakCmp extends NodeBreakComponent { + + @Override + public boolean processBreak() throws Exception { + return true; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/CCmp.java new file mode 100644 index 000000000..54d0799b5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/CCmp.java @@ -0,0 +1,16 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.FallbackCmp; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent("c") +@FallbackCmp +public class CCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/DCmp.java new file mode 100644 index 000000000..5d7fd18ee --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/DCmp.java @@ -0,0 +1,13 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent("d") +public class DCmp extends NodeComponent { + + @Override + public void process() throws Exception { + throw new RuntimeException("component[d]"); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/ForCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/ForCmp.java new file mode 100644 index 000000000..2607f8acc --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/ForCmp.java @@ -0,0 +1,15 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.FallbackCmp; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeForComponent; + +@LiteflowComponent("for1") +@FallbackCmp +public class ForCmp extends NodeForComponent { + + @Override + public int processFor() throws Exception { + return 3; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp1.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp1.java new file mode 100644 index 000000000..62b47dec1 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp1.java @@ -0,0 +1,13 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeIfComponent; + +@LiteflowComponent("ifn1") +public class IfCmp1 extends NodeIfComponent { + + @Override + public boolean processIf() throws Exception { + return true; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp2.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp2.java new file mode 100644 index 000000000..c5b20fcd8 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IfCmp2.java @@ -0,0 +1,15 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.FallbackCmp; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeIfComponent; + +@LiteflowComponent("ifn2") +@FallbackCmp +public class IfCmp2 extends NodeIfComponent { + + @Override + public boolean processIf() throws Exception { + return false; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IteratorCmp1.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IteratorCmp1.java new file mode 100644 index 000000000..b63cb7c71 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IteratorCmp1.java @@ -0,0 +1,16 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeIteratorComponent; + +import java.util.Arrays; +import java.util.Iterator; + +@LiteflowComponent("itn1") +public class IteratorCmp1 extends NodeIteratorComponent { + + @Override + public Iterator processIterator() throws Exception { + return Arrays.asList("a", "b", "c").iterator(); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IteratorCmp2.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IteratorCmp2.java new file mode 100644 index 000000000..c45f19034 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/IteratorCmp2.java @@ -0,0 +1,18 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.FallbackCmp; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeIteratorComponent; + +import java.util.Collections; +import java.util.Iterator; + +@LiteflowComponent("itn2") +@FallbackCmp +public class IteratorCmp2 extends NodeIteratorComponent { + + @Override + public Iterator processIterator() throws Exception { + return Collections.emptyIterator(); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/SwitchCmp1.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/SwitchCmp1.java new file mode 100644 index 000000000..1cb3fe1c3 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/SwitchCmp1.java @@ -0,0 +1,13 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeSwitchComponent; + +@LiteflowComponent("swn1") +public class SwitchCmp1 extends NodeSwitchComponent { + + @Override + public String processSwitch() throws Exception { + return "a"; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/SwitchCmp2.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/SwitchCmp2.java new file mode 100644 index 000000000..28b1edcfd --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/SwitchCmp2.java @@ -0,0 +1,15 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.FallbackCmp; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeSwitchComponent; + +@LiteflowComponent("swn2") +@FallbackCmp +public class SwitchCmp2 extends NodeSwitchComponent { + + @Override + public String processSwitch() throws Exception { + return "b"; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp1.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp1.java new file mode 100644 index 000000000..6769480c6 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp1.java @@ -0,0 +1,26 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeWhileComponent; + +import java.util.HashSet; +import java.util.Set; + +@LiteflowComponent("wn1") +public class WhileCmp1 extends NodeWhileComponent { + private int count = 0; + + // 执行过的 chain + Set executedChain = new HashSet<>(); + + @Override + public boolean processWhile() throws Exception { + // 判断是否切换了 chain + if (!executedChain.contains(this.getCurrChainId())) { + count = 0; + executedChain.add(this.getCurrChainId()); + } + count++; + return count <= 3; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp2.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp2.java new file mode 100644 index 000000000..b198faa0e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/fallback/cmp/WhileCmp2.java @@ -0,0 +1,15 @@ +package com.yomahub.liteflow.test.fallback.cmp; + +import com.yomahub.liteflow.annotation.FallbackCmp; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeWhileComponent; + +@LiteflowComponent("wn2") +@FallbackCmp +public class WhileCmp2 extends NodeWhileComponent { + + @Override + public boolean processWhile() throws Exception { + return false; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/fallback/application.xml b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/fallback/application.xml new file mode 100644 index 000000000..950c3106e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/fallback/application.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/fallback/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/fallback/flow.el.xml new file mode 100644 index 000000000..9647a51d6 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/fallback/flow.el.xml @@ -0,0 +1,136 @@ + + + + + THEN(a, node("x")); + + + + THEN(PRE(node("x1")), node("x2"), FINALLY(node("x3"))); + + + + + WHEN(b, node("x")); + + + + + IF(node("x"), a) + + + + + IF(ifn1, node("x")) + + + + + FOR(node("x")).DO(a); + + + + + FOR(3).DO(node("x")); + + + + + WHILE(node("x")).DO(a) + + + + + WHILE(wn1).DO(node("x")) + + + + + ITERATOR(node("x")).DO(a) + + + + + ITERATOR(itn1).DO(node("x")) + + + + + FOR(3).DO(a).BREAK(node("x")); + + + + WHILE(wn1).DO(a).BREAK(node("x")); + + + + ITERATOR(itn1).DO(a).BREAK(node("x")); + + + + + SWITCH(node("x")).to(a,b); + + + + + SWITCH(swn1).to(node("x"),a); + + + + + IF(AND(node("x"),ifn1), a); + + + + + IF(OR(node("x"),ifn1), a); + + + + + IF(NOT(node("x")), a); + + + + + CATCH(THEN(a, d)).DO(node("x")) + + + + + THEN( + a, + node("x1"), + IF(node("x2"), b) + ); + + + + IF( + OR(node("x1"), ifn1), + THEN(a, node("x2")) + ); + + + + FOR(node("x1")).DO( + THEN(b, node("x2")) + ); + + + + + WHEN( + THEN(node("x1")), + IF(node("x2"), b) + ).maxWaitSeconds(10000); + + + + WHEN( + node("x1"), + IF(node("x2"), b) + ).maxWaitSeconds(10000); + + \ No newline at end of file