From 0efc040aaf0fd165248c665ffc04bc20b13b61d9 Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Mon, 13 Mar 2023 20:58:37 +0800 Subject: [PATCH] =?UTF-8?q?feature=20#I6MPYF=20=E5=A2=9E=E5=8A=A0CATCH?= =?UTF-8?q?=E8=AF=AD=E6=B3=95=E8=A1=A8=E8=BE=BE=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../element/condition/CatchCondition.java | 14 ++++++------- .../test/catchcase/CatchELSpringbootTest.java | 14 +++++++++++++ .../liteflow/test/catchcase/cmp/ECmp.java | 21 +++++++++++++++++++ .../src/test/resources/catchcase/flow.el.xml | 14 +++++++++++++ 4 files changed, 55 insertions(+), 8 deletions(-) create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/catchcase/cmp/ECmp.java diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/CatchCondition.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/CatchCondition.java index a56d17f5..48e8721a 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/CatchCondition.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/CatchCondition.java @@ -28,15 +28,13 @@ public class CatchCondition extends Condition{ catchExecutable.execute(slotIndex); }catch (Exception e){ Executable doExecutable = this.getDoItem(); - if (ObjectUtil.isNull(doExecutable)){ - String errorInfo = StrUtil.format("[{}]:no catch do item find", slot.getRequestId()); - throw new CatchErrorException(errorInfo); + if (ObjectUtil.isNotNull(doExecutable)){ + doExecutable.setCurrChainId(this.getCurrChainId()); + doExecutable.execute(slotIndex); + //catch之后需要把exception给清除掉 + //正如同java的catch一样,异常自己处理了,属于正常流程了,整个流程状态应该是成功的 + DataBus.getSlot(slotIndex).removeException(); } - doExecutable.setCurrChainId(this.getCurrChainId()); - doExecutable.execute(slotIndex); - //catch之后需要把exception给清除掉 - //正如同java的catch一样,异常自己处理了,属于正常流程了,整个流程状态应该是成功的 - DataBus.getSlot(slotIndex).removeException(); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/catchcase/CatchELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/catchcase/CatchELSpringbootTest.java index ffe41767..4841446e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/catchcase/CatchELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/catchcase/CatchELSpringbootTest.java @@ -42,4 +42,18 @@ public class CatchELSpringbootTest extends BaseTest { Assert.assertFalse(response.isSuccess()); Assert.assertEquals("a==>d", response.getExecuteStepStrWithoutTime()); } + + @Test + public void testCatch3() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("a", response.getExecuteStepStrWithoutTime()); + } + + @Test + public void testCatch4() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("LOOP_3==>a==>b==>a==>b==>a==>b", response.getExecuteStepStrWithoutTime()); + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/catchcase/cmp/ECmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/catchcase/cmp/ECmp.java new file mode 100644 index 00000000..e7bf0994 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/catchcase/cmp/ECmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.catchcase.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +@Component("e") +public class ECmp extends NodeComponent { + + @Override + public void process() { + System.out.println("ECmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/catchcase/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/catchcase/flow.el.xml index 026ef934..31017e0b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/catchcase/flow.el.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/catchcase/flow.el.xml @@ -12,4 +12,18 @@ THEN(a,b) ).DO(d) + + + CATCH( + THEN(a,b) + ); + + + + FOR(3).DO( + CATCH( + THEN(a,e,FINALLY(b)) + ) + ); + \ No newline at end of file