允许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

@@ -92,6 +92,7 @@ public class LiteFlowChainELBuilder {
EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.MAX_WAIT_SECONDS, Object.class, new MaxWaitSecondsOperator());
EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.MAX_WAIT_MILLISECONDS, Object.class, new MaxWaitMillisecondsOperator());
EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.PARALLEL, Object.class, new ParallelOperator());
EXPRESS_RUNNER.addFunctionAndClassMethod(ChainConstant.RETRY_TIMES, Object.class, new RetryTimesOperator());
}
public static LiteFlowChainELBuilder createChain() {

View File

@@ -0,0 +1,30 @@
package com.yomahub.liteflow.builder.el.operator;
import com.yomahub.liteflow.builder.el.operator.base.BaseOperator;
import com.yomahub.liteflow.builder.el.operator.base.OperatorHelper;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.flow.element.Condition;
import com.yomahub.liteflow.flow.element.Executable;
import com.yomahub.liteflow.flow.element.condition.RetryCondition;
import com.yomahub.liteflow.flow.element.condition.ThenCondition;
import com.yomahub.liteflow.flow.element.condition.WhileCondition;
/**
*
* @author Rain
* @since 2.11.5
*
*/
public class RetryTimesOperator extends BaseOperator<Condition> {
@Override
public Condition build(Object[] objects) throws Exception {
OperatorHelper.checkObjectSizeGtTwo(objects);
Executable executable = OperatorHelper.convert(objects[0], Executable.class);
Integer retryTimes = OperatorHelper.convert(objects[1], Integer.class);
RetryCondition retryCondition = new RetryCondition();
retryCondition.addExecutable(executable);
retryCondition.setRetryTimes(retryTimes);
return retryCondition;
}
}

View File

@@ -94,4 +94,6 @@ public interface ChainConstant {
String EXTENDS = "extends";
String RETRY_TIMES = "retryTimes";
}

View File

@@ -0,0 +1,87 @@
package com.yomahub.liteflow.flow.element.condition;
import cn.hutool.core.text.StrFormatter;
import cn.hutool.core.util.ObjectUtil;
import com.yomahub.liteflow.exception.ChainEndException;
import com.yomahub.liteflow.exception.ELParseException;
import com.yomahub.liteflow.flow.element.Chain;
import com.yomahub.liteflow.flow.element.Condition;
import com.yomahub.liteflow.flow.element.Executable;
import com.yomahub.liteflow.flow.element.Node;
import com.yomahub.liteflow.log.LFLog;
import com.yomahub.liteflow.log.LFLoggerManager;
import com.yomahub.liteflow.slot.DataBus;
public class RetryCondition extends ThenCondition{
private final LFLog LOG = LFLoggerManager.getLogger(this.getClass());
private Integer retryTimes;
public Integer getRetryTimes() {
return retryTimes;
}
public void setRetryTimes(Integer retryTimes) {
this.retryTimes = retryTimes;
}
@Override
public void executeCondition(Integer slotIndex) throws Exception {
int retryTimes = this.getRetryTimes() < 0 ? 0 : this.getRetryTimes();
for (int i = 0; i <= retryTimes; i ++) {
try {
if(i == 0) {
super.executeCondition(slotIndex);
} else {
retry(slotIndex, i);
}
break;
} catch (ChainEndException e) {
throw e;
} catch (Exception e) {
if(i >= retryTimes) {
if(retryTimes > 0) {
String retryFailMsg = StrFormatter.format("retry fail when executing the chain[{}] because {} occurs {}.",
this.getCurrChainId(), this.getCurrentExecutableId(), e);
LOG.error(retryFailMsg);
}
throw e;
} else {
DataBus.getSlot(slotIndex).removeException();
}
}
}
}
private void retry(Integer slotIndex, int retryTime) throws Exception {
LOG.info("{} performs {} retry ", this.getCurrentExecutableId(), retryTime);
super.executeCondition(slotIndex);
}
/**
* 获取当前组件的 id
*
* @return
*/
private String getCurrentExecutableId() {
// retryCondition 只有一个 Executable
Executable executable = this.getExecutableList().get(0);
if (ObjectUtil.isNotNull(executable.getId())) {
// 已经有 id 了
return executable.getId();
}
// 定义 id
switch (executable.getExecuteType()) {
// chain 和 node 一般都有 id
case CHAIN:
return ((Chain) executable).getChainId();
case CONDITION:
return "condition-" + ((Condition) executable).getConditionType().getName();
case NODE:
return "node-" + ((Node) executable).getType().getCode();
default:
return "unknown-executable";
}
}
}

View File

@@ -0,0 +1,108 @@
package com.yomahub.liteflow.test.retryTimes;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.test.BaseTest;
import com.yomahub.liteflow.test.rollback.RollbackELDeclMultiSpringbootTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import javax.annotation.Resource;
@ExtendWith(SpringExtension.class)
@TestPropertySource(value = "classpath:/retryTimes/application.properties")
@SpringBootTest(classes = RetryTimesELDeclMultiSpringbootTest.class)
@EnableAutoConfiguration
@ComponentScan({ "com.yomahub.liteflow.test.retryTimes.cmp" })
public class RetryTimesELDeclMultiSpringbootTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
// 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,82 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
import cn.hutool.core.collection.ListUtil;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.annotation.LiteflowMethod;
import com.yomahub.liteflow.annotation.LiteflowRetry;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
import com.yomahub.liteflow.enums.NodeTypeEnum;
import com.yomahub.liteflow.slot.DefaultContext;
import java.util.Iterator;
import java.util.List;
@LiteflowComponent
public class CmpConfig {
int flagb = 0;
int flagc = 0;
int flagd = 0;
int flagf = 0;
int flagi = 0;
int flagn = 0;
int flagw = 0;
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a")
public void processA(NodeComponent bindCmp) {
System.out.println("ACmp executed!");
}
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b")
public void processB(NodeComponent bindCmp) {
flagb ++;
System.out.println("BCmp executed!");
if(flagb < 4) throw new RuntimeException();
else flagb = 0;
}
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_FOR, nodeId = "c", nodeType = NodeTypeEnum.FOR)
public int processC(NodeComponent bindCmp) {
flagc ++;
System.out.println("CCmp executed!");
if(flagc < 4) throw new RuntimeException();
else return 1;
}
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeId = "d", nodeType = NodeTypeEnum.SWITCH)
public String processD(NodeComponent bindCmp) {
flagd ++;
System.out.println("DCmp executed!");
if(flagd < 4) throw new RuntimeException();
else return "a";
}
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_IF, nodeId = "f", nodeType = NodeTypeEnum.IF)
public boolean processF(NodeComponent bindCmp) {
System.out.println("FCmp executed!");
flagf ++;
if(flagf < 4) throw new RuntimeException();
else return true;
}
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_ITERATOR, nodeId = "i", nodeType = NodeTypeEnum.ITERATOR)
public Iterator<?> processI(NodeComponent bindCmp) {
flagi ++;
if(flagi < 4) throw new RuntimeException();
else {
List<String> list = ListUtil.toList("jack");
return list.iterator();
}
}
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_WHILE, nodeId = "n", nodeType = NodeTypeEnum.WHILE)
public boolean processN(NodeComponent bindCmp) {
flagn ++;
System.out.println("NCmp executed!");
if(flagn < 4) throw new RuntimeException();
else return flagn == 4 ? true : false;
}
}

View File

@@ -0,0 +1 @@
liteflow.rule-source=retryTimes/flow.el.xml

View File

@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<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>

View File

@@ -0,0 +1,104 @@
package com.yomahub.liteflow.test.retryTimes;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.test.context.TestPropertySource;
import javax.annotation.Resource;
@TestPropertySource(value = "classpath:/retryTimes/application.properties")
@SpringBootTest(classes = RetryTimesELDeclSpringbootTest.class)
@EnableAutoConfiguration
@ComponentScan({ "com.yomahub.liteflow.test.retryTimes.cmp" })
public class RetryTimesELDeclSpringbootTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
// 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,12 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
@LiteflowComponent("a")
public class ACmp extends NodeComponent {
@Override
public void process() {
System.out.println("ACmp executed!");
}
}

View File

@@ -0,0 +1,17 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
@LiteflowComponent("b")
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,17 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeForComponent;
@LiteflowComponent("c")
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,17 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeSwitchComponent;
@LiteflowComponent("d")
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,16 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeIfComponent;
@LiteflowComponent("f")
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,23 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
import cn.hutool.core.collection.ListUtil;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeIteratorComponent;
import java.util.Iterator;
import java.util.List;
@LiteflowComponent("i")
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,17 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeWhileComponent;
@LiteflowComponent("n")
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 @@
liteflow.rule-source=retryTimes/flow.el.xml

View File

@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<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>

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>

View File

@@ -0,0 +1,100 @@
package com.yomahub.liteflow.test.retryTimes;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.noear.solon.annotation.Inject;
import org.noear.solon.test.SolonJUnit5Extension;
import org.noear.solon.test.annotation.TestPropertySource;
@ExtendWith(SolonJUnit5Extension.class)
@TestPropertySource("classpath:/retryTimes/application.properties")
public class RetryTimesSpringbootTest extends BaseTest {
@Inject
private FlowExecutor flowExecutor;
// 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,12 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.noear.solon.annotation.Component;
@Component("a")
public class ACmp extends NodeComponent {
@Override
public void process() {
System.out.println("ACmp executed!");
}
}

View File

@@ -0,0 +1,17 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.noear.solon.annotation.Component;
@Component("b")
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,17 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
import com.yomahub.liteflow.core.NodeForComponent;
import org.noear.solon.annotation.Component;
@Component("c")
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,17 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
import com.yomahub.liteflow.core.NodeSwitchComponent;
import org.noear.solon.annotation.Component;
@Component("d")
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,16 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
import com.yomahub.liteflow.core.NodeIfComponent;
import org.noear.solon.annotation.Component;
@Component("f")
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,23 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
import cn.hutool.core.collection.ListUtil;
import com.yomahub.liteflow.core.NodeIteratorComponent;
import org.noear.solon.annotation.Component;
import java.util.Iterator;
import java.util.List;
@Component("i")
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,17 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
import com.yomahub.liteflow.core.NodeWhileComponent;
import org.noear.solon.annotation.Component;
@Component("n")
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 @@
liteflow.rule-source=retryTimes/flow.el.xml

View File

@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<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>

View File

@@ -0,0 +1,105 @@
package com.yomahub.liteflow.test.retryTimes;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.slot.DefaultContext;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.test.context.TestPropertySource;
import javax.annotation.Resource;
@TestPropertySource(value = "classpath:/retryTimes/application.properties")
@SpringBootTest(classes = RetryTimesSpringbootTest.class)
@EnableAutoConfiguration
@ComponentScan({ "com.yomahub.liteflow.test.retryTimes.cmp" })
public class RetryTimesSpringbootTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
// 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,12 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
@LiteflowComponent("a")
public class ACmp extends NodeComponent {
@Override
public void process() {
System.out.println("ACmp executed!");
}
}

View File

@@ -0,0 +1,18 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.annotation.LiteflowRetry;
import com.yomahub.liteflow.core.NodeComponent;
@LiteflowComponent("b")
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,17 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeForComponent;
@LiteflowComponent("c")
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,17 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeSwitchComponent;
@LiteflowComponent("d")
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,16 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeIfComponent;
@LiteflowComponent("f")
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,23 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
import cn.hutool.core.collection.ListUtil;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeIteratorComponent;
import java.util.Iterator;
import java.util.List;
@LiteflowComponent("i")
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,17 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeWhileComponent;
@LiteflowComponent("n")
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 @@
liteflow.rule-source=retryTimes/flow.el.xml

View File

@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<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>

View File

@@ -0,0 +1,101 @@
package com.yomahub.liteflow.test.retryTimes;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import javax.annotation.Resource;
@ExtendWith(SpringExtension.class)
@ContextConfiguration("classpath:/retryTimes/application.xml")
public class RetryTimesSpringTest extends BaseTest {
@Resource
private FlowExecutor flowExecutor;
// 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,12 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("a")
public class ACmp extends NodeComponent {
@Override
public void process() {
System.out.println("ACmp executed!");
}
}

View File

@@ -0,0 +1,17 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("b")
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,17 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
import com.yomahub.liteflow.core.NodeForComponent;
import org.springframework.stereotype.Component;
@Component("c")
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,17 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
import com.yomahub.liteflow.core.NodeSwitchComponent;
import org.springframework.stereotype.Component;
@Component("d")
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,16 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
import com.yomahub.liteflow.core.NodeIfComponent;
import org.springframework.stereotype.Component;
@Component("f")
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,23 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
import cn.hutool.core.collection.ListUtil;
import com.yomahub.liteflow.core.NodeIteratorComponent;
import org.springframework.stereotype.Component;
import java.util.Iterator;
import java.util.List;
@Component("i")
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,17 @@
package com.yomahub.liteflow.test.retryTimes.cmp;
import com.yomahub.liteflow.core.NodeWhileComponent;
import org.springframework.stereotype.Component;
@Component("n")
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,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<context:component-scan base-package="com.yomahub.liteflow.test.retryTimes.cmp" />
<bean id="springAware" class="com.yomahub.liteflow.spi.spring.SpringAware"/>
<bean class="com.yomahub.liteflow.spring.ComponentScanner"/>
<bean id="liteflowConfig" class="com.yomahub.liteflow.property.LiteflowConfig">
<property name="ruleSource" value="retryTimes/flow.el.xml"/>
</bean>
<bean id="flowExecutor" class="com.yomahub.liteflow.core.FlowExecutor">
<constructor-arg name="liteflowConfig" ref="liteflowConfig"/>
</bean>
</beans>

View File

@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<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>