mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 12:12:08 +08:00
补充测试用例
This commit is contained in:
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package com.yomahub.liteflow.test.useTTLInWhen;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在when异步节点的情况下去拿ThreadLocal里的测试场景
|
||||||
|
* @author Bryan.Zhang
|
||||||
|
* @since 2.6.3
|
||||||
|
*/
|
||||||
|
public class UseTTLInWhenTest extends BaseTest {
|
||||||
|
|
||||||
|
private static FlowExecutor flowExecutor;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void init(){
|
||||||
|
LiteflowConfig config = new LiteflowConfig();
|
||||||
|
config.setRuleSource("useTTLInWhen/flow.xml");
|
||||||
|
flowExecutor = FlowExecutorHolder.loadInstance(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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.useTTLInWhen.cmp;
|
||||||
|
|
||||||
|
import com.yomahub.liteflow.core.NodeComponent;
|
||||||
|
import com.yomahub.liteflow.test.useTTLInWhen.TestTL;
|
||||||
|
|
||||||
|
public class ACmp extends NodeComponent {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void process() {
|
||||||
|
TestTL.set("hello");
|
||||||
|
System.out.println("ACmp executed!");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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.useTTLInWhen.cmp;
|
||||||
|
|
||||||
|
import com.yomahub.liteflow.core.NodeComponent;
|
||||||
|
import com.yomahub.liteflow.test.useTTLInWhen.TestTL;
|
||||||
|
|
||||||
|
public class BCmp extends NodeComponent {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void process() {
|
||||||
|
String value = TestTL.get();
|
||||||
|
this.getSlot().setData(this.getNodeId(),value+",b");
|
||||||
|
System.out.println("BCmp executed!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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.useTTLInWhen.cmp;
|
||||||
|
|
||||||
|
import com.yomahub.liteflow.core.NodeComponent;
|
||||||
|
import com.yomahub.liteflow.test.useTTLInWhen.TestTL;
|
||||||
|
|
||||||
|
public class CCmp extends NodeComponent {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void process() {
|
||||||
|
String value = TestTL.get();
|
||||||
|
this.getSlot().setData(this.getNodeId(),value+",c");
|
||||||
|
System.out.println("CCmp executed!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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.useTTLInWhen.cmp;
|
||||||
|
|
||||||
|
import com.yomahub.liteflow.core.NodeComponent;
|
||||||
|
import com.yomahub.liteflow.test.useTTLInWhen.TestTL;
|
||||||
|
|
||||||
|
public class DCmp extends NodeComponent {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void process() {
|
||||||
|
String value = TestTL.get();
|
||||||
|
this.getSlot().setData(this.getNodeId(),value+",d");
|
||||||
|
System.out.println("DCmp executed!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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.useTTLInWhen.cmp;
|
||||||
|
|
||||||
|
import com.yomahub.liteflow.core.NodeComponent;
|
||||||
|
import com.yomahub.liteflow.test.useTTLInWhen.TestTL;
|
||||||
|
|
||||||
|
public class ECmp extends NodeComponent {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void process() {
|
||||||
|
String value = TestTL.get();
|
||||||
|
this.getSlot().setData(this.getNodeId(),value+",e");
|
||||||
|
System.out.println("ECmp executed!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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.useTTLInWhen.cmp;
|
||||||
|
|
||||||
|
import com.yomahub.liteflow.core.NodeComponent;
|
||||||
|
import com.yomahub.liteflow.test.useTTLInWhen.TestTL;
|
||||||
|
|
||||||
|
public class FCmp extends NodeComponent {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void process() {
|
||||||
|
String value = TestTL.get();
|
||||||
|
this.getSlot().setData(this.getNodeId(),value+",f");
|
||||||
|
System.out.println("FCmp executed!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<flow>
|
||||||
|
<nodes>
|
||||||
|
<node id="a" class="com.yomahub.liteflow.test.useTTLInWhen.cmp.ACmp"/>
|
||||||
|
<node id="b" class="com.yomahub.liteflow.test.useTTLInWhen.cmp.BCmp"/>
|
||||||
|
<node id="c" class="com.yomahub.liteflow.test.useTTLInWhen.cmp.CCmp"/>
|
||||||
|
<node id="d" class="com.yomahub.liteflow.test.useTTLInWhen.cmp.DCmp"/>
|
||||||
|
<node id="e" class="com.yomahub.liteflow.test.useTTLInWhen.cmp.ECmp"/>
|
||||||
|
<node id="f" class="com.yomahub.liteflow.test.useTTLInWhen.cmp.FCmp"/>
|
||||||
|
</nodes>
|
||||||
|
|
||||||
|
<chain name="chain1">
|
||||||
|
<then value="a"/>
|
||||||
|
<when value="b,c,d,e,f"/>
|
||||||
|
</chain>
|
||||||
|
</flow>
|
||||||
Reference in New Issue
Block a user