Bladeren bron

feature #I6MPYF 增加CATCH语法表达式

everywhere.z 2 jaren geleden
bovenliggende
commit
0efc040aaf

+ 6 - 8
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();
         }
     }
 

+ 14 - 0
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());
+    }
 }

+ 21 - 0
liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/catchcase/cmp/ECmp.java

@@ -0,0 +1,21 @@
+/**
+ * <p>Title: liteflow</p>
+ * <p>Description: 轻量级的组件式流程框架</p>
+ * @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!");
+	}
+
+}

+ 14 - 0
liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/catchcase/flow.el.xml

@@ -12,4 +12,18 @@
             THEN(a,b)
         ).DO(d)
     </chain>
+
+    <chain name="chain3">
+        CATCH(
+            THEN(a,b)
+        );
+    </chain>
+
+    <chain name="chain4">
+        FOR(3).DO(
+            CATCH(
+                THEN(a,e,FINALLY(b))
+            )
+        );
+    </chain>
 </flow>