diff --git a/liteflow-core/pom.xml b/liteflow-core/pom.xml index fb2664fd..0c9c917e 100644 --- a/liteflow-core/pom.xml +++ b/liteflow-core/pom.xml @@ -61,5 +61,9 @@ <groupId>com.alibaba</groupId> <artifactId>transmittable-thread-local</artifactId> </dependency> + <dependency> + <groupId>net.bytebuddy</groupId> + <artifactId>byte-buddy</artifactId> + </dependency> </dependencies> </project> diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowCmpDefine.java b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowCmpDefine.java new file mode 100644 index 00000000..bbddb6cb --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowCmpDefine.java @@ -0,0 +1,10 @@ +package com.yomahub.liteflow.annotation; + +import java.lang.annotation.*; + +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +public @interface LiteflowCmpDefine { +} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowCondCmpDefine.java b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowCondCmpDefine.java new file mode 100644 index 00000000..7700ee38 --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowCondCmpDefine.java @@ -0,0 +1,10 @@ +package com.yomahub.liteflow.annotation; + +import java.lang.annotation.*; + +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +public @interface LiteflowCondCmpDefine { +} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowMethod.java b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowMethod.java new file mode 100644 index 00000000..c43b60df --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowMethod.java @@ -0,0 +1,14 @@ +package com.yomahub.liteflow.annotation; + +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +import java.lang.annotation.*; + +@Target({ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +public @interface LiteflowMethod { + + LiteFlowMethodEnum value(); +} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/util/AnnoUtil.java b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/util/AnnoUtil.java index a7af0f06..47460d35 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/util/AnnoUtil.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/util/AnnoUtil.java @@ -4,6 +4,7 @@ import cn.hutool.core.annotation.AnnotationUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ReflectUtil; import com.yomahub.liteflow.annotation.AliasFor; +import com.yomahub.liteflow.util.LiteFlowProxyUtil; import java.lang.annotation.Annotation; import java.lang.reflect.AnnotatedElement; diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/LiteFlowNodeBuilder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/LiteFlowNodeBuilder.java index b580d995..4deb8a6c 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/LiteFlowNodeBuilder.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/LiteFlowNodeBuilder.java @@ -64,6 +64,12 @@ public class LiteFlowNodeBuilder { return this; } + public LiteFlowNodeBuilder setClazz(Class<?> clazz){ + assert clazz != null; + setClazz(clazz.getName()); + return this; + } + // 设置节点组件的class public LiteFlowNodeBuilder setNodeComponentClazz(Class<? extends NodeComponent> nodeComponentClass) { assert nodeComponentClass != null; diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeComponent.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeComponent.java index 11138a0e..da45ee8a 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeComponent.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeComponent.java @@ -35,7 +35,7 @@ import java.util.Map; */ public abstract class NodeComponent{ - private static final Logger LOG = LoggerFactory.getLogger(NodeComponent.class); + private final Logger LOG = LoggerFactory.getLogger(this.getClass()); private final TransmittableThreadLocal<Integer> slotIndexTL = new TransmittableThreadLocal<>(); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/ComponentProxy.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/ComponentProxy.java new file mode 100644 index 00000000..515b222e --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/ComponentProxy.java @@ -0,0 +1,129 @@ +package com.yomahub.liteflow.core.proxy; + +import cn.hutool.core.util.*; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.exception.ComponentMethodDefineErrorException; +import com.yomahub.liteflow.util.LiteFlowProxyUtil; +import com.yomahub.liteflow.util.SerialsUtil; +import net.bytebuddy.ByteBuddy; +import net.bytebuddy.implementation.InvocationHandlerAdapter; +import net.bytebuddy.matcher.ElementMatchers; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * 声明式组件的代理核心生成类 + * @author Bryan.Zhang + * @since 2.6.14 + */ +public class ComponentProxy { + + private final Logger LOG = LoggerFactory.getLogger(this.getClass()); + + private final String nodeId; + + private final Object bean; + + private final Class<?> clazz; + + public ComponentProxy(String nodeId, Object bean, Class<?> clazz) { + this.nodeId = nodeId; + this.bean = bean; + this.clazz = clazz; + } + + public Object getProxy() throws Exception{ + //这里要判断bean是否是spring代理过的bean,如果是代理过的bean需要取到原class对象 + Class<?> beanClazz; + if (LiteFlowProxyUtil.isCglibProxyClass(bean.getClass())){ + beanClazz = LiteFlowProxyUtil.getUserClass(bean.getClass()); + }else{ + beanClazz = bean.getClass(); + } + + //得到当前bean里所覆盖的组件方法(一定是被@LiteFlowMethod修饰的),自己定义的不算 + List<String> methodStrList = Arrays.stream(beanClazz.getDeclaredMethods()).filter( + m -> m.getAnnotation(LiteflowMethod.class) != null + ).map(m -> { + LiteflowMethod liteflowMethod = m.getAnnotation(LiteflowMethod.class); + return liteflowMethod.value().getMethodName(); + }).collect(Collectors.toList()); + + //创建对象 + //这里package进行了重设,放到了被代理对象的所在目录 + //生成的对象也加了上被代理对象拥有的注解 + //被拦截的对象也根据被代理对象根据@LiteFlowMethod所标注的进行了动态判断 + return new ByteBuddy().subclass(clazz) + .name(StrUtil.format("{}.ByteBuddy${}${}", + ClassUtil.getPackage(bean.getClass()), + nodeId, + SerialsUtil.generateShortUUID())) + .method(ElementMatchers.namedOneOf(methodStrList.toArray(new String[]{}))) + .intercept(InvocationHandlerAdapter.of(new AopInvocationHandler(bean))) + .annotateType(bean.getClass().getAnnotations()) + .make() + .load(ComponentProxy.class.getClassLoader()) + .getLoaded() + .newInstance(); + } + + public class AopInvocationHandler implements InvocationHandler { + + private final Object bean; + + public AopInvocationHandler(Object bean) { + this.bean = bean; + } + + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + //这里做了2件事情 + //先是从普通的bean里过滤出含有@LiteFlowMethod这个标注的方法 + //然后进行转换成LiteFlowMethodBean对象List,形成<methodName,Method>键值对的对象 + List<LiteFlowMethodBean> liteFlowMethodBeanList = Arrays.stream(ReflectUtil.getMethods(bean.getClass())).filter(m -> { + LiteflowMethod liteFlowMethod = m.getAnnotation(LiteflowMethod.class); + return ObjectUtil.isNotNull(liteFlowMethod); + }).map(m -> { + LiteflowMethod liteFlowMethod = m.getAnnotation(LiteflowMethod.class); + return new LiteFlowMethodBean(liteFlowMethod.value().getMethodName(), m); + }).collect(Collectors.toList()); + + //获取当前调用方法,是否在被代理的对象方法里面(根据@LiteFlowMethod这个标注去判断) + //如果在里面,则返回那个LiteFlowMethodBean,不在则返回null + LiteFlowMethodBean liteFlowMethodBean = liteFlowMethodBeanList.stream().filter( + liteFlowMethodBean1 -> liteFlowMethodBean1.getMethod().getName().equals(method.getName()) + ).findFirst().orElse(null); + + //如果被代理的对象里有此标注标的方法,则调用此被代理的对象里的方法,如果没有,则调用父类里的方法 + if (liteFlowMethodBean != null){ + //进行检查,检查被代理的bean里是否有且仅有NodeComponent这个类型的参数 + boolean checkFlag = liteFlowMethodBean.getMethod().getParameterTypes().length == 1 + && Arrays.asList(liteFlowMethodBean.getMethod().getParameterTypes()).contains(NodeComponent.class); + if (!checkFlag){ + String errMsg = StrUtil.format("Method[{}.{}] must have NodeComponent parameter(and only one parameter)", bean.getClass().getName(), liteFlowMethodBean.getMethod().getName()); + LOG.error(errMsg); + throw new ComponentMethodDefineErrorException(errMsg); + } + + try{ + return liteFlowMethodBean.getMethod().invoke(bean, proxy); + }catch (Exception e){ + InvocationTargetException targetEx = (InvocationTargetException)e; + throw targetEx.getTargetException(); + } + }else{ + //理论上来说这句应该执行不到,因为前面在设置拦截对象类型的时候,已经根据当前bean所覆盖的方法进行了动态判断 + return method.invoke(proxy, args); + } + } + } +} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/LiteFlowMethodBean.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/LiteFlowMethodBean.java new file mode 100644 index 00000000..3da3caf4 --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/LiteFlowMethodBean.java @@ -0,0 +1,31 @@ +package com.yomahub.liteflow.core.proxy; + +import java.lang.reflect.Method; + +public class LiteFlowMethodBean { + + private String methodName; + + private Method method; + + public LiteFlowMethodBean(String methodName, Method method) { + this.methodName = methodName; + this.method = method; + } + + public String getMethodName() { + return methodName; + } + + public void setMethodName(String methodName) { + this.methodName = methodName; + } + + public Method getMethod() { + return method; + } + + public void setMethod(Method method) { + this.method = method; + } +} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/enums/LiteFlowMethodEnum.java b/liteflow-core/src/main/java/com/yomahub/liteflow/enums/LiteFlowMethodEnum.java new file mode 100644 index 00000000..ec4c6ef2 --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/enums/LiteFlowMethodEnum.java @@ -0,0 +1,26 @@ +package com.yomahub.liteflow.enums; + +public enum LiteFlowMethodEnum { + PROCESS("process"), + PROCESS_COND("processCond"), + IS_ACCESS("isAccess"), + + IS_END("isEnd"), + IS_CONTINUE_ON_ERROR("isContinueOnError"), + + GET_NODE_EXECUTOR_CLASS("getNodeExecutorClass"); + + private String methodName; + + LiteFlowMethodEnum(String methodName){ + this.methodName = methodName; + } + + public String getMethodName() { + return methodName; + } + + public void setMethodName(String methodName) { + this.methodName = methodName; + } +} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ComponentMethodDefineErrorException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ComponentMethodDefineErrorException.java new file mode 100644 index 00000000..9e8beb8a --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ComponentMethodDefineErrorException.java @@ -0,0 +1,22 @@ + +package com.yomahub.liteflow.exception; + +public class ComponentMethodDefineErrorException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + /** 异常信息 */ + private String message; + + public ComponentMethodDefineErrorException(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ComponentProxyErrorException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ComponentProxyErrorException.java new file mode 100644 index 00000000..4b04c29b --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ComponentProxyErrorException.java @@ -0,0 +1,22 @@ + +package com.yomahub.liteflow.exception; + +public class ComponentProxyErrorException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + /** 异常信息 */ + private String message; + + public ComponentProxyErrorException(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/FlowBus.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/FlowBus.java index 99b1a4d9..7caac00b 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/FlowBus.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/FlowBus.java @@ -28,8 +28,11 @@ import com.yomahub.liteflow.parser.LocalYmlFlowParser; import com.yomahub.liteflow.script.ScriptExecutor; import com.yomahub.liteflow.script.ScriptExecutorFactory; import com.yomahub.liteflow.script.exception.ScriptSpiException; +import com.yomahub.liteflow.spi.ContextAware; import com.yomahub.liteflow.spi.holder.ContextAwareHolder; +import com.yomahub.liteflow.spi.local.LocalContextAware; import com.yomahub.liteflow.util.CopyOnWriteHashMap; +import com.yomahub.liteflow.util.LiteFlowProxyUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -82,8 +85,13 @@ public class FlowBus { nodeMap.put(nodeId, new Node(ComponentInitializer.loadInstance().initComponent(nodeComponent, NodeTypeEnum.COMMON, null, nodeId))); } - public static void addCommonNode(String nodeId, String name, String cmpClazzStr) throws Exception { - Class<NodeComponent> cmpClazz = (Class<NodeComponent>) Class.forName(cmpClazzStr); + public static void addCommonNode(String nodeId, String name, String cmpClazzStr){ + Class<?> cmpClazz; + try{ + cmpClazz = Class.forName(cmpClazzStr); + }catch (Exception e){ + throw new ComponentCannotRegisterException(e.getMessage()); + } addNode(nodeId, name, NodeTypeEnum.COMMON, cmpClazz, null); } @@ -99,18 +107,36 @@ public class FlowBus { addNode(nodeId, name, NodeTypeEnum.COND_SCRIPT, ScriptCondComponent.class, script); } - private static void addNode(String nodeId, String name, NodeTypeEnum type, Class<? extends NodeComponent> cmpClazz, String script) { + private static void addNode(String nodeId, String name, NodeTypeEnum type, Class<?> cmpClazz, String script) { try { - //以node方式配置,本质上是为了适配无spring的环境,如果有spring环境,其实不用这么配置 - //这里的逻辑是判断是否能从spring上下文中取到,如果没有spring,则就是new instance了 - //如果是script类型的节点,因为class只有一个,所以也不能注册进spring上下文,注册的时候需要new Instance + //判断此类是否是声明式的组件,如果是声明式的组件,就用动态代理生成实例 + //如果不是声明式的,就用传统的方式进行判断 NodeComponent cmpInstance = null; - if (!CollectionUtil.newArrayList(NodeTypeEnum.SCRIPT, NodeTypeEnum.COND_SCRIPT).contains(type)){ - cmpInstance = ContextAwareHolder.loadContextAware().registerOrGet(nodeId, cmpClazz); - } + if (LiteFlowProxyUtil.isMarkedCmp(cmpClazz)){ + //这里的逻辑要仔细看下 + //如果是spring体系,把原始的类往spring上下文中进行注册,那么会走到ComponentScanner中 + //由于ComponentScanner中已经对原始类进行了动态代理,出来的对象已经变成了动态代理类,所以这时候的bean已经是NodeComponent的子类了 + //所以spring体系下,无需再对这个bean做二次代理 + //但是在非spring体系下,这个bean依旧是原来那个bean,所以需要对这个bean做一次代理 + //这里用ContextAware的spi机制来判断是否spring体系 + ContextAware contextAware = ContextAwareHolder.loadContextAware(); + Object bean = ContextAwareHolder.loadContextAware().registerBean(nodeId, cmpClazz); + if (LocalContextAware.class.isAssignableFrom(contextAware.getClass())){ + cmpInstance = LiteFlowProxyUtil.proxy2NodeComponent(bean, nodeId); + }else { + cmpInstance = (NodeComponent) bean; + } + }else{ + //以node方式配置,本质上是为了适配无spring的环境,如果有spring环境,其实不用这么配置 + //这里的逻辑是判断是否能从spring上下文中取到,如果没有spring,则就是new instance了 + //如果是script类型的节点,因为class只有一个,所以也不能注册进spring上下文,注册的时候需要new Instance + if (!CollectionUtil.newArrayList(NodeTypeEnum.SCRIPT, NodeTypeEnum.COND_SCRIPT).contains(type)){ + cmpInstance = (NodeComponent) ContextAwareHolder.loadContextAware().registerOrGet(nodeId, cmpClazz); + } - if (ObjectUtil.isNull(cmpInstance)) { - cmpInstance = cmpClazz.newInstance(); + if (ObjectUtil.isNull(cmpInstance)) { + cmpInstance = (NodeComponent) cmpClazz.newInstance(); + } } //进行初始化 diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/ContextAware.java b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/ContextAware.java index d313f857..b6b60aaf 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/ContextAware.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/ContextAware.java @@ -16,5 +16,7 @@ public interface ContextAware extends SpiPriority { <T> T registerBean(Class<T> clazz); + <T> T registerBean(String beanName, Object bean); + <T> T registerOrGet(String beanName, Class<T> clazz); } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalContextAware.java b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalContextAware.java index 8734b270..54cf12f8 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalContextAware.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalContextAware.java @@ -30,6 +30,11 @@ public class LocalContextAware implements ContextAware { return registerBean(null, clazz); } + @Override + public <T> T registerBean(String beanName, Object bean) { + return (T)bean; + } + @Override public <T> T registerOrGet(String beanName, Class<T> clazz) { return registerBean(beanName, clazz); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/util/LiteFlowProxyUtil.java b/liteflow-core/src/main/java/com/yomahub/liteflow/util/LiteFlowProxyUtil.java new file mode 100644 index 00000000..4478a691 --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/util/LiteFlowProxyUtil.java @@ -0,0 +1,102 @@ +package com.yomahub.liteflow.util; + +import cn.hutool.core.collection.ListUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowCondCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.core.NodeCondComponent; +import com.yomahub.liteflow.core.proxy.ComponentProxy; +import com.yomahub.liteflow.exception.ComponentProxyErrorException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Arrays; + +/** + * 组件代理类通用方法 + * 主要用于声明式组件 + * @author Bryan.Zhang + * @since 2.6.14 + */ +public class LiteFlowProxyUtil { + + private static final Logger LOG = LoggerFactory.getLogger(LiteFlowProxyUtil.class); + + //判断一个bean是否是解耦式组件 + public static boolean isMarkedCmp(Class<?> clazz){ + //判断bean是否标记了@LiteflowCmpDefine或者@LiteflowCondCmpDefine这2个标注之一 + boolean flag1 = clazz.getAnnotation(LiteflowCmpDefine.class) != null + || clazz.getAnnotation(LiteflowCondCmpDefine.class) != null; + + if (!flag1){ + return false; + } + + //看超类是否是NodeComponent和NodeCondComponent中的一个,如果不是,则说明满足条件。是的话,也不满足 + boolean flag2 = !ListUtil.toList(NodeComponent.class, NodeCondComponent.class).contains(clazz.getSuperclass()); + + if (!flag2){ + return false; + } + + //查看bean里的method是否有方法标记了@LiteflowMethod标注 + //这里的bean有可能是cglib加强过的class,所以要先进行个判断 + Class<?> targetClass; + if (isCglibProxyClass(clazz)){ + targetClass = getUserClass(clazz); + }else{ + targetClass = clazz; + } + boolean flag3 = Arrays.stream(targetClass.getMethods()).anyMatch( + method -> method.getAnnotation(LiteflowMethod.class) != null + ); + + return flag3; + } + + //对一个满足声明式的bean进行代理 + public static NodeComponent proxy2NodeComponent(Object bean, String nodeId){ + try{ + LiteflowCmpDefine liteflowCmpDefine = bean.getClass().getAnnotation(LiteflowCmpDefine.class); + LiteflowCondCmpDefine liteflowCondCmpDefine = bean.getClass().getAnnotation(LiteflowCondCmpDefine.class); + + ComponentProxy proxy; + if (ObjectUtil.isNotNull(liteflowCmpDefine)){ + proxy = new ComponentProxy(nodeId, bean, NodeComponent.class); + return (NodeComponent) proxy.getProxy(); + } + + if (ObjectUtil.isNotNull(liteflowCondCmpDefine)){ + proxy = new ComponentProxy(nodeId, bean, NodeCondComponent.class); + return (NodeCondComponent) proxy.getProxy(); + } + + throw new RuntimeException(); + }catch (Exception e){ + String errMsg = StrUtil.format("Error while proxying bean[{}]",bean.getClass().getName()); + LOG.error(errMsg, e); + throw new ComponentProxyErrorException(errMsg); + } + } + + public static boolean isCglibProxyClass(Class<?> clazz) { + return (clazz != null && isCglibProxyClassName(clazz.getName())); + } + + public static Class<?> getUserClass(Class<?> clazz) { + if (clazz.getName().contains("$$")) { + Class<?> superclass = clazz.getSuperclass(); + if (superclass != null && superclass != Object.class) { + return superclass; + } + } + return clazz; + } + + private static boolean isCglibProxyClassName(String className) { + return (className != null && className.contains("$$")); + } +} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/util/SerialsUtil.java b/liteflow-core/src/main/java/com/yomahub/liteflow/util/SerialsUtil.java new file mode 100644 index 00000000..ac7abb6a --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/util/SerialsUtil.java @@ -0,0 +1,192 @@ +package com.yomahub.liteflow.util; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.*; + +public class SerialsUtil { + + public static int serialInt = 1; + + private static final DecimalFormat format8 = new DecimalFormat("00000000"); + private static final DecimalFormat format12 = new DecimalFormat("000000000000"); + private static final BigInteger divisor; + private static final BigInteger divisor12; + + static { + divisor = BigInteger.valueOf(19999999L).multiply(BigInteger.valueOf(5)); + divisor12 = BigInteger.valueOf(190000000097L).multiply(BigInteger.valueOf(5)); + } + + public static String genSerialNo(){ + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); + String strNow = sdf.format(new Date()); + + // 生成3位随机数 + Random random = new Random(); + int intRandom = random.nextInt(999); + + String strRandom = String.valueOf(intRandom); + int len = strRandom.length(); + for (int i = 0; i < (3-len); i++) { + strRandom = "0" + strRandom; + } + String serialStr = SerialsUtil.nextSerial(); + return (strNow + strRandom + serialStr) ; + } + + public static synchronized String nextSerial(){ + int serial = serialInt++; + if (serial > 999){ + serialInt = 1; + serial=1; + } + String serialStr = serial + ""; + int len = serialStr.length(); + for (int i = 0; i < (3-len); i++) { + serialStr = "0" + serialStr; + } + + return serialStr; + } + + + /** + * 生成一个12位随机数 + * + * @param seed 种子 + * @return + */ + public static String randomNum12(long seed) { + // 被除数 + BigInteger dividend = BigDecimal.valueOf(seed).pow(5).toBigInteger(); + return format12.format(dividend.remainder(divisor12)); + } + + /** + * 生成一个8位随机数 + * + * @param seed 种子 + * @return + */ + public static String randomNum8(long seed) { + // 被除数 + BigInteger dividend = BigDecimal.valueOf(seed).pow(5).toBigInteger(); + return format8.format(dividend.remainder(divisor)); + } + + /* + * 10进制转32进制(去除0,O,1,I) + */ + public static String from10To32(String numStr, int size){ + long to=32; + long num = Long.parseLong(numStr); + String jg=""; + while(num!=0){ + switch (new Long(num%to).intValue()) { + case 0:jg="B"+jg;break; case 1:jg="R"+jg;break; case 2:jg="6"+jg;break; case 3:jg="U"+jg;break; + case 4:jg="M"+jg;break; case 5:jg="E"+jg;break; case 6:jg="H"+jg;break; case 7:jg="C"+jg;break; + case 8:jg="G"+jg;break; case 9:jg="Q"+jg;break; case 10:jg="A"+jg;break; case 11:jg="8"+jg;break; + case 12:jg="3"+jg;break; case 13:jg="S"+jg;break; case 14:jg="J"+jg;break; case 15:jg="Y"+jg;break; + case 16:jg="7"+jg;break; case 17:jg="5"+jg;break; case 18:jg="W"+jg;break; case 19:jg="9"+jg;break; + case 20:jg="F"+jg;break; case 21:jg="T"+jg;break; case 22:jg="D"+jg;break; case 23:jg="2"+jg;break; + case 24:jg="P"+jg;break; case 25:jg="Z"+jg;break; case 26:jg="N"+jg;break; case 27:jg="K"+jg;break; + case 28:jg="V"+jg;break; case 29:jg="X"+jg;break; case 30:jg="L"+jg;break; case 31:jg="4"+jg;break; + default: jg=String.valueOf(num%to)+jg;break; + } + num=num/to; + } + if (jg.length() < size){ + int loop = size - jg.length(); + for (int i = 0; i < loop; i++){ + jg = "2" + jg; + } + } + return jg; + } + + /* + * 10进制转32进制(去除0,O,1,I) + */ + public static String from10To24(String numStr, int size){ + long to=24; + long num = Long.parseLong(numStr); + String jg=""; + while(num!=0){ + switch (new Long(num%to).intValue()) { + case 0:jg="B"+jg;break; + case 1:jg="R"+jg;break; + case 2:jg="U"+jg;break; + case 3:jg="M"+jg;break; + case 4:jg="E"+jg;break; + case 5:jg="H"+jg;break; + case 6:jg="C"+jg;break; + case 7:jg="G"+jg;break; + case 8:jg="Q"+jg;break; + case 9:jg="A"+jg;break; + case 10:jg="S"+jg;break; + case 11:jg="J"+jg;break; + case 12:jg="Y"+jg;break; + case 13:jg="W"+jg;break; + case 14:jg="F"+jg;break; + case 15:jg="T"+jg;break; + case 16:jg="D"+jg;break; + case 17:jg="P"+jg;break; + case 18:jg="Z"+jg;break; + case 19:jg="N"+jg;break; + case 20:jg="K"+jg;break; + case 21:jg="V"+jg;break; + case 22:jg="X"+jg;break; + case 23:jg="L"+jg;break; + default: jg=String.valueOf(num%to)+jg;break; + } + num=num/to; + } + if (jg.length() < size){ + int loop = size - jg.length(); + for (int i = 0; i < loop; i++){ + jg = "B" + jg; + } + } + return jg; + } + + /** + * 32位 + * @return + */ + public static String getUUID() { + UUID uuid = UUID.randomUUID(); + String str = uuid.toString(); + // 去掉"-"符号 + String temp = str.substring(0, 8) + str.substring(9, 13) + str.substring(14, 18) + str.substring(19, 23) + str.substring(24); + return temp; + } + + public static String generateShortUUID() { + String str = randomNum8(System.nanoTime()); + return from10To24(str, 6); + } + + public static String generateFileUUID() { + String str = randomNum12(System.nanoTime()); + return from10To32(str, 8); + } + + public static String genToken(){ + return from10To32(randomNum12(System.currentTimeMillis()),8) + from10To32(randomNum12(System.nanoTime()),8); + } + + public static void main(String[] args) { + Set set = new HashSet(); + String str; + for (int i = 0; i < 300; i++) { + str = generateShortUUID(); + System.out.println(str); + set.add(str); + } + System.out.println(set.size()); + } +} \ No newline at end of file diff --git a/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringAware.java b/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringAware.java index e3f5e904..0634c113 100644 --- a/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringAware.java +++ b/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringAware.java @@ -4,11 +4,13 @@ import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ReflectUtil; import com.yomahub.liteflow.spi.ContextAware; import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.AutowireCapableBeanFactory; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.GenericBeanDefinition; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; +import org.springframework.context.ConfigurableApplicationContext; /** * 基于代码形式的spring上下文工具类 @@ -64,6 +66,14 @@ public class SpringAware implements ApplicationContextAware, ContextAware { return registerBean(c.getName(), c); } + @Override + public <T> T registerBean(String beanName, Object bean) { + ConfigurableApplicationContext configurableApplicationContext = (ConfigurableApplicationContext) applicationContext; + DefaultListableBeanFactory defaultListableBeanFactory = (DefaultListableBeanFactory) configurableApplicationContext.getAutowireCapableBeanFactory(); + defaultListableBeanFactory.registerSingleton(beanName,bean); + return (T) configurableApplicationContext.getBean(beanName); + } + public <T> T registerOrGet(String beanName, Class<T> clazz) { if (ObjectUtil.isNull(applicationContext)){ return null; diff --git a/liteflow-spring/src/main/java/com/yomahub/liteflow/spring/ComponentScanner.java b/liteflow-spring/src/main/java/com/yomahub/liteflow/spring/ComponentScanner.java index c932bcd8..25439090 100644 --- a/liteflow-spring/src/main/java/com/yomahub/liteflow/spring/ComponentScanner.java +++ b/liteflow-spring/src/main/java/com/yomahub/liteflow/spring/ComponentScanner.java @@ -12,6 +12,7 @@ import com.yomahub.liteflow.aop.ICmpAroundAspect; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.property.LiteflowConfig; import com.yomahub.liteflow.util.LOGOPrinter; +import com.yomahub.liteflow.util.LiteFlowProxyUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeansException; @@ -55,17 +56,29 @@ public class ComponentScanner implements BeanPostProcessor { @Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { Class clazz = bean.getClass(); + + //判断是不是声明式组件 + //如果是,就缓存到类属性的map中 + if (LiteFlowProxyUtil.isMarkedCmp(bean.getClass())){ + LOG.info("proxy component[{}] has been found", beanName); + NodeComponent nodeComponent = LiteFlowProxyUtil.proxy2NodeComponent(bean, beanName); + nodeComponentMap.put(beanName, nodeComponent); + return nodeComponent; + } + // 组件的扫描发现,扫到之后缓存到类属性map中 if (NodeComponent.class.isAssignableFrom(clazz)) { LOG.info("component[{}] has been found", beanName); NodeComponent nodeComponent = (NodeComponent) bean; nodeComponentMap.put(beanName, nodeComponent); + return nodeComponent; } // 组件Aop的实现类加载 if (ICmpAroundAspect.class.isAssignableFrom(clazz)) { LOG.info("component aspect implement[{}] has been found", beanName); cmpAroundAspect = (ICmpAroundAspect) bean; + return cmpAroundAspect; } return bean; diff --git a/liteflow-testcase-declare-component/pom.xml b/liteflow-testcase-declare-component/pom.xml new file mode 100644 index 00000000..e0f7c22c --- /dev/null +++ b/liteflow-testcase-declare-component/pom.xml @@ -0,0 +1,69 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <artifactId>liteflow</artifactId> + <groupId>com.yomahub</groupId> + <version>2.6.14</version> + </parent> + <modelVersion>4.0.0</modelVersion> + + <artifactId>liteflow-testcase-declare-component</artifactId> + + <dependencies> + <dependency> + <groupId>com.yomahub</groupId> + <artifactId>liteflow-spring-boot-starter</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <version>${springboot.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.aspectj</groupId> + <artifactId>aspectjweaver</artifactId> + <version>1.8.13</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.curator</groupId> + <artifactId>curator-test</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.101tec</groupId> + <artifactId>zkclient</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.yomahub</groupId> + <artifactId>liteflow-script-qlexpress</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <version>${springboot.version}</version> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-deploy-plugin</artifactId> + <version>2.8.2</version> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + </plugins> + </build> + +</project> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/BaseTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/BaseTest.java new file mode 100644 index 00000000..64886670 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/BaseTest.java @@ -0,0 +1,20 @@ +package com.yomahub.liteflow.test; + +import com.yomahub.liteflow.flow.FlowBus; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.spi.holder.SpiFactoryCleaner; +import com.yomahub.liteflow.spring.ComponentScanner; +import com.yomahub.liteflow.thread.ExecutorHelper; +import org.junit.AfterClass; + +public class BaseTest { + + @AfterClass + public static void cleanScanCache(){ + ComponentScanner.cleanCache(); + FlowBus.cleanCache(); + ExecutorHelper.loadInstance().clearExecutorServiceMap(); + SpiFactoryCleaner.clean(); + LiteflowConfigGetter.clean(); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathSpringbootTest.java new file mode 100644 index 00000000..09b6de2a --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathSpringbootTest.java @@ -0,0 +1,42 @@ +package com.yomahub.liteflow.test.absoluteConfigPath; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * springboot环境下异步线程超时日志打印测试 + * @author Bryan.Zhang + * @since 2.6.4 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/absoluteConfigPath/application.properties") +@SpringBootTest(classes = AbsoluteConfigPathSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.absoluteConfigPath.cmp"}) +public class AbsoluteConfigPathSpringbootTest extends BaseTest { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testAbsoluteConfig() throws Exception{ + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/ACmp.java new file mode 100644 index 00000000..f2370fa6 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/ACmp.java @@ -0,0 +1,24 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.absoluteConfigPath.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/BCmp.java new file mode 100644 index 00000000..e83723bd --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.absoluteConfigPath.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/CCmp.java new file mode 100644 index 00000000..17a09659 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.absoluteConfigPath.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/CustomAOPSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/CustomAOPSpringbootTest.java new file mode 100644 index 00000000..41c08bce --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/CustomAOPSpringbootTest.java @@ -0,0 +1,56 @@ +package com.yomahub.liteflow.test.aop; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import com.yomahub.liteflow.test.aop.aspect.CustomAspect; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Import; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * 切面场景单元测试 + * 在声明式组件场景中,自定义aspect的aop不生效的,因为生成的代理类并不是原类,也不是原类的子类,而是NodeComponent的子类 + * 所以切不到,暂且没有想出办法来解决,这个测试类暂时不用 + * @author Bryan.Zhang + */ +/*@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/aop/application.properties") +@SpringBootTest(classes = CustomAOPSpringbootTest.class) +@EnableAutoConfiguration +@Import(CustomAspect.class) +@ComponentScan({"com.yomahub.liteflow.test.aop.cmp1","com.yomahub.liteflow.test.aop.cmp2"})*/ +public class CustomAOPSpringbootTest extends BaseTest { + + /*@Resource + private FlowExecutor flowExecutor; + + //测试自定义AOP,串行场景 + @Test + public void testCustomAopS() { + LiteflowResponse<DefaultSlot> response= flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("before_after", response.getSlot().getData("a")); + Assert.assertEquals("before_after", response.getSlot().getData("b")); + Assert.assertEquals("before_after", response.getSlot().getData("c")); + } + + //测试自定义AOP,并行场景 + @Test + public void testCustomAopP() { + LiteflowResponse<DefaultSlot> response= flowExecutor.execute2Resp("chain2", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("before_after", response.getSlot().getData("a")); + Assert.assertEquals("before_after", response.getSlot().getData("b")); + Assert.assertEquals("before_after", response.getSlot().getData("c")); + }*/ +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/GlobalAOPSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/GlobalAOPSpringbootTest.java new file mode 100644 index 00000000..43f0f5bd --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/GlobalAOPSpringbootTest.java @@ -0,0 +1,76 @@ +package com.yomahub.liteflow.test.aop; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.spring.ComponentScanner; +import com.yomahub.liteflow.test.BaseTest; +import com.yomahub.liteflow.test.aop.aspect.CmpAspect; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Import; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * 切面场景单元测试 + * @author Bryan.Zhang + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/aop/application.properties") +@SpringBootTest(classes = GlobalAOPSpringbootTest.class) +@EnableAutoConfiguration +@Import(CmpAspect.class) +@ComponentScan({"com.yomahub.liteflow.test.aop.cmp1","com.yomahub.liteflow.test.aop.cmp2"}) +public class GlobalAOPSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试全局AOP,串行场景 + @Test + public void testGlobalAopS() { + LiteflowResponse<DefaultSlot> response= flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("before_after", response.getSlot().getData("a")); + Assert.assertEquals("before_after", response.getSlot().getData("b")); + Assert.assertEquals("before_after", response.getSlot().getData("c")); + Assert.assertEquals("before_after", response.getSlot().getData("d")); + Assert.assertEquals("before_after", response.getSlot().getData("e")); + } + + //测试全局AOP,并行场景 + @Test + public void testGlobalAopP() { + LiteflowResponse<DefaultSlot> response= flowExecutor.execute2Resp("chain2", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("before_after", response.getSlot().getData("a")); + Assert.assertEquals("before_after", response.getSlot().getData("b")); + Assert.assertEquals("before_after", response.getSlot().getData("c")); + Assert.assertEquals("before_after", response.getSlot().getData("d")); + Assert.assertEquals("before_after", response.getSlot().getData("e")); + } + + @Test + public void testGlobalAopException() { + LiteflowResponse<DefaultSlot> response= flowExecutor.execute2Resp("chain3", "it's a request"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("before_after", response.getSlot().getData("a")); + Assert.assertEquals("before_after", response.getSlot().getData("b")); + Assert.assertEquals("before_after", response.getSlot().getData("c")); + Assert.assertEquals("before_after", response.getSlot().getData("f")); + } + + @AfterClass + public static void cleanScanCache(){ + BaseTest.cleanScanCache(); + ComponentScanner.cmpAroundAspect = null; + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/aspect/CmpAspect.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/aspect/CmpAspect.java new file mode 100644 index 00000000..22a94daa --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/aspect/CmpAspect.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.aop.aspect; + +import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.aop.ICmpAroundAspect; +import com.yomahub.liteflow.entity.data.Slot; + +public class CmpAspect implements ICmpAroundAspect { + @Override + public void beforeProcess(String nodeId, Slot slot) { + slot.setData(nodeId, "before"); + } + + @Override + public void afterProcess(String nodeId, Slot slot) { + slot.setData(nodeId, StrUtil.format("{}_{}", slot.getData(nodeId), "after")); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/aspect/CustomAspect.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/aspect/CustomAspect.java new file mode 100644 index 00000000..50de54ca --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/aspect/CustomAspect.java @@ -0,0 +1,27 @@ +package com.yomahub.liteflow.test.aop.aspect; + +import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.Slot; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; + +@Aspect +public class CustomAspect { + + @Pointcut("execution(* com.yomahub.liteflow.test.aop.cmp1.*.process(*))") + public void cut() { + } + + @Around("cut()") + public Object around(ProceedingJoinPoint jp) throws Throwable { + NodeComponent cmp = (NodeComponent) jp.getThis(); + Slot slot = cmp.getSlot(); + slot.setData(cmp.getNodeId(), "before"); + Object returnObj = jp.proceed(); + slot.setData(cmp.getNodeId(), StrUtil.format("{}_{}", slot.getData(cmp.getNodeId()), "after")); + return returnObj; + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp1/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp1/ACmp.java new file mode 100644 index 00000000..8802336f --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp1/ACmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.aop.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("Acomp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp1/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp1/BCmp.java new file mode 100644 index 00000000..8b688aef --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp1/BCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.aop.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("Bcomp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp1/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp1/CCmp.java new file mode 100644 index 00000000..b8c52b50 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp1/CCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.aop.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("Ccomp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp2/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp2/DCmp.java new file mode 100644 index 00000000..ff4680e1 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp2/DCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.aop.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("d") +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("Dcomp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp2/ECmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp2/ECmp.java new file mode 100644 index 00000000..99db4df8 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp2/ECmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.aop.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("e") +@LiteflowCmpDefine +public class ECmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("Ecomp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp2/FCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp2/FCmp.java new file mode 100644 index 00000000..38b8971c --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp2/FCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.aop.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("f") +@LiteflowCmpDefine +public class FCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + throw new RuntimeException("test error"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeSpringbootTest.java new file mode 100644 index 00000000..b6cc97ca --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeSpringbootTest.java @@ -0,0 +1,134 @@ +package com.yomahub.liteflow.test.asyncNode; + +import cn.hutool.core.collection.ListUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import com.yomahub.liteflow.test.asyncNode.exception.TestException; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * 测试隐式调用子流程 + * 单元测试 + * + * @author ssss + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/asyncNode/application.properties") +@SpringBootTest(classes = AsyncNodeSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.asyncNode.cmp"}) +public class AsyncNodeSpringbootTest extends BaseTest { + @Resource + private FlowExecutor flowExecutor; + + /***** + * 标准chain 嵌套选择 嵌套子chain进行执行 + * 验证了when情况下 多个node是并行执行 + * 验证了默认参数情况下 when可以加载执行 + * **/ + @Test + public void testAsyncFlow1() { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "it's a base request"); + Assert.assertTrue(response.isSuccess()); + System.out.println(response.getSlot().getExecuteStepStr()); + } + + //这个和test1有点类似,只不过进一步验证了步骤 + @Test + public void testAsyncFlow2() { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain2", "it's a base request"); + Assert.assertTrue(ListUtil.toList("b==>j==>g==>f==>h","b==>j==>g==>h==>f", + "b==>j==>h==>g==>f","b==>j==>h==>f==>g", + "b==>j==>f==>h==>g","b==>j==>f==>g==>h" + ).contains(response.getSlot().getExecuteStepStr())); + } + + //测试errorResume,默认的errorResume为false,这里测试默认的 + @Test + public void testAsyncFlow3_1() { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain3-1", "it's a base request"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(response.getSlot().getException().getClass(), TestException.class); + } + + //测试errorResume,默认的errorResume为false,这里设置为true + @Test + public void testAsyncFlow3_2() { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain3-2", "it's a base request"); + Assert.assertTrue(response.isSuccess()); + } + + //相同group的并行组,会合并,并且errorResume根据第一个when来,这里第一个when配置了不抛错 + @Test + public void testAsyncFlow4() { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain4", "it's a base request"); + //因为不记录错误,所以最终结果是true + Assert.assertTrue(response.isSuccess()); + //因为是并行组,所以即便抛错了,其他组件也会执行,i在流程里配置了2遍,i抛错,但是也执行了2遍,这里验证下 + Integer count = response.getSlot().getData("count"); + Assert.assertEquals(new Integer(2), count); + //因为配置了不抛错,所以response里的cause应该为null + Assert.assertNull(response.getCause()); + } + + //相同group的并行组,会合并,并且errorResume根据第一个when来,这里第一个when配置了会抛错 + @Test + public void testAsyncFlow5() throws Exception { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain5", "it's a base request"); + //整个并行组是报错的,所以最终结果是false + Assert.assertFalse(response.isSuccess()); + //因为是并行组,所以即便抛错了,其他组件也会执行,i在流程里配置了2遍,i抛错,但是也执行了2遍,这里验证下 + Integer count = response.getSlot().getData("count"); + Assert.assertEquals(new Integer(2), count); + //因为第一个when配置了会报错,所以response里的cause里应该会有TestException + Assert.assertEquals(TestException.class, response.getCause().getClass()); + } + + //不同group的并行组,不会合并,第一个when的errorResume是false,会抛错,那第二个when就不会执行 + @Test + public void testAsyncFlow6() throws Exception { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain6", "it's a base request"); + //第一个when会抛错,所以最终结果是false + Assert.assertFalse(response.isSuccess()); + //因为是不同组并行组,第一组的when里的i就抛错了,所以i就执行了1遍 + Integer count = response.getSlot().getData("count"); + Assert.assertEquals(new Integer(1), count); + //第一个when会报错,所以最终response的cause里应该会有TestException + Assert.assertEquals(TestException.class, response.getCause().getClass()); + } + + //不同group的并行组,不会合并,第一个when的errorResume是true,不会报错,那第二个when还会继续执行,但是第二个when的errorResume是false,所以第二个when会报错 + @Test + public void testAsyncFlow7() throws Exception { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain7", "it's a base request"); + //第二个when会抛错,所以最终结果是false + Assert.assertFalse(response.isSuccess()); + // 传递了slotIndex,则set的size==2 + Integer count = response.getSlot().getData("count"); + Assert.assertEquals(new Integer(2), count); + //第一个when会报错,所以最终response的cause里应该会有TestException + Assert.assertEquals(TestException.class, response.getCause().getClass()); + } + + //测试任意异步一个执行完即继续的场景 + //d g h并行,配置了any=true,其中d耗时1秒,g耗时0.5秒,其他都不设耗时 + //最终执行效果应该是h先返回,然后执行abc,最后gd + //这里要注意的是,由于step是先加入,所以step的打印顺序并不是这样的。但是实际执行是正确的 + @Test + public void testAsyncFlow8() throws Exception { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain8", "it's a base request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertTrue(response.getSlot().getData("check").toString().startsWith("habc")); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ACmp.java new file mode 100644 index 00000000..21eac78b --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ACmp.java @@ -0,0 +1,28 @@ +package com.yomahub.liteflow.test.asyncNode.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + Slot slot = bindCmp.getSlot(); + synchronized (NodeComponent.class){ + if (slot.hasData("check")){ + String str = slot.getData("check"); + str += bindCmp.getNodeId(); + slot.setData("check", str); + }else{ + slot.setData("check", bindCmp.getNodeId()); + } + } + System.out.println("Acomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/BCmp.java new file mode 100644 index 00000000..2d3a1f21 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/BCmp.java @@ -0,0 +1,28 @@ +package com.yomahub.liteflow.test.asyncNode.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + Slot slot = bindCmp.getSlot(); + synchronized (NodeComponent.class){ + if (slot.hasData("check")){ + String str = slot.getData("check"); + str += bindCmp.getNodeId(); + slot.setData("check", str); + }else{ + slot.setData("check", bindCmp.getNodeId()); + } + } + System.out.println("Bcomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/CCmp.java new file mode 100644 index 00000000..3c79fe62 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/CCmp.java @@ -0,0 +1,28 @@ +package com.yomahub.liteflow.test.asyncNode.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + Slot slot = bindCmp.getSlot(); + synchronized (NodeComponent.class){ + if (slot.hasData("check")){ + String str = slot.getData("check"); + str += bindCmp.getNodeId(); + slot.setData("check", str); + }else{ + slot.setData("check", bindCmp.getNodeId()); + } + } + System.out.println("Ccomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/DCmp.java new file mode 100644 index 00000000..e96d0b9f --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/DCmp.java @@ -0,0 +1,29 @@ +package com.yomahub.liteflow.test.asyncNode.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + + +@Component("d") +@LiteflowCmpDefine +public class DCmp{ + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + Thread.sleep(1000); + Slot slot = bindCmp.getSlot(); + synchronized (NodeComponent.class){ + if (slot.hasData("check")){ + String str = slot.getData("check"); + str += bindCmp.getNodeId(); + slot.setData("check", str); + }else{ + slot.setData("check", bindCmp.getNodeId()); + } + } + System.out.println("Dcomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ECmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ECmp.java new file mode 100644 index 00000000..56869f5c --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ECmp.java @@ -0,0 +1,20 @@ +package com.yomahub.liteflow.test.asyncNode.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCondCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.core.NodeCondComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + + +@Component("e") +@LiteflowCondCmpDefine +public class ECmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS_COND) + public String processCond(NodeComponent bindCmp) throws Exception { + System.out.println("Ecomp executed!"); + return "g"; + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/FCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/FCmp.java new file mode 100644 index 00000000..83eac404 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/FCmp.java @@ -0,0 +1,18 @@ +package com.yomahub.liteflow.test.asyncNode.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + + +@Component("f") +@LiteflowCmpDefine +public class FCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + System.out.println("Fcomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/GCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/GCmp.java new file mode 100644 index 00000000..1a719d52 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/GCmp.java @@ -0,0 +1,30 @@ +package com.yomahub.liteflow.test.asyncNode.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + + +@Component("g") +@LiteflowCmpDefine +public class GCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + Thread.sleep(500); + Slot slot = bindCmp.getSlot(); + synchronized (NodeComponent.class){ + if (slot.hasData("check")){ + String str = slot.getData("check"); + str += bindCmp.getNodeId(); + slot.setData("check", str); + }else{ + slot.setData("check", bindCmp.getNodeId()); + } + } + System.out.println("Gcomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/HCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/HCmp.java new file mode 100644 index 00000000..b8ae6ce8 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/HCmp.java @@ -0,0 +1,30 @@ +package com.yomahub.liteflow.test.asyncNode.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + + +@Component("h") +@LiteflowCmpDefine +public class HCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + Slot slot = bindCmp.getSlot(); + synchronized (NodeComponent.class){ + if (slot.hasData("check")){ + String str = slot.getData("check"); + str += bindCmp.getNodeId(); + slot.setData("check", str); + }else{ + slot.setData("check", bindCmp.getNodeId()); + } + } + + System.out.println("Hcomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ICmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ICmp.java new file mode 100644 index 00000000..37937c23 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ICmp.java @@ -0,0 +1,28 @@ +package com.yomahub.liteflow.test.asyncNode.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.test.asyncNode.exception.TestException; +import org.springframework.stereotype.Component; + + +@Component("i") +@LiteflowCmpDefine +public class ICmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + Slot slot = bindCmp.getSlot(); + if (slot.hasData("count")){ + Integer count = slot.getData("count"); + slot.setData("count", ++count); + } else{ + slot.setData("count", 1); + } + System.out.println("Icomp executed! throw Exception!"); + throw new TestException(); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/JCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/JCmp.java new file mode 100644 index 00000000..48e19487 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/JCmp.java @@ -0,0 +1,21 @@ +package com.yomahub.liteflow.test.asyncNode.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowCondCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.core.NodeCondComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + + +@Component("j") +@LiteflowCondCmpDefine +public class JCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS_COND) + public String processCond(NodeComponent bindCmp) throws Exception { + System.out.println("Jcomp executed!"); + return "chain3"; + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/exception/TestException.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/exception/TestException.java new file mode 100644 index 00000000..e786e9f8 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/exception/TestException.java @@ -0,0 +1,4 @@ +package com.yomahub.liteflow.test.asyncNode.exception; + +public class TestException extends Exception{ +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/BaseSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/BaseSpringbootTest.java new file mode 100644 index 00000000..029d3a5c --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/BaseSpringbootTest.java @@ -0,0 +1,39 @@ +package com.yomahub.liteflow.test.base; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * springboot环境最普通的例子测试 + * @author Bryan.Zhang + * @since 2.6.4 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/base/application.properties") +@SpringBootTest(classes = BaseSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.base.cmp"}) +public class BaseSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testBase() throws Exception{ + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/ACmp.java new file mode 100644 index 00000000..d192c24a --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/ACmp.java @@ -0,0 +1,24 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.base.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/BCmp.java new file mode 100644 index 00000000..0f29823c --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.base.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/CCmp.java new file mode 100644 index 00000000..d147a02c --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.base.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/DCmp.java new file mode 100644 index 00000000..937c79b9 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/DCmp.java @@ -0,0 +1,31 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.base.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +@Component("d") +@LiteflowCmpDefine +public class DCmp{ + + @Resource + private TestDomain testDomain; + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + testDomain.sayHi(); + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/TestDomain.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/TestDomain.java new file mode 100644 index 00000000..16f15932 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/TestDomain.java @@ -0,0 +1,10 @@ +package com.yomahub.liteflow.test.base.cmp; + +import org.springframework.stereotype.Component; + +@Component +public class TestDomain { + public void sayHi(){ + System.out.println("hello"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/BuilderSpringbootTest1.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/BuilderSpringbootTest1.java new file mode 100644 index 00000000..55f4011c --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/BuilderSpringbootTest1.java @@ -0,0 +1,217 @@ +package com.yomahub.liteflow.test.builder; + +import com.yomahub.liteflow.builder.LiteFlowChainBuilder; +import com.yomahub.liteflow.builder.LiteFlowConditionBuilder; +import com.yomahub.liteflow.builder.LiteFlowNodeBuilder; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.ExecutableEntity; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.enums.NodeTypeEnum; +import com.yomahub.liteflow.test.BaseTest; +import com.yomahub.liteflow.test.builder.cmp1.*; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +//基于builder模式的单元测试 +//这里只是最基本的builder模式的测试,只是为了验证在springboot模式下的正常性 +//更详细的builder模式测试用例会单独拉testcase去做 +@RunWith(SpringRunner.class) +@SpringBootTest(classes = BuilderSpringbootTest1.class) +@EnableAutoConfiguration +public class BuilderSpringbootTest1 extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //基于普通组件的builder模式测试 + @Test + public void testBuilder() throws Exception { + LiteFlowNodeBuilder.createNode().setId("a") + .setName("组件A") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.ACmp") + .build(); + LiteFlowNodeBuilder.createNode().setId("b") + .setName("组件B") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.BCmp") + .build(); + LiteFlowNodeBuilder.createNode().setId("c") + .setName("组件C") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.CCmp") + .build(); + LiteFlowNodeBuilder.createNode().setId("d") + .setName("组件D") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.DCmp") + .build(); + LiteFlowNodeBuilder.createNode().setId("e") + .setName("组件E") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.ECmp") + .build(); + LiteFlowNodeBuilder.createNode().setId("f") + .setName("组件F") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.FCmp") + .build(); + LiteFlowNodeBuilder.createNode().setId("g") + .setName("组件G") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.GCmp") + .build(); + + + LiteFlowChainBuilder.createChain().setChainName("chain2").setCondition( + LiteFlowConditionBuilder.createThenCondition().setValue("c,d").build() + ).build(); + + LiteFlowChainBuilder.createChain().setChainName("chain1").setCondition( + LiteFlowConditionBuilder + .createThenCondition() + .setValue("a,b").build() + ).setCondition( + LiteFlowConditionBuilder.createWhenCondition() + .setValue("e(f|g|chain2)").build() + ).build(); + + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a[组件A]==>b[组件B]==>e[组件E]==>c[组件C]==>d[组件D]", response.getSlot().getExecuteStepStr()); + } + + //基于普通组件的builder模式测试 + @Test + public void testBuilderForClassAndCode() throws Exception { + LiteFlowNodeBuilder.createNode().setId("a") + .setName("组件A") + .setTypeCode(NodeTypeEnum.COMMON.getCode()) + .setClazz(ACmp.class) + .build(); + LiteFlowNodeBuilder.createNode().setId("b") + .setName("组件B") + .setTypeCode(NodeTypeEnum.COMMON.getCode()) + .setClazz(BCmp.class) + .build(); + LiteFlowNodeBuilder.createNode().setId("c") + .setName("组件C") + .setTypeCode(NodeTypeEnum.COMMON.getCode()) + .setClazz(CCmp.class) + .build(); + LiteFlowNodeBuilder.createNode().setId("d") + .setName("组件D") + .setTypeCode(NodeTypeEnum.COMMON.getCode()) + .setClazz(DCmp.class) + .build(); + LiteFlowNodeBuilder.createNode().setId("e") + .setName("组件E") + .setTypeCode(NodeTypeEnum.COMMON.getCode()) + .setClazz(ECmp.class) + .build(); + LiteFlowNodeBuilder.createNode().setId("f") + .setName("组件F") + .setTypeCode(NodeTypeEnum.COMMON.getCode()) + .setClazz(FCmp.class) + .build(); + LiteFlowNodeBuilder.createNode().setId("g") + .setName("组件G") + .setTypeCode(NodeTypeEnum.COMMON.getCode()) + .setClazz(GCmp.class) + .build(); + + + LiteFlowChainBuilder.createChain().setChainName("chain2").setCondition( + LiteFlowConditionBuilder.createThenCondition().setValue("c,d").build() + ).build(); + + LiteFlowChainBuilder.createChain().setChainName("chain1").setCondition( + LiteFlowConditionBuilder + .createThenCondition() + .setValue("a,b").build() + ).setCondition( + LiteFlowConditionBuilder.createWhenCondition() + .setValue("e(f|g|chain2)").build() + ).build(); + + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a[组件A]==>b[组件B]==>e[组件E]==>c[组件C]==>d[组件D]", response.getSlot().getExecuteStepStr()); + } + + + //基于普通组件的builder模式测试 + @Test + public void testBuilderForConditionNode() throws Exception { + LiteFlowNodeBuilder.createNode().setId("a") + .setName("组件A") + .setTypeCode(NodeTypeEnum.COMMON.getCode()) + .setClazz(ACmp.class) + .build(); + LiteFlowNodeBuilder.createNode().setId("b") + .setName("组件B") + .setTypeCode(NodeTypeEnum.COMMON.getCode()) + .setClazz(BCmp.class) + .build(); + LiteFlowNodeBuilder.createNode().setId("c") + .setName("组件C") + .setTypeCode(NodeTypeEnum.COMMON.getCode()) + .setClazz(CCmp.class) + .build(); + LiteFlowNodeBuilder.createNode().setId("d") + .setName("组件D") + .setTypeCode(NodeTypeEnum.COMMON.getCode()) + .setClazz(DCmp.class) + .build(); + LiteFlowNodeBuilder.createNode().setId("e") + .setName("组件E") + .setTypeCode(NodeTypeEnum.COMMON.getCode()) + .setClazz(ECmp.class) + .build(); + LiteFlowNodeBuilder.createNode().setId("f") + .setName("组件F") + .setTypeCode(NodeTypeEnum.COMMON.getCode()) + .setClazz(FCmp.class) + .build(); + LiteFlowNodeBuilder.createNode().setId("g") + .setName("组件G") + .setTypeCode(NodeTypeEnum.COMMON.getCode()) + .setClazz(GCmp.class) + .build(); + + + LiteFlowChainBuilder.createChain().setChainName("chain2").setCondition( + LiteFlowConditionBuilder.createThenCondition() + .setExecutable(new ExecutableEntity().setId("c")) + .setExecutable(new ExecutableEntity().setId("d")) + .build() + ).build(); + + LiteFlowChainBuilder.createChain().setChainName("chain1").setCondition( + LiteFlowConditionBuilder + .createThenCondition() + .setExecutable(new ExecutableEntity().setId("a").setTag("hello")) + .setExecutable(new ExecutableEntity().setId("b")) + .build() + ).setCondition( + LiteFlowConditionBuilder.createWhenCondition() + .setExecutable( + new ExecutableEntity().setId("e") + .addNodeCondComponent(new ExecutableEntity().setId("f").setTag("FHello")) + .addNodeCondComponent(new ExecutableEntity().setId("g")) + .addNodeCondComponent(new ExecutableEntity().setId("chain2") + )).build() + ).build(); + + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a[组件A]==>b[组件B]==>e[组件E]==>c[组件C]==>d[组件D]", response.getSlot().getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/BuilderSpringbootTest2.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/BuilderSpringbootTest2.java new file mode 100644 index 00000000..d412674c --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/BuilderSpringbootTest2.java @@ -0,0 +1,41 @@ +package com.yomahub.liteflow.test.builder; + +import com.yomahub.liteflow.builder.LiteFlowChainBuilder; +import com.yomahub.liteflow.builder.LiteFlowConditionBuilder; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +//基于builder模式的单元测试 +//这里测试的是通过spring去扫描,但是通过代码去构建chain的用例 +@RunWith(SpringRunner.class) +@SpringBootTest(classes = BuilderSpringbootTest2.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.builder.cmp2"}) +public class BuilderSpringbootTest2 extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //通过spring去扫描组件,通过代码去构建chain + @Test + public void testBuilder() throws Exception { + LiteFlowChainBuilder.createChain().setChainName("chain1").setCondition( + LiteFlowConditionBuilder.createThenCondition().setValue("h,i,j").build() + ).build(); + + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("h==>i==>j", response.getSlot().getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ACmp.java new file mode 100644 index 00000000..a9ffd1f0 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ACmp.java @@ -0,0 +1,22 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.builder.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/BCmp.java new file mode 100644 index 00000000..e13b0434 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/BCmp.java @@ -0,0 +1,23 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.builder.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/CCmp.java new file mode 100644 index 00000000..6fbbc10e --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/CCmp.java @@ -0,0 +1,23 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.builder.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/DCmp.java new file mode 100644 index 00000000..27fb0fd4 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/DCmp.java @@ -0,0 +1,23 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.builder.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("DCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ECmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ECmp.java new file mode 100644 index 00000000..3fbb2dac --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ECmp.java @@ -0,0 +1,24 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.builder.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCondCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowCondCmpDefine +public class ECmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS_COND) + public String processCond(NodeComponent bindCmp) throws Exception { + System.out.println("ECmp executed!"); + return "chain2"; + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/FCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/FCmp.java new file mode 100644 index 00000000..a300c50f --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/FCmp.java @@ -0,0 +1,23 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.builder.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowCmpDefine +public class FCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("FCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/GCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/GCmp.java new file mode 100644 index 00000000..4035e89c --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/GCmp.java @@ -0,0 +1,23 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.builder.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowCmpDefine +public class GCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("GCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp2/HCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp2/HCmp.java new file mode 100644 index 00000000..a3bd495a --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp2/HCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.builder.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("h") +@LiteflowCmpDefine +public class HCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("HCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp2/ICmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp2/ICmp.java new file mode 100644 index 00000000..a7546b33 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp2/ICmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.builder.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("i") +@LiteflowCmpDefine +public class ICmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ICmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp2/JCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp2/JCmp.java new file mode 100644 index 00000000..a270fc3c --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp2/JCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.builder.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("j") +@LiteflowCmpDefine +public class JCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("JCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetrySpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetrySpringbootTest.java new file mode 100644 index 00000000..d744c69b --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetrySpringbootTest.java @@ -0,0 +1,64 @@ +package com.yomahub.liteflow.test.cmpRetry; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + + +/** + * 测试springboot下的节点执行器 + * @author Bryan.Zhang + * @since 2.5.10 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/cmpRetry/application.properties") +@SpringBootTest(classes = LiteflowRetrySpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.cmpRetry.cmp"}) +public class LiteflowRetrySpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //全局重试配置测试 + @Test + public void testRetry1() { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>b==>b", response.getSlot().getExecuteStepStr()); + } + + //单个组件重试配置测试 + @Test + public void testRetry2() { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("c==>c==>c==>c==>c==>c", response.getSlot().getExecuteStepStr()); + } + + //单个组件指定异常,但抛出的并不是指定异常的场景测试 + @Test + public void testRetry3() { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertFalse(response.isSuccess()); + } + + //单个组件指定异常重试,抛出的是指定异常或者 + @Test + public void testRetry4() { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("e==>e==>e==>e==>e==>e", response.getSlot().getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ACmp.java new file mode 100644 index 00000000..2bd62629 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ACmp.java @@ -0,0 +1,24 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.cmpRetry.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/BCmp.java new file mode 100644 index 00000000..9107e238 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/BCmp.java @@ -0,0 +1,31 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.cmpRetry.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("b") +@LiteflowCmpDefine +public class BCmp { + + private int flag = 0; + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + if (flag < 2){ + flag++; + throw new RuntimeException("demo exception"); + } + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/CCmp.java new file mode 100644 index 00000000..05ea10fd --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/CCmp.java @@ -0,0 +1,28 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.cmpRetry.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.annotation.LiteflowRetry; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("c") +@LiteflowRetry(5) +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + throw new RuntimeException("demo exception"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/DCmp.java new file mode 100644 index 00000000..c3d21e72 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/DCmp.java @@ -0,0 +1,28 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.cmpRetry.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.annotation.LiteflowRetry; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("d") +@LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class}) +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("DCmp executed!"); + throw new RuntimeException("demo exception"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ECmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ECmp.java new file mode 100644 index 00000000..f33b4ca6 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ECmp.java @@ -0,0 +1,28 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.cmpRetry.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.annotation.LiteflowRetry; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("e") +@LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class}) +@LiteflowCmpDefine +public class ECmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ECmp executed!"); + throw new NullPointerException("demo null exception"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorSpringbootTest.java new file mode 100644 index 00000000..140cffe6 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorSpringbootTest.java @@ -0,0 +1,94 @@ +package com.yomahub.liteflow.test.component; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.util.ReflectionUtils; + +import javax.annotation.Resource; + +/** + * 组件功能点测试 + * 单元测试 + * + * @author donguo.tao + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/component/application.properties") +@SpringBootTest(classes = FlowExecutorSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.component.cmp1","com.yomahub.liteflow.test.component.cmp2"}) +public class FlowExecutorSpringbootTest extends BaseTest { + private static final Logger LOG = LoggerFactory.getLogger(FlowExecutorSpringbootTest.class); + + @Resource + private FlowExecutor flowExecutor; + + //isAccess方法的功能测试 + @Test + public void testIsAccess() { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", 101); + Assert.assertTrue(response.isSuccess()); + Assert.assertNotNull(response.getSlot().getResponseData()); + } + + //组件抛错的功能点测试 + @Test(expected = ArithmeticException.class) + public void testComponentException() throws Exception { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain2", 0); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("/ by zero", response.getMessage()); + ReflectionUtils.rethrowException(response.getCause()); + } + + //isContinueOnError方法的功能点测试 + @Test + public void testIsContinueOnError() throws Exception { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain3", 0); + Assert.assertTrue(response.isSuccess()); + Assert.assertNull(response.getCause()); + } + + //isEnd方法的功能点测试 + @Test + public void testIsEnd() throws Exception { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain4", 10); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("d",response.getSlot().getExecuteStepStr()); + } + + //setIsEnd方法的功能点测试 + @Test + public void testSetIsEnd1() throws Exception { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain5", 10); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("e",response.getSlot().getExecuteStepStr()); + } + + //条件组件的功能点测试 + @Test + public void testNodeCondComponent() { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain6", 0); + Assert.assertTrue(response.isSuccess()); + } + + //测试setIsEnd如果为true,continueError也为true,那不应该continue了 + @Test + public void testSetIsEnd2() throws Exception { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain7", 10); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("g",response.getSlot().getExecuteStepStr()); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/ACmp.java new file mode 100644 index 00000000..25012ae4 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/ACmp.java @@ -0,0 +1,30 @@ +package com.yomahub.liteflow.test.component.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +import java.util.Objects; + + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("AComp executed!"); + bindCmp.getSlot().setResponseData("AComp executed!"); + } + + @LiteflowMethod(LiteFlowMethodEnum.IS_ACCESS) + public boolean isAccess(NodeComponent bindCmp) { + Integer requestData = bindCmp.getSlot().getRequestData(); + if (Objects.nonNull(requestData) && requestData > 100){ + return true; + } + System.out.println("AComp isAccess false."); + return false; + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/BCmp.java new file mode 100644 index 00000000..832060c0 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/BCmp.java @@ -0,0 +1,33 @@ +package com.yomahub.liteflow.test.component.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +import java.util.Objects; + + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BComp executed!"); + Integer requestData = bindCmp.getSlot().getRequestData(); + Integer divisor = 130; + Integer result = divisor / requestData; + bindCmp.getSlot().setResponseData(result); + } + + @LiteflowMethod(LiteFlowMethodEnum.IS_ACCESS) + public boolean isAccess(NodeComponent bindCmp) { + Integer requestData = bindCmp.getSlot().getRequestData(); + if (Objects.nonNull(requestData)){ + return true; + } + return false; + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/CCmp.java new file mode 100644 index 00000000..c741a1ec --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/CCmp.java @@ -0,0 +1,33 @@ +package com.yomahub.liteflow.test.component.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +import java.util.Objects; + + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CComp executed!"); + Integer requestData = bindCmp.getSlot().getRequestData(); + Integer divisor = 130; + Integer result = divisor / requestData; + bindCmp.getSlot().setResponseData(result); + System.out.println("responseData="+Integer.parseInt(bindCmp.getSlot().getResponseData())); + } + + @LiteflowMethod(LiteFlowMethodEnum.IS_CONTINUE_ON_ERROR) + public boolean isContinueOnError(NodeComponent bindCmp) { + Integer requestData = bindCmp.getSlot().getRequestData(); + if (Objects.nonNull(requestData)){ + return true; + } + return false; + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/DCmp.java new file mode 100644 index 00000000..96253f09 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/DCmp.java @@ -0,0 +1,30 @@ +package com.yomahub.liteflow.test.component.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +import java.util.Objects; + + +@Component("d") +@LiteflowCmpDefine +public class DCmp{ + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + System.out.println("DComp executed!"); + } + + @LiteflowMethod(LiteFlowMethodEnum.IS_END) + public boolean isEnd(NodeComponent bindCmp) { + //组件的process执行完之后才会执行isEnd + Object requestData = bindCmp.getSlot().getResponseData(); + if (Objects.isNull(requestData)){ + System.out.println("DComp flow isEnd, because of responseData is null."); + return true; + } + return false; + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/ECmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/ECmp.java new file mode 100644 index 00000000..7a509924 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/ECmp.java @@ -0,0 +1,28 @@ +package com.yomahub.liteflow.test.component.cmp1; + +import com.alibaba.fastjson.JSON; +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +import java.util.Objects; + + +@Component("e") +@LiteflowCmpDefine +public class ECmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + System.out.println("EComp executed!"); + Object responseData = bindCmp.getSlot().getResponseData(); + if (Objects.isNull(responseData)){ + System.out.println("EComp responseData flow must be set end ."); + //执行到某个条件时,手动结束流程。 + bindCmp.setIsEnd(true); + } + System.out.println("EComp responseData responseData=" + JSON.toJSONString(responseData)); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/GCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/GCmp.java new file mode 100644 index 00000000..ebfd97d2 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/GCmp.java @@ -0,0 +1,30 @@ +/** + * <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.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("g") +@LiteflowCmpDefine +public class GCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("GCmp executed!"); + bindCmp.setIsEnd(true); + } + + @LiteflowMethod(LiteFlowMethodEnum.IS_CONTINUE_ON_ERROR) + public boolean isContinueOnError(NodeComponent bindCmp) { + return true; + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/HCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/HCmp.java new file mode 100644 index 00000000..c2a30d0a --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/HCmp.java @@ -0,0 +1,24 @@ +/** + * <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.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("h") +@LiteflowCmpDefine +public class HCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("HCmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp2/FCondCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp2/FCondCmp.java new file mode 100644 index 00000000..360e02cb --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp2/FCondCmp.java @@ -0,0 +1,27 @@ +package com.yomahub.liteflow.test.component.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowCondCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.core.NodeCondComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +import java.util.Objects; + + +@Component("f") +@LiteflowCondCmpDefine +public class FCondCmp{ + @LiteflowMethod(LiteFlowMethodEnum.PROCESS_COND) + public String processCond(NodeComponent bindCmp) { + Integer requestData = bindCmp.getSlot().getRequestData(); + if (Objects.isNull(requestData)){ + return "d"; + } else if(requestData == 0){ + return "c"; + } else { + return "b"; + } + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesSpringbootTest.java new file mode 100644 index 00000000..ec49601a --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesSpringbootTest.java @@ -0,0 +1,45 @@ +package com.yomahub.liteflow.test.customNodes; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * springboot环境下自定义声明节点的测试 + * 不通过spring扫描的方式,通过在配置文件里定义nodes的方式 + * @author Bryan.Zhang + * @since 2.6.4 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/customNodes/application.properties") +@SpringBootTest(classes = CustomNodesSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.customNodes.domain"}) +public class CustomNodesSpringbootTest extends BaseTest { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testCustomNodes() throws Exception{ + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ACmp.java new file mode 100644 index 00000000..fb8982c2 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ACmp.java @@ -0,0 +1,22 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.customNodes.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/BCmp.java new file mode 100644 index 00000000..67ed16bc --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/BCmp.java @@ -0,0 +1,29 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.customNodes.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.test.customNodes.domain.DemoDomain; + +import javax.annotation.Resource; + +@LiteflowCmpDefine +public class BCmp{ + + @Resource + private DemoDomain demoDomain; + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + demoDomain.sayHi(); + System.out.println("BCmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/CCmp.java new file mode 100644 index 00000000..d4ee3cf1 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/CCmp.java @@ -0,0 +1,23 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.customNodes.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/DCmp.java new file mode 100644 index 00000000..619905b1 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/DCmp.java @@ -0,0 +1,23 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.customNodes.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("DCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ECmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ECmp.java new file mode 100644 index 00000000..27b3243c --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ECmp.java @@ -0,0 +1,30 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.customNodes.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.test.customNodes.domain.DemoDomain; + +import javax.annotation.Resource; + +@LiteflowCmpDefine +public class ECmp{ + + @Resource + private DemoDomain demoDomain; + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + demoDomain.sayHi(); + System.out.println("ECmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/FCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/FCmp.java new file mode 100644 index 00000000..a7f22de9 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/FCmp.java @@ -0,0 +1,23 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.customNodes.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowCmpDefine +public class FCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("FCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/domain/DemoDomain.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/domain/DemoDomain.java new file mode 100644 index 00000000..d0b10dc0 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/domain/DemoDomain.java @@ -0,0 +1,11 @@ +package com.yomahub.liteflow.test.customNodes.domain; + +import org.springframework.stereotype.Component; + +@Component +public class DemoDomain { + + public void sayHi(){ + System.out.println("hi"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java new file mode 100644 index 00000000..6f88c4cd --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java @@ -0,0 +1,25 @@ +package com.yomahub.liteflow.test.customWhenThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomThreadExecutor1 implements ExecutorBuilder { + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + //只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor( + liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenQueueLimit(), + "customer-when-1-thead-"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java new file mode 100644 index 00000000..7d45e4ad --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java @@ -0,0 +1,24 @@ +package com.yomahub.liteflow.test.customWhenThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomThreadExecutor2 implements ExecutorBuilder { + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + //只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor( + liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenQueueLimit(), + "customer-when-2-thead-"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java new file mode 100644 index 00000000..875dc3d1 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java @@ -0,0 +1,24 @@ +package com.yomahub.liteflow.test.customWhenThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomThreadExecutor3 implements ExecutorBuilder { + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + //只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor( + liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenQueueLimit(), + "customer-when-3-thead-"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolSpringbootTest.java new file mode 100644 index 00000000..b21eed76 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolSpringbootTest.java @@ -0,0 +1,72 @@ +package com.yomahub.liteflow.test.customWhenThreadPool; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * springboot环境下异步线程超时日志打印测试 + * + * @author Bryan.Zhang + * @since 2.6.4 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/customWhenThreadPool/application.properties") +@SpringBootTest(classes = CustomWhenThreadPoolSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.customWhenThreadPool.cmp"}) +public class CustomWhenThreadPoolSpringbootTest extends BaseTest { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Resource + private FlowExecutor flowExecutor; + + /** + * 测试全局线程池配置 + */ + @Test + public void testGlobalThreadPool() { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertTrue(response.getSlot().getData("threadName").toString().startsWith("lf-when-thead")); + } + + /** + * 测试全局和when上自定义线程池-优先以when上为准 + */ + @Test + public void testGlobalAndCustomWhenThreadPool() { + LiteflowResponse<DefaultSlot> response1 = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response1.isSuccess()); + Assert.assertTrue(response1.getSlot().getData("threadName").toString().startsWith("customer-when-1-thead")); + } + + + /** + * when配置的线程池可以共用 + */ + @Test + public void testCustomWhenThreadPool() { + // 使用when - thread1 + testGlobalAndCustomWhenThreadPool(); + // chain配置同一个thead1 + LiteflowResponse<DefaultSlot> response2 = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response2.isSuccess()); + Assert.assertTrue(response2.getSlot().getData("threadName").toString().startsWith("customer-when-1-thead")); + + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ACmp.java new file mode 100644 index 00000000..ebe0cbf5 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ACmp.java @@ -0,0 +1,24 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.customWhenThreadPool.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/BCmp.java new file mode 100644 index 00000000..2a00fb1a --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/BCmp.java @@ -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.customWhenThreadPool.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + bindCmp.getSlot().setData("threadName", Thread.currentThread().getName()); + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/CCmp.java new file mode 100644 index 00000000..1a85ad0c --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/CCmp.java @@ -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.customWhenThreadPool.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + bindCmp.getSlot().setData("threadName", Thread.currentThread().getName()); + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/DCmp.java new file mode 100644 index 00000000..d5b9f6ce --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/DCmp.java @@ -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.customWhenThreadPool.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("d") +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + bindCmp.getSlot().setData("threadName", Thread.currentThread().getName()); + System.out.println("DCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ECmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ECmp.java new file mode 100644 index 00000000..c9bac33b --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ECmp.java @@ -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.customWhenThreadPool.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("e") +@LiteflowCmpDefine +public class ECmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + bindCmp.getSlot().setData("threadName", Thread.currentThread().getName()); + System.out.println("ECmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/FCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/FCmp.java new file mode 100644 index 00000000..552ea97a --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/FCmp.java @@ -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.customWhenThreadPool.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("f") +@LiteflowCmpDefine +public class FCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + bindCmp.getSlot().setData("threadName", Thread.currentThread().getName()); + System.out.println("FCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/ExceptionSpringBootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/ExceptionSpringBootTest.java new file mode 100644 index 00000000..de1c3a28 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/ExceptionSpringBootTest.java @@ -0,0 +1,83 @@ +package com.yomahub.liteflow.test.exception; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.exception.ChainNotFoundException; +import com.yomahub.liteflow.exception.ConfigErrorException; +import com.yomahub.liteflow.exception.FlowExecutorNotInitException; +import com.yomahub.liteflow.exception.FlowSystemException; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.util.ReflectionUtils; + +import javax.annotation.Resource; + +/** + * 流程执行异常 + * 单元测试 + * + * @author zendwang + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/exception/application.properties") +@SpringBootTest(classes = ExceptionSpringBootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.exception.cmp"}) +public class ExceptionSpringBootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Autowired + private ApplicationContext context; + + @Test(expected = ConfigErrorException.class) + public void testConfigErrorException() { + flowExecutor.setLiteflowConfig(null); + flowExecutor.init(); + } + + @Test(expected = FlowExecutorNotInitException.class) + public void testFlowExecutorNotInitException() { + LiteflowConfig config = context.getBean(LiteflowConfig.class); + config.setRuleSource("error/flow.txt"); + flowExecutor.init(); + } + + @Test(expected = ChainNotFoundException.class) + public void testChainNotFoundException() throws Exception { + flowExecutor.execute("chain0", "it's a request"); + } + + @Test(expected = RuntimeException.class) + public void testComponentCustomException() throws Exception { + flowExecutor.execute("chain1", "exception"); + } + + @Test(expected = FlowSystemException.class) + public void testNoConditionInChainException() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "test"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("no conditionList in this chain[chain2]", response.getMessage()); + ReflectionUtils.rethrowException(response.getCause()); + } + + @Test + public void testGetSlotFromResponseWhenException() throws Exception{ + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain4", "test"); + Assert.assertFalse(response.isSuccess()); + Assert.assertNotNull(response.getCause()); + Assert.assertNotNull(response.getSlot()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/ACmp.java new file mode 100644 index 00000000..21523bf9 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/ACmp.java @@ -0,0 +1,34 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.exception.cmp; + +import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + private static final Logger LOG = LoggerFactory.getLogger(ACmp.class); + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + String str = bindCmp.getSlot().getRequestData(); + if(StrUtil.isNotBlank(str) && str.equals("exception")) { + throw new RuntimeException("chain execute execption"); + } + LOG.info("Acomp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/BCmp.java new file mode 100644 index 00000000..5ec0f8b0 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/BCmp.java @@ -0,0 +1,39 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.exception.cmp; + +import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + private static final Logger LOG = LoggerFactory.getLogger(BCmp.class); + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws InterruptedException { + String str = bindCmp.getSlot().getRequestData(); + if(StrUtil.isNotBlank(str) && str.equals("when")) { + try { + LOG.info("Bcomp sleep begin"); + Thread.sleep(3000); + LOG.info("Bcomp sleep end"); + } catch (InterruptedException e) { + throw e; + } + } + LOG.info("Bcomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/CCmp.java new file mode 100644 index 00000000..4e4b4e25 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/CCmp.java @@ -0,0 +1,28 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.exception.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + private static final Logger LOG = LoggerFactory.getLogger(CCmp.class); + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + LOG.info("Ccomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/DCmp.java new file mode 100644 index 00000000..6da4fe9a --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/DCmp.java @@ -0,0 +1,31 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.exception.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +@Component("d") +@LiteflowCmpDefine +public class DCmp{ + + private static final Logger LOG = LoggerFactory.getLogger(DCmp.class); + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + if(1==1){ + int a = 1/0; + } + LOG.info("Dcomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureSpringbootTest.java new file mode 100644 index 00000000..d2460105 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureSpringbootTest.java @@ -0,0 +1,41 @@ +package com.yomahub.liteflow.test.execute2Future; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; +import java.util.concurrent.Future; + +/** + * springboot环境执行返回future的例子 + * @author Bryan.Zhang + * @since 2.6.13 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/execute2Future/application.properties") +@SpringBootTest(classes = Executor2FutureSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.execute2Future.cmp"}) +public class Executor2FutureSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testFuture() throws Exception{ + Future<LiteflowResponse<DefaultSlot>> future = flowExecutor.execute2Future("chain1", "arg", DefaultSlot.class); + LiteflowResponse<DefaultSlot> response = future.get(); + Assert.assertTrue(response.isSuccess()); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/ACmp.java new file mode 100644 index 00000000..a46e144e --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/ACmp.java @@ -0,0 +1,24 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.execute2Future.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/BCmp.java new file mode 100644 index 00000000..2678f255 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.execute2Future.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/CCmp.java new file mode 100644 index 00000000..a3ca40a8 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.execute2Future.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/DCmp.java new file mode 100644 index 00000000..12161982 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/DCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.execute2Future.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("d") +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/FlowMetaSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/FlowMetaSpringbootTest.java new file mode 100644 index 00000000..5e7ed572 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/FlowMetaSpringbootTest.java @@ -0,0 +1,38 @@ +package com.yomahub.liteflow.test.flowmeta; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.flow.FlowBus; +import com.yomahub.liteflow.test.BaseTest; +import com.yomahub.liteflow.test.flowmeta.cmp2.DCmp; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/flowmeta/application.properties") +@SpringBootTest(classes = FlowMetaSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.flowmeta.cmp1"}) +public class FlowMetaSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试动态添加元信息节点 + @Test + public void testFlowMeta() { + FlowBus.addCommonNode("d", "d组件", DCmp.class.getName()); + LiteflowResponse<DefaultSlot> response= flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>d[d组件]", response.getSlot().getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp1/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp1/ACmp.java new file mode 100644 index 00000000..4c315157 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp1/ACmp.java @@ -0,0 +1,24 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.flowmeta.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp1/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp1/BCmp.java new file mode 100644 index 00000000..134185ae --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp1/BCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.flowmeta.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp1/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp1/CCmp.java new file mode 100644 index 00000000..30c3f8bf --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp1/CCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.flowmeta.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp2/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp2/DCmp.java new file mode 100644 index 00000000..260ad809 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp2/DCmp.java @@ -0,0 +1,23 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.flowmeta.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("Dcomp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/LazySpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/LazySpringbootTest.java new file mode 100644 index 00000000..6e350021 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/LazySpringbootTest.java @@ -0,0 +1,33 @@ +package com.yomahub.liteflow.test.lazy; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/lazy/application.properties") +@SpringBootTest(classes = LazySpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.lazy.cmp"}) +public class LazySpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testLazy() throws Exception{ + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/cmp/ACmp.java new file mode 100644 index 00000000..01a43e2a --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/cmp/ACmp.java @@ -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.lazy.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Component; + +@Lazy +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/cmp/BCmp.java new file mode 100644 index 00000000..628760c6 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.lazy.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/cmp/CCmp.java new file mode 100644 index 00000000..781d1a20 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.lazy.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/LiteflowComponentSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/LiteflowComponentSpringbootTest.java new file mode 100644 index 00000000..954bee88 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/LiteflowComponentSpringbootTest.java @@ -0,0 +1,39 @@ +package com.yomahub.liteflow.test.liteflowcomponent; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + + +/** + * 测试@LiteflowComponent标注 + * @author Bryan.Zhang + * @since 2.5.10 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/liteflowComponent/application.properties") +@SpringBootTest(classes = LiteflowComponentSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.liteflowComponent.cmp"}) +public class LiteflowComponentSpringbootTest extends BaseTest { + + @Autowired + private FlowExecutor flowExecutor; + + @Test + public void testConfig() { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a[A组件]==>b[B组件]==>c[C组件]==>b[B组件]==>a[A组件]==>d", response.getSlot().getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/ACmp.java new file mode 100644 index 00000000..cbb4d438 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/ACmp.java @@ -0,0 +1,24 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.liteflowcomponent.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent(id = "a", name = "A组件") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/BCmp.java new file mode 100644 index 00000000..dfab6f34 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.liteflowcomponent.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent(id = "b", name = "B组件") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/CCmp.java new file mode 100644 index 00000000..1f4fdd22 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.liteflowcomponent.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent(id = "c", name = "C组件") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/DCmp.java new file mode 100644 index 00000000..9f338fa0 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/DCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.liteflowcomponent.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("d") +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("DCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/MonitorSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/MonitorSpringbootTest.java new file mode 100644 index 00000000..11147d10 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/MonitorSpringbootTest.java @@ -0,0 +1,50 @@ +package com.yomahub.liteflow.test.monitor; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.monitor.MonitorBus; +import com.yomahub.liteflow.spi.holder.ContextAwareHolder; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * springboot环境最普通的例子测试 + * @author Bryan.Zhang + * @since 2.6.4 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/monitor/application.properties") +@SpringBootTest(classes = MonitorSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.monitor.cmp"}) +public class MonitorSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testMonitor() throws Exception{ + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + + Thread.sleep(10000); + } + + @AfterClass + public static void clean(){ + MonitorBus monitorBus = ContextAwareHolder.loadContextAware().getBean(MonitorBus.class); + monitorBus.closeScheduler(); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/cmp/ACmp.java new file mode 100644 index 00000000..314ca078 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/cmp/ACmp.java @@ -0,0 +1,32 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.monitor.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +import java.util.Random; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + try { + Thread.sleep(new Random().nextInt(2000)); + }catch (Exception e){ + e.printStackTrace(); + } + + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/cmp/BCmp.java new file mode 100644 index 00000000..51d239b7 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/cmp/BCmp.java @@ -0,0 +1,32 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.monitor.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +import java.util.Random; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + try { + Thread.sleep(new Random().nextInt(2000)); + }catch (Exception e){ + e.printStackTrace(); + } + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/cmp/CCmp.java new file mode 100644 index 00000000..3d802e5e --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/cmp/CCmp.java @@ -0,0 +1,32 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.monitor.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +import java.util.Random; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + try { + Thread.sleep(new Random().nextInt(2000)); + }catch (Exception e){ + e.printStackTrace(); + } + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeSpringbootTest.java new file mode 100644 index 00000000..91ef144e --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeSpringbootTest.java @@ -0,0 +1,42 @@ +package com.yomahub.liteflow.test.multipleType; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + + +/** + * 测试springboot下混合格式规则的场景 + * @author Bryan.Zhang + * @since 2.5.10 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/multipleType/application.properties") +@SpringBootTest(classes = LiteflowMultipleTypeSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.multipleType.cmp"}) +public class LiteflowMultipleTypeSpringbootTest extends BaseTest { + + @Autowired + private FlowExecutor flowExecutor; + + @Test + public void testMultipleType() { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a", response.getSlot().getExecuteStepStr()); + response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c", response.getSlot().getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/ACmp.java new file mode 100644 index 00000000..31fb6b25 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/ACmp.java @@ -0,0 +1,24 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.multipleType.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/BCmp.java new file mode 100644 index 00000000..4f6b64df --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.multipleType.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/CCmp.java new file mode 100644 index 00000000..66dadb7e --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.multipleType.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerDefaultNodeExecutor.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerDefaultNodeExecutor.java new file mode 100644 index 00000000..84b60247 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerDefaultNodeExecutor.java @@ -0,0 +1,19 @@ +package com.yomahub.liteflow.test.nodeExecutor; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.DataBus; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.entity.executor.NodeExecutor; + +/** + * 自定义默认的节点执行器 + */ +public class CustomerDefaultNodeExecutor extends NodeExecutor { + @Override + public void execute(NodeComponent instance) throws Exception { + Slot slot = DataBus.getSlot(instance.getSlotIndex()); + LOG.info("使用customerDefaultNodeExecutor进行执行"); + slot.setData("customerDefaultNodeExecutor", this.getClass()); + super.execute(instance); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java new file mode 100644 index 00000000..247bc3d4 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java @@ -0,0 +1,20 @@ +package com.yomahub.liteflow.test.nodeExecutor; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.DataBus; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.entity.executor.NodeExecutor; + +/** + * 自定义节点执行器 + */ +public class CustomerNodeExecutor extends NodeExecutor { + @Override + public void execute(NodeComponent instance) throws Exception { + Slot slot = DataBus.getSlot(instance.getSlotIndex()); + LOG.info("使用customerNodeExecutor进行执行"); + slot.setData("customerNodeExecutor", this.getClass()); + super.execute(instance); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java new file mode 100644 index 00000000..46792852 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java @@ -0,0 +1,29 @@ +package com.yomahub.liteflow.test.nodeExecutor; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.DataBus; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.entity.executor.NodeExecutor; + +import java.util.concurrent.TimeUnit; + +/** + * 自定义节点执行器 + */ +public class CustomerNodeExecutorAndCustomRetry extends NodeExecutor { + @Override + public void execute(NodeComponent instance) throws Exception { + Slot slot = DataBus.getSlot(instance.getSlotIndex()); + LOG.info("使用customerNodeExecutorAndCustomRetry进行执行"); + slot.setData("customerNodeExecutorAndCustomRetry", this.getClass()); + super.execute(instance); + } + + @Override + protected void retry(NodeComponent instance, int currentRetryCount) throws Exception { + TimeUnit.MICROSECONDS.sleep(20L); + Slot slot = DataBus.getSlot(instance.getSlotIndex()); + slot.setData("retryLogic", this.getClass()); + super.retry(instance, currentRetryCount); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorSpringbootTest.java new file mode 100644 index 00000000..0c13bdad --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorSpringbootTest.java @@ -0,0 +1,69 @@ +package com.yomahub.liteflow.test.nodeExecutor; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + + +/** + * 测试springboot下的组件重试 + * + * @author Bryan.Zhang + * @since 2.5.10 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/nodeExecutor/application.properties") +@SpringBootTest(classes = LiteflowNodeExecutorSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.nodeExecutor.cmp"}) +public class LiteflowNodeExecutorSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + // 默认执行器测试 + @Test + public void testCustomerDefaultNodeExecutor() { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(CustomerDefaultNodeExecutor.class, response.getSlot().getData("customerDefaultNodeExecutor")); + Assert.assertEquals("a", response.getSlot().getExecuteStepStr()); + } + + //默认执行器测试+全局重试配置测试 + @Test + public void testDefaultExecutorForRetry() { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(CustomerDefaultNodeExecutor.class, response.getSlot().getData("customerDefaultNodeExecutor")); + Assert.assertEquals("b==>b==>b", response.getSlot().getExecuteStepStr()); + } + + //自定义执行器测试 + @Test + public void testCustomerExecutor() { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("c", response.getSlot().getExecuteStepStr()); + } + + //自定义执行器测试+全局重试配置测试 + @Test + public void testCustomExecutorForRetry() { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(CustomerNodeExecutorAndCustomRetry.class, response.getSlot().getData("retryLogic")); + Assert.assertEquals("d==>d==>d==>d==>d==>d", response.getSlot().getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/ACmp.java new file mode 100644 index 00000000..e576f564 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/ACmp.java @@ -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.nodeExecutor.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/BCmp.java new file mode 100644 index 00000000..9581a065 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/BCmp.java @@ -0,0 +1,31 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.nodeExecutor.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("b") +@LiteflowCmpDefine +public class BCmp{ + + private int flag = 0; + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + if (flag < 2){ + flag++; + throw new RuntimeException("demo exception"); + } + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CCmp.java new file mode 100644 index 00000000..3cf2a06f --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CCmp.java @@ -0,0 +1,33 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.nodeExecutor.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.annotation.LiteflowRetry; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.executor.NodeExecutor; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.test.nodeExecutor.CustomerNodeExecutor; + +@LiteflowComponent("c") +@LiteflowRetry(5) +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + + @LiteflowMethod(LiteFlowMethodEnum.GET_NODE_EXECUTOR_CLASS) + public Class<? extends NodeExecutor> getNodeExecutorClass(NodeComponent bindCmp) { + return CustomerNodeExecutor.class; + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/DCmp.java new file mode 100644 index 00000000..61c8b4c1 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/DCmp.java @@ -0,0 +1,35 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.nodeExecutor.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.annotation.LiteflowRetry; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.executor.NodeExecutor; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.test.nodeExecutor.CustomerNodeExecutorAndCustomRetry; + +@LiteflowComponent("d") +@LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class}) +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("DCmp executed!"); + throw new NullPointerException("demo exception"); + } + + @LiteflowMethod(LiteFlowMethodEnum.GET_NODE_EXECUTOR_CLASS) + public Class<? extends NodeExecutor> getNodeExecutorClass(NodeComponent bindCmp) { + return CustomerNodeExecutorAndCustomRetry.class; + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonSpringbootTest.java new file mode 100644 index 00000000..5f61dc20 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonSpringbootTest.java @@ -0,0 +1,39 @@ +package com.yomahub.liteflow.test.parsecustom; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * springboot环境的自定义json parser单元测试 + * @author dongguo.tao + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/parsecustom/application-custom-json.properties") +@SpringBootTest(classes = CustomParserJsonSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.parsecustom.cmp"}) +public class CustomParserJsonSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试springboot场景的自定义json parser + @Test + public void testJsonCustomParser() { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "args"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserXmlSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserXmlSpringbootTest.java new file mode 100644 index 00000000..b534a745 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserXmlSpringbootTest.java @@ -0,0 +1,40 @@ +package com.yomahub.liteflow.test.parsecustom; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * springboot环境的自定义xml parser单元测试 + * 主要测试自定义配置源类是否能引入springboot中的其他依赖 + * @author bryan.zhang + * @since 2.5.7 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/parsecustom/application-custom-xml.properties") +@SpringBootTest(classes = CustomParserXmlSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.parsecustom.cmp","com.yomahub.liteflow.test.parsecustom.bean"}) +public class CustomParserXmlSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试springboot场景的自定义json parser + @Test + public void testXmlCustomParser() { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "args"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/bean/TestBean.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/bean/TestBean.java new file mode 100644 index 00000000..3d4eece3 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/bean/TestBean.java @@ -0,0 +1,11 @@ +package com.yomahub.liteflow.test.parsecustom.bean; + +import org.springframework.stereotype.Component; + +@Component +public class TestBean { + + public String returnXmlContent(){ + return "<?xml version=\"1.0\" encoding=\"UTF-8\"?><flow><chain name=\"chain1\"><then value=\"a,b,c,d\"/></chain></flow>"; + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ACmp.java new file mode 100644 index 00000000..ed877bf9 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ACmp.java @@ -0,0 +1,30 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parsecustom.cmp; + +import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.exception.FlowSystemException; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + String str = bindCmp.getSlot().getRequestData(); + if(StrUtil.isNotBlank(str) && str.equals("exception")) { + throw new FlowSystemException("chain execute execption"); + } + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/BCmp.java new file mode 100644 index 00000000..440ea579 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parsecustom.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/CCmp.java new file mode 100644 index 00000000..75ca9441 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parsecustom.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/DCmp.java new file mode 100644 index 00000000..12789ff2 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/DCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parsecustom.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("d") +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("DCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ECmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ECmp.java new file mode 100644 index 00000000..7b15119d --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ECmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parsecustom.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCondCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.core.NodeCondComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("e") +@LiteflowCondCmpDefine +public class ECmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS_COND) + public String processCond(NodeComponent bindCmp) throws Exception { + return "g"; + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/FCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/FCmp.java new file mode 100644 index 00000000..4bb6d031 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/FCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parsecustom.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("f") +@LiteflowCmpDefine +public class FCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("FCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/GCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/GCmp.java new file mode 100644 index 00000000..62242e69 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/GCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parsecustom.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("g") +@LiteflowCmpDefine +public class GCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("GCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomJsonFlowParser.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomJsonFlowParser.java new file mode 100644 index 00000000..dd3a4192 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomJsonFlowParser.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.parsecustom.parser; + +import com.yomahub.liteflow.parser.ClassJsonFlowParser; + +/** + * 模拟用户自定义源解析 + * @author dongguo.tao + * @since 2.5.0 + */ +public class CustomJsonFlowParser extends ClassJsonFlowParser { + @Override + public String parseCustom() { + //模拟自定义解析结果 + String content = "{\"flow\":{\"nodes\":{\"node\":[{\"id\":\"a\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.ACmp\"},{\"id\":\"b\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.BCmp\"},{\"id\":\"c\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.CCmp\"},{\"id\":\"d\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.DCmp\"},{\"id\":\"e\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.ECmp\"},{\"id\":\"f\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.FCmp\"},{\"id\":\"g\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.GCmp\"}]},\"chain\":[{\"name\":\"chain2\",\"condition\":[{\"type\":\"then\",\"value\":\"c,g,f\"}]},{\"name\":\"chain1\",\"condition\":[{\"type\":\"then\",\"value\":\"a,c\"},{\"type\":\"when\",\"value\":\"b,d,e(f|g)\"},{\"type\":\"then\",\"value\":\"chain2\"}]}]}}"; + return content; + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomXmlFlowParser.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomXmlFlowParser.java new file mode 100644 index 00000000..064323b8 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomXmlFlowParser.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.parsecustom.parser; + +import com.yomahub.liteflow.parser.ClassXmlFlowParser; +import com.yomahub.liteflow.test.parsecustom.bean.TestBean; + +import javax.annotation.Resource; + +/** + * springboot环境的自定义xml parser单元测试 + * 主要测试自定义配置源类是否能引入springboot中的其他依赖 + * @author bryan.zhang + * @since 2.5.7 + */ +public class CustomXmlFlowParser extends ClassXmlFlowParser { + + @Resource + private TestBean testBean; + + @Override + public String parseCustom() { + return testBean.returnXmlContent(); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/JsonParserSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/JsonParserSpringbootTest.java new file mode 100644 index 00000000..6b4ee17f --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/JsonParserSpringbootTest.java @@ -0,0 +1,37 @@ +package com.yomahub.liteflow.test.parser; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * spring环境的json parser单元测试 + * @author Bryan.Zhang + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/parser/application-json.properties") +@SpringBootTest(classes = JsonParserSpringbootTest.class) +@EnableAutoConfiguration +public class JsonParserSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试spring场景的json parser + @Test + public void testJsonParser() { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/SpringELSupportSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/SpringELSupportSpringbootTest.java new file mode 100644 index 00000000..ec0e2acc --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/SpringELSupportSpringbootTest.java @@ -0,0 +1,32 @@ +package com.yomahub.liteflow.test.parser; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/parser/application-springEL.properties") +@SpringBootTest(classes = SpringELSupportSpringbootTest.class) +@EnableAutoConfiguration +public class SpringELSupportSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试springEL的解析情况 + @Test + public void testSpringELParser() { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/XmlParserSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/XmlParserSpringbootTest.java new file mode 100644 index 00000000..562e7456 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/XmlParserSpringbootTest.java @@ -0,0 +1,37 @@ +package com.yomahub.liteflow.test.parser; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * springboot环境的xml parser单元测试 + * @author Bryan.Zhang + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/parser/application-xml.properties") +@SpringBootTest(classes = XmlParserSpringbootTest.class) +@EnableAutoConfiguration +public class XmlParserSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试无springboot场景的xml parser + @Test + public void testXmlParser() { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/YmlParserSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/YmlParserSpringbootTest.java new file mode 100644 index 00000000..ad2050c0 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/YmlParserSpringbootTest.java @@ -0,0 +1,37 @@ +package com.yomahub.liteflow.test.parser; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * springboot下的yml parser测试用例 + * @author Bryan.Zhang + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/parser/application-yml.properties") +@SpringBootTest(classes = YmlParserSpringbootTest.class) +@EnableAutoConfiguration +public class YmlParserSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试无springboot场景的yml parser + @Test + public void testYmlParser() { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/ACmp.java new file mode 100644 index 00000000..33d611a3 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/ACmp.java @@ -0,0 +1,24 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parser.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/BCmp.java new file mode 100644 index 00000000..d40b13d2 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parser.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/CCmp.java new file mode 100644 index 00000000..e9d3dceb --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parser.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/DCmp.java new file mode 100644 index 00000000..9f86ac0f --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/DCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parser.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("d") +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("DCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/ECmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/ECmp.java new file mode 100644 index 00000000..620495a5 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/ECmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parser.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCondCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.core.NodeCondComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("e") +@LiteflowCondCmpDefine +public class ECmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS_COND) + public String processCond(NodeComponent bindCmp) throws Exception { + return "g"; + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/FCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/FCmp.java new file mode 100644 index 00000000..84e178b5 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/FCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parser.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("f") +@LiteflowCmpDefine +public class FCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("FCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/GCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/GCmp.java new file mode 100644 index 00000000..8b50f245 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/GCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parser.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("g") +@LiteflowCmpDefine +public class GCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("GCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallySpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallySpringbootTest.java new file mode 100644 index 00000000..0becd826 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallySpringbootTest.java @@ -0,0 +1,64 @@ +package com.yomahub.liteflow.test.preAndFinally; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * springboot环境下pre节点和finally节点的测试 + * @author Bryan.Zhang + * @since 2.6.4 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/preAndFinally/application.properties") +@SpringBootTest(classes = PreAndFinallySpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.preAndFinally.cmp"}) +public class PreAndFinallySpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试普通的pre和finally节点 + @Test + public void testPreAndFinally1() throws Exception{ + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("p1==>p2==>a==>b==>c==>f1==>f2",response.getSlot().getExecuteStepStr()); + } + + //测试pre和finally节点不放在开头和结尾的情况 + @Test + public void testPreAndFinally2() throws Exception{ + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("p1==>p2==>a==>b==>c==>f1==>f2",response.getSlot().getExecuteStepStr()); + } + + //测试有节点报错是否还执行finally节点的情况,其中d节点会报错,但依旧执行f1,f2节点 + @Test + public void testPreAndFinally3() throws Exception{ + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("p1==>p2==>a==>d==>f1==>f2", response.getSlot().getExecuteStepStr()); + } + + //测试在finally节点里是否能获取exception + @Test + public void testPreAndFinally4() throws Exception{ + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertTrue(response.getSlot().getData("hasEx")); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/ACmp.java new file mode 100644 index 00000000..c5b4afe6 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/ACmp.java @@ -0,0 +1,24 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.preAndFinally.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/BCmp.java new file mode 100644 index 00000000..92644fca --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.preAndFinally.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/CCmp.java new file mode 100644 index 00000000..23813b76 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.preAndFinally.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/DCmp.java new file mode 100644 index 00000000..f6f94827 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/DCmp.java @@ -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.preAndFinally.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("d") +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + int i = 1/0; + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally1Cmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally1Cmp.java new file mode 100644 index 00000000..fd5fed96 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally1Cmp.java @@ -0,0 +1,24 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.preAndFinally.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("f1") +@LiteflowCmpDefine +public class Finally1Cmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("Finally1Cmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally2Cmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally2Cmp.java new file mode 100644 index 00000000..e1c80972 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally2Cmp.java @@ -0,0 +1,24 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.preAndFinally.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("f2") +@LiteflowCmpDefine +public class Finally2Cmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("Finally2Cmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally3Cmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally3Cmp.java new file mode 100644 index 00000000..a775a42a --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally3Cmp.java @@ -0,0 +1,32 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.preAndFinally.cmp; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("f3") +@LiteflowCmpDefine +public class Finally3Cmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception{ + Slot slot = bindCmp.getSlot(); + if (ObjectUtil.isNull(slot.getException())){ + slot.setData("hasEx", false); + }else{ + slot.setData("hasEx", true); + } + System.out.println("Finally3Cmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre1Cmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre1Cmp.java new file mode 100644 index 00000000..ffe0556c --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre1Cmp.java @@ -0,0 +1,24 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.preAndFinally.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("p1") +@LiteflowCmpDefine +public class Pre1Cmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("Pre1Cmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre2Cmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre2Cmp.java new file mode 100644 index 00000000..f00a7526 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre2Cmp.java @@ -0,0 +1,24 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.preAndFinally.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("p2") +@LiteflowCmpDefine +public class Pre2Cmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("Pre2Cmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliverySpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliverySpringbootTest.java new file mode 100644 index 00000000..9f283119 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliverySpringbootTest.java @@ -0,0 +1,41 @@ +package com.yomahub.liteflow.test.privateDelivery; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; +import java.util.Set; + +/** + * springboot环境下隐私投递的测试 + * @author Bryan.Zhang + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/privateDelivery/application.properties") +@SpringBootTest(classes = PrivateDeliverySpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.privateDelivery.cmp"}) +public class PrivateDeliverySpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testPrivateDelivery() throws Exception{ + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg"); + Set<Integer> set = response.getSlot().getData("testSet"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(100, set.size()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/ACmp.java new file mode 100644 index 00000000..d2c8a321 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/ACmp.java @@ -0,0 +1,34 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.privateDelivery.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +import java.util.HashSet; + +@LiteflowComponent("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + Slot slot = bindCmp.getSlot(); + slot.setData("testSet", new HashSet<>()); + + for (int i = 0; i < 100; i++) { + bindCmp.sendPrivateDeliveryData("b",i+1); + } + } +} + diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/BCmp.java new file mode 100644 index 00000000..3290d9ca --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/BCmp.java @@ -0,0 +1,30 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.privateDelivery.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +import java.util.Set; + +@LiteflowComponent("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + Integer value = bindCmp.getPrivateDeliveryData(); + Set<Integer> testSet = bindCmp.getSlot().getData("testSet"); + testSet.add(value); + } +} + diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/CCmp.java new file mode 100644 index 00000000..c73d6640 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.privateDelivery.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/DCmp.java new file mode 100644 index 00000000..354abbb9 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/DCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.privateDelivery.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("d") +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleSpringbootTest.java new file mode 100644 index 00000000..d4504ce5 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleSpringbootTest.java @@ -0,0 +1,70 @@ +package com.yomahub.liteflow.test.refreshRule; + +import cn.hutool.core.io.resource.ResourceUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.enums.FlowParserTypeEnum; +import com.yomahub.liteflow.flow.FlowBus; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * springboot环境下重新加载规则测试 + * @author Bryan.Zhang + * @since 2.6.4 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/refreshRule/application.properties") +@SpringBootTest(classes = RefreshRuleSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.refreshRule.cmp"}) +public class RefreshRuleSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试普通刷新流程的场景 + @Test + public void testRefresh1() throws Exception{ + String content = ResourceUtil.readUtf8Str("classpath: /refreshRule/flow_update.xml"); + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_XML, content); + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } + + //测试优雅刷新的场景 + @Test + public void testRefresh2() throws Exception{ + new Thread(() -> { + try { + Thread.sleep(3000L); + String content = ResourceUtil.readUtf8Str("classpath: /refreshRule/flow_update.xml"); + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_XML, content); + } catch (Exception e) { + e.printStackTrace(); + } + + }).start(); + + for (int i = 0; i < 500; i++) { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + try { + Thread.sleep(10L); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/ACmp.java new file mode 100644 index 00000000..6912aaf8 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/ACmp.java @@ -0,0 +1,24 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.refreshRule.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/BCmp.java new file mode 100644 index 00000000..aaef859a --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.refreshRule.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/CCmp.java new file mode 100644 index 00000000..7e935c27 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.refreshRule.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/ReloadSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/ReloadSpringbootTest.java new file mode 100644 index 00000000..e09edbdd --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/ReloadSpringbootTest.java @@ -0,0 +1,41 @@ +package com.yomahub.liteflow.test.reload; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * springboot环境下重新加载规则测试 + * @author Bryan.Zhang + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/reload/application.properties") +@SpringBootTest(classes = ReloadSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.reload.cmp"}) +public class ReloadSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //用reloadRule去重新加载,这里如果配置是放在本地。如果想修改,则要去修改target下面的flow.xml + //这里的测试,手动打断点然后去修改,是ok的。但是整个测试,暂且只是为了测试这个功能是否能正常运行 + @Test + public void testReload() throws Exception{ + flowExecutor.reloadRule(); + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/cmp/ACmp.java new file mode 100644 index 00000000..57cc3a6d --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/cmp/ACmp.java @@ -0,0 +1,24 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.reload.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/cmp/BCmp.java new file mode 100644 index 00000000..5ca7ff6d --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.reload.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/cmp/CCmp.java new file mode 100644 index 00000000..af6e8b52 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.reload.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/ResizeSlotSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/ResizeSlotSpringbootTest.java new file mode 100644 index 00000000..7af320ed --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/ResizeSlotSpringbootTest.java @@ -0,0 +1,65 @@ +package com.yomahub.liteflow.test.resizeSlot; + +import cn.hutool.core.util.ReflectUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DataBus; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +/** + * springboot环境下slot扩容测试 + * @author Bryan.Zhang + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/resizeSlot/application.properties") +@SpringBootTest(classes = ResizeSlotSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.resizeSlot.cmp"}) +public class ResizeSlotSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testResize() throws Exception{ + ExecutorService pool = Executors.newCachedThreadPool(); + + List<Future<LiteflowResponse<DefaultSlot>>> futureList = new ArrayList<>(); + for (int i = 0; i < 100; i++) { + Future<LiteflowResponse<DefaultSlot>> future = pool.submit(() -> flowExecutor.execute2Resp("chain1", "arg")); + futureList.add(future); + } + + for(Future<LiteflowResponse<DefaultSlot>> future : futureList){ + Assert.assertTrue(future.get().isSuccess()); + } + + //取到static的对象QUEUE + Field field = ReflectUtil.getField(DataBus.class, "QUEUE"); + ConcurrentLinkedQueue<Integer> queue = (ConcurrentLinkedQueue<Integer>) ReflectUtil.getStaticFieldValue(field); + + //因为初始slotSize是4,按照0.75的扩容比,要满足100个线程,应该扩容5~6次,5次=65,6次=114 + //为什么不是直接114呢? + //因为在单测中根据机器的性能,在多线程情况下,有些机器跑的慢一点,也就是说65个就足够了。有些机器跑的快一点,是能真正扩容到114个的 + Assert.assertTrue(queue.size() > 4); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/cmp/ACmp.java new file mode 100644 index 00000000..c05adbf3 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/cmp/ACmp.java @@ -0,0 +1,24 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.resizeSlot.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/cmp/BCmp.java new file mode 100644 index 00000000..4a5e5ea8 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.resizeSlot.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/cmp/CCmp.java new file mode 100644 index 00000000..a0156105 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.resizeSlot.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowSpringbootTest.java new file mode 100644 index 00000000..82540c12 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowSpringbootTest.java @@ -0,0 +1,49 @@ +package com.yomahub.liteflow.test.subflow; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; +import java.util.HashSet; +import java.util.Set; + +/** + * 测试隐式调用子流程 + * 单元测试 + * + * @author justin.xu + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/subflow/application-implicit.properties") +@SpringBootTest(classes = ImplicitSubFlowSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp2"}) +public class ImplicitSubFlowSpringbootTest extends BaseTest { + @Resource + private FlowExecutor flowExecutor; + + public static final Set<String> RUN_TIME_SLOT = new HashSet<>(); + + //这里GCmp中隐式的调用chain4,从而执行了h,m + @Test + public void testImplicitSubFlow() { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain3", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("f==>g==>h==>m", response.getSlot().getExecuteStepStr()); + + // 传递了slotIndex,则set的size==1 + Assert.assertEquals(1, RUN_TIME_SLOT.size()); + // set中第一次设置的requestId和response中的requestId一致 + Assert.assertTrue(RUN_TIME_SLOT.contains(response.getSlot().getRequestId())); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigSpringbootTest.java new file mode 100644 index 00000000..a3179eca --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigSpringbootTest.java @@ -0,0 +1,54 @@ +package com.yomahub.liteflow.test.subflow; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.exception.MultipleParsersException; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * 测试主流程与子流程在不同的配置文件的场景 + * + * @author Bryan.Zhang + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/subflow/application-subInDifferentConfig1.properties") +@SpringBootTest(classes = SubflowInDifferentConfigSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp1","com.yomahub.liteflow.test.subflow.cmp2"}) +public class SubflowInDifferentConfigSpringbootTest extends BaseTest { + @Resource + private FlowExecutor flowExecutor; + + //是否按照流程定义配置执行 + @Test + public void testExplicitSubFlow1() { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>b==>a==>e==>d", response.getSlot().getExecuteStepStr()); + } + + @Autowired + private ApplicationContext context; + + //主要测试有不同的配置类型后会不会报出既定的错误 + @Test(expected = MultipleParsersException.class) + public void testExplicitSubFlow2() { + LiteflowConfig config = context.getBean(LiteflowConfig.class); + config.setRuleSource("subflow/flow-main.xml,subflow/flow-sub1.xml,subflow/flow-sub2.yml"); + flowExecutor.init(); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/SubflowJsonSpringBootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/SubflowJsonSpringBootTest.java new file mode 100644 index 00000000..f112252e --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/SubflowJsonSpringBootTest.java @@ -0,0 +1,40 @@ +package com.yomahub.liteflow.test.subflow; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * 测试显示调用子流程(json) + * 单元测试 + * + * @author justin.xu + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/subflow/application-json.properties") +@SpringBootTest(classes = SubflowJsonSpringBootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp1"}) +public class SubflowJsonSpringBootTest extends BaseTest { + @Resource + private FlowExecutor flowExecutor; + + //是否按照流程定义配置执行 + @Test + public void testExplicitSubFlow() { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getSlot().getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLSpringBootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLSpringBootTest.java new file mode 100644 index 00000000..96d0d701 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLSpringBootTest.java @@ -0,0 +1,40 @@ +package com.yomahub.liteflow.test.subflow; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * 测试显示调用子流程(xml) + * 单元测试 + * + * @author justin.xu + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/subflow/application-xml.properties") +@SpringBootTest(classes = SubflowXMLSpringBootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp1"}) +public class SubflowXMLSpringBootTest extends BaseTest { + @Resource + private FlowExecutor flowExecutor; + + //是否按照流程定义配置执行 + @Test + public void testExplicitSubFlow() { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getSlot().getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlSpringBootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlSpringBootTest.java new file mode 100644 index 00000000..5b250132 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlSpringBootTest.java @@ -0,0 +1,40 @@ +package com.yomahub.liteflow.test.subflow; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * 测试显示调用子流程(yml) + * 单元测试 + * + * @author justin.xu + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/subflow/application-yml.properties") +@SpringBootTest(classes = SubflowYmlSpringBootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp1"}) +public class SubflowYmlSpringBootTest extends BaseTest { + @Resource + private FlowExecutor flowExecutor; + + //是否按照流程定义配置执行 + @Test + public void testExplicitSubFlowYml() { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getSlot().getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ACmp.java new file mode 100644 index 00000000..f20ef02a --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ACmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.subflow.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("Acomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/BCmp.java new file mode 100644 index 00000000..4801ac86 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/BCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.subflow.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("Bcomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CCmp.java new file mode 100644 index 00000000..2ae551ea --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.subflow.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + System.out.println("Ccomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/DCmp.java new file mode 100644 index 00000000..e734549c --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/DCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.subflow.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + + +@Component("d") +@LiteflowCmpDefine +public class DCmp{ + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + System.out.println("Dcomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ECmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ECmp.java new file mode 100644 index 00000000..d8ae800c --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ECmp.java @@ -0,0 +1,18 @@ +package com.yomahub.liteflow.test.subflow.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + + +@Component("e") +@LiteflowCmpDefine +public class ECmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + System.out.println("Ecomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/FCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/FCmp.java new file mode 100644 index 00000000..f260b44a --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/FCmp.java @@ -0,0 +1,22 @@ +package com.yomahub.liteflow.test.subflow.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowSpringbootTest.RUN_TIME_SLOT; + + +@Component("f") +@LiteflowCmpDefine +public class FCmp{ + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + + RUN_TIME_SLOT.add(bindCmp.getSlot().getRequestId()); + + System.out.println("Fcomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/GCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/GCmp.java new file mode 100644 index 00000000..ef110aea --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/GCmp.java @@ -0,0 +1,31 @@ +package com.yomahub.liteflow.test.subflow.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowSpringbootTest.RUN_TIME_SLOT; + + +@Component("g") +@LiteflowCmpDefine +public class GCmp{ + + @Autowired + private FlowExecutor flowExecutor; + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + + RUN_TIME_SLOT.add(bindCmp.getSlot().getRequestId()); + + System.out.println("Gcmp executed!"); + + flowExecutor.invoke("chain4", "it's implicit subflow.", DefaultSlot.class, bindCmp.getSlotIndex()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java new file mode 100644 index 00000000..d8c5eebf --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java @@ -0,0 +1,22 @@ +package com.yomahub.liteflow.test.subflow.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowSpringbootTest.RUN_TIME_SLOT; + + +@Component("h") +@LiteflowCmpDefine +public class HCmp{ + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + + RUN_TIME_SLOT.add(bindCmp.getSlot().getRequestId()); + + System.out.println("Hcomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/MCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/MCmp.java new file mode 100644 index 00000000..199abff7 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/MCmp.java @@ -0,0 +1,22 @@ +package com.yomahub.liteflow.test.subflow.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowSpringbootTest.RUN_TIME_SLOT; + + +@Component("m") +@LiteflowCmpDefine +public class MCmp{ + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + + RUN_TIME_SLOT.add(bindCmp.getSlot().getRequestId()); + + System.out.println("Mcomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/NodeTagSpringbootJsonTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/NodeTagSpringbootJsonTest.java new file mode 100644 index 00000000..b4454127 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/NodeTagSpringbootJsonTest.java @@ -0,0 +1,67 @@ +package com.yomahub.liteflow.test.tag; + +import cn.hutool.core.collection.ConcurrentHashSet; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * springboot环境下隐私投递的测试 + * @author Bryan.Zhang + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/tag/application-json.properties") +@SpringBootTest(classes = NodeTagSpringbootJsonTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.tag.cmp"}) +public class NodeTagSpringbootJsonTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testTag1() throws Exception{ + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("123",response.getSlot().getData("test")); + } + + @Test + public void testTag2() throws Exception{ + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>a==>a==>c==>e", response.getSlot().getExecuteStepStr()); + } + + //测试多线程when情况下的tag取值是否正确 + //这里循环多次的原因是,因为when多线程,有时候因为凑巧,可能正确。所以多次情况下在2.6.4版本肯定出错 + @Test + public void testTag3() throws Exception{ + for (int i = 0; i < 50; i++) { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + ConcurrentHashSet<String> testSet = response.getSlot().getData("test"); + Assert.assertEquals(3, testSet.size()); + } + } + + //测试tag是否能在isAccess中起效 + @Test + public void testTag4() throws Exception{ + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("g", response.getSlot().getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/NodeTagSpringbootXmlTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/NodeTagSpringbootXmlTest.java new file mode 100644 index 00000000..7ed25755 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/NodeTagSpringbootXmlTest.java @@ -0,0 +1,67 @@ +package com.yomahub.liteflow.test.tag; + +import cn.hutool.core.collection.ConcurrentHashSet; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * springboot环境下隐私投递的测试 + * @author Bryan.Zhang + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/tag/application-xml.properties") +@SpringBootTest(classes = NodeTagSpringbootXmlTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.tag.cmp"}) +public class NodeTagSpringbootXmlTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testTag1() throws Exception{ + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("123",response.getSlot().getData("test")); + } + + @Test + public void testTag2() throws Exception{ + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>a==>a==>c==>e", response.getSlot().getExecuteStepStr()); + } + + //测试多线程when情况下的tag取值是否正确 + //这里循环多次的原因是,因为when多线程,有时候因为凑巧,可能正确。所以多次情况下在2.6.4版本肯定出错 + @Test + public void testTag3() throws Exception{ + for (int i = 0; i < 50; i++) { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + ConcurrentHashSet<String> testSet = response.getSlot().getData("test"); + Assert.assertEquals(3, testSet.size()); + } + } + + //测试tag是否能在isAccess中起效 + @Test + public void testTag4() throws Exception{ + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("g", response.getSlot().getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/ACmp.java new file mode 100644 index 00000000..08ddb9ed --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/ACmp.java @@ -0,0 +1,34 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.tag.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + String testKey = "test"; + + Slot slot = bindCmp.getSlot(); + if (slot.getData(testKey) == null){ + slot.setData(testKey,bindCmp.getTag()); + }else{ + String s = slot.getData(testKey); + s += bindCmp.getTag(); + slot.setData(testKey, s); + } + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/B1Cmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/B1Cmp.java new file mode 100644 index 00000000..5fb5e35e --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/B1Cmp.java @@ -0,0 +1,27 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.tag.cmp; + +import cn.hutool.core.collection.ConcurrentHashSet; +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("b1") +@LiteflowCmpDefine +public class B1Cmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + Slot slot = bindCmp.getSlot(); + slot.setData("test",new ConcurrentHashSet<String>()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/BCmp.java new file mode 100644 index 00000000..06da76a8 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/BCmp.java @@ -0,0 +1,28 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.tag.cmp; + +import cn.hutool.core.collection.ConcurrentHashSet; +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + Slot slot = bindCmp.getSlot(); + ConcurrentHashSet<String> testSet = slot.getData("test"); + testSet.add(bindCmp.getTag()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/CCmp.java new file mode 100644 index 00000000..7639fc6b --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/CCmp.java @@ -0,0 +1,30 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.tag.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowCondCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.core.NodeCondComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("c") +@LiteflowCondCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS_COND) + public String processCond(NodeComponent bindCmp) throws Exception { + if(bindCmp.getTag().equals("2")){ + return "e"; + }else{ + return "d"; + } + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/DCmp.java new file mode 100644 index 00000000..8ee32b74 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/DCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.tag.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("d") +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println(bindCmp.getTag()); + System.out.println("DCmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/ECmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/ECmp.java new file mode 100644 index 00000000..84423ee7 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/ECmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.tag.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("e") +@LiteflowCmpDefine +public class ECmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println(bindCmp.getTag()); + System.out.println("ECmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/FCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/FCmp.java new file mode 100644 index 00000000..e3ea2023 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/FCmp.java @@ -0,0 +1,29 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.tag.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("f") +@LiteflowCmpDefine +public class FCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process() { + System.out.println("FCmp executed!"); + } + + @LiteflowMethod(LiteFlowMethodEnum.IS_ACCESS) + public boolean isAccess(NodeComponent bindCmp) { + return Boolean.parseBoolean(bindCmp.getTag()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/GCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/GCmp.java new file mode 100644 index 00000000..f8aae453 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/GCmp.java @@ -0,0 +1,24 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.tag.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("g") +@LiteflowCmpDefine +public class GCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("GCmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/TestTL.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/TestTL.java new file mode 100644 index 00000000..fee0055e --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/TestTL.java @@ -0,0 +1,16 @@ +package com.yomahub.liteflow.test.useTTLInWhen; + +import com.alibaba.ttl.TransmittableThreadLocal; + +public class TestTL { + + public static ThreadLocal<String> tl = new TransmittableThreadLocal<>(); + + public static String get(){ + return tl.get(); + } + + public static void set(String value){ + tl.set(value); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/UseTTLInWhenSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/UseTTLInWhenSpringbootTest.java new file mode 100644 index 00000000..5d74a18a --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/UseTTLInWhenSpringbootTest.java @@ -0,0 +1,42 @@ +package com.yomahub.liteflow.test.useTTLInWhen; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * 在when异步节点的情况下去拿ThreadLocal里的测试场景 + * @author Bryan.Zhang + * @since 2.6.3 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/useTTLInWhen/application.properties") +@SpringBootTest(classes = UseTTLInWhenSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.useTTLInWhen.cmp"}) +public class UseTTLInWhenSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testUseTTLInWhen() throws Exception{ + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertEquals("hello,b", response.getSlot().getData("b")); + Assert.assertEquals("hello,c", response.getSlot().getData("c")); + Assert.assertEquals("hello,d", response.getSlot().getData("d")); + Assert.assertEquals("hello,e", response.getSlot().getData("e")); + Assert.assertEquals("hello,f", response.getSlot().getData("f")); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ACmp.java new file mode 100644 index 00000000..18687b6e --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ACmp.java @@ -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.useTTLInWhen.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.test.useTTLInWhen.TestTL; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + TestTL.set("hello"); + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/BCmp.java new file mode 100644 index 00000000..b2e30c9b --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/BCmp.java @@ -0,0 +1,28 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.useTTLInWhen.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.test.useTTLInWhen.TestTL; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + String value = TestTL.get(); + bindCmp.getSlot().setData(bindCmp.getNodeId(),value+",b"); + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CCmp.java new file mode 100644 index 00000000..429eca6d --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CCmp.java @@ -0,0 +1,28 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.useTTLInWhen.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.test.useTTLInWhen.TestTL; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + String value = TestTL.get(); + bindCmp.getSlot().setData(bindCmp.getNodeId(),value+",c"); + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/DCmp.java new file mode 100644 index 00000000..a9e657f9 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/DCmp.java @@ -0,0 +1,28 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.useTTLInWhen.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.test.useTTLInWhen.TestTL; +import org.springframework.stereotype.Component; + +@Component("d") +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + String value = TestTL.get(); + bindCmp.getSlot().setData(bindCmp.getNodeId(),value+",d"); + System.out.println("DCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ECmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ECmp.java new file mode 100644 index 00000000..f039dbcc --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ECmp.java @@ -0,0 +1,28 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.useTTLInWhen.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.test.useTTLInWhen.TestTL; +import org.springframework.stereotype.Component; + +@Component("e") +@LiteflowCmpDefine +public class ECmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + String value = TestTL.get(); + bindCmp.getSlot().setData(bindCmp.getNodeId(),value+",e"); + System.out.println("ECmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/FCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/FCmp.java new file mode 100644 index 00000000..2cb04f0a --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/FCmp.java @@ -0,0 +1,28 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.useTTLInWhen.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.test.useTTLInWhen.TestTL; +import org.springframework.stereotype.Component; + +@Component("f") +@LiteflowCmpDefine +public class FCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + String value = TestTL.get(); + bindCmp.getSlot().setData(bindCmp.getNodeId(),value+",f"); + System.out.println("FCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutSpringbootTest1.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutSpringbootTest1.java new file mode 100644 index 00000000..78e6a33c --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutSpringbootTest1.java @@ -0,0 +1,45 @@ +package com.yomahub.liteflow.test.whenTimeOut; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.exception.WhenTimeoutException; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * springboot环境下异步线程超时日志打印测试 + * @author Bryan.Zhang + * @since 2.6.4 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/whenTimeOut/application1.properties") +@SpringBootTest(classes = WhenTimeOutSpringbootTest1.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.whenTimeOut.cmp"}) +public class WhenTimeOutSpringbootTest1 extends BaseTest { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Resource + private FlowExecutor flowExecutor; + + //其中b和c在when情况下超时,所以抛出了WhenTimeoutException这个错 + @Test + public void testWhenTimeOut() throws Exception{ + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(WhenTimeoutException.class, response.getCause().getClass()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutSpringbootTest2.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutSpringbootTest2.java new file mode 100644 index 00000000..74c8223f --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutSpringbootTest2.java @@ -0,0 +1,43 @@ +package com.yomahub.liteflow.test.whenTimeOut; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * springboot环境下异步线程超时日志打印测试 + * @author Bryan.Zhang + * @since 2.6.4 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/whenTimeOut/application2.properties") +@SpringBootTest(classes = WhenTimeOutSpringbootTest2.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.whenTimeOut.cmp"}) +public class WhenTimeOutSpringbootTest2 extends BaseTest { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Resource + private FlowExecutor flowExecutor; + + //其中d,e,f都sleep 4秒,其中def是不同的组,超时设置5秒 + @Test + public void testWhenTimeOut() throws Exception{ + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ACmp.java new file mode 100644 index 00000000..236b7093 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ACmp.java @@ -0,0 +1,24 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.whenTimeOut.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/BCmp.java new file mode 100644 index 00000000..6628e838 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/BCmp.java @@ -0,0 +1,30 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.whenTimeOut.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + try { + Thread.sleep(4000); + }catch (Exception ignored){ + + } + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CCmp.java new file mode 100644 index 00000000..e26c064f --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CCmp.java @@ -0,0 +1,30 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.whenTimeOut.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + try { + Thread.sleep(3500); + }catch (Exception ignored){ + + } + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/DCmp.java new file mode 100644 index 00000000..720a4a8b --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/DCmp.java @@ -0,0 +1,30 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.whenTimeOut.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("d") +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + try { + Thread.sleep(4000); + }catch (Exception ignored){ + + } + System.out.println("DCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ECmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ECmp.java new file mode 100644 index 00000000..6485ae74 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ECmp.java @@ -0,0 +1,30 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.whenTimeOut.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("e") +@LiteflowCmpDefine +public class ECmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + try { + Thread.sleep(4000); + }catch (Exception ignored){ + + } + System.out.println("ECmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/FCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/FCmp.java new file mode 100644 index 00000000..f16bda6a --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/FCmp.java @@ -0,0 +1,30 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.whenTimeOut.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("f") +@LiteflowCmpDefine +public class FCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + try { + Thread.sleep(4000); + }catch (Exception ignored){ + + } + System.out.println("FCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithJsonSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithJsonSpringbootTest.java new file mode 100644 index 00000000..474c3fd9 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithJsonSpringbootTest.java @@ -0,0 +1,83 @@ +package com.yomahub.liteflow.test.zookeeper; + +import cn.hutool.core.io.resource.ResourceUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.I0Itec.zkclient.ZkClient; +import org.I0Itec.zkclient.exception.ZkMarshallingError; +import org.I0Itec.zkclient.serialize.ZkSerializer; +import org.apache.curator.test.TestingServer; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; +import java.nio.charset.Charset; +import java.util.concurrent.CountDownLatch; + +/** + * springboot环境下的zk配置源功能测试 + * ZK节点存储数据的格式为json文件 + * @author zendwang + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/zookeeper/application-json.properties") +@SpringBootTest(classes = ZkNodeWithJsonSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.zookeeper.cmp"}) +public class ZkNodeWithJsonSpringbootTest extends BaseTest { + + private static final String ZK_NODE_PATH = "/lite-flow/flow"; + + private static TestingServer zkServer; + + @Resource + private FlowExecutor flowExecutor; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + zkServer = new TestingServer(21810); + CountDownLatch latch = new CountDownLatch(1); + new Thread(() -> { + String data = ResourceUtil.readUtf8Str("zookeeper/flow.json"); + ZkClient zkClient = new ZkClient("127.0.0.1:21810"); + zkClient.setZkSerializer(new ZkSerializer() { + @Override + public byte[] serialize(final Object o) throws ZkMarshallingError { + return o.toString().getBytes(Charset.forName("UTF-8")); + } + + @Override + public Object deserialize(final byte[] bytes) throws ZkMarshallingError { + return new String(bytes, Charset.forName("UTF-8")); + } + }); + zkClient.createPersistent(ZK_NODE_PATH, true); + zkClient.writeData(ZK_NODE_PATH, data); + zkClient.close(); + latch.countDown(); + }).start(); + latch.await(); + } + + @Test + public void testZkNodeWithJson() { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } + + @AfterClass + public static void tearDown() throws Exception { + zkServer.stop(); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithXmlSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithXmlSpringbootTest.java new file mode 100644 index 00000000..c80a72fc --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithXmlSpringbootTest.java @@ -0,0 +1,83 @@ +package com.yomahub.liteflow.test.zookeeper; + +import cn.hutool.core.io.resource.ResourceUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.I0Itec.zkclient.ZkClient; +import org.I0Itec.zkclient.exception.ZkMarshallingError; +import org.I0Itec.zkclient.serialize.ZkSerializer; +import org.apache.curator.test.TestingServer; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; +import java.nio.charset.Charset; +import java.util.concurrent.CountDownLatch; + +/** + * springboot环境下的zk配置源功能测试 + * ZK节点存储数据的格式为xml文件 + * @author zendwang + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/zookeeper/application-xml.properties") +@SpringBootTest(classes = ZkNodeWithXmlSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.zookeeper.cmp"}) +public class ZkNodeWithXmlSpringbootTest extends BaseTest { + + private static final String ZK_NODE_PATH = "/lite-flow/flow"; + + private static TestingServer zkServer; + + @Resource + private FlowExecutor flowExecutor; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + zkServer = new TestingServer(21810); + CountDownLatch latch = new CountDownLatch(1); + new Thread(() -> { + String data = ResourceUtil.readUtf8Str("zookeeper/flow.xml"); + ZkClient zkClient = new ZkClient("127.0.0.1:21810"); + zkClient.setZkSerializer(new ZkSerializer() { + @Override + public byte[] serialize(final Object o) throws ZkMarshallingError { + return o.toString().getBytes(Charset.forName("UTF-8")); + } + + @Override + public Object deserialize(final byte[] bytes) throws ZkMarshallingError { + return new String(bytes, Charset.forName("UTF-8")); + } + }); + zkClient.createPersistent(ZK_NODE_PATH, true); + zkClient.writeData(ZK_NODE_PATH, data); + zkClient.close(); + latch.countDown(); + }).start(); + latch.await(); + } + + @Test + public void testZkNodeWithXml() { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } + + @AfterClass + public static void tearDown() throws Exception { + zkServer.stop(); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithYmlSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithYmlSpringbootTest.java new file mode 100644 index 00000000..5cc62daa --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithYmlSpringbootTest.java @@ -0,0 +1,83 @@ +package com.yomahub.liteflow.test.zookeeper; + +import cn.hutool.core.io.resource.ResourceUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.I0Itec.zkclient.ZkClient; +import org.I0Itec.zkclient.exception.ZkMarshallingError; +import org.I0Itec.zkclient.serialize.ZkSerializer; +import org.apache.curator.test.TestingServer; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; +import java.nio.charset.Charset; +import java.util.concurrent.CountDownLatch; + +/** + * springboot环境下的zk配置源功能测试 + * ZK节点存储数据的格式为yml文件 + * @author zendwang + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/zookeeper/application-yml.properties") +@SpringBootTest(classes = ZkNodeWithYmlSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.zookeeper.cmp"}) +public class ZkNodeWithYmlSpringbootTest extends BaseTest { + + private static final String ZK_NODE_PATH = "/lite-flow/flow"; + + private static TestingServer zkServer; + + @Resource + private FlowExecutor flowExecutor; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + zkServer = new TestingServer(21810); + CountDownLatch latch = new CountDownLatch(1); + new Thread(() -> { + String data = ResourceUtil.readUtf8Str("zookeeper/flow.yml"); + ZkClient zkClient = new ZkClient("127.0.0.1:21810"); + zkClient.setZkSerializer(new ZkSerializer() { + @Override + public byte[] serialize(final Object o) throws ZkMarshallingError { + return o.toString().getBytes(Charset.forName("UTF-8")); + } + + @Override + public Object deserialize(final byte[] bytes) throws ZkMarshallingError { + return new String(bytes, Charset.forName("UTF-8")); + } + }); + zkClient.createPersistent(ZK_NODE_PATH, true); + zkClient.writeData(ZK_NODE_PATH, data); + zkClient.close(); + latch.countDown(); + }).start(); + latch.await(); + } + + @Test + public void testZkNodeWithYml() { + LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } + + @AfterClass + public static void tearDown() throws Exception { + zkServer.stop(); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/ACmp.java new file mode 100644 index 00000000..31ae50e3 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/ACmp.java @@ -0,0 +1,24 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.zookeeper.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/BCmp.java new file mode 100644 index 00000000..0599bc17 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.zookeeper.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/CCmp.java new file mode 100644 index 00000000..cddcc336 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + * <p>Title: liteflow</p> + * <p>Description: 轻量级的组件式流程框架</p> + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.zookeeper.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/resources/absoluteConfigPath/application.properties b/liteflow-testcase-declare-component/src/test/resources/absoluteConfigPath/application.properties new file mode 100644 index 00000000..55fe91fd --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/absoluteConfigPath/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=/usr/local/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/absoluteConfigPath/flow.xml b/liteflow-testcase-declare-component/src/test/resources/absoluteConfigPath/flow.xml new file mode 100644 index 00000000..a6fda5aa --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/absoluteConfigPath/flow.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!--这里只是内容,在这个测试用例中这个文件请移到/usr/local/flow.xml中--> +<flow> + <chain name="chain1"> + <when value="a,b,c"/> + </chain> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/aop/application.properties b/liteflow-testcase-declare-component/src/test/resources/aop/application.properties new file mode 100644 index 00000000..f9075d1c --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/aop/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=aop/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/aop/flow.xml b/liteflow-testcase-declare-component/src/test/resources/aop/flow.xml new file mode 100644 index 00000000..84e8d458 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/aop/flow.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <chain name="chain1"> + <then value="a,b,c,d,e"/> + </chain> + + <chain name="chain2"> + <then value="a,b,c"/> + <when value="d,e"/> + </chain> + + <chain name="chain3"> + <then value="a,b,c,f"/> + </chain> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/asyncNode/application.properties b/liteflow-testcase-declare-component/src/test/resources/asyncNode/application.properties new file mode 100644 index 00000000..db0c76e7 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/asyncNode/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=asyncNode/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/asyncNode/flow.xml b/liteflow-testcase-declare-component/src/test/resources/asyncNode/flow.xml new file mode 100644 index 00000000..e81546bb --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/asyncNode/flow.xml @@ -0,0 +1,56 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <!-- base test --> + <chain name="chain1"> + <then value="a,b,c"/> <!-- a b c 串联执行--> + <when value="d,e(f|g)"/> <!-- e d 并联执行--> + <then value="chain2"/> + </chain> + <chain name="chain2"> + <then value="b,j(a|chain3)"/> + </chain> + + <chain name="chain3"> + <when value="g,f,h"/> + </chain> + + <chain name="chain3-1"> + <when value="f,g,i" group="1"/> + <when value="h" group="2"/> + </chain> + + <chain name="chain3-2"> + <when value="f,g,i" errorResume="true" group="1"/> + <when value="h" group="2"/> + </chain> + + <chain name="chain4"> + <then value="a,b,c"/> <!-- a b c 串联执行--> + <when value="d,i" errorResume="true"/> <!-- d i 并联执行--> + <when value="g,i,h" errorResume="false"/><!-- 此时 g i h 与 d i并联执行 并且默认异常不抛出--> + </chain> + + <chain name="chain5"> + <then value="a,b,c"/> <!-- a b c 串联执行--> + <when value="d,i" errorResume="false"/> <!-- d i 并联执行--> + <when value="g,i,h" errorResume="true"/><!-- 此时 g i h 与 d i并联执行 并且默认异常抛出--> + </chain> + + <chain name="chain6"> + <then value="a,b,c"/> <!-- a b c 串联执行--> + <when value="d,i" errorResume="false" group="1"/> <!-- d i 并联执行--> + <when value="g,i,h" errorResume="true" group="2"/><!-- 此时 g i h 与 d i并联执行 并且默认异常抛出--> + </chain> + + <chain name="chain7"> + <then value="a,b,c"/> <!-- a b c 串联执行--> + <when value="d,i" errorResume="true" group="1"/> <!-- d i 并联执行--> + <when value="g,i,h" errorResume="false" group="2"/><!-- 此时 g i h 与 d i并联执行 并且默认异常抛出--> + </chain> + + <chain name="chain8"> + <when value="d,g,h" any="true"/> <!-- a b c 串联执行--> + <then value="a,b,c"/> <!-- d g h 并联执行,任意一个执行完毕即结束--> + </chain> + +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/base/application.properties b/liteflow-testcase-declare-component/src/test/resources/base/application.properties new file mode 100644 index 00000000..cf3ccb24 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/base/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=base/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/base/flow.xml b/liteflow-testcase-declare-component/src/test/resources/base/flow.xml new file mode 100644 index 00000000..7068d6ce --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/base/flow.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <chain name="chain1"> + <then value="a,b"/> + <when value="c,d"/> + </chain> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/cmpRetry/application.properties b/liteflow-testcase-declare-component/src/test/resources/cmpRetry/application.properties new file mode 100644 index 00000000..bd5d04cd --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/cmpRetry/application.properties @@ -0,0 +1,3 @@ +liteflow.rule-source=cmpRetry/flow.xml +liteflow.retry-count=3 +liteflow.slot-size=512 \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/cmpRetry/flow.xml b/liteflow-testcase-declare-component/src/test/resources/cmpRetry/flow.xml new file mode 100644 index 00000000..d44e3ee0 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/cmpRetry/flow.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <chain name="chain1"> + <then value="a,b"/> + </chain> + + <chain name="chain2"> + <then value="c"/> + </chain> + + <chain name="chain3"> + <then value="d"/> + </chain> + + <chain name="chain4"> + <then value="e"/> + </chain> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/component/application.properties b/liteflow-testcase-declare-component/src/test/resources/component/application.properties new file mode 100644 index 00000000..d5b0e66d --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/component/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=component/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/component/flow.xml b/liteflow-testcase-declare-component/src/test/resources/component/flow.xml new file mode 100644 index 00000000..2a504fd0 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/component/flow.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <chain name="chain1"> + <then value="a"/> + </chain> + + <chain name="chain2"> + <then value="b"/> + </chain> + + <chain name="chain3"> + <then value="c"/> + </chain> + + <chain name="chain4"> + <then value="a,d,c"/> + </chain> + + <chain name="chain5"> + <then value="a,e,c"/> + </chain> + + <chain name="chain6"> + <then value="f(d | c | b)" /> + </chain> + + <chain name="chain7"> + <then value="g,h"/> + </chain> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/config/aaa/bbb/flow1.xml b/liteflow-testcase-declare-component/src/test/resources/config/aaa/bbb/flow1.xml new file mode 100644 index 00000000..ced398c9 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/config/aaa/bbb/flow1.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <chain name="chain2"> + <then value="a,c"/> + <then value="b,d"/> + </chain> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/config/aaa/flow0.xml b/liteflow-testcase-declare-component/src/test/resources/config/aaa/flow0.xml new file mode 100644 index 00000000..22870d94 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/config/aaa/flow0.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <chain name="chain1"> + <then value="a,b,c"/> + </chain> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/config/application1.properties b/liteflow-testcase-declare-component/src/test/resources/config/application1.properties new file mode 100644 index 00000000..4ac6c4d6 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/config/application1.properties @@ -0,0 +1 @@ +liteflow.rule-source=config/flow.yml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/config/application2.properties b/liteflow-testcase-declare-component/src/test/resources/config/application2.properties new file mode 100644 index 00000000..5079ac3d --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/config/application2.properties @@ -0,0 +1 @@ +liteflow.rule-source=config/**/flow*.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/config/flow.yml b/liteflow-testcase-declare-component/src/test/resources/config/flow.yml new file mode 100644 index 00000000..3cdaced3 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/config/flow.yml @@ -0,0 +1,6 @@ +flow: + chain: + - name: chain1 + condition: + - type: then + value: 'a,b,c' diff --git a/liteflow-testcase-declare-component/src/test/resources/customNodes/application.properties b/liteflow-testcase-declare-component/src/test/resources/customNodes/application.properties new file mode 100644 index 00000000..ab7716a6 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/customNodes/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=customNodes/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/customNodes/flow.xml b/liteflow-testcase-declare-component/src/test/resources/customNodes/flow.xml new file mode 100644 index 00000000..ecc1abcd --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/customNodes/flow.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <nodes> + <node id="a" class="com.yomahub.liteflow.test.customNodes.cmp.ACmp"/> + <node id="b" class="com.yomahub.liteflow.test.customNodes.cmp.BCmp"/> + <node id="c" class="com.yomahub.liteflow.test.customNodes.cmp.CCmp"/> + <node id="d" class="com.yomahub.liteflow.test.customNodes.cmp.DCmp"/> + <node id="e" class="com.yomahub.liteflow.test.customNodes.cmp.ECmp"/> + <node id="f" class="com.yomahub.liteflow.test.customNodes.cmp.FCmp"/> + </nodes> + + <chain name="chain1"> + <when value="a,b,c"/> + </chain> + + <chain name="chain2"> + <when value="d,e,f"/> + </chain> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/customWhenThreadPool/application.properties b/liteflow-testcase-declare-component/src/test/resources/customWhenThreadPool/application.properties new file mode 100644 index 00000000..3447aaa3 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/customWhenThreadPool/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=customWhenThreadPool/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/customWhenThreadPool/flow.xml b/liteflow-testcase-declare-component/src/test/resources/customWhenThreadPool/flow.xml new file mode 100644 index 00000000..c6f199dd --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/customWhenThreadPool/flow.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <chain name="chain"> + <when value="a,b"/> + </chain> + <chain name="chain1"> + <when value="c,d" threadExecutorClass="com.yomahub.liteflow.test.customWhenThreadPool.CustomThreadExecutor1"/> + </chain> + <chain name="chain2"> + <when value="e,f" threadExecutorClass="com.yomahub.liteflow.test.customWhenThreadPool.CustomThreadExecutor1"/> + </chain> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/deadLoopChain/application.properties b/liteflow-testcase-declare-component/src/test/resources/deadLoopChain/application.properties new file mode 100644 index 00000000..8e35187c --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/deadLoopChain/application.properties @@ -0,0 +1,2 @@ +liteflow.rule-source=deadLoopChain/flow.xml +liteflow.parse-on-start=false \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/deadLoopChain/flow.xml b/liteflow-testcase-declare-component/src/test/resources/deadLoopChain/flow.xml new file mode 100644 index 00000000..ca6e1c3f --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/deadLoopChain/flow.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <chain name="chain1"> + <then value="a,b,chain2"/> + </chain> + + <chain name="chain2"> + <then value="c,chain1"/> + </chain> + +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/emptyFlow/application.properties b/liteflow-testcase-declare-component/src/test/resources/emptyFlow/application.properties new file mode 100644 index 00000000..953c0206 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/emptyFlow/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=emptyFlow/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/emptyFlow/flow.xml b/liteflow-testcase-declare-component/src/test/resources/emptyFlow/flow.xml new file mode 100644 index 00000000..e69de29b diff --git a/liteflow-testcase-declare-component/src/test/resources/enable/application.properties b/liteflow-testcase-declare-component/src/test/resources/enable/application.properties new file mode 100644 index 00000000..64bcf001 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/enable/application.properties @@ -0,0 +1,2 @@ +liteflow.enable=false +liteflow.rule-source=enable/flow.xml diff --git a/liteflow-testcase-declare-component/src/test/resources/enable/flow.xml b/liteflow-testcase-declare-component/src/test/resources/enable/flow.xml new file mode 100644 index 00000000..22870d94 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/enable/flow.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <chain name="chain1"> + <then value="a,b,c"/> + </chain> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/exception/application.properties b/liteflow-testcase-declare-component/src/test/resources/exception/application.properties new file mode 100644 index 00000000..79b39156 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/exception/application.properties @@ -0,0 +1,2 @@ +liteflow.rule-source=exception/flow.xml +liteflow.when-max-wait-seconds=1 \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/exception/flow.xml b/liteflow-testcase-declare-component/src/test/resources/exception/flow.xml new file mode 100644 index 00000000..e975ef32 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/exception/flow.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <chain name="chain1"> + <then value="a,b,c"/> + </chain> + + <chain name="chain2"> + </chain> + <chain name="chain3"> + <then value="a" /> + <when value="b,c" errorResume="false" /> + </chain> + + <chain name="chain4"> + <then value="c,d"/> + </chain> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/execute2Future/application.properties b/liteflow-testcase-declare-component/src/test/resources/execute2Future/application.properties new file mode 100644 index 00000000..1545d0a1 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/execute2Future/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=execute2Future/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/execute2Future/flow.xml b/liteflow-testcase-declare-component/src/test/resources/execute2Future/flow.xml new file mode 100644 index 00000000..a7517a2c --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/execute2Future/flow.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <chain name="chain1"> + <then value="a,b"/> + <when value="c,d"/> + </chain> + +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/flowmeta/application.properties b/liteflow-testcase-declare-component/src/test/resources/flowmeta/application.properties new file mode 100644 index 00000000..83834c85 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/flowmeta/application.properties @@ -0,0 +1,2 @@ +liteflow.rule-source=flowmeta/flow.xml +liteflow.parse-on-start=false \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/flowmeta/flow.xml b/liteflow-testcase-declare-component/src/test/resources/flowmeta/flow.xml new file mode 100644 index 00000000..7153add8 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/flowmeta/flow.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <chain name="chain1"> + <then value="a,b,c,d"/> + </chain> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/lazy/application.properties b/liteflow-testcase-declare-component/src/test/resources/lazy/application.properties new file mode 100644 index 00000000..372a320c --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/lazy/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=lazy/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/lazy/flow.xml b/liteflow-testcase-declare-component/src/test/resources/lazy/flow.xml new file mode 100644 index 00000000..22870d94 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/lazy/flow.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <chain name="chain1"> + <then value="a,b,c"/> + </chain> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/liteflowComponent/application.properties b/liteflow-testcase-declare-component/src/test/resources/liteflowComponent/application.properties new file mode 100644 index 00000000..62a916d4 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/liteflowComponent/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=liteflowComponent/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/liteflowComponent/flow.xml b/liteflow-testcase-declare-component/src/test/resources/liteflowComponent/flow.xml new file mode 100644 index 00000000..62def0c3 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/liteflowComponent/flow.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <chain name="chain1"> + <then value="a,b,chain2"/> + </chain> + + <chain name="chain2"> + <then value="c,b,a,d"/> + </chain> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/monitor/application.properties b/liteflow-testcase-declare-component/src/test/resources/monitor/application.properties new file mode 100644 index 00000000..ee78cdf4 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/monitor/application.properties @@ -0,0 +1,5 @@ +liteflow.rule-source=monitor/flow.xml +liteflow.monitor.enable-log=true +liteflow.monitor.queue-limit=200 +liteflow.monitor.delay=5000 +liteflow.monitor.period=5000 \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/monitor/flow.xml b/liteflow-testcase-declare-component/src/test/resources/monitor/flow.xml new file mode 100644 index 00000000..e8ea83f9 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/monitor/flow.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <chain name="chain1"> + <then value="a"/> + <when value="b,c"/> + </chain> + +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/multipleType/application.properties b/liteflow-testcase-declare-component/src/test/resources/multipleType/application.properties new file mode 100644 index 00000000..a6da8abe --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/multipleType/application.properties @@ -0,0 +1,2 @@ +liteflow.support-multiple-type=true +liteflow.rule-source=multipleType/flow.xml,multipleType/flow.yml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/multipleType/flow.xml b/liteflow-testcase-declare-component/src/test/resources/multipleType/flow.xml new file mode 100644 index 00000000..38b70321 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/multipleType/flow.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <chain name="chain1"> + <then value="a,b,chain2"/> + </chain> + + <chain name="chain2"> + <then value="c,b,a"/> + </chain> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/multipleType/flow.yml b/liteflow-testcase-declare-component/src/test/resources/multipleType/flow.yml new file mode 100644 index 00000000..4c1d8375 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/multipleType/flow.yml @@ -0,0 +1,6 @@ +flow: + chain: + - name: chain3 + condition: + - type: then + value: 'a,b,c' diff --git a/liteflow-testcase-declare-component/src/test/resources/nodeExecutor/application.properties b/liteflow-testcase-declare-component/src/test/resources/nodeExecutor/application.properties new file mode 100644 index 00000000..b2ca1d08 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/nodeExecutor/application.properties @@ -0,0 +1,4 @@ +liteflow.rule-source=nodeExecutor/flow.xml +liteflow.retry-count=3 +liteflow.slot-size=512 +liteflow.node-executor-class=com.yomahub.liteflow.test.nodeExecutor.CustomerDefaultNodeExecutor \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/nodeExecutor/flow.xml b/liteflow-testcase-declare-component/src/test/resources/nodeExecutor/flow.xml new file mode 100644 index 00000000..6b867c5b --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/nodeExecutor/flow.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <chain name="chain1"> + <then value="a"/> + </chain> + + <chain name="chain2"> + <then value="b"/> + </chain> + + <chain name="chain3"> + <then value="c"/> + </chain> + + <chain name="chain4"> + <then value="d"/> + </chain> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/nullParam/application.properties b/liteflow-testcase-declare-component/src/test/resources/nullParam/application.properties new file mode 100644 index 00000000..7f320b59 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/nullParam/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=nullParam/flow.xml diff --git a/liteflow-testcase-declare-component/src/test/resources/nullParam/flow.xml b/liteflow-testcase-declare-component/src/test/resources/nullParam/flow.xml new file mode 100644 index 00000000..eb30c8e4 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/nullParam/flow.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <chain name="chain1"> + <then value="a,b"/> + <when value="c"/> + </chain> +</flow> diff --git a/liteflow-testcase-declare-component/src/test/resources/parsecustom/application-custom-json.properties b/liteflow-testcase-declare-component/src/test/resources/parsecustom/application-custom-json.properties new file mode 100644 index 00000000..989a199c --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/parsecustom/application-custom-json.properties @@ -0,0 +1 @@ +liteflow.rule-source=com.yomahub.liteflow.test.parsecustom.parser.CustomJsonFlowParser \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/parsecustom/application-custom-xml.properties b/liteflow-testcase-declare-component/src/test/resources/parsecustom/application-custom-xml.properties new file mode 100644 index 00000000..c1763fe1 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/parsecustom/application-custom-xml.properties @@ -0,0 +1 @@ +liteflow.rule-source=com.yomahub.liteflow.test.parsecustom.parser.CustomXmlFlowParser \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/parser/application-json.properties b/liteflow-testcase-declare-component/src/test/resources/parser/application-json.properties new file mode 100644 index 00000000..e8b24722 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/parser/application-json.properties @@ -0,0 +1 @@ +liteflow.rule-source=parser/flow.json \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/parser/application-springEL.properties b/liteflow-testcase-declare-component/src/test/resources/parser/application-springEL.properties new file mode 100644 index 00000000..7db93206 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/parser/application-springEL.properties @@ -0,0 +1 @@ +liteflow.rule-source=parser/**/*.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/parser/application-xml.properties b/liteflow-testcase-declare-component/src/test/resources/parser/application-xml.properties new file mode 100644 index 00000000..d8aacc36 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/parser/application-xml.properties @@ -0,0 +1 @@ +liteflow.rule-source=parser/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/parser/application-yml.properties b/liteflow-testcase-declare-component/src/test/resources/parser/application-yml.properties new file mode 100644 index 00000000..e0680a12 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/parser/application-yml.properties @@ -0,0 +1 @@ +liteflow.rule-source=parser/flow.yml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/parser/flow.json b/liteflow-testcase-declare-component/src/test/resources/parser/flow.json new file mode 100644 index 00000000..52d0d05c --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/parser/flow.json @@ -0,0 +1,52 @@ +{ + "flow": { + "nodes": { + "node": [ + { + "id": "a", + "class": "com.yomahub.liteflow.test.parser.cmp.ACmp" + }, + { + "id": "b", + "class": "com.yomahub.liteflow.test.parser.cmp.BCmp" + }, + { + "id": "c", + "class": "com.yomahub.liteflow.test.parser.cmp.CCmp" + }, + { + "id": "d", + "class": "com.yomahub.liteflow.test.parser.cmp.DCmp" + }, + { + "id": "e", + "class": "com.yomahub.liteflow.test.parser.cmp.ECmp" + }, + { + "id": "f", + "class": "com.yomahub.liteflow.test.parser.cmp.FCmp" + }, + { + "id": "g", + "class": "com.yomahub.liteflow.test.parser.cmp.GCmp" + } + ] + }, + "chain": [ + { + "name": "chain2", + "condition": [ + {"type": "then", "value": "c,g,f"} + ] + }, + { + "name": "chain1", + "condition": [ + {"type": "then", "value": "a,c"}, + {"type": "when", "value": "b,d,e(f|g)"}, + {"type": "then", "value": "chain2"} + ] + } + ] + } +} \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/parser/flow.xml b/liteflow-testcase-declare-component/src/test/resources/parser/flow.xml new file mode 100644 index 00000000..0775c5ec --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/parser/flow.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <nodes> + <node id="a" class="com.yomahub.liteflow.test.parser.cmp.ACmp"/> + <node id="b" class="com.yomahub.liteflow.test.parser.cmp.BCmp"/> + <node id="c" class="com.yomahub.liteflow.test.parser.cmp.CCmp"/> + <node id="d" class="com.yomahub.liteflow.test.parser.cmp.DCmp"/> + <node id="e" class="com.yomahub.liteflow.test.parser.cmp.ECmp"/> + <node id="f" class="com.yomahub.liteflow.test.parser.cmp.FCmp"/> + <node id="g" class="com.yomahub.liteflow.test.parser.cmp.GCmp"/> + </nodes> + + <chain name="chain1"> + <then value="a,c"/> + <when value="b,d,e(f|g)"/> + <then value="chain2"/> + </chain> + + <chain name="chain2"> + <then value="c,g,f"/> + </chain> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/parser/flow.yml b/liteflow-testcase-declare-component/src/test/resources/parser/flow.yml new file mode 100644 index 00000000..814f59d5 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/parser/flow.yml @@ -0,0 +1,30 @@ +flow: + nodes: + node: + - id: a + class: com.yomahub.liteflow.test.parser.cmp.ACmp + - id: b + class: com.yomahub.liteflow.test.parser.cmp.BCmp + - id: c + class: com.yomahub.liteflow.test.parser.cmp.CCmp + - id: d + class: com.yomahub.liteflow.test.parser.cmp.DCmp + - id: e + class: com.yomahub.liteflow.test.parser.cmp.ECmp + - id: f + class: com.yomahub.liteflow.test.parser.cmp.FCmp + - id: g + class: com.yomahub.liteflow.test.parser.cmp.GCmp + chain: + - name: chain1 + condition: + - type: then + value: 'a,c' + - type: when + value: 'b,d,e(f|g)' + - type: then + value: 'chain2' + - name: chain2 + condition: + - type: then + value: 'c,g,f' diff --git a/liteflow-testcase-declare-component/src/test/resources/parser/subFoder1/subFoder2/flow1.xml b/liteflow-testcase-declare-component/src/test/resources/parser/subFoder1/subFoder2/flow1.xml new file mode 100644 index 00000000..0775c5ec --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/parser/subFoder1/subFoder2/flow1.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <nodes> + <node id="a" class="com.yomahub.liteflow.test.parser.cmp.ACmp"/> + <node id="b" class="com.yomahub.liteflow.test.parser.cmp.BCmp"/> + <node id="c" class="com.yomahub.liteflow.test.parser.cmp.CCmp"/> + <node id="d" class="com.yomahub.liteflow.test.parser.cmp.DCmp"/> + <node id="e" class="com.yomahub.liteflow.test.parser.cmp.ECmp"/> + <node id="f" class="com.yomahub.liteflow.test.parser.cmp.FCmp"/> + <node id="g" class="com.yomahub.liteflow.test.parser.cmp.GCmp"/> + </nodes> + + <chain name="chain1"> + <then value="a,c"/> + <when value="b,d,e(f|g)"/> + <then value="chain2"/> + </chain> + + <chain name="chain2"> + <then value="c,g,f"/> + </chain> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/parser/subFoder1/subFoder2/flow2.xml b/liteflow-testcase-declare-component/src/test/resources/parser/subFoder1/subFoder2/flow2.xml new file mode 100644 index 00000000..d739f6b5 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/parser/subFoder1/subFoder2/flow2.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + + <chain name="chain1"> + <then value="a,c"/> + <when value="b,d,e(f|g)"/> + <then value="chain2"/> + </chain> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/parser/subFoder1/subFoder2/flow3.xml b/liteflow-testcase-declare-component/src/test/resources/parser/subFoder1/subFoder2/flow3.xml new file mode 100644 index 00000000..0a898126 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/parser/subFoder1/subFoder2/flow3.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <chain name="chain2"> + <then value="c,g,f"/> + </chain> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/preAndFinally/application.properties b/liteflow-testcase-declare-component/src/test/resources/preAndFinally/application.properties new file mode 100644 index 00000000..9ea8432e --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/preAndFinally/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=preAndFinally/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/preAndFinally/flow.xml b/liteflow-testcase-declare-component/src/test/resources/preAndFinally/flow.xml new file mode 100644 index 00000000..5dac9fb0 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/preAndFinally/flow.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <chain name="chain1"> + <pre value="p1,p2"/> + <then value="a,b,c"/> + <finally value="f1,f2"/> + </chain> + + <chain name="chain2"> + <then value="a"/> + <pre value="p1,p2"/> + <finally value="f1,f2"/> + <then value="b,c"/> + </chain> + + <chain name="chain3"> + <pre value="p1,p2"/> + <then value="a,d,c"/> + <finally value="f1,f2"/> + </chain> + + <chain name="chain4"> + <then value="a,d,c"/> + <finally value="f3"/> + </chain> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/privateDelivery/application.properties b/liteflow-testcase-declare-component/src/test/resources/privateDelivery/application.properties new file mode 100644 index 00000000..c515ad38 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/privateDelivery/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=privateDelivery/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/privateDelivery/flow.xml b/liteflow-testcase-declare-component/src/test/resources/privateDelivery/flow.xml new file mode 100644 index 00000000..bf714621 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/privateDelivery/flow.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <chain name="chain1"> + <then value="a"/> + <!-- 100个b组件并发 --> + <when value="b,b,b,b,b,b,b,b,b,b"/> + <when value="b,b,b,b,b,b,b,b,b,b"/> + <when value="b,b,b,b,b,b,b,b,b,b"/> + <when value="b,b,b,b,b,b,b,b,b,b"/> + <when value="b,b,b,b,b,b,b,b,b,b"/> + <when value="b,b,b,b,b,b,b,b,b,b"/> + <when value="b,b,b,b,b,b,b,b,b,b"/> + <when value="b,b,b,b,b,b,b,b,b,b"/> + <when value="b,b,b,b,b,b,b,b,b,b"/> + <when value="b,b,b,b,b,b,b,b,b,b"/> + <then value="c"/> + </chain> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/refreshRule/application.properties b/liteflow-testcase-declare-component/src/test/resources/refreshRule/application.properties new file mode 100644 index 00000000..174501a6 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/refreshRule/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=refreshRule/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/refreshRule/flow.xml b/liteflow-testcase-declare-component/src/test/resources/refreshRule/flow.xml new file mode 100644 index 00000000..22870d94 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/refreshRule/flow.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <chain name="chain1"> + <then value="a,b,c"/> + </chain> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/refreshRule/flow_update.xml b/liteflow-testcase-declare-component/src/test/resources/refreshRule/flow_update.xml new file mode 100644 index 00000000..29090f04 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/refreshRule/flow_update.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <chain name="chain1"> + <then value="c,b,a"/> + </chain> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/reload/application.properties b/liteflow-testcase-declare-component/src/test/resources/reload/application.properties new file mode 100644 index 00000000..5150bc23 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/reload/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=reload/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/reload/flow.xml b/liteflow-testcase-declare-component/src/test/resources/reload/flow.xml new file mode 100644 index 00000000..22870d94 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/reload/flow.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <chain name="chain1"> + <then value="a,b,c"/> + </chain> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/removeChain/application.properties b/liteflow-testcase-declare-component/src/test/resources/removeChain/application.properties new file mode 100644 index 00000000..72987950 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/removeChain/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=removeChain/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/removeChain/flow.xml b/liteflow-testcase-declare-component/src/test/resources/removeChain/flow.xml new file mode 100644 index 00000000..c89c4447 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/removeChain/flow.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <chain name="chain1"> + <then value="a,b"/> + <when value="c,d"/> + </chain> + + <chain name="chain2"> + <then value="a,b,c,d"/> + </chain> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/resizeSlot/application.properties b/liteflow-testcase-declare-component/src/test/resources/resizeSlot/application.properties new file mode 100644 index 00000000..6bea4bd1 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/resizeSlot/application.properties @@ -0,0 +1,2 @@ +liteflow.rule-source=resizeSlot/flow.xml +liteflow.slot-size=4 \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/resizeSlot/flow.xml b/liteflow-testcase-declare-component/src/test/resources/resizeSlot/flow.xml new file mode 100644 index 00000000..22870d94 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/resizeSlot/flow.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <chain name="chain1"> + <then value="a,b,c"/> + </chain> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/subflow/application-implicit.properties b/liteflow-testcase-declare-component/src/test/resources/subflow/application-implicit.properties new file mode 100644 index 00000000..3fc4f024 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/subflow/application-implicit.properties @@ -0,0 +1 @@ +liteflow.rule-source=subflow/flow-implicit.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/subflow/application-json.properties b/liteflow-testcase-declare-component/src/test/resources/subflow/application-json.properties new file mode 100644 index 00000000..7ca7b7be --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/subflow/application-json.properties @@ -0,0 +1 @@ +liteflow.rule-source=subflow/flow.json \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/subflow/application-subInDifferentConfig1.properties b/liteflow-testcase-declare-component/src/test/resources/subflow/application-subInDifferentConfig1.properties new file mode 100644 index 00000000..8c77ba82 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/subflow/application-subInDifferentConfig1.properties @@ -0,0 +1 @@ +liteflow.rule-source=subflow/flow-main.xml,subflow/flow-sub1.xml,subflow/flow-sub2.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/subflow/application-subInDifferentConfig2.properties b/liteflow-testcase-declare-component/src/test/resources/subflow/application-subInDifferentConfig2.properties new file mode 100644 index 00000000..e02c3b6a --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/subflow/application-subInDifferentConfig2.properties @@ -0,0 +1 @@ +liteflow.rule-source=subflow/flow-main.xml,subflow/flow-sub1.xml,subflow/flow-sub2.yml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/subflow/application-xml.properties b/liteflow-testcase-declare-component/src/test/resources/subflow/application-xml.properties new file mode 100644 index 00000000..1abd5049 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/subflow/application-xml.properties @@ -0,0 +1 @@ +liteflow.rule-source=subflow/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/subflow/application-yml.properties b/liteflow-testcase-declare-component/src/test/resources/subflow/application-yml.properties new file mode 100644 index 00000000..72074ec8 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/subflow/application-yml.properties @@ -0,0 +1 @@ +liteflow.rule-source=subflow/flow.yml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/subflow/flow-implicit.xml b/liteflow-testcase-declare-component/src/test/resources/subflow/flow-implicit.xml new file mode 100644 index 00000000..5baca707 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/subflow/flow-implicit.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <chain name="chain3"> + <then value="f,g"/> <!-- g隐式调用chain4 --> + </chain> + + <chain name="chain4"> + <then value="h,m"/> + </chain> + <!-- f,g,h,m --> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/subflow/flow-main.xml b/liteflow-testcase-declare-component/src/test/resources/subflow/flow-main.xml new file mode 100644 index 00000000..0adf54fc --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/subflow/flow-main.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <chain name="chain1"> + <then value="a,b"/> + <then value="chain2"/> <!-- 测试调用c流程后是否正常调用chain2 --> + </chain> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/subflow/flow-sub1.xml b/liteflow-testcase-declare-component/src/test/resources/subflow/flow-sub1.xml new file mode 100644 index 00000000..471dee3f --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/subflow/flow-sub1.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <chain name="chain2"> + <then value="b,a"/> + <then value="chain3"/> + </chain> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/subflow/flow-sub2.xml b/liteflow-testcase-declare-component/src/test/resources/subflow/flow-sub2.xml new file mode 100644 index 00000000..63dd964b --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/subflow/flow-sub2.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <chain name="chain3"> + <then value="e,d"/> + </chain> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/subflow/flow-sub2.yml b/liteflow-testcase-declare-component/src/test/resources/subflow/flow-sub2.yml new file mode 100644 index 00000000..8ba43c10 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/subflow/flow-sub2.yml @@ -0,0 +1,6 @@ +flow: + chain: + - name: chain3 + condition: + - type: then + value: 'e,d' \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/subflow/flow.json b/liteflow-testcase-declare-component/src/test/resources/subflow/flow.json new file mode 100644 index 00000000..14358931 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/subflow/flow.json @@ -0,0 +1,33 @@ +{ + "flow": { + "chain": [ + { + "name": "chain3", + "condition": [ + {"type": "then", "value": "e,d"} + ] + }, + { + "name": "chain2", + "condition": [ + {"type": "then", "value": "b,a"}, + {"type": "then", "value": "chain3"} + ] + }, + { + "name": "chain1", + "condition": [ + {"type": "then", "value": "a,b"}, + {"type": "then", "value": "c"}, + {"type": "then", "value": "chain2"} + ] + }, + { + "name": "c", + "condition": [ + {"type": "then", "value": "d,e"} + ] + } + ] + } +} \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/subflow/flow.xml b/liteflow-testcase-declare-component/src/test/resources/subflow/flow.xml new file mode 100644 index 00000000..03cf8129 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/subflow/flow.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <chain name="chain1"> + <then value="a,b"/> + <then value="c"/> <!-- 显式的调用了chain(c),当这里存在Node(c)时,测试是否为优先调用了Node(c)--> + <then value="chain2"/> <!-- 测试调用c流程后是否正常调用chain2 --> + </chain> + + <chain name="c"> + <then value="d,e"/> + </chain> + + <chain name="chain2"> + <then value="b,a"/> + <then value="chain3"/> + </chain> + + <chain name="chain3"> + <then value="e,d"/> + </chain> + <!-- a,b,c,b,a,e,d --> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/subflow/flow.yml b/liteflow-testcase-declare-component/src/test/resources/subflow/flow.yml new file mode 100644 index 00000000..cdd8de74 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/subflow/flow.yml @@ -0,0 +1,24 @@ +flow: + chain: + - name: chain3 + condition: + - type: then + value: 'e,d' + - name: chain1 + condition: + - type: then + value: 'a,b' + - type: then + value: 'c' + - type: then + value: 'chain2' + - name: c + condition: + - type: then + value: 'd,e' + - name: chain2 + condition: + - type: then + value: 'b,a' + - type: then + value: 'chain3' \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/tag/application-json.properties b/liteflow-testcase-declare-component/src/test/resources/tag/application-json.properties new file mode 100644 index 00000000..2f9c09d4 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/tag/application-json.properties @@ -0,0 +1 @@ +liteflow.rule-source=tag/flow.json \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/tag/application-xml.properties b/liteflow-testcase-declare-component/src/test/resources/tag/application-xml.properties new file mode 100644 index 00000000..cc52d7cb --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/tag/application-xml.properties @@ -0,0 +1 @@ +liteflow.rule-source=tag/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/tag/flow.json b/liteflow-testcase-declare-component/src/test/resources/tag/flow.json new file mode 100644 index 00000000..49c902e4 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/tag/flow.json @@ -0,0 +1,31 @@ +{ + "flow": { + "chain": [ + { + "name": "chain1", + "condition": [ + {"type": "then", "value": "a[1],a[2],a[3]"} + ] + }, + { + "name": "chain2", + "condition": [ + {"type": "then", "value": "a[1],a[2],a[3],c[2](d[5]|e[6])"} + ] + }, + { + "name": "chain3", + "condition": [ + {"type": "then", "value": "b1"}, + {"type": "when", "value": "b[1],b[2],b[3]"} + ] + }, + { + "name": "chain4", + "condition": [ + {"type": "then", "value": "f[false],g"} + ] + } + ] + } +} \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/tag/flow.xml b/liteflow-testcase-declare-component/src/test/resources/tag/flow.xml new file mode 100644 index 00000000..b7ceb903 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/tag/flow.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <chain name="chain1"> + <then value="a[1],a[2],a[3]"/> + </chain> + + <chain name="chain2"> + <then value="a[1],a[2],a[3],c[2](d[5]|e[6])"/> + </chain> + + <chain name="chain3"> + <then value="b1"/> + <when value="b[1],b[2],b[3]"/> + </chain> + + <chain name="chain4"> + <then value="f[false],g"/> + </chain> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/useTTLInWhen/application.properties b/liteflow-testcase-declare-component/src/test/resources/useTTLInWhen/application.properties new file mode 100644 index 00000000..58d40f9a --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/useTTLInWhen/application.properties @@ -0,0 +1,2 @@ +liteflow.rule-source=useTTLInWhen/flow.xml +liteflow.when-max-workers=2 \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/useTTLInWhen/flow.xml b/liteflow-testcase-declare-component/src/test/resources/useTTLInWhen/flow.xml new file mode 100644 index 00000000..af6d2ef5 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/useTTLInWhen/flow.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <chain name="chain1"> + <then value="a"/> + <when value="b,c,d,e,f"/> + </chain> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/whenTimeOut/application1.properties b/liteflow-testcase-declare-component/src/test/resources/whenTimeOut/application1.properties new file mode 100644 index 00000000..05eb9ab0 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/whenTimeOut/application1.properties @@ -0,0 +1,2 @@ +liteflow.rule-source=whenTimeOut/flow1.xml +liteflow.when-max-wait-seconds=3 \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/whenTimeOut/application2.properties b/liteflow-testcase-declare-component/src/test/resources/whenTimeOut/application2.properties new file mode 100644 index 00000000..b90ff9c3 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/whenTimeOut/application2.properties @@ -0,0 +1,2 @@ +liteflow.rule-source=whenTimeOut/flow2.xml +liteflow.when-max-wait-seconds=5 \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/whenTimeOut/flow1.xml b/liteflow-testcase-declare-component/src/test/resources/whenTimeOut/flow1.xml new file mode 100644 index 00000000..657f64cc --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/whenTimeOut/flow1.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <chain name="chain1"> + <when value="a,b,c"/> + </chain> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/whenTimeOut/flow2.xml b/liteflow-testcase-declare-component/src/test/resources/whenTimeOut/flow2.xml new file mode 100644 index 00000000..6586ab0b --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/whenTimeOut/flow2.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <chain name="chain1"> + <when value="d" group="1"/> + <when value="e" group="2"/> + <when value="f" group="3"/> + </chain> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/zookeeper/application-json.properties b/liteflow-testcase-declare-component/src/test/resources/zookeeper/application-json.properties new file mode 100644 index 00000000..50d6ddca --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/zookeeper/application-json.properties @@ -0,0 +1 @@ +liteflow.rule-source=json:127.0.0.1:21810 \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/zookeeper/application-xml.properties b/liteflow-testcase-declare-component/src/test/resources/zookeeper/application-xml.properties new file mode 100644 index 00000000..e56e9975 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/zookeeper/application-xml.properties @@ -0,0 +1 @@ +liteflow.rule-source=xml:127.0.0.1:21810 \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/zookeeper/application-yml.properties b/liteflow-testcase-declare-component/src/test/resources/zookeeper/application-yml.properties new file mode 100644 index 00000000..9c88b3fd --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/zookeeper/application-yml.properties @@ -0,0 +1 @@ +liteflow.rule-source=yml:127.0.0.1:21810 \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/zookeeper/flow.json b/liteflow-testcase-declare-component/src/test/resources/zookeeper/flow.json new file mode 100644 index 00000000..24615d62 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/zookeeper/flow.json @@ -0,0 +1,12 @@ +{ + "flow": { + "chain": [ + { + "name": "chain1", + "condition": [ + {"type": "then", "value": "a,b,c"} + ] + } + ] + } +} \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/zookeeper/flow.xml b/liteflow-testcase-declare-component/src/test/resources/zookeeper/flow.xml new file mode 100644 index 00000000..22870d94 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/zookeeper/flow.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<flow> + <chain name="chain1"> + <then value="a,b,c"/> + </chain> +</flow> \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/zookeeper/flow.yml b/liteflow-testcase-declare-component/src/test/resources/zookeeper/flow.yml new file mode 100644 index 00000000..3cdaced3 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/zookeeper/flow.yml @@ -0,0 +1,6 @@ +flow: + chain: + - name: chain1 + condition: + - type: then + value: 'a,b,c' diff --git a/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeTest.java b/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeTest.java index acc563cf..0988be13 100644 --- a/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeTest.java +++ b/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeTest.java @@ -28,7 +28,7 @@ public class LiteflowMultipleTypeTest extends BaseTest { } @Test - public void testConfig() { + public void testMultipleType() { LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg"); Assert.assertTrue(response.isSuccess()); Assert.assertEquals("a==>b==>c==>b==>a", response.getSlot().getExecuteStepStr()); diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeSpringbootTest.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeSpringbootTest.java index 20d2c85d..91ef144e 100644 --- a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeSpringbootTest.java +++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeSpringbootTest.java @@ -31,7 +31,7 @@ public class LiteflowMultipleTypeSpringbootTest extends BaseTest { private FlowExecutor flowExecutor; @Test - public void testConfig() { + public void testMultipleType() { LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg"); Assert.assertTrue(response.isSuccess()); Assert.assertEquals("a==>b==>c==>b==>a", response.getSlot().getExecuteStepStr()); diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeSpringTest.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeSpringTest.java index 7a9f95d9..8207ff5c 100644 --- a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeSpringTest.java +++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeSpringTest.java @@ -25,7 +25,7 @@ public class LiteflowMultipleTypeSpringTest extends BaseTest { private FlowExecutor flowExecutor; @Test - public void testConfig() { + public void testMultipleType() { LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg"); Assert.assertTrue(response.isSuccess()); Assert.assertEquals("a==>b==>c==>b==>a", response.getSlot().getExecuteStepStr()); diff --git a/pom.xml b/pom.xml index dcf98531..8714790c 100644 --- a/pom.xml +++ b/pom.xml @@ -55,6 +55,7 @@ <zkclient.version>0.10</zkclient.version> <qlexpress.version>3.2.7</qlexpress.version> <groovy.version>3.0.8</groovy.version> + <bytebuddy.version>1.11.13</bytebuddy.version> </properties> <dependencyManagement> @@ -177,6 +178,11 @@ <artifactId>groovy-jsr223</artifactId> <version>${groovy.version}</version> </dependency> + <dependency> + <groupId>net.bytebuddy</groupId> + <artifactId>byte-buddy</artifactId> + <version>${bytebuddy.version}</version> + </dependency> </dependencies> </dependencyManagement> @@ -255,7 +261,8 @@ <module>liteflow-testcase-script-groovy</module> <module>liteflow-testcase-nospring</module> <module>liteflow-spring</module> - </modules> + <module>liteflow-testcase-declare-component</module> + </modules> <distributionManagement> <snapshotRepository>