From a88b7997dc90ffe1f8bf2341fcdc91edc85f9bba Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Thu, 13 Feb 2025 00:51:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B5=8B=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=EF=BC=8C=E4=B8=BA=E4=BA=86=E9=AA=8C=E8=AF=81=E5=BC=82?= =?UTF-8?q?=E6=AD=A5=E5=BE=AA=E7=8E=AF=E4=B8=8B=E7=9A=84=E5=B9=B6=E5=8F=91?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yomahub/liteflow/slot/DefaultContext.java | 2 +- .../parallelLoop/ParallelLoopCase_IASW3I.java | 56 +++++++++++++++++++ .../liteflow/test/parallelLoop/cmp/JCmp.java | 19 +++++++ .../application_IASW3I.properties | 4 ++ .../resources/parallelLoop/flow_IASW3I.xml | 6 ++ 5 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/ParallelLoopCase_IASW3I.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/JCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/parallelLoop/application_IASW3I.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/parallelLoop/flow_IASW3I.xml diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/slot/DefaultContext.java b/liteflow-core/src/main/java/com/yomahub/liteflow/slot/DefaultContext.java index 04fb8f055..857394eaf 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/slot/DefaultContext.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/slot/DefaultContext.java @@ -13,7 +13,7 @@ import java.util.concurrent.ConcurrentHashMap; */ public class DefaultContext { - private final ConcurrentHashMap dataMap = new ConcurrentHashMap<>(); + public final ConcurrentHashMap dataMap = new ConcurrentHashMap<>(); private void putDataMap(String key, T t) { if (ObjectUtil.isNull(t)) { diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/ParallelLoopCase_IASW3I.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/ParallelLoopCase_IASW3I.java new file mode 100644 index 000000000..bb725e31c --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/ParallelLoopCase_IASW3I.java @@ -0,0 +1,56 @@ +package com.yomahub.liteflow.test.parallelLoop; + +import cn.hutool.core.collection.ListUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.exception.LiteFlowException; +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.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; +import java.util.List; +import java.util.function.Consumer; +import java.util.regex.Pattern; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +/** + * springboot环境EL异步循环测试 + * + * @author zhhhhy + * @since 2.11.0 + */ +@ExtendWith(SpringExtension.class) +@TestPropertySource(value = "classpath:/parallelLoop/application_IASW3I.properties") +@SpringBootTest(classes = ParallelLoopCase_IASW3I.class) +@EnableAutoConfiguration +@ComponentScan({ "com.yomahub.liteflow.test.parallelLoop.cmp" }) +public class ParallelLoopCase_IASW3I extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + // 为了验证https://gitee.com/dromara/liteFlow/issues/IASW3I + // 为了验证2点 + // 1.异步循环不是串行的 2.不会有重复,并发问题 + @Test + public void testParallelLoop1() throws Exception { + List list = IntStream.range(0, 10000).boxed().collect(Collectors.toList()); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", list, DefaultContext.class); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertEquals(10000, context.dataMap.size()); + + } + + + + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/JCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/JCmp.java new file mode 100644 index 000000000..c8642e385 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/cmp/JCmp.java @@ -0,0 +1,19 @@ +package com.yomahub.liteflow.test.parallelLoop.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + + +@Component("j") +public class JCmp extends NodeComponent{ + + @Override + public void process() throws Exception { + DefaultContext context = this.getFirstContextBean(); + Integer loopObj = this.getCurrLoopObj(); + context.setData(loopObj.toString(), loopObj); + Thread.sleep(100L); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/parallelLoop/application_IASW3I.properties b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/parallelLoop/application_IASW3I.properties new file mode 100644 index 000000000..ba1b05413 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/parallelLoop/application_IASW3I.properties @@ -0,0 +1,4 @@ +liteflow.rule-source=parallelLoop/flow_IASW3I.xml +liteflow.global-thread-pool-size=64 +liteflow.global-thread-pool-queue-size=512 +liteflow.print-execution-log=false \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/parallelLoop/flow_IASW3I.xml b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/parallelLoop/flow_IASW3I.xml new file mode 100644 index 000000000..6d0fd0097 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/parallelLoop/flow_IASW3I.xml @@ -0,0 +1,6 @@ + + + + ITERATOR(it).parallel(true).DO(j); + + \ No newline at end of file