From 9f5f8959fbb372d3dd002c192f0995ebbf99d25d Mon Sep 17 00:00:00 2001 From: Dale Lee <1658850308@qq.com> Date: Fri, 7 Jul 2023 09:49:57 +0800 Subject: [PATCH] =?UTF-8?q?feature=20#I7I3LL=20=E5=A2=9E=E5=8A=A0maxWaitSe?= =?UTF-8?q?conds=E5=85=B3=E9=94=AE=E5=AD=97,=E5=85=81=E8=AE=B8=E5=AF=B9EL?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E6=AF=8F=E4=B8=80=E4=B8=AA=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E8=B6=85=E6=97=B6=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../builder/el/LiteFlowChainELBuilder.java | 1 + .../el/operator/MaxWaitSecondsOperator.java | 89 +++++++++ .../liteflow/common/ChainConstant.java | 2 + .../flow/element/condition/WhenCondition.java | 44 ++++- .../MaxWaitSecondsELSpringBootTest.java | 184 ++++++++++++++++++ .../test/maxWaitSeconds/cmp/ACmp.java | 20 ++ .../test/maxWaitSeconds/cmp/BCmp.java | 18 ++ .../test/maxWaitSeconds/cmp/CCmp.java | 18 ++ .../test/maxWaitSeconds/cmp/DCmp.java | 24 +++ .../test/maxWaitSeconds/cmp/FCmp.java | 12 ++ .../test/maxWaitSeconds/cmp/SCmp.java | 13 ++ .../test/maxWaitSeconds/cmp/WCmp.java | 14 ++ .../test/maxWaitSeconds/cmp/XCmp.java | 17 ++ .../maxWaitSeconds/application.properties | 1 + .../test/resources/maxWaitSeconds/flow.el.xml | 98 ++++++++++ 15 files changed, 546 insertions(+), 9 deletions(-) create mode 100644 liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/MaxWaitSecondsOperator.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/MaxWaitSecondsELSpringBootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/ACmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/BCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/CCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/DCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/FCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/SCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/WCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/XCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/maxWaitSeconds/application.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/maxWaitSeconds/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 cc1e3d4d..53a98df0 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 @@ -78,6 +78,7 @@ public class LiteFlowChainELBuilder { EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.DO, Object.class, new DoOperator()); EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.BREAK, Object.class, new BreakOperator()); EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.DATA, Object.class, new DataOperator()); + EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.MAX_WAIT_SECONDS, Object.class, new MaxWaitSecondsOperator()); } public static LiteFlowChainELBuilder createChain() { diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/MaxWaitSecondsOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/MaxWaitSecondsOperator.java new file mode 100644 index 00000000..a6b1d5bd --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/MaxWaitSecondsOperator.java @@ -0,0 +1,89 @@ +package com.yomahub.liteflow.builder.el.operator; + +import cn.hutool.core.collection.CollUtil; +import com.ql.util.express.exception.QLException; +import com.yomahub.liteflow.builder.el.operator.base.BaseOperator; +import com.yomahub.liteflow.builder.el.operator.base.OperatorHelper; +import com.yomahub.liteflow.flow.element.Condition; +import com.yomahub.liteflow.flow.element.Executable; +import com.yomahub.liteflow.flow.element.condition.ConditionKey; +import com.yomahub.liteflow.flow.element.condition.FinallyCondition; +import com.yomahub.liteflow.flow.element.condition.ThenCondition; +import com.yomahub.liteflow.flow.element.condition.WhenCondition; + +import java.util.List; +import java.util.concurrent.TimeUnit; + +/** + * EL 规则中的 maxWaitSeconds 的操作符 + * + * @author DaleLee + * @since 2.11.0 + */ +public class MaxWaitSecondsOperator extends BaseOperator { + @Override + public Condition build(Object[] objects) throws Exception { + OperatorHelper.checkObjectSizeEqTwo(objects); + Executable executable = OperatorHelper.convert(objects[0], Executable.class); + // 获取传入的时间参数 + Integer maxWaitSeconds = OperatorHelper.convert(objects[1], Integer.class); + if (executable instanceof WhenCondition) { + // WhenCondition,直接设置等待时间 + WhenCondition whenCondition = OperatorHelper.convert(executable, WhenCondition.class); + whenCondition.setMaxWaitTime(maxWaitSeconds); + whenCondition.setMaxWaitTimeUnit(TimeUnit.SECONDS); + return whenCondition; + } else if (executable instanceof FinallyCondition) { + // FINALLY,报错 + String errorMsg = "The caller cannot be FinallyCondition item"; + throw new QLException(errorMsg); + } else if (containsFinally(executable)) { + // 处理 THEN 中的 FINALLY + ThenCondition thenCondition = OperatorHelper.convert(executable, ThenCondition.class); + return handleFinally(thenCondition, maxWaitSeconds); + } else { + // 其他情况,被 WHEN 包装 + return wrappedByWhen(executable, maxWaitSeconds); + } + } + + // 将一个 Executable 包装为带有单独超时控制的 WhenCondition + private WhenCondition wrappedByWhen(Executable executable, Integer maxWaitSeconds) { + WhenCondition whenCondition = new WhenCondition(); + whenCondition.addExecutable(executable); + whenCondition.setMaxWaitTime(maxWaitSeconds); + whenCondition.setMaxWaitTimeUnit(TimeUnit.SECONDS); + return whenCondition; + } + + // 判断 THEN 中是否含有 FINALLY 组件 + private boolean containsFinally(Executable executable) { + return executable instanceof ThenCondition + && CollUtil.isNotEmpty(((ThenCondition) executable).getFinallyConditionList()); + } + + // 将 FINALLY 排除在超时控制之外 + private ThenCondition handleFinally(ThenCondition thenCondition, Integer maxWaitSeconds) { + // 进行如下转换 + // THEN(PRE(a),b,FINALLY(c)) + // => THEN( + // WHEN(THEN(PRE(a),b)), + // FINALLY(c)) + + // 定义外层 THEN + ThenCondition outerThenCondition = new ThenCondition(); + + // 把 FINALLY 转移到外层 THEN + List finallyList = thenCondition.getExecutableList(ConditionKey.FINALLY_KEY); + finallyList.forEach(executable + -> outerThenCondition + .addFinallyCondition((FinallyCondition) executable)); + finallyList.clear(); + + // 包装内部 THEN + WhenCondition whenCondition = wrappedByWhen(thenCondition, maxWaitSeconds); + outerThenCondition.addExecutable(whenCondition); + + return outerThenCondition; + } +} 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 0cdbdce9..5be9dc6f 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 @@ -81,4 +81,6 @@ public interface ChainConstant { String NOT = "NOT"; + String MAX_WAIT_SECONDS = "maxWaitSeconds"; + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/WhenCondition.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/WhenCondition.java index f18c59d5..830aee65 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/WhenCondition.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/WhenCondition.java @@ -52,6 +52,12 @@ public class WhenCondition extends Condition { // when单独的线程池名称 private String threadExecutorClass; + // 异步线程最⻓的等待时间 + private Integer maxWaitTime; + + // 等待时间单位 + private TimeUnit maxWaitTimeUnit; + @Override public void executeCondition(Integer slotIndex) throws Exception { executeAsyncCondition(slotIndex); @@ -86,15 +92,20 @@ public class WhenCondition extends Condition { // 3.根据condition.getNodeList()的集合进行流处理,用map进行把executable对象转换成List> // 4.在转的过程中,套入CompletableFutureTimeout方法进行超时判断,如果超时则用WhenFutureObj.timeOut返回超时的对象 // 5.第2个参数是主要的本体CompletableFuture,传入了ParallelSupplier和线程池对象 - Integer whenMaxWaitTime; - TimeUnit whenMaxWaitTimeUnit; + if (ObjectUtil.isNull(this.getMaxWaitTime())) { + if (ObjectUtil.isNotNull(liteflowConfig.getWhenMaxWaitSeconds())) { + // 获取全局异步线程最长等待秒数 + this.setMaxWaitTime(liteflowConfig.getWhenMaxWaitSeconds()); + this.setMaxWaitTimeUnit(TimeUnit.SECONDS); + } else { + // 获取全局异步线程最⻓的等待时间 + this.setMaxWaitTime(liteflowConfig.getWhenMaxWaitTime()); + } + } - if (ObjectUtil.isNotNull(liteflowConfig.getWhenMaxWaitSeconds())){ - whenMaxWaitTime = liteflowConfig.getWhenMaxWaitSeconds(); - whenMaxWaitTimeUnit = TimeUnit.SECONDS; - }else{ - whenMaxWaitTime = liteflowConfig.getWhenMaxWaitTime(); - whenMaxWaitTimeUnit = liteflowConfig.getWhenMaxWaitTimeUnit(); + if (ObjectUtil.isNull(this.getMaxWaitTimeUnit())) { + // 获取全局异步线程最⻓的等待时间单位 + this.setMaxWaitTimeUnit(liteflowConfig.getWhenMaxWaitTimeUnit()); } List> completableFutureList = this.getExecutableList() @@ -112,7 +123,7 @@ public class WhenCondition extends Condition { WhenFutureObj.timeOut(executable.getId()), CompletableFuture.supplyAsync(new ParallelSupplier(executable, currChainName, slotIndex), parallelExecutor), - whenMaxWaitTime, whenMaxWaitTimeUnit)) + this.getMaxWaitTime(), this.getMaxWaitTimeUnit())) .collect(Collectors.toList()); CompletableFuture resultCompletableFuture; @@ -221,4 +232,19 @@ public class WhenCondition extends Condition { this.threadExecutorClass = threadExecutorClass; } + public Integer getMaxWaitTime() { + return maxWaitTime; + } + + public void setMaxWaitTime(Integer maxWaitTime) { + this.maxWaitTime = maxWaitTime; + } + + public TimeUnit getMaxWaitTimeUnit() { + return maxWaitTimeUnit; + } + + public void setMaxWaitTimeUnit(TimeUnit maxWaitTimeUnit) { + this.maxWaitTimeUnit = maxWaitTimeUnit; + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/MaxWaitSecondsELSpringBootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/MaxWaitSecondsELSpringBootTest.java new file mode 100644 index 00000000..93167104 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/MaxWaitSecondsELSpringBootTest.java @@ -0,0 +1,184 @@ +package com.yomahub.liteflow.test.maxWaitSeconds; + +import com.yomahub.liteflow.builder.LiteFlowNodeBuilder; +import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.enums.NodeTypeEnum; +import com.yomahub.liteflow.exception.WhenTimeoutException; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.BaseTest; +import com.yomahub.liteflow.test.validateRule.cmp.ACmp; +import com.yomahub.liteflow.test.validateRule.cmp.BCmp; +import com.yomahub.liteflow.test.validateRule.cmp.CCmp; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +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.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * springboot环境下超时控制测试 + * + * @author DaleLee + * @since 2.11.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/maxWaitSeconds/application.properties") +@SpringBootTest(classes = MaxWaitSecondsELSpringBootTest.class) +@EnableAutoConfiguration +@ComponentScan({ "com.yomahub.liteflow.test.maxWaitSeconds.cmp" }) +public class MaxWaitSecondsELSpringBootTest extends BaseTest { + @Resource + private FlowExecutor flowExecutor; + + public static final String CONTENT_KEY = "testKey"; + + // 测试 THEN 的超时情况 + @Test + public void testThen1() { + assertTimeout("then1"); + } + + // 测试 THEN 的非超时情况 + @Test + public void testThen2() { + assertNotTimeout("then2"); + } + + // 测试 When 的超时情况 + @Test + public void testWhen1() { + assertTimeout("when1"); + } + + // 测试 WHEN 的非超时情况 + @Test + public void testWhen2() { + assertNotTimeout("when2"); + } + + // 测试 FOR 的超时情况 + @Test + public void testFor1() { + assertTimeout("for1"); + } + + // 测试 FOR 的非超时情况 + @Test + public void testFor2() { + assertNotTimeout("for2"); + } + + // 测试 WHILE 的超时情况 + @Test + public void testWhile1() { + assertTimeout("while1"); + } + + // 测试 WHILE 的非超时情况 + @Test + public void testWhile2() { + assertNotTimeout("while2"); + } + + // 测试 ITERATOR 的超时情况 + @Test + public void testIterator1() { + assertTimeout("iterator1"); + } + + // 测试 ITERATOR 的非超时情况 + @Test + public void testIterator2() { + assertNotTimeout("iterator2"); + } + + // 测试 SWITCH 的超时情况 + @Test + public void testSwitch1() { + assertTimeout("switch1"); + } + + // 测试 SWITCH 的非超时情况 + @Test + public void testSwitch2() { + assertNotTimeout("switch2"); + } + + // 测试 IF 的超时情况 + @Test + public void testIf1() { + assertTimeout("if1"); + } + + // 测试 SWITCH 的非超时情况 + @Test + public void testIf2() { + assertNotTimeout("if2"); + } + + // 测试单个组件的超时情况 + @Test + public void testComponent1() { + assertTimeout("component1"); + } + + // 测试单个组件的非超时情况 + @Test + public void testComponent2() { + assertNotTimeout("component2"); + } + + // 测试 FINALLY,虽然超时,但 FINALLY 仍会执行 + @Test + public void testFinally1() { + LiteflowResponse response = flowExecutor.execute2Resp("finally", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(WhenTimeoutException.class, response.getCause().getClass()); + // FINALLY 执行时在默认数据上下文中放入了 CONTENT_KEY + DefaultContext contextBean = response.getFirstContextBean(); + Assert.assertTrue(contextBean.hasData(CONTENT_KEY)); + + } + + // 测试 maxWaitSeconds 关键字不能作用于 Finally + @Test + public void testFinally2() { + LiteFlowNodeBuilder.createNode() + .setId("a") + .setName("组件A") + .setType(NodeTypeEnum.COMMON) + .setClazz(ACmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("b") + .setName("组件B") + .setType(NodeTypeEnum.COMMON) + .setClazz(BCmp.class) + .build(); + LiteFlowNodeBuilder.createNode() + .setId("c") + .setName("组件C") + .setType(NodeTypeEnum.COMMON) + .setClazz(CCmp.class) + .build(); + Assert.assertFalse(LiteFlowChainELBuilder.validate("THEN(a, b, FINALLY(c).maxWaitSeconds(10))")); + } + + private void assertTimeout(String chainId) { + LiteflowResponse response = flowExecutor.execute2Resp(chainId, "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(WhenTimeoutException.class, response.getCause().getClass()); + } + + private void assertNotTimeout(String chainId) { + LiteflowResponse response = flowExecutor.execute2Resp(chainId, "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/ACmp.java new file mode 100644 index 00000000..28a669d8 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/ACmp.java @@ -0,0 +1,20 @@ +package com.yomahub.liteflow.test.maxWaitSeconds.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +import java.util.Random; + +@LiteflowComponent("a") +public class ACmp extends NodeComponent { + @Override + public void process() { + try { + Thread.sleep(1000); + } catch (Exception e) { + e.printStackTrace(); + } + + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/BCmp.java new file mode 100644 index 00000000..08bd6d21 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/BCmp.java @@ -0,0 +1,18 @@ +package com.yomahub.liteflow.test.maxWaitSeconds.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent("b") +public class BCmp extends NodeComponent { + @Override + public void process() { + try { + Thread.sleep(2000); + } catch (Exception e) { + e.printStackTrace(); + } + + System.out.println("BCmp executed!"); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/CCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/CCmp.java new file mode 100644 index 00000000..e991188f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/CCmp.java @@ -0,0 +1,18 @@ +package com.yomahub.liteflow.test.maxWaitSeconds.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; + +@LiteflowComponent("c") +public class CCmp extends NodeComponent { + @Override + public void process() { + try { + Thread.sleep(5000); + } catch (Exception e) { + e.printStackTrace(); + } + + System.out.println("CCmp executed!"); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/DCmp.java new file mode 100644 index 00000000..6e580133 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/DCmp.java @@ -0,0 +1,24 @@ +package com.yomahub.liteflow.test.maxWaitSeconds.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; + +import static com.yomahub.liteflow.test.maxWaitSeconds.MaxWaitSecondsELSpringBootTest.CONTENT_KEY; + +@LiteflowComponent("d") +public class DCmp extends NodeComponent { + + @Override + public void process() { + try { + Thread.sleep(500); + DefaultContext contextBean = this.getFirstContextBean(); + contextBean.setData(CONTENT_KEY,"value"); + } catch (Exception e) { + e.printStackTrace(); + } + + System.out.println("DCmp executed!"); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/FCmp.java new file mode 100644 index 00000000..89ef9f92 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/FCmp.java @@ -0,0 +1,12 @@ +package com.yomahub.liteflow.test.maxWaitSeconds.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeIfComponent; + +@LiteflowComponent("f") +public class FCmp extends NodeIfComponent { + @Override + public boolean processIf() throws Exception { + return true; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/SCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/SCmp.java new file mode 100644 index 00000000..e0e138ef --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/SCmp.java @@ -0,0 +1,13 @@ +package com.yomahub.liteflow.test.maxWaitSeconds.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeSwitchComponent; + +@LiteflowComponent("s") +public class SCmp extends NodeSwitchComponent { + + @Override + public String processSwitch() throws Exception { + return "b"; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/WCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/WCmp.java new file mode 100644 index 00000000..5cb8dac0 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/WCmp.java @@ -0,0 +1,14 @@ +package com.yomahub.liteflow.test.maxWaitSeconds.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.core.NodeWhileComponent; + +@LiteflowComponent("w") +public class WCmp extends NodeWhileComponent { + private int count = 0; + @Override + public boolean processWhile() throws Exception { + count++; + return count <= 2; + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/XCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/XCmp.java new file mode 100644 index 00000000..c8bf8b6d --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/maxWaitSeconds/cmp/XCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.maxWaitSeconds.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("x") +public class XCmp extends NodeIteratorComponent { + @Override + public Iterator processIterator() throws Exception { + List list = ListUtil.toList("one", "two"); + return list.iterator(); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/maxWaitSeconds/application.properties b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/maxWaitSeconds/application.properties new file mode 100644 index 00000000..4dae0def --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/maxWaitSeconds/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=maxWaitSeconds/flow.el.xml \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/maxWaitSeconds/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/maxWaitSeconds/flow.el.xml new file mode 100644 index 00000000..e32dc320 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/maxWaitSeconds/flow.el.xml @@ -0,0 +1,98 @@ + + + + + + + THEN(a,b).maxWaitSeconds(2); + + + + THEN(a,b).maxWaitSeconds(5); + + + + + + WHEN(a,c).maxWaitSeconds(3); + + + + WHEN(a,b).maxWaitSeconds(3); + + + + + + FOR(2).DO(a).maxWaitSeconds(1); + + + + FOR(2).DO(a).maxWaitSeconds(3); + + + + + WHILE(w).DO(a).maxWaitSeconds(1); + + + + WHILE(w).DO(a).maxWaitSeconds(3); + + + + + ITERATOR(x).DO(a).maxWaitSeconds(1); + + + + ITERATOR(x).DO(a).maxWaitSeconds(3); + + + + + + + SWITCH(s).TO(a, b).maxWaitSeconds(1); + + + + SWITCH(s).TO(a, b).maxWaitSeconds(3); + + + + + + + IF(f, b, c).maxWaitSeconds(1); + + + + IF(f, b, c).maxWaitSeconds(3); + + + + + + WHEN( + a.maxWaitSeconds(2), + c.maxWaitSeconds(3) + ); + + + + WHEN( + a.maxWaitSeconds(2), + b.maxWaitSeconds(3) + ); + + + + + + THEN(PRE(a), b, FINALLY(d)).maxWaitSeconds(2); + + + \ No newline at end of file