bug #I4HQAA setIsEnd目前受isContinue的判断影响,还是会继续

This commit is contained in:
bryan31
2021-11-10 17:16:00 +08:00
parent ecfebfdc19
commit 30b28729e0
6 changed files with 66 additions and 7 deletions

View File

@@ -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()) {

View File

@@ -72,7 +72,7 @@ public class FlowExecutorTest extends BaseTest {
//setIsEnd方法的功能点测试
@Test
public void testSetIsEnd() throws Exception {
public void testSetIsEnd1() throws Exception {
LiteflowResponse<DefaultSlot> 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如果为truecontinueError也为true那不应该continue了
@Test
public void testSetIsEnd2() throws Exception {
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain7", 10);
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("g",response.getSlot().printStep());
}
}

View File

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

View File

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

View File

@@ -1,2 +1 @@
liteflow.rule-source=component/flow.xml
liteflow.retry_count=3
liteflow.rule-source=component/flow.xml

View File

@@ -23,4 +23,8 @@
<chain name="chain6">
<then value="f(d | c | b)" />
</chain>
<chain name="chain7">
<then value="g,h"/>
</chain>
</flow>