对EL语句里设置重试次数的代码进行优化

This commit is contained in:
rain
2024-01-26 14:31:36 +08:00
parent 9677b128ca
commit 82348cb926
73 changed files with 592 additions and 352 deletions

View File

@@ -1,4 +1,4 @@
package com.yomahub.liteflow.test.retryTimes;
package com.yomahub.liteflow.test.retry;
import com.yomahub.liteflow.core.FlowExecutor;
@@ -10,14 +10,14 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
public class RetryTimesTest extends BaseTest {
public class RetryTest extends BaseTest {
private static FlowExecutor flowExecutor;
@BeforeAll
public static void init() {
LiteflowConfig config = new LiteflowConfig();
config.setRuleSource("retryTimes/flow.el.xml");
config.setRuleSource("retry/flow.el.xml");
flowExecutor = FlowExecutorHolder.loadInstance(config);
}
@@ -41,7 +41,6 @@ public class RetryTimesTest extends BaseTest {
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测试
@@ -100,4 +99,18 @@ public class RetryTimesTest extends BaseTest {
Assertions.assertEquals("a==>b", response.getExecuteStepStr());
}
// 指定异常重试测试1
@Test
public void testException1() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain11", "arg");
Assertions.assertTrue(response.isSuccess());
}
// 指定异常重试测试2
@Test
public void testException2() throws Exception {
LiteflowResponse response = flowExecutor.execute2Resp("chain12", "arg");
Assertions.assertFalse(response.isSuccess());
}
}

View File

@@ -1,4 +1,4 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
package com.yomahub.liteflow.test.retry.cmp;
import com.yomahub.liteflow.core.NodeComponent;

View File

@@ -1,4 +1,4 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
package com.yomahub.liteflow.test.retry.cmp;
import com.yomahub.liteflow.core.NodeComponent;

View File

@@ -1,4 +1,4 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
package com.yomahub.liteflow.test.retry.cmp;
import com.yomahub.liteflow.core.NodeForComponent;

View File

@@ -1,4 +1,4 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
package com.yomahub.liteflow.test.retry.cmp;
import com.yomahub.liteflow.core.NodeSwitchComponent;

View File

@@ -1,4 +1,4 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
package com.yomahub.liteflow.test.retry.cmp;
import com.yomahub.liteflow.core.NodeIfComponent;

View File

@@ -1,4 +1,4 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
package com.yomahub.liteflow.test.retry.cmp;
import cn.hutool.core.collection.ListUtil;

View File

@@ -0,0 +1,16 @@
package com.yomahub.liteflow.test.retry.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.exception.ELParseException;
public class MCmp extends NodeComponent {
int flag = 0;
@Override
public void process() throws Exception {
flag ++;
System.out.println("MCmp executed!");
if(flag < 4) throw new ELParseException("MCmp error!");
else flag = 0;
}
}

View File

@@ -1,4 +1,4 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
package com.yomahub.liteflow.test.retry.cmp;
import com.yomahub.liteflow.core.NodeWhileComponent;

View File

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

View File

@@ -1,52 +0,0 @@
<?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>