补充测试用例

This commit is contained in:
bryan31
2022-03-07 19:19:12 +08:00
parent d1421adc53
commit 2114394baa
51 changed files with 708 additions and 23 deletions

View File

@@ -1,5 +1,6 @@
package com.yomahub.liteflow.test;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.flow.FlowBus;
import com.yomahub.liteflow.property.LiteflowConfigGetter;
import com.yomahub.liteflow.spi.holder.SpiFactoryCleaner;
@@ -14,5 +15,6 @@ public class BaseTest {
ExecutorHelper.loadInstance().clearExecutorServiceMap();
SpiFactoryCleaner.clean();
LiteflowConfigGetter.clean();
FlowExecutorHolder.clean();
}
}

View File

@@ -1,6 +1,7 @@
package com.yomahub.liteflow.test.absoluteConfigPath;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.property.LiteflowConfig;
@@ -22,7 +23,7 @@ public class AbsoluteConfigPathTest extends BaseTest {
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("/usr/local/flow2.xml");
flowExecutor = FlowExecutor.loadInstance(config);
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
@Test

View File

@@ -2,6 +2,7 @@ package com.yomahub.liteflow.test.asyncNode;
import cn.hutool.core.collection.ListUtil;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.property.LiteflowConfig;
@@ -27,7 +28,7 @@ public class AsyncNodeTest extends BaseTest {
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("asyncNode/flow.xml");
flowExecutor = FlowExecutor.loadInstance(config);
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
/*****

View File

@@ -1,6 +1,7 @@
package com.yomahub.liteflow.test.base;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.property.LiteflowConfig;
@@ -16,7 +17,7 @@ public class BaseCommonTest {
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("base/flow.xml");
flowExecutor = FlowExecutor.loadInstance(config);
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
@Test

View File

@@ -4,6 +4,7 @@ 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.core.FlowExecutorHolder;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.enums.NodeTypeEnum;
@@ -20,7 +21,7 @@ public class BuilderTest extends BaseTest {
@BeforeClass
public static void init(){
LiteflowConfig config = new LiteflowConfig();
flowExecutor = FlowExecutor.loadInstance(config);
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
//基于普通组件的builder模式测试

View File

@@ -1,6 +1,7 @@
package com.yomahub.liteflow.test.cmpRetry;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.property.LiteflowConfig;
@@ -28,7 +29,7 @@ public class LiteflowRetryTest extends BaseTest {
config.setRuleSource("cmpRetry/flow.xml");
config.setRetryCount(3);
config.setSlotSize(512);
flowExecutor = FlowExecutor.loadInstance(config);
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
//全局重试配置测试

View File

@@ -1,6 +1,7 @@
package com.yomahub.liteflow.test.component;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.property.LiteflowConfig;
@@ -24,7 +25,7 @@ public class FlowExecutorTest extends BaseTest {
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("component/flow.xml");
flowExecutor = FlowExecutor.loadInstance(config);
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
//isAccess方法的功能测试

View File

@@ -1,6 +1,7 @@
package com.yomahub.liteflow.test.config;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.property.LiteflowConfig;
@@ -23,7 +24,7 @@ public class LiteflowConfigTest1 extends BaseTest {
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("config/flow.xml");
flowExecutor = FlowExecutor.loadInstance(config);
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
@Test

View File

@@ -1,6 +1,7 @@
package com.yomahub.liteflow.test.customWhenThreadPool;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.property.LiteflowConfig;
@@ -23,7 +24,7 @@ public class CustomWhenThreadPoolTest extends BaseTest {
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("customWhenThreadPool/flow.xml");
flowExecutor = FlowExecutor.loadInstance(config);
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
/**

View File

@@ -1,6 +1,7 @@
package com.yomahub.liteflow.test.emptyflow;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.BeforeClass;
@@ -18,7 +19,7 @@ public class EmptyFlowTest extends BaseTest {
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("emptyflow/flow.xml");
flowExecutor = FlowExecutor.loadInstance(config);
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
//测试空flow的情况下liteflow是否能正常启动

View File

@@ -1,6 +1,7 @@
package com.yomahub.liteflow.test.exception;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.exception.ChainNotFoundException;
@@ -28,7 +29,7 @@ public class ExceptionTest extends BaseTest {
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("exception/flow.xml");
config.setWhenMaxWaitSeconds(1);
flowExecutor = FlowExecutor.loadInstance(config);
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
@Test(expected = FlowExecutorNotInitException.class)

View File

@@ -1,6 +1,7 @@
package com.yomahub.liteflow.test.flowmeta;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.flow.FlowBus;
@@ -20,7 +21,7 @@ public class FlowMetaTest extends BaseTest {
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("flowmeta/flow.xml");
config.setParseOnStart(false);
flowExecutor = FlowExecutor.loadInstance(config);
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
//测试动态添加元信息节点

View File

@@ -1,6 +1,7 @@
package com.yomahub.liteflow.test.multipleType;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.property.LiteflowConfig;
@@ -23,7 +24,7 @@ public class LiteflowMultipleTypeTest extends BaseTest {
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("multipleType/flow.xml,multipleType/flow.yml");
config.setSupportMultipleType(true);
flowExecutor = FlowExecutor.loadInstance(config);
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
@Test

View File

@@ -1,6 +1,7 @@
package com.yomahub.liteflow.test.nodeExecutor;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.property.LiteflowConfig;
@@ -26,7 +27,7 @@ public class LiteflowNodeExecutorTest extends BaseTest {
config.setRetryCount(3);
config.setSlotSize(512);
config.setNodeExecutorClass("com.yomahub.liteflow.test.nodeExecutor.CustomerDefaultNodeExecutor");
flowExecutor = FlowExecutor.loadInstance(config);
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
// 默认执行器测试

View File

@@ -1,6 +1,7 @@
package com.yomahub.liteflow.test.nullParam;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.property.LiteflowConfig;
@@ -22,7 +23,7 @@ public class NullParamTest {
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("nullParam/flow.xml");
flowExecutor = FlowExecutor.loadInstance(config);
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
/**

View File

@@ -1,6 +1,7 @@
package com.yomahub.liteflow.test.parsecustom;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.property.LiteflowConfig;
@@ -22,7 +23,7 @@ public class CustomParserJsonTest extends BaseTest {
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("com.yomahub.liteflow.test.parsecustom.parser.CustomJsonFlowParser");
flowExecutor = FlowExecutor.loadInstance(config);
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
//测试springboot场景的自定义json parser

View File

@@ -1,6 +1,7 @@
package com.yomahub.liteflow.test.parsecustom;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.property.LiteflowConfig;
@@ -22,7 +23,7 @@ public class CustomParserXmlTest extends BaseTest {
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("com.yomahub.liteflow.test.parsecustom.parser.CustomXmlFlowParser");
flowExecutor = FlowExecutor.loadInstance(config);
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
//测试springboot场景的自定义json parser

View File

@@ -1,6 +1,7 @@
package com.yomahub.liteflow.test.parser;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.property.LiteflowConfig;
@@ -22,7 +23,7 @@ public class JsonParserTest extends BaseTest {
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("parser/flow.json");
flowExecutor = FlowExecutor.loadInstance(config);
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
//测试spring场景的json parser

View File

@@ -1,6 +1,7 @@
package com.yomahub.liteflow.test.parser;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.property.LiteflowConfig;
@@ -22,7 +23,7 @@ public class XmlParserTest extends BaseTest {
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("parser/flow.xml");
flowExecutor = FlowExecutor.loadInstance(config);
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
//测试无springboot场景的xml parser

View File

@@ -1,6 +1,7 @@
package com.yomahub.liteflow.test.parser;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.property.LiteflowConfig;
@@ -22,7 +23,7 @@ public class YmlParserTest extends BaseTest {
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("parser/flow.yml");
flowExecutor = FlowExecutor.loadInstance(config);
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
//测试无springboot场景的yml parser

View File

@@ -1,6 +1,7 @@
package com.yomahub.liteflow.test.preAndFinally;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.property.LiteflowConfig;
@@ -22,7 +23,7 @@ public class PreAndFinallyTest extends BaseTest {
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("preAndFinally/flow.xml");
flowExecutor = FlowExecutor.loadInstance(config);
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
//测试普通的pre和finally节点

View File

@@ -1,6 +1,7 @@
package com.yomahub.liteflow.test.privateDelivery;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.property.LiteflowConfig;
@@ -23,7 +24,7 @@ public class PrivateDeliveryTest extends BaseTest {
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("privateDelivery/flow.xml");
flowExecutor = FlowExecutor.loadInstance(config);
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
@Test

View File

@@ -2,6 +2,7 @@ package com.yomahub.liteflow.test.refreshRule;
import cn.hutool.core.io.resource.ResourceUtil;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.enums.FlowParserTypeEnum;
@@ -25,7 +26,7 @@ public class RefreshRuleTest extends BaseTest {
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("refreshRule/flow.xml");
flowExecutor = FlowExecutor.loadInstance(config);
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
//测试普通刷新流程的场景

View File

@@ -1,6 +1,7 @@
package com.yomahub.liteflow.test.reload;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.property.LiteflowConfig;
@@ -22,7 +23,7 @@ public class ReloadTest extends BaseTest {
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("reload/flow.xml");
flowExecutor = FlowExecutor.loadInstance(config);
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
//用reloadRule去重新加载这里如果配置是放在本地。如果想修改则要去修改target下面的flow.xml

View File

@@ -0,0 +1,62 @@
package com.yomahub.liteflow.test.resizeSlot;
import cn.hutool.core.util.ReflectUtil;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
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.property.LiteflowConfig;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
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
*/
public class ResizeSlotTest extends BaseTest {
private static FlowExecutor flowExecutor;
@BeforeClass
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("resizeSlot/flow.xml");
config.setSlotSize(4);
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
@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次=656次=114
//为什么不是直接114呢
//因为在单测中根据机器的性能在多线程情况下有些机器跑的慢一点也就是说65个就足够了。有些机器跑的快一点是能真正扩容到114个的
Assert.assertTrue(queue.size() > 4);
}
}

View File

@@ -0,0 +1,18 @@
/**
* <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.core.NodeComponent;
public class ACmp extends NodeComponent {
@Override
public void process() {
System.out.println("ACmp executed!");
}
}

View File

@@ -0,0 +1,19 @@
/**
* <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.core.NodeComponent;
public class BCmp extends NodeComponent {
@Override
public void process() {
System.out.println("BCmp executed!");
}
}

View File

@@ -0,0 +1,19 @@
/**
* <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.core.NodeComponent;
public class CCmp extends NodeComponent {
@Override
public void process() {
System.out.println("CCmp executed!");
}
}

View File

@@ -0,0 +1,46 @@
package com.yomahub.liteflow.test.subflow;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import java.util.HashSet;
import java.util.Set;
/**
* 测试隐式调用子流程
* 单元测试
*
* @author justin.xu
*/
public class ImplicitSubFlowTest extends BaseTest {
private static FlowExecutor flowExecutor;
@BeforeClass
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("subflow/flow-implicit.xml");
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
public static final Set<String> RUN_TIME_SLOT = new HashSet<>();
//这里GCmp中隐式的调用chain4从而执行了hm
@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()));
}
}

View File

@@ -0,0 +1,46 @@
package com.yomahub.liteflow.test.subflow;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
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.property.LiteflowConfigGetter;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* 测试主流程与子流程在不同的配置文件的场景
*
* @author Bryan.Zhang
*/
public class SubflowInDifferentConfigTest extends BaseTest {
private static FlowExecutor flowExecutor;
@BeforeClass
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("subflow/flow-main.xml,subflow/flow-sub1.xml,subflow/flow-sub2.xml");
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
//是否按照流程定义配置执行
@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());
}
//主要测试有不同的配置类型后会不会报出既定的错误
@Test(expected = MultipleParsersException.class)
public void testExplicitSubFlow2() {
LiteflowConfig config = LiteflowConfigGetter.get();
config.setRuleSource("subflow/flow-main.xml,subflow/flow-sub1.xml,subflow/flow-sub2.yml");
flowExecutor.init();
}
}

View File

@@ -0,0 +1,37 @@
package com.yomahub.liteflow.test.subflow;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* 测试显示调用子流程(json)
* 单元测试
*
* @author justin.xu
*/
public class SubflowJsonTest extends BaseTest {
private static FlowExecutor flowExecutor;
@BeforeClass
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("subflow/flow.json");
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
//是否按照流程定义配置执行
@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());
}
}

View File

@@ -0,0 +1,37 @@
package com.yomahub.liteflow.test.subflow;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* 测试显示调用子流程(xml)
* 单元测试
*
* @author justin.xu
*/
public class SubflowXMLTest extends BaseTest {
private static FlowExecutor flowExecutor;
@BeforeClass
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("subflow/flow.xml");
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
//是否按照流程定义配置执行
@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());
}
}

View File

@@ -0,0 +1,37 @@
package com.yomahub.liteflow.test.subflow;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* 测试显示调用子流程(yml)
* 单元测试
*
* @author justin.xu
*/
public class SubflowYmlTest extends BaseTest {
private static FlowExecutor flowExecutor;
@BeforeClass
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("subflow/flow.yml");
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
//是否按照流程定义配置执行
@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());
}
}

View File

@@ -0,0 +1,11 @@
package com.yomahub.liteflow.test.subflow.cmp1;
import com.yomahub.liteflow.core.NodeComponent;
public class ACmp extends NodeComponent {
@Override
public void process() {
System.out.println("Acomp executed!");
}
}

View File

@@ -0,0 +1,10 @@
package com.yomahub.liteflow.test.subflow.cmp1;
import com.yomahub.liteflow.core.NodeComponent;
public class BCmp extends NodeComponent {
@Override
public void process() {
System.out.println("Bcomp executed!");
}
}

View File

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

View File

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

View File

@@ -0,0 +1,11 @@
package com.yomahub.liteflow.test.subflow.cmp1;
import com.yomahub.liteflow.core.NodeComponent;
public class ECmp extends NodeComponent {
@Override
public void process() throws Exception {
System.out.println("Ecomp executed!");
}
}

View File

@@ -0,0 +1,15 @@
package com.yomahub.liteflow.test.subflow.cmp2;
import com.yomahub.liteflow.core.NodeComponent;
import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowTest.RUN_TIME_SLOT;
public class FCmp extends NodeComponent {
@Override
public void process() throws Exception {
RUN_TIME_SLOT.add(this.getSlot().getRequestId());
System.out.println("Fcomp executed!");
}
}

View File

@@ -0,0 +1,23 @@
package com.yomahub.liteflow.test.subflow.cmp2;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowTest.RUN_TIME_SLOT;
public class GCmp extends NodeComponent {
@Override
public void process() throws Exception {
RUN_TIME_SLOT.add(this.getSlot().getRequestId());
System.out.println("Gcmp executed!");
FlowExecutor flowExecutor = FlowExecutorHolder.loadInstance();
flowExecutor.invoke("chain4", "it's implicit subflow.", DefaultSlot.class, this.getSlotIndex());
}
}

View File

@@ -0,0 +1,15 @@
package com.yomahub.liteflow.test.subflow.cmp2;
import com.yomahub.liteflow.core.NodeComponent;
import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowTest.RUN_TIME_SLOT;
public class HCmp extends NodeComponent {
@Override
public void process() throws Exception {
RUN_TIME_SLOT.add(this.getSlot().getRequestId());
System.out.println("Hcomp executed!");
}
}

View File

@@ -0,0 +1,15 @@
package com.yomahub.liteflow.test.subflow.cmp2;
import com.yomahub.liteflow.core.NodeComponent;
import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowTest.RUN_TIME_SLOT;
public class MCmp extends NodeComponent {
@Override
public void process() throws Exception {
RUN_TIME_SLOT.add(this.getSlot().getRequestId());
System.out.println("Mcomp executed!");
}
}

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<nodes>
<node id="a" class="com.yomahub.liteflow.test.resizeSlot.cmp.ACmp"/>
<node id="b" class="com.yomahub.liteflow.test.resizeSlot.cmp.BCmp"/>
<node id="c" class="com.yomahub.liteflow.test.resizeSlot.cmp.CCmp"/>
</nodes>
<chain name="chain1">
<then value="a,b,c"/>
</chain>
</flow>

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<nodes>
<node id="f" class="com.yomahub.liteflow.test.subflow.cmp2.FCmp"/>
<node id="g" class="com.yomahub.liteflow.test.subflow.cmp2.GCmp"/>
<node id="h" class="com.yomahub.liteflow.test.subflow.cmp2.HCmp"/>
<node id="m" class="com.yomahub.liteflow.test.subflow.cmp2.MCmp"/>
</nodes>
<chain name="chain3">
<then value="f,g"/> <!-- g隐式调用chain4 -->
</chain>
<chain name="chain4">
<then value="h,m"/>
</chain>
<!-- f,g,h,m -->
</flow>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<nodes>
<node id="a" class="com.yomahub.liteflow.test.subflow.cmp1.ACmp"/>
<node id="b" class="com.yomahub.liteflow.test.subflow.cmp1.BCmp"/>
<node id="c" class="com.yomahub.liteflow.test.subflow.cmp1.CCmp"/>
<node id="d" class="com.yomahub.liteflow.test.subflow.cmp1.DCmp"/>
<node id="e" class="com.yomahub.liteflow.test.subflow.cmp1.ECmp"/>
<node id="f" class="com.yomahub.liteflow.test.subflow.cmp2.FCmp"/>
<node id="g" class="com.yomahub.liteflow.test.subflow.cmp2.GCmp"/>
<node id="h" class="com.yomahub.liteflow.test.subflow.cmp2.HCmp"/>
<node id="m" class="com.yomahub.liteflow.test.subflow.cmp2.MCmp"/>
</nodes>
<chain name="chain1">
<then value="a,b"/>
<then value="chain2"/> <!-- 测试调用c流程后是否正常调用chain2 -->
</chain>
</flow>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<chain name="chain2">
<then value="b,a"/>
<then value="chain3"/>
</chain>
</flow>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<chain name="chain3">
<then value="e,d"/>
</chain>
</flow>

View File

@@ -0,0 +1,6 @@
flow:
chain:
- name: chain3
condition:
- type: then
value: 'e,d'

View File

@@ -0,0 +1,73 @@
{
"flow": {
"nodes": {
"node": [
{
"id": "a",
"class": "com.yomahub.liteflow.test.subflow.cmp1.ACmp"
},
{
"id": "b",
"class": "com.yomahub.liteflow.test.subflow.cmp1.BCmp"
},
{
"id": "c",
"class": "com.yomahub.liteflow.test.subflow.cmp1.CCmp"
},
{
"id": "d",
"class": "com.yomahub.liteflow.test.subflow.cmp1.DCmp"
},
{
"id": "e",
"class": "com.yomahub.liteflow.test.subflow.cmp1.ECmp"
},
{
"id": "f",
"class": "com.yomahub.liteflow.test.subflow.cmp2.FCmp"
},
{
"id": "g",
"class": "com.yomahub.liteflow.test.subflow.cmp2.GCmp"
},
{
"id": "h",
"class": "com.yomahub.liteflow.test.subflow.cmp2.HCmp"
},
{
"id": "M",
"class": "com.yomahub.liteflow.test.subflow.cmp2.MCmp"
}
]
},
"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"}
]
}
]
}
}

View File

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<nodes>
<node id="a" class="com.yomahub.liteflow.test.subflow.cmp1.ACmp"/>
<node id="b" class="com.yomahub.liteflow.test.subflow.cmp1.BCmp"/>
<node id="c" class="com.yomahub.liteflow.test.subflow.cmp1.CCmp"/>
<node id="d" class="com.yomahub.liteflow.test.subflow.cmp1.DCmp"/>
<node id="e" class="com.yomahub.liteflow.test.subflow.cmp1.ECmp"/>
<node id="f" class="com.yomahub.liteflow.test.subflow.cmp2.FCmp"/>
<node id="g" class="com.yomahub.liteflow.test.subflow.cmp2.GCmp"/>
<node id="h" class="com.yomahub.liteflow.test.subflow.cmp2.HCmp"/>
<node id="m" class="com.yomahub.liteflow.test.subflow.cmp2.MCmp"/>
</nodes>
<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>

View File

@@ -0,0 +1,44 @@
flow:
nodes:
node:
- id: a
class: com.yomahub.liteflow.test.subflow.cmp1.ACmp
- id: b
class: com.yomahub.liteflow.test.subflow.cmp1.BCmp
- id: c
class: com.yomahub.liteflow.test.subflow.cmp1.CCmp
- id: d
class: com.yomahub.liteflow.test.subflow.cmp1.DCmp
- id: e
class: com.yomahub.liteflow.test.subflow.cmp1.ECmp
- id: f
class: com.yomahub.liteflow.test.subflow.cmp2.FCmp
- id: g
class: com.yomahub.liteflow.test.subflow.cmp2.GCmp
- id: h
class: com.yomahub.liteflow.test.subflow.cmp2.HCmp
- id: h
class: com.yomahub.liteflow.test.subflow.cmp2.MCmp
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'