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