mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-15 12:32:09 +08:00
@@ -441,7 +441,7 @@ public class FlowExecutor {
|
||||
while(cmpStepIterator.hasNext()) {
|
||||
CmpStep cmpStep = cmpStepIterator.next();
|
||||
if(cmpStep.getInstance().isRollback()) {
|
||||
Rollbackable rollbackItem = new Node(cmpStep.getInstance());
|
||||
Rollbackable rollbackItem = cmpStep.getRefNode();
|
||||
rollbackItem.rollback(slotIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,6 +100,7 @@ public abstract class NodeComponent {
|
||||
CmpStep cmpStep = new CmpStep(nodeId, name, CmpStepTypeEnum.SINGLE);
|
||||
cmpStep.setTag(this.getTag());
|
||||
cmpStep.setInstance(this);
|
||||
cmpStep.setRefNode(this.getRefNode());
|
||||
slot.addStep(cmpStep);
|
||||
|
||||
StopWatch stopWatch = new StopWatch();
|
||||
@@ -158,6 +159,7 @@ public abstract class NodeComponent {
|
||||
|
||||
CmpStep cmpStep = new CmpStep(nodeId, name, CmpStepTypeEnum.SINGLE);
|
||||
cmpStep.setTag(this.getTag());
|
||||
cmpStep.setInstance(this);
|
||||
slot.addRollbackStep(cmpStep);
|
||||
|
||||
StopWatch stopWatch = new StopWatch();
|
||||
|
||||
@@ -12,6 +12,7 @@ import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.enums.CmpStepTypeEnum;
|
||||
import com.yomahub.liteflow.flow.element.Node;
|
||||
|
||||
/**
|
||||
* 组件步骤对象
|
||||
@@ -43,6 +44,10 @@ public class CmpStep {
|
||||
// 回滚消耗的时间
|
||||
private Long rollbackTimeSpent;
|
||||
|
||||
// 当前执行的node
|
||||
private Node refNode;
|
||||
|
||||
|
||||
public CmpStep(String nodeId, String nodeName, CmpStepTypeEnum stepType) {
|
||||
this.nodeId = nodeId;
|
||||
this.nodeName = nodeName;
|
||||
@@ -113,6 +118,14 @@ public class CmpStep {
|
||||
this.rollbackTimeSpent = rollbackTimeSpent;
|
||||
}
|
||||
|
||||
public Node getRefNode() {
|
||||
return refNode;
|
||||
}
|
||||
|
||||
public void setRefNode(Node refNode) {
|
||||
this.refNode = refNode;
|
||||
}
|
||||
|
||||
public String buildString() {
|
||||
if (stepType.equals(CmpStepTypeEnum.SINGLE)) {
|
||||
if (StrUtil.isBlank(nodeName)) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.yomahub.liteflow.test.rollback;
|
||||
|
||||
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;
|
||||
@@ -90,4 +91,13 @@ public class RollbackELDeclMultiSpringbootTest 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"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.yomahub.liteflow.annotation.LiteflowMethod;
|
||||
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;
|
||||
@@ -20,6 +21,17 @@ public class CmpConfig {
|
||||
|
||||
@LiteflowMethod(value = LiteFlowMethodEnum.ROLLBACK, nodeId = "a")
|
||||
public void rollbackA(NodeComponent bindCmp) throws Exception {
|
||||
String testKey = "test";
|
||||
|
||||
DefaultContext context = bindCmp.getFirstContextBean();
|
||||
if (context.getData(testKey) == null) {
|
||||
context.setData(testKey, bindCmp.getTag());
|
||||
}
|
||||
else {
|
||||
String s = context.getData(testKey);
|
||||
s += bindCmp.getTag();
|
||||
context.setData(testKey, s);
|
||||
}
|
||||
System.out.println("ACmp rollback!");
|
||||
}
|
||||
|
||||
|
||||
@@ -31,4 +31,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>
|
||||
@@ -2,6 +2,7 @@ package com.yomahub.liteflow.test.rollback;
|
||||
|
||||
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 com.yomahub.liteflow.test.whenTimeOut.WhenTimeOutELDeclSpringbootTest1;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
@@ -92,4 +93,13 @@ public class RollbackELDeclSpringbootTest 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"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
package com.yomahub.liteflow.test.rollback.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("a")
|
||||
@@ -20,6 +21,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!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,4 +31,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>
|
||||
@@ -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"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
@@ -2,6 +2,7 @@ package com.yomahub.liteflow.test.rollback;
|
||||
|
||||
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;
|
||||
@@ -84,4 +85,13 @@ public class RollbackSpringbootTest 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"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
package com.yomahub.liteflow.test.rollback.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import org.noear.solon.annotation.Component;
|
||||
|
||||
|
||||
@@ -21,6 +22,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!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,4 +31,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>
|
||||
@@ -2,6 +2,7 @@ package com.yomahub.liteflow.test.rollback;
|
||||
|
||||
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;
|
||||
@@ -87,4 +88,13 @@ public class RollbackSpringbootTest extends BaseTest {
|
||||
Assertions.assertNull(response.getCause());
|
||||
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"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
package com.yomahub.liteflow.test.rollback.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("a")
|
||||
@@ -20,6 +21,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!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,4 +31,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>
|
||||
@@ -2,6 +2,7 @@ package com.yomahub.liteflow.test.rollback;
|
||||
|
||||
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;
|
||||
@@ -85,5 +86,14 @@ public class RollbackSpringTest 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"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
package com.yomahub.liteflow.test.rollback.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.slot.DefaultContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("a")
|
||||
@@ -20,6 +21,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!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,4 +31,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>
|
||||
Reference in New Issue
Block a user