!218 BUGFIX #I7ZMVM 一个 node 同时覆盖 isContinueOnError 和 isEnd 场景的 bug

Merge pull request !218 from 与或非/issues/I7ZMVM
This commit is contained in:
铂赛东
2023-09-11 12:51:11 +00:00
committed by Gitee
6 changed files with 62 additions and 1 deletions

View File

@@ -154,8 +154,13 @@ public class Node implements Executable, Cloneable, Rollbackable{
throw e;
}
catch (Exception e) {
// 如果组件覆盖了isEnd方法或者在在逻辑中主要调用了setEnd(true)的话,流程就会立马结束
if (instance.isEnd()) {
String errorInfo = StrUtil.format("[{}] lead the chain to end", instance.getDisplayName());
throw new ChainEndException(errorInfo);
}
// 如果组件覆盖了isContinueOnError方法返回为true那即便出了异常也会继续流程
if (instance.isContinueOnError()) {
else if (instance.isContinueOnError()) {
String errorMsg = StrUtil.format("component[{}] cause error,but flow is still go on", id);
LOG.error(errorMsg);
}

View File

@@ -83,4 +83,12 @@ public class FlowExecutorTest extends BaseTest {
Assertions.assertEquals("g", response.getExecuteStepStr());
}
// 测试setIsEnd如果为truecontinueError也为true那不应该continue了,并且都在同一个 cmp 中
@Test
public void testSetIsEnd3() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain8", 10);
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("i", response.getExecuteStepStr());
}
}

View File

@@ -0,0 +1,21 @@
package com.yomahub.liteflow.test.component.cmp1;
import com.yomahub.liteflow.core.NodeComponent;
public class ICmp extends NodeComponent {
@Override
public void process() throws Exception {
System.out.println("process i");
throw new RuntimeException();
}
@Override
public boolean isContinueOnError() {
return true;
}
@Override
public boolean isEnd() {
return true;
}
}

View File

@@ -0,0 +1,10 @@
package com.yomahub.liteflow.test.component.cmp1;
import com.yomahub.liteflow.core.NodeComponent;
public class JCmp extends NodeComponent {
@Override
public void process() throws Exception {
System.out.println("process j");
}
}

View File

@@ -0,0 +1,10 @@
package com.yomahub.liteflow.test.component.cmp1;
import com.yomahub.liteflow.core.NodeComponent;
public class KCmp extends NodeComponent {
@Override
public void process() throws Exception {
System.out.println("process k");
}
}

View File

@@ -9,6 +9,9 @@
<node id="f" class="com.yomahub.liteflow.test.component.cmp2.FSwitchCmp"/>
<node id="g" class="com.yomahub.liteflow.test.component.cmp1.GCmp"/>
<node id="h" class="com.yomahub.liteflow.test.component.cmp1.HCmp"/>
<node id="i" class="com.yomahub.liteflow.test.component.cmp1.ICmp"/>
<node id="j" class="com.yomahub.liteflow.test.component.cmp1.JCmp"/>
<node id="k" class="com.yomahub.liteflow.test.component.cmp1.KCmp"/>
</nodes>
<chain name="chain1">
@@ -38,4 +41,8 @@
<chain name="chain7">
THEN(g, h);
</chain>
<chain name="chain8">
THEN(i, j, k);
</chain>
</flow>