mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 20:22:07 +08:00
feature #I7YYLE 格式化代码
This commit is contained in:
@@ -9,20 +9,20 @@ import com.yomahub.liteflow.flow.element.Node;
|
||||
import com.yomahub.liteflow.flow.element.condition.IteratorCondition;
|
||||
|
||||
public class IteratorOperator extends BaseOperator<IteratorCondition> {
|
||||
|
||||
|
||||
@Override
|
||||
public IteratorCondition build(Object[] objects) throws Exception {
|
||||
OperatorHelper.checkObjectSizeEq(objects, 1);
|
||||
|
||||
|
||||
Node node = OperatorHelper.convert(objects[0], Node.class);
|
||||
if (!ListUtil.toList(NodeTypeEnum.ITERATOR, NodeTypeEnum.FALLBACK).contains(node.getType())) {
|
||||
throw new QLException("The parameter must be iterator-node item");
|
||||
}
|
||||
|
||||
|
||||
IteratorCondition iteratorCondition = new IteratorCondition();
|
||||
iteratorCondition.setIteratorNode(node);
|
||||
|
||||
|
||||
return iteratorCondition;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -24,26 +24,26 @@ import com.yomahub.liteflow.property.LiteflowConfigGetter;
|
||||
* @since 2.8.3
|
||||
*/
|
||||
public class NodeOperator extends BaseOperator<Node> {
|
||||
|
||||
@Override
|
||||
public Node build(Object[] objects) throws Exception {
|
||||
// 检查是否开启了组件降级功能
|
||||
LiteflowConfig liteflowConfig = LiteflowConfigGetter.get();
|
||||
Boolean enable = liteflowConfig.getFallbackCmpEnable();
|
||||
if (!enable) {
|
||||
throw new ELParseException("The fallback component is disabled");
|
||||
}
|
||||
|
||||
OperatorHelper.checkObjectSizeEqOne(objects);
|
||||
String nodeId = OperatorHelper.convert(objects[0], String.class);
|
||||
|
||||
if (FlowBus.containNode(nodeId)) {
|
||||
// 找到对应节点
|
||||
return FlowBus.getNode(nodeId);
|
||||
} else {
|
||||
// 生成代理节点
|
||||
return new FallbackNodeProxy(nodeId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Node build(Object[] objects) throws Exception {
|
||||
// 检查是否开启了组件降级功能
|
||||
LiteflowConfig liteflowConfig = LiteflowConfigGetter.get();
|
||||
Boolean enable = liteflowConfig.getFallbackCmpEnable();
|
||||
if (!enable) {
|
||||
throw new ELParseException("The fallback component is disabled");
|
||||
}
|
||||
|
||||
OperatorHelper.checkObjectSizeEqOne(objects);
|
||||
String nodeId = OperatorHelper.convert(objects[0], String.class);
|
||||
|
||||
if (FlowBus.containNode(nodeId)) {
|
||||
// 找到对应节点
|
||||
return FlowBus.getNode(nodeId);
|
||||
} else {
|
||||
// 生成代理节点
|
||||
return new FallbackNodeProxy(nodeId);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,20 +15,20 @@ import com.yomahub.liteflow.flow.element.condition.SwitchCondition;
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public class SwitchOperator extends BaseOperator<SwitchCondition> {
|
||||
|
||||
|
||||
@Override
|
||||
public SwitchCondition build(Object[] objects) throws Exception {
|
||||
OperatorHelper.checkObjectSizeEqOne(objects);
|
||||
|
||||
|
||||
Node switchNode = OperatorHelper.convert(objects[0], Node.class);
|
||||
if (!ListUtil.toList(NodeTypeEnum.SWITCH, NodeTypeEnum.SWITCH_SCRIPT, NodeTypeEnum.FALLBACK)
|
||||
.contains(switchNode.getType())) {
|
||||
throw new QLException("The caller must be Switch item");
|
||||
}
|
||||
|
||||
|
||||
SwitchCondition switchCondition = new SwitchCondition();
|
||||
switchCondition.setSwitchNode(switchNode);
|
||||
|
||||
|
||||
return switchCondition;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,25 +6,25 @@ package com.yomahub.liteflow.exception;
|
||||
* @author DaleLee
|
||||
*/
|
||||
public class FallbackCmpNotFoundException extends RuntimeException {
|
||||
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
/**
|
||||
* 异常信息
|
||||
*/
|
||||
private String message;
|
||||
|
||||
|
||||
public FallbackCmpNotFoundException(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -47,63 +47,63 @@ import java.util.stream.Collectors;
|
||||
* @author Bryan.Zhang
|
||||
*/
|
||||
public class FlowBus {
|
||||
|
||||
|
||||
private static final LFLog LOG = LFLoggerManager.getLogger(FlowBus.class);
|
||||
|
||||
|
||||
private static final Map<String, Chain> chainMap = new CopyOnWriteHashMap<>();
|
||||
|
||||
|
||||
private static final Map<String, Node> nodeMap = new CopyOnWriteHashMap<>();
|
||||
|
||||
|
||||
private static final Map<NodeTypeEnum, Node> fallbackNodeMap = new CopyOnWriteHashMap<>();
|
||||
|
||||
|
||||
private FlowBus() {
|
||||
}
|
||||
|
||||
|
||||
public static Chain getChain(String id) {
|
||||
return chainMap.get(id);
|
||||
}
|
||||
|
||||
|
||||
// 这一方法主要用于第一阶段chain的预装载
|
||||
public static void addChain(String chainName) {
|
||||
if (!chainMap.containsKey(chainName)) {
|
||||
chainMap.put(chainName, new Chain(chainName));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 这个方法主要用于第二阶段的替换chain
|
||||
public static void addChain(Chain chain) {
|
||||
chainMap.put(chain.getChainId(), chain);
|
||||
}
|
||||
|
||||
|
||||
public static boolean containChain(String chainId) {
|
||||
return chainMap.containsKey(chainId);
|
||||
}
|
||||
|
||||
|
||||
public static boolean needInit() {
|
||||
return MapUtil.isEmpty(chainMap);
|
||||
}
|
||||
|
||||
|
||||
public static boolean containNode(String nodeId) {
|
||||
return nodeMap.containsKey(nodeId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加已托管的节点(如:Spring、Solon 管理的节点)
|
||||
*/
|
||||
public static void addManagedNode(String nodeId, NodeComponent nodeComponent) {
|
||||
// 根据class来猜测类型
|
||||
NodeTypeEnum type = NodeTypeEnum.guessType(nodeComponent.getClass());
|
||||
|
||||
|
||||
if (type == null) {
|
||||
throw new NullNodeTypeException(StrUtil.format("node type is null for node[{}]", nodeId));
|
||||
}
|
||||
|
||||
|
||||
Node node = new Node(ComponentInitializer.loadInstance()
|
||||
.initComponent(nodeComponent, type, nodeComponent.getName(), nodeId));
|
||||
nodeMap.put(nodeId, node);
|
||||
addFallbackNode(node);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加 node
|
||||
*
|
||||
@@ -115,7 +115,7 @@ public class FlowBus {
|
||||
public static void addNode(String nodeId, String name, NodeTypeEnum type, Class<?> cmpClazz) {
|
||||
addNode(nodeId, name, type, cmpClazz, null, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加 node
|
||||
*
|
||||
@@ -133,7 +133,7 @@ public class FlowBus {
|
||||
}
|
||||
addNode(nodeId, name, nodeType, cmpClazz, null, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加脚本 node
|
||||
*
|
||||
@@ -143,12 +143,12 @@ public class FlowBus {
|
||||
* @param script 脚本
|
||||
*/
|
||||
public static void addScriptNode(String nodeId, String name, NodeTypeEnum nodeType, String script,
|
||||
String language) {
|
||||
String language) {
|
||||
addNode(nodeId, name, nodeType, ScriptComponent.ScriptComponentClassMap.get(nodeType), script, language);
|
||||
}
|
||||
|
||||
|
||||
private static void addNode(String nodeId, String name, NodeTypeEnum type, Class<?> cmpClazz, String script,
|
||||
String language) {
|
||||
String language) {
|
||||
try {
|
||||
// 判断此类是否是声明式的组件,如果是声明式的组件,就用动态代理生成实例
|
||||
// 如果不是声明式的,就用传统的方式进行判断
|
||||
@@ -188,10 +188,10 @@ public class FlowBus {
|
||||
.initComponent(cmpInstance, type, name,
|
||||
cmpInstance.getNodeId() == null ? nodeId : cmpInstance.getNodeId()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
|
||||
// 初始化Node,把component放到Node里去
|
||||
List<Node> nodes = cmpInstances.stream().map(Node::new).collect(Collectors.toList());
|
||||
|
||||
|
||||
for (int i = 0; i < nodes.size(); i++) {
|
||||
Node node = nodes.get(i);
|
||||
NodeComponent cmpInstance = cmpInstances.get(i);
|
||||
@@ -206,12 +206,12 @@ public class FlowBus {
|
||||
throw new ScriptLoadException(errorMsg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String activeNodeId = StrUtil.isEmpty(cmpInstance.getNodeId()) ? nodeId : cmpInstance.getNodeId();
|
||||
nodeMap.put(activeNodeId, node);
|
||||
addFallbackNode(node);
|
||||
}
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
String error = StrUtil.format("component[{}] register error",
|
||||
StrUtil.isEmpty(name) ? nodeId : StrUtil.format("{}({})", nodeId, name));
|
||||
@@ -219,30 +219,30 @@ public class FlowBus {
|
||||
throw new ComponentCannotRegisterException(StrUtil.format("{} {}", error, e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Node getNode(String nodeId) {
|
||||
return nodeMap.get(nodeId);
|
||||
}
|
||||
|
||||
|
||||
public static Map<String, Node> getNodeMap() {
|
||||
return nodeMap;
|
||||
}
|
||||
|
||||
|
||||
public static Map<String, Chain> getChainMap() {
|
||||
return chainMap;
|
||||
}
|
||||
|
||||
|
||||
public static Node getFallBackNode(NodeTypeEnum nodeType) {
|
||||
return fallbackNodeMap.get(nodeType);
|
||||
}
|
||||
|
||||
|
||||
public static void cleanCache() {
|
||||
chainMap.clear();
|
||||
nodeMap.clear();
|
||||
fallbackNodeMap.clear();
|
||||
cleanScriptCache();
|
||||
}
|
||||
|
||||
|
||||
public static void cleanScriptCache() {
|
||||
// 如果引入了脚本组件SPI,则还需要清理脚本的缓存
|
||||
try {
|
||||
@@ -250,7 +250,7 @@ public class FlowBus {
|
||||
} catch (ScriptSpiException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void refreshFlowMetaData(FlowParserTypeEnum type, String content) throws Exception {
|
||||
if (type.equals(FlowParserTypeEnum.TYPE_EL_XML)) {
|
||||
new LocalXmlFlowELParser().parse(content);
|
||||
@@ -260,7 +260,7 @@ public class FlowBus {
|
||||
new LocalYmlFlowELParser().parse(content);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static boolean removeChain(String chainId) {
|
||||
if (containChain(chainId)) {
|
||||
chainMap.remove(chainId);
|
||||
@@ -271,23 +271,23 @@ public class FlowBus {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void removeChain(String... chainIds) {
|
||||
Arrays.stream(chainIds).forEach(FlowBus::removeChain);
|
||||
}
|
||||
|
||||
|
||||
private static void addFallbackNode(Node node) {
|
||||
NodeComponent nodeComponent = node.getInstance();
|
||||
FallbackCmp fallbackCmp = AnnoUtil.getAnnotation(nodeComponent.getClass(), FallbackCmp.class);
|
||||
if (fallbackCmp == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
NodeTypeEnum nodeType = node.getType();
|
||||
if (nodeType == null) {
|
||||
nodeType = fallbackCmp.type();
|
||||
}
|
||||
fallbackNodeMap.put(nodeType, node);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -30,21 +30,21 @@ import java.util.Map;
|
||||
* @author Bryan.Zhang
|
||||
*/
|
||||
public abstract class Condition implements Executable {
|
||||
|
||||
|
||||
private String id;
|
||||
|
||||
|
||||
private String tag;
|
||||
|
||||
|
||||
/**
|
||||
* 可执行元素的集合
|
||||
*/
|
||||
private final Map<String, List<Executable>> executableGroup = new HashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
* 当前所在的ChainName 如果对于子流程来说,那这个就是子流程所在的Chain
|
||||
*/
|
||||
private String currChainId;
|
||||
|
||||
|
||||
@Override
|
||||
public void execute(Integer slotIndex) throws Exception {
|
||||
// 当前 Condition 入栈
|
||||
@@ -70,18 +70,18 @@ public abstract class Condition implements Executable {
|
||||
slot.popCondition();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public abstract void executeCondition(Integer slotIndex) throws Exception;
|
||||
|
||||
|
||||
@Override
|
||||
public ExecuteTypeEnum getExecuteType() {
|
||||
return ExecuteTypeEnum.CONDITION;
|
||||
}
|
||||
|
||||
|
||||
public List<Executable> getExecutableList() {
|
||||
return getExecutableList(ConditionKey.DEFAULT_KEY);
|
||||
}
|
||||
|
||||
|
||||
public List<Executable> getExecutableList(String groupKey) {
|
||||
List<Executable> executableList = this.executableGroup.get(groupKey);
|
||||
if (CollUtil.isEmpty(executableList)) {
|
||||
@@ -89,7 +89,7 @@ public abstract class Condition implements Executable {
|
||||
}
|
||||
return executableList;
|
||||
}
|
||||
|
||||
|
||||
public Executable getExecutableOne(String groupKey) {
|
||||
List<Executable> list = getExecutableList(groupKey);
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
@@ -98,15 +98,15 @@ public abstract class Condition implements Executable {
|
||||
return list.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setExecutableList(List<Executable> executableList) {
|
||||
this.executableGroup.put(ConditionKey.DEFAULT_KEY, executableList);
|
||||
}
|
||||
|
||||
|
||||
public void addExecutable(Executable executable) {
|
||||
addExecutable(ConditionKey.DEFAULT_KEY, executable);
|
||||
}
|
||||
|
||||
|
||||
public void addExecutable(String groupKey, Executable executable) {
|
||||
if (ObjectUtil.isNull(executable)) {
|
||||
return;
|
||||
@@ -118,29 +118,29 @@ public abstract class Condition implements Executable {
|
||||
this.executableGroup.get(groupKey).add(executable);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public abstract ConditionTypeEnum getConditionType();
|
||||
|
||||
@Override
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@Override
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@Override
|
||||
public void setTag(String tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 请使用 {@link #setCurrChainId(String)}
|
||||
*/
|
||||
@@ -148,16 +148,16 @@ public abstract class Condition implements Executable {
|
||||
public String getCurrChainName() {
|
||||
return currChainId;
|
||||
}
|
||||
|
||||
|
||||
public String getCurrChainId() {
|
||||
return currChainId;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setCurrChainId(String currChainId) {
|
||||
this.currChainId = currChainId;
|
||||
}
|
||||
|
||||
|
||||
public Map<String, List<Executable>> getExecutableGroup() {
|
||||
return executableGroup;
|
||||
}
|
||||
|
||||
@@ -18,29 +18,29 @@ import com.yomahub.liteflow.slot.DataBus;
|
||||
import com.yomahub.liteflow.slot.Slot;
|
||||
|
||||
public class FallbackNodeProxy extends Node {
|
||||
|
||||
|
||||
// 原节点 id
|
||||
private String expectedNodeId;
|
||||
|
||||
|
||||
// 降级节点
|
||||
private Node fallbackNode;
|
||||
|
||||
|
||||
public FallbackNodeProxy() {
|
||||
this.setType(NodeTypeEnum.FALLBACK);
|
||||
}
|
||||
|
||||
|
||||
public FallbackNodeProxy(String expectedNodeId) {
|
||||
this();
|
||||
this.expectedNodeId = expectedNodeId;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void execute(Integer slotIndex) throws Exception {
|
||||
loadFallBackNode(slotIndex);
|
||||
this.fallbackNode.setCurrChainId(this.getCurrChainId());
|
||||
this.fallbackNode.execute(slotIndex);
|
||||
}
|
||||
|
||||
|
||||
private void loadFallBackNode(Integer slotIndex) throws Exception {
|
||||
if (ObjectUtil.isNotNull(this.fallbackNode)) {
|
||||
// 已经加载过了
|
||||
@@ -60,7 +60,7 @@ public class FallbackNodeProxy extends Node {
|
||||
// 使用 node 的副本
|
||||
this.fallbackNode = node.copy();
|
||||
}
|
||||
|
||||
|
||||
private Node findFallbackNode(Condition condition) {
|
||||
ConditionTypeEnum conditionType = condition.getConditionType();
|
||||
switch (conditionType) {
|
||||
@@ -87,95 +87,95 @@ public class FallbackNodeProxy extends Node {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Node findNodeInIf(IfCondition ifCondition) {
|
||||
Executable ifItem = ifCondition.getIfItem();
|
||||
if (ifItem == this) {
|
||||
// 需要条件组件
|
||||
return FlowBus.getFallBackNode(NodeTypeEnum.IF);
|
||||
}
|
||||
|
||||
|
||||
// 需要普通组件
|
||||
return FlowBus.getFallBackNode(NodeTypeEnum.COMMON);
|
||||
}
|
||||
|
||||
|
||||
private Node findNodeInSwitch(SwitchCondition switchCondition) {
|
||||
Node switchNode = switchCondition.getSwitchNode();
|
||||
if (switchNode == this) {
|
||||
return FlowBus.getFallBackNode(NodeTypeEnum.SWITCH);
|
||||
}
|
||||
|
||||
|
||||
return FlowBus.getFallBackNode(NodeTypeEnum.COMMON);
|
||||
}
|
||||
|
||||
|
||||
private Node findNodeInFor(ForCondition forCondition) {
|
||||
Node forNode = forCondition.getForNode();
|
||||
if (forNode == this) {
|
||||
return FlowBus.getFallBackNode(NodeTypeEnum.FOR);
|
||||
}
|
||||
|
||||
|
||||
return findNodeInLoop(forCondition);
|
||||
}
|
||||
|
||||
|
||||
private Node findNodeInWhile(WhileCondition whileCondition) {
|
||||
Executable whileItem = whileCondition.getWhileItem();
|
||||
if (whileItem == this) {
|
||||
return FlowBus.getFallBackNode(NodeTypeEnum.WHILE);
|
||||
}
|
||||
|
||||
|
||||
return findNodeInLoop(whileCondition);
|
||||
}
|
||||
|
||||
|
||||
private Node findNodeInIterator(IteratorCondition iteratorCondition) {
|
||||
Node iteratorNode = iteratorCondition.getIteratorNode();
|
||||
if (iteratorNode == this) {
|
||||
return FlowBus.getFallBackNode(NodeTypeEnum.ITERATOR);
|
||||
}
|
||||
|
||||
|
||||
return findNodeInLoop(iteratorCondition);
|
||||
}
|
||||
|
||||
|
||||
private Node findNodeInLoop(LoopCondition loopCondition) {
|
||||
Executable breakItem = loopCondition.getExecutableOne(ConditionKey.BREAK_KEY);
|
||||
if (breakItem == this) {
|
||||
return FlowBus.getFallBackNode(NodeTypeEnum.BREAK);
|
||||
}
|
||||
|
||||
|
||||
return FlowBus.getFallBackNode(NodeTypeEnum.COMMON);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public <T> T getItemResultMetaValue(Integer slotIndex) {
|
||||
return this.fallbackNode.getItemResultMetaValue(slotIndex);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isAccess(Integer slotIndex) throws Exception {
|
||||
// 可能会先访问这个方法,所以在这里就要加载降级节点
|
||||
loadFallBackNode(slotIndex);
|
||||
return this.fallbackNode.isAccess(slotIndex);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return this.fallbackNode == null ? null : this.fallbackNode.getId();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Node copy() {
|
||||
// 代理节点不复制
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public NodeTypeEnum getType() {
|
||||
return NodeTypeEnum.FALLBACK;
|
||||
}
|
||||
|
||||
|
||||
public String getExpectedNodeId() {
|
||||
return expectedNodeId;
|
||||
}
|
||||
|
||||
|
||||
public void setExpectedNodeId(String expectedNodeId) {
|
||||
this.expectedNodeId = expectedNodeId;
|
||||
}
|
||||
|
||||
@@ -16,24 +16,24 @@ import javax.annotation.Resource;
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan({"com.yomahub.liteflow.test.fallback.cmp"})
|
||||
public class FallbackSpringbootTest {
|
||||
|
||||
|
||||
@Resource
|
||||
private FlowExecutor flowExecutor;
|
||||
|
||||
|
||||
@Test
|
||||
public void testThen1() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("then1", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("a==>c", response.getExecuteStepStrWithoutTime());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testThen2() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("then2", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("c==>c==>c", response.getExecuteStepStrWithoutTime());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testWhen1() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("when1", "arg");
|
||||
@@ -41,140 +41,140 @@ public class FallbackSpringbootTest {
|
||||
String executeStepStr = response.getExecuteStepStrWithoutTime();
|
||||
Assertions.assertTrue("b==>c".equals(executeStepStr) || "c==>b".equals(executeStepStr));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testIf1() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("if1", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("ifn2", response.getExecuteStepStrWithoutTime());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testIf2() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("if2", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("ifn1==>c", response.getExecuteStepStrWithoutTime());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testFor1() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("for1", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("for1==>a==>a==>a", response.getExecuteStepStrWithoutTime());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testFor2() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("for2", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("LOOP_3==>c==>c==>c", response.getExecuteStepStrWithoutTime());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testWhile1() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("while1", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("wn2", response.getExecuteStepStrWithoutTime());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testWhile2() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("while2", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("wn1==>c==>wn1==>c==>wn1==>c==>wn1", response.getExecuteStepStrWithoutTime());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testIterator1() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("iterator1", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("itn2", response.getExecuteStepStrWithoutTime());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testIterator2() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("iterator2", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("itn1==>c==>c==>c", response.getExecuteStepStrWithoutTime());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBreak1() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("break1", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("LOOP_3==>a==>bn1", response.getExecuteStepStrWithoutTime());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBreak2() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("break2", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("wn1==>a==>bn1", response.getExecuteStepStrWithoutTime());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBreak3() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("break3", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("itn1==>a==>bn1", response.getExecuteStepStrWithoutTime());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSwitch1() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("switch1", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("swn2==>b", response.getExecuteStepStrWithoutTime());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSwitch2() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("switch2", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("swn1==>a", response.getExecuteStepStrWithoutTime());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAnd1() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("and1", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("ifn2", response.getExecuteStepStrWithoutTime());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testOr1() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("or1", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("ifn2==>ifn1==>a", response.getExecuteStepStrWithoutTime());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testNot1() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("not1", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("ifn2==>a", response.getExecuteStepStrWithoutTime());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCatch1() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("catch1", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("a==>d==>c", response.getExecuteStepStrWithoutTime());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMulti1() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("multi1", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("a==>c==>ifn2", response.getExecuteStepStrWithoutTime());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMulti2() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("multi2", "arg");
|
||||
Assertions.assertTrue(response.isSuccess());
|
||||
Assertions.assertEquals("ifn2==>ifn1==>a==>c", response.getExecuteStepStrWithoutTime());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMulti3() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("multi3", "arg");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
*
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
@@ -13,9 +14,9 @@ import com.yomahub.liteflow.core.NodeComponent;
|
||||
@LiteflowComponent("a")
|
||||
public class ACmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("ACmp executed!");
|
||||
}
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("ACmp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
*
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
@@ -16,9 +17,9 @@ import javax.annotation.Resource;
|
||||
@LiteflowComponent("b")
|
||||
public class BCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("BCmp executed!");
|
||||
}
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("BCmp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.yomahub.liteflow.core.NodeBreakComponent;
|
||||
@LiteflowComponent("bn1")
|
||||
@FallbackCmp
|
||||
public class BreakCmp extends NodeBreakComponent {
|
||||
|
||||
|
||||
@Override
|
||||
public boolean processBreak() throws Exception {
|
||||
return true;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
*
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
@@ -17,9 +18,9 @@ import org.springframework.stereotype.Component;
|
||||
@FallbackCmp
|
||||
public class CCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("CCmp executed!");
|
||||
}
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("CCmp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
||||
@LiteflowComponent("d")
|
||||
public class DCmp extends NodeComponent {
|
||||
|
||||
|
||||
@Override
|
||||
public void process() throws Exception {
|
||||
throw new RuntimeException("component[d]");
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.yomahub.liteflow.core.NodeForComponent;
|
||||
@LiteflowComponent("for1")
|
||||
@FallbackCmp
|
||||
public class ForCmp extends NodeForComponent {
|
||||
|
||||
|
||||
@Override
|
||||
public int processFor() throws Exception {
|
||||
return 3;
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.yomahub.liteflow.core.NodeIfComponent;
|
||||
|
||||
@LiteflowComponent("ifn1")
|
||||
public class IfCmp1 extends NodeIfComponent {
|
||||
|
||||
|
||||
@Override
|
||||
public boolean processIf() throws Exception {
|
||||
return true;
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.yomahub.liteflow.core.NodeIfComponent;
|
||||
@LiteflowComponent("ifn2")
|
||||
@FallbackCmp
|
||||
public class IfCmp2 extends NodeIfComponent {
|
||||
|
||||
|
||||
@Override
|
||||
public boolean processIf() throws Exception {
|
||||
return false;
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.Iterator;
|
||||
|
||||
@LiteflowComponent("itn1")
|
||||
public class IteratorCmp1 extends NodeIteratorComponent {
|
||||
|
||||
|
||||
@Override
|
||||
public Iterator<?> processIterator() throws Exception {
|
||||
return Arrays.asList("a", "b", "c").iterator();
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.Iterator;
|
||||
@LiteflowComponent("itn2")
|
||||
@FallbackCmp
|
||||
public class IteratorCmp2 extends NodeIteratorComponent {
|
||||
|
||||
|
||||
@Override
|
||||
public Iterator<?> processIterator() throws Exception {
|
||||
return Collections.emptyIterator();
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.yomahub.liteflow.core.NodeSwitchComponent;
|
||||
|
||||
@LiteflowComponent("swn1")
|
||||
public class SwitchCmp1 extends NodeSwitchComponent {
|
||||
|
||||
|
||||
@Override
|
||||
public String processSwitch() throws Exception {
|
||||
return "a";
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.yomahub.liteflow.core.NodeSwitchComponent;
|
||||
@LiteflowComponent("swn2")
|
||||
@FallbackCmp
|
||||
public class SwitchCmp2 extends NodeSwitchComponent {
|
||||
|
||||
|
||||
@Override
|
||||
public String processSwitch() throws Exception {
|
||||
return "b";
|
||||
|
||||
@@ -9,10 +9,10 @@ import java.util.Set;
|
||||
@LiteflowComponent("wn1")
|
||||
public class WhileCmp1 extends NodeWhileComponent {
|
||||
private int count = 0;
|
||||
|
||||
|
||||
// 执行过的 chain
|
||||
Set<String> executedChain = new HashSet<>();
|
||||
|
||||
|
||||
@Override
|
||||
public boolean processWhile() throws Exception {
|
||||
// 判断是否切换了 chain
|
||||
|
||||
Reference in New Issue
Block a user