This commit is contained in:
zy
2023-10-09 20:35:17 +08:00
239 changed files with 6747 additions and 1341 deletions

View File

@@ -1,14 +1,21 @@
package com.yomahub.liteflow.test.absoluteConfigPath;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.StrUtil;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.property.LiteflowConfigGetter;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.util.Objects;
/**
* 非spring环境下异步线程超时日志打印测试
*
@@ -17,19 +24,50 @@ import org.junit.jupiter.api.Test;
*/
public class AbsoluteConfigPathTest extends BaseTest {
private static String rootDir;
private static FlowExecutor flowExecutor;
@BeforeAll
public static void init() {
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("/usr/local/flow2.xml");
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
@Test
public void testAbsoluteConfig() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
Assertions.assertTrue(response.isSuccess());
Assertions.assertTrue(() -> {
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource(StrUtil.format("{}/sub/a/flow1.xml",rootDir));
flowExecutor = FlowExecutorHolder.loadInstance(config);
return flowExecutor.execute2Resp("chain1", "arg").isSuccess();
});
}
@Test
public void testAbsolutePathMatch() throws Exception {
Assertions.assertTrue(() -> {
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource(StrUtil.format("{}/sub/**/*.xml",rootDir));
flowExecutor = FlowExecutorHolder.loadInstance(config);
return flowExecutor.execute2Resp("chain1", "arg").isSuccess();
});
}
@BeforeAll
public static void createFiles() {
rootDir = Objects.requireNonNull(AbsoluteConfigPathTest.class.getResource("/")).getPath();
String path1 = StrUtil.format("{}/sub/a", rootDir);
String path2 = StrUtil.format("{}/sub/b", rootDir);
FileUtil.mkdir(path1);
FileUtil.mkdir(path2);
String content1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><flow><nodes><node id=\"a\" class=\"com.yomahub.liteflow.test.absoluteConfigPath.cmp.ACmp\"/><node id=\"b\" class=\"com.yomahub.liteflow.test.absoluteConfigPath.cmp.BCmp\"/><node id=\"c\" class=\"com.yomahub.liteflow.test.absoluteConfigPath.cmp.CCmp\"/></nodes><chain name=\"chain1\">WHEN(a, b, c);</chain></flow>";
String content2 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><flow><nodes><node id=\"a\" class=\"com.yomahub.liteflow.test.absoluteConfigPath.cmp.ACmp\"/><node id=\"b\" class=\"com.yomahub.liteflow.test.absoluteConfigPath.cmp.BCmp\"/><node id=\"c\" class=\"com.yomahub.liteflow.test.absoluteConfigPath.cmp.CCmp\"/></nodes><chain name=\"chain2\">THEN(c, chain1);</chain></flow>";
FileUtil.writeString(content1, path1 + "/flow1.xml", CharsetUtil.CHARSET_UTF_8);
FileUtil.writeString(content2, path2 + "/flow2.xml", CharsetUtil.CHARSET_UTF_8);
}
@AfterAll
public static void removeFiles() {
FileUtil.del(StrUtil.format("{}/sub", rootDir));
}
}

View File

@@ -0,0 +1,31 @@
package com.yomahub.liteflow.test.endlessLoop;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.exception.CyclicDependencyException;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.property.LiteflowConfigGetter;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
/**
* 测试多文件情况下 chain 死循环逻辑
*
* @author luo yi
* @since 2.11.1
*/
public class FlowInDifferentConfigTest extends BaseTest {
// 测试 chain 死循环
@Test
public void testChainEndlessLoop() {
Assertions.assertThrows(CyclicDependencyException.class, () -> {
LiteflowConfig config = LiteflowConfigGetter.get();
config.setRuleSource("endlessLoop/flow-main.el.xml,endlessLoop/flow-sub1.el.xml");
FlowExecutorHolder.loadInstance(config);
});
}
}

View File

@@ -0,0 +1,29 @@
package com.yomahub.liteflow.test.endlessLoop;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.exception.CyclicDependencyException;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.property.LiteflowConfigGetter;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
/**
* 测试 json 文件情况下 chain 死循环逻辑
*
* @author luo yi
* @since 2.11.1
*/
public class FlowJsonTest extends BaseTest {
// 测试 chain 死循环
@Test
public void testChainEndlessLoop() {
Assertions.assertThrows(CyclicDependencyException.class, () -> {
LiteflowConfig config = LiteflowConfigGetter.get();
config.setRuleSource("endlessLoop/flow.el.json");
FlowExecutorHolder.loadInstance(config);
});
}
}

View File

@@ -0,0 +1,29 @@
package com.yomahub.liteflow.test.endlessLoop;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.exception.CyclicDependencyException;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.property.LiteflowConfigGetter;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
/**
* 测试 xml 文件情况下 chain 死循环逻辑
*
* @author luo yi
* @since 2.11.1
*/
public class FlowXMLTest extends BaseTest {
// 测试 chain 死循环
@Test
public void testChainEndlessLoop() {
Assertions.assertThrows(CyclicDependencyException.class, () -> {
LiteflowConfig config = LiteflowConfigGetter.get();
config.setRuleSource("endlessLoop/flow.el.xml");
FlowExecutorHolder.loadInstance(config);
});
}
}

View File

@@ -0,0 +1,29 @@
package com.yomahub.liteflow.test.endlessLoop;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.exception.CyclicDependencyException;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.property.LiteflowConfigGetter;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
/**
* 测试 yml 文件情况下 chain 死循环逻辑
*
* @author luo yi
* @since 2.11.1
*/
public class FlowYMLTest extends BaseTest {
// 测试 chain 死循环
@Test
public void testChainEndlessLoop() {
Assertions.assertThrows(CyclicDependencyException.class, () -> {
LiteflowConfig config = LiteflowConfigGetter.get();
config.setRuleSource("endlessLoop/flow.el.yml");
FlowExecutorHolder.loadInstance(config);
});
}
}

View File

@@ -0,0 +1,12 @@
package com.yomahub.liteflow.test.endlessLoop.cmp;
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,12 @@
package com.yomahub.liteflow.test.endlessLoop.cmp;
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,12 @@
package com.yomahub.liteflow.test.endlessLoop.cmp;
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,12 @@
package com.yomahub.liteflow.test.endlessLoop.cmp;
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,12 @@
package com.yomahub.liteflow.test.endlessLoop.cmp;
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,225 @@
package com.yomahub.liteflow.test.fallback;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
/**
* 非 Spring 环境下组件降级测试
*
* @author DaleLee
* @since 2.11.1
*/
public class FallbackTest extends BaseTest {
private static FlowExecutor flowExecutor;
@BeforeAll
public static void init() {
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("fallback/flow.el.xml");
config.setFallbackCmpEnable(true);
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
@Test
public void testThen1() {
LiteflowResponse response = flowExecutor.execute2Resp("then1", "arg");
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("a==>c", response.getExecuteStepStrWithoutTime());
}
@Test
public void testThen2() {
LiteflowResponse response = flowExecutor.execute2Resp("then2", "arg");
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("c==>c==>c", response.getExecuteStepStrWithoutTime());
}
@Test
public void testWhen1() {
LiteflowResponse response = flowExecutor.execute2Resp("when1", "arg");
Assertions.assertTrue(response.isSuccess());
String executeStepStr = response.getExecuteStepStrWithoutTime();
Assertions.assertTrue("b==>c".equals(executeStepStr) || "c==>b".equals(executeStepStr));
}
@Test
public void testIf1() {
LiteflowResponse response = flowExecutor.execute2Resp("if1", "arg");
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("ifn2", response.getExecuteStepStrWithoutTime());
}
@Test
public void testIf2() {
LiteflowResponse response = flowExecutor.execute2Resp("if2", "arg");
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("ifn1==>c", response.getExecuteStepStrWithoutTime());
}
@Test
public void testFor1() {
LiteflowResponse response = flowExecutor.execute2Resp("for1", "arg");
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("for1==>a==>a==>a", response.getExecuteStepStrWithoutTime());
}
@Test
public void testFor2() {
LiteflowResponse response = flowExecutor.execute2Resp("for2", "arg");
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("LOOP_3==>c==>c==>c", response.getExecuteStepStrWithoutTime());
}
@Test
public void testWhile1() {
LiteflowResponse response = flowExecutor.execute2Resp("while1", "arg");
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("wn2", response.getExecuteStepStrWithoutTime());
}
@Test
public void testWhile2() {
LiteflowResponse response = flowExecutor.execute2Resp("while2", "arg");
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("wn1==>c==>wn1==>c==>wn1==>c==>wn1", response.getExecuteStepStrWithoutTime());
}
@Test
public void testIterator1() {
LiteflowResponse response = flowExecutor.execute2Resp("iterator1", "arg");
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("itn2", response.getExecuteStepStrWithoutTime());
}
@Test
public void testIterator2() {
LiteflowResponse response = flowExecutor.execute2Resp("iterator2", "arg");
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("itn1==>c==>c==>c", response.getExecuteStepStrWithoutTime());
}
@Test
public void testBreak1() {
LiteflowResponse response = flowExecutor.execute2Resp("break1", "arg");
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("LOOP_3==>a==>bn1", response.getExecuteStepStrWithoutTime());
}
@Test
public void testBreak2() {
LiteflowResponse response = flowExecutor.execute2Resp("break2", "arg");
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("wn1==>a==>bn1", response.getExecuteStepStrWithoutTime());
}
@Test
public void testBreak3() {
LiteflowResponse response = flowExecutor.execute2Resp("break3", "arg");
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("itn1==>a==>bn1", response.getExecuteStepStrWithoutTime());
}
@Test
public void testSwitch1() {
LiteflowResponse response = flowExecutor.execute2Resp("switch1", "arg");
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("swn2==>b", response.getExecuteStepStrWithoutTime());
}
@Test
public void testSwitch2() {
LiteflowResponse response = flowExecutor.execute2Resp("switch2", "arg");
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("swn1==>a", response.getExecuteStepStrWithoutTime());
}
@Test
public void testAnd1() {
LiteflowResponse response = flowExecutor.execute2Resp("and1", "arg");
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("ifn2", response.getExecuteStepStrWithoutTime());
}
@Test
public void testOr1() {
LiteflowResponse response = flowExecutor.execute2Resp("or1", "arg");
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("ifn2==>ifn1==>a", response.getExecuteStepStrWithoutTime());
}
@Test
public void testNot1() {
LiteflowResponse response = flowExecutor.execute2Resp("not1", "arg");
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("ifn2==>a", response.getExecuteStepStrWithoutTime());
}
@Test
public void testCatch1() {
LiteflowResponse response = flowExecutor.execute2Resp("catch1", "arg");
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("a==>d==>c", response.getExecuteStepStrWithoutTime());
}
@Test
public void testMulti1() {
LiteflowResponse response = flowExecutor.execute2Resp("multi1", "arg");
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("a==>c==>ifn2", response.getExecuteStepStrWithoutTime());
}
@Test
public void testMulti2() {
LiteflowResponse response = flowExecutor.execute2Resp("multi2", "arg");
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("ifn2==>ifn1==>a==>c", response.getExecuteStepStrWithoutTime());
}
@Test
public void testMulti3() {
LiteflowResponse response = flowExecutor.execute2Resp("multi3", "arg");
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("for1==>b==>c==>b==>c==>b==>c", response.getExecuteStepStrWithoutTime());
}
@Test
public void testConcurrent1() {
LiteflowResponse response = flowExecutor.execute2Resp("concurrent1", "arg");
Assertions.assertTrue(response.isSuccess());
String stepStr = response.getExecuteStepStrWithoutTime();
Assertions.assertTrue("c==>ifn2".equals(stepStr) || "ifn2==>c".equals(stepStr));
}
@Test
public void testConcurrent2() {
LiteflowResponse response = flowExecutor.execute2Resp("concurrent2", "arg");
Assertions.assertTrue(response.isSuccess());
String stepStr = response.getExecuteStepStrWithoutTime();
Assertions.assertTrue("c==>ifn2".equals(stepStr) || "ifn2==>c".equals(stepStr));
}
@Test
public void testConcurrent3() throws ExecutionException, InterruptedException {
// 执行多条 chain
Future<LiteflowResponse> future1 = flowExecutor.execute2Future("concurrent1", "arg", new Object());
Future<LiteflowResponse> future2 = flowExecutor.execute2Future("concurrent2", "arg", new Object());
Thread.sleep(1000);
LiteflowResponse response1 = future1.get();
LiteflowResponse response2 = future2.get();
Assertions.assertTrue(response1.isSuccess());
String stepStr1 = response1.getExecuteStepStrWithoutTime();
Assertions.assertTrue("c==>ifn2".equals(stepStr1) || "ifn2==>c".equals(stepStr1));
Assertions.assertTrue(response2.isSuccess());
String stepStr2 = response2.getExecuteStepStrWithoutTime();
Assertions.assertTrue("c==>ifn2".equals(stepStr2) || "ifn2==>c".equals(stepStr2));
}
}

View File

@@ -0,0 +1,12 @@
package com.yomahub.liteflow.test.fallback.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,12 @@
package com.yomahub.liteflow.test.fallback.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,13 @@
package com.yomahub.liteflow.test.fallback.cmp;
import com.yomahub.liteflow.annotation.FallbackCmp;
import com.yomahub.liteflow.core.NodeBreakComponent;
@FallbackCmp
public class BreakCmp extends NodeBreakComponent {
@Override
public boolean processBreak() throws Exception {
return true;
}
}

View File

@@ -0,0 +1,14 @@
package com.yomahub.liteflow.test.fallback.cmp;
import com.yomahub.liteflow.annotation.FallbackCmp;
import com.yomahub.liteflow.core.NodeComponent;
@FallbackCmp
public class CCmp extends NodeComponent {
@Override
public void process() {
System.out.println("CCmp executed!");
}
}

View File

@@ -0,0 +1,11 @@
package com.yomahub.liteflow.test.fallback.cmp;
import com.yomahub.liteflow.core.NodeComponent;
public class DCmp extends NodeComponent {
@Override
public void process() throws Exception {
throw new RuntimeException("component[d]");
}
}

View File

@@ -0,0 +1,13 @@
package com.yomahub.liteflow.test.fallback.cmp;
import com.yomahub.liteflow.annotation.FallbackCmp;
import com.yomahub.liteflow.core.NodeForComponent;
@FallbackCmp
public class ForCmp extends NodeForComponent {
@Override
public int processFor() throws Exception {
return 3;
}
}

View File

@@ -0,0 +1,11 @@
package com.yomahub.liteflow.test.fallback.cmp;
import com.yomahub.liteflow.core.NodeIfComponent;
public class IfCmp1 extends NodeIfComponent {
@Override
public boolean processIf() throws Exception {
return true;
}
}

View File

@@ -0,0 +1,13 @@
package com.yomahub.liteflow.test.fallback.cmp;
import com.yomahub.liteflow.annotation.FallbackCmp;
import com.yomahub.liteflow.core.NodeIfComponent;
@FallbackCmp
public class IfCmp2 extends NodeIfComponent {
@Override
public boolean processIf() throws Exception {
return false;
}
}

View File

@@ -0,0 +1,14 @@
package com.yomahub.liteflow.test.fallback.cmp;
import com.yomahub.liteflow.core.NodeIteratorComponent;
import java.util.Arrays;
import java.util.Iterator;
public class IteratorCmp1 extends NodeIteratorComponent {
@Override
public Iterator<?> processIterator() throws Exception {
return Arrays.asList("a", "b", "c").iterator();
}
}

View File

@@ -0,0 +1,16 @@
package com.yomahub.liteflow.test.fallback.cmp;
import com.yomahub.liteflow.annotation.FallbackCmp;
import com.yomahub.liteflow.core.NodeIteratorComponent;
import java.util.Collections;
import java.util.Iterator;
@FallbackCmp
public class IteratorCmp2 extends NodeIteratorComponent {
@Override
public Iterator<?> processIterator() throws Exception {
return Collections.emptyIterator();
}
}

View File

@@ -0,0 +1,11 @@
package com.yomahub.liteflow.test.fallback.cmp;
import com.yomahub.liteflow.core.NodeSwitchComponent;
public class SwitchCmp1 extends NodeSwitchComponent {
@Override
public String processSwitch() throws Exception {
return "a";
}
}

View File

@@ -0,0 +1,13 @@
package com.yomahub.liteflow.test.fallback.cmp;
import com.yomahub.liteflow.annotation.FallbackCmp;
import com.yomahub.liteflow.core.NodeSwitchComponent;
@FallbackCmp
public class SwitchCmp2 extends NodeSwitchComponent {
@Override
public String processSwitch() throws Exception {
return "b";
}
}

View File

@@ -0,0 +1,24 @@
package com.yomahub.liteflow.test.fallback.cmp;
import com.yomahub.liteflow.core.NodeWhileComponent;
import java.util.HashSet;
import java.util.Set;
public class WhileCmp1 extends NodeWhileComponent {
private int count = 0;
// 执行过的 chain
Set<String> executedChain = new HashSet<>();
@Override
public boolean processWhile() throws Exception {
// 判断是否切换了 chain
if (!executedChain.contains(this.getCurrChainId())) {
count = 0;
executedChain.add(this.getCurrChainId());
}
count++;
return count <= 3;
}
}

View File

@@ -0,0 +1,13 @@
package com.yomahub.liteflow.test.fallback.cmp;
import com.yomahub.liteflow.annotation.FallbackCmp;
import com.yomahub.liteflow.core.NodeWhileComponent;
@FallbackCmp
public class WhileCmp2 extends NodeWhileComponent {
@Override
public boolean processWhile() throws Exception {
return false;
}
}

View File

@@ -3,7 +3,9 @@ package com.yomahub.liteflow.test.rollback;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.flow.entity.CmpStep;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.slot.DefaultContext;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
@@ -88,5 +90,13 @@ public class RollbackTest extends BaseTest {
Assertions.assertEquals("", response.getRollbackStepStr());
}
@Test
// 对获取数据的测试
public void testData() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain9", "arg");
DefaultContext context = response.getFirstContextBean();
Assertions.assertFalse(response.isSuccess());
Assertions.assertEquals("321", context.getData("test"));
}
}

View File

@@ -8,6 +8,7 @@
package com.yomahub.liteflow.test.rollback.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
public class ACmp extends NodeComponent {
@@ -18,6 +19,17 @@ public class ACmp extends NodeComponent {
@Override
public void rollback() throws Exception {
String testKey = "test";
DefaultContext context = this.getFirstContextBean();
if (context.getData(testKey) == null) {
context.setData(testKey, this.getTag());
}
else {
String s = context.getData(testKey);
s += this.getTag();
context.setData(testKey, s);
}
System.out.println("ACmp rollback!");
}
}

View File

@@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--这里只是内容,在这个测试用例中这个文件请移到/usr/local/flow.xml中-->
<flow>
<chain name="chain1">
WHEN(a,b,c);
</chain>
</flow>

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<nodes>
<node id="a" class="com.yomahub.liteflow.test.endlessLoop.cmp.ACmp"/>
<node id="b" class="com.yomahub.liteflow.test.endlessLoop.cmp.BCmp"/>
<node id="c" class="com.yomahub.liteflow.test.endlessLoop.cmp.CCmp"/>
<node id="d" class="com.yomahub.liteflow.test.endlessLoop.cmp.DCmp"/>
<node id="e" class="com.yomahub.liteflow.test.endlessLoop.cmp.ECmp"/>
</nodes>
<chain name="chain1">
THEN(a, b, chain2);
</chain>
</flow>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<chain name="chain2">
THEN(b, a, chain1);
</chain>
</flow>

View File

@@ -0,0 +1,42 @@
{
"flow": {
"nodes": {
"node": [
{
"id": "a",
"class": "com.yomahub.liteflow.test.endlessLoop.cmp.ACmp"
},
{
"id": "b",
"class": "com.yomahub.liteflow.test.endlessLoop.cmp.BCmp"
},
{
"id": "c",
"class": "com.yomahub.liteflow.test.endlessLoop.cmp.CCmp"
},
{
"id": "d",
"class": "com.yomahub.liteflow.test.endlessLoop.cmp.DCmp"
},
{
"id": "e",
"class": "com.yomahub.liteflow.test.endlessLoop.cmp.ECmp"
}
]
},
"chain": [
{
"name": "chain7",
"value": "THEN(a, chain8);"
},
{
"name": "chain8",
"value": "THEN(b, chain9);"
},
{
"name": "chain9",
"value": "WHEN(c, chain7);"
}
]
}
}

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<nodes>
<node id="a" class="com.yomahub.liteflow.test.endlessLoop.cmp.ACmp"/>
<node id="b" class="com.yomahub.liteflow.test.endlessLoop.cmp.BCmp"/>
<node id="c" class="com.yomahub.liteflow.test.endlessLoop.cmp.CCmp"/>
<node id="d" class="com.yomahub.liteflow.test.endlessLoop.cmp.DCmp"/>
<node id="e" class="com.yomahub.liteflow.test.endlessLoop.cmp.ECmp"/>
</nodes>
<chain name="chain1">
THEN(a, chain2);
</chain>
<chain name="chain2">
THEN(b, chain3);
</chain>
<chain name="chain3">
THEN(c, chain1);
</chain>
</flow>

View File

@@ -0,0 +1,20 @@
flow:
nodes:
node:
- id: a
class: com.yomahub.liteflow.test.endlessLoop.cmp.ACmp
- id: b
class: com.yomahub.liteflow.test.endlessLoop.cmp.BCmp
- id: c
class: com.yomahub.liteflow.test.endlessLoop.cmp.CCmp
- id: d
class: com.yomahub.liteflow.test.endlessLoop.cmp.DCmp
- id: e
class: com.yomahub.liteflow.test.endlessLoop.cmp.ECmp
chain:
- name: chain4
value: "THEN(a, chain5);"
- name: chain5
value: "THEN(b, chain6);"
- name: chain6
value: "THEN(c, chain5);"

View File

@@ -0,0 +1,153 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<nodes>
<node id = "a" class="com.yomahub.liteflow.test.fallback.cmp.ACmp"/>
<node id = "b" class="com.yomahub.liteflow.test.fallback.cmp.BCmp"/>
<node id = "c" class="com.yomahub.liteflow.test.fallback.cmp.CCmp"/>
<node id = "d" class="com.yomahub.liteflow.test.fallback.cmp.DCmp"/>
<node id = "ifn1" class="com.yomahub.liteflow.test.fallback.cmp.IfCmp1"/>
<node id = "ifn2" class="com.yomahub.liteflow.test.fallback.cmp.IfCmp2"/>
<node id = "swn1" class="com.yomahub.liteflow.test.fallback.cmp.SwitchCmp1"/>
<node id = "swn2" class="com.yomahub.liteflow.test.fallback.cmp.SwitchCmp2"/>
<node id = "for1" class="com.yomahub.liteflow.test.fallback.cmp.ForCmp"/>
<node id = "wn1" class="com.yomahub.liteflow.test.fallback.cmp.WhileCmp1"/>
<node id = "wn2" class="com.yomahub.liteflow.test.fallback.cmp.WhileCmp2"/>
<node id = "itn1" class="com.yomahub.liteflow.test.fallback.cmp.IteratorCmp1"/>
<node id = "itn2" class="com.yomahub.liteflow.test.fallback.cmp.IteratorCmp2"/>
<node id = "bn1" class="com.yomahub.liteflow.test.fallback.cmp.BreakCmp"/>
</nodes>
<!-- THEN 普通组件降级 -->
<chain name="then1">
THEN(a, node("x"));
</chain>
<chain name="then2">
THEN(PRE(node("x1")), node("x2"), FINALLY(node("x3")));
</chain>
<!-- WHEN 普通组件降级 -->
<chain name="when1">
WHEN(b, node("x"));
</chain>
<!-- IF 条件组件降级 -->
<chain name="if1">
IF(node("x"), a)
</chain>
<!-- IF 普通组件降级 -->
<chain name="if2">
IF(ifn1, node("x"))
</chain>
<!-- FOR 次数循环组件降级 -->
<chain name="for1">
FOR(node("x")).DO(a);
</chain>
<!-- FOR 普通组件降级 -->
<chain name="for2">
FOR(3).DO(node("x"));
</chain>
<!-- WHILE 条件循环组件降级 -->
<chain name="while1">
WHILE(node("x")).DO(a)
</chain>
<!-- WHILE 普通组件降级 -->
<chain name="while2">
WHILE(wn1).DO(node("x"))
</chain>
<!-- ITERATOR 迭代组件降级 -->
<chain name="iterator1">
ITERATOR(node("x")).DO(a)
</chain>
<!-- ITERATOR 普通组件降级 -->
<chain name="iterator2">
ITERATOR(itn1).DO(node("x"))
</chain>
<!-- BREAK 退出循环组件降级 -->
<chain name="break1">
FOR(3).DO(a).BREAK(node("x"));
</chain>
<chain name="break2">
WHILE(wn1).DO(a).BREAK(node("x"));
</chain>
<chain name="break3">
ITERATOR(itn1).DO(a).BREAK(node("x"));
</chain>
<!-- SWITCH 选择组件降级 -->
<chain name="switch1">
SWITCH(node("x")).to(a,b);
</chain>
<!-- SWITCH 普通组件降级 -->
<chain name="switch2">
SWITCH(swn1).to(node("x"),a);
</chain>
<!-- AND 条件组件降级 -->
<chain name="and1">
IF(AND(node("x"),ifn1), a);
</chain>
<!-- OR 条件组件降级 -->
<chain name="or1">
IF(OR(node("x"),ifn1), a);
</chain>
<!-- NOT 条件组件降级 -->
<chain name="not1">
IF(NOT(node("x")), a);
</chain>
<!-- CATCH 普通组件降级 -->
<chain name="catch1">
CATCH(THEN(a, d)).DO(node("x"))
</chain>
<!-- 多个组件降级 -->
<chain name="multi1">
THEN(
a,
node("x1"),
IF(node("x2"), b)
);
</chain>
<chain name="multi2">
IF(
OR(node("x1"), ifn1),
THEN(a, node("x2"))
);
</chain>
<chain name="multi3">
FOR(node("x1")).DO(
THEN(b, node("x2"))
);
</chain>
<!-- 并发降级测试 -->
<chain name="concurrent1">
WHEN(
THEN(node("x1")),
IF(node("x2"), b)
).maxWaitSeconds(10000);
</chain>
<chain name="concurrent2">
WHEN(
node("x1"),
IF(node("x2"), b)
).maxWaitSeconds(10000);
</chain>
</flow>

View File

@@ -44,4 +44,8 @@
<chain name="chain8">
CATCH( THEN(b, c, d) ).DO(a);
</chain>
<chain name="chain9">
THEN(a.tag("1"), a.tag("2"), a.tag("3"), d);
</chain>
</flow>