feature #I7I3LL 完善代码及注释

This commit is contained in:
Dale Lee
2023-07-08 23:18:01 +08:00
parent 5e095553cf
commit 605aab0694
13 changed files with 95 additions and 19 deletions

View File

@@ -47,7 +47,12 @@ public class MaxWaitSecondsOperator extends BaseOperator<Condition> {
}
}
// 将一个 Executable 包装为带有单独超时控制的 WhenCondition
/**
* 将一个 Executable 包装为带有单独超时控制的 WhenCondition
* @param executable 带包装对象
* @param maxWaitSeconds 最大等待秒数
* @return 包装后的 WhenCondition
*/
private WhenCondition wrappedByWhen(Executable executable, Integer maxWaitSeconds) {
WhenCondition whenCondition = new WhenCondition();
whenCondition.addExecutable(executable);
@@ -56,13 +61,22 @@ public class MaxWaitSecondsOperator extends BaseOperator<Condition> {
return whenCondition;
}
// 判断 THEN 中是否含有 FINALLY 组件
/**
* 判断 THEN 中是否含有 FINALLY 组件
* @param executable 判断对象
* @return 含有 FINALLY 组件返回 true否则返回 false
*/
private boolean containsFinally(Executable executable) {
return executable instanceof ThenCondition
&& CollUtil.isNotEmpty(((ThenCondition) executable).getFinallyConditionList());
}
// 将 FINALLY 排除在超时控制之外
/**
* 将 FINALLY 排除在超时控制之外
* @param thenCondition 待处理的 ThenCondition
* @param maxWaitSeconds 最大等待秒数
* @return 处理后的 ThenCondition
*/
private ThenCondition handleFinally(ThenCondition thenCondition, Integer maxWaitSeconds) {
// 进行如下转换
// THEN(PRE(a),b,FINALLY(c))

View File

@@ -20,7 +20,7 @@ import javax.annotation.Resource;
import static com.yomahub.liteflow.test.maxWaitSeconds.cmp.CmpConfig.CONTENT_KEY;
/**
* springboot环境下超时控制测试
* Spring Boot 环境下超时控制测试
*
* @author DaleLee
* @since 2.11.0

View File

@@ -8,8 +8,10 @@ import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
import com.yomahub.liteflow.enums.NodeTypeEnum;
import com.yomahub.liteflow.slot.DefaultContext;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@LiteflowComponent
public class CmpConfig {
@@ -18,7 +20,8 @@ public class CmpConfig {
private int count = 0;
private boolean changed = false;
// 执行过的 chain
Set<String> executedChain = new HashSet<>();
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a")
public void processA(NodeComponent bindCmp) {
@@ -79,9 +82,9 @@ public class CmpConfig {
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_WHILE, nodeId = "w", nodeType = NodeTypeEnum.WHILE)
public boolean processWhile(NodeComponent bindCmp) throws Exception {
// 判断是否切换了 chain
if (bindCmp.getCurrChainId().equals("while2") && !changed) {
if (!executedChain.contains(bindCmp.getCurrChainId())) {
count = 0;
changed = true;
executedChain.add(bindCmp.getCurrChainId());
}
count++;
return count <= 2;

View File

@@ -8,7 +8,6 @@ import com.yomahub.liteflow.exception.WhenTimeoutException;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.slot.DefaultContext;
import com.yomahub.liteflow.test.BaseTest;
import com.yomahub.liteflow.test.loop.LoopELDeclSpringbootTest;
import com.yomahub.liteflow.test.maxWaitSeconds.cmp.ACmp;
import com.yomahub.liteflow.test.maxWaitSeconds.cmp.BCmp;
import com.yomahub.liteflow.test.maxWaitSeconds.cmp.CCmp;
@@ -26,17 +25,17 @@ import javax.annotation.Resource;
import static com.yomahub.liteflow.test.maxWaitSeconds.cmp.DCmp.CONTENT_KEY;
/**
* springboot环境下超时控制测试
* Spring Boot 环境下超时控制测试
*
* @author DaleLee
* @since 2.11.0
*/
@RunWith(SpringRunner.class)
@TestPropertySource(value = "classpath:/maxWaitSeconds/application.properties")
@SpringBootTest(classes = MaxWaitSecondsELDeclSpringBootTest.class)
@SpringBootTest(classes = MaxWaitSecondsELDeclSpringbootTest.class)
@EnableAutoConfiguration
@ComponentScan({ "com.yomahub.liteflow.test.maxWaitSeconds.cmp" })
public class MaxWaitSecondsELDeclSpringBootTest extends BaseTest {
public class MaxWaitSecondsELDeclSpringbootTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;

View File

@@ -7,13 +7,24 @@ import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
import com.yomahub.liteflow.enums.NodeTypeEnum;
import java.util.HashSet;
import java.util.Set;
@LiteflowComponent("w")
@LiteflowCmpDefine(NodeTypeEnum.WHILE)
public class WCmp {
private int count = 0;
// 执行过的 chain
Set<String> executedChain = new HashSet<>();
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_WHILE, nodeType = NodeTypeEnum.WHILE)
public boolean processWhile(NodeComponent bindCmp) throws Exception {
// 判断是否切换了 chain
if (!executedChain.contains(bindCmp.getCurrChainId())) {
count = 0;
executedChain.add(bindCmp.getCurrChainId());
}
count++;
return count <= 2;
}

View File

@@ -19,6 +19,12 @@ import org.junit.Test;
import static com.yomahub.liteflow.test.maxWaitSeconds.cmp.DCmp.CONTENT_KEY;
/**
* 非 Spring 环境下超时控制测试
*
* @author DaleLee
* @since 2.11.0
*/
public class MaxWaitSecondsTest extends BaseTest {
private static FlowExecutor flowExecutor;

View File

@@ -2,10 +2,22 @@ package com.yomahub.liteflow.test.maxWaitSeconds.cmp;
import com.yomahub.liteflow.core.NodeWhileComponent;
import java.util.HashSet;
import java.util.Set;
public class WCmp extends NodeWhileComponent {
private int count = 0;
// 执行过的 chain
Set<String> executedChain = new HashSet<>();
@Override
public boolean processWhile() throws Exception {
// 判断是否切换了 chain
if (!executedChain.contains(this.getCurrChainId())) {
count = 0;
executedChain.add(this.getCurrChainId());
}
count++;
return count <= 2;
}

View File

@@ -21,7 +21,7 @@ import org.noear.solon.test.annotation.TestPropertySource;
import static com.yomahub.liteflow.test.maxWaitSeconds.cmp.DCmp.CONTENT_KEY;
/**
* solon环境下超时控制测试
* Solon 环境下超时控制测试
*
* @author DaleLee
* @since 2.11.0

View File

@@ -22,23 +22,24 @@ import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import static com.yomahub.liteflow.test.maxWaitSeconds.cmp.DCmp.CONTENT_KEY;
/**
* springboot环境下超时控制测试
* Spring Boot 环境下超时控制测试
*
* @author DaleLee
* @since 2.11.0
*/
@RunWith(SpringRunner.class)
@TestPropertySource(value = "classpath:/maxWaitSeconds/application.properties")
@SpringBootTest(classes = MaxWaitSecondsELSpringBootTest.class)
@SpringBootTest(classes = MaxWaitSecondsELSpringbootTest.class)
@EnableAutoConfiguration
@ComponentScan({ "com.yomahub.liteflow.test.maxWaitSeconds.cmp" })
public class MaxWaitSecondsELSpringBootTest extends BaseTest {
public class MaxWaitSecondsELSpringbootTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
public static final String CONTENT_KEY = "testKey";
// 测试 THEN 的超时情况
@Test
public void testThen1() {

View File

@@ -4,11 +4,11 @@ import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
import static com.yomahub.liteflow.test.maxWaitSeconds.MaxWaitSecondsELSpringBootTest.CONTENT_KEY;
@LiteflowComponent("d")
public class DCmp extends NodeComponent {
public static final String CONTENT_KEY = "testKey";
@Override
public void process() {
try {

View File

@@ -3,11 +3,23 @@ package com.yomahub.liteflow.test.maxWaitSeconds.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeWhileComponent;
import java.util.HashSet;
import java.util.Set;
@LiteflowComponent("w")
public class WCmp extends NodeWhileComponent {
private int count = 0;
// 执行过的 chain
Set<String> executedChain = new HashSet<>();
@Override
public boolean processWhile() throws Exception {
// 判断是否切换了 chain
if (!executedChain.contains(this.getCurrChainId())) {
count = 0;
executedChain.add(this.getCurrChainId());
}
count++;
return count <= 2;
}

View File

@@ -21,6 +21,12 @@ import javax.annotation.Resource;
import static com.yomahub.liteflow.test.maxWaitSeconds.cmp.DCmp.CONTENT_KEY;
/**
* Spring 环境下超时控制测试
*
* @author DaleLee
* @since 2.11.0
*/
@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:/maxWaitSeconds/application.xml")
public class MaxWaitSecondsELSpringTest extends BaseTest {

View File

@@ -3,11 +3,23 @@ package com.yomahub.liteflow.test.maxWaitSeconds.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeWhileComponent;
import java.util.HashSet;
import java.util.Set;
@LiteflowComponent("w")
public class WCmp extends NodeWhileComponent {
private int count = 0;
// 执行过的 chain
Set<String> executedChain = new HashSet<>();
@Override
public boolean processWhile() throws Exception {
// 判断是否切换了 chain
if (!executedChain.contains(this.getCurrChainId())) {
count = 0;
executedChain.add(this.getCurrChainId());
}
count++;
return count <= 2;
}