mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 20:22:07 +08:00
补充测试用例
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
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.property.LiteflowConfig;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
/**
|
||||
* 测试非spring环境下的自定义组件执行器
|
||||
* @author Bryan.Zhang
|
||||
* @since 2.5.10
|
||||
*/
|
||||
public class LiteflowNodeExecutorTest extends BaseTest {
|
||||
|
||||
private static FlowExecutor flowExecutor;
|
||||
|
||||
@BeforeClass
|
||||
public static void init(){
|
||||
LiteflowConfig config = new LiteflowConfig();
|
||||
config.setRuleSource("nodeExecutor/flow.xml");
|
||||
config.setRetryCount(3);
|
||||
config.setSlotSize(512);
|
||||
config.setNodeExecutorClass("com.yomahub.liteflow.test.nodeExecutor.CustomerDefaultNodeExecutor");
|
||||
flowExecutor = FlowExecutor.loadInstance(config);
|
||||
}
|
||||
|
||||
// 默认执行器测试
|
||||
@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());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
*
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.test.nodeExecutor.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
||||
public class ACmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("ACmp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.nodeExecutor.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
|
||||
public class BCmp extends NodeComponent {
|
||||
|
||||
private int flag = 0;
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("BCmp executed!");
|
||||
if (flag < 2){
|
||||
flag++;
|
||||
throw new RuntimeException("demo exception");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.nodeExecutor.cmp;
|
||||
|
||||
import com.yomahub.liteflow.annotation.LiteflowRetry;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.entity.executor.NodeExecutor;
|
||||
import com.yomahub.liteflow.test.nodeExecutor.CustomerNodeExecutor;
|
||||
|
||||
@LiteflowRetry(5)
|
||||
public class CCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("CCmp executed!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends NodeExecutor> getNodeExecutorClass() {
|
||||
return CustomerNodeExecutor.class;
|
||||
}
|
||||
}
|
||||
@@ -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.nodeExecutor.cmp;
|
||||
|
||||
import com.yomahub.liteflow.annotation.LiteflowRetry;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.entity.executor.NodeExecutor;
|
||||
import com.yomahub.liteflow.test.nodeExecutor.CustomerNodeExecutorAndCustomRetry;
|
||||
|
||||
@LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class})
|
||||
public class DCmp extends NodeComponent {
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
System.out.println("DCmp executed!");
|
||||
throw new NullPointerException("demo exception");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends NodeExecutor> getNodeExecutorClass() {
|
||||
return CustomerNodeExecutorAndCustomRetry.class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<flow>
|
||||
<nodes>
|
||||
<node id="a" class="com.yomahub.liteflow.test.nodeExecutor.cmp.ACmp"/>
|
||||
<node id="b" class="com.yomahub.liteflow.test.nodeExecutor.cmp.BCmp"/>
|
||||
<node id="c" class="com.yomahub.liteflow.test.nodeExecutor.cmp.CCmp"/>
|
||||
<node id="d" class="com.yomahub.liteflow.test.nodeExecutor.cmp.DCmp"/>
|
||||
</nodes>
|
||||
|
||||
<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>
|
||||
Reference in New Issue
Block a user