diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/entity/flow/Node.java b/liteflow-core/src/main/java/com/yomahub/liteflow/entity/flow/Node.java index 9fe0bf51c..4d7b73e68 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/entity/flow/Node.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/entity/flow/Node.java @@ -107,7 +107,7 @@ public class Node implements Executable,Cloneable{ instance.setSlotIndex(slotIndex); Slot slot = DataBus.getSlot(slotIndex); - try{ + try { //判断是否可执行,所以isAccess经常作为一个组件进入的实际判断要素,用作检查slot里的参数的完备性 if (instance.isAccess()) { @@ -135,7 +135,7 @@ public class Node implements Executable,Cloneable{ boolean flag = forExceptions.stream().anyMatch(clazz -> clazz.isAssignableFrom(e.getClass())); //两种情况不重试,1)抛出异常不在指定异常范围内 2)已经重试次数大于等于配置次数 - if (!flag || i >= retryCount){ + if (!flag || i >= retryCount) { throw e; } } @@ -144,12 +144,14 @@ public class Node implements Executable,Cloneable{ //如果组件覆盖了isEnd方法,或者在在逻辑中主要调用了setEnd(true)的话,流程就会立马结束 if (instance.isEnd()) { - String errorInfo = StrUtil.format("[{}]:component[{}] lead the chain to end",slot.getRequestId(),instance.getClass().getSimpleName()); + String errorInfo = StrUtil.format("[{}]:component[{}] lead the chain to end", slot.getRequestId(), instance.getClass().getSimpleName()); throw new ChainEndException(errorInfo); } } else { - LOG.info("[{}]:[X]skip component[{}] execution",slot.getRequestId(),instance.getClass().getSimpleName()); + LOG.info("[{}]:[X]skip component[{}] execution", slot.getRequestId(), instance.getClass().getSimpleName()); } + } catch (ChainEndException e){ + throw e; } catch (Exception e) { //如果组件覆盖了isContinueOnError方法,返回为true,那即便出了异常,也会继续流程 if (instance.isContinueOnError()) { diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorTest.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorTest.java index 5d983b5cc..4ce37867c 100644 --- a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorTest.java +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorTest.java @@ -72,7 +72,7 @@ public class FlowExecutorTest extends BaseTest { //setIsEnd方法的功能点测试 @Test - public void testSetIsEnd() throws Exception { + public void testSetIsEnd1() throws Exception { LiteflowResponse response = flowExecutor.execute2Resp("chain5", 10); Assert.assertTrue(response.isSuccess()); Assert.assertEquals("e",response.getSlot().printStep()); @@ -85,4 +85,12 @@ public class FlowExecutorTest extends BaseTest { Assert.assertTrue(response.isSuccess()); } + //测试setIsEnd如果为true,continueError也为true,那不应该continue了 + @Test + public void testSetIsEnd2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", 10); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("g",response.getSlot().printStep()); + } + } diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/GCmp.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/GCmp.java new file mode 100644 index 000000000..f7917cfae --- /dev/null +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/GCmp.java @@ -0,0 +1,26 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.component.cmp1; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +@Component("g") +public class GCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("GCmp executed!"); + this.setIsEnd(true); + } + + @Override + public boolean isContinueOnError() { + return true; + } +} diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/HCmp.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/HCmp.java new file mode 100644 index 000000000..df41a9c13 --- /dev/null +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/component/cmp1/HCmp.java @@ -0,0 +1,20 @@ +/** + *

Title: liteflow

+ *

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

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.component.cmp1; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +@Component("h") +public class HCmp extends NodeComponent { + + @Override + public void process() { + System.out.println("HCmp executed!"); + } +} diff --git a/liteflow-testcase-springboot/src/test/resources/component/application.properties b/liteflow-testcase-springboot/src/test/resources/component/application.properties index d7ed8babe..d5b0e66d5 100644 --- a/liteflow-testcase-springboot/src/test/resources/component/application.properties +++ b/liteflow-testcase-springboot/src/test/resources/component/application.properties @@ -1,2 +1 @@ -liteflow.rule-source=component/flow.xml -liteflow.retry_count=3 \ No newline at end of file +liteflow.rule-source=component/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-springboot/src/test/resources/component/flow.xml b/liteflow-testcase-springboot/src/test/resources/component/flow.xml index f79857e76..2a504fd01 100644 --- a/liteflow-testcase-springboot/src/test/resources/component/flow.xml +++ b/liteflow-testcase-springboot/src/test/resources/component/flow.xml @@ -23,4 +23,8 @@ + + + + \ No newline at end of file