提交subflow的一个嵌套例子

This commit is contained in:
everywhere.z
2025-05-29 14:51:03 +08:00
parent 7c1aa510dd
commit 1a2410afaa
5 changed files with 99 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ 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.subflow.context.TestContext;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -68,4 +69,14 @@ public class SubflowSpringbootTest extends BaseTest {
Assertions.assertEquals(100, testMap.get("inner"));
}
@Test
public void testSubflow7() throws Exception {
for (int i = 0; i < 500; i++) {
LiteflowResponse response = flowExecutor.execute2Resp("chain7", null, TestContext.class);
Assertions.assertTrue(response.isSuccess());
TestContext context = response.getFirstContextBean();
Assertions.assertEquals(5, context.getSet().size());
}
}
}

View File

@@ -0,0 +1,31 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.subflow.cmp;
import com.yomahub.liteflow.core.FlowExecutorHolder;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.slot.DefaultContext;
import com.yomahub.liteflow.test.subflow.context.TestContext;
import org.springframework.stereotype.Component;
@Component("j")
public class JCmp extends NodeComponent {
@Override
public void process() {
TestContext currentContext = this.getFirstContextBean();
String value = this.getTag();
LiteflowResponse response = FlowExecutorHolder.loadInstance().execute2Resp("chain7_invoke", value, DefaultContext.class);
DefaultContext subContext = response.getFirstContextBean();
String tagValue = subContext.getData("test");
currentContext.add2Set(tagValue);
}
}

View File

@@ -0,0 +1,23 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.subflow.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
import org.springframework.stereotype.Component;
@Component("k")
public class KCmp extends NodeComponent {
@Override
public void process() {
DefaultContext context = this.getFirstContextBean();
String value = this.getRequestData();
context.setData("test", value);
}
}

View File

@@ -0,0 +1,16 @@
package com.yomahub.liteflow.test.subflow.context;
import cn.hutool.core.collection.ConcurrentHashSet;
public class TestContext {
private ConcurrentHashSet<String> set = new ConcurrentHashSet<>();
public void add2Set(String value){
set.add(value);
}
public ConcurrentHashSet<String> getSet(){
return set;
}
}

View File

@@ -29,4 +29,22 @@
<chain name="chain6">
THEN(a, h.data("inner"));
</chain>
<chain name="chain7">
THEN(
a,
WHEN(
j.tag("1"),
j.tag("2"),
j.tag("3"),
j.tag("4"),
j.tag("5")
)
);
</chain>
<chain name="chain7_invoke">
THEN(k);
</chain>
</flow>