From 9677b128cad64f4747fbb4a2d05308105ff8fd03 Mon Sep 17 00:00:00 2001 From: rain <672378783@qq.com> Date: Thu, 18 Jan 2024 15:59:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=81=E8=AE=B8EL=E8=AF=AD=E5=8F=A5=E9=87=8C?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E9=87=8D=E8=AF=95=E6=AC=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../builder/el/LiteFlowChainELBuilder.java | 1 + .../el/operator/RetryTimesOperator.java | 30 +++++ .../liteflow/common/ChainConstant.java | 2 + .../element/condition/RetryCondition.java | 87 ++++++++++++++ .../RetryTimesELDeclMultiSpringbootTest.java | 108 ++++++++++++++++++ .../test/retryTimes/cmp/CmpConfig.java | 82 +++++++++++++ .../retryTimes/application.properties | 1 + .../src/test/resources/retryTimes/flow.el.xml | 43 +++++++ .../RetryTimesELDeclSpringbootTest.java | 104 +++++++++++++++++ .../liteflow/test/retryTimes/cmp/ACmp.java | 12 ++ .../liteflow/test/retryTimes/cmp/BCmp.java | 17 +++ .../liteflow/test/retryTimes/cmp/CCmp.java | 17 +++ .../liteflow/test/retryTimes/cmp/DCmp.java | 17 +++ .../liteflow/test/retryTimes/cmp/FCmp.java | 16 +++ .../liteflow/test/retryTimes/cmp/ICmp.java | 23 ++++ .../liteflow/test/retryTimes/cmp/NCmp.java | 17 +++ .../retryTimes/application.properties | 1 + .../src/test/resources/retryTimes/flow.el.xml | 43 +++++++ .../test/retryTimes/RetryTimesTest.java | 103 +++++++++++++++++ .../liteflow/test/retryTimes/cmp/ACmp.java | 11 ++ .../liteflow/test/retryTimes/cmp/BCmp.java | 16 +++ .../liteflow/test/retryTimes/cmp/CCmp.java | 16 +++ .../liteflow/test/retryTimes/cmp/DCmp.java | 16 +++ .../liteflow/test/retryTimes/cmp/FCmp.java | 15 +++ .../liteflow/test/retryTimes/cmp/ICmp.java | 21 ++++ .../liteflow/test/retryTimes/cmp/NCmp.java | 16 +++ .../src/test/resources/retryTimes/flow.el.xml | 52 +++++++++ .../retryTimes/RetryTimesSpringbootTest.java | 100 ++++++++++++++++ .../liteflow/test/retryTimes/cmp/ACmp.java | 12 ++ .../liteflow/test/retryTimes/cmp/BCmp.java | 17 +++ .../liteflow/test/retryTimes/cmp/CCmp.java | 17 +++ .../liteflow/test/retryTimes/cmp/DCmp.java | 17 +++ .../liteflow/test/retryTimes/cmp/FCmp.java | 16 +++ .../liteflow/test/retryTimes/cmp/ICmp.java | 23 ++++ .../liteflow/test/retryTimes/cmp/NCmp.java | 17 +++ .../retryTimes/application.properties | 1 + .../src/test/resources/retryTimes/flow.el.xml | 43 +++++++ .../retryTimes/RetryTimesSpringbootTest.java | 105 +++++++++++++++++ .../liteflow/test/retryTimes/cmp/ACmp.java | 12 ++ .../liteflow/test/retryTimes/cmp/BCmp.java | 18 +++ .../liteflow/test/retryTimes/cmp/CCmp.java | 17 +++ .../liteflow/test/retryTimes/cmp/DCmp.java | 17 +++ .../liteflow/test/retryTimes/cmp/FCmp.java | 16 +++ .../liteflow/test/retryTimes/cmp/ICmp.java | 23 ++++ .../liteflow/test/retryTimes/cmp/NCmp.java | 17 +++ .../retryTimes/application.properties | 1 + .../src/test/resources/retryTimes/flow.el.xml | 42 +++++++ .../test/retryTimes/RetryTimesSpringTest.java | 101 ++++++++++++++++ .../liteflow/test/retryTimes/cmp/ACmp.java | 12 ++ .../liteflow/test/retryTimes/cmp/BCmp.java | 17 +++ .../liteflow/test/retryTimes/cmp/CCmp.java | 17 +++ .../liteflow/test/retryTimes/cmp/DCmp.java | 17 +++ .../liteflow/test/retryTimes/cmp/FCmp.java | 16 +++ .../liteflow/test/retryTimes/cmp/ICmp.java | 23 ++++ .../liteflow/test/retryTimes/cmp/NCmp.java | 17 +++ .../test/resources/retryTimes/application.xml | 23 ++++ .../src/test/resources/retryTimes/flow.el.xml | 43 +++++++ 57 files changed, 1704 insertions(+) create mode 100644 liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/RetryTimesOperator.java create mode 100644 liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/RetryCondition.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/RetryTimesELDeclMultiSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/CmpConfig.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/retryTimes/application.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/retryTimes/flow.el.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/RetryTimesELDeclSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ACmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/BCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/CCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/DCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/FCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ICmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/NCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/retryTimes/application.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/retryTimes/flow.el.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retryTimes/RetryTimesTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ACmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/BCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/CCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/DCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/FCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ICmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/NCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/retryTimes/flow.el.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retryTimes/RetryTimesSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ACmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/BCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/CCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/DCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/FCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ICmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/NCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/retryTimes/application.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/retryTimes/flow.el.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/RetryTimesSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ACmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/BCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/CCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/DCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/FCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ICmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/NCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/retryTimes/application.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/retryTimes/flow.el.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retryTimes/RetryTimesSpringTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ACmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/BCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/CCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/DCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/FCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ICmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/NCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/retryTimes/application.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/retryTimes/flow.el.xml diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java index 0f1a65ad7..f749aee94 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java @@ -92,6 +92,7 @@ public class LiteFlowChainELBuilder { EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.MAX_WAIT_SECONDS, Object.class, new MaxWaitSecondsOperator()); EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.MAX_WAIT_MILLISECONDS, Object.class, new MaxWaitMillisecondsOperator()); EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.PARALLEL, Object.class, new ParallelOperator()); + EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.RETRY_TIMES, Object.class, new RetryTimesOperator()); } public static LiteFlowChainELBuilder createChain() { diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/RetryTimesOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/RetryTimesOperator.java new file mode 100644 index 000000000..72ac3dded --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/RetryTimesOperator.java @@ -0,0 +1,30 @@ +package com.yomahub.liteflow.builder.el.operator; + +import com.yomahub.liteflow.builder.el.operator.base.BaseOperator; +import com.yomahub.liteflow.builder.el.operator.base.OperatorHelper; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.flow.element.Condition; +import com.yomahub.liteflow.flow.element.Executable; +import com.yomahub.liteflow.flow.element.condition.RetryCondition; +import com.yomahub.liteflow.flow.element.condition.ThenCondition; +import com.yomahub.liteflow.flow.element.condition.WhileCondition; + +/** + * + * @author Rain + * @since 2.11.5 + * + */ +public class RetryTimesOperator extends BaseOperator { + @Override + public Condition build(Object[] objects) throws Exception { + OperatorHelper.checkObjectSizeGtTwo(objects); + Executable executable = OperatorHelper.convert(objects[0], Executable.class); + Integer retryTimes = OperatorHelper.convert(objects[1], Integer.class); + RetryCondition retryCondition = new RetryCondition(); + retryCondition.addExecutable(executable); + retryCondition.setRetryTimes(retryTimes); + return retryCondition; + } + +} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/common/ChainConstant.java b/liteflow-core/src/main/java/com/yomahub/liteflow/common/ChainConstant.java index 884b8b157..977a9371a 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/common/ChainConstant.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/common/ChainConstant.java @@ -94,4 +94,6 @@ public interface ChainConstant { String EXTENDS = "extends"; + String RETRY_TIMES = "retryTimes"; + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/RetryCondition.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/RetryCondition.java new file mode 100644 index 000000000..6f4bbaf99 --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/RetryCondition.java @@ -0,0 +1,87 @@ +package com.yomahub.liteflow.flow.element.condition; + +import cn.hutool.core.text.StrFormatter; +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.exception.ChainEndException; +import com.yomahub.liteflow.exception.ELParseException; +import com.yomahub.liteflow.flow.element.Chain; +import com.yomahub.liteflow.flow.element.Condition; +import com.yomahub.liteflow.flow.element.Executable; +import com.yomahub.liteflow.flow.element.Node; +import com.yomahub.liteflow.log.LFLog; +import com.yomahub.liteflow.log.LFLoggerManager; +import com.yomahub.liteflow.slot.DataBus; + +public class RetryCondition extends ThenCondition{ + + private final LFLog LOG = LFLoggerManager.getLogger(this.getClass()); + + private Integer retryTimes; + + public Integer getRetryTimes() { + return retryTimes; + } + + public void setRetryTimes(Integer retryTimes) { + this.retryTimes = retryTimes; + } + + @Override + public void executeCondition(Integer slotIndex) throws Exception { + int retryTimes = this.getRetryTimes() < 0 ? 0 : this.getRetryTimes(); + for (int i = 0; i <= retryTimes; i ++) { + try { + if(i == 0) { + super.executeCondition(slotIndex); + } else { + retry(slotIndex, i); + } + break; + } catch (ChainEndException e) { + throw e; + } catch (Exception e) { + if(i >= retryTimes) { + if(retryTimes > 0) { + String retryFailMsg = StrFormatter.format("retry fail when executing the chain[{}] because {} occurs {}.", + this.getCurrChainId(), this.getCurrentExecutableId(), e); + LOG.error(retryFailMsg); + } + throw e; + } else { + DataBus.getSlot(slotIndex).removeException(); + } + } + } + } + + private void retry(Integer slotIndex, int retryTime) throws Exception { + LOG.info("{} performs {} retry ", this.getCurrentExecutableId(), retryTime); + super.executeCondition(slotIndex); + } + + /** + * 获取当前组件的 id + * + * @return + */ + private String getCurrentExecutableId() { + // retryCondition 只有一个 Executable + Executable executable = this.getExecutableList().get(0); + if (ObjectUtil.isNotNull(executable.getId())) { + // 已经有 id 了 + return executable.getId(); + } + // 定义 id + switch (executable.getExecuteType()) { + // chain 和 node 一般都有 id + case CHAIN: + return ((Chain) executable).getChainId(); + case CONDITION: + return "condition-" + ((Condition) executable).getConditionType().getName(); + case NODE: + return "node-" + ((Node) executable).getType().getCode(); + default: + return "unknown-executable"; + } + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/RetryTimesELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/RetryTimesELDeclMultiSpringbootTest.java new file mode 100644 index 000000000..2ed4fe38e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/RetryTimesELDeclMultiSpringbootTest.java @@ -0,0 +1,108 @@ +package com.yomahub.liteflow.test.retryTimes; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import com.yomahub.liteflow.test.rollback.RollbackELDeclMultiSpringbootTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +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 org.springframework.test.context.junit.jupiter.SpringExtension; + +import javax.annotation.Resource; + + +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:/retryTimes/application.properties") +@SpringBootTest(classes = RetryTimesELDeclMultiSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({ "com.yomahub.liteflow.test.retryTimes.cmp" }) +public class RetryTimesELDeclMultiSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + // THEN测试 + @Test + public void testThen() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("a==>b==>a==>b==>a==>b==>a==>b", response.getExecuteStepStr()); + } + + // WHEN测试 + @Test + public void testWhen() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertTrue(response.isSuccess()); + } + + // node测试 + @Test + public void testNode() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("a==>b==>b==>b==>b", response.getExecuteStepStr()); + } + + // FOR测试 + @Test + public void testFor() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("c==>c==>c==>c==>a", response.getExecuteStepStr()); + } + + // SWITCH测试 + @Test + public void testSwitch() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("d==>d==>d==>d==>a", response.getExecuteStepStr()); + } + + // IF测试 + @Test + public void testIf() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("f==>f==>f==>f==>a", response.getExecuteStepStr()); + } + + // WHILE测试 + @Test + public void testWhile() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("n==>n==>n==>n==>a==>n", response.getExecuteStepStr()); + } + + // ITERATOR测试 + @Test + public void testIterator() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain8", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("i==>i==>i==>i==>a", response.getExecuteStepStr()); + } + + // 重试失败提示信息测试 + @Test + public void testRetryFail() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain9", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals("a==>b==>a==>b", response.getExecuteStepStr()); + } + + // FINALLY测试 + @Test + public void testFinally() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain10", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals("a==>b", response.getExecuteStepStr()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/CmpConfig.java new file mode 100644 index 000000000..da8c2cb99 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/CmpConfig.java @@ -0,0 +1,82 @@ +package com.yomahub.liteflow.test.retryTimes.cmp; + +import cn.hutool.core.collection.ListUtil; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.annotation.LiteflowRetry; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.enums.NodeTypeEnum; +import com.yomahub.liteflow.slot.DefaultContext; + +import java.util.Iterator; +import java.util.List; + +@LiteflowComponent +public class CmpConfig { + + int flagb = 0; + int flagc = 0; + int flagd = 0; + int flagf = 0; + int flagi = 0; + int flagn = 0; + int flagw = 0; + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) { + flagb ++; + System.out.println("BCmp executed!"); + if(flagb < 4) throw new RuntimeException(); + else flagb = 0; + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_FOR, nodeId = "c", nodeType = NodeTypeEnum.FOR) + public int processC(NodeComponent bindCmp) { + flagc ++; + System.out.println("CCmp executed!"); + if(flagc < 4) throw new RuntimeException(); + else return 1; + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeId = "d", nodeType = NodeTypeEnum.SWITCH) + public String processD(NodeComponent bindCmp) { + flagd ++; + System.out.println("DCmp executed!"); + if(flagd < 4) throw new RuntimeException(); + else return "a"; + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_IF, nodeId = "f", nodeType = NodeTypeEnum.IF) + public boolean processF(NodeComponent bindCmp) { + System.out.println("FCmp executed!"); + flagf ++; + if(flagf < 4) throw new RuntimeException(); + else return true; + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_ITERATOR, nodeId = "i", nodeType = NodeTypeEnum.ITERATOR) + public Iterator processI(NodeComponent bindCmp) { + flagi ++; + if(flagi < 4) throw new RuntimeException(); + else { + List list = ListUtil.toList("jack"); + return list.iterator(); + } + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_WHILE, nodeId = "n", nodeType = NodeTypeEnum.WHILE) + public boolean processN(NodeComponent bindCmp) { + flagn ++; + System.out.println("NCmp executed!"); + if(flagn < 4) throw new RuntimeException(); + else return flagn == 4 ? true : false; + } + + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/retryTimes/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/retryTimes/application.properties new file mode 100644 index 000000000..ecdb08bea --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/retryTimes/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=retryTimes/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/retryTimes/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/retryTimes/flow.el.xml new file mode 100644 index 000000000..775e7a742 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/retryTimes/flow.el.xml @@ -0,0 +1,43 @@ + + + + THEN( a, b ).retryTimes(3); + + + + WHEN( a, b ).retryTimes(3); + + + + THEN( a, b.retryTimes(3) ); + + + + FOR(c).DO(a).retryTimes(3); + + + + SWITCH(d).TO(a).retryTimes(3); + + + + IF(f, a).retryTimes(3); + + + + WHILE(n).DO(a).retryTimes(3); + + + + ITERATOR(i).DO(a).retryTimes(3); + + + + THEN( a, b ).retryTimes(1); + + + + THEN( a, FINALLY(b, a).retryTimes(3) ); + + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/RetryTimesELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/RetryTimesELDeclSpringbootTest.java new file mode 100644 index 000000000..9a65758dc --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/RetryTimesELDeclSpringbootTest.java @@ -0,0 +1,104 @@ +package com.yomahub.liteflow.test.retryTimes; + +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; + + +@TestPropertySource(value = "classpath:/retryTimes/application.properties") +@SpringBootTest(classes = RetryTimesELDeclSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({ "com.yomahub.liteflow.test.retryTimes.cmp" }) +public class RetryTimesELDeclSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + // THEN测试 + @Test + public void testThen() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("a==>b==>a==>b==>a==>b==>a==>b", response.getExecuteStepStr()); + } + + // WHEN测试 + @Test + public void testWhen() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertTrue(response.isSuccess()); + } + + // node测试 + @Test + public void testNode() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("a==>b==>b==>b==>b", response.getExecuteStepStr()); + } + + // FOR测试 + @Test + public void testFor() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("c==>c==>c==>c==>a", response.getExecuteStepStr()); + } + + // SWITCH测试 + @Test + public void testSwitch() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("d==>d==>d==>d==>a", response.getExecuteStepStr()); + } + + // IF测试 + @Test + public void testIf() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("f==>f==>f==>f==>a", response.getExecuteStepStr()); + } + + // WHILE测试 + @Test + public void testWhile() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("n==>n==>n==>n==>a==>n", response.getExecuteStepStr()); + } + + // ITERATOR测试 + @Test + public void testIterator() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain8", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("i==>i==>i==>i==>a", response.getExecuteStepStr()); + } + + // 重试失败提示信息测试 + @Test + public void testRetryFail() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain9", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals("a==>b==>a==>b", response.getExecuteStepStr()); + } + + // FINALLY测试 + @Test + public void testFinally() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain10", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals("a==>b", response.getExecuteStepStr()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ACmp.java new file mode 100644 index 000000000..46e99dc1f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ACmp.java @@ -0,0 +1,12 @@ +package com.yomahub.liteflow.test.retryTimes.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-declare-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/BCmp.java new file mode 100644 index 000000000..5a02501b3 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/BCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.retryTimes.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent("b") +public class BCmp extends NodeComponent { + int flag = 0; + + @Override + public void process() { + flag ++; + System.out.println("BCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else flag = 0; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/CCmp.java new file mode 100644 index 000000000..f6a1014ee --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/CCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.retryTimes.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeForComponent; + +@LiteflowComponent("c") +public class CCmp extends NodeForComponent { + int flag = 0; + + @Override + public int processFor() throws Exception { + flag ++; + System.out.println("CCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else return 1; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/DCmp.java new file mode 100644 index 000000000..319c98cd5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/DCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.retryTimes.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeSwitchComponent; + +@LiteflowComponent("d") +public class DCmp extends NodeSwitchComponent { + int flag = 0; + + @Override + public String processSwitch() throws Exception { + flag ++; + System.out.println("DCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else return "a"; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/FCmp.java new file mode 100644 index 000000000..f9764757e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/FCmp.java @@ -0,0 +1,16 @@ +package com.yomahub.liteflow.test.retryTimes.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeIfComponent; + +@LiteflowComponent("f") +public class FCmp extends NodeIfComponent { + int flag = 0; + @Override + public boolean processIf() throws Exception { + System.out.println("FCmp executed!"); + flag ++; + if(flag < 4) throw new RuntimeException(); + else return true; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ICmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ICmp.java new file mode 100644 index 000000000..3341869d8 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ICmp.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.retryTimes.cmp; + + +import cn.hutool.core.collection.ListUtil; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeIteratorComponent; + +import java.util.Iterator; +import java.util.List; + +@LiteflowComponent("i") +public class ICmp extends NodeIteratorComponent { + int flag = 0; + @Override + public Iterator processIterator() throws Exception { + flag ++; + if(flag < 4) throw new RuntimeException(); + else { + List list = ListUtil.toList("jack"); + return list.iterator(); + } + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/NCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/NCmp.java new file mode 100644 index 000000000..d4e371647 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/NCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.retryTimes.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeWhileComponent; + +@LiteflowComponent("n") +public class NCmp extends NodeWhileComponent { + int flag = 0; + + @Override + public boolean processWhile() throws Exception { + flag ++; + System.out.println("NCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else return flag == 4 ? true : false; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/retryTimes/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/retryTimes/application.properties new file mode 100644 index 000000000..ecdb08bea --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/retryTimes/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=retryTimes/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/retryTimes/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/retryTimes/flow.el.xml new file mode 100644 index 000000000..775e7a742 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/retryTimes/flow.el.xml @@ -0,0 +1,43 @@ + + + + THEN( a, b ).retryTimes(3); + + + + WHEN( a, b ).retryTimes(3); + + + + THEN( a, b.retryTimes(3) ); + + + + FOR(c).DO(a).retryTimes(3); + + + + SWITCH(d).TO(a).retryTimes(3); + + + + IF(f, a).retryTimes(3); + + + + WHILE(n).DO(a).retryTimes(3); + + + + ITERATOR(i).DO(a).retryTimes(3); + + + + THEN( a, b ).retryTimes(1); + + + + THEN( a, FINALLY(b, a).retryTimes(3) ); + + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retryTimes/RetryTimesTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retryTimes/RetryTimesTest.java new file mode 100644 index 000000000..b3dec4514 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retryTimes/RetryTimesTest.java @@ -0,0 +1,103 @@ +package com.yomahub.liteflow.test.retryTimes; + + +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; + +public class RetryTimesTest extends BaseTest { + + private static FlowExecutor flowExecutor; + + @BeforeAll + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("retryTimes/flow.el.xml"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } + + // THEN测试 + @Test + public void testThen() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("a==>b==>a==>b==>a==>b==>a==>b", response.getExecuteStepStr()); + } + + // WHEN测试 + @Test + public void testWhen() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertTrue(response.isSuccess()); + } + + // node测试 + @Test + public void testNode() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("a==>b==>b==>b==>b", response.getExecuteStepStr()); + } + + // FOR测试 + @Test + public void testFor() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("c==>c==>c==>c==>a", response.getExecuteStepStr()); + } + + // SWITCH测试 + @Test + public void testSwitch() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("d==>d==>d==>d==>a", response.getExecuteStepStr()); + } + + // IF测试 + @Test + public void testIf() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("f==>f==>f==>f==>a", response.getExecuteStepStr()); + } + + // WHILE测试 + @Test + public void testWhile() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("n==>n==>n==>n==>a==>n", response.getExecuteStepStr()); + } + + // ITERATOR测试 + @Test + public void testIterator() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain8", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("i==>i==>i==>i==>a", response.getExecuteStepStr()); + } + + // 重试失败提示信息测试 + @Test + public void testRetryFail() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain9", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals("a==>b==>a==>b", response.getExecuteStepStr()); + } + + // FINALLY测试 + @Test + public void testFinally() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain10", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals("a==>b", response.getExecuteStepStr()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ACmp.java new file mode 100644 index 000000000..23ed69a7a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ACmp.java @@ -0,0 +1,11 @@ +package com.yomahub.liteflow.test.retryTimes.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/retryTimes/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/BCmp.java new file mode 100644 index 000000000..d52cfdb2d --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/BCmp.java @@ -0,0 +1,16 @@ +package com.yomahub.liteflow.test.retryTimes.cmp; + + +import com.yomahub.liteflow.core.NodeComponent; + +public class BCmp extends NodeComponent { + int flag = 0; + + @Override + public void process() { + flag ++; + System.out.println("BCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else flag = 0; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/CCmp.java new file mode 100644 index 000000000..9a39cb349 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/CCmp.java @@ -0,0 +1,16 @@ +package com.yomahub.liteflow.test.retryTimes.cmp; + + +import com.yomahub.liteflow.core.NodeForComponent; + +public class CCmp extends NodeForComponent { + int flag = 0; + + @Override + public int processFor() throws Exception { + flag ++; + System.out.println("CCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else return 1; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/DCmp.java new file mode 100644 index 000000000..e88942178 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/DCmp.java @@ -0,0 +1,16 @@ +package com.yomahub.liteflow.test.retryTimes.cmp; + + +import com.yomahub.liteflow.core.NodeSwitchComponent; + +public class DCmp extends NodeSwitchComponent { + int flag = 0; + + @Override + public String processSwitch() throws Exception { + flag ++; + System.out.println("DCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else return "a"; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/FCmp.java new file mode 100644 index 000000000..bd5601bbb --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/FCmp.java @@ -0,0 +1,15 @@ +package com.yomahub.liteflow.test.retryTimes.cmp; + + +import com.yomahub.liteflow.core.NodeIfComponent; + +public class FCmp extends NodeIfComponent { + int flag = 0; + @Override + public boolean processIf() throws Exception { + System.out.println("FCmp executed!"); + flag ++; + if(flag < 4) throw new RuntimeException(); + else return true; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ICmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ICmp.java new file mode 100644 index 000000000..058bb3c4e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ICmp.java @@ -0,0 +1,21 @@ +package com.yomahub.liteflow.test.retryTimes.cmp; + + +import cn.hutool.core.collection.ListUtil; +import com.yomahub.liteflow.core.NodeIteratorComponent; + +import java.util.Iterator; +import java.util.List; + +public class ICmp extends NodeIteratorComponent { + int flag = 0; + @Override + public Iterator processIterator() throws Exception { + flag ++; + if(flag < 4) throw new RuntimeException(); + else { + List list = ListUtil.toList("jack"); + return list.iterator(); + } + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/NCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/NCmp.java new file mode 100644 index 000000000..68409ab83 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/NCmp.java @@ -0,0 +1,16 @@ +package com.yomahub.liteflow.test.retryTimes.cmp; + + +import com.yomahub.liteflow.core.NodeWhileComponent; + +public class NCmp extends NodeWhileComponent { + int flag = 0; + + @Override + public boolean processWhile() throws Exception { + flag ++; + System.out.println("NCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else return flag == 4 ? true : false; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/retryTimes/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/retryTimes/flow.el.xml new file mode 100644 index 000000000..685f6ef27 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/retryTimes/flow.el.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + THEN( a, b ).retryTimes(3); + + + + WHEN( a, b ).retryTimes(3); + + + + THEN( a, b.retryTimes(3) ); + + + + FOR(c).DO(a).retryTimes(3); + + + + SWITCH(d).TO(a).retryTimes(3); + + + + IF(f, a).retryTimes(3); + + + + WHILE(n).DO(a).retryTimes(3); + + + + ITERATOR(i).DO(a).retryTimes(3); + + + + THEN( a, b ).retryTimes(1); + + + + THEN( a, FINALLY(b, a).retryTimes(3) ); + + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retryTimes/RetryTimesSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retryTimes/RetryTimesSpringbootTest.java new file mode 100644 index 000000000..79b92c2b3 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retryTimes/RetryTimesSpringbootTest.java @@ -0,0 +1,100 @@ +package com.yomahub.liteflow.test.retryTimes; + + +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; + +@ExtendWith(SolonJUnit5Extension.class) +@TestPropertySource("classpath:/retryTimes/application.properties") +public class RetryTimesSpringbootTest extends BaseTest { + + @Inject + private FlowExecutor flowExecutor; + + // THEN测试 + @Test + public void testThen() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("a==>b==>a==>b==>a==>b==>a==>b", response.getExecuteStepStr()); + } + + // WHEN测试 + @Test + public void testWhen() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertTrue(response.isSuccess()); + } + + // node测试 + @Test + public void testNode() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("a==>b==>b==>b==>b", response.getExecuteStepStr()); + } + + // FOR测试 + @Test + public void testFor() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("c==>c==>c==>c==>a", response.getExecuteStepStr()); + } + + // SWITCH测试 + @Test + public void testSwitch() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("d==>d==>d==>d==>a", response.getExecuteStepStr()); + } + + // IF测试 + @Test + public void testIf() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("f==>f==>f==>f==>a", response.getExecuteStepStr()); + } + + // WHILE测试 + @Test + public void testWhile() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("n==>n==>n==>n==>a==>n", response.getExecuteStepStr()); + } + + // ITERATOR测试 + @Test + public void testIterator() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain8", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("i==>i==>i==>i==>a", response.getExecuteStepStr()); + } + + // 重试失败提示信息测试 + @Test + public void testRetryFail() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain9", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals("a==>b==>a==>b", response.getExecuteStepStr()); + } + + // FINALLY测试 + @Test + public void testFinally() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain10", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals("a==>b", response.getExecuteStepStr()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ACmp.java new file mode 100644 index 000000000..9c5531a86 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ACmp.java @@ -0,0 +1,12 @@ +package com.yomahub.liteflow.test.retryTimes.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.noear.solon.annotation.Component; + +@Component("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/retryTimes/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/BCmp.java new file mode 100644 index 000000000..b4890b4ef --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/BCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.retryTimes.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.noear.solon.annotation.Component; + +@Component("b") +public class BCmp extends NodeComponent { + int flag = 0; + + @Override + public void process() { + flag ++; + System.out.println("BCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else flag = 0; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/CCmp.java new file mode 100644 index 000000000..069acb496 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/CCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.retryTimes.cmp; + +import com.yomahub.liteflow.core.NodeForComponent; +import org.noear.solon.annotation.Component; + +@Component("c") +public class CCmp extends NodeForComponent { + int flag = 0; + + @Override + public int processFor() throws Exception { + flag ++; + System.out.println("CCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else return 1; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/DCmp.java new file mode 100644 index 000000000..ccbd72a3e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/DCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.retryTimes.cmp; + +import com.yomahub.liteflow.core.NodeSwitchComponent; +import org.noear.solon.annotation.Component; + +@Component("d") +public class DCmp extends NodeSwitchComponent { + int flag = 0; + + @Override + public String processSwitch() throws Exception { + flag ++; + System.out.println("DCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else return "a"; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/FCmp.java new file mode 100644 index 000000000..5d13709bb --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/FCmp.java @@ -0,0 +1,16 @@ +package com.yomahub.liteflow.test.retryTimes.cmp; + +import com.yomahub.liteflow.core.NodeIfComponent; +import org.noear.solon.annotation.Component; + +@Component("f") +public class FCmp extends NodeIfComponent { + int flag = 0; + @Override + public boolean processIf() throws Exception { + System.out.println("FCmp executed!"); + flag ++; + if(flag < 4) throw new RuntimeException(); + else return true; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ICmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ICmp.java new file mode 100644 index 000000000..922ace500 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ICmp.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.retryTimes.cmp; + + +import cn.hutool.core.collection.ListUtil; +import com.yomahub.liteflow.core.NodeIteratorComponent; +import org.noear.solon.annotation.Component; + +import java.util.Iterator; +import java.util.List; + +@Component("i") +public class ICmp extends NodeIteratorComponent { + int flag = 0; + @Override + public Iterator processIterator() throws Exception { + flag ++; + if(flag < 4) throw new RuntimeException(); + else { + List list = ListUtil.toList("jack"); + return list.iterator(); + } + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/NCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/NCmp.java new file mode 100644 index 000000000..e6b27d11f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/NCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.retryTimes.cmp; + +import com.yomahub.liteflow.core.NodeWhileComponent; +import org.noear.solon.annotation.Component; + +@Component("n") +public class NCmp extends NodeWhileComponent { + int flag = 0; + + @Override + public boolean processWhile() throws Exception { + flag ++; + System.out.println("NCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else return flag == 4 ? true : false; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/retryTimes/application.properties b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/retryTimes/application.properties new file mode 100644 index 000000000..ecdb08bea --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/retryTimes/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=retryTimes/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/retryTimes/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/retryTimes/flow.el.xml new file mode 100644 index 000000000..775e7a742 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/retryTimes/flow.el.xml @@ -0,0 +1,43 @@ + + + + THEN( a, b ).retryTimes(3); + + + + WHEN( a, b ).retryTimes(3); + + + + THEN( a, b.retryTimes(3) ); + + + + FOR(c).DO(a).retryTimes(3); + + + + SWITCH(d).TO(a).retryTimes(3); + + + + IF(f, a).retryTimes(3); + + + + WHILE(n).DO(a).retryTimes(3); + + + + ITERATOR(i).DO(a).retryTimes(3); + + + + THEN( a, b ).retryTimes(1); + + + + THEN( a, FINALLY(b, a).retryTimes(3) ); + + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/RetryTimesSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/RetryTimesSpringbootTest.java new file mode 100644 index 000000000..24d30a669 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/RetryTimesSpringbootTest.java @@ -0,0 +1,105 @@ +package com.yomahub.liteflow.test.retryTimes; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.slot.DefaultContext; +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; + + +@TestPropertySource(value = "classpath:/retryTimes/application.properties") +@SpringBootTest(classes = RetryTimesSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({ "com.yomahub.liteflow.test.retryTimes.cmp" }) +public class RetryTimesSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + // THEN测试 + @Test + public void testThen() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("a==>b==>a==>b==>a==>b==>a==>b", response.getExecuteStepStr()); + } + + // WHEN测试 + @Test + public void testWhen() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertTrue(response.isSuccess()); + } + + // node测试 + @Test + public void testNode() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("a==>b==>b==>b==>b", response.getExecuteStepStr()); + } + + // FOR测试 + @Test + public void testFor() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("c==>c==>c==>c==>a", response.getExecuteStepStr()); + } + + // SWITCH测试 + @Test + public void testSwitch() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("d==>d==>d==>d==>a", response.getExecuteStepStr()); + } + + // IF测试 + @Test + public void testIf() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("f==>f==>f==>f==>a", response.getExecuteStepStr()); + } + + // WHILE测试 + @Test + public void testWhile() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("n==>n==>n==>n==>a==>n", response.getExecuteStepStr()); + } + + // ITERATOR测试 + @Test + public void testIterator() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain8", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("i==>i==>i==>i==>a", response.getExecuteStepStr()); + } + + // 重试失败提示信息测试 + @Test + public void testRetryFail() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain9", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals("a==>b==>a==>b", response.getExecuteStepStr()); + } + + // FINALLY测试 + @Test + public void testFinally() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain10", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals("a==>b", response.getExecuteStepStr()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ACmp.java new file mode 100644 index 000000000..46e99dc1f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ACmp.java @@ -0,0 +1,12 @@ +package com.yomahub.liteflow.test.retryTimes.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-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/BCmp.java new file mode 100644 index 000000000..e5ab69d42 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/BCmp.java @@ -0,0 +1,18 @@ +package com.yomahub.liteflow.test.retryTimes.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowRetry; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent("b") +public class BCmp extends NodeComponent { + int flag = 0; + + @Override + public void process() { + flag ++; + System.out.println("BCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else flag = 0; + } +} \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/CCmp.java new file mode 100644 index 000000000..f6a1014ee --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/CCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.retryTimes.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeForComponent; + +@LiteflowComponent("c") +public class CCmp extends NodeForComponent { + int flag = 0; + + @Override + public int processFor() throws Exception { + flag ++; + System.out.println("CCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else return 1; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/DCmp.java new file mode 100644 index 000000000..319c98cd5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/DCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.retryTimes.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeSwitchComponent; + +@LiteflowComponent("d") +public class DCmp extends NodeSwitchComponent { + int flag = 0; + + @Override + public String processSwitch() throws Exception { + flag ++; + System.out.println("DCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else return "a"; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/FCmp.java new file mode 100644 index 000000000..f9764757e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/FCmp.java @@ -0,0 +1,16 @@ +package com.yomahub.liteflow.test.retryTimes.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeIfComponent; + +@LiteflowComponent("f") +public class FCmp extends NodeIfComponent { + int flag = 0; + @Override + public boolean processIf() throws Exception { + System.out.println("FCmp executed!"); + flag ++; + if(flag < 4) throw new RuntimeException(); + else return true; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ICmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ICmp.java new file mode 100644 index 000000000..3341869d8 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ICmp.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.retryTimes.cmp; + + +import cn.hutool.core.collection.ListUtil; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeIteratorComponent; + +import java.util.Iterator; +import java.util.List; + +@LiteflowComponent("i") +public class ICmp extends NodeIteratorComponent { + int flag = 0; + @Override + public Iterator processIterator() throws Exception { + flag ++; + if(flag < 4) throw new RuntimeException(); + else { + List list = ListUtil.toList("jack"); + return list.iterator(); + } + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/NCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/NCmp.java new file mode 100644 index 000000000..d4e371647 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/NCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.retryTimes.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeWhileComponent; + +@LiteflowComponent("n") +public class NCmp extends NodeWhileComponent { + int flag = 0; + + @Override + public boolean processWhile() throws Exception { + flag ++; + System.out.println("NCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else return flag == 4 ? true : false; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/retryTimes/application.properties b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/retryTimes/application.properties new file mode 100644 index 000000000..ecdb08bea --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/retryTimes/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=retryTimes/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/retryTimes/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/retryTimes/flow.el.xml new file mode 100644 index 000000000..b12f5eced --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/retryTimes/flow.el.xml @@ -0,0 +1,42 @@ + + + + THEN( a, b ).retryTimes(3); + + + + WHEN( a, b ).retryTimes(3); + + + + THEN( a, b.retryTimes(3) ); + + + + FOR(c).DO(a).retryTimes(3); + + + + SWITCH(d).TO(a).retryTimes(3); + + + + IF(f, a).retryTimes(3); + + + + WHILE(n).DO(a).retryTimes(3); + + + + ITERATOR(i).DO(a).retryTimes(3); + + + + THEN( a, b ).retryTimes(1); + + + + THEN( a, FINALLY(b, a).retryTimes(3) ); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retryTimes/RetryTimesSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retryTimes/RetryTimesSpringTest.java new file mode 100644 index 000000000..7026672e5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retryTimes/RetryTimesSpringTest.java @@ -0,0 +1,101 @@ +package com.yomahub.liteflow.test.retryTimes; + +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; + + +@ExtendWith(SpringExtension.class) +@ContextConfiguration("classpath:/retryTimes/application.xml") +public class RetryTimesSpringTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + // THEN测试 + @Test + public void testThen() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("a==>b==>a==>b==>a==>b==>a==>b", response.getExecuteStepStr()); + } + + // WHEN测试 + @Test + public void testWhen() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assertions.assertTrue(response.isSuccess()); + } + + // node测试 + @Test + public void testNode() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("a==>b==>b==>b==>b", response.getExecuteStepStr()); + } + + // FOR测试 + @Test + public void testFor() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("c==>c==>c==>c==>a", response.getExecuteStepStr()); + } + + // SWITCH测试 + @Test + public void testSwitch() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("d==>d==>d==>d==>a", response.getExecuteStepStr()); + } + + // IF测试 + @Test + public void testIf() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("f==>f==>f==>f==>a", response.getExecuteStepStr()); + } + + // WHILE测试 + @Test + public void testWhile() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("n==>n==>n==>n==>a==>n", response.getExecuteStepStr()); + } + + // ITERATOR测试 + @Test + public void testIterator() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain8", "arg"); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertEquals("i==>i==>i==>i==>a", response.getExecuteStepStr()); + } + + // 重试失败提示信息测试 + @Test + public void testRetryFail() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain9", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals("a==>b==>a==>b", response.getExecuteStepStr()); + } + + // FINALLY测试 + @Test + public void testFinally() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain10", "arg"); + Assertions.assertFalse(response.isSuccess()); + Assertions.assertEquals("a==>b", response.getExecuteStepStr()); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ACmp.java new file mode 100644 index 000000000..0dd4114a0 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ACmp.java @@ -0,0 +1,12 @@ +package com.yomahub.liteflow.test.retryTimes.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +@Component("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/retryTimes/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/BCmp.java new file mode 100644 index 000000000..a50952f53 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/BCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.retryTimes.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +@Component("b") +public class BCmp extends NodeComponent { + int flag = 0; + + @Override + public void process() { + flag ++; + System.out.println("BCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else flag = 0; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/CCmp.java new file mode 100644 index 000000000..51949af98 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/CCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.retryTimes.cmp; + +import com.yomahub.liteflow.core.NodeForComponent; +import org.springframework.stereotype.Component; + +@Component("c") +public class CCmp extends NodeForComponent { + int flag = 0; + + @Override + public int processFor() throws Exception { + flag ++; + System.out.println("CCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else return 1; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/DCmp.java new file mode 100644 index 000000000..ee453a2ab --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/DCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.retryTimes.cmp; + +import com.yomahub.liteflow.core.NodeSwitchComponent; +import org.springframework.stereotype.Component; + +@Component("d") +public class DCmp extends NodeSwitchComponent { + int flag = 0; + + @Override + public String processSwitch() throws Exception { + flag ++; + System.out.println("DCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else return "a"; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/FCmp.java new file mode 100644 index 000000000..d41ed62c9 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/FCmp.java @@ -0,0 +1,16 @@ +package com.yomahub.liteflow.test.retryTimes.cmp; + +import com.yomahub.liteflow.core.NodeIfComponent; +import org.springframework.stereotype.Component; + +@Component("f") +public class FCmp extends NodeIfComponent { + int flag = 0; + @Override + public boolean processIf() throws Exception { + System.out.println("FCmp executed!"); + flag ++; + if(flag < 4) throw new RuntimeException(); + else return true; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ICmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ICmp.java new file mode 100644 index 000000000..e936cc096 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/ICmp.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.retryTimes.cmp; + + +import cn.hutool.core.collection.ListUtil; +import com.yomahub.liteflow.core.NodeIteratorComponent; +import org.springframework.stereotype.Component; + +import java.util.Iterator; +import java.util.List; + +@Component("i") +public class ICmp extends NodeIteratorComponent { + int flag = 0; + @Override + public Iterator processIterator() throws Exception { + flag ++; + if(flag < 4) throw new RuntimeException(); + else { + List list = ListUtil.toList("jack"); + return list.iterator(); + } + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/NCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/NCmp.java new file mode 100644 index 000000000..5bb3b5865 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/retryTimes/cmp/NCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.retryTimes.cmp; + +import com.yomahub.liteflow.core.NodeWhileComponent; +import org.springframework.stereotype.Component; + +@Component("n") +public class NCmp extends NodeWhileComponent { + int flag = 0; + + @Override + public boolean processWhile() throws Exception { + flag ++; + System.out.println("NCmp executed!"); + if(flag < 4) throw new RuntimeException(); + else return flag == 4 ? true : false; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/retryTimes/application.xml b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/retryTimes/application.xml new file mode 100644 index 000000000..c1d4af03e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/retryTimes/application.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/retryTimes/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/retryTimes/flow.el.xml new file mode 100644 index 000000000..775e7a742 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/retryTimes/flow.el.xml @@ -0,0 +1,43 @@ + + + + THEN( a, b ).retryTimes(3); + + + + WHEN( a, b ).retryTimes(3); + + + + THEN( a, b.retryTimes(3) ); + + + + FOR(c).DO(a).retryTimes(3); + + + + SWITCH(d).TO(a).retryTimes(3); + + + + IF(f, a).retryTimes(3); + + + + WHILE(n).DO(a).retryTimes(3); + + + + ITERATOR(i).DO(a).retryTimes(3); + + + + THEN( a, b ).retryTimes(1); + + + + THEN( a, FINALLY(b, a).retryTimes(3) ); + + + \ No newline at end of file