多层异步循环测试用例补充

This commit is contained in:
everywhere.z 2025-05-07 18:47:30 +08:00
parent 62b183727b
commit a8cdbfbb48
7 changed files with 76 additions and 8 deletions

View File

@ -1,5 +1,6 @@
package com.yomahub.liteflow.test.iterator;
import cn.hutool.core.collection.ConcurrentHashSet;
import cn.hutool.core.collection.ListUtil;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
@ -83,12 +84,15 @@ public class IteratorELSpringbootTest extends BaseTest {
@Test
public void testIt5() throws Exception {
DefaultContext context = new DefaultContext();
context.setData("set", new HashSet<>());
context.setData("set", new ConcurrentHashSet<>());
context.setData("list1", ListUtil.toList("a", "b", "c", "d", "e", "f"));
context.setData("list2", ListUtil.toList("1", "2", "3", "4", "5", "6", "7", "8", "9"));
context.setData("list2", ListUtil.toList("L2_1", "L2_2", "L2_3"));
context.setData("list3", ListUtil.toList("L3_1", "L3_2", "L3_3", "L3_4"));
context.setData("list4", ListUtil.toList("L4_1", "L4_2"));
context.setData("list5", ListUtil.toList("L5_1", "L5_2", "L5_3"));
LiteflowResponse response = flowExecutor.execute2Resp("chain5",null, context);
Assertions.assertTrue(response.isSuccess());
Set<String> set = context.getData("set");
Assertions.assertEquals(54, set.size());
Assertions.assertEquals(6*3*4*2*3, set.size());
}
}

View File

@ -13,12 +13,15 @@ public class FCmp extends NodeComponent {
@Override
public void process() throws Exception {
Object obj1 = this.getPreLoopObj();
Object obj2 = this.getCurrLoopObj();
Object obj1 = this.getCurrLoopObj();
Object obj2 = this.getPreNLoopObj(1);
Object obj3 = this.getPreNLoopObj(2);
Object obj4 = this.getPreNLoopObj(3);
Object obj5 = this.getPreNLoopObj(4);
if (obj1 == null || obj2 == null) {
throw new RuntimeException("");
}
String str = StrUtil.format("{}{}", obj1, obj2);
String str = StrUtil.format("{}-{}-{}-{}-{}", obj5, obj4, obj3, obj2, obj1);
DefaultContext context = this.getFirstContextBean();
Set<String> set = context.getData("set");
set.add(str);

View File

@ -0,0 +1,18 @@
package com.yomahub.liteflow.test.iterator.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeIteratorComponent;
import com.yomahub.liteflow.slot.DefaultContext;
import java.util.Iterator;
import java.util.List;
@LiteflowComponent("x3")
public class X3Cmp extends NodeIteratorComponent {
@Override
public Iterator<?> processIterator() throws Exception {
DefaultContext context = this.getFirstContextBean();
List<String> list = context.getData("list3");
return list.iterator();
}
}

View File

@ -0,0 +1,18 @@
package com.yomahub.liteflow.test.iterator.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeIteratorComponent;
import com.yomahub.liteflow.slot.DefaultContext;
import java.util.Iterator;
import java.util.List;
@LiteflowComponent("x4")
public class X4Cmp extends NodeIteratorComponent {
@Override
public Iterator<?> processIterator() throws Exception {
DefaultContext context = this.getFirstContextBean();
List<String> list = context.getData("list4");
return list.iterator();
}
}

View File

@ -0,0 +1,18 @@
package com.yomahub.liteflow.test.iterator.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeIteratorComponent;
import com.yomahub.liteflow.slot.DefaultContext;
import java.util.Iterator;
import java.util.List;
@LiteflowComponent("x5")
public class X5Cmp extends NodeIteratorComponent {
@Override
public Iterator<?> processIterator() throws Exception {
DefaultContext context = this.getFirstContextBean();
List<String> list = context.getData("list5");
return list.iterator();
}
}

View File

@ -1 +1,2 @@
liteflow.rule-source=iterator/flow.xml
liteflow.rule-source=iterator/flow.xml
liteflow.global-thread-pool-size=500

View File

@ -27,7 +27,13 @@
<chain name="chain5">
ITERATOR(x1).parallel(true).DO(
ITERATOR(x2).parallel(true).DO(f)
ITERATOR(x2).parallel(true).DO(
ITERATOR(x3).parallel(true).DO(
ITERATOR(x4).parallel(true).DO(
ITERATOR(x5).parallel(true).DO(f)
)
)
)
);
</chain>
</flow>