补充测试用例

This commit is contained in:
bryan31
2022-03-08 00:52:39 +08:00
parent b773760cb1
commit 7435a9742b
10 changed files with 238 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
package com.yomahub.liteflow.test.whenTimeOut;
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.WhenTimeoutException;
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.6.4
*/
public class WhenTimeOutTest1 extends BaseTest {
private static FlowExecutor flowExecutor;
@BeforeClass
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("whenTimeOut/flow1.xml");
config.setWhenMaxWaitSeconds(3);
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
//其中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());
}
}

View File

@@ -0,0 +1,36 @@
package com.yomahub.liteflow.test.whenTimeOut;
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;
/**
* 非spring环境下异步线程超时日志打印测试
* @author Bryan.Zhang
* @since 2.6.4
*/
public class WhenTimeOutTest2 extends BaseTest {
private static FlowExecutor flowExecutor;
@BeforeClass
public static void init(){
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("whenTimeOut/flow2.xml");
config.setWhenMaxWaitSeconds(5);
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
//其中d,e,f都sleep 4秒其中def是不同的组超时设置5秒
@Test
public void testWhenTimeOut() throws Exception{
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertTrue(response.isSuccess());
}
}

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.whenTimeOut.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,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.core.NodeComponent;
public class BCmp extends NodeComponent {
@Override
public void process() {
try {
Thread.sleep(4000);
}catch (Exception ignored){
}
System.out.println("BCmp executed!");
}
}

View File

@@ -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.core.NodeComponent;
public class CCmp extends NodeComponent {
@Override
public void process() {
try {
Thread.sleep(3500);
}catch (Exception ignored){
}
System.out.println("CCmp executed!");
}
}

View File

@@ -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.core.NodeComponent;
public class DCmp extends NodeComponent {
@Override
public void process() {
try {
Thread.sleep(4000);
}catch (Exception ignored){
}
System.out.println("DCmp executed!");
}
}

View File

@@ -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.core.NodeComponent;
public class ECmp extends NodeComponent {
@Override
public void process() {
try {
Thread.sleep(4000);
}catch (Exception ignored){
}
System.out.println("ECmp executed!");
}
}

View File

@@ -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.core.NodeComponent;
public class FCmp extends NodeComponent {
@Override
public void process() {
try {
Thread.sleep(4000);
}catch (Exception ignored){
}
System.out.println("FCmp executed!");
}
}

View File

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

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<nodes>
<node id="d" class="com.yomahub.liteflow.test.whenTimeOut.cmp.DCmp"/>
<node id="e" class="com.yomahub.liteflow.test.whenTimeOut.cmp.ECmp"/>
<node id="f" class="com.yomahub.liteflow.test.whenTimeOut.cmp.FCmp"/>
</nodes>
<chain name="chain1">
<when value="d" group="1"/>
<when value="e" group="2"/>
<when value="f" group="3"/>
</chain>
</flow>