增加测试用例,为了验证异步循环下的并发问题

This commit is contained in:
everywhere.z
2025-02-13 00:51:33 +08:00
parent ebdab8b846
commit a88b7997dc
5 changed files with 86 additions and 1 deletions

View File

@@ -13,7 +13,7 @@ import java.util.concurrent.ConcurrentHashMap;
*/
public class DefaultContext {
private final ConcurrentHashMap<String, Object> dataMap = new ConcurrentHashMap<>();
public final ConcurrentHashMap<String, Object> dataMap = new ConcurrentHashMap<>();
private <T> void putDataMap(String key, T t) {
if (ObjectUtil.isNull(t)) {

View File

@@ -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<Integer> 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());
}
}

View File

@@ -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);
}
}

View File

@@ -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

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<chain name="chain1">
ITERATOR(it).parallel(true).DO(j);
</chain>
</flow>