允许EL语句里设置重试次数

This commit is contained in:
rain
2024-01-18 15:59:46 +08:00
parent 74fe9a0c5a
commit 9677b128ca
57 changed files with 1704 additions and 0 deletions

View File

@@ -0,0 +1,103 @@
package com.yomahub.liteflow.test.retryTimes;
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;
public class RetryTimesTest extends BaseTest {
private static FlowExecutor flowExecutor;
@BeforeAll
public static void init() {
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("retryTimes/flow.el.xml");
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
// THEN测试
@Test
public void testThen() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("a==>b==>a==>b==>a==>b==>a==>b", response.getExecuteStepStr());
}
// WHEN测试
@Test
public void testWhen() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg");
Assertions.assertTrue(response.isSuccess());
}
// node测试
@Test
public void testNode() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg");
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("a==>b==>b==>b==>b", response.getExecuteStepStr());
}
// FOR测试
@Test
public void testFor() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg");
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("c==>c==>c==>c==>a", response.getExecuteStepStr());
}
// SWITCH测试
@Test
public void testSwitch() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain5", "arg");
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("d==>d==>d==>d==>a", response.getExecuteStepStr());
}
// IF测试
@Test
public void testIf() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain6", "arg");
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("f==>f==>f==>f==>a", response.getExecuteStepStr());
}
// WHILE测试
@Test
public void testWhile() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain7", "arg");
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("n==>n==>n==>n==>a==>n", response.getExecuteStepStr());
}
// ITERATOR测试
@Test
public void testIterator() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain8", "arg");
Assertions.assertTrue(response.isSuccess());
Assertions.assertEquals("i==>i==>i==>i==>a", response.getExecuteStepStr());
}
// 重试失败提示信息测试
@Test
public void testRetryFail() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain9", "arg");
Assertions.assertFalse(response.isSuccess());
Assertions.assertEquals("a==>b==>a==>b", response.getExecuteStepStr());
}
// FINALLY测试
@Test
public void testFinally() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain10", "arg");
Assertions.assertFalse(response.isSuccess());
Assertions.assertEquals("a==>b", response.getExecuteStepStr());
}
}

View File

@@ -0,0 +1,11 @@
package com.yomahub.liteflow.test.retryTimes.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,16 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
import com.yomahub.liteflow.core.NodeComponent;
public class BCmp extends NodeComponent {
int flag = 0;
@Override
public void process() {
flag ++;
System.out.println("BCmp executed!");
if(flag < 4) throw new RuntimeException();
else flag = 0;
}
}

View File

@@ -0,0 +1,16 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
import com.yomahub.liteflow.core.NodeForComponent;
public class CCmp extends NodeForComponent {
int flag = 0;
@Override
public int processFor() throws Exception {
flag ++;
System.out.println("CCmp executed!");
if(flag < 4) throw new RuntimeException();
else return 1;
}
}

View File

@@ -0,0 +1,16 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
import com.yomahub.liteflow.core.NodeSwitchComponent;
public class DCmp extends NodeSwitchComponent {
int flag = 0;
@Override
public String processSwitch() throws Exception {
flag ++;
System.out.println("DCmp executed!");
if(flag < 4) throw new RuntimeException();
else return "a";
}
}

View File

@@ -0,0 +1,15 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
import com.yomahub.liteflow.core.NodeIfComponent;
public class FCmp extends NodeIfComponent {
int flag = 0;
@Override
public boolean processIf() throws Exception {
System.out.println("FCmp executed!");
flag ++;
if(flag < 4) throw new RuntimeException();
else return true;
}
}

View File

@@ -0,0 +1,21 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
import cn.hutool.core.collection.ListUtil;
import com.yomahub.liteflow.core.NodeIteratorComponent;
import java.util.Iterator;
import java.util.List;
public class ICmp extends NodeIteratorComponent {
int flag = 0;
@Override
public Iterator<?> processIterator() throws Exception {
flag ++;
if(flag < 4) throw new RuntimeException();
else {
List<String> list = ListUtil.toList("jack");
return list.iterator();
}
}
}

View File

@@ -0,0 +1,16 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
import com.yomahub.liteflow.core.NodeWhileComponent;
public class NCmp extends NodeWhileComponent {
int flag = 0;
@Override
public boolean processWhile() throws Exception {
flag ++;
System.out.println("NCmp executed!");
if(flag < 4) throw new RuntimeException();
else return flag == 4 ? true : false;
}
}

View File

@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<nodes>
<node id="a" class="com.yomahub.liteflow.test.retryTimes.cmp.ACmp"/>
<node id="b" class="com.yomahub.liteflow.test.retryTimes.cmp.BCmp"/>
<node id="c" class="com.yomahub.liteflow.test.retryTimes.cmp.CCmp"/>
<node id="d" class="com.yomahub.liteflow.test.retryTimes.cmp.DCmp"/>
<node id="f" class="com.yomahub.liteflow.test.retryTimes.cmp.FCmp"/>
<node id="i" class="com.yomahub.liteflow.test.retryTimes.cmp.ICmp"/>
<node id="n" class="com.yomahub.liteflow.test.retryTimes.cmp.NCmp"/>
</nodes>
<chain name="chain1">
THEN( a, b ).retryTimes(3);
</chain>
<chain name="chain2">
WHEN( a, b ).retryTimes(3);
</chain>
<chain name="chain3">
THEN( a, b.retryTimes(3) );
</chain>
<chain name="chain4">
FOR(c).DO(a).retryTimes(3);
</chain>
<chain name="chain5">
SWITCH(d).TO(a).retryTimes(3);
</chain>
<chain name="chain6">
IF(f, a).retryTimes(3);
</chain>
<chain name="chain7">
WHILE(n).DO(a).retryTimes(3);
</chain>
<chain name="chain8">
ITERATOR(i).DO(a).retryTimes(3);
</chain>
<chain name="chain9">
THEN( a, b ).retryTimes(1);
</chain>
<chain name="chain10">
THEN( a, FINALLY(b, a).retryTimes(3) );
</chain>
</flow>