From a41a4d9a5b1a1017ae7bad271235633ca8e4c545 Mon Sep 17 00:00:00 2001 From: jason <2353220944@qq.com> Date: Mon, 21 Oct 2024 21:10:08 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E6=96=B0=E5=A2=9Echain-thread-pool-isolate?= =?UTF-8?q?=E6=8E=A7=E5=88=B6when+=E5=BC=82=E6=AD=A5=E5=BE=AA=E7=8E=AF?= =?UTF-8?q?=E7=9A=84=E7=BA=BF=E7=A8=8B=E6=B1=A0=E9=9A=94=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../builder/el/operator/WhenOperator.java | 3 ++ .../flow/element/condition/ForCondition.java | 2 +- .../element/condition/IteratorCondition.java | 2 +- .../element/condition/WhileCondition.java | 2 +- .../strategy/ParallelStrategyExecutor.java | 13 +++++- .../strategy/SpecifyParallelExecutor.java | 2 +- .../liteflow/property/LiteflowConfig.java | 33 ++++++++++++++- .../liteflow/thread/ExecutorHelper.java | 40 +++++++++++++++++-- .../LiteFlowDefaultChainExecutorBuilder.java | 28 +++++++++++++ .../config/LiteflowAutoConfiguration.java | 1 + .../solon/config/LiteflowProperty.java | 23 +++++++++++ .../META-INF/liteflow-default.properties | 1 + .../liteflow/springboot/LiteflowProperty.java | 12 ++++++ .../LiteflowPropertyAutoConfiguration.java | 1 + ...itional-spring-configuration-metadata.json | 7 ++++ .../META-INF/liteflow-default.properties | 1 + 16 files changed, 160 insertions(+), 11 deletions(-) create mode 100644 liteflow-core/src/main/java/com/yomahub/liteflow/thread/LiteFlowDefaultChainExecutorBuilder.java diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/WhenOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/WhenOperator.java index 00cfa58e0..60b676dc5 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/WhenOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/WhenOperator.java @@ -26,6 +26,9 @@ public class WhenOperator extends BaseOperator { OperatorHelper.checkObjMustBeCommonTypeItem(obj); whenCondition.addExecutable(OperatorHelper.convert(obj, Executable.class)); whenCondition.setThreadExecutorClass(liteflowConfig.getThreadExecutorClass()); + if (liteflowConfig.getChainThreadPoolIsolate()) { + whenCondition.setThreadExecutorClass(liteflowConfig.getChainThreadExecutorClass()); + } } return whenCondition; } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/ForCondition.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/ForCondition.java index 50f0a56e3..f77ee4017 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/ForCondition.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/ForCondition.java @@ -77,7 +77,7 @@ public class ForCondition extends LoopCondition { //存储所有的并行执行子项的CompletableFuture List> futureList = new ArrayList<>(); //获取并行循环的线程池 - ExecutorService parallelExecutor = ExecutorHelper.loadInstance().buildLoopParallelExecutor(); + ExecutorService parallelExecutor = ExecutorHelper.loadInstance().buildLoopParallelExecutor(slotIndex); for (int i = 0; i < forCount; i++){ //提交异步任务 CompletableFuture future = diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/IteratorCondition.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/IteratorCondition.java index 2a2a640b0..f0efae8c0 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/IteratorCondition.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/IteratorCondition.java @@ -80,7 +80,7 @@ public class IteratorCondition extends LoopCondition { //存储所有的并行执行子项的CompletableFuture List> futureList = new ArrayList<>(); //获取并行循环的线程池 - ExecutorService parallelExecutor = ExecutorHelper.loadInstance().buildLoopParallelExecutor(); + ExecutorService parallelExecutor = ExecutorHelper.loadInstance().buildLoopParallelExecutor(slotIndex); while (it.hasNext()) { Object itObj = it.next(); //提交异步任务 diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/WhileCondition.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/WhileCondition.java index 0e00e761f..145489c10 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/WhileCondition.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/WhileCondition.java @@ -61,7 +61,7 @@ public class WhileCondition extends LoopCondition { //并行循环逻辑 List> futureList = new ArrayList<>(); //获取并行循环的线程池 - ExecutorService parallelExecutor = ExecutorHelper.loadInstance().buildLoopParallelExecutor(); + ExecutorService parallelExecutor = ExecutorHelper.loadInstance().buildLoopParallelExecutor(slotIndex); while (getWhileResult(slotIndex, index)){ CompletableFuture future = CompletableFuture.supplyAsync(new LoopParallelSupplier(executableItem, this.getCurrChainId(), slotIndex, index), parallelExecutor); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/strategy/ParallelStrategyExecutor.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/strategy/ParallelStrategyExecutor.java index 398b71749..bbdd44c41 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/strategy/ParallelStrategyExecutor.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/strategy/ParallelStrategyExecutor.java @@ -5,6 +5,8 @@ import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.yomahub.liteflow.enums.ParallelStrategyEnum; import com.yomahub.liteflow.exception.WhenExecuteException; +import com.yomahub.liteflow.flow.FlowBus; +import com.yomahub.liteflow.flow.element.Chain; import com.yomahub.liteflow.flow.element.Executable; import com.yomahub.liteflow.flow.element.Node; import com.yomahub.liteflow.flow.element.condition.FinallyCondition; @@ -122,7 +124,7 @@ public abstract class ParallelStrategyExecutor { * @param whenCondition * @return */ - protected ExecutorService getWhenExecutorService(WhenCondition whenCondition) { + protected ExecutorService getWhenExecutorService(WhenCondition whenCondition, Integer slotIndex) { LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); @@ -133,6 +135,13 @@ public abstract class ParallelStrategyExecutor { if (BooleanUtil.isTrue(liteflowConfig.getWhenThreadPoolIsolate())) { parallelExecutor = ExecutorHelper.loadInstance().buildWhenExecutorWithHash(whenCondition.getThreadExecutorClass(), String.valueOf(whenCondition.hashCode())); + } else if (BooleanUtil.isTrue(liteflowConfig.getChainThreadPoolIsolate())) { + //chain 线程池隔离 + String chainId = DataBus.getSlot(slotIndex).getChainId(); + Chain chain = FlowBus.getChain(chainId); + parallelExecutor = + ExecutorHelper.loadInstance().buildWhenExecutorWithHash(whenCondition.getThreadExecutorClass(), + String.valueOf(chain.hashCode())); } else { parallelExecutor = ExecutorHelper.loadInstance().buildWhenExecutor(whenCondition.getThreadExecutorClass()); } @@ -155,7 +164,7 @@ public abstract class ParallelStrategyExecutor { this.setWhenConditionParams(whenCondition); // 获取 WHEN 所需线程池 - ExecutorService parallelExecutor = getWhenExecutorService(whenCondition); + ExecutorService parallelExecutor = getWhenExecutorService(whenCondition, slotIndex); // 这里主要是做了封装 CompletableFuture 对象,用 lambda 表达式做了很多事情,这句代码要仔细理清 // 根据 condition.getNodeList() 的集合进行流处理,用 map 进行把 executable 对象转换成 List> diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/strategy/SpecifyParallelExecutor.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/strategy/SpecifyParallelExecutor.java index bfa89cdc5..8f204c396 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/strategy/SpecifyParallelExecutor.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/strategy/SpecifyParallelExecutor.java @@ -26,7 +26,7 @@ public class SpecifyParallelExecutor extends ParallelStrategyExecutor { this.setWhenConditionParams(whenCondition); // 获取 WHEN 所需线程池 - ExecutorService parallelExecutor = getWhenExecutorService(whenCondition); + ExecutorService parallelExecutor = getWhenExecutorService(whenCondition, slotIndex); // 指定完成的任务 CompletableFuture specifyTask; diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java b/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java index d269da250..c39ed27bc 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java @@ -13,7 +13,6 @@ import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.yomahub.liteflow.enums.ParseModeEnum; -import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; @@ -45,6 +44,9 @@ public class LiteflowConfig { // 并行线程执行器class路径 private String threadExecutorClass; + // chain线程执行器class路径 + private String chainThreadExecutorClass; + // 异步线程最大等待秒数 @Deprecated private Integer whenMaxWaitSeconds; @@ -124,6 +126,11 @@ public class LiteflowConfig { //脚本特殊设置选项 private Map scriptSetting; + // chain线程池是否隔离 + // 每一个chain里的when和异步循环合并起来都用单独的线程池。也就是说定义了多少个chain,就有多少个线程池 + private Boolean chainThreadPoolIsolate; + + public Boolean getEnableMonitorFile() { return enableMonitorFile; } @@ -311,6 +318,18 @@ public class LiteflowConfig { this.threadExecutorClass = threadExecutorClass; } + public String getChainThreadExecutorClass() { + if (StrUtil.isBlank(chainThreadExecutorClass)) { + return "com.yomahub.liteflow.thread.LiteFlowDefaultChainExecutorBuilder"; + } else { + return chainThreadExecutorClass; + } + } + + public void setChainThreadExecutorClass(String threadExecutorClass) { + this.threadExecutorClass = threadExecutorClass; + } + public String getNodeExecutorClass() { if (StrUtil.isBlank(nodeExecutorClass)) { return "com.yomahub.liteflow.flow.executor.DefaultNodeExecutor"; @@ -509,4 +528,16 @@ public class LiteflowConfig { public void setScriptSetting(Map scriptSetting) { this.scriptSetting = scriptSetting; } + + public Boolean getChainThreadPoolIsolate() { + if (ObjectUtil.isNull(chainThreadPoolIsolate)) { + return Boolean.FALSE; + } else { + return chainThreadPoolIsolate; + } + } + + public void setChainThreadPoolIsolate(Boolean chainThreadPoolIsolate) { + this.chainThreadPoolIsolate = chainThreadPoolIsolate; + } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java index 02973448f..b283e11e5 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java @@ -9,19 +9,22 @@ package com.yomahub.liteflow.thread; import cn.hutool.core.map.MapUtil; +import cn.hutool.core.util.BooleanUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.yomahub.liteflow.exception.ThreadExecutorServiceCreateException; +import com.yomahub.liteflow.flow.FlowBus; +import com.yomahub.liteflow.flow.element.Chain; import com.yomahub.liteflow.log.LFLog; import com.yomahub.liteflow.log.LFLoggerManager; import com.yomahub.liteflow.property.LiteflowConfig; import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.slot.DataBus; import com.yomahub.liteflow.spi.holder.ContextAwareHolder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.Map; -import java.util.concurrent.*; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.TimeUnit; /** * 线程池工具类 @@ -128,8 +131,15 @@ public class ExecutorHelper { } //构造并行循环的线程池 - public ExecutorService buildLoopParallelExecutor(){ + public ExecutorService buildLoopParallelExecutor(Integer slotIndex) { LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + //chain线程池 + if (BooleanUtil.isTrue(liteflowConfig.getWhenThreadPoolIsolate())) { + //获取chain的hash + String chainId = DataBus.getSlot(slotIndex).getChainId(); + Chain chain = FlowBus.getChain(chainId); + return getExecutorService(liteflowConfig.getThreadExecutorClass(), String.valueOf(chain.hashCode())); + } return getExecutorService(liteflowConfig.getParallelLoopExecutorClass()); } @@ -173,4 +183,26 @@ public class ExecutorHelper { } } + // 构建when线程池 - clazz和condition的hash值共同作为缓存key + public ExecutorService buildChainExecutorWithHash(String conditionHash) { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + return buildChainExecutorWithHash(liteflowConfig.getThreadExecutorClass(), conditionHash); + } + + // 构建when线程池 - clazz和condition的hash值共同作为缓存key + public ExecutorService buildChainExecutorWithHash(String clazz, String conditionHash) { + if (StrUtil.isBlank(clazz)) { + return buildWhenExecutorWithHash(conditionHash); + } + return getExecutorService(clazz, conditionHash); + } + + // 构建when线程池 - 支持多个when公用一个线程池 + public ExecutorService buildChainExecutor(String clazz) { + if (StrUtil.isBlank(clazz)) { + return buildWhenExecutor(); + } + return getExecutorService(clazz); + } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/LiteFlowDefaultChainExecutorBuilder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/LiteFlowDefaultChainExecutorBuilder.java new file mode 100644 index 000000000..45f0a517b --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/LiteFlowDefaultChainExecutorBuilder.java @@ -0,0 +1,28 @@ +package com.yomahub.liteflow.thread; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; + +import java.util.concurrent.ExecutorService; + +/** + * LiteFlow默认的并行多线程执行器实现 + * + * @author Bryan.Zhang + * @since 2.6.6 + */ +public class LiteFlowDefaultChainExecutorBuilder implements ExecutorBuilder { + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenQueueLimit(), "chain-thread-"); + } + +} diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowAutoConfiguration.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowAutoConfiguration.java index 5d560cfde..4879d7d5e 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowAutoConfiguration.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowAutoConfiguration.java @@ -30,6 +30,7 @@ public class LiteflowAutoConfiguration { liteflowConfig.setRuleSourceExtDataMap(property.getRuleSourceExtDataMap()); liteflowConfig.setSlotSize(property.getSlotSize()); liteflowConfig.setThreadExecutorClass(property.getThreadExecutorClass()); + liteflowConfig.setChainThreadExecutorClass(property.getChainThreadExecutorClass()); liteflowConfig.setWhenMaxWaitSeconds(property.getWhenMaxWaitSeconds()); liteflowConfig.setEnableLog(liteflowMonitorProperty.isEnableLog()); liteflowConfig.setQueueLimit(liteflowMonitorProperty.getQueueLimit()); diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowProperty.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowProperty.java index d58dd333f..d68158f8c 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowProperty.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowProperty.java @@ -40,6 +40,9 @@ public class LiteflowProperty { // 并行线程执行器class路径 private String threadExecutorClass; + // chain线程执行器class路径 + private String chainThreadExecutorClass; + // 异步线程最大等待描述 private int whenMaxWaitSeconds; @@ -83,6 +86,10 @@ public class LiteflowProperty { // 是否启用组件降级 private Boolean fallbackCmpEnable; + // chain线程池是否隔离 + // 每一个chain里的when和异步循环合并起来都用单独的线程池。也就是说定义了多少个chain,就有多少个线程池 + private boolean chainThreadPoolIsolate; + public boolean isEnable() { return enable; } @@ -168,6 +175,14 @@ public class LiteflowProperty { this.threadExecutorClass = threadExecutorClass; } + public String getChainThreadExecutorClass() { + return chainThreadExecutorClass; + } + + public void setChainThreadExecutorClass(String chainThreadExecutorClass) { + this.chainThreadExecutorClass = chainThreadExecutorClass; + } + public String getNodeExecutorClass() { return nodeExecutorClass; } @@ -267,4 +282,12 @@ public class LiteflowProperty { public Boolean getFallbackCmpEnable() { return fallbackCmpEnable; } + + public void setChainThreadPoolIsolate(boolean chainThreadPoolIsolate) { + this.chainThreadPoolIsolate = chainThreadPoolIsolate; + } + + public boolean isChainThreadPoolIsolate() { + return chainThreadPoolIsolate; + } } diff --git a/liteflow-solon-plugin/src/main/resources/META-INF/liteflow-default.properties b/liteflow-solon-plugin/src/main/resources/META-INF/liteflow-default.properties index c1fda2e94..07ac3e2b6 100644 --- a/liteflow-solon-plugin/src/main/resources/META-INF/liteflow-default.properties +++ b/liteflow-solon-plugin/src/main/resources/META-INF/liteflow-default.properties @@ -5,6 +5,7 @@ liteflow.main-executor-works=64 liteflow.main-executor-class=com.yomahub.liteflow.thread.LiteFlowDefaultMainExecutorBuilder liteflow.request-id-generator-class=com.yomahub.liteflow.flow.id.DefaultRequestIdGenerator liteflow.thread-executor-class=com.yomahub.liteflow.thread.LiteFlowDefaultWhenExecutorBuilder +liteflow.chain-thread-executor-class=com.yomahub.liteflow.thread.LiteFlowDefaultChainExecutorBuilder liteflow.when-max-wait-seconds=15 liteflow.when-max-workers=16 liteflow.when-queue-limit=512 diff --git a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowProperty.java b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowProperty.java index 930a62d4c..c829fd2a9 100644 --- a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowProperty.java +++ b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowProperty.java @@ -101,6 +101,10 @@ public class LiteflowProperty { //脚本特殊设置选项 private Map scriptSetting; + // chain线程池是否隔离 + // 每一个chain里的when和异步循环合并起来都用单独的线程池。也就是说定义了多少个chain,就有多少个线程池 + private Boolean chainThreadPoolIsolate; + public boolean isEnableMonitorFile() { return enableMonitorFile; } @@ -336,4 +340,12 @@ public class LiteflowProperty { public void setScriptSetting(Map scriptSetting) { this.scriptSetting = scriptSetting; } + + public void setChainThreadPoolIsolate(boolean chainThreadPoolIsolate) { + this.chainThreadPoolIsolate = chainThreadPoolIsolate; + } + + public boolean isChainThreadPoolIsolate() { + return chainThreadPoolIsolate; + } } diff --git a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowPropertyAutoConfiguration.java b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowPropertyAutoConfiguration.java index 37356fcb3..a4dc8ef10 100644 --- a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowPropertyAutoConfiguration.java +++ b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowPropertyAutoConfiguration.java @@ -54,6 +54,7 @@ public class LiteflowPropertyAutoConfiguration { liteflowConfig.setDelay(liteflowMonitorProperty.getDelay()); liteflowConfig.setPeriod(liteflowMonitorProperty.getPeriod()); liteflowConfig.setScriptSetting(property.getScriptSetting()); + liteflowConfig.setChainThreadPoolIsolate(property.isChainThreadPoolIsolate()); return liteflowConfig; } diff --git a/liteflow-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/liteflow-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 83b0b668e..a5c09d6aa 100644 --- a/liteflow-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/liteflow-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -110,6 +110,13 @@ "sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty", "defaultValue": false }, + { + "name": "liteflow.chain-thread-pool-isolate", + "type": "java.lang.Boolean", + "description": "set whether the chain thread pool is isolated.", + "sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty", + "defaultValue": false + }, { "name": "liteflow.parse-mode", "type": "com.yomahub.liteflow.enums.ParseModeEnum", diff --git a/liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties b/liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties index 37aeb4645..83db19650 100644 --- a/liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties +++ b/liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties @@ -10,6 +10,7 @@ liteflow.when-max-wait-time-unit=MILLISECONDS liteflow.when-max-workers=16 liteflow.when-queue-limit=512 liteflow.when-thread-pool-isolate=false +liteflow.chain-thread-pool-isolate=false liteflow.parse-mode=PARSE_ALL_ON_START liteflow.retry-count=0 liteflow.support-multiple-type=false From 8e4634b0b8d4a96ff661b261ac93834108fe1a4d Mon Sep 17 00:00:00 2001 From: jason <2353220944@qq.com> Date: Tue, 22 Oct 2024 15:31:47 +0800 Subject: [PATCH 2/9] add springboot test --- .../strategy/ParallelStrategyExecutor.java | 2 +- .../liteflow/property/LiteflowConfig.java | 36 +++++++- .../liteflow/thread/ExecutorHelper.java | 19 ++-- .../LiteFlowDefaultChainExecutorBuilder.java | 9 +- .../liteflow/springboot/LiteflowProperty.java | 34 +++++++ .../LiteflowPropertyAutoConfiguration.java | 3 + .../META-INF/liteflow-default.properties | 2 + ...CustomChainThreadPoolELSpringbootTest.java | 92 +++++++++++++++++++ .../CustomThreadExecutor1.java | 23 +++++ .../CustomThreadExecutor2.java | 23 +++++ ...efaultChainThreadPoolELSpringbootTest.java | 45 +++++++++ .../test/chainThreadPool/cmp/ACmp.java | 22 +++++ .../test/chainThreadPool/cmp/BCmp.java | 25 +++++ .../test/chainThreadPool/cmp/DCmp.java | 30 ++++++ .../test/chainThreadPool/cmp/FCmp.java | 25 +++++ .../test/chainThreadPool/cmp/ICmp.java | 25 +++++ .../test/chainThreadPool/cmp/ITCmp.java | 17 ++++ .../test/chainThreadPool/cmp/WCmp.java | 25 +++++ .../test/chainThreadPool/cmp/ZCmp.java | 21 +++++ .../chainThreadPool/application.properties | 4 + .../chainThreadPool/application2.properties | 5 + .../resources/chainThreadPool/flow.el.xml | 9 ++ .../resources/chainThreadPool/flow2.el.xml | 27 ++++++ 23 files changed, 500 insertions(+), 23 deletions(-) create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomChainThreadPoolELSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomThreadExecutor1.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomThreadExecutor2.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/DefaultChainThreadPoolELSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ACmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/BCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/DCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/FCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ICmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ITCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/WCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ZCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/application.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/application2.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/flow.el.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/flow2.el.xml diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/strategy/ParallelStrategyExecutor.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/strategy/ParallelStrategyExecutor.java index bbdd44c41..109055a53 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/strategy/ParallelStrategyExecutor.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/strategy/ParallelStrategyExecutor.java @@ -140,7 +140,7 @@ public abstract class ParallelStrategyExecutor { String chainId = DataBus.getSlot(slotIndex).getChainId(); Chain chain = FlowBus.getChain(chainId); parallelExecutor = - ExecutorHelper.loadInstance().buildWhenExecutorWithHash(whenCondition.getThreadExecutorClass(), + ExecutorHelper.loadInstance().buildChainExecutorWithHash(whenCondition.getThreadExecutorClass(), String.valueOf(chain.hashCode())); } else { parallelExecutor = ExecutorHelper.loadInstance().buildWhenExecutor(whenCondition.getThreadExecutorClass()); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java b/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java index c39ed27bc..5ddb3d2e0 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java @@ -76,6 +76,12 @@ public class LiteflowConfig { // 异步线程池最大队列数量 private Integer whenQueueLimit; + // chain线程池最大线程数 + private Integer chainMaxWorkers; + + // chain线程池最大队列数量 + private Integer chainQueueLimit; + // 解析模式,一共有三种,具体看其定义 private ParseModeEnum parseMode; @@ -250,7 +256,6 @@ public class LiteflowConfig { public void setWhenMaxWorkers(Integer whenMaxWorkers) { this.whenMaxWorkers = whenMaxWorkers; } - public Integer getWhenQueueLimit() { if (ObjectUtil.isNull(whenQueueLimit)) { return 512; @@ -326,8 +331,8 @@ public class LiteflowConfig { } } - public void setChainThreadExecutorClass(String threadExecutorClass) { - this.threadExecutorClass = threadExecutorClass; + public void setChainThreadExecutorClass(String chainThreadExecutorClass) { + this.chainThreadExecutorClass = chainThreadExecutorClass; } public String getNodeExecutorClass() { @@ -540,4 +545,29 @@ public class LiteflowConfig { public void setChainThreadPoolIsolate(Boolean chainThreadPoolIsolate) { this.chainThreadPoolIsolate = chainThreadPoolIsolate; } + + public Integer getChainMaxWorkers() { + if (ObjectUtil.isNull(chainMaxWorkers)) { + return 16; + } else { + return chainMaxWorkers; + } + } + + public void setChainMaxWorkers(Integer chainMaxWorkers) { + this.chainMaxWorkers = chainMaxWorkers; + } + + public Integer getChainQueueLimit() { + if (ObjectUtil.isNull(chainMaxWorkers)) { + return 512; + } else { + return chainQueueLimit; + } + } + + public void setChainQueueLimit(Integer chainQueueLimit) { + this.chainQueueLimit = chainQueueLimit; + } + } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java index b283e11e5..f0a4a27d8 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java @@ -134,11 +134,11 @@ public class ExecutorHelper { public ExecutorService buildLoopParallelExecutor(Integer slotIndex) { LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); //chain线程池 - if (BooleanUtil.isTrue(liteflowConfig.getWhenThreadPoolIsolate())) { + if (BooleanUtil.isTrue(liteflowConfig.getChainThreadPoolIsolate())) { //获取chain的hash String chainId = DataBus.getSlot(slotIndex).getChainId(); Chain chain = FlowBus.getChain(chainId); - return getExecutorService(liteflowConfig.getThreadExecutorClass(), String.valueOf(chain.hashCode())); + return getExecutorService(liteflowConfig.getChainThreadExecutorClass(), String.valueOf(chain.hashCode())); } return getExecutorService(liteflowConfig.getParallelLoopExecutorClass()); } @@ -183,26 +183,19 @@ public class ExecutorHelper { } } - // 构建when线程池 - clazz和condition的hash值共同作为缓存key + // 构建chain线程池 - clazz和condition的hash值共同作为缓存key public ExecutorService buildChainExecutorWithHash(String conditionHash) { LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - return buildChainExecutorWithHash(liteflowConfig.getThreadExecutorClass(), conditionHash); + return buildChainExecutorWithHash(liteflowConfig.getChainThreadExecutorClass(), conditionHash); } - // 构建when线程池 - clazz和condition的hash值共同作为缓存key + // 构建chain线程池 - clazz和condition的hash值共同作为缓存key public ExecutorService buildChainExecutorWithHash(String clazz, String conditionHash) { if (StrUtil.isBlank(clazz)) { - return buildWhenExecutorWithHash(conditionHash); + return buildChainExecutorWithHash(conditionHash); } return getExecutorService(clazz, conditionHash); } - // 构建when线程池 - 支持多个when公用一个线程池 - public ExecutorService buildChainExecutor(String clazz) { - if (StrUtil.isBlank(clazz)) { - return buildWhenExecutor(); - } - return getExecutorService(clazz); - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/LiteFlowDefaultChainExecutorBuilder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/LiteFlowDefaultChainExecutorBuilder.java index 45f0a517b..3148a08cf 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/LiteFlowDefaultChainExecutorBuilder.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/LiteFlowDefaultChainExecutorBuilder.java @@ -7,10 +7,7 @@ import com.yomahub.liteflow.property.LiteflowConfigGetter; import java.util.concurrent.ExecutorService; /** - * LiteFlow默认的并行多线程执行器实现 - * - * @author Bryan.Zhang - * @since 2.6.6 + * LiteFlow默认的chain多线程执行器实现 */ public class LiteFlowDefaultChainExecutorBuilder implements ExecutorBuilder { @@ -21,8 +18,8 @@ public class LiteFlowDefaultChainExecutorBuilder implements ExecutorBuilder { if (ObjectUtil.isNull(liteflowConfig)) { liteflowConfig = new LiteflowConfig(); } - return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), "chain-thread-"); + return buildDefaultExecutor(liteflowConfig.getChainMaxWorkers(), liteflowConfig.getChainMaxWorkers(), + liteflowConfig.getChainQueueLimit(), "chain-thread-"); } } diff --git a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowProperty.java b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowProperty.java index c829fd2a9..34e3c434d 100644 --- a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowProperty.java +++ b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowProperty.java @@ -105,6 +105,15 @@ public class LiteflowProperty { // 每一个chain里的when和异步循环合并起来都用单独的线程池。也就是说定义了多少个chain,就有多少个线程池 private Boolean chainThreadPoolIsolate; + // chain线程池最大线程数 + private int chainMaxWorkers; + + // chain线程池最大队列数量 + private int chainQueueLimit; + + // chain线程执行器class路径 + private String chainThreadExecutorClass; + public boolean isEnableMonitorFile() { return enableMonitorFile; } @@ -348,4 +357,29 @@ public class LiteflowProperty { public boolean isChainThreadPoolIsolate() { return chainThreadPoolIsolate; } + + public int getChainMaxWorkers() { + return chainMaxWorkers; + } + + public void setChainMaxWorkers(int chainMaxWorkers) { + this.chainMaxWorkers = chainMaxWorkers; + } + + public int getChainQueueLimit() { + return chainQueueLimit; + } + + public void setChainQueueLimit(int chainQueueLimit) { + this.chainQueueLimit = chainQueueLimit; + } + + public String getChainThreadExecutorClass() { + return chainThreadExecutorClass; + } + + public void setChainThreadExecutorClass(String chainThreadExecutorClass) { + this.chainThreadExecutorClass = chainThreadExecutorClass; + } + } diff --git a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowPropertyAutoConfiguration.java b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowPropertyAutoConfiguration.java index a4dc8ef10..4976f0eca 100644 --- a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowPropertyAutoConfiguration.java +++ b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowPropertyAutoConfiguration.java @@ -55,6 +55,9 @@ public class LiteflowPropertyAutoConfiguration { liteflowConfig.setPeriod(liteflowMonitorProperty.getPeriod()); liteflowConfig.setScriptSetting(property.getScriptSetting()); liteflowConfig.setChainThreadPoolIsolate(property.isChainThreadPoolIsolate()); + liteflowConfig.setChainThreadExecutorClass(property.getChainThreadExecutorClass()); + liteflowConfig.setChainMaxWorkers(property.getChainMaxWorkers()); + liteflowConfig.setChainQueueLimit(property.getChainQueueLimit()); return liteflowConfig; } diff --git a/liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties b/liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties index 83db19650..f97867ad5 100644 --- a/liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties +++ b/liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties @@ -9,6 +9,8 @@ liteflow.when-max-wait-time=15000 liteflow.when-max-wait-time-unit=MILLISECONDS liteflow.when-max-workers=16 liteflow.when-queue-limit=512 +liteflow.chain-max-workers=16 +liteflow.chain-queue-limit=512 liteflow.when-thread-pool-isolate=false liteflow.chain-thread-pool-isolate=false liteflow.parse-mode=PARSE_ALL_ON_START diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomChainThreadPoolELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomChainThreadPoolELSpringbootTest.java new file mode 100644 index 000000000..b98d4bbda --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomChainThreadPoolELSpringbootTest.java @@ -0,0 +1,92 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.collection.ListUtil; +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 org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +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 javax.annotation.Resource; +import java.util.List; + +/** + * springboot环境下chain线程池隔离测试 + */ +@TestPropertySource(value = "classpath:/chainThreadPool/application2.properties") +@SpringBootTest(classes = CustomChainThreadPoolELSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.chainThreadPool.cmp"}) +public class CustomChainThreadPoolELSpringbootTest extends BaseTest { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Resource + private FlowExecutor flowExecutor; + + /** + * 测试chain自定义线程池隔离 + */ + @Test + public void testCustomChainThreadPool1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertTrue(context.getData("threadNameFor").toString().startsWith("customer-chain-thead-1")); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead-1")); + } + + /** + * 测试when上自定义线程池和chain线程池隔离-优先以when上为准 + */ + @Test + public void testCustomChainThreadPool2() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead-2")); + } + + /** + * 测试并行FOR循环全局线程池和chain线程池隔离-优先以chain线程池上为准 + */ + @Test + public void testCustomChainThreadPool3() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadNameFor").toString().startsWith("customer-chain-thead-1")); + } + + /** + * 测试并行条件循环全局线程池和chain线程池隔离-优先以chain线程池上为准 + */ + @Test + public void testCustomChainThreadPool4() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain4", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadNameWhile").toString().startsWith("customer-chain-thead-1")); + } + + /** + * 测试并行迭代循环全局线程池和chain线程池隔离-优先以chain线程池上为准 + */ + @Test + public void testCustomChainThreadPool5() { + List list = ListUtil.toList("1", "2", "3", "4", "5"); + LiteflowResponse response1 = flowExecutor.execute2Resp("chain5", list); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadNameIterator").toString().startsWith("customer-chain-thead-1")); + } + + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomThreadExecutor1.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomThreadExecutor1.java new file mode 100644 index 000000000..f19c37ec4 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomThreadExecutor1.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomThreadExecutor1 implements ExecutorBuilder { + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(liteflowConfig.getChainMaxWorkers(), liteflowConfig.getChainMaxWorkers(), + liteflowConfig.getChainQueueLimit(), "customer-chain-thead-1"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomThreadExecutor2.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomThreadExecutor2.java new file mode 100644 index 000000000..4527fbd16 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomThreadExecutor2.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomThreadExecutor2 implements ExecutorBuilder { + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(liteflowConfig.getChainMaxWorkers(), liteflowConfig.getChainMaxWorkers(), + liteflowConfig.getChainQueueLimit(), "customer-chain-thead-2"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/DefaultChainThreadPoolELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/DefaultChainThreadPoolELSpringbootTest.java new file mode 100644 index 000000000..5c31217aa --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/DefaultChainThreadPoolELSpringbootTest.java @@ -0,0 +1,45 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +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 org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +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 javax.annotation.Resource; + +/** + * springboot环境下chain线程池隔离测试 + */ +@TestPropertySource(value = "classpath:/chainThreadPool/application.properties") +@SpringBootTest(classes = DefaultChainThreadPoolELSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.chainThreadPool.cmp"}) +public class DefaultChainThreadPoolELSpringbootTest extends BaseTest { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Resource + private FlowExecutor flowExecutor; + + /** + * 测试chain默认线程池隔离 + */ + @Test + public void testDefaultChainThreadPool() { + LiteflowResponse response = flowExecutor.execute2Resp("chain", "arg"); + DefaultContext context = response.getFirstContextBean(); + Assertions.assertTrue(response.isSuccess()); + Assertions.assertTrue(context.getData("threadNameFor").toString().startsWith("chain-thread-")); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("chain-thread-")); + + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ACmp.java new file mode 100644 index 000000000..774bb1b38 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ACmp.java @@ -0,0 +1,22 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +@Component("a") +public class ACmp extends NodeComponent { + + @Override + public void process() { + System.out.println("ACmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/BCmp.java new file mode 100644 index 000000000..f15e585b7 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("b") +public class BCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/DCmp.java new file mode 100644 index 000000000..0921b17b3 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/DCmp.java @@ -0,0 +1,30 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("d") +public class DCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + String key = "test"; + if (context.hasData(key)) { + int count = context.getData(key); + context.setData(key, ++count); + } else { + context.setData(key, 1); + } + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/FCmp.java new file mode 100644 index 000000000..3e48aac9f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/FCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("f") +public class FCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData("threadNameFor", Thread.currentThread().getName()); + System.out.println("FCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ICmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ICmp.java new file mode 100644 index 000000000..25424c581 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ICmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("i") +public class ICmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData("threadNameIterator", Thread.currentThread().getName()); + System.out.println("ICmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ITCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ITCmp.java new file mode 100644 index 000000000..6a20f11d7 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ITCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.core.NodeIteratorComponent; +import org.springframework.stereotype.Component; + +import java.util.Iterator; +import java.util.List; + +@Component("it") +public class ITCmp extends NodeIteratorComponent { + + @Override + public Iterator processIterator() throws Exception { + List list = this.getRequestData(); + return list.iterator(); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/WCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/WCmp.java new file mode 100644 index 000000000..8c394ddb5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/WCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("w") +public class WCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData("threadNameWhile", Thread.currentThread().getName()); + System.out.println("WCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ZCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ZCmp.java new file mode 100644 index 000000000..4c608f1c0 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ZCmp.java @@ -0,0 +1,21 @@ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.core.NodeBooleanComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("z") +public class ZCmp extends NodeBooleanComponent { + + @Override + public boolean processBoolean() throws Exception { + DefaultContext context = this.getFirstContextBean(); + String key = "test"; + if (context.hasData(key)) { + int count = context.getData("test"); + return count < 5; + } else { + return true; + } + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/application.properties b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/application.properties new file mode 100644 index 000000000..587e96142 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/application.properties @@ -0,0 +1,4 @@ +liteflow.rule-source=chainThreadPool/flow.el.xml +liteflow.chain-thread-pool-isolate=true +liteflow.chain-max-workers=10 +liteflow.chain-queue-limit=1024 diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/application2.properties b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/application2.properties new file mode 100644 index 000000000..7a2dc1480 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/application2.properties @@ -0,0 +1,5 @@ +liteflow.rule-source=chainThreadPool/flow2.el.xml +liteflow.chain-thread-pool-isolate=true +liteflow.chain-max-workers=10 +liteflow.chain-queue-limit=1024 +liteflow.chain-thread-executor-class=com.yomahub.liteflow.test.chainThreadPool.CustomThreadExecutor1 diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/flow.el.xml new file mode 100644 index 000000000..f15a3b45f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/flow.el.xml @@ -0,0 +1,9 @@ + + + + FOR(5).parallel(true).DO(THEN(f,WHEN( + THEN(a,b) + )) + ); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/flow2.el.xml b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/flow2.el.xml new file mode 100644 index 000000000..c8a40aaaf --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/flow2.el.xml @@ -0,0 +1,27 @@ + + + + FOR(5).parallel(true).DO(THEN(f,WHEN( + THEN(a,b) + )) + ); + + + + WHEN(a, b).threadPool("com.yomahub.liteflow.test.chainThreadPool.CustomThreadExecutor2"); + + + + FOR(5).parallel(true).DO(THEN(a,f + ) + ); + + + + WHILE(z).parallel(true).DO(THEN(w,d)); + + + + ITERATOR(it).parallel(true).DO(THEN(a,i)); + + \ No newline at end of file From dee0e9ee1048324887c87d695dc9e92479c5a412 Mon Sep 17 00:00:00 2001 From: jason <2353220944@qq.com> Date: Tue, 22 Oct 2024 15:42:51 +0800 Subject: [PATCH 3/9] bugfix --- .../liteflow/property/LiteflowConfig.java | 42 ++++++------- .../config/LiteflowAutoConfiguration.java | 6 +- .../solon/config/LiteflowProperty.java | 63 +++++++++++++------ .../META-INF/liteflow-default.properties | 5 +- ...itional-spring-configuration-metadata.json | 35 ++++++++--- .../META-INF/liteflow-default.properties | 7 ++- 6 files changed, 105 insertions(+), 53 deletions(-) diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java b/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java index 5ddb3d2e0..89350c00c 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java @@ -44,9 +44,6 @@ public class LiteflowConfig { // 并行线程执行器class路径 private String threadExecutorClass; - // chain线程执行器class路径 - private String chainThreadExecutorClass; - // 异步线程最大等待秒数 @Deprecated private Integer whenMaxWaitSeconds; @@ -76,12 +73,6 @@ public class LiteflowConfig { // 异步线程池最大队列数量 private Integer whenQueueLimit; - // chain线程池最大线程数 - private Integer chainMaxWorkers; - - // chain线程池最大队列数量 - private Integer chainQueueLimit; - // 解析模式,一共有三种,具体看其定义 private ParseModeEnum parseMode; @@ -132,6 +123,15 @@ public class LiteflowConfig { //脚本特殊设置选项 private Map scriptSetting; + // chain线程池最大线程数 + private Integer chainMaxWorkers; + + // chain线程池最大队列数量 + private Integer chainQueueLimit; + + // chain线程执行器class路径 + private String chainThreadExecutorClass; + // chain线程池是否隔离 // 每一个chain里的when和异步循环合并起来都用单独的线程池。也就是说定义了多少个chain,就有多少个线程池 private Boolean chainThreadPoolIsolate; @@ -256,6 +256,7 @@ public class LiteflowConfig { public void setWhenMaxWorkers(Integer whenMaxWorkers) { this.whenMaxWorkers = whenMaxWorkers; } + public Integer getWhenQueueLimit() { if (ObjectUtil.isNull(whenQueueLimit)) { return 512; @@ -323,18 +324,6 @@ public class LiteflowConfig { this.threadExecutorClass = threadExecutorClass; } - public String getChainThreadExecutorClass() { - if (StrUtil.isBlank(chainThreadExecutorClass)) { - return "com.yomahub.liteflow.thread.LiteFlowDefaultChainExecutorBuilder"; - } else { - return chainThreadExecutorClass; - } - } - - public void setChainThreadExecutorClass(String chainThreadExecutorClass) { - this.chainThreadExecutorClass = chainThreadExecutorClass; - } - public String getNodeExecutorClass() { if (StrUtil.isBlank(nodeExecutorClass)) { return "com.yomahub.liteflow.flow.executor.DefaultNodeExecutor"; @@ -570,4 +559,15 @@ public class LiteflowConfig { this.chainQueueLimit = chainQueueLimit; } + public String getChainThreadExecutorClass() { + if (StrUtil.isBlank(chainThreadExecutorClass)) { + return "com.yomahub.liteflow.thread.LiteFlowDefaultChainExecutorBuilder"; + } else { + return chainThreadExecutorClass; + } + } + + public void setChainThreadExecutorClass(String chainThreadExecutorClass) { + this.chainThreadExecutorClass = chainThreadExecutorClass; + } } diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowAutoConfiguration.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowAutoConfiguration.java index 4879d7d5e..fd4856f40 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowAutoConfiguration.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowAutoConfiguration.java @@ -30,7 +30,6 @@ public class LiteflowAutoConfiguration { liteflowConfig.setRuleSourceExtDataMap(property.getRuleSourceExtDataMap()); liteflowConfig.setSlotSize(property.getSlotSize()); liteflowConfig.setThreadExecutorClass(property.getThreadExecutorClass()); - liteflowConfig.setChainThreadExecutorClass(property.getChainThreadExecutorClass()); liteflowConfig.setWhenMaxWaitSeconds(property.getWhenMaxWaitSeconds()); liteflowConfig.setEnableLog(liteflowMonitorProperty.isEnableLog()); liteflowConfig.setQueueLimit(liteflowMonitorProperty.getQueueLimit()); @@ -52,6 +51,11 @@ public class LiteflowAutoConfiguration { liteflowConfig.setParallelQueueLimit(property.getParallelQueueLimit()); liteflowConfig.setParallelLoopExecutorClass(property.getParallelLoopExecutorClass()); liteflowConfig.setFallbackCmpEnable(property.isFallbackCmpEnable()); + liteflowConfig.setChainThreadExecutorClass(property.getChainThreadExecutorClass()); + liteflowConfig.setChainQueueLimit(property.getParallelQueueLimit()); + liteflowConfig.setChainMaxWorkers(property.getParallelMaxWorkers()); + liteflowConfig.setChainThreadPoolIsolate(property.isChainThreadPoolIsolate()); + return liteflowConfig; } diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowProperty.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowProperty.java index d68158f8c..734eda775 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowProperty.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowProperty.java @@ -40,9 +40,6 @@ public class LiteflowProperty { // 并行线程执行器class路径 private String threadExecutorClass; - // chain线程执行器class路径 - private String chainThreadExecutorClass; - // 异步线程最大等待描述 private int whenMaxWaitSeconds; @@ -86,9 +83,18 @@ public class LiteflowProperty { // 是否启用组件降级 private Boolean fallbackCmpEnable; - // chain线程池是否隔离 - // 每一个chain里的when和异步循环合并起来都用单独的线程池。也就是说定义了多少个chain,就有多少个线程池 - private boolean chainThreadPoolIsolate; + // chain线程池是否隔离 + // 每一个chain里的when和异步循环合并起来都用单独的线程池。也就是说定义了多少个chain,就有多少个线程池 + private Boolean chainThreadPoolIsolate; + + // chain线程池最大线程数 + private int chainMaxWorkers; + + // chain线程池最大队列数量 + private int chainQueueLimit; + + // chain线程执行器class路径 + private String chainThreadExecutorClass; public boolean isEnable() { return enable; @@ -175,14 +181,6 @@ public class LiteflowProperty { this.threadExecutorClass = threadExecutorClass; } - public String getChainThreadExecutorClass() { - return chainThreadExecutorClass; - } - - public void setChainThreadExecutorClass(String chainThreadExecutorClass) { - this.chainThreadExecutorClass = chainThreadExecutorClass; - } - public String getNodeExecutorClass() { return nodeExecutorClass; } @@ -283,11 +281,36 @@ public class LiteflowProperty { return fallbackCmpEnable; } - public void setChainThreadPoolIsolate(boolean chainThreadPoolIsolate) { - this.chainThreadPoolIsolate = chainThreadPoolIsolate; - } + public void setChainThreadPoolIsolate(boolean chainThreadPoolIsolate) { + this.chainThreadPoolIsolate = chainThreadPoolIsolate; + } + + public boolean isChainThreadPoolIsolate() { + return chainThreadPoolIsolate; + } + + public int getChainMaxWorkers() { + return chainMaxWorkers; + } + + public void setChainMaxWorkers(int chainMaxWorkers) { + this.chainMaxWorkers = chainMaxWorkers; + } + + public int getChainQueueLimit() { + return chainQueueLimit; + } + + public void setChainQueueLimit(int chainQueueLimit) { + this.chainQueueLimit = chainQueueLimit; + } + + public String getChainThreadExecutorClass() { + return chainThreadExecutorClass; + } + + public void setChainThreadExecutorClass(String chainThreadExecutorClass) { + this.chainThreadExecutorClass = chainThreadExecutorClass; + } - public boolean isChainThreadPoolIsolate() { - return chainThreadPoolIsolate; - } } diff --git a/liteflow-solon-plugin/src/main/resources/META-INF/liteflow-default.properties b/liteflow-solon-plugin/src/main/resources/META-INF/liteflow-default.properties index 07ac3e2b6..b669a3a64 100644 --- a/liteflow-solon-plugin/src/main/resources/META-INF/liteflow-default.properties +++ b/liteflow-solon-plugin/src/main/resources/META-INF/liteflow-default.properties @@ -5,7 +5,6 @@ liteflow.main-executor-works=64 liteflow.main-executor-class=com.yomahub.liteflow.thread.LiteFlowDefaultMainExecutorBuilder liteflow.request-id-generator-class=com.yomahub.liteflow.flow.id.DefaultRequestIdGenerator liteflow.thread-executor-class=com.yomahub.liteflow.thread.LiteFlowDefaultWhenExecutorBuilder -liteflow.chain-thread-executor-class=com.yomahub.liteflow.thread.LiteFlowDefaultChainExecutorBuilder liteflow.when-max-wait-seconds=15 liteflow.when-max-workers=16 liteflow.when-queue-limit=512 @@ -19,3 +18,7 @@ liteflow.monitor.queue-limit=200 liteflow.monitor.delay=300000 liteflow.monitor.period=300000 liteflow.fallback-cmp-enable=false +liteflow.chain-max-workers=16 +liteflow.chain-queue-limit=512 +liteflow.chain-thread-pool-isolate=false +liteflow.chain-thread-executor-class=com.yomahub.liteflow.thread.LiteFlowDefaultChainExecutorBuilder \ No newline at end of file diff --git a/liteflow-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/liteflow-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json index a5c09d6aa..91514d93c 100644 --- a/liteflow-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/liteflow-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -110,13 +110,6 @@ "sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty", "defaultValue": false }, - { - "name": "liteflow.chain-thread-pool-isolate", - "type": "java.lang.Boolean", - "description": "set whether the chain thread pool is isolated.", - "sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty", - "defaultValue": false - }, { "name": "liteflow.parse-mode", "type": "com.yomahub.liteflow.enums.ParseModeEnum", @@ -227,6 +220,34 @@ "type": "java.util.Map", "description": "script special settings.", "sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty" + }, + { + "name": "liteflow.chain-thread-pool-isolate", + "type": "java.lang.Boolean", + "description": "set whether the chain thread pool is isolated.", + "sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty", + "defaultValue": false + }, + { + "name": "liteflow.chain-max-workers", + "type": "java.lang.Integer", + "description": "Set the chain thread pool worker max-size on \" when \" mode.", + "sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty", + "defaultValue": 16 + }, + { + "name": "liteflow.chain-queue-limit", + "type": "java.lang.Integer", + "description": "Set the chain thread pool queue max-size on \" when \" mode.", + "sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty", + "defaultValue": 512 + }, + { + "name": "liteflow.chain-thread-executor-class", + "type": "java.lang.String", + "description": "Custom chain thread pool implement for when executor.", + "sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty", + "defaultValue": "com.yomahub.liteflow.thread.LiteFlowDefaultChainExecutorBuilder" } ] } \ No newline at end of file diff --git a/liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties b/liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties index f97867ad5..eeaeb1b99 100644 --- a/liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties +++ b/liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties @@ -9,10 +9,7 @@ liteflow.when-max-wait-time=15000 liteflow.when-max-wait-time-unit=MILLISECONDS liteflow.when-max-workers=16 liteflow.when-queue-limit=512 -liteflow.chain-max-workers=16 -liteflow.chain-queue-limit=512 liteflow.when-thread-pool-isolate=false -liteflow.chain-thread-pool-isolate=false liteflow.parse-mode=PARSE_ALL_ON_START liteflow.retry-count=0 liteflow.support-multiple-type=false @@ -29,4 +26,8 @@ liteflow.monitor.queue-limit=200 liteflow.monitor.delay=300000 liteflow.monitor.period=300000 liteflow.enable-monitor-file=false +liteflow.chain-max-workers=16 +liteflow.chain-queue-limit=512 +liteflow.chain-thread-pool-isolate=false +liteflow.chain-thread-executor-class=com.yomahub.liteflow.thread.LiteFlowDefaultChainExecutorBuilder From 91d3e9b368a5a6967b24fd6438114e7b646248b7 Mon Sep 17 00:00:00 2001 From: jason <2353220944@qq.com> Date: Mon, 28 Oct 2024 15:10:49 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E6=96=B0=E5=A2=9Echain=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E6=B1=A0=E9=9A=94=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../builder/el/LiteFlowChainELBuilder.java | 11 ++- .../builder/el/operator/WhenOperator.java | 3 - .../liteflow/common/ChainConstant.java | 2 + .../yomahub/liteflow/flow/element/Chain.java | 17 +++- .../strategy/ParallelStrategyExecutor.java | 18 +++-- .../liteflow/parser/helper/ParserHelper.java | 28 +++---- .../liteflow/property/LiteflowConfig.java | 62 --------------- .../liteflow/thread/ExecutorHelper.java | 39 ++++----- .../LiteFlowDefaultChainExecutorBuilder.java | 25 ------ .../src/main/resources/dtd/liteflow.dtd | 1 + .../config/LiteflowAutoConfiguration.java | 5 -- .../solon/config/LiteflowProperty.java | 46 ----------- .../META-INF/liteflow-default.properties | 4 - .../liteflow/springboot/LiteflowProperty.java | 46 ----------- .../LiteflowPropertyAutoConfiguration.java | 4 - ...itional-spring-configuration-metadata.json | 28 ------- .../META-INF/liteflow-default.properties | 4 - ...r1.java => CustomChainThreadExecutor.java} | 6 +- ... => CustomThreadPoolELSpringbootTest.java} | 43 ++++------ ...or2.java => CustomWhenThreadExecutor.java} | 6 +- ...efaultChainThreadPoolELSpringbootTest.java | 45 ----------- .../GlobalThreadPoolELSpringbootTest.java | 79 +++++++++++++++++++ .../test/chainThreadPool/cmp/FCmp.java | 2 +- .../test/chainThreadPool/cmp/ICmp.java | 2 +- .../test/chainThreadPool/cmp/WCmp.java | 2 +- .../chainThreadPool/application.properties | 3 - .../chainThreadPool/application2.properties | 5 +- .../resources/chainThreadPool/flow.el.xml | 23 +++++- .../resources/chainThreadPool/flow2.el.xml | 21 +++-- 29 files changed, 198 insertions(+), 382 deletions(-) delete mode 100644 liteflow-core/src/main/java/com/yomahub/liteflow/thread/LiteFlowDefaultChainExecutorBuilder.java rename liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/{CustomThreadExecutor1.java => CustomChainThreadExecutor.java} (70%) rename liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/{CustomChainThreadPoolELSpringbootTest.java => CustomThreadPoolELSpringbootTest.java} (60%) rename liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/{CustomThreadExecutor2.java => CustomWhenThreadExecutor.java} (70%) delete mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/DefaultChainThreadPoolELSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/GlobalThreadPoolELSpringbootTest.java diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java index 0e5505217..0995f3cf0 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/LiteFlowChainELBuilder.java @@ -1,7 +1,10 @@ package com.yomahub.liteflow.builder.el; import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.util.*; +import cn.hutool.core.util.ArrayUtil; +import cn.hutool.core.util.CharUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.ql.util.express.DefaultContext; @@ -30,7 +33,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Objects; -import java.util.function.Consumer; /** * Chain基于代码形式的组装器 EL表达式规则专属组装器 @@ -243,6 +245,11 @@ public class LiteFlowChainELBuilder { return this; } + public LiteFlowChainELBuilder setThreadPoolExecutorClass(String threadPoolExecutorClass) { + this.chain.setThreadPoolExecutorClass(threadPoolExecutorClass); + return this; + } + /** * EL表达式校验,此方法已经过时,请使用 {@link LiteFlowChainELBuilder#validateWithEx(String)} * diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/WhenOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/WhenOperator.java index 60b676dc5..00cfa58e0 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/WhenOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/WhenOperator.java @@ -26,9 +26,6 @@ public class WhenOperator extends BaseOperator { OperatorHelper.checkObjMustBeCommonTypeItem(obj); whenCondition.addExecutable(OperatorHelper.convert(obj, Executable.class)); whenCondition.setThreadExecutorClass(liteflowConfig.getThreadExecutorClass()); - if (liteflowConfig.getChainThreadPoolIsolate()) { - whenCondition.setThreadExecutorClass(liteflowConfig.getChainThreadExecutorClass()); - } } return whenCondition; } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/common/ChainConstant.java b/liteflow-core/src/main/java/com/yomahub/liteflow/common/ChainConstant.java index e54c6af2f..071ae60e3 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/common/ChainConstant.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/common/ChainConstant.java @@ -34,6 +34,8 @@ public interface ChainConstant { String NAMESPACE = "namespace"; + String THREAD_POOL_EXECUTOR_CLASS = "thread-pool-executor-class"; + String DEFAULT_NAMESPACE = "default"; String VALUE = "value"; diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/Chain.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/Chain.java index f8d6ae437..a9203432b 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/Chain.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/Chain.java @@ -12,18 +12,17 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.BooleanUtil; import com.yomahub.liteflow.builder.el.LiteFlowChainELBuilder; import com.yomahub.liteflow.common.ChainConstant; +import com.yomahub.liteflow.enums.ExecuteableTypeEnum; import com.yomahub.liteflow.exception.ChainEndException; +import com.yomahub.liteflow.exception.FlowSystemException; import com.yomahub.liteflow.lifecycle.LifeCycleHolder; -import com.yomahub.liteflow.lifecycle.PostProcessChainExecuteLifeCycle; import com.yomahub.liteflow.log.LFLog; import com.yomahub.liteflow.log.LFLoggerManager; import com.yomahub.liteflow.slot.DataBus; import com.yomahub.liteflow.slot.Slot; -import com.yomahub.liteflow.enums.ExecuteableTypeEnum; -import com.yomahub.liteflow.exception.FlowSystemException; + import java.util.ArrayList; import java.util.List; -import java.util.function.Consumer; /** * chain对象,实现可执行器 @@ -46,6 +45,8 @@ public class Chain implements Executable{ private String namespace = ChainConstant.DEFAULT_NAMESPACE; + private String threadPoolExecutorClass; + public Chain(String chainName) { this.chainId = chainName; } @@ -223,4 +224,12 @@ public class Chain implements Executable{ public void setNamespace(String namespace) { this.namespace = namespace; } + + public String getThreadPoolExecutorClass() { + return threadPoolExecutorClass; + } + + public void setThreadPoolExecutorClass(String threadPoolExecutorClass) { + this.threadPoolExecutorClass = threadPoolExecutorClass; + } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/strategy/ParallelStrategyExecutor.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/strategy/ParallelStrategyExecutor.java index 109055a53..42cb958de 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/strategy/ParallelStrategyExecutor.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/strategy/ParallelStrategyExecutor.java @@ -133,16 +133,22 @@ public abstract class ParallelStrategyExecutor { // 默认设置不隔离。也就是说,默认情况是一个线程池类一个实例,如果什么都不配置,那也就是在 when 的情况下,全局一个线程池。 ExecutorService parallelExecutor; + String chainId = DataBus.getSlot(slotIndex).getChainId(); + + Chain chain = FlowBus.getChain(chainId); + if (BooleanUtil.isTrue(liteflowConfig.getWhenThreadPoolIsolate())) { - parallelExecutor = ExecutorHelper.loadInstance().buildWhenExecutorWithHash(whenCondition.getThreadExecutorClass(), String.valueOf(whenCondition.hashCode())); - } else if (BooleanUtil.isTrue(liteflowConfig.getChainThreadPoolIsolate())) { - //chain 线程池隔离 - String chainId = DataBus.getSlot(slotIndex).getChainId(); - Chain chain = FlowBus.getChain(chainId); + //condition层级线程池 parallelExecutor = - ExecutorHelper.loadInstance().buildChainExecutorWithHash(whenCondition.getThreadExecutorClass(), + ExecutorHelper.loadInstance().buildWhenExecutorWithHash(whenCondition.getThreadExecutorClass(), + String.valueOf(whenCondition.hashCode())); + } else if (ObjectUtil.isNotEmpty(chain.getThreadPoolExecutorClass())) { + //chain层级线程池 + parallelExecutor = + ExecutorHelper.loadInstance().buildWhenExecutorWithHash(chain.getThreadPoolExecutorClass(), String.valueOf(chain.hashCode())); } else { + //全局线程池 parallelExecutor = ExecutorHelper.loadInstance().buildWhenExecutor(whenCondition.getThreadExecutorClass()); } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/helper/ParserHelper.java b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/helper/ParserHelper.java index 9c3df1206..50dafedd0 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/helper/ParserHelper.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/helper/ParserHelper.java @@ -1,6 +1,5 @@ package com.yomahub.liteflow.parser.helper; -import cn.hutool.core.util.BooleanUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.fasterxml.jackson.databind.JsonNode; @@ -17,15 +16,8 @@ import com.yomahub.liteflow.util.ElRegexUtil; import org.dom4j.Document; import org.dom4j.Element; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; +import java.util.*; import java.util.function.Consumer; -import java.util.function.Function; import static com.yomahub.liteflow.common.ChainConstant.*; @@ -96,10 +88,6 @@ public class ParserHelper { .build(); } - /** - * xml 形式的主要解析过程 - * @param documentList documentList - */ /** * xml 形式的主要解析过程 * @param documentList documentList @@ -316,7 +304,12 @@ public class ParserHelper { JsonNode routeJsonNode = chainNode.get(ROUTE); - LiteFlowChainELBuilder builder = LiteFlowChainELBuilder.createChain().setChainId(chainId).setNamespace(namespace); + String threadPoolExecutorClass = chainNode.get(THREAD_POOL_EXECUTOR_CLASS) == null ? + null : chainNode.get(THREAD_POOL_EXECUTOR_CLASS).textValue(); + + LiteFlowChainELBuilder builder = + LiteFlowChainELBuilder.createChain().setChainId(chainId).setNamespace(namespace) + .setThreadPoolExecutorClass(threadPoolExecutorClass); // 如果有route这个标签,说明是决策表chain // 决策表链路必须有route和body这两个标签 @@ -347,7 +340,12 @@ public class ParserHelper { Element routeElement = e.element(ROUTE); - LiteFlowChainELBuilder builder = LiteFlowChainELBuilder.createChain().setChainId(chainId).setNamespace(namespace); + String threadPoolExecutorClass = e.attributeValue(THREAD_POOL_EXECUTOR_CLASS) == null ? + null : e.attributeValue(THREAD_POOL_EXECUTOR_CLASS); + + LiteFlowChainELBuilder builder = + LiteFlowChainELBuilder.createChain().setChainId(chainId).setNamespace(namespace) + .setThreadPoolExecutorClass(threadPoolExecutorClass); // 如果有route这个标签,说明是决策表chain // 决策表链路必须有route和body这两个标签 diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java b/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java index 89350c00c..7568b95ab 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java @@ -123,20 +123,6 @@ public class LiteflowConfig { //脚本特殊设置选项 private Map scriptSetting; - // chain线程池最大线程数 - private Integer chainMaxWorkers; - - // chain线程池最大队列数量 - private Integer chainQueueLimit; - - // chain线程执行器class路径 - private String chainThreadExecutorClass; - - // chain线程池是否隔离 - // 每一个chain里的when和异步循环合并起来都用单独的线程池。也就是说定义了多少个chain,就有多少个线程池 - private Boolean chainThreadPoolIsolate; - - public Boolean getEnableMonitorFile() { return enableMonitorFile; } @@ -522,52 +508,4 @@ public class LiteflowConfig { public void setScriptSetting(Map scriptSetting) { this.scriptSetting = scriptSetting; } - - public Boolean getChainThreadPoolIsolate() { - if (ObjectUtil.isNull(chainThreadPoolIsolate)) { - return Boolean.FALSE; - } else { - return chainThreadPoolIsolate; - } - } - - public void setChainThreadPoolIsolate(Boolean chainThreadPoolIsolate) { - this.chainThreadPoolIsolate = chainThreadPoolIsolate; - } - - public Integer getChainMaxWorkers() { - if (ObjectUtil.isNull(chainMaxWorkers)) { - return 16; - } else { - return chainMaxWorkers; - } - } - - public void setChainMaxWorkers(Integer chainMaxWorkers) { - this.chainMaxWorkers = chainMaxWorkers; - } - - public Integer getChainQueueLimit() { - if (ObjectUtil.isNull(chainMaxWorkers)) { - return 512; - } else { - return chainQueueLimit; - } - } - - public void setChainQueueLimit(Integer chainQueueLimit) { - this.chainQueueLimit = chainQueueLimit; - } - - public String getChainThreadExecutorClass() { - if (StrUtil.isBlank(chainThreadExecutorClass)) { - return "com.yomahub.liteflow.thread.LiteFlowDefaultChainExecutorBuilder"; - } else { - return chainThreadExecutorClass; - } - } - - public void setChainThreadExecutorClass(String chainThreadExecutorClass) { - this.chainThreadExecutorClass = chainThreadExecutorClass; - } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java index f0a4a27d8..d8b49f82a 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java @@ -9,7 +9,6 @@ package com.yomahub.liteflow.thread; import cn.hutool.core.map.MapUtil; -import cn.hutool.core.util.BooleanUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.yomahub.liteflow.exception.ThreadExecutorServiceCreateException; @@ -132,15 +131,24 @@ public class ExecutorHelper { //构造并行循环的线程池 public ExecutorService buildLoopParallelExecutor(Integer slotIndex) { + ExecutorService parallelExecutor; LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - //chain线程池 - if (BooleanUtil.isTrue(liteflowConfig.getChainThreadPoolIsolate())) { - //获取chain的hash - String chainId = DataBus.getSlot(slotIndex).getChainId(); - Chain chain = FlowBus.getChain(chainId); - return getExecutorService(liteflowConfig.getChainThreadExecutorClass(), String.valueOf(chain.hashCode())); + //获取chain的hash + String chainId = DataBus.getSlot(slotIndex).getChainId(); + Chain chain = FlowBus.getChain(chainId); + + //condition层级线程池 TODO + + //chain层级线程池 + if (ObjectUtil.isNotEmpty(chain.getThreadPoolExecutorClass())) { + //chain层级线程池 + parallelExecutor = getExecutorService(chain.getThreadPoolExecutorClass(), + String.valueOf(chain.hashCode())); + } else { + //全局线程池 + parallelExecutor = getExecutorService(liteflowConfig.getParallelLoopExecutorClass()); } - return getExecutorService(liteflowConfig.getParallelLoopExecutorClass()); + return parallelExecutor; } private ExecutorService getExecutorService(String clazz){ @@ -183,19 +191,4 @@ public class ExecutorHelper { } } - // 构建chain线程池 - clazz和condition的hash值共同作为缓存key - public ExecutorService buildChainExecutorWithHash(String conditionHash) { - LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - return buildChainExecutorWithHash(liteflowConfig.getChainThreadExecutorClass(), conditionHash); - } - - // 构建chain线程池 - clazz和condition的hash值共同作为缓存key - public ExecutorService buildChainExecutorWithHash(String clazz, String conditionHash) { - if (StrUtil.isBlank(clazz)) { - return buildChainExecutorWithHash(conditionHash); - } - return getExecutorService(clazz, conditionHash); - } - - } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/LiteFlowDefaultChainExecutorBuilder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/LiteFlowDefaultChainExecutorBuilder.java deleted file mode 100644 index 3148a08cf..000000000 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/LiteFlowDefaultChainExecutorBuilder.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.yomahub.liteflow.thread; - -import cn.hutool.core.util.ObjectUtil; -import com.yomahub.liteflow.property.LiteflowConfig; -import com.yomahub.liteflow.property.LiteflowConfigGetter; - -import java.util.concurrent.ExecutorService; - -/** - * LiteFlow默认的chain多线程执行器实现 - */ -public class LiteFlowDefaultChainExecutorBuilder implements ExecutorBuilder { - - @Override - public ExecutorService buildExecutor() { - LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - // 只有在非spring的场景下liteflowConfig才会为null - if (ObjectUtil.isNull(liteflowConfig)) { - liteflowConfig = new LiteflowConfig(); - } - return buildDefaultExecutor(liteflowConfig.getChainMaxWorkers(), liteflowConfig.getChainMaxWorkers(), - liteflowConfig.getChainQueueLimit(), "chain-thread-"); - } - -} diff --git a/liteflow-core/src/main/resources/dtd/liteflow.dtd b/liteflow-core/src/main/resources/dtd/liteflow.dtd index 324f17cbe..d7927fd29 100644 --- a/liteflow-core/src/main/resources/dtd/liteflow.dtd +++ b/liteflow-core/src/main/resources/dtd/liteflow.dtd @@ -22,4 +22,5 @@ extends CDATA #IMPLIED enable (true|false) #IMPLIED namespace CDATA #IMPLIED + thread-pool-executor-class CDATA #IMPLIED > \ No newline at end of file diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowAutoConfiguration.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowAutoConfiguration.java index fd4856f40..5d560cfde 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowAutoConfiguration.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowAutoConfiguration.java @@ -51,11 +51,6 @@ public class LiteflowAutoConfiguration { liteflowConfig.setParallelQueueLimit(property.getParallelQueueLimit()); liteflowConfig.setParallelLoopExecutorClass(property.getParallelLoopExecutorClass()); liteflowConfig.setFallbackCmpEnable(property.isFallbackCmpEnable()); - liteflowConfig.setChainThreadExecutorClass(property.getChainThreadExecutorClass()); - liteflowConfig.setChainQueueLimit(property.getParallelQueueLimit()); - liteflowConfig.setChainMaxWorkers(property.getParallelMaxWorkers()); - liteflowConfig.setChainThreadPoolIsolate(property.isChainThreadPoolIsolate()); - return liteflowConfig; } diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowProperty.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowProperty.java index 734eda775..d58dd333f 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowProperty.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowProperty.java @@ -83,19 +83,6 @@ public class LiteflowProperty { // 是否启用组件降级 private Boolean fallbackCmpEnable; - // chain线程池是否隔离 - // 每一个chain里的when和异步循环合并起来都用单独的线程池。也就是说定义了多少个chain,就有多少个线程池 - private Boolean chainThreadPoolIsolate; - - // chain线程池最大线程数 - private int chainMaxWorkers; - - // chain线程池最大队列数量 - private int chainQueueLimit; - - // chain线程执行器class路径 - private String chainThreadExecutorClass; - public boolean isEnable() { return enable; } @@ -280,37 +267,4 @@ public class LiteflowProperty { public Boolean getFallbackCmpEnable() { return fallbackCmpEnable; } - - public void setChainThreadPoolIsolate(boolean chainThreadPoolIsolate) { - this.chainThreadPoolIsolate = chainThreadPoolIsolate; - } - - public boolean isChainThreadPoolIsolate() { - return chainThreadPoolIsolate; - } - - public int getChainMaxWorkers() { - return chainMaxWorkers; - } - - public void setChainMaxWorkers(int chainMaxWorkers) { - this.chainMaxWorkers = chainMaxWorkers; - } - - public int getChainQueueLimit() { - return chainQueueLimit; - } - - public void setChainQueueLimit(int chainQueueLimit) { - this.chainQueueLimit = chainQueueLimit; - } - - public String getChainThreadExecutorClass() { - return chainThreadExecutorClass; - } - - public void setChainThreadExecutorClass(String chainThreadExecutorClass) { - this.chainThreadExecutorClass = chainThreadExecutorClass; - } - } diff --git a/liteflow-solon-plugin/src/main/resources/META-INF/liteflow-default.properties b/liteflow-solon-plugin/src/main/resources/META-INF/liteflow-default.properties index b669a3a64..c1fda2e94 100644 --- a/liteflow-solon-plugin/src/main/resources/META-INF/liteflow-default.properties +++ b/liteflow-solon-plugin/src/main/resources/META-INF/liteflow-default.properties @@ -18,7 +18,3 @@ liteflow.monitor.queue-limit=200 liteflow.monitor.delay=300000 liteflow.monitor.period=300000 liteflow.fallback-cmp-enable=false -liteflow.chain-max-workers=16 -liteflow.chain-queue-limit=512 -liteflow.chain-thread-pool-isolate=false -liteflow.chain-thread-executor-class=com.yomahub.liteflow.thread.LiteFlowDefaultChainExecutorBuilder \ No newline at end of file diff --git a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowProperty.java b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowProperty.java index 34e3c434d..930a62d4c 100644 --- a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowProperty.java +++ b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowProperty.java @@ -101,19 +101,6 @@ public class LiteflowProperty { //脚本特殊设置选项 private Map scriptSetting; - // chain线程池是否隔离 - // 每一个chain里的when和异步循环合并起来都用单独的线程池。也就是说定义了多少个chain,就有多少个线程池 - private Boolean chainThreadPoolIsolate; - - // chain线程池最大线程数 - private int chainMaxWorkers; - - // chain线程池最大队列数量 - private int chainQueueLimit; - - // chain线程执行器class路径 - private String chainThreadExecutorClass; - public boolean isEnableMonitorFile() { return enableMonitorFile; } @@ -349,37 +336,4 @@ public class LiteflowProperty { public void setScriptSetting(Map scriptSetting) { this.scriptSetting = scriptSetting; } - - public void setChainThreadPoolIsolate(boolean chainThreadPoolIsolate) { - this.chainThreadPoolIsolate = chainThreadPoolIsolate; - } - - public boolean isChainThreadPoolIsolate() { - return chainThreadPoolIsolate; - } - - public int getChainMaxWorkers() { - return chainMaxWorkers; - } - - public void setChainMaxWorkers(int chainMaxWorkers) { - this.chainMaxWorkers = chainMaxWorkers; - } - - public int getChainQueueLimit() { - return chainQueueLimit; - } - - public void setChainQueueLimit(int chainQueueLimit) { - this.chainQueueLimit = chainQueueLimit; - } - - public String getChainThreadExecutorClass() { - return chainThreadExecutorClass; - } - - public void setChainThreadExecutorClass(String chainThreadExecutorClass) { - this.chainThreadExecutorClass = chainThreadExecutorClass; - } - } diff --git a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowPropertyAutoConfiguration.java b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowPropertyAutoConfiguration.java index 4976f0eca..37356fcb3 100644 --- a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowPropertyAutoConfiguration.java +++ b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowPropertyAutoConfiguration.java @@ -54,10 +54,6 @@ public class LiteflowPropertyAutoConfiguration { liteflowConfig.setDelay(liteflowMonitorProperty.getDelay()); liteflowConfig.setPeriod(liteflowMonitorProperty.getPeriod()); liteflowConfig.setScriptSetting(property.getScriptSetting()); - liteflowConfig.setChainThreadPoolIsolate(property.isChainThreadPoolIsolate()); - liteflowConfig.setChainThreadExecutorClass(property.getChainThreadExecutorClass()); - liteflowConfig.setChainMaxWorkers(property.getChainMaxWorkers()); - liteflowConfig.setChainQueueLimit(property.getChainQueueLimit()); return liteflowConfig; } diff --git a/liteflow-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/liteflow-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 91514d93c..83b0b668e 100644 --- a/liteflow-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/liteflow-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -220,34 +220,6 @@ "type": "java.util.Map", "description": "script special settings.", "sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty" - }, - { - "name": "liteflow.chain-thread-pool-isolate", - "type": "java.lang.Boolean", - "description": "set whether the chain thread pool is isolated.", - "sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty", - "defaultValue": false - }, - { - "name": "liteflow.chain-max-workers", - "type": "java.lang.Integer", - "description": "Set the chain thread pool worker max-size on \" when \" mode.", - "sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty", - "defaultValue": 16 - }, - { - "name": "liteflow.chain-queue-limit", - "type": "java.lang.Integer", - "description": "Set the chain thread pool queue max-size on \" when \" mode.", - "sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty", - "defaultValue": 512 - }, - { - "name": "liteflow.chain-thread-executor-class", - "type": "java.lang.String", - "description": "Custom chain thread pool implement for when executor.", - "sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty", - "defaultValue": "com.yomahub.liteflow.thread.LiteFlowDefaultChainExecutorBuilder" } ] } \ No newline at end of file diff --git a/liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties b/liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties index eeaeb1b99..37aeb4645 100644 --- a/liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties +++ b/liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties @@ -26,8 +26,4 @@ liteflow.monitor.queue-limit=200 liteflow.monitor.delay=300000 liteflow.monitor.period=300000 liteflow.enable-monitor-file=false -liteflow.chain-max-workers=16 -liteflow.chain-queue-limit=512 -liteflow.chain-thread-pool-isolate=false -liteflow.chain-thread-executor-class=com.yomahub.liteflow.thread.LiteFlowDefaultChainExecutorBuilder diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomThreadExecutor1.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomChainThreadExecutor.java similarity index 70% rename from liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomThreadExecutor1.java rename to liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomChainThreadExecutor.java index f19c37ec4..c46a2e8e5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomThreadExecutor1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomChainThreadExecutor.java @@ -7,7 +7,7 @@ import com.yomahub.liteflow.thread.ExecutorBuilder; import java.util.concurrent.ExecutorService; -public class CustomThreadExecutor1 implements ExecutorBuilder { +public class CustomChainThreadExecutor implements ExecutorBuilder { @Override public ExecutorService buildExecutor() { @@ -16,8 +16,8 @@ public class CustomThreadExecutor1 implements ExecutorBuilder { if (ObjectUtil.isNull(liteflowConfig)) { liteflowConfig = new LiteflowConfig(); } - return buildDefaultExecutor(liteflowConfig.getChainMaxWorkers(), liteflowConfig.getChainMaxWorkers(), - liteflowConfig.getChainQueueLimit(), "customer-chain-thead-1"); + return buildDefaultExecutor(16, 16, + 512, "customer-chain-thead"); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomChainThreadPoolELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomThreadPoolELSpringbootTest.java similarity index 60% rename from liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomChainThreadPoolELSpringbootTest.java rename to liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomThreadPoolELSpringbootTest.java index b98d4bbda..f50aa6389 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomChainThreadPoolELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomThreadPoolELSpringbootTest.java @@ -21,10 +21,10 @@ import java.util.List; * springboot环境下chain线程池隔离测试 */ @TestPropertySource(value = "classpath:/chainThreadPool/application2.properties") -@SpringBootTest(classes = CustomChainThreadPoolELSpringbootTest.class) +@SpringBootTest(classes = CustomThreadPoolELSpringbootTest.class) @EnableAutoConfiguration @ComponentScan({"com.yomahub.liteflow.test.chainThreadPool.cmp"}) -public class CustomChainThreadPoolELSpringbootTest extends BaseTest { +public class CustomThreadPoolELSpringbootTest extends BaseTest { private final Logger log = LoggerFactory.getLogger(this.getClass()); @@ -32,61 +32,48 @@ public class CustomChainThreadPoolELSpringbootTest extends BaseTest { private FlowExecutor flowExecutor; /** - * 测试chain自定义线程池隔离 + * 测试WEHN上condition线程池和chain线程池隔离-优先以WHEN上为准 */ @Test - public void testCustomChainThreadPool1() { - LiteflowResponse response = flowExecutor.execute2Resp("chain", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assertions.assertTrue(response.isSuccess()); - Assertions.assertTrue(context.getData("threadNameFor").toString().startsWith("customer-chain-thead-1")); - Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead-1")); + public void testCustomChainThreadPool() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-when-thead")); } /** - * 测试when上自定义线程池和chain线程池隔离-优先以when上为准 + * 测试FOR上condition线程池和chain线程池隔离-优先以FOR上为准 */ @Test public void testCustomChainThreadPool2() { LiteflowResponse response1 = flowExecutor.execute2Resp("chain2", "arg"); DefaultContext context = response1.getFirstContextBean(); Assertions.assertTrue(response1.isSuccess()); - Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead-2")); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); } /** - * 测试并行FOR循环全局线程池和chain线程池隔离-优先以chain线程池上为准 + * 测试WHILE上condition线程池和chain线程池隔离-优先以WHILE上为准 */ @Test public void testCustomChainThreadPool3() { LiteflowResponse response1 = flowExecutor.execute2Resp("chain3", "arg"); DefaultContext context = response1.getFirstContextBean(); Assertions.assertTrue(response1.isSuccess()); - Assertions.assertTrue(context.getData("threadNameFor").toString().startsWith("customer-chain-thead-1")); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); } /** - * 测试并行条件循环全局线程池和chain线程池隔离-优先以chain线程池上为准 + * 测试ITERATOR上condition线程池和chain线程池隔离-优先以ITERATOR上为准 */ @Test public void testCustomChainThreadPool4() { - LiteflowResponse response1 = flowExecutor.execute2Resp("chain4", "arg"); - DefaultContext context = response1.getFirstContextBean(); - Assertions.assertTrue(response1.isSuccess()); - Assertions.assertTrue(context.getData("threadNameWhile").toString().startsWith("customer-chain-thead-1")); - } - - /** - * 测试并行迭代循环全局线程池和chain线程池隔离-优先以chain线程池上为准 - */ - @Test - public void testCustomChainThreadPool5() { List list = ListUtil.toList("1", "2", "3", "4", "5"); - LiteflowResponse response1 = flowExecutor.execute2Resp("chain5", list); + LiteflowResponse response1 = flowExecutor.execute2Resp("chain4", list); DefaultContext context = response1.getFirstContextBean(); Assertions.assertTrue(response1.isSuccess()); - Assertions.assertTrue(context.getData("threadNameIterator").toString().startsWith("customer-chain-thead-1")); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); } - } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomThreadExecutor2.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomWhenThreadExecutor.java similarity index 70% rename from liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomThreadExecutor2.java rename to liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomWhenThreadExecutor.java index 4527fbd16..d0571543f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomThreadExecutor2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomWhenThreadExecutor.java @@ -7,7 +7,7 @@ import com.yomahub.liteflow.thread.ExecutorBuilder; import java.util.concurrent.ExecutorService; -public class CustomThreadExecutor2 implements ExecutorBuilder { +public class CustomWhenThreadExecutor implements ExecutorBuilder { @Override public ExecutorService buildExecutor() { @@ -16,8 +16,8 @@ public class CustomThreadExecutor2 implements ExecutorBuilder { if (ObjectUtil.isNull(liteflowConfig)) { liteflowConfig = new LiteflowConfig(); } - return buildDefaultExecutor(liteflowConfig.getChainMaxWorkers(), liteflowConfig.getChainMaxWorkers(), - liteflowConfig.getChainQueueLimit(), "customer-chain-thead-2"); + return buildDefaultExecutor(16, 16, + 512, "customer-when-thead"); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/DefaultChainThreadPoolELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/DefaultChainThreadPoolELSpringbootTest.java deleted file mode 100644 index 5c31217aa..000000000 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/DefaultChainThreadPoolELSpringbootTest.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.yomahub.liteflow.test.chainThreadPool; - -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 org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -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 javax.annotation.Resource; - -/** - * springboot环境下chain线程池隔离测试 - */ -@TestPropertySource(value = "classpath:/chainThreadPool/application.properties") -@SpringBootTest(classes = DefaultChainThreadPoolELSpringbootTest.class) -@EnableAutoConfiguration -@ComponentScan({"com.yomahub.liteflow.test.chainThreadPool.cmp"}) -public class DefaultChainThreadPoolELSpringbootTest extends BaseTest { - - private final Logger log = LoggerFactory.getLogger(this.getClass()); - - @Resource - private FlowExecutor flowExecutor; - - /** - * 测试chain默认线程池隔离 - */ - @Test - public void testDefaultChainThreadPool() { - LiteflowResponse response = flowExecutor.execute2Resp("chain", "arg"); - DefaultContext context = response.getFirstContextBean(); - Assertions.assertTrue(response.isSuccess()); - Assertions.assertTrue(context.getData("threadNameFor").toString().startsWith("chain-thread-")); - Assertions.assertTrue(context.getData("threadName").toString().startsWith("chain-thread-")); - - } - -} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/GlobalThreadPoolELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/GlobalThreadPoolELSpringbootTest.java new file mode 100644 index 000000000..f307c0496 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/GlobalThreadPoolELSpringbootTest.java @@ -0,0 +1,79 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.collection.ListUtil; +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 org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +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 javax.annotation.Resource; +import java.util.List; + +/** + * springboot环境下chain线程池隔离测试 + */ +@TestPropertySource(value = "classpath:/chainThreadPool/application.properties") +@SpringBootTest(classes = GlobalThreadPoolELSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.chainThreadPool.cmp"}) +public class GlobalThreadPoolELSpringbootTest extends BaseTest { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Resource + private FlowExecutor flowExecutor; + + /** + * 测试WHEN上全局线程池和chain线程池隔离-优先以chain上为准 + */ + @Test + public void testGlobalChainThreadPool() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + } + + /** + * 测试FOR上全局线程池和chain线程池隔离-优先以chain上为准 + */ + @Test + public void testGlobalChainThreadPool2() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + } + + /** + * 测试WHILE上全局线程池和chain线程池隔离-优先以chain上为准 + */ + @Test + public void testGlobalChainThreadPool3() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + } + + /** + * 测试ITERATOR上全局线程池和chain线程池隔离-优先以chain上为准 + */ + @Test + public void testGlobalChainThreadPool4() { + List list = ListUtil.toList("1", "2", "3", "4", "5"); + LiteflowResponse response1 = flowExecutor.execute2Resp("chain4", list); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/FCmp.java index 3e48aac9f..0905db127 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/FCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/FCmp.java @@ -18,7 +18,7 @@ public class FCmp extends NodeComponent { @Override public void process() { DefaultContext context = this.getFirstContextBean(); - context.setData("threadNameFor", Thread.currentThread().getName()); + context.setData("threadName", Thread.currentThread().getName()); System.out.println("FCmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ICmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ICmp.java index 25424c581..3caaabda6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ICmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ICmp.java @@ -18,7 +18,7 @@ public class ICmp extends NodeComponent { @Override public void process() { DefaultContext context = this.getFirstContextBean(); - context.setData("threadNameIterator", Thread.currentThread().getName()); + context.setData("threadName", Thread.currentThread().getName()); System.out.println("ICmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/WCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/WCmp.java index 8c394ddb5..bbe890509 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/WCmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/WCmp.java @@ -18,7 +18,7 @@ public class WCmp extends NodeComponent { @Override public void process() { DefaultContext context = this.getFirstContextBean(); - context.setData("threadNameWhile", Thread.currentThread().getName()); + context.setData("threadName", Thread.currentThread().getName()); System.out.println("WCmp executed!"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/application.properties b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/application.properties index 587e96142..aad6bd9de 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/application.properties +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/application.properties @@ -1,4 +1 @@ liteflow.rule-source=chainThreadPool/flow.el.xml -liteflow.chain-thread-pool-isolate=true -liteflow.chain-max-workers=10 -liteflow.chain-queue-limit=1024 diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/application2.properties b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/application2.properties index 7a2dc1480..ecac47dd6 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/application2.properties +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/application2.properties @@ -1,5 +1,2 @@ liteflow.rule-source=chainThreadPool/flow2.el.xml -liteflow.chain-thread-pool-isolate=true -liteflow.chain-max-workers=10 -liteflow.chain-queue-limit=1024 -liteflow.chain-thread-executor-class=com.yomahub.liteflow.test.chainThreadPool.CustomThreadExecutor1 +liteflow.when-thread-pool-isolate=true diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/flow.el.xml index f15a3b45f..da5f247c5 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/flow.el.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/flow.el.xml @@ -1,9 +1,24 @@ - - FOR(5).parallel(true).DO(THEN(f,WHEN( - THEN(a,b) - )) + + WHEN(a,b); + + + + FOR(5).parallel(true).DO(THEN(a,f + ) ); + + + WHILE(z).parallel(true).DO(THEN(w,d)); + + + + ITERATOR(it).parallel(true).DO(THEN(a,i)); + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/flow2.el.xml b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/flow2.el.xml index c8a40aaaf..4b280ba91 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/flow2.el.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/flow2.el.xml @@ -1,27 +1,24 @@ - - FOR(5).parallel(true).DO(THEN(f,WHEN( - THEN(a,b) - )) - ); + + WHEN(a,b).threadPool("com.yomahub.liteflow.test.chainThreadPool.CustomWhenThreadExecutor"); - - WHEN(a, b).threadPool("com.yomahub.liteflow.test.chainThreadPool.CustomThreadExecutor2"); - - - + FOR(5).parallel(true).DO(THEN(a,f ) ); - + WHILE(z).parallel(true).DO(THEN(w,d)); - + ITERATOR(it).parallel(true).DO(THEN(a,i)); \ No newline at end of file From 51d1bfd43d6ce18c215664c108244d5fecc81f7c Mon Sep 17 00:00:00 2001 From: jason <2353220944@qq.com> Date: Mon, 28 Oct 2024 16:34:00 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=E5=85=BC=E5=AE=B9=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E4=BD=93=E7=B3=BB=E7=BA=BF=E7=A8=8B=E6=B1=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../builder/el/operator/WhenOperator.java | 5 +- .../liteflow/property/LiteflowConfig.java | 63 +++++++++++++++ .../liteflow/thread/ExecutorHelper.java | 11 ++- .../LiteFlowDefaultGlobalExecutorBuilder.java | 27 +++++++ .../config/LiteflowAutoConfiguration.java | 3 + .../solon/config/LiteflowProperty.java | 47 +++++++++++ .../liteflow/springboot/LiteflowProperty.java | 66 +++++++++++++++- .../LiteflowPropertyAutoConfiguration.java | 3 + ...itional-spring-configuration-metadata.json | 21 +++++ .../META-INF/liteflow-default.properties | 3 + .../ChainThreadPoolELSpringbootTest.java | 79 +++++++++++++++++++ ... ConditionThreadPoolELSpringbootTest.java} | 12 +-- .../CustomGlobalThreadExecutor.java | 23 ++++++ .../GlobalThreadPoolELSpringbootTest.java | 30 +++---- .../chainThreadPool/application3.properties | 4 + .../resources/chainThreadPool/flow3.el.xml | 20 +++++ 16 files changed, 391 insertions(+), 26 deletions(-) create mode 100644 liteflow-core/src/main/java/com/yomahub/liteflow/thread/LiteFlowDefaultGlobalExecutorBuilder.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ChainThreadPoolELSpringbootTest.java rename liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/{CustomThreadPoolELSpringbootTest.java => ConditionThreadPoolELSpringbootTest.java} (89%) create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomGlobalThreadExecutor.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/application3.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/flow3.el.xml diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/WhenOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/WhenOperator.java index 00cfa58e0..2be0c5365 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/WhenOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/WhenOperator.java @@ -7,6 +7,8 @@ import com.yomahub.liteflow.flow.element.condition.WhenCondition; import com.yomahub.liteflow.property.LiteflowConfig; import com.yomahub.liteflow.property.LiteflowConfigGetter; +import java.util.Optional; + /** * EL规则中的WHEN的操作符 * @@ -25,7 +27,8 @@ public class WhenOperator extends BaseOperator { for (Object obj : objects) { OperatorHelper.checkObjMustBeCommonTypeItem(obj); whenCondition.addExecutable(OperatorHelper.convert(obj, Executable.class)); - whenCondition.setThreadExecutorClass(liteflowConfig.getThreadExecutorClass()); + whenCondition.setThreadExecutorClass(Optional.ofNullable(liteflowConfig.getThreadExecutorClass()) + .orElse(liteflowConfig.getGlobalThreadPoolExecutorClass())); } return whenCondition; } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java b/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java index 7568b95ab..b6d4982d8 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java @@ -42,6 +42,7 @@ public class LiteflowConfig { private Integer slotSize; // 并行线程执行器class路径 + @Deprecated private String threadExecutorClass; // 异步线程最大等待秒数 @@ -68,9 +69,11 @@ public class LiteflowConfig { private Long period; // 异步线程池最大线程数 + @Deprecated private Integer whenMaxWorkers; // 异步线程池最大队列数量 + @Deprecated private Integer whenQueueLimit; // 解析模式,一共有三种,具体看其定义 @@ -106,12 +109,15 @@ public class LiteflowConfig { private Boolean enableMonitorFile = Boolean.FALSE; //并行循环线程池所用class路径 + @Deprecated private String parallelLoopExecutorClass; //使用默认并行循环线程池时,最大线程数 + @Deprecated private Integer parallelMaxWorkers; //使用默认并行循环线程池时,最大队列数 + @Deprecated private Integer parallelQueueLimit; // 是否启用组件降级 @@ -131,6 +137,15 @@ public class LiteflowConfig { this.enableMonitorFile = enableMonitorFile; } + //全局线程池所用class路径(when+异步循环) + private String globalThreadPoolExecutorClass; + + //全局线程池最大线程数(when+异步循环) + private Integer globalThreadPoolSize; + + //全局线程池最大队列数(when+异步循环) + private Integer globalThreadPoolQueueSize; + public Boolean getEnable() { if (ObjectUtil.isNull(enable)) { return Boolean.TRUE; @@ -230,6 +245,7 @@ public class LiteflowConfig { this.enableLog = enableLog; } + @Deprecated public Integer getWhenMaxWorkers() { if (ObjectUtil.isNull(whenMaxWorkers)) { return 16; @@ -239,10 +255,13 @@ public class LiteflowConfig { } } + @Deprecated + public void setWhenMaxWorkers(Integer whenMaxWorkers) { this.whenMaxWorkers = whenMaxWorkers; } + @Deprecated public Integer getWhenQueueLimit() { if (ObjectUtil.isNull(whenQueueLimit)) { return 512; @@ -252,6 +271,7 @@ public class LiteflowConfig { } } + @Deprecated public void setWhenQueueLimit(Integer whenQueueLimit) { this.whenQueueLimit = whenQueueLimit; } @@ -297,6 +317,7 @@ public class LiteflowConfig { this.printBanner = printBanner; } + @Deprecated public String getThreadExecutorClass() { if (StrUtil.isBlank(threadExecutorClass)) { return "com.yomahub.liteflow.thread.LiteFlowDefaultWhenExecutorBuilder"; @@ -306,6 +327,7 @@ public class LiteflowConfig { } } + @Deprecated public void setThreadExecutorClass(String threadExecutorClass) { this.threadExecutorClass = threadExecutorClass; } @@ -423,6 +445,7 @@ public class LiteflowConfig { this.parallelMaxWorkers = parallelMaxWorkers; } + @Deprecated public Integer getParallelQueueLimit() { if(ObjectUtil.isNull(parallelQueueLimit)){ return 512; @@ -431,10 +454,12 @@ public class LiteflowConfig { } } + @Deprecated public void setParallelQueueLimit(Integer parallelQueueLimit) { this.parallelQueueLimit = parallelQueueLimit; } + @Deprecated public String getParallelLoopExecutorClass() { if (StrUtil.isBlank(parallelLoopExecutorClass)) { return "com.yomahub.liteflow.thread.LiteFlowDefaultParallelLoopExecutorBuilder"; @@ -443,6 +468,8 @@ public class LiteflowConfig { return parallelLoopExecutorClass; } } + + @Deprecated public void setParallelLoopExecutorClass(String parallelLoopExecutorClass) { this.parallelLoopExecutorClass = parallelLoopExecutorClass; } @@ -508,4 +535,40 @@ public class LiteflowConfig { public void setScriptSetting(Map scriptSetting) { this.scriptSetting = scriptSetting; } + + public Integer getGlobalThreadPoolSize() { + if (ObjectUtil.isNull(globalThreadPoolSize)) { + return 16; + } else { + return globalThreadPoolSize; + } + } + + public void setGlobalThreadPoolSize(Integer globalThreadPoolSize) { + this.globalThreadPoolSize = globalThreadPoolSize; + } + + public Integer getGlobalThreadPoolQueueSize() { + if (ObjectUtil.isNull(globalThreadPoolQueueSize)) { + return 512; + } else { + return globalThreadPoolQueueSize; + } + } + + public void setGlobalThreadPoolQueueSize(Integer globalThreadPoolQueueSize) { + this.globalThreadPoolQueueSize = globalThreadPoolQueueSize; + } + + public String getGlobalThreadPoolExecutorClass() { + if (StrUtil.isBlank(globalThreadPoolExecutorClass)) { + return "com.yomahub.liteflow.thread.LiteFlowDefaultGlobalExecutorBuilder"; + } else { + return globalThreadPoolExecutorClass; + } + } + + public void setGlobalThreadPoolExecutorClass(String globalThreadPoolExecutorClass) { + this.globalThreadPoolExecutorClass = globalThreadPoolExecutorClass; + } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java index d8b49f82a..9f8d75104 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java @@ -22,6 +22,7 @@ import com.yomahub.liteflow.slot.DataBus; import com.yomahub.liteflow.spi.holder.ContextAwareHolder; import java.util.Map; +import java.util.Optional; import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; @@ -91,7 +92,8 @@ public class ExecutorHelper { // 构建默认when线程池 public ExecutorService buildWhenExecutor() { LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - return buildWhenExecutor(liteflowConfig.getThreadExecutorClass()); + return buildWhenExecutor(Optional.ofNullable(liteflowConfig.getGlobalThreadPoolExecutorClass()) + .orElse(liteflowConfig.getThreadExecutorClass())); } // 构建when线程池 - 支持多个when公用一个线程池 @@ -105,7 +107,9 @@ public class ExecutorHelper { // 构建when线程池 - clazz和condition的hash值共同作为缓存key public ExecutorService buildWhenExecutorWithHash(String conditionHash) { LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - return buildWhenExecutorWithHash(liteflowConfig.getThreadExecutorClass(), conditionHash); + return buildWhenExecutorWithHash(Optional.ofNullable(liteflowConfig.getThreadExecutorClass()) + .orElse(liteflowConfig.getGlobalThreadPoolExecutorClass()), + conditionHash); } // 构建when线程池 - clazz和condition的hash值共同作为缓存key @@ -146,7 +150,8 @@ public class ExecutorHelper { String.valueOf(chain.hashCode())); } else { //全局线程池 - parallelExecutor = getExecutorService(liteflowConfig.getParallelLoopExecutorClass()); + parallelExecutor = getExecutorService(Optional.ofNullable(liteflowConfig.getParallelLoopExecutorClass()) + .orElse(liteflowConfig.getGlobalThreadPoolExecutorClass())); } return parallelExecutor; } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/LiteFlowDefaultGlobalExecutorBuilder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/LiteFlowDefaultGlobalExecutorBuilder.java new file mode 100644 index 000000000..e1c44bc18 --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/LiteFlowDefaultGlobalExecutorBuilder.java @@ -0,0 +1,27 @@ +package com.yomahub.liteflow.thread; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; + +import java.util.concurrent.ExecutorService; + +/** + * LiteFlow默认的when线程池+异步多线程执行器实现 + * + * @author jason + */ +public class LiteFlowDefaultGlobalExecutorBuilder implements ExecutorBuilder { + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(liteflowConfig.getGlobalThreadPoolSize(), liteflowConfig.getGlobalThreadPoolSize(), + liteflowConfig.getGlobalThreadPoolQueueSize(), "global-thread-"); + } + +} diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowAutoConfiguration.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowAutoConfiguration.java index 5d560cfde..f4763fd46 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowAutoConfiguration.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowAutoConfiguration.java @@ -51,6 +51,9 @@ public class LiteflowAutoConfiguration { liteflowConfig.setParallelQueueLimit(property.getParallelQueueLimit()); liteflowConfig.setParallelLoopExecutorClass(property.getParallelLoopExecutorClass()); liteflowConfig.setFallbackCmpEnable(property.isFallbackCmpEnable()); + liteflowConfig.setGlobalThreadPoolExecutorClass(property.getGlobalThreadPoolExecutorClass()); + liteflowConfig.setGlobalThreadPoolSize(property.getGlobalThreadPoolSize()); + liteflowConfig.setGlobalThreadPoolQueueSize(property.getGlobalThreadPoolQueueSize()); return liteflowConfig; } diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowProperty.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowProperty.java index d58dd333f..663d3c241 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowProperty.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowProperty.java @@ -1,5 +1,7 @@ package com.yomahub.liteflow.solon.config; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; import com.yomahub.liteflow.enums.ParseModeEnum; import org.noear.solon.annotation.Configuration; import org.noear.solon.annotation.Inject; @@ -83,6 +85,15 @@ public class LiteflowProperty { // 是否启用组件降级 private Boolean fallbackCmpEnable; + //全局线程池所用class路径(when+异步循环) + private String globalThreadPoolExecutorClass; + + //全局线程池最大线程数(when+异步循环) + private Integer globalThreadPoolSize; + + //全局线程池最大队列数(when+异步循环) + private Integer globalThreadPoolQueueSize; + public boolean isEnable() { return enable; } @@ -267,4 +278,40 @@ public class LiteflowProperty { public Boolean getFallbackCmpEnable() { return fallbackCmpEnable; } + + public Integer getGlobalThreadPoolSize() { + if (ObjectUtil.isNull(globalThreadPoolSize)) { + return 16; + } else { + return globalThreadPoolSize; + } + } + + public void setGlobalThreadPoolSize(Integer globalThreadPoolSize) { + this.globalThreadPoolSize = globalThreadPoolSize; + } + + public Integer getGlobalThreadPoolQueueSize() { + if (ObjectUtil.isNull(globalThreadPoolQueueSize)) { + return 512; + } else { + return globalThreadPoolQueueSize; + } + } + + public void setGlobalThreadPoolQueueSize(Integer globalThreadPoolQueueSize) { + this.globalThreadPoolQueueSize = globalThreadPoolQueueSize; + } + + public String getGlobalThreadPoolExecutorClass() { + if (StrUtil.isBlank(globalThreadPoolExecutorClass)) { + return "com.yomahub.liteflow.thread.LiteFlowDefaultGlobalExecutorBuilder"; + } else { + return globalThreadPoolExecutorClass; + } + } + + public void setGlobalThreadPoolExecutorClass(String globalThreadPoolExecutorClass) { + this.globalThreadPoolExecutorClass = globalThreadPoolExecutorClass; + } } diff --git a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowProperty.java b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowProperty.java index 930a62d4c..34c93c967 100644 --- a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowProperty.java +++ b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowProperty.java @@ -1,5 +1,7 @@ package com.yomahub.liteflow.springboot; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; import com.yomahub.liteflow.enums.ParseModeEnum; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -36,6 +38,7 @@ public class LiteflowProperty { private String mainExecutorClass; // 并行线程执行器class路径 + @Deprecated private String threadExecutorClass; // 异步线程最大等待描述 @@ -47,9 +50,11 @@ public class LiteflowProperty { private TimeUnit whenMaxWaitTimeUnit; // 异步线程池最大线程数 + @Deprecated private int whenMaxWorkers; // 异步线程池最大队列数量 + @Deprecated private int whenQueueLimit; // 异步线程池是否隔离 @@ -80,13 +85,15 @@ public class LiteflowProperty { // 规则文件/脚本文件变更监听 private boolean enableMonitorFile; - + @Deprecated private String parallelLoopExecutorClass; //使用默认并行循环线程池时,最大线程数 + @Deprecated private int parallelMaxWorkers; //使用默认并行循环线程池时,最大队列数 + @Deprecated private int parallelQueueLimit; // 是否启用组件降级 @@ -101,6 +108,15 @@ public class LiteflowProperty { //脚本特殊设置选项 private Map scriptSetting; + //全局线程池所用class路径(when+异步循环) + private String globalThreadPoolExecutorClass; + + //全局线程池最大线程数(when+异步循环) + private Integer globalThreadPoolSize; + + //全局线程池最大队列数(when+异步循环) + private Integer globalThreadPoolQueueSize; + public boolean isEnableMonitorFile() { return enableMonitorFile; } @@ -143,18 +159,22 @@ public class LiteflowProperty { this.whenMaxWaitSeconds = whenMaxWaitSeconds; } + @Deprecated public int getWhenMaxWorkers() { return whenMaxWorkers; } + @Deprecated public void setWhenMaxWorkers(int whenMaxWorkers) { this.whenMaxWorkers = whenMaxWorkers; } + @Deprecated public int getWhenQueueLimit() { return whenQueueLimit; } + @Deprecated public void setWhenQueueLimit(int whenQueueLimit) { this.whenQueueLimit = whenQueueLimit; } @@ -193,10 +213,12 @@ public class LiteflowProperty { this.printBanner = printBanner; } + @Deprecated public String getThreadExecutorClass() { return threadExecutorClass; } + @Deprecated public void setThreadExecutorClass(String threadExecutorClass) { this.threadExecutorClass = threadExecutorClass; } @@ -273,26 +295,32 @@ public class LiteflowProperty { this.whenMaxWaitTimeUnit = whenMaxWaitTimeUnit; } + @Deprecated public String getParallelLoopExecutorClass() { return parallelLoopExecutorClass; } + @Deprecated public void setParallelLoopExecutorClass(String parallelLoopExecutorClass) { this.parallelLoopExecutorClass = parallelLoopExecutorClass; } + @Deprecated public int getParallelMaxWorkers() { return parallelMaxWorkers; } + @Deprecated public void setParallelMaxWorkers(int parallelMaxWorkers) { this.parallelMaxWorkers = parallelMaxWorkers; } + @Deprecated public int getParallelQueueLimit() { return parallelQueueLimit; } + @Deprecated public void setParallelQueueLimit(int parallelQueueLimit) { this.parallelQueueLimit = parallelQueueLimit; } @@ -336,4 +364,40 @@ public class LiteflowProperty { public void setScriptSetting(Map scriptSetting) { this.scriptSetting = scriptSetting; } + + public Integer getGlobalThreadPoolSize() { + if (ObjectUtil.isNull(globalThreadPoolSize)) { + return 16; + } else { + return globalThreadPoolSize; + } + } + + public void setGlobalThreadPoolSize(Integer globalThreadPoolSize) { + this.globalThreadPoolSize = globalThreadPoolSize; + } + + public Integer getGlobalThreadPoolQueueSize() { + if (ObjectUtil.isNull(globalThreadPoolQueueSize)) { + return 512; + } else { + return globalThreadPoolQueueSize; + } + } + + public void setGlobalThreadPoolQueueSize(Integer globalThreadPoolQueueSize) { + this.globalThreadPoolQueueSize = globalThreadPoolQueueSize; + } + + public String getGlobalThreadPoolExecutorClass() { + if (StrUtil.isBlank(globalThreadPoolExecutorClass)) { + return "com.yomahub.liteflow.thread.LiteFlowDefaultGlobalExecutorBuilder"; + } else { + return globalThreadPoolExecutorClass; + } + } + + public void setGlobalThreadPoolExecutorClass(String globalThreadPoolExecutorClass) { + this.globalThreadPoolExecutorClass = globalThreadPoolExecutorClass; + } } diff --git a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowPropertyAutoConfiguration.java b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowPropertyAutoConfiguration.java index 37356fcb3..d68f5a393 100644 --- a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowPropertyAutoConfiguration.java +++ b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowPropertyAutoConfiguration.java @@ -54,6 +54,9 @@ public class LiteflowPropertyAutoConfiguration { liteflowConfig.setDelay(liteflowMonitorProperty.getDelay()); liteflowConfig.setPeriod(liteflowMonitorProperty.getPeriod()); liteflowConfig.setScriptSetting(property.getScriptSetting()); + liteflowConfig.setGlobalThreadPoolExecutorClass(property.getGlobalThreadPoolExecutorClass()); + liteflowConfig.setGlobalThreadPoolQueueSize(property.getGlobalThreadPoolQueueSize()); + liteflowConfig.setGlobalThreadPoolSize(property.getGlobalThreadPoolSize()); return liteflowConfig; } diff --git a/liteflow-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/liteflow-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 83b0b668e..ae2c22a44 100644 --- a/liteflow-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/liteflow-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -220,6 +220,27 @@ "type": "java.util.Map", "description": "script special settings.", "sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty" + }, + { + "name": "liteflow.global-thread-pool-size", + "type": "java.lang.Integer", + "description": "Set the global chain thread pool worker max-size.", + "sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty", + "defaultValue": 16 + }, + { + "name": "liteflow.global-thread-pool-queue-size", + "type": "java.lang.Integer", + "description": "Set the global chain thread pool queue max-size ", + "sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty", + "defaultValue": 512 + }, + { + "name": "liteflow.global-thread-pool-executor-class", + "type": "java.lang.String", + "description": "Custom the global chain thread pool implement for global chain executor.", + "sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty", + "defaultValue": "com.yomahub.liteflow.thread.LiteFlowDefaultGlobalExecutorBuilder" } ] } \ No newline at end of file diff --git a/liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties b/liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties index 37aeb4645..5dec76788 100644 --- a/liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties +++ b/liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties @@ -26,4 +26,7 @@ liteflow.monitor.queue-limit=200 liteflow.monitor.delay=300000 liteflow.monitor.period=300000 liteflow.enable-monitor-file=false +liteflow.global-thread-pool-size=16 +liteflow.global-thread-pool-queue-size=512 +liteflow.global-thread-pool-executor-class=comcom.yomahub.liteflow.thread.LiteFlowDefaultGlobalExecutorBuilder diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ChainThreadPoolELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ChainThreadPoolELSpringbootTest.java new file mode 100644 index 000000000..ed9532134 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ChainThreadPoolELSpringbootTest.java @@ -0,0 +1,79 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.collection.ListUtil; +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 org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +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 javax.annotation.Resource; +import java.util.List; + +/** + * springboot环境下chain线程池隔离测试 + */ +@TestPropertySource(value = "classpath:/chainThreadPool/application.properties") +@SpringBootTest(classes = ChainThreadPoolELSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.chainThreadPool.cmp"}) +public class ChainThreadPoolELSpringbootTest extends BaseTest { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Resource + private FlowExecutor flowExecutor; + + /** + * 测试WHEN上全局线程池和chain线程池隔离-优先以chain上为准 + */ + @Test + public void testChainThreadPool() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + } + + /** + * 测试FOR上全局线程池和chain线程池隔离-优先以chain上为准 + */ + @Test + public void testChainThreadPool2() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + } + + /** + * 测试WHILE上全局线程池和chain线程池隔离-优先以chain上为准 + */ + @Test + public void testChainThreadPool3() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + } + + /** + * 测试ITERATOR上全局线程池和chain线程池隔离-优先以chain上为准 + */ + @Test + public void testChainThreadPool4() { + List list = ListUtil.toList("1", "2", "3", "4", "5"); + LiteflowResponse response1 = flowExecutor.execute2Resp("chain4", list); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomThreadPoolELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ConditionThreadPoolELSpringbootTest.java similarity index 89% rename from liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomThreadPoolELSpringbootTest.java rename to liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ConditionThreadPoolELSpringbootTest.java index f50aa6389..1821e4dca 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomThreadPoolELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ConditionThreadPoolELSpringbootTest.java @@ -21,10 +21,10 @@ import java.util.List; * springboot环境下chain线程池隔离测试 */ @TestPropertySource(value = "classpath:/chainThreadPool/application2.properties") -@SpringBootTest(classes = CustomThreadPoolELSpringbootTest.class) +@SpringBootTest(classes = ConditionThreadPoolELSpringbootTest.class) @EnableAutoConfiguration @ComponentScan({"com.yomahub.liteflow.test.chainThreadPool.cmp"}) -public class CustomThreadPoolELSpringbootTest extends BaseTest { +public class ConditionThreadPoolELSpringbootTest extends BaseTest { private final Logger log = LoggerFactory.getLogger(this.getClass()); @@ -35,7 +35,7 @@ public class CustomThreadPoolELSpringbootTest extends BaseTest { * 测试WEHN上condition线程池和chain线程池隔离-优先以WHEN上为准 */ @Test - public void testCustomChainThreadPool() { + public void testConditionThreadPool() { LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); DefaultContext context = response1.getFirstContextBean(); Assertions.assertTrue(response1.isSuccess()); @@ -46,7 +46,7 @@ public class CustomThreadPoolELSpringbootTest extends BaseTest { * 测试FOR上condition线程池和chain线程池隔离-优先以FOR上为准 */ @Test - public void testCustomChainThreadPool2() { + public void testConditionThreadPool2() { LiteflowResponse response1 = flowExecutor.execute2Resp("chain2", "arg"); DefaultContext context = response1.getFirstContextBean(); Assertions.assertTrue(response1.isSuccess()); @@ -57,7 +57,7 @@ public class CustomThreadPoolELSpringbootTest extends BaseTest { * 测试WHILE上condition线程池和chain线程池隔离-优先以WHILE上为准 */ @Test - public void testCustomChainThreadPool3() { + public void testConditionThreadPool3() { LiteflowResponse response1 = flowExecutor.execute2Resp("chain3", "arg"); DefaultContext context = response1.getFirstContextBean(); Assertions.assertTrue(response1.isSuccess()); @@ -68,7 +68,7 @@ public class CustomThreadPoolELSpringbootTest extends BaseTest { * 测试ITERATOR上condition线程池和chain线程池隔离-优先以ITERATOR上为准 */ @Test - public void testCustomChainThreadPool4() { + public void testConditionThreadPool4() { List list = ListUtil.toList("1", "2", "3", "4", "5"); LiteflowResponse response1 = flowExecutor.execute2Resp("chain4", list); DefaultContext context = response1.getFirstContextBean(); diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomGlobalThreadExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomGlobalThreadExecutor.java new file mode 100644 index 000000000..32ca62e39 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomGlobalThreadExecutor.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomGlobalThreadExecutor implements ExecutorBuilder { + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(16, 16, + 512, "customer-global-thead"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/GlobalThreadPoolELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/GlobalThreadPoolELSpringbootTest.java index f307c0496..50dad85d9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/GlobalThreadPoolELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/GlobalThreadPoolELSpringbootTest.java @@ -1,4 +1,4 @@ -package com.yomahub.liteflow.test.chainThreadPool; +package com.yomahub.liteflow.test.GlobalThreadPool; import cn.hutool.core.collection.ListUtil; import com.yomahub.liteflow.core.FlowExecutor; @@ -18,9 +18,9 @@ import javax.annotation.Resource; import java.util.List; /** - * springboot环境下chain线程池隔离测试 + * springboot环境下Global线程池隔离测试 */ -@TestPropertySource(value = "classpath:/chainThreadPool/application.properties") +@TestPropertySource(value = "classpath:/chainThreadPool/application3.properties") @SpringBootTest(classes = GlobalThreadPoolELSpringbootTest.class) @EnableAutoConfiguration @ComponentScan({"com.yomahub.liteflow.test.chainThreadPool.cmp"}) @@ -32,48 +32,48 @@ public class GlobalThreadPoolELSpringbootTest extends BaseTest { private FlowExecutor flowExecutor; /** - * 测试WHEN上全局线程池和chain线程池隔离-优先以chain上为准 + * 测试WHEN上全局线程池 */ @Test - public void testGlobalChainThreadPool() { + public void testGlobalThreadPool() { LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); DefaultContext context = response1.getFirstContextBean(); Assertions.assertTrue(response1.isSuccess()); - Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-Global-thead")); } /** - * 测试FOR上全局线程池和chain线程池隔离-优先以chain上为准 + * 测试FOR上全局线程池 */ @Test - public void testGlobalChainThreadPool2() { + public void testGlobalThreadPool2() { LiteflowResponse response1 = flowExecutor.execute2Resp("chain2", "arg"); DefaultContext context = response1.getFirstContextBean(); Assertions.assertTrue(response1.isSuccess()); - Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-Global-thead")); } /** - * 测试WHILE上全局线程池和chain线程池隔离-优先以chain上为准 + * 测试WHILE上全局线程池 */ @Test - public void testGlobalChainThreadPool3() { + public void testGlobalThreadPool3() { LiteflowResponse response1 = flowExecutor.execute2Resp("chain3", "arg"); DefaultContext context = response1.getFirstContextBean(); Assertions.assertTrue(response1.isSuccess()); - Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-Global-thead")); } /** - * 测试ITERATOR上全局线程池和chain线程池隔离-优先以chain上为准 + * 测试ITERATOR上全局线程池 */ @Test - public void testGlobalChainThreadPool4() { + public void testGlobalThreadPool4() { List list = ListUtil.toList("1", "2", "3", "4", "5"); LiteflowResponse response1 = flowExecutor.execute2Resp("chain4", list); DefaultContext context = response1.getFirstContextBean(); Assertions.assertTrue(response1.isSuccess()); - Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-Global-thead")); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/application3.properties b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/application3.properties new file mode 100644 index 000000000..d7ec64e9a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/application3.properties @@ -0,0 +1,4 @@ +liteflow.rule-source=chainThreadPool/flow3.el.xml +liteflow.global-thread-pool-size=16 +liteflow.global-thread-pool-queue-size=512 +liteflow.global-thread-pool-executor-class=com.yomahub.liteflow.test.chainThreadPool.CustomGlobalThreadExecutor \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/flow3.el.xml b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/flow3.el.xml new file mode 100644 index 000000000..bd35f961f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/flow3.el.xml @@ -0,0 +1,20 @@ + + + + WHEN(a,b); + + + + FOR(5).parallel(true).DO(THEN(a,f + ) + ); + + + + WHILE(z).parallel(true).DO(THEN(w,d)); + + + + ITERATOR(it).parallel(true).DO(THEN(a,i)); + + \ No newline at end of file From a27397c9d46551e4fc901467ee3d82241fb98355 Mon Sep 17 00:00:00 2001 From: jason <2353220944@qq.com> Date: Mon, 28 Oct 2024 20:01:49 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=BC=82=E6=AD=A5?= =?UTF-8?q?=E5=BE=AA=E7=8E=AFcondition=E5=B1=82=E7=BA=A7=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E6=B1=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../el/operator/ThreadPoolOperator.java | 30 ++++++++++++++----- .../flow/element/condition/ForCondition.java | 3 +- .../element/condition/IteratorCondition.java | 3 +- .../flow/element/condition/LoopCondition.java | 10 +++++++ .../element/condition/WhileCondition.java | 2 +- .../liteflow/thread/ExecutorHelper.java | 14 ++++++--- .../ConditionThreadPoolELSpringbootTest.java | 6 ++-- .../CustomLoopThreadExecutor.java | 23 ++++++++++++++ .../resources/chainThreadPool/flow2.el.xml | 8 ++--- 9 files changed, 77 insertions(+), 22 deletions(-) create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomLoopThreadExecutor.java diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ThreadPoolOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ThreadPoolOperator.java index d6ad98b2f..0a65e27df 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ThreadPoolOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ThreadPoolOperator.java @@ -1,27 +1,43 @@ package com.yomahub.liteflow.builder.el.operator; +import com.ql.util.express.exception.QLException; import com.yomahub.liteflow.builder.el.operator.base.BaseOperator; import com.yomahub.liteflow.builder.el.operator.base.OperatorHelper; +import com.yomahub.liteflow.flow.element.Condition; +import com.yomahub.liteflow.flow.element.condition.LoopCondition; import com.yomahub.liteflow.flow.element.condition.WhenCondition; /** - * EL规则中的threadPool的操作符 + * EL规则中的threadPool的操作符 有四种用法 WHEN().threadPool() FOR...DO().threadPool() WHILE...DO.threadPool() ITERATOR...DO + * .threadPool() * * @author Bryan.Zhang * @since 2.8.0 */ -public class ThreadPoolOperator extends BaseOperator { +public class ThreadPoolOperator extends BaseOperator { @Override - public WhenCondition build(Object[] objects) throws Exception { + public Condition build(Object[] objects) throws Exception { OperatorHelper.checkObjectSizeEqTwo(objects); - String errorMsg = "The caller must be WhenCondition item"; - WhenCondition whenCondition = OperatorHelper.convert(objects[0], WhenCondition.class, errorMsg); + if (objects[0] instanceof WhenCondition) { + String errorMsg = "The caller must be WhenCondition item"; - whenCondition.setThreadExecutorClass(OperatorHelper.convert(objects[1], String.class)); + WhenCondition condition = OperatorHelper.convert(objects[0], WhenCondition.class, errorMsg); - return whenCondition; + condition.setThreadExecutorClass(OperatorHelper.convert(objects[1], String.class)); + return condition; + } else if (objects[0] instanceof LoopCondition) { + String errorMsg = "The caller must be LoopCondition item"; + + LoopCondition condition = OperatorHelper.convert(objects[0], LoopCondition.class, errorMsg); + + condition.setThreadPoolExecutorClass(OperatorHelper.convert(objects[1], String.class)); + return condition; + } else { + String errorMsg = "The caller must be LoopCondition or WhenCondition item"; + throw new QLException(errorMsg); + } } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/ForCondition.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/ForCondition.java index f77ee4017..b8dd9429f 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/ForCondition.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/ForCondition.java @@ -77,7 +77,8 @@ public class ForCondition extends LoopCondition { //存储所有的并行执行子项的CompletableFuture List> futureList = new ArrayList<>(); //获取并行循环的线程池 - ExecutorService parallelExecutor = ExecutorHelper.loadInstance().buildLoopParallelExecutor(slotIndex); + ExecutorService parallelExecutor = ExecutorHelper.loadInstance().buildLoopParallelExecutor(this, + slotIndex); for (int i = 0; i < forCount; i++){ //提交异步任务 CompletableFuture future = diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/IteratorCondition.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/IteratorCondition.java index f0efae8c0..0cbf7645d 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/IteratorCondition.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/IteratorCondition.java @@ -80,7 +80,8 @@ public class IteratorCondition extends LoopCondition { //存储所有的并行执行子项的CompletableFuture List> futureList = new ArrayList<>(); //获取并行循环的线程池 - ExecutorService parallelExecutor = ExecutorHelper.loadInstance().buildLoopParallelExecutor(slotIndex); + ExecutorService parallelExecutor = ExecutorHelper.loadInstance().buildLoopParallelExecutor(this, + slotIndex); while (it.hasNext()) { Object itObj = it.next(); //提交异步任务 diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/LoopCondition.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/LoopCondition.java index 5242ee839..1623e90c3 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/LoopCondition.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/LoopCondition.java @@ -20,6 +20,8 @@ import java.util.function.Supplier; public abstract class LoopCondition extends Condition { //判断循环是否并行执行,默认为false private boolean parallel = false; + //loop condition层级的线程池 + private String threadPoolExecutorClass; protected Executable getBreakItem() { return this.getExecutableOne(ConditionKey.BREAK_KEY); @@ -37,6 +39,14 @@ public abstract class LoopCondition extends Condition { this.addExecutable(ConditionKey.DO_KEY, executable); } + public String getThreadPoolExecutorClass() { + return threadPoolExecutorClass; + } + + public void setThreadPoolExecutorClass(String threadPoolExecutorClass) { + this.threadPoolExecutorClass = threadPoolExecutorClass; + } + protected void setLoopIndex(Executable executableItem, int index) { if (executableItem instanceof Chain) { ((Chain) executableItem).getConditionList().forEach(condition -> setLoopIndex(condition, index)); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/WhileCondition.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/WhileCondition.java index 145489c10..8e109632a 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/WhileCondition.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/element/condition/WhileCondition.java @@ -61,7 +61,7 @@ public class WhileCondition extends LoopCondition { //并行循环逻辑 List> futureList = new ArrayList<>(); //获取并行循环的线程池 - ExecutorService parallelExecutor = ExecutorHelper.loadInstance().buildLoopParallelExecutor(slotIndex); + ExecutorService parallelExecutor = ExecutorHelper.loadInstance().buildLoopParallelExecutor(this, slotIndex); while (getWhileResult(slotIndex, index)){ CompletableFuture future = CompletableFuture.supplyAsync(new LoopParallelSupplier(executableItem, this.getCurrChainId(), slotIndex, index), parallelExecutor); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java index 9f8d75104..f82d3cb61 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java @@ -14,6 +14,7 @@ import cn.hutool.core.util.StrUtil; import com.yomahub.liteflow.exception.ThreadExecutorServiceCreateException; import com.yomahub.liteflow.flow.FlowBus; import com.yomahub.liteflow.flow.element.Chain; +import com.yomahub.liteflow.flow.element.condition.LoopCondition; import com.yomahub.liteflow.log.LFLog; import com.yomahub.liteflow.log.LFLoggerManager; import com.yomahub.liteflow.property.LiteflowConfig; @@ -134,25 +135,30 @@ public class ExecutorHelper { } //构造并行循环的线程池 - public ExecutorService buildLoopParallelExecutor(Integer slotIndex) { + public ExecutorService buildLoopParallelExecutor(LoopCondition loopCondition, Integer slotIndex) { ExecutorService parallelExecutor; LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); //获取chain的hash String chainId = DataBus.getSlot(slotIndex).getChainId(); Chain chain = FlowBus.getChain(chainId); - //condition层级线程池 TODO + //condition层级线程池 + if (ObjectUtil.isNotEmpty(loopCondition.getThreadPoolExecutorClass())) { + parallelExecutor = getExecutorService(loopCondition.getThreadPoolExecutorClass(), + String.valueOf(loopCondition.hashCode())); - //chain层级线程池 - if (ObjectUtil.isNotEmpty(chain.getThreadPoolExecutorClass())) { + } else if (ObjectUtil.isNotEmpty(chain.getThreadPoolExecutorClass())) { //chain层级线程池 parallelExecutor = getExecutorService(chain.getThreadPoolExecutorClass(), String.valueOf(chain.hashCode())); + } else { //全局线程池 parallelExecutor = getExecutorService(Optional.ofNullable(liteflowConfig.getParallelLoopExecutorClass()) .orElse(liteflowConfig.getGlobalThreadPoolExecutorClass())); + } + return parallelExecutor; } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ConditionThreadPoolELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ConditionThreadPoolELSpringbootTest.java index 1821e4dca..6b3dbdf73 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ConditionThreadPoolELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ConditionThreadPoolELSpringbootTest.java @@ -50,7 +50,7 @@ public class ConditionThreadPoolELSpringbootTest extends BaseTest { LiteflowResponse response1 = flowExecutor.execute2Resp("chain2", "arg"); DefaultContext context = response1.getFirstContextBean(); Assertions.assertTrue(response1.isSuccess()); - Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-loop-thead")); } /** @@ -61,7 +61,7 @@ public class ConditionThreadPoolELSpringbootTest extends BaseTest { LiteflowResponse response1 = flowExecutor.execute2Resp("chain3", "arg"); DefaultContext context = response1.getFirstContextBean(); Assertions.assertTrue(response1.isSuccess()); - Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-loop-thead")); } /** @@ -73,7 +73,7 @@ public class ConditionThreadPoolELSpringbootTest extends BaseTest { LiteflowResponse response1 = flowExecutor.execute2Resp("chain4", list); DefaultContext context = response1.getFirstContextBean(); Assertions.assertTrue(response1.isSuccess()); - Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-loop-thead")); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomLoopThreadExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomLoopThreadExecutor.java new file mode 100644 index 000000000..63d3222e4 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomLoopThreadExecutor.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomLoopThreadExecutor implements ExecutorBuilder { + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(16, 16, + 512, "customer-loop-thead"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/flow2.el.xml b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/flow2.el.xml index 4b280ba91..741e264ba 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/flow2.el.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/flow2.el.xml @@ -7,18 +7,16 @@ - FOR(5).parallel(true).DO(THEN(a,f - ) - ); + FOR(5).parallel(true).DO(THEN(a,f)).threadPool("com.yomahub.liteflow.test.chainThreadPool.CustomLoopThreadExecutor"); - WHILE(z).parallel(true).DO(THEN(w,d)); + WHILE(z).parallel(true).DO(THEN(w,d)).threadPool("com.yomahub.liteflow.test.chainThreadPool.CustomLoopThreadExecutor"); - ITERATOR(it).parallel(true).DO(THEN(a,i)); + ITERATOR(it).parallel(true).DO(THEN(a,i)).threadPool("com.yomahub.liteflow.test.chainThreadPool.CustomLoopThreadExecutor"); \ No newline at end of file From 3fbd8e1c8e674677560ad9676e487e6deec95d2c Mon Sep 17 00:00:00 2001 From: jason <2353220944@qq.com> Date: Fri, 1 Nov 2024 11:54:01 +0800 Subject: [PATCH 7/9] remove code && add springBoot test --- .../el/operator/ThreadPoolOperator.java | 2 +- .../builder/el/operator/WhenOperator.java | 5 +- .../liteflow/parser/helper/ParserHelper.java | 11 +- .../liteflow/property/LiteflowConfig.java | 106 ------------------ .../liteflow/thread/ExecutorHelper.java | 14 +-- .../LiteFlowDefaultGlobalExecutorBuilder.java | 2 +- ...lowDefaultParallelLoopExecutorBuilder.java | 27 ----- .../LiteFlowDefaultWhenExecutorBuilder.java | 28 ----- .../config/LiteflowAutoConfiguration.java | 6 - .../solon/config/LiteflowProperty.java | 6 +- .../META-INF/liteflow-default.properties | 6 +- .../liteflow/springboot/LiteflowProperty.java | 82 -------------- .../LiteflowPropertyAutoConfiguration.java | 6 - ...itional-spring-configuration-metadata.json | 42 ------- .../META-INF/liteflow-default.properties | 8 +- .../parallelLoop/application.properties | 6 +- .../parallelLoop/application.properties | 6 +- .../parallelLoop/application.properties | 6 +- .../parallelLoop/application.properties | 6 +- .../GlobalThreadPoolELSpringbootTest.java | 10 +- .../CustomThreadExecutor1.java | 4 +- .../CustomThreadExecutor2.java | 4 +- .../CustomThreadExecutor3.java | 4 +- .../CustomWhenThreadPoolELSpringbootTest.java | 2 +- .../parallelLoop/CustomThreadExecutor.java | 4 +- .../resources/chainThreadPool/flow.el.xml | 4 +- .../resources/chainThreadPool/flow3.el.xml | 3 +- .../parallelLoop/application.properties | 6 +- 28 files changed, 50 insertions(+), 366 deletions(-) delete mode 100644 liteflow-core/src/main/java/com/yomahub/liteflow/thread/LiteFlowDefaultParallelLoopExecutorBuilder.java delete mode 100644 liteflow-core/src/main/java/com/yomahub/liteflow/thread/LiteFlowDefaultWhenExecutorBuilder.java diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ThreadPoolOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ThreadPoolOperator.java index 0a65e27df..6d297e84e 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ThreadPoolOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/ThreadPoolOperator.java @@ -35,7 +35,7 @@ public class ThreadPoolOperator extends BaseOperator { condition.setThreadPoolExecutorClass(OperatorHelper.convert(objects[1], String.class)); return condition; } else { - String errorMsg = "The caller must be LoopCondition or WhenCondition item"; + String errorMsg = "The caller must be WhenCondition or LoopCondition item"; throw new QLException(errorMsg); } } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/WhenOperator.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/WhenOperator.java index 2be0c5365..a657b0c45 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/WhenOperator.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/el/operator/WhenOperator.java @@ -7,8 +7,6 @@ import com.yomahub.liteflow.flow.element.condition.WhenCondition; import com.yomahub.liteflow.property.LiteflowConfig; import com.yomahub.liteflow.property.LiteflowConfigGetter; -import java.util.Optional; - /** * EL规则中的WHEN的操作符 * @@ -27,8 +25,7 @@ public class WhenOperator extends BaseOperator { for (Object obj : objects) { OperatorHelper.checkObjMustBeCommonTypeItem(obj); whenCondition.addExecutable(OperatorHelper.convert(obj, Executable.class)); - whenCondition.setThreadExecutorClass(Optional.ofNullable(liteflowConfig.getThreadExecutorClass()) - .orElse(liteflowConfig.getGlobalThreadPoolExecutorClass())); + whenCondition.setThreadExecutorClass(liteflowConfig.getGlobalThreadPoolExecutorClass()); } return whenCondition; } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/helper/ParserHelper.java b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/helper/ParserHelper.java index 50dafedd0..128f428cc 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/helper/ParserHelper.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/helper/ParserHelper.java @@ -304,8 +304,8 @@ public class ParserHelper { JsonNode routeJsonNode = chainNode.get(ROUTE); - String threadPoolExecutorClass = chainNode.get(THREAD_POOL_EXECUTOR_CLASS) == null ? - null : chainNode.get(THREAD_POOL_EXECUTOR_CLASS).textValue(); + String threadPoolExecutorClass = chainNode.get(THREAD_POOL_EXECUTOR_CLASS) == null ? null : + chainNode.get(THREAD_POOL_EXECUTOR_CLASS).textValue(); LiteFlowChainELBuilder builder = LiteFlowChainELBuilder.createChain().setChainId(chainId).setNamespace(namespace) @@ -340,12 +340,11 @@ public class ParserHelper { Element routeElement = e.element(ROUTE); - String threadPoolExecutorClass = e.attributeValue(THREAD_POOL_EXECUTOR_CLASS) == null ? - null : e.attributeValue(THREAD_POOL_EXECUTOR_CLASS); + String threadPoolExecutorClass = e.attributeValue(THREAD_POOL_EXECUTOR_CLASS) == null ? null : + e.attributeValue(THREAD_POOL_EXECUTOR_CLASS); LiteFlowChainELBuilder builder = - LiteFlowChainELBuilder.createChain().setChainId(chainId).setNamespace(namespace) - .setThreadPoolExecutorClass(threadPoolExecutorClass); + LiteFlowChainELBuilder.createChain().setChainId(chainId).setNamespace(namespace).setThreadPoolExecutorClass(threadPoolExecutorClass); // 如果有route这个标签,说明是决策表chain // 决策表链路必须有route和body这两个标签 diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java b/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java index b6d4982d8..2e6f4d6b0 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java @@ -41,10 +41,6 @@ public class LiteflowConfig { // slot的数量 private Integer slotSize; - // 并行线程执行器class路径 - @Deprecated - private String threadExecutorClass; - // 异步线程最大等待秒数 @Deprecated private Integer whenMaxWaitSeconds; @@ -68,10 +64,6 @@ public class LiteflowConfig { // 每隔多少秒打印 private Long period; - // 异步线程池最大线程数 - @Deprecated - private Integer whenMaxWorkers; - // 异步线程池最大队列数量 @Deprecated private Integer whenQueueLimit; @@ -107,18 +99,6 @@ public class LiteflowConfig { // 规则文件/脚本文件变更监听 private Boolean enableMonitorFile = Boolean.FALSE; - - //并行循环线程池所用class路径 - @Deprecated - private String parallelLoopExecutorClass; - - //使用默认并行循环线程池时,最大线程数 - @Deprecated - private Integer parallelMaxWorkers; - - //使用默认并行循环线程池时,最大队列数 - @Deprecated - private Integer parallelQueueLimit; // 是否启用组件降级 private Boolean fallbackCmpEnable; @@ -245,37 +225,6 @@ public class LiteflowConfig { this.enableLog = enableLog; } - @Deprecated - public Integer getWhenMaxWorkers() { - if (ObjectUtil.isNull(whenMaxWorkers)) { - return 16; - } - else { - return whenMaxWorkers; - } - } - - @Deprecated - - public void setWhenMaxWorkers(Integer whenMaxWorkers) { - this.whenMaxWorkers = whenMaxWorkers; - } - - @Deprecated - public Integer getWhenQueueLimit() { - if (ObjectUtil.isNull(whenQueueLimit)) { - return 512; - } - else { - return whenQueueLimit; - } - } - - @Deprecated - public void setWhenQueueLimit(Integer whenQueueLimit) { - this.whenQueueLimit = whenQueueLimit; - } - public Boolean isSupportMultipleType() { if (ObjectUtil.isNull(supportMultipleType)) { return Boolean.FALSE; @@ -317,20 +266,6 @@ public class LiteflowConfig { this.printBanner = printBanner; } - @Deprecated - public String getThreadExecutorClass() { - if (StrUtil.isBlank(threadExecutorClass)) { - return "com.yomahub.liteflow.thread.LiteFlowDefaultWhenExecutorBuilder"; - } - else { - return threadExecutorClass; - } - } - - @Deprecated - public void setThreadExecutorClass(String threadExecutorClass) { - this.threadExecutorClass = threadExecutorClass; - } public String getNodeExecutorClass() { if (StrUtil.isBlank(nodeExecutorClass)) { @@ -432,47 +367,6 @@ public class LiteflowConfig { public void setWhenMaxWaitTimeUnit(TimeUnit whenMaxWaitTimeUnit) { this.whenMaxWaitTimeUnit = whenMaxWaitTimeUnit; } - - public Integer getParallelMaxWorkers() { - if(ObjectUtil.isNull(parallelMaxWorkers)){ - return 16; - }else{ - return parallelMaxWorkers; - } - } - - public void setParallelMaxWorkers(Integer parallelMaxWorkers) { - this.parallelMaxWorkers = parallelMaxWorkers; - } - - @Deprecated - public Integer getParallelQueueLimit() { - if(ObjectUtil.isNull(parallelQueueLimit)){ - return 512; - }else{ - return parallelQueueLimit; - } - } - - @Deprecated - public void setParallelQueueLimit(Integer parallelQueueLimit) { - this.parallelQueueLimit = parallelQueueLimit; - } - - @Deprecated - public String getParallelLoopExecutorClass() { - if (StrUtil.isBlank(parallelLoopExecutorClass)) { - return "com.yomahub.liteflow.thread.LiteFlowDefaultParallelLoopExecutorBuilder"; - } - else { - return parallelLoopExecutorClass; - } - } - - @Deprecated - public void setParallelLoopExecutorClass(String parallelLoopExecutorClass) { - this.parallelLoopExecutorClass = parallelLoopExecutorClass; - } public Boolean getFallbackCmpEnable() { if (ObjectUtil.isNull(this.fallbackCmpEnable)) { diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java index f82d3cb61..a14c16fc3 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java @@ -23,7 +23,6 @@ import com.yomahub.liteflow.slot.DataBus; import com.yomahub.liteflow.spi.holder.ContextAwareHolder; import java.util.Map; -import java.util.Optional; import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; @@ -93,8 +92,7 @@ public class ExecutorHelper { // 构建默认when线程池 public ExecutorService buildWhenExecutor() { LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - return buildWhenExecutor(Optional.ofNullable(liteflowConfig.getGlobalThreadPoolExecutorClass()) - .orElse(liteflowConfig.getThreadExecutorClass())); + return buildWhenExecutor(liteflowConfig.getGlobalThreadPoolExecutorClass()); } // 构建when线程池 - 支持多个when公用一个线程池 @@ -108,9 +106,7 @@ public class ExecutorHelper { // 构建when线程池 - clazz和condition的hash值共同作为缓存key public ExecutorService buildWhenExecutorWithHash(String conditionHash) { LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - return buildWhenExecutorWithHash(Optional.ofNullable(liteflowConfig.getThreadExecutorClass()) - .orElse(liteflowConfig.getGlobalThreadPoolExecutorClass()), - conditionHash); + return buildWhenExecutorWithHash(liteflowConfig.getGlobalThreadPoolExecutorClass(), conditionHash); } // 构建when线程池 - clazz和condition的hash值共同作为缓存key @@ -138,12 +134,11 @@ public class ExecutorHelper { public ExecutorService buildLoopParallelExecutor(LoopCondition loopCondition, Integer slotIndex) { ExecutorService parallelExecutor; LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - //获取chain的hash String chainId = DataBus.getSlot(slotIndex).getChainId(); Chain chain = FlowBus.getChain(chainId); - //condition层级线程池 if (ObjectUtil.isNotEmpty(loopCondition.getThreadPoolExecutorClass())) { + //condition层级线程池 parallelExecutor = getExecutorService(loopCondition.getThreadPoolExecutorClass(), String.valueOf(loopCondition.hashCode())); @@ -154,8 +149,7 @@ public class ExecutorHelper { } else { //全局线程池 - parallelExecutor = getExecutorService(Optional.ofNullable(liteflowConfig.getParallelLoopExecutorClass()) - .orElse(liteflowConfig.getGlobalThreadPoolExecutorClass())); + parallelExecutor = getExecutorService(liteflowConfig.getGlobalThreadPoolExecutorClass()); } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/LiteFlowDefaultGlobalExecutorBuilder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/LiteFlowDefaultGlobalExecutorBuilder.java index e1c44bc18..97ef96a8b 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/LiteFlowDefaultGlobalExecutorBuilder.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/LiteFlowDefaultGlobalExecutorBuilder.java @@ -7,7 +7,7 @@ import com.yomahub.liteflow.property.LiteflowConfigGetter; import java.util.concurrent.ExecutorService; /** - * LiteFlow默认的when线程池+异步多线程执行器实现 + * LiteFlow默认全局线程池执行器实现 * * @author jason */ diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/LiteFlowDefaultParallelLoopExecutorBuilder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/LiteFlowDefaultParallelLoopExecutorBuilder.java deleted file mode 100644 index 064a7cc34..000000000 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/LiteFlowDefaultParallelLoopExecutorBuilder.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.yomahub.liteflow.thread; - -import cn.hutool.core.util.ObjectUtil; -import com.yomahub.liteflow.property.LiteflowConfig; -import com.yomahub.liteflow.property.LiteflowConfigGetter; - -import java.util.concurrent.ExecutorService; - -/** - * LiteFlow默认的并行循环执行器实现 - * - * @author zhhhhy - * @since 2.11.0 - */ - -public class LiteFlowDefaultParallelLoopExecutorBuilder implements ExecutorBuilder { - @Override - public ExecutorService buildExecutor() { - LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - // 只有在非spring的场景下liteflowConfig才会为null - if (ObjectUtil.isNull(liteflowConfig)) { - liteflowConfig = new LiteflowConfig(); - } - return buildDefaultExecutor(liteflowConfig.getParallelMaxWorkers(), liteflowConfig.getParallelMaxWorkers(), - liteflowConfig.getParallelQueueLimit(), "loop-thread-"); - } -} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/LiteFlowDefaultWhenExecutorBuilder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/LiteFlowDefaultWhenExecutorBuilder.java deleted file mode 100644 index 32242b0c8..000000000 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/LiteFlowDefaultWhenExecutorBuilder.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.yomahub.liteflow.thread; - -import cn.hutool.core.util.ObjectUtil; -import com.yomahub.liteflow.property.LiteflowConfig; -import com.yomahub.liteflow.property.LiteflowConfigGetter; - -import java.util.concurrent.*; - -/** - * LiteFlow默认的并行多线程执行器实现 - * - * @author Bryan.Zhang - * @since 2.6.6 - */ -public class LiteFlowDefaultWhenExecutorBuilder implements ExecutorBuilder { - - @Override - public ExecutorService buildExecutor() { - LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - // 只有在非spring的场景下liteflowConfig才会为null - if (ObjectUtil.isNull(liteflowConfig)) { - liteflowConfig = new LiteflowConfig(); - } - return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), "when-thread-"); - } - -} diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowAutoConfiguration.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowAutoConfiguration.java index f4763fd46..572015c80 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowAutoConfiguration.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowAutoConfiguration.java @@ -29,14 +29,11 @@ public class LiteflowAutoConfiguration { liteflowConfig.setRuleSourceExtData(property.getRuleSourceExtData()); liteflowConfig.setRuleSourceExtDataMap(property.getRuleSourceExtDataMap()); liteflowConfig.setSlotSize(property.getSlotSize()); - liteflowConfig.setThreadExecutorClass(property.getThreadExecutorClass()); liteflowConfig.setWhenMaxWaitSeconds(property.getWhenMaxWaitSeconds()); liteflowConfig.setEnableLog(liteflowMonitorProperty.isEnableLog()); liteflowConfig.setQueueLimit(liteflowMonitorProperty.getQueueLimit()); liteflowConfig.setDelay(liteflowMonitorProperty.getDelay()); liteflowConfig.setPeriod(liteflowMonitorProperty.getPeriod()); - liteflowConfig.setWhenMaxWorkers(property.getWhenMaxWorkers()); - liteflowConfig.setWhenQueueLimit(property.getWhenQueueLimit()); liteflowConfig.setParseMode(property.getParseMode()); liteflowConfig.setEnable(property.isEnable()); liteflowConfig.setSupportMultipleType(property.isSupportMultipleType()); @@ -47,9 +44,6 @@ public class LiteflowAutoConfiguration { liteflowConfig.setMainExecutorWorks(property.getMainExecutorWorks()); liteflowConfig.setMainExecutorClass(property.getMainExecutorClass()); liteflowConfig.setPrintExecutionLog(property.isPrintExecutionLog()); - liteflowConfig.setParallelMaxWorkers(property.getParallelMaxWorkers()); - liteflowConfig.setParallelQueueLimit(property.getParallelQueueLimit()); - liteflowConfig.setParallelLoopExecutorClass(property.getParallelLoopExecutorClass()); liteflowConfig.setFallbackCmpEnable(property.isFallbackCmpEnable()); liteflowConfig.setGlobalThreadPoolExecutorClass(property.getGlobalThreadPoolExecutorClass()); liteflowConfig.setGlobalThreadPoolSize(property.getGlobalThreadPoolSize()); diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowProperty.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowProperty.java index 663d3c241..5472ddda5 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowProperty.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowProperty.java @@ -85,13 +85,13 @@ public class LiteflowProperty { // 是否启用组件降级 private Boolean fallbackCmpEnable; - //全局线程池所用class路径(when+异步循环) + //全局线程池所用class路径 private String globalThreadPoolExecutorClass; - //全局线程池最大线程数(when+异步循环) + //全局线程池最大线程数 private Integer globalThreadPoolSize; - //全局线程池最大队列数(when+异步循环) + //全局线程池最大队列数 private Integer globalThreadPoolQueueSize; public boolean isEnable() { diff --git a/liteflow-solon-plugin/src/main/resources/META-INF/liteflow-default.properties b/liteflow-solon-plugin/src/main/resources/META-INF/liteflow-default.properties index c1fda2e94..b2c34ff3b 100644 --- a/liteflow-solon-plugin/src/main/resources/META-INF/liteflow-default.properties +++ b/liteflow-solon-plugin/src/main/resources/META-INF/liteflow-default.properties @@ -4,10 +4,7 @@ liteflow.slot-size=1024 liteflow.main-executor-works=64 liteflow.main-executor-class=com.yomahub.liteflow.thread.LiteFlowDefaultMainExecutorBuilder liteflow.request-id-generator-class=com.yomahub.liteflow.flow.id.DefaultRequestIdGenerator -liteflow.thread-executor-class=com.yomahub.liteflow.thread.LiteFlowDefaultWhenExecutorBuilder liteflow.when-max-wait-seconds=15 -liteflow.when-max-workers=16 -liteflow.when-queue-limit=512 liteflow.parse-on-start=true liteflow.retry-count=0 liteflow.support-multiple-type=false @@ -18,3 +15,6 @@ liteflow.monitor.queue-limit=200 liteflow.monitor.delay=300000 liteflow.monitor.period=300000 liteflow.fallback-cmp-enable=false +liteflow.global-thread-pool-size=16 +liteflow.global-thread-pool-queue-size=512 +liteflow.global-thread-pool-executor-class=com.yomahub.liteflow.thread.LiteFlowDefaultGlobalExecutorBuilder diff --git a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowProperty.java b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowProperty.java index 34c93c967..56c68b771 100644 --- a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowProperty.java +++ b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowProperty.java @@ -37,10 +37,6 @@ public class LiteflowProperty { // FlowExecutor的execute2Future的自定义线程池 private String mainExecutorClass; - // 并行线程执行器class路径 - @Deprecated - private String threadExecutorClass; - // 异步线程最大等待描述 @Deprecated private int whenMaxWaitSeconds; @@ -49,14 +45,6 @@ public class LiteflowProperty { private TimeUnit whenMaxWaitTimeUnit; - // 异步线程池最大线程数 - @Deprecated - private int whenMaxWorkers; - - // 异步线程池最大队列数量 - @Deprecated - private int whenQueueLimit; - // 异步线程池是否隔离 private boolean whenThreadPoolIsolate; @@ -85,16 +73,6 @@ public class LiteflowProperty { // 规则文件/脚本文件变更监听 private boolean enableMonitorFile; - @Deprecated - private String parallelLoopExecutorClass; - - //使用默认并行循环线程池时,最大线程数 - @Deprecated - private int parallelMaxWorkers; - - //使用默认并行循环线程池时,最大队列数 - @Deprecated - private int parallelQueueLimit; // 是否启用组件降级 private boolean fallbackCmpEnable; @@ -159,26 +137,6 @@ public class LiteflowProperty { this.whenMaxWaitSeconds = whenMaxWaitSeconds; } - @Deprecated - public int getWhenMaxWorkers() { - return whenMaxWorkers; - } - - @Deprecated - public void setWhenMaxWorkers(int whenMaxWorkers) { - this.whenMaxWorkers = whenMaxWorkers; - } - - @Deprecated - public int getWhenQueueLimit() { - return whenQueueLimit; - } - - @Deprecated - public void setWhenQueueLimit(int whenQueueLimit) { - this.whenQueueLimit = whenQueueLimit; - } - public ParseModeEnum getParseMode() { return parseMode; } @@ -213,16 +171,6 @@ public class LiteflowProperty { this.printBanner = printBanner; } - @Deprecated - public String getThreadExecutorClass() { - return threadExecutorClass; - } - - @Deprecated - public void setThreadExecutorClass(String threadExecutorClass) { - this.threadExecutorClass = threadExecutorClass; - } - public String getNodeExecutorClass() { return nodeExecutorClass; } @@ -295,36 +243,6 @@ public class LiteflowProperty { this.whenMaxWaitTimeUnit = whenMaxWaitTimeUnit; } - @Deprecated - public String getParallelLoopExecutorClass() { - return parallelLoopExecutorClass; - } - - @Deprecated - public void setParallelLoopExecutorClass(String parallelLoopExecutorClass) { - this.parallelLoopExecutorClass = parallelLoopExecutorClass; - } - - @Deprecated - public int getParallelMaxWorkers() { - return parallelMaxWorkers; - } - - @Deprecated - public void setParallelMaxWorkers(int parallelMaxWorkers) { - this.parallelMaxWorkers = parallelMaxWorkers; - } - - @Deprecated - public int getParallelQueueLimit() { - return parallelQueueLimit; - } - - @Deprecated - public void setParallelQueueLimit(int parallelQueueLimit) { - this.parallelQueueLimit = parallelQueueLimit; - } - public boolean isFallbackCmpEnable() { return fallbackCmpEnable; } diff --git a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowPropertyAutoConfiguration.java b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowPropertyAutoConfiguration.java index d68f5a393..8091dd5e7 100644 --- a/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowPropertyAutoConfiguration.java +++ b/liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowPropertyAutoConfiguration.java @@ -26,12 +26,9 @@ public class LiteflowPropertyAutoConfiguration { liteflowConfig.setRuleSourceExtData(property.getRuleSourceExtData()); liteflowConfig.setRuleSourceExtDataMap(property.getRuleSourceExtDataMap()); liteflowConfig.setSlotSize(property.getSlotSize()); - liteflowConfig.setThreadExecutorClass(property.getThreadExecutorClass()); liteflowConfig.setWhenMaxWaitSeconds(property.getWhenMaxWaitSeconds()); liteflowConfig.setWhenMaxWaitTime(property.getWhenMaxWaitTime()); liteflowConfig.setWhenMaxWaitTimeUnit(property.getWhenMaxWaitTimeUnit()); - liteflowConfig.setWhenMaxWorkers(property.getWhenMaxWorkers()); - liteflowConfig.setWhenQueueLimit(property.getWhenQueueLimit()); liteflowConfig.setWhenThreadPoolIsolate(property.isWhenThreadPoolIsolate()); liteflowConfig.setParseMode(property.getParseMode()); liteflowConfig.setEnable(property.isEnable()); @@ -44,9 +41,6 @@ public class LiteflowPropertyAutoConfiguration { liteflowConfig.setMainExecutorClass(property.getMainExecutorClass()); liteflowConfig.setPrintExecutionLog(property.isPrintExecutionLog()); liteflowConfig.setEnableMonitorFile(property.isEnableMonitorFile()); - liteflowConfig.setParallelMaxWorkers(property.getParallelMaxWorkers()); - liteflowConfig.setParallelQueueLimit(property.getParallelQueueLimit()); - liteflowConfig.setParallelLoopExecutorClass(property.getParallelLoopExecutorClass()); liteflowConfig.setFallbackCmpEnable(property.isFallbackCmpEnable()); liteflowConfig.setFastLoad(property.isFastLoad()); liteflowConfig.setEnableLog(liteflowMonitorProperty.isEnableLog()); diff --git a/liteflow-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/liteflow-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json index ae2c22a44..39b0617a9 100644 --- a/liteflow-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/liteflow-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -61,13 +61,6 @@ "sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty", "defaultValue": "com.yomahub.liteflow.thread.LiteFlowDefaultMainExecutorBuilder" }, - { - "name": "liteflow.thread-executor-class", - "type": "java.lang.String", - "description": "Custom thread pool implement for when executor.", - "sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty", - "defaultValue": "com.yomahub.liteflow.thread.LiteFlowDefaultWhenExecutorBuilder" - }, { "name": "liteflow.when-max-wait-seconds", "type": "java.lang.Integer", @@ -89,20 +82,6 @@ "sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty", "defaultValue": "MILLISECONDS" }, - { - "name": "liteflow.when-max-workers", - "type": "java.lang.Integer", - "description": "Set the async thread pool worker max-size on \" when \" mode.", - "sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty", - "defaultValue": 16 - }, - { - "name": "liteflow.when-queue-limit", - "type": "java.lang.Integer", - "description": "Set the async thread pool queue max-size on \" when \" mode.", - "sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty", - "defaultValue": 512 - }, { "name": "liteflow.when-thread-pool-isolate", "type": "java.lang.Boolean", @@ -194,27 +173,6 @@ "sourceType": "com.yomahub.liteflow.springboot.LiteflowMonitorProperty", "defaultValue": false }, - { - "name": "liteflow.parallel-max-workers", - "type": "java.lang.Integer", - "description": "Set the async thread pool worker max-size on \" parallel-loop \" mode.", - "sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty", - "defaultValue": 16 - }, - { - "name": "liteflow.parallel-queue-limit", - "type": "java.lang.Integer", - "description": "Set the async thread pool queue max-size on \" parallel-loop \" mode.", - "sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty", - "defaultValue": 512 - }, - { - "name": "liteflow.parallel-loop-executor-class", - "type": "java.lang.String", - "description": "Custom thread pool implement for parallel-loop executor.", - "sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty", - "defaultValue": "com.yomahub.liteflow.thread.LiteFlowDefaultParallelLoopExecutorBuilder" - }, { "name": "liteflow.script-setting", "type": "java.util.Map", diff --git a/liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties b/liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties index 5dec76788..6222261dd 100644 --- a/liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties +++ b/liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties @@ -4,11 +4,8 @@ liteflow.slot-size=1024 liteflow.main-executor-works=64 liteflow.main-executor-class=com.yomahub.liteflow.thread.LiteFlowDefaultMainExecutorBuilder liteflow.request-id-generator-class=com.yomahub.liteflow.flow.id.DefaultRequestIdGenerator -liteflow.thread-executor-class=com.yomahub.liteflow.thread.LiteFlowDefaultWhenExecutorBuilder liteflow.when-max-wait-time=15000 liteflow.when-max-wait-time-unit=MILLISECONDS -liteflow.when-max-workers=16 -liteflow.when-queue-limit=512 liteflow.when-thread-pool-isolate=false liteflow.parse-mode=PARSE_ALL_ON_START liteflow.retry-count=0 @@ -18,9 +15,6 @@ liteflow.print-execution-log=true liteflow.fallback-cmp-enable=false liteflow.fast-load=false liteflow.check-node-exists=true -liteflow.parallel-max-workers=16 -liteflow.parallel-queue-limit=512 -liteflow.parallel-loop-executor-class=com.yomahub.liteflow.thread.LiteFlowDefaultParallelLoopExecutorBuilder liteflow.monitor.enable-log=false liteflow.monitor.queue-limit=200 liteflow.monitor.delay=300000 @@ -28,5 +22,5 @@ liteflow.monitor.period=300000 liteflow.enable-monitor-file=false liteflow.global-thread-pool-size=16 liteflow.global-thread-pool-queue-size=512 -liteflow.global-thread-pool-executor-class=comcom.yomahub.liteflow.thread.LiteFlowDefaultGlobalExecutorBuilder +liteflow.global-thread-pool-executor-class=com.yomahub.liteflow.thread.LiteFlowDefaultGlobalExecutorBuilder diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/resources/parallelLoop/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/resources/parallelLoop/application.properties index ebf6a6eda..8552e5441 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/resources/parallelLoop/application.properties +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/resources/parallelLoop/application.properties @@ -1,4 +1,4 @@ liteflow.rule-source=parallelLoop/flow.xml -liteflow.parallel-max-workers = 10 -liteflow.parallel-queue-limit = 1024 -liteflow.parallel-loop-executor-class =com.yomahub.liteflow.test.parallelLoop.CustomThreadExecutor \ No newline at end of file +liteflow.global-thread-pool-size=16 +liteflow.global-thread-pool-queue-size=512 +liteflow.global-thread-pool-executor-class=com.yomahub.liteflow.test.parallelLoop.CustomThreadExecutor \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parallelLoop/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parallelLoop/application.properties index ebf6a6eda..8552e5441 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parallelLoop/application.properties +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/parallelLoop/application.properties @@ -1,4 +1,4 @@ liteflow.rule-source=parallelLoop/flow.xml -liteflow.parallel-max-workers = 10 -liteflow.parallel-queue-limit = 1024 -liteflow.parallel-loop-executor-class =com.yomahub.liteflow.test.parallelLoop.CustomThreadExecutor \ No newline at end of file +liteflow.global-thread-pool-size=16 +liteflow.global-thread-pool-queue-size=512 +liteflow.global-thread-pool-executor-class=com.yomahub.liteflow.test.parallelLoop.CustomThreadExecutor \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/parallelLoop/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/parallelLoop/application.properties index ebf6a6eda..8552e5441 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/parallelLoop/application.properties +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/parallelLoop/application.properties @@ -1,4 +1,4 @@ liteflow.rule-source=parallelLoop/flow.xml -liteflow.parallel-max-workers = 10 -liteflow.parallel-queue-limit = 1024 -liteflow.parallel-loop-executor-class =com.yomahub.liteflow.test.parallelLoop.CustomThreadExecutor \ No newline at end of file +liteflow.global-thread-pool-size=16 +liteflow.global-thread-pool-queue-size=512 +liteflow.global-thread-pool-executor-class=com.yomahub.liteflow.test.parallelLoop.CustomThreadExecutor \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/parallelLoop/application.properties b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/parallelLoop/application.properties index ebf6a6eda..8552e5441 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/parallelLoop/application.properties +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/parallelLoop/application.properties @@ -1,4 +1,4 @@ liteflow.rule-source=parallelLoop/flow.xml -liteflow.parallel-max-workers = 10 -liteflow.parallel-queue-limit = 1024 -liteflow.parallel-loop-executor-class =com.yomahub.liteflow.test.parallelLoop.CustomThreadExecutor \ No newline at end of file +liteflow.global-thread-pool-size=16 +liteflow.global-thread-pool-queue-size=512 +liteflow.global-thread-pool-executor-class=com.yomahub.liteflow.test.parallelLoop.CustomThreadExecutor \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/GlobalThreadPoolELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/GlobalThreadPoolELSpringbootTest.java index 50dad85d9..1b547f22e 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/GlobalThreadPoolELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/GlobalThreadPoolELSpringbootTest.java @@ -1,4 +1,4 @@ -package com.yomahub.liteflow.test.GlobalThreadPool; +package com.yomahub.liteflow.test.chainThreadPool; import cn.hutool.core.collection.ListUtil; import com.yomahub.liteflow.core.FlowExecutor; @@ -39,7 +39,7 @@ public class GlobalThreadPoolELSpringbootTest extends BaseTest { LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); DefaultContext context = response1.getFirstContextBean(); Assertions.assertTrue(response1.isSuccess()); - Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-Global-thead")); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-global-thead")); } /** @@ -50,7 +50,7 @@ public class GlobalThreadPoolELSpringbootTest extends BaseTest { LiteflowResponse response1 = flowExecutor.execute2Resp("chain2", "arg"); DefaultContext context = response1.getFirstContextBean(); Assertions.assertTrue(response1.isSuccess()); - Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-Global-thead")); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-global-thead")); } /** @@ -61,7 +61,7 @@ public class GlobalThreadPoolELSpringbootTest extends BaseTest { LiteflowResponse response1 = flowExecutor.execute2Resp("chain3", "arg"); DefaultContext context = response1.getFirstContextBean(); Assertions.assertTrue(response1.isSuccess()); - Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-Global-thead")); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-global-thead")); } /** @@ -73,7 +73,7 @@ public class GlobalThreadPoolELSpringbootTest extends BaseTest { LiteflowResponse response1 = flowExecutor.execute2Resp("chain4", list); DefaultContext context = response1.getFirstContextBean(); Assertions.assertTrue(response1.isSuccess()); - Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-Global-thead")); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-global-thead")); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java index 6034ba621..82d03185c 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java @@ -16,8 +16,8 @@ public class CustomThreadExecutor1 implements ExecutorBuilder { if (ObjectUtil.isNull(liteflowConfig)) { liteflowConfig = new LiteflowConfig(); } - return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), "customer-when-1-thead-"); + return buildDefaultExecutor(liteflowConfig.getGlobalThreadPoolSize(), liteflowConfig.getGlobalThreadPoolSize(), + liteflowConfig.getQueueLimit(), "customer-when-1-thead-"); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java index 8f9008e0a..9f382f5dc 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java @@ -16,8 +16,8 @@ public class CustomThreadExecutor2 implements ExecutorBuilder { if (ObjectUtil.isNull(liteflowConfig)) { liteflowConfig = new LiteflowConfig(); } - return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), "customer-when-2-thead-"); + return buildDefaultExecutor(liteflowConfig.getGlobalThreadPoolSize(), liteflowConfig.getGlobalThreadPoolSize(), + liteflowConfig.getQueueLimit(), "customer-when-2-thead-"); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java index dc6f63995..e7f9bd244 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java @@ -16,8 +16,8 @@ public class CustomThreadExecutor3 implements ExecutorBuilder { if (ObjectUtil.isNull(liteflowConfig)) { liteflowConfig = new LiteflowConfig(); } - return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), "customer-when-3-thead-"); + return buildDefaultExecutor(liteflowConfig.getGlobalThreadPoolSize(), liteflowConfig.getGlobalThreadPoolSize(), + liteflowConfig.getQueueLimit(), "customer-when-3-thead-"); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELSpringbootTest.java index b186d8f7c..40c58ceb9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELSpringbootTest.java @@ -40,7 +40,7 @@ public class CustomWhenThreadPoolELSpringbootTest extends BaseTest { LiteflowResponse response = flowExecutor.execute2Resp("chain", "arg"); DefaultContext context = response.getFirstContextBean(); Assertions.assertTrue(response.isSuccess()); - Assertions.assertTrue(context.getData("threadName").toString().startsWith("when-thread-1")); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("global-thread-1")); } /** diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/CustomThreadExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/CustomThreadExecutor.java index 72773f38a..4cdd82890 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/CustomThreadExecutor.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/CustomThreadExecutor.java @@ -16,8 +16,8 @@ public class CustomThreadExecutor implements ExecutorBuilder { if (ObjectUtil.isNull(liteflowConfig)) { liteflowConfig = new LiteflowConfig(); } - return buildDefaultExecutor(liteflowConfig.getParallelMaxWorkers(), liteflowConfig.getParallelMaxWorkers(), - liteflowConfig.getParallelQueueLimit(), "customer-loop-thead-"); + return buildDefaultExecutor(liteflowConfig.getGlobalThreadPoolSize(), liteflowConfig.getGlobalThreadPoolSize(), + liteflowConfig.getQueueLimit(), "customer-loop-thead-"); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/flow.el.xml index da5f247c5..502724229 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/flow.el.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/chainThreadPool/flow.el.xml @@ -7,9 +7,7 @@ - FOR(5).parallel(true).DO(THEN(a,f - ) - ); + FOR(5).parallel(true).DO(THEN(a,f)); - FOR(5).parallel(true).DO(THEN(a,f - ) + FOR(5).parallel(true).DO(THEN(a,f) ); diff --git a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/parallelLoop/application.properties b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/parallelLoop/application.properties index ebf6a6eda..8552e5441 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/parallelLoop/application.properties +++ b/liteflow-testcase-el/liteflow-testcase-el-springboot/src/test/resources/parallelLoop/application.properties @@ -1,4 +1,4 @@ liteflow.rule-source=parallelLoop/flow.xml -liteflow.parallel-max-workers = 10 -liteflow.parallel-queue-limit = 1024 -liteflow.parallel-loop-executor-class =com.yomahub.liteflow.test.parallelLoop.CustomThreadExecutor \ No newline at end of file +liteflow.global-thread-pool-size=16 +liteflow.global-thread-pool-queue-size=512 +liteflow.global-thread-pool-executor-class=com.yomahub.liteflow.test.parallelLoop.CustomThreadExecutor \ No newline at end of file From e9e293fdbe4dfaefe96c274245b337a57ed963f5 Mon Sep 17 00:00:00 2001 From: jason <2353220944@qq.com> Date: Mon, 4 Nov 2024 10:44:54 +0800 Subject: [PATCH 8/9] code review --- .../flow/parallel/strategy/ParallelStrategyExecutor.java | 8 ++++---- .../com/yomahub/liteflow/parser/helper/ParserHelper.java | 3 ++- .../java/com/yomahub/liteflow/thread/ExecutorHelper.java | 5 +++++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/strategy/ParallelStrategyExecutor.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/strategy/ParallelStrategyExecutor.java index 42cb958de..2590f40c1 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/strategy/ParallelStrategyExecutor.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/parallel/strategy/ParallelStrategyExecutor.java @@ -127,10 +127,10 @@ public abstract class ParallelStrategyExecutor { protected ExecutorService getWhenExecutorService(WhenCondition whenCondition, Integer slotIndex) { LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); - - // 如果设置了线程池隔离,则每个 when 都会有对应的线程池,这是为了避免多层嵌套时如果线程池数量不够时出现单个线程池死锁。用线程池隔离的方式会更加好 - // 如果 when 没有超多层的嵌套,还是用默认的比较好。 - // 默认设置不隔离。也就是说,默认情况是一个线程池类一个实例,如果什么都不配置,那也就是在 when 的情况下,全局一个线程池。 + //线程池的优先级 condition层级>chain层级>全局体系 + // 1、如果设置了线程池隔离,则每个 when 都会有对应的线程池,这是为了避免多层嵌套时如果线程池数量不够时出现单个线程池死锁。用线程池隔离的方式会更加好 + // 2、如果在chain上自定义线程池,同一个chain下的when+异步线程池共享一个线程池 + // 3、默认全局一个线程池,所有的when+异步共享一个线程池 ExecutorService parallelExecutor; String chainId = DataBus.getSlot(slotIndex).getChainId(); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/helper/ParserHelper.java b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/helper/ParserHelper.java index 128f428cc..98b118aa6 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/parser/helper/ParserHelper.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/parser/helper/ParserHelper.java @@ -344,7 +344,8 @@ public class ParserHelper { e.attributeValue(THREAD_POOL_EXECUTOR_CLASS); LiteFlowChainELBuilder builder = - LiteFlowChainELBuilder.createChain().setChainId(chainId).setNamespace(namespace).setThreadPoolExecutorClass(threadPoolExecutorClass); + LiteFlowChainELBuilder.createChain().setChainId(chainId).setNamespace(namespace) + .setThreadPoolExecutorClass(threadPoolExecutorClass); // 如果有route这个标签,说明是决策表chain // 决策表链路必须有route和body这两个标签 diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java index a14c16fc3..37bd1217f 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java @@ -137,6 +137,11 @@ public class ExecutorHelper { String chainId = DataBus.getSlot(slotIndex).getChainId(); Chain chain = FlowBus.getChain(chainId); + //线程池的优先级 condition层级>chain层级>全局体系 + // 1、如果设置了线程池隔离,则每个 异步 都会有对应的线程池,这是为了避免多层嵌套时如果线程池数量不够时出现单个线程池死锁。用线程池隔离的方式会更加好 + // 2、如果在chain上自定义线程池,同一个chain下的when+异步线程池共享一个线程池 + // 3、默认全局一个线程池,所有的when+异步共享一个线程池 + if (ObjectUtil.isNotEmpty(loopCondition.getThreadPoolExecutorClass())) { //condition层级线程池 parallelExecutor = getExecutorService(loopCondition.getThreadPoolExecutorClass(), From 6c45e80c906681a6fcafba5ec57eb88c67101bfd Mon Sep 17 00:00:00 2001 From: jason <2353220944@qq.com> Date: Mon, 4 Nov 2024 16:19:52 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/LiteflowAutoConfiguration.java | 1 + .../solon/config/LiteflowProperty.java | 15 ++++ .../CustomThreadExecutor1.java | 4 +- .../ChainThreadPoolELSpringbootTest.java | 72 +++++++++++++++++ .../ConditionThreadPoolELSpringbootTest.java | 73 +++++++++++++++++ .../CustomChainThreadExecutor.java | 23 ++++++ .../CustomGlobalThreadExecutor.java | 23 ++++++ .../CustomLoopThreadExecutor.java | 23 ++++++ .../CustomWhenThreadExecutor.java | 23 ++++++ .../GlobalThreadPoolELSpringbootTest.java | 71 ++++++++++++++++ .../test/chainThreadPool/cmp/CmpConfig.java | 81 +++++++++++++++++++ .../CustomThreadExecutor1.java | 4 +- .../CustomThreadExecutor2.java | 4 +- .../CustomThreadExecutor3.java | 4 +- ...enThreadPoolELDeclMultiSpringbootTest.java | 2 +- .../parallelLoop/CustomThreadExecutor.java | 4 +- .../chainThreadPool/application.properties | 1 + .../chainThreadPool/application2.properties | 2 + .../chainThreadPool/application3.properties | 4 + .../resources/chainThreadPool/flow.el.xml | 22 +++++ .../resources/chainThreadPool/flow2.el.xml | 22 +++++ .../resources/chainThreadPool/flow3.el.xml | 19 +++++ .../ChainThreadPoolELSpringbootTest.java | 79 ++++++++++++++++++ .../ConditionThreadPoolELSpringbootTest.java | 79 ++++++++++++++++++ .../CustomChainThreadExecutor.java | 23 ++++++ .../CustomGlobalThreadExecutor.java | 23 ++++++ .../CustomLoopThreadExecutor.java | 23 ++++++ .../CustomWhenThreadExecutor.java | 23 ++++++ .../GlobalThreadPoolELSpringbootTest.java | 79 ++++++++++++++++++ .../test/chainThreadPool/cmp/CmpConfig.java | 81 +++++++++++++++++++ .../CustomThreadExecutor1.java | 4 +- .../CustomThreadExecutor2.java | 4 +- .../CustomThreadExecutor3.java | 4 +- ...enThreadPoolELDeclMultiSpringbootTest.java | 5 +- .../parallelLoop/CustomThreadExecutor.java | 4 +- .../chainThreadPool/application.properties | 1 + .../chainThreadPool/application2.properties | 2 + .../chainThreadPool/application3.properties | 4 + .../resources/chainThreadPool/flow.el.xml | 22 +++++ .../resources/chainThreadPool/flow2.el.xml | 22 +++++ .../resources/chainThreadPool/flow3.el.xml | 19 +++++ .../ChainThreadPoolELSpringbootTest.java | 79 ++++++++++++++++++ .../ConditionThreadPoolELSpringbootTest.java | 79 ++++++++++++++++++ .../CustomChainThreadExecutor.java | 23 ++++++ .../CustomGlobalThreadExecutor.java | 23 ++++++ .../CustomLoopThreadExecutor.java | 23 ++++++ .../CustomWhenThreadExecutor.java | 23 ++++++ .../GlobalThreadPoolELSpringbootTest.java | 79 ++++++++++++++++++ .../test/chainThreadPool/cmp/ACmp.java | 24 ++++++ .../test/chainThreadPool/cmp/BCmp.java | 27 +++++++ .../test/chainThreadPool/cmp/CmpConfig.java | 81 +++++++++++++++++++ .../test/chainThreadPool/cmp/DCmp.java | 32 ++++++++ .../test/chainThreadPool/cmp/FCmp.java | 19 +++++ .../test/chainThreadPool/cmp/ICmp.java | 27 +++++++ .../test/chainThreadPool/cmp/ITCmp.java | 23 ++++++ .../test/chainThreadPool/cmp/WCmp.java | 27 +++++++ .../test/chainThreadPool/cmp/ZCmp.java | 25 ++++++ .../CustomThreadExecutor1.java | 4 +- .../CustomThreadExecutor2.java | 4 +- .../CustomThreadExecutor3.java | 4 +- ...tomWhenThreadPoolELDeclSpringbootTest.java | 5 +- .../parallelLoop/CustomThreadExecutor.java | 4 +- .../chainThreadPool/application.properties | 1 + .../chainThreadPool/application2.properties | 2 + .../chainThreadPool/application3.properties | 4 + .../resources/chainThreadPool/flow.el.xml | 22 +++++ .../resources/chainThreadPool/flow2.el.xml | 22 +++++ .../resources/chainThreadPool/flow3.el.xml | 19 +++++ .../ChainThreadPoolELSpringbootTest.java | 76 +++++++++++++++++ .../ConditionThreadPoolELSpringbootTest.java | 76 +++++++++++++++++ .../CustomChainThreadExecutor.java | 23 ++++++ .../CustomGlobalThreadExecutor.java | 23 ++++++ .../CustomLoopThreadExecutor.java | 23 ++++++ .../CustomWhenThreadExecutor.java | 23 ++++++ .../GlobalThreadPoolELSpringbootTest.java | 80 ++++++++++++++++++ .../test/chainThreadPool/cmp/ACmp.java | 21 +++++ .../test/chainThreadPool/cmp/BCmp.java | 23 ++++++ .../test/chainThreadPool/cmp/DCmp.java | 28 +++++++ .../test/chainThreadPool/cmp/FCmp.java | 24 ++++++ .../test/chainThreadPool/cmp/ICmp.java | 23 ++++++ .../test/chainThreadPool/cmp/ITCmp.java | 15 ++++ .../test/chainThreadPool/cmp/WCmp.java | 23 ++++++ .../test/chainThreadPool/cmp/ZCmp.java | 20 +++++ .../test/config/LiteflowConfigTest1.java | 4 +- .../CustomThreadExecutor1.java | 4 +- .../CustomThreadExecutor2.java | 4 +- .../CustomThreadExecutor3.java | 4 +- .../CustomWhenThreadPoolTest.java | 2 +- .../parallelLoop/CustomThreadExecutor.java | 4 +- .../test/parallelLoop/ParallelLoopTest.java | 7 +- .../chainThreadPool/application.properties | 1 + .../chainThreadPool/application2.properties | 2 + .../chainThreadPool/application3.properties | 4 + .../resources/chainThreadPool/flow.el.xml | 33 ++++++++ .../resources/chainThreadPool/flow2.el.xml | 32 ++++++++ .../resources/chainThreadPool/flow3.el.xml | 29 +++++++ .../liteflow-testcase-el-solon/pom.xml | 4 + .../ChainThreadPoolELSpringbootTest.java | 72 +++++++++++++++++ .../ConditionThreadPoolELSpringbootTest.java | 73 +++++++++++++++++ .../CustomChainThreadExecutor.java | 23 ++++++ .../CustomGlobalThreadExecutor.java | 23 ++++++ .../CustomLoopThreadExecutor.java | 23 ++++++ .../CustomWhenThreadExecutor.java | 23 ++++++ .../GlobalThreadPoolELSpringbootTest.java | 71 ++++++++++++++++ .../test/chainThreadPool/cmp/ACmp.java | 22 +++++ .../test/chainThreadPool/cmp/BCmp.java | 25 ++++++ .../test/chainThreadPool/cmp/DCmp.java | 30 +++++++ .../test/chainThreadPool/cmp/FCmp.java | 25 ++++++ .../test/chainThreadPool/cmp/ICmp.java | 25 ++++++ .../test/chainThreadPool/cmp/ITCmp.java | 17 ++++ .../test/chainThreadPool/cmp/WCmp.java | 25 ++++++ .../test/chainThreadPool/cmp/ZCmp.java | 21 +++++ .../CustomThreadExecutor1.java | 4 +- .../CustomThreadExecutor2.java | 4 +- .../CustomThreadExecutor3.java | 4 +- .../CustomWhenThreadPoolELSpringbootTest.java | 3 +- .../parallelLoop/CustomThreadExecutor.java | 4 +- .../chainThreadPool/application.properties | 1 + .../chainThreadPool/application2.properties | 2 + .../chainThreadPool/application3.properties | 4 + .../resources/chainThreadPool/flow.el.xml | 22 +++++ .../resources/chainThreadPool/flow2.el.xml | 22 +++++ .../resources/chainThreadPool/flow3.el.xml | 19 +++++ .../ChainThreadPoolELSpringbootTest.java | 76 +++++++++++++++++ .../ConditionThreadPoolELSpringbootTest.java | 76 +++++++++++++++++ .../CustomChainThreadExecutor.java | 23 ++++++ .../CustomGlobalThreadExecutor.java | 23 ++++++ .../CustomLoopThreadExecutor.java | 23 ++++++ .../CustomWhenThreadExecutor.java | 23 ++++++ .../GlobalThreadPoolELSpringbootTest.java | 73 +++++++++++++++++ .../test/chainThreadPool/cmp/ACmp.java | 22 +++++ .../test/chainThreadPool/cmp/BCmp.java | 25 ++++++ .../test/chainThreadPool/cmp/DCmp.java | 30 +++++++ .../test/chainThreadPool/cmp/FCmp.java | 25 ++++++ .../test/chainThreadPool/cmp/ICmp.java | 25 ++++++ .../test/chainThreadPool/cmp/ITCmp.java | 17 ++++ .../test/chainThreadPool/cmp/WCmp.java | 25 ++++++ .../test/chainThreadPool/cmp/ZCmp.java | 21 +++++ .../config/LiteflowConfigELSpringTest.java | 3 +- .../CustomThreadExecutor1.java | 4 +- .../CustomThreadExecutor2.java | 4 +- .../CustomThreadExecutor3.java | 4 +- .../CustomWhenThreadPoolELSpringTest.java | 2 +- .../parallelLoop/CustomThreadExecutor.java | 4 +- .../resources/chainThreadPool/application.xml | 23 ++++++ .../chainThreadPool/application2.xml | 24 ++++++ .../chainThreadPool/application3.xml | 27 +++++++ .../resources/chainThreadPool/flow.el.xml | 22 +++++ .../resources/chainThreadPool/flow2.el.xml | 22 +++++ .../resources/chainThreadPool/flow3.el.xml | 19 +++++ .../resources/parallelLoop/application.xml | 7 +- .../resources/useTTLInWhen/application.xml | 2 +- 152 files changed, 3527 insertions(+), 72 deletions(-) create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ChainThreadPoolELSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ConditionThreadPoolELSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomChainThreadExecutor.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomGlobalThreadExecutor.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomLoopThreadExecutor.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomWhenThreadExecutor.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/GlobalThreadPoolELSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/CmpConfig.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/resources/chainThreadPool/application.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/resources/chainThreadPool/application2.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/resources/chainThreadPool/application3.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/resources/chainThreadPool/flow.el.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/resources/chainThreadPool/flow2.el.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/resources/chainThreadPool/flow3.el.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ChainThreadPoolELSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ConditionThreadPoolELSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomChainThreadExecutor.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomGlobalThreadExecutor.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomLoopThreadExecutor.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomWhenThreadExecutor.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/GlobalThreadPoolELSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/CmpConfig.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/chainThreadPool/application.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/chainThreadPool/application2.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/chainThreadPool/application3.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/chainThreadPool/flow.el.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/chainThreadPool/flow2.el.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/chainThreadPool/flow3.el.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ChainThreadPoolELSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ConditionThreadPoolELSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomChainThreadExecutor.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomGlobalThreadExecutor.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomLoopThreadExecutor.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomWhenThreadExecutor.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/GlobalThreadPoolELSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ACmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/BCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/CmpConfig.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/DCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/FCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ICmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ITCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/WCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ZCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/chainThreadPool/application.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/chainThreadPool/application2.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/chainThreadPool/application3.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/chainThreadPool/flow.el.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/chainThreadPool/flow2.el.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/chainThreadPool/flow3.el.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ChainThreadPoolELSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ConditionThreadPoolELSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomChainThreadExecutor.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomGlobalThreadExecutor.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomLoopThreadExecutor.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomWhenThreadExecutor.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/GlobalThreadPoolELSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ACmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/BCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/DCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/FCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ICmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ITCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/WCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ZCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/chainThreadPool/application.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/chainThreadPool/application2.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/chainThreadPool/application3.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/chainThreadPool/flow.el.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/chainThreadPool/flow2.el.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/chainThreadPool/flow3.el.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ChainThreadPoolELSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ConditionThreadPoolELSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomChainThreadExecutor.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomGlobalThreadExecutor.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomLoopThreadExecutor.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomWhenThreadExecutor.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/GlobalThreadPoolELSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ACmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/BCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/DCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/FCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ICmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ITCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/WCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ZCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/chainThreadPool/application.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/chainThreadPool/application2.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/chainThreadPool/application3.properties create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/chainThreadPool/flow.el.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/chainThreadPool/flow2.el.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/chainThreadPool/flow3.el.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ChainThreadPoolELSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ConditionThreadPoolELSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomChainThreadExecutor.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomGlobalThreadExecutor.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomLoopThreadExecutor.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomWhenThreadExecutor.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/GlobalThreadPoolELSpringbootTest.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ACmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/BCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/DCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/FCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ICmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ITCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/WCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ZCmp.java create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/chainThreadPool/application.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/chainThreadPool/application2.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/chainThreadPool/application3.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/chainThreadPool/flow.el.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/chainThreadPool/flow2.el.xml create mode 100644 liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/chainThreadPool/flow3.el.xml diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowAutoConfiguration.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowAutoConfiguration.java index 572015c80..3f719ca49 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowAutoConfiguration.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowAutoConfiguration.java @@ -48,6 +48,7 @@ public class LiteflowAutoConfiguration { liteflowConfig.setGlobalThreadPoolExecutorClass(property.getGlobalThreadPoolExecutorClass()); liteflowConfig.setGlobalThreadPoolSize(property.getGlobalThreadPoolSize()); liteflowConfig.setGlobalThreadPoolQueueSize(property.getGlobalThreadPoolQueueSize()); + liteflowConfig.setWhenThreadPoolIsolate(property.getWhenThreadPoolIsolate()); return liteflowConfig; } diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowProperty.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowProperty.java index 5472ddda5..23f83550c 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowProperty.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/config/LiteflowProperty.java @@ -94,6 +94,9 @@ public class LiteflowProperty { //全局线程池最大队列数 private Integer globalThreadPoolQueueSize; + // 异步线程池是否隔离 + private Boolean whenThreadPoolIsolate; + public boolean isEnable() { return enable; } @@ -314,4 +317,16 @@ public class LiteflowProperty { public void setGlobalThreadPoolExecutorClass(String globalThreadPoolExecutorClass) { this.globalThreadPoolExecutorClass = globalThreadPoolExecutorClass; } + + public Boolean getWhenThreadPoolIsolate() { + if (ObjectUtil.isNull(whenThreadPoolIsolate)) { + return Boolean.FALSE; + } else { + return whenThreadPoolIsolate; + } + } + + public void setWhenThreadPoolIsolate(Boolean whenThreadPoolIsolate) { + this.whenThreadPoolIsolate = whenThreadPoolIsolate; + } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-builder/src/test/java/com/yomahub/liteflow/test/builder/customTreadExecutor/CustomThreadExecutor1.java b/liteflow-testcase-el/liteflow-testcase-el-builder/src/test/java/com/yomahub/liteflow/test/builder/customTreadExecutor/CustomThreadExecutor1.java index 4a4d95409..0ae22130b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-builder/src/test/java/com/yomahub/liteflow/test/builder/customTreadExecutor/CustomThreadExecutor1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-builder/src/test/java/com/yomahub/liteflow/test/builder/customTreadExecutor/CustomThreadExecutor1.java @@ -22,8 +22,8 @@ public class CustomThreadExecutor1 implements ExecutorBuilder { if (ObjectUtil.isNull(liteflowConfig)) { liteflowConfig = new LiteflowConfig(); } - return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), "customer-when-1-thead-"); + return buildDefaultExecutor(liteflowConfig.getGlobalThreadPoolSize(), liteflowConfig.getGlobalThreadPoolSize(), + liteflowConfig.getGlobalThreadPoolQueueSize(), "customer-when-1-thead-"); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ChainThreadPoolELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ChainThreadPoolELSpringbootTest.java new file mode 100644 index 000000000..1aff2de34 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ChainThreadPoolELSpringbootTest.java @@ -0,0 +1,72 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.collection.ListUtil; +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 org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.noear.solon.annotation.Import; +import org.noear.solon.annotation.Inject; +import org.noear.solon.test.SolonTest; + +import java.util.List; + +/** + * springboot环境下chain线程池隔离测试 + */ +@SolonTest +@Import(profiles = "classpath:/chainThreadPool/application.properties") +public class ChainThreadPoolELSpringbootTest extends BaseTest { + + + @Inject + private FlowExecutor flowExecutor; + + /** + * 测试WHEN上全局线程池和chain线程池隔离-优先以chain上为准 + */ + @Test + public void testChainThreadPool() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + } + + /** + * 测试FOR上全局线程池和chain线程池隔离-优先以chain上为准 + */ + @Test + public void testChainThreadPool2() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + } + + /** + * 测试WHILE上全局线程池和chain线程池隔离-优先以chain上为准 + */ + @Test + public void testChainThreadPool3() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + } + + /** + * 测试ITERATOR上全局线程池和chain线程池隔离-优先以chain上为准 + */ + @Test + public void testChainThreadPool4() { + List list = ListUtil.toList("1", "2", "3", "4", "5"); + LiteflowResponse response1 = flowExecutor.execute2Resp("chain4", list); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ConditionThreadPoolELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ConditionThreadPoolELSpringbootTest.java new file mode 100644 index 000000000..4648e661c --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ConditionThreadPoolELSpringbootTest.java @@ -0,0 +1,73 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.collection.ListUtil; +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 org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.noear.solon.annotation.Import; +import org.noear.solon.annotation.Inject; +import org.noear.solon.test.SolonTest; + +import java.util.List; + +/** + * springboot环境下chain线程池隔离测试 + */ + +@SolonTest +@Import(profiles = "classpath:/chainThreadPool/application2.properties") +public class ConditionThreadPoolELSpringbootTest extends BaseTest { + + + @Inject + private FlowExecutor flowExecutor; + + /** + * 测试WEHN上condition线程池和chain线程池隔离-优先以WHEN上为准 + */ + @Test + public void testConditionThreadPool() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-when-thead")); + } + + /** + * 测试FOR上condition线程池和chain线程池隔离-优先以FOR上为准 + */ + @Test + public void testConditionThreadPool2() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-loop-thead")); + } + + /** + * 测试WHILE上condition线程池和chain线程池隔离-优先以WHILE上为准 + */ + @Test + public void testConditionThreadPool3() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-loop-thead")); + } + + /** + * 测试ITERATOR上condition线程池和chain线程池隔离-优先以ITERATOR上为准 + */ + @Test + public void testConditionThreadPool4() { + List list = ListUtil.toList("1", "2", "3", "4", "5"); + LiteflowResponse response1 = flowExecutor.execute2Resp("chain4", list); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-loop-thead")); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomChainThreadExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomChainThreadExecutor.java new file mode 100644 index 000000000..cd366a9e2 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomChainThreadExecutor.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomChainThreadExecutor implements ExecutorBuilder { + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(16, 16, + 512, "customer-chain-thead"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomGlobalThreadExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomGlobalThreadExecutor.java new file mode 100644 index 000000000..260f1d97e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomGlobalThreadExecutor.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomGlobalThreadExecutor implements ExecutorBuilder { + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(16, 16, + 512, "customer-global-thead"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomLoopThreadExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomLoopThreadExecutor.java new file mode 100644 index 000000000..647addafb --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomLoopThreadExecutor.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomLoopThreadExecutor implements ExecutorBuilder { + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(16, 16, + 512, "customer-loop-thead"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomWhenThreadExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomWhenThreadExecutor.java new file mode 100644 index 000000000..b7186db65 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomWhenThreadExecutor.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomWhenThreadExecutor implements ExecutorBuilder { + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(16, 16, + 512, "customer-when-thead"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/GlobalThreadPoolELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/GlobalThreadPoolELSpringbootTest.java new file mode 100644 index 000000000..0dd3caf59 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/GlobalThreadPoolELSpringbootTest.java @@ -0,0 +1,71 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.collection.ListUtil; +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 org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.noear.solon.annotation.Import; +import org.noear.solon.annotation.Inject; +import org.noear.solon.test.SolonTest; + +import java.util.List; + +/** + * springboot环境下Global线程池隔离测试 + */ +@SolonTest +@Import(profiles = "classpath:/chainThreadPool/application3.properties") +public class GlobalThreadPoolELSpringbootTest extends BaseTest { + + @Inject + private FlowExecutor flowExecutor; + + /** + * 测试WHEN上全局线程池 + */ + @Test + public void testGlobalThreadPool() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-global-thead")); + } + + /** + * 测试FOR上全局线程池 + */ + @Test + public void testGlobalThreadPool2() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-global-thead")); + } + + /** + * 测试WHILE上全局线程池 + */ + @Test + public void testGlobalThreadPool3() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-global-thead")); + } + + /** + * 测试ITERATOR上全局线程池 + */ + @Test + public void testGlobalThreadPool4() { + List list = ListUtil.toList("1", "2", "3", "4", "5"); + LiteflowResponse response1 = flowExecutor.execute2Resp("chain4", list); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-global-thead")); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/CmpConfig.java new file mode 100644 index 000000000..8b169a14f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/CmpConfig.java @@ -0,0 +1,81 @@ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.enums.NodeTypeEnum; +import com.yomahub.liteflow.slot.DefaultContext; + +import java.util.Iterator; +import java.util.List; + +@LiteflowComponent +public class CmpConfig { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { + + System.out.println("ACmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("BCmp executed!"); + } + + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "d") + public void processD(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + String key = "test"; + if (context.hasData(key)) { + int count = context.getData(key); + context.setData(key, ++count); + } else { + context.setData(key, 1); + } + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "f") + public void processE(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("FCmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "i") + public void processI(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("ICmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_ITERATOR, nodeId = "it", nodeType = NodeTypeEnum.ITERATOR) + public Iterator processIT(NodeComponent bindCmp) { + List list = bindCmp.getRequestData(); + return list.iterator(); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "w") + public void processW(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("WCmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN, nodeId = "z", nodeType = NodeTypeEnum.BOOLEAN) + public boolean processZ(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + String key = "test"; + if (context.hasData(key)) { + int count = context.getData("test"); + return count < 5; + } else { + return true; + } + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java index 6034ba621..e8236072a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java @@ -16,8 +16,8 @@ public class CustomThreadExecutor1 implements ExecutorBuilder { if (ObjectUtil.isNull(liteflowConfig)) { liteflowConfig = new LiteflowConfig(); } - return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), "customer-when-1-thead-"); + return buildDefaultExecutor(liteflowConfig.getGlobalThreadPoolSize(), liteflowConfig.getGlobalThreadPoolSize(), + liteflowConfig.getGlobalThreadPoolQueueSize(), "customer-when-1-thead-"); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java index 8f9008e0a..d22667183 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java @@ -16,8 +16,8 @@ public class CustomThreadExecutor2 implements ExecutorBuilder { if (ObjectUtil.isNull(liteflowConfig)) { liteflowConfig = new LiteflowConfig(); } - return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), "customer-when-2-thead-"); + return buildDefaultExecutor(liteflowConfig.getGlobalThreadPoolSize(), liteflowConfig.getGlobalThreadPoolSize(), + liteflowConfig.getGlobalThreadPoolQueueSize(), "customer-when-2-thead-"); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java index dc6f63995..e630075e3 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java @@ -16,8 +16,8 @@ public class CustomThreadExecutor3 implements ExecutorBuilder { if (ObjectUtil.isNull(liteflowConfig)) { liteflowConfig = new LiteflowConfig(); } - return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), "customer-when-3-thead-"); + return buildDefaultExecutor(liteflowConfig.getGlobalThreadPoolSize(), liteflowConfig.getGlobalThreadPoolSize(), + liteflowConfig.getGlobalThreadPoolQueueSize(), "customer-when-3-thead-"); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELDeclMultiSpringbootTest.java index 98b15408d..5951f1137 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELDeclMultiSpringbootTest.java @@ -35,7 +35,7 @@ public class CustomWhenThreadPoolELDeclMultiSpringbootTest extends BaseTest { LiteflowResponse response = flowExecutor.execute2Resp("chain", "arg"); DefaultContext context = response.getFirstContextBean(); Assertions.assertTrue(response.isSuccess()); - Assertions.assertTrue(context.getData("threadName").toString().startsWith("when-thread-1")); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("global-thread-1")); } /** diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/parallelLoop/CustomThreadExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/parallelLoop/CustomThreadExecutor.java index 72773f38a..338be1c31 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/parallelLoop/CustomThreadExecutor.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/java/com/yomahub/liteflow/test/parallelLoop/CustomThreadExecutor.java @@ -16,8 +16,8 @@ public class CustomThreadExecutor implements ExecutorBuilder { if (ObjectUtil.isNull(liteflowConfig)) { liteflowConfig = new LiteflowConfig(); } - return buildDefaultExecutor(liteflowConfig.getParallelMaxWorkers(), liteflowConfig.getParallelMaxWorkers(), - liteflowConfig.getParallelQueueLimit(), "customer-loop-thead-"); + return buildDefaultExecutor(liteflowConfig.getGlobalThreadPoolSize(), liteflowConfig.getGlobalThreadPoolSize(), + liteflowConfig.getGlobalThreadPoolQueueSize(), "customer-loop-thead-"); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/resources/chainThreadPool/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/resources/chainThreadPool/application.properties new file mode 100644 index 000000000..aad6bd9de --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/resources/chainThreadPool/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=chainThreadPool/flow.el.xml diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/resources/chainThreadPool/application2.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/resources/chainThreadPool/application2.properties new file mode 100644 index 000000000..ecac47dd6 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/resources/chainThreadPool/application2.properties @@ -0,0 +1,2 @@ +liteflow.rule-source=chainThreadPool/flow2.el.xml +liteflow.when-thread-pool-isolate=true diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/resources/chainThreadPool/application3.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/resources/chainThreadPool/application3.properties new file mode 100644 index 000000000..d7ec64e9a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/resources/chainThreadPool/application3.properties @@ -0,0 +1,4 @@ +liteflow.rule-source=chainThreadPool/flow3.el.xml +liteflow.global-thread-pool-size=16 +liteflow.global-thread-pool-queue-size=512 +liteflow.global-thread-pool-executor-class=com.yomahub.liteflow.test.chainThreadPool.CustomGlobalThreadExecutor \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/resources/chainThreadPool/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/resources/chainThreadPool/flow.el.xml new file mode 100644 index 000000000..502724229 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/resources/chainThreadPool/flow.el.xml @@ -0,0 +1,22 @@ + + + + WHEN(a,b); + + + + FOR(5).parallel(true).DO(THEN(a,f)); + + + + WHILE(z).parallel(true).DO(THEN(w,d)); + + + + ITERATOR(it).parallel(true).DO(THEN(a,i)); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/resources/chainThreadPool/flow2.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/resources/chainThreadPool/flow2.el.xml new file mode 100644 index 000000000..741e264ba --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/resources/chainThreadPool/flow2.el.xml @@ -0,0 +1,22 @@ + + + + WHEN(a,b).threadPool("com.yomahub.liteflow.test.chainThreadPool.CustomWhenThreadExecutor"); + + + + FOR(5).parallel(true).DO(THEN(a,f)).threadPool("com.yomahub.liteflow.test.chainThreadPool.CustomLoopThreadExecutor"); + + + + WHILE(z).parallel(true).DO(THEN(w,d)).threadPool("com.yomahub.liteflow.test.chainThreadPool.CustomLoopThreadExecutor"); + + + + ITERATOR(it).parallel(true).DO(THEN(a,i)).threadPool("com.yomahub.liteflow.test.chainThreadPool.CustomLoopThreadExecutor"); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/resources/chainThreadPool/flow3.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/resources/chainThreadPool/flow3.el.xml new file mode 100644 index 000000000..a544de8c5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-solon/src/test/resources/chainThreadPool/flow3.el.xml @@ -0,0 +1,19 @@ + + + + WHEN(a,b); + + + + FOR(5).parallel(true).DO(THEN(a,f) + ); + + + + WHILE(z).parallel(true).DO(THEN(w,d)); + + + + ITERATOR(it).parallel(true).DO(THEN(a,i)); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ChainThreadPoolELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ChainThreadPoolELSpringbootTest.java new file mode 100644 index 000000000..03ddb6ce5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ChainThreadPoolELSpringbootTest.java @@ -0,0 +1,79 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.collection.ListUtil; +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 org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +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 javax.annotation.Resource; +import java.util.List; + +/** + * springboot环境下chain线程池隔离测试 + */ +@TestPropertySource(value = "classpath:/chainThreadPool/application.properties") +@SpringBootTest(classes = ChainThreadPoolELSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.chainThreadPool.cmp"}) +public class ChainThreadPoolELSpringbootTest extends BaseTest { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Resource + private FlowExecutor flowExecutor; + + /** + * 测试WHEN上全局线程池和chain线程池隔离-优先以chain上为准 + */ + @Test + public void testChainThreadPool() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + } + + /** + * 测试FOR上全局线程池和chain线程池隔离-优先以chain上为准 + */ + @Test + public void testChainThreadPool2() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + } + + /** + * 测试WHILE上全局线程池和chain线程池隔离-优先以chain上为准 + */ + @Test + public void testChainThreadPool3() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + } + + /** + * 测试ITERATOR上全局线程池和chain线程池隔离-优先以chain上为准 + */ + @Test + public void testChainThreadPool4() { + List list = ListUtil.toList("1", "2", "3", "4", "5"); + LiteflowResponse response1 = flowExecutor.execute2Resp("chain4", list); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ConditionThreadPoolELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ConditionThreadPoolELSpringbootTest.java new file mode 100644 index 000000000..7f7870dbc --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ConditionThreadPoolELSpringbootTest.java @@ -0,0 +1,79 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.collection.ListUtil; +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 org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +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 javax.annotation.Resource; +import java.util.List; + +/** + * springboot环境下chain线程池隔离测试 + */ +@TestPropertySource(value = "classpath:/chainThreadPool/application2.properties") +@SpringBootTest(classes = ConditionThreadPoolELSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.chainThreadPool.cmp"}) +public class ConditionThreadPoolELSpringbootTest extends BaseTest { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Resource + private FlowExecutor flowExecutor; + + /** + * 测试WEHN上condition线程池和chain线程池隔离-优先以WHEN上为准 + */ + @Test + public void testConditionThreadPool() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-when-thead")); + } + + /** + * 测试FOR上condition线程池和chain线程池隔离-优先以FOR上为准 + */ + @Test + public void testConditionThreadPool2() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-loop-thead")); + } + + /** + * 测试WHILE上condition线程池和chain线程池隔离-优先以WHILE上为准 + */ + @Test + public void testConditionThreadPool3() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-loop-thead")); + } + + /** + * 测试ITERATOR上condition线程池和chain线程池隔离-优先以ITERATOR上为准 + */ + @Test + public void testConditionThreadPool4() { + List list = ListUtil.toList("1", "2", "3", "4", "5"); + LiteflowResponse response1 = flowExecutor.execute2Resp("chain4", list); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-loop-thead")); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomChainThreadExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomChainThreadExecutor.java new file mode 100644 index 000000000..cd366a9e2 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomChainThreadExecutor.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomChainThreadExecutor implements ExecutorBuilder { + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(16, 16, + 512, "customer-chain-thead"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomGlobalThreadExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomGlobalThreadExecutor.java new file mode 100644 index 000000000..260f1d97e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomGlobalThreadExecutor.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomGlobalThreadExecutor implements ExecutorBuilder { + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(16, 16, + 512, "customer-global-thead"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomLoopThreadExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomLoopThreadExecutor.java new file mode 100644 index 000000000..647addafb --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomLoopThreadExecutor.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomLoopThreadExecutor implements ExecutorBuilder { + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(16, 16, + 512, "customer-loop-thead"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomWhenThreadExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomWhenThreadExecutor.java new file mode 100644 index 000000000..b7186db65 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomWhenThreadExecutor.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomWhenThreadExecutor implements ExecutorBuilder { + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(16, 16, + 512, "customer-when-thead"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/GlobalThreadPoolELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/GlobalThreadPoolELSpringbootTest.java new file mode 100644 index 000000000..8873255eb --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/GlobalThreadPoolELSpringbootTest.java @@ -0,0 +1,79 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.collection.ListUtil; +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 org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +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 javax.annotation.Resource; +import java.util.List; + +/** + * springboot环境下Global线程池隔离测试 + */ +@TestPropertySource(value = "classpath:/chainThreadPool/application3.properties") +@SpringBootTest(classes = GlobalThreadPoolELSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.chainThreadPool.cmp"}) +public class GlobalThreadPoolELSpringbootTest extends BaseTest { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Resource + private FlowExecutor flowExecutor; + + /** + * 测试WHEN上全局线程池 + */ + @Test + public void testGlobalThreadPool() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-global-thead")); + } + + /** + * 测试FOR上全局线程池 + */ + @Test + public void testGlobalThreadPool2() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-global-thead")); + } + + /** + * 测试WHILE上全局线程池 + */ + @Test + public void testGlobalThreadPool3() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-global-thead")); + } + + /** + * 测试ITERATOR上全局线程池 + */ + @Test + public void testGlobalThreadPool4() { + List list = ListUtil.toList("1", "2", "3", "4", "5"); + LiteflowResponse response1 = flowExecutor.execute2Resp("chain4", list); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-global-thead")); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/CmpConfig.java new file mode 100644 index 000000000..fca056baf --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/CmpConfig.java @@ -0,0 +1,81 @@ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.enums.NodeTypeEnum; +import com.yomahub.liteflow.slot.DefaultContext; + +import java.util.Iterator; +import java.util.List; + +@LiteflowComponent +public class CmpConfig { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { + + System.out.println("ACmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("BCmp executed!"); + } + + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "d") + public void processD(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + String key = "test"; + if (context.hasData(key)) { + int count = context.getData(key); + context.setData(key, ++count); + } else { + context.setData(key, 1); + } + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "f") + public void processE(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("FCmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "i") + public void processI(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("ICmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_ITERATOR, nodeId = "it", nodeType = NodeTypeEnum.ITERATOR) + public Iterator processIT(NodeComponent bindCmp) { + List list = bindCmp.getRequestData(); + return list.iterator(); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "w") + public void processW(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("WCmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN, nodeId = "z", nodeType = NodeTypeEnum.BOOLEAN) + public boolean processZ(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + String key = "test"; + if (context.hasData(key)) { + int count = context.getData("test"); + return count < 5; + } else { + return true; + } + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java index 6034ba621..37d441487 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java @@ -16,8 +16,8 @@ public class CustomThreadExecutor1 implements ExecutorBuilder { if (ObjectUtil.isNull(liteflowConfig)) { liteflowConfig = new LiteflowConfig(); } - return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), "customer-when-1-thead-"); + return buildDefaultExecutor(liteflowConfig.getGlobalThreadPoolSize(), liteflowConfig.getGlobalThreadPoolSize(), + liteflowConfig.getGlobalThreadPoolQueueSize(), "customer-when-1-thead-"); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java index 8f9008e0a..87323ad2a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java @@ -16,8 +16,8 @@ public class CustomThreadExecutor2 implements ExecutorBuilder { if (ObjectUtil.isNull(liteflowConfig)) { liteflowConfig = new LiteflowConfig(); } - return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), "customer-when-2-thead-"); + return buildDefaultExecutor(liteflowConfig.getGlobalThreadPoolSize(), liteflowConfig.getGlobalThreadPoolSize(), + liteflowConfig.getGlobalThreadPoolQueueSize(), "customer-when-2-thead-"); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java index dc6f63995..0b322bb20 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java @@ -16,8 +16,8 @@ public class CustomThreadExecutor3 implements ExecutorBuilder { if (ObjectUtil.isNull(liteflowConfig)) { liteflowConfig = new LiteflowConfig(); } - return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), "customer-when-3-thead-"); + return buildDefaultExecutor(liteflowConfig.getGlobalThreadPoolSize(), liteflowConfig.getGlobalThreadPoolSize(), + liteflowConfig.getGlobalThreadPoolQueueSize(), "customer-when-3-thead-"); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELDeclMultiSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELDeclMultiSpringbootTest.java index 119166dd4..6d14a32ed 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELDeclMultiSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELDeclMultiSpringbootTest.java @@ -7,14 +7,13 @@ 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.test.context.junit.jupiter.SpringExtension; import org.slf4j.Logger; import org.slf4j.LoggerFactory; 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.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import javax.annotation.Resource; @@ -44,7 +43,7 @@ public class CustomWhenThreadPoolELDeclMultiSpringbootTest extends BaseTest { LiteflowResponse response = flowExecutor.execute2Resp("chain", "arg"); DefaultContext context = response.getFirstContextBean(); Assertions.assertTrue(response.isSuccess()); - Assertions.assertTrue(context.getData("threadName").toString().startsWith("when-thread-1")); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("global-thread-1")); } /** diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/CustomThreadExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/CustomThreadExecutor.java index 72773f38a..f82cf346b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/CustomThreadExecutor.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/CustomThreadExecutor.java @@ -16,8 +16,8 @@ public class CustomThreadExecutor implements ExecutorBuilder { if (ObjectUtil.isNull(liteflowConfig)) { liteflowConfig = new LiteflowConfig(); } - return buildDefaultExecutor(liteflowConfig.getParallelMaxWorkers(), liteflowConfig.getParallelMaxWorkers(), - liteflowConfig.getParallelQueueLimit(), "customer-loop-thead-"); + return buildDefaultExecutor(liteflowConfig.getGlobalThreadPoolSize(), liteflowConfig.getGlobalThreadPoolSize(), + liteflowConfig.getGlobalThreadPoolQueueSize(), "customer-loop-thead-"); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/chainThreadPool/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/chainThreadPool/application.properties new file mode 100644 index 000000000..aad6bd9de --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/chainThreadPool/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=chainThreadPool/flow.el.xml diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/chainThreadPool/application2.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/chainThreadPool/application2.properties new file mode 100644 index 000000000..ecac47dd6 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/chainThreadPool/application2.properties @@ -0,0 +1,2 @@ +liteflow.rule-source=chainThreadPool/flow2.el.xml +liteflow.when-thread-pool-isolate=true diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/chainThreadPool/application3.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/chainThreadPool/application3.properties new file mode 100644 index 000000000..d7ec64e9a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/chainThreadPool/application3.properties @@ -0,0 +1,4 @@ +liteflow.rule-source=chainThreadPool/flow3.el.xml +liteflow.global-thread-pool-size=16 +liteflow.global-thread-pool-queue-size=512 +liteflow.global-thread-pool-executor-class=com.yomahub.liteflow.test.chainThreadPool.CustomGlobalThreadExecutor \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/chainThreadPool/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/chainThreadPool/flow.el.xml new file mode 100644 index 000000000..502724229 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/chainThreadPool/flow.el.xml @@ -0,0 +1,22 @@ + + + + WHEN(a,b); + + + + FOR(5).parallel(true).DO(THEN(a,f)); + + + + WHILE(z).parallel(true).DO(THEN(w,d)); + + + + ITERATOR(it).parallel(true).DO(THEN(a,i)); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/chainThreadPool/flow2.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/chainThreadPool/flow2.el.xml new file mode 100644 index 000000000..741e264ba --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/chainThreadPool/flow2.el.xml @@ -0,0 +1,22 @@ + + + + WHEN(a,b).threadPool("com.yomahub.liteflow.test.chainThreadPool.CustomWhenThreadExecutor"); + + + + FOR(5).parallel(true).DO(THEN(a,f)).threadPool("com.yomahub.liteflow.test.chainThreadPool.CustomLoopThreadExecutor"); + + + + WHILE(z).parallel(true).DO(THEN(w,d)).threadPool("com.yomahub.liteflow.test.chainThreadPool.CustomLoopThreadExecutor"); + + + + ITERATOR(it).parallel(true).DO(THEN(a,i)).threadPool("com.yomahub.liteflow.test.chainThreadPool.CustomLoopThreadExecutor"); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/chainThreadPool/flow3.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/chainThreadPool/flow3.el.xml new file mode 100644 index 000000000..a544de8c5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/resources/chainThreadPool/flow3.el.xml @@ -0,0 +1,19 @@ + + + + WHEN(a,b); + + + + FOR(5).parallel(true).DO(THEN(a,f) + ); + + + + WHILE(z).parallel(true).DO(THEN(w,d)); + + + + ITERATOR(it).parallel(true).DO(THEN(a,i)); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ChainThreadPoolELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ChainThreadPoolELSpringbootTest.java new file mode 100644 index 000000000..03ddb6ce5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ChainThreadPoolELSpringbootTest.java @@ -0,0 +1,79 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.collection.ListUtil; +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 org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +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 javax.annotation.Resource; +import java.util.List; + +/** + * springboot环境下chain线程池隔离测试 + */ +@TestPropertySource(value = "classpath:/chainThreadPool/application.properties") +@SpringBootTest(classes = ChainThreadPoolELSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.chainThreadPool.cmp"}) +public class ChainThreadPoolELSpringbootTest extends BaseTest { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Resource + private FlowExecutor flowExecutor; + + /** + * 测试WHEN上全局线程池和chain线程池隔离-优先以chain上为准 + */ + @Test + public void testChainThreadPool() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + } + + /** + * 测试FOR上全局线程池和chain线程池隔离-优先以chain上为准 + */ + @Test + public void testChainThreadPool2() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + } + + /** + * 测试WHILE上全局线程池和chain线程池隔离-优先以chain上为准 + */ + @Test + public void testChainThreadPool3() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + } + + /** + * 测试ITERATOR上全局线程池和chain线程池隔离-优先以chain上为准 + */ + @Test + public void testChainThreadPool4() { + List list = ListUtil.toList("1", "2", "3", "4", "5"); + LiteflowResponse response1 = flowExecutor.execute2Resp("chain4", list); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ConditionThreadPoolELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ConditionThreadPoolELSpringbootTest.java new file mode 100644 index 000000000..7f7870dbc --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ConditionThreadPoolELSpringbootTest.java @@ -0,0 +1,79 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.collection.ListUtil; +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 org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +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 javax.annotation.Resource; +import java.util.List; + +/** + * springboot环境下chain线程池隔离测试 + */ +@TestPropertySource(value = "classpath:/chainThreadPool/application2.properties") +@SpringBootTest(classes = ConditionThreadPoolELSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.chainThreadPool.cmp"}) +public class ConditionThreadPoolELSpringbootTest extends BaseTest { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Resource + private FlowExecutor flowExecutor; + + /** + * 测试WEHN上condition线程池和chain线程池隔离-优先以WHEN上为准 + */ + @Test + public void testConditionThreadPool() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-when-thead")); + } + + /** + * 测试FOR上condition线程池和chain线程池隔离-优先以FOR上为准 + */ + @Test + public void testConditionThreadPool2() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-loop-thead")); + } + + /** + * 测试WHILE上condition线程池和chain线程池隔离-优先以WHILE上为准 + */ + @Test + public void testConditionThreadPool3() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-loop-thead")); + } + + /** + * 测试ITERATOR上condition线程池和chain线程池隔离-优先以ITERATOR上为准 + */ + @Test + public void testConditionThreadPool4() { + List list = ListUtil.toList("1", "2", "3", "4", "5"); + LiteflowResponse response1 = flowExecutor.execute2Resp("chain4", list); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-loop-thead")); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomChainThreadExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomChainThreadExecutor.java new file mode 100644 index 000000000..cd366a9e2 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomChainThreadExecutor.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomChainThreadExecutor implements ExecutorBuilder { + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(16, 16, + 512, "customer-chain-thead"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomGlobalThreadExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomGlobalThreadExecutor.java new file mode 100644 index 000000000..260f1d97e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomGlobalThreadExecutor.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomGlobalThreadExecutor implements ExecutorBuilder { + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(16, 16, + 512, "customer-global-thead"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomLoopThreadExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomLoopThreadExecutor.java new file mode 100644 index 000000000..647addafb --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomLoopThreadExecutor.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomLoopThreadExecutor implements ExecutorBuilder { + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(16, 16, + 512, "customer-loop-thead"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomWhenThreadExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomWhenThreadExecutor.java new file mode 100644 index 000000000..b7186db65 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomWhenThreadExecutor.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomWhenThreadExecutor implements ExecutorBuilder { + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(16, 16, + 512, "customer-when-thead"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/GlobalThreadPoolELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/GlobalThreadPoolELSpringbootTest.java new file mode 100644 index 000000000..8873255eb --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/GlobalThreadPoolELSpringbootTest.java @@ -0,0 +1,79 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.collection.ListUtil; +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 org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +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 javax.annotation.Resource; +import java.util.List; + +/** + * springboot环境下Global线程池隔离测试 + */ +@TestPropertySource(value = "classpath:/chainThreadPool/application3.properties") +@SpringBootTest(classes = GlobalThreadPoolELSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.chainThreadPool.cmp"}) +public class GlobalThreadPoolELSpringbootTest extends BaseTest { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Resource + private FlowExecutor flowExecutor; + + /** + * 测试WHEN上全局线程池 + */ + @Test + public void testGlobalThreadPool() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-global-thead")); + } + + /** + * 测试FOR上全局线程池 + */ + @Test + public void testGlobalThreadPool2() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-global-thead")); + } + + /** + * 测试WHILE上全局线程池 + */ + @Test + public void testGlobalThreadPool3() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-global-thead")); + } + + /** + * 测试ITERATOR上全局线程池 + */ + @Test + public void testGlobalThreadPool4() { + List list = ListUtil.toList("1", "2", "3", "4", "5"); + LiteflowResponse response1 = flowExecutor.execute2Resp("chain4", list); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-global-thead")); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ACmp.java new file mode 100644 index 000000000..369996ec3 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ACmp.java @@ -0,0 +1,24 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +public class ACmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/BCmp.java new file mode 100644 index 000000000..1f83d390d --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/BCmp.java @@ -0,0 +1,27 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("b") +public class BCmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/CmpConfig.java new file mode 100644 index 000000000..fca056baf --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/CmpConfig.java @@ -0,0 +1,81 @@ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.enums.NodeTypeEnum; +import com.yomahub.liteflow.slot.DefaultContext; + +import java.util.Iterator; +import java.util.List; + +@LiteflowComponent +public class CmpConfig { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a") + public void processA(NodeComponent bindCmp) { + + System.out.println("ACmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "b") + public void processB(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("BCmp executed!"); + } + + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "d") + public void processD(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + String key = "test"; + if (context.hasData(key)) { + int count = context.getData(key); + context.setData(key, ++count); + } else { + context.setData(key, 1); + } + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "f") + public void processE(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("FCmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "i") + public void processI(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("ICmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_ITERATOR, nodeId = "it", nodeType = NodeTypeEnum.ITERATOR) + public Iterator processIT(NodeComponent bindCmp) { + List list = bindCmp.getRequestData(); + return list.iterator(); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "w") + public void processW(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("WCmp executed!"); + } + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN, nodeId = "z", nodeType = NodeTypeEnum.BOOLEAN) + public boolean processZ(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + String key = "test"; + if (context.hasData(key)) { + int count = context.getData("test"); + return count < 5; + } else { + return true; + } + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/DCmp.java new file mode 100644 index 000000000..4dda80d7e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/DCmp.java @@ -0,0 +1,32 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("d") +public class DCmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + String key = "test"; + if (context.hasData(key)) { + int count = context.getData(key); + context.setData(key, ++count); + } else { + context.setData(key, 1); + } + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/FCmp.java new file mode 100644 index 000000000..f3da88e1b --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/FCmp.java @@ -0,0 +1,19 @@ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("f") +public class FCmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("FCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ICmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ICmp.java new file mode 100644 index 000000000..171ea5ed5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ICmp.java @@ -0,0 +1,27 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("i") +public class ICmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("ICmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ITCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ITCmp.java new file mode 100644 index 000000000..ed743ed46 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ITCmp.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.enums.NodeTypeEnum; +import org.springframework.stereotype.Component; + +import java.util.Iterator; +import java.util.List; + +@Component("it") +@LiteflowCmpDefine(NodeTypeEnum.ITERATOR) +public class ITCmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS_ITERATOR) + public Iterator processIterator(NodeComponent bindCmp) throws Exception { + List list = bindCmp.getRequestData(); + return list.iterator(); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/WCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/WCmp.java new file mode 100644 index 000000000..393b39220 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/WCmp.java @@ -0,0 +1,27 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("w") +public class WCmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + DefaultContext context = bindCmp.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("WCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ZCmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ZCmp.java new file mode 100644 index 000000000..0b2138195 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ZCmp.java @@ -0,0 +1,25 @@ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.enums.NodeTypeEnum; +import com.yomahub.liteflow.slot.DefaultContext; + +@LiteflowComponent("z") +public class ZCmp { + + @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN, nodeType = NodeTypeEnum.BOOLEAN) + public boolean processWhile(NodeComponent bindCmp) throws Exception { + DefaultContext context = bindCmp.getFirstContextBean(); + String key = "test"; + if (context.hasData(key)) { + int count = context.getData("test"); + return count < 5; + } else { + return true; + } + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java index 6034ba621..4108c2927 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java @@ -16,8 +16,8 @@ public class CustomThreadExecutor1 implements ExecutorBuilder { if (ObjectUtil.isNull(liteflowConfig)) { liteflowConfig = new LiteflowConfig(); } - return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), "customer-when-1-thead-"); + return buildDefaultExecutor(liteflowConfig.getGlobalThreadPoolSize(), liteflowConfig.getGlobalThreadPoolSize(), + liteflowConfig.getGlobalThreadPoolSize(), "customer-when-1-thead-"); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java index 8f9008e0a..87323ad2a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java @@ -16,8 +16,8 @@ public class CustomThreadExecutor2 implements ExecutorBuilder { if (ObjectUtil.isNull(liteflowConfig)) { liteflowConfig = new LiteflowConfig(); } - return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), "customer-when-2-thead-"); + return buildDefaultExecutor(liteflowConfig.getGlobalThreadPoolSize(), liteflowConfig.getGlobalThreadPoolSize(), + liteflowConfig.getGlobalThreadPoolQueueSize(), "customer-when-2-thead-"); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java index dc6f63995..0b322bb20 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java @@ -16,8 +16,8 @@ public class CustomThreadExecutor3 implements ExecutorBuilder { if (ObjectUtil.isNull(liteflowConfig)) { liteflowConfig = new LiteflowConfig(); } - return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), "customer-when-3-thead-"); + return buildDefaultExecutor(liteflowConfig.getGlobalThreadPoolSize(), liteflowConfig.getGlobalThreadPoolSize(), + liteflowConfig.getGlobalThreadPoolQueueSize(), "customer-when-3-thead-"); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELDeclSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELDeclSpringbootTest.java index 9ff391c87..e3f590c19 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELDeclSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELDeclSpringbootTest.java @@ -7,14 +7,13 @@ 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.test.context.junit.jupiter.SpringExtension; import org.slf4j.Logger; import org.slf4j.LoggerFactory; 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.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import javax.annotation.Resource; @@ -44,7 +43,7 @@ public class CustomWhenThreadPoolELDeclSpringbootTest extends BaseTest { LiteflowResponse response = flowExecutor.execute2Resp("chain", "arg"); DefaultContext context = response.getFirstContextBean(); Assertions.assertTrue(response.isSuccess()); - Assertions.assertTrue(context.getData("threadName").toString().startsWith("when-thread-1")); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("global-thread-1")); } /** diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/CustomThreadExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/CustomThreadExecutor.java index 72773f38a..f82cf346b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/CustomThreadExecutor.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/parallelLoop/CustomThreadExecutor.java @@ -16,8 +16,8 @@ public class CustomThreadExecutor implements ExecutorBuilder { if (ObjectUtil.isNull(liteflowConfig)) { liteflowConfig = new LiteflowConfig(); } - return buildDefaultExecutor(liteflowConfig.getParallelMaxWorkers(), liteflowConfig.getParallelMaxWorkers(), - liteflowConfig.getParallelQueueLimit(), "customer-loop-thead-"); + return buildDefaultExecutor(liteflowConfig.getGlobalThreadPoolSize(), liteflowConfig.getGlobalThreadPoolSize(), + liteflowConfig.getGlobalThreadPoolQueueSize(), "customer-loop-thead-"); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/chainThreadPool/application.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/chainThreadPool/application.properties new file mode 100644 index 000000000..aad6bd9de --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/chainThreadPool/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=chainThreadPool/flow.el.xml diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/chainThreadPool/application2.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/chainThreadPool/application2.properties new file mode 100644 index 000000000..ecac47dd6 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/chainThreadPool/application2.properties @@ -0,0 +1,2 @@ +liteflow.rule-source=chainThreadPool/flow2.el.xml +liteflow.when-thread-pool-isolate=true diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/chainThreadPool/application3.properties b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/chainThreadPool/application3.properties new file mode 100644 index 000000000..d7ec64e9a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/chainThreadPool/application3.properties @@ -0,0 +1,4 @@ +liteflow.rule-source=chainThreadPool/flow3.el.xml +liteflow.global-thread-pool-size=16 +liteflow.global-thread-pool-queue-size=512 +liteflow.global-thread-pool-executor-class=com.yomahub.liteflow.test.chainThreadPool.CustomGlobalThreadExecutor \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/chainThreadPool/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/chainThreadPool/flow.el.xml new file mode 100644 index 000000000..502724229 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/chainThreadPool/flow.el.xml @@ -0,0 +1,22 @@ + + + + WHEN(a,b); + + + + FOR(5).parallel(true).DO(THEN(a,f)); + + + + WHILE(z).parallel(true).DO(THEN(w,d)); + + + + ITERATOR(it).parallel(true).DO(THEN(a,i)); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/chainThreadPool/flow2.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/chainThreadPool/flow2.el.xml new file mode 100644 index 000000000..741e264ba --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/chainThreadPool/flow2.el.xml @@ -0,0 +1,22 @@ + + + + WHEN(a,b).threadPool("com.yomahub.liteflow.test.chainThreadPool.CustomWhenThreadExecutor"); + + + + FOR(5).parallel(true).DO(THEN(a,f)).threadPool("com.yomahub.liteflow.test.chainThreadPool.CustomLoopThreadExecutor"); + + + + WHILE(z).parallel(true).DO(THEN(w,d)).threadPool("com.yomahub.liteflow.test.chainThreadPool.CustomLoopThreadExecutor"); + + + + ITERATOR(it).parallel(true).DO(THEN(a,i)).threadPool("com.yomahub.liteflow.test.chainThreadPool.CustomLoopThreadExecutor"); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/chainThreadPool/flow3.el.xml b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/chainThreadPool/flow3.el.xml new file mode 100644 index 000000000..a544de8c5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/resources/chainThreadPool/flow3.el.xml @@ -0,0 +1,19 @@ + + + + WHEN(a,b); + + + + FOR(5).parallel(true).DO(THEN(a,f) + ); + + + + WHILE(z).parallel(true).DO(THEN(w,d)); + + + + ITERATOR(it).parallel(true).DO(THEN(a,i)); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ChainThreadPoolELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ChainThreadPoolELSpringbootTest.java new file mode 100644 index 000000000..41b9a324f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ChainThreadPoolELSpringbootTest.java @@ -0,0 +1,76 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.collection.ListUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.core.FlowExecutorHolder; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import java.util.List; + +/** + * springboot环境下chain线程池隔离测试 + */ + +public class ChainThreadPoolELSpringbootTest extends BaseTest { + + private static FlowExecutor flowExecutor; + + @BeforeAll + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("chainThreadPool/flow.el.xml"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } + + /** + * 测试WHEN上全局线程池和chain线程池隔离-优先以chain上为准 + */ + @Test + public void testChainThreadPool() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + } + + /** + * 测试FOR上全局线程池和chain线程池隔离-优先以chain上为准 + */ + @Test + public void testChainThreadPool2() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + } + + /** + * 测试WHILE上全局线程池和chain线程池隔离-优先以chain上为准 + */ + @Test + public void testChainThreadPool3() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + } + + /** + * 测试ITERATOR上全局线程池和chain线程池隔离-优先以chain上为准 + */ + @Test + public void testChainThreadPool4() { + List list = ListUtil.toList("1", "2", "3", "4", "5"); + LiteflowResponse response1 = flowExecutor.execute2Resp("chain4", list); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ConditionThreadPoolELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ConditionThreadPoolELSpringbootTest.java new file mode 100644 index 000000000..aeea77f7a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ConditionThreadPoolELSpringbootTest.java @@ -0,0 +1,76 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.collection.ListUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.core.FlowExecutorHolder; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import java.util.List; + +/** + * springboot环境下chain线程池隔离测试 + */ +public class ConditionThreadPoolELSpringbootTest extends BaseTest { + + private static FlowExecutor flowExecutor; + + @BeforeAll + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("chainThreadPool/flow2.el.xml"); + config.setWhenThreadPoolIsolate(true); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } + + /** + * 测试WEHN上condition线程池和chain线程池隔离-优先以WHEN上为准 + */ + @Test + public void testConditionThreadPool() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-when-thead")); + } + + /** + * 测试FOR上condition线程池和chain线程池隔离-优先以FOR上为准 + */ + @Test + public void testConditionThreadPool2() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-loop-thead")); + } + + /** + * 测试WHILE上condition线程池和chain线程池隔离-优先以WHILE上为准 + */ + @Test + public void testConditionThreadPool3() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-loop-thead")); + } + + /** + * 测试ITERATOR上condition线程池和chain线程池隔离-优先以ITERATOR上为准 + */ + @Test + public void testConditionThreadPool4() { + List list = ListUtil.toList("1", "2", "3", "4", "5"); + LiteflowResponse response1 = flowExecutor.execute2Resp("chain4", list); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-loop-thead")); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomChainThreadExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomChainThreadExecutor.java new file mode 100644 index 000000000..cd366a9e2 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomChainThreadExecutor.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomChainThreadExecutor implements ExecutorBuilder { + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(16, 16, + 512, "customer-chain-thead"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomGlobalThreadExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomGlobalThreadExecutor.java new file mode 100644 index 000000000..260f1d97e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomGlobalThreadExecutor.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomGlobalThreadExecutor implements ExecutorBuilder { + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(16, 16, + 512, "customer-global-thead"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomLoopThreadExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomLoopThreadExecutor.java new file mode 100644 index 000000000..647addafb --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomLoopThreadExecutor.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomLoopThreadExecutor implements ExecutorBuilder { + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(16, 16, + 512, "customer-loop-thead"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomWhenThreadExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomWhenThreadExecutor.java new file mode 100644 index 000000000..b7186db65 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomWhenThreadExecutor.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomWhenThreadExecutor implements ExecutorBuilder { + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(16, 16, + 512, "customer-when-thead"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/GlobalThreadPoolELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/GlobalThreadPoolELSpringbootTest.java new file mode 100644 index 000000000..22f36992c --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/GlobalThreadPoolELSpringbootTest.java @@ -0,0 +1,80 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.collection.ListUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.core.FlowExecutorHolder; +import com.yomahub.liteflow.flow.LiteflowResponse; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.slot.DefaultContext; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import java.util.List; + +/** + * springboot环境下Global线程池隔离测试 + */ + +public class GlobalThreadPoolELSpringbootTest extends BaseTest { + + + private static FlowExecutor flowExecutor; + + @BeforeAll + public static void init() { + LiteflowConfig config = new LiteflowConfig(); + config.setRuleSource("chainThreadPool/flow3.el.xml"); + config.setGlobalThreadPoolSize(10); + config.setGlobalThreadPoolQueueSize(1024); + config.setGlobalThreadPoolExecutorClass("com.yomahub.liteflow.test.chainThreadPool.CustomGlobalThreadExecutor"); + flowExecutor = FlowExecutorHolder.loadInstance(config); + } + + /** + * 测试WHEN上全局线程池 + */ + @Test + public void testGlobalThreadPool() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-global-thead")); + } + + /** + * 测试FOR上全局线程池 + */ + @Test + public void testGlobalThreadPool2() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-global-thead")); + } + + /** + * 测试WHILE上全局线程池 + */ + @Test + public void testGlobalThreadPool3() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-global-thead")); + } + + /** + * 测试ITERATOR上全局线程池 + */ + @Test + public void testGlobalThreadPool4() { + List list = ListUtil.toList("1", "2", "3", "4", "5"); + LiteflowResponse response1 = flowExecutor.execute2Resp("chain4", list); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-global-thead")); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ACmp.java new file mode 100644 index 000000000..e795c9a30 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ACmp.java @@ -0,0 +1,21 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.core.NodeComponent; + + +public class ACmp extends NodeComponent { + + @Override + public void process() { + System.out.println("ACmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/BCmp.java new file mode 100644 index 000000000..aa16ef55a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/BCmp.java @@ -0,0 +1,23 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; + +public class BCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/DCmp.java new file mode 100644 index 000000000..be50f26cb --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/DCmp.java @@ -0,0 +1,28 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; + +public class DCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + String key = "test"; + if (context.hasData(key)) { + int count = context.getData(key); + context.setData(key, ++count); + } else { + context.setData(key, 1); + } + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/FCmp.java new file mode 100644 index 000000000..735645127 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/FCmp.java @@ -0,0 +1,24 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; + + +public class FCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("FCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ICmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ICmp.java new file mode 100644 index 000000000..b14d0a09f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ICmp.java @@ -0,0 +1,23 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; + +public class ICmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("ICmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ITCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ITCmp.java new file mode 100644 index 000000000..d1f74a1da --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ITCmp.java @@ -0,0 +1,15 @@ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.core.NodeIteratorComponent; + +import java.util.Iterator; +import java.util.List; + +public class ITCmp extends NodeIteratorComponent { + + @Override + public Iterator processIterator() throws Exception { + List list = this.getRequestData(); + return list.iterator(); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/WCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/WCmp.java new file mode 100644 index 000000000..541762286 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/WCmp.java @@ -0,0 +1,23 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; + +public class WCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("WCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ZCmp.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ZCmp.java new file mode 100644 index 000000000..482aacac8 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ZCmp.java @@ -0,0 +1,20 @@ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.core.NodeBooleanComponent; +import com.yomahub.liteflow.slot.DefaultContext; + + +public class ZCmp extends NodeBooleanComponent { + + @Override + public boolean processBoolean() throws Exception { + DefaultContext context = this.getFirstContextBean(); + String key = "test"; + if (context.hasData(key)) { + int count = context.getData("test"); + return count < 5; + } else { + return true; + } + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/config/LiteflowConfigTest1.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/config/LiteflowConfigTest1.java index cd8d00808..2b2b2a48d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/config/LiteflowConfigTest1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/config/LiteflowConfigTest1.java @@ -42,8 +42,8 @@ public class LiteflowConfigTest1 extends BaseTest { Assertions.assertEquals(300000L, config.getDelay().longValue()); Assertions.assertEquals(300000L, config.getPeriod().longValue()); Assertions.assertFalse(config.getEnableLog()); - Assertions.assertEquals(16, config.getWhenMaxWorkers().longValue()); - Assertions.assertEquals(512, config.getWhenQueueLimit().longValue()); + Assertions.assertEquals(16, config.getGlobalThreadPoolSize().longValue()); + Assertions.assertEquals(512, config.getGlobalThreadPoolQueueSize().longValue()); Assertions.assertEquals(ParseModeEnum.PARSE_ALL_ON_START, config.getParseMode()); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java index 6034ba621..37d441487 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java @@ -16,8 +16,8 @@ public class CustomThreadExecutor1 implements ExecutorBuilder { if (ObjectUtil.isNull(liteflowConfig)) { liteflowConfig = new LiteflowConfig(); } - return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), "customer-when-1-thead-"); + return buildDefaultExecutor(liteflowConfig.getGlobalThreadPoolSize(), liteflowConfig.getGlobalThreadPoolSize(), + liteflowConfig.getGlobalThreadPoolQueueSize(), "customer-when-1-thead-"); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java index 8f9008e0a..87323ad2a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java @@ -16,8 +16,8 @@ public class CustomThreadExecutor2 implements ExecutorBuilder { if (ObjectUtil.isNull(liteflowConfig)) { liteflowConfig = new LiteflowConfig(); } - return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), "customer-when-2-thead-"); + return buildDefaultExecutor(liteflowConfig.getGlobalThreadPoolSize(), liteflowConfig.getGlobalThreadPoolSize(), + liteflowConfig.getGlobalThreadPoolQueueSize(), "customer-when-2-thead-"); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java index dc6f63995..0b322bb20 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java @@ -16,8 +16,8 @@ public class CustomThreadExecutor3 implements ExecutorBuilder { if (ObjectUtil.isNull(liteflowConfig)) { liteflowConfig = new LiteflowConfig(); } - return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), "customer-when-3-thead-"); + return buildDefaultExecutor(liteflowConfig.getGlobalThreadPoolSize(), liteflowConfig.getGlobalThreadPoolSize(), + liteflowConfig.getGlobalThreadPoolQueueSize(), "customer-when-3-thead-"); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolTest.java index 126389e58..35583c62d 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolTest.java @@ -35,7 +35,7 @@ public class CustomWhenThreadPoolTest extends BaseTest { LiteflowResponse response = flowExecutor.execute2Resp("chain", "arg"); DefaultContext context = response.getFirstContextBean(); Assertions.assertTrue(response.isSuccess()); - Assertions.assertTrue(context.getData("threadName").toString().startsWith("when-thread-1")); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("global-thread-1")); } /** diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parallelLoop/CustomThreadExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parallelLoop/CustomThreadExecutor.java index 72773f38a..f82cf346b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parallelLoop/CustomThreadExecutor.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parallelLoop/CustomThreadExecutor.java @@ -16,8 +16,8 @@ public class CustomThreadExecutor implements ExecutorBuilder { if (ObjectUtil.isNull(liteflowConfig)) { liteflowConfig = new LiteflowConfig(); } - return buildDefaultExecutor(liteflowConfig.getParallelMaxWorkers(), liteflowConfig.getParallelMaxWorkers(), - liteflowConfig.getParallelQueueLimit(), "customer-loop-thead-"); + return buildDefaultExecutor(liteflowConfig.getGlobalThreadPoolSize(), liteflowConfig.getGlobalThreadPoolSize(), + liteflowConfig.getGlobalThreadPoolQueueSize(), "customer-loop-thead-"); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parallelLoop/ParallelLoopTest.java b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parallelLoop/ParallelLoopTest.java index c299608fa..35e7dd7ea 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parallelLoop/ParallelLoopTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/java/com/yomahub/liteflow/test/parallelLoop/ParallelLoopTest.java @@ -12,7 +12,6 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; - import java.util.List; import java.util.regex.Pattern; @@ -31,9 +30,9 @@ public class ParallelLoopTest extends BaseTest { public static void init() { LiteflowConfig config = new LiteflowConfig(); config.setRuleSource("parallelLoop/flow.xml"); - config.setParallelMaxWorkers(10); - config.setParallelQueueLimit(1024); - config.setParallelLoopExecutorClass("com.yomahub.liteflow.test.parallelLoop.CustomThreadExecutor"); + config.setGlobalThreadPoolSize(10); + config.setGlobalThreadPoolQueueSize(1024); + config.setGlobalThreadPoolExecutorClass("com.yomahub.liteflow.test.parallelLoop.CustomThreadExecutor"); flowExecutor = FlowExecutorHolder.loadInstance(config); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/chainThreadPool/application.properties b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/chainThreadPool/application.properties new file mode 100644 index 000000000..aad6bd9de --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/chainThreadPool/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=chainThreadPool/flow.el.xml diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/chainThreadPool/application2.properties b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/chainThreadPool/application2.properties new file mode 100644 index 000000000..ecac47dd6 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/chainThreadPool/application2.properties @@ -0,0 +1,2 @@ +liteflow.rule-source=chainThreadPool/flow2.el.xml +liteflow.when-thread-pool-isolate=true diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/chainThreadPool/application3.properties b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/chainThreadPool/application3.properties new file mode 100644 index 000000000..d7ec64e9a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/chainThreadPool/application3.properties @@ -0,0 +1,4 @@ +liteflow.rule-source=chainThreadPool/flow3.el.xml +liteflow.global-thread-pool-size=16 +liteflow.global-thread-pool-queue-size=512 +liteflow.global-thread-pool-executor-class=com.yomahub.liteflow.test.chainThreadPool.CustomGlobalThreadExecutor \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/chainThreadPool/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/chainThreadPool/flow.el.xml new file mode 100644 index 000000000..b7db70a69 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/chainThreadPool/flow.el.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + WHEN(a,b); + + + + FOR(5).parallel(true).DO(THEN(a,f)); + + + + WHILE(z).parallel(true).DO(THEN(w,d)); + + + + ITERATOR(it).parallel(true).DO(THEN(a,i)); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/chainThreadPool/flow2.el.xml b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/chainThreadPool/flow2.el.xml new file mode 100644 index 000000000..2ffe4e1d4 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/chainThreadPool/flow2.el.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + WHEN(a,b).threadPool("com.yomahub.liteflow.test.chainThreadPool.CustomWhenThreadExecutor"); + + + + FOR(5).parallel(true).DO(THEN(a,f)).threadPool("com.yomahub.liteflow.test.chainThreadPool.CustomLoopThreadExecutor"); + + + + WHILE(z).parallel(true).DO(THEN(w,d)).threadPool("com.yomahub.liteflow.test.chainThreadPool.CustomLoopThreadExecutor"); + + + + ITERATOR(it).parallel(true).DO(THEN(a,i)).threadPool("com.yomahub.liteflow.test.chainThreadPool.CustomLoopThreadExecutor"); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/chainThreadPool/flow3.el.xml b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/chainThreadPool/flow3.el.xml new file mode 100644 index 000000000..9f81bfb60 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-nospring/src/test/resources/chainThreadPool/flow3.el.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + WHEN(a,b); + + + + FOR(5).parallel(true).DO(THEN(a,f) + ); + + + + WHILE(z).parallel(true).DO(THEN(w,d)); + + + + ITERATOR(it).parallel(true).DO(THEN(a,i)); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/pom.xml b/liteflow-testcase-el/liteflow-testcase-el-solon/pom.xml index 7c5699159..438a1bd1b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/pom.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/pom.xml @@ -66,5 +66,9 @@ logback-classic 1.2.11 + + org.springframework + spring-test + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ChainThreadPoolELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ChainThreadPoolELSpringbootTest.java new file mode 100644 index 000000000..1aff2de34 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ChainThreadPoolELSpringbootTest.java @@ -0,0 +1,72 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.collection.ListUtil; +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 org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.noear.solon.annotation.Import; +import org.noear.solon.annotation.Inject; +import org.noear.solon.test.SolonTest; + +import java.util.List; + +/** + * springboot环境下chain线程池隔离测试 + */ +@SolonTest +@Import(profiles = "classpath:/chainThreadPool/application.properties") +public class ChainThreadPoolELSpringbootTest extends BaseTest { + + + @Inject + private FlowExecutor flowExecutor; + + /** + * 测试WHEN上全局线程池和chain线程池隔离-优先以chain上为准 + */ + @Test + public void testChainThreadPool() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + } + + /** + * 测试FOR上全局线程池和chain线程池隔离-优先以chain上为准 + */ + @Test + public void testChainThreadPool2() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + } + + /** + * 测试WHILE上全局线程池和chain线程池隔离-优先以chain上为准 + */ + @Test + public void testChainThreadPool3() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + } + + /** + * 测试ITERATOR上全局线程池和chain线程池隔离-优先以chain上为准 + */ + @Test + public void testChainThreadPool4() { + List list = ListUtil.toList("1", "2", "3", "4", "5"); + LiteflowResponse response1 = flowExecutor.execute2Resp("chain4", list); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ConditionThreadPoolELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ConditionThreadPoolELSpringbootTest.java new file mode 100644 index 000000000..4648e661c --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ConditionThreadPoolELSpringbootTest.java @@ -0,0 +1,73 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.collection.ListUtil; +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 org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.noear.solon.annotation.Import; +import org.noear.solon.annotation.Inject; +import org.noear.solon.test.SolonTest; + +import java.util.List; + +/** + * springboot环境下chain线程池隔离测试 + */ + +@SolonTest +@Import(profiles = "classpath:/chainThreadPool/application2.properties") +public class ConditionThreadPoolELSpringbootTest extends BaseTest { + + + @Inject + private FlowExecutor flowExecutor; + + /** + * 测试WEHN上condition线程池和chain线程池隔离-优先以WHEN上为准 + */ + @Test + public void testConditionThreadPool() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-when-thead")); + } + + /** + * 测试FOR上condition线程池和chain线程池隔离-优先以FOR上为准 + */ + @Test + public void testConditionThreadPool2() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-loop-thead")); + } + + /** + * 测试WHILE上condition线程池和chain线程池隔离-优先以WHILE上为准 + */ + @Test + public void testConditionThreadPool3() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-loop-thead")); + } + + /** + * 测试ITERATOR上condition线程池和chain线程池隔离-优先以ITERATOR上为准 + */ + @Test + public void testConditionThreadPool4() { + List list = ListUtil.toList("1", "2", "3", "4", "5"); + LiteflowResponse response1 = flowExecutor.execute2Resp("chain4", list); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-loop-thead")); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomChainThreadExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomChainThreadExecutor.java new file mode 100644 index 000000000..cd366a9e2 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomChainThreadExecutor.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomChainThreadExecutor implements ExecutorBuilder { + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(16, 16, + 512, "customer-chain-thead"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomGlobalThreadExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomGlobalThreadExecutor.java new file mode 100644 index 000000000..260f1d97e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomGlobalThreadExecutor.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomGlobalThreadExecutor implements ExecutorBuilder { + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(16, 16, + 512, "customer-global-thead"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomLoopThreadExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomLoopThreadExecutor.java new file mode 100644 index 000000000..647addafb --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomLoopThreadExecutor.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomLoopThreadExecutor implements ExecutorBuilder { + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(16, 16, + 512, "customer-loop-thead"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomWhenThreadExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomWhenThreadExecutor.java new file mode 100644 index 000000000..b7186db65 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomWhenThreadExecutor.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomWhenThreadExecutor implements ExecutorBuilder { + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(16, 16, + 512, "customer-when-thead"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/GlobalThreadPoolELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/GlobalThreadPoolELSpringbootTest.java new file mode 100644 index 000000000..0dd3caf59 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/GlobalThreadPoolELSpringbootTest.java @@ -0,0 +1,71 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.collection.ListUtil; +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 org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.noear.solon.annotation.Import; +import org.noear.solon.annotation.Inject; +import org.noear.solon.test.SolonTest; + +import java.util.List; + +/** + * springboot环境下Global线程池隔离测试 + */ +@SolonTest +@Import(profiles = "classpath:/chainThreadPool/application3.properties") +public class GlobalThreadPoolELSpringbootTest extends BaseTest { + + @Inject + private FlowExecutor flowExecutor; + + /** + * 测试WHEN上全局线程池 + */ + @Test + public void testGlobalThreadPool() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-global-thead")); + } + + /** + * 测试FOR上全局线程池 + */ + @Test + public void testGlobalThreadPool2() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-global-thead")); + } + + /** + * 测试WHILE上全局线程池 + */ + @Test + public void testGlobalThreadPool3() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-global-thead")); + } + + /** + * 测试ITERATOR上全局线程池 + */ + @Test + public void testGlobalThreadPool4() { + List list = ListUtil.toList("1", "2", "3", "4", "5"); + LiteflowResponse response1 = flowExecutor.execute2Resp("chain4", list); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-global-thead")); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ACmp.java new file mode 100644 index 000000000..6b1511ec6 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ACmp.java @@ -0,0 +1,22 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.noear.solon.annotation.Component; + +@Component("a") +public class ACmp extends NodeComponent { + + @Override + public void process() { + System.out.println("ACmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/BCmp.java new file mode 100644 index 000000000..1c17aac73 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.noear.solon.annotation.Component; + +@Component("b") +public class BCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/DCmp.java new file mode 100644 index 000000000..8003ba44a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/DCmp.java @@ -0,0 +1,30 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.noear.solon.annotation.Component; + +@Component("d") +public class DCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + String key = "test"; + if (context.hasData(key)) { + int count = context.getData(key); + context.setData(key, ++count); + } else { + context.setData(key, 1); + } + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/FCmp.java new file mode 100644 index 000000000..6b9f29751 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/FCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.noear.solon.annotation.Component; + +@Component("f") +public class FCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("FCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ICmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ICmp.java new file mode 100644 index 000000000..7a025647f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ICmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.noear.solon.annotation.Component; + +@Component("i") +public class ICmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("ICmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ITCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ITCmp.java new file mode 100644 index 000000000..7d231dc22 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ITCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.core.NodeIteratorComponent; +import org.noear.solon.annotation.Component; + +import java.util.Iterator; +import java.util.List; + +@Component("it") +public class ITCmp extends NodeIteratorComponent { + + @Override + public Iterator processIterator() throws Exception { + List list = this.getRequestData(); + return list.iterator(); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/WCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/WCmp.java new file mode 100644 index 000000000..82ccbca73 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/WCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.noear.solon.annotation.Component; + +@Component("w") +public class WCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("WCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ZCmp.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ZCmp.java new file mode 100644 index 000000000..897086ba1 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ZCmp.java @@ -0,0 +1,21 @@ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.core.NodeBooleanComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.noear.solon.annotation.Component; + +@Component("z") +public class ZCmp extends NodeBooleanComponent { + + @Override + public boolean processBoolean() throws Exception { + DefaultContext context = this.getFirstContextBean(); + String key = "test"; + if (context.hasData(key)) { + int count = context.getData("test"); + return count < 5; + } else { + return true; + } + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java index 6034ba621..37d441487 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java @@ -16,8 +16,8 @@ public class CustomThreadExecutor1 implements ExecutorBuilder { if (ObjectUtil.isNull(liteflowConfig)) { liteflowConfig = new LiteflowConfig(); } - return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), "customer-when-1-thead-"); + return buildDefaultExecutor(liteflowConfig.getGlobalThreadPoolSize(), liteflowConfig.getGlobalThreadPoolSize(), + liteflowConfig.getGlobalThreadPoolQueueSize(), "customer-when-1-thead-"); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java index 8f9008e0a..87323ad2a 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java @@ -16,8 +16,8 @@ public class CustomThreadExecutor2 implements ExecutorBuilder { if (ObjectUtil.isNull(liteflowConfig)) { liteflowConfig = new LiteflowConfig(); } - return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), "customer-when-2-thead-"); + return buildDefaultExecutor(liteflowConfig.getGlobalThreadPoolSize(), liteflowConfig.getGlobalThreadPoolSize(), + liteflowConfig.getGlobalThreadPoolQueueSize(), "customer-when-2-thead-"); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java index dc6f63995..0b322bb20 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java @@ -16,8 +16,8 @@ public class CustomThreadExecutor3 implements ExecutorBuilder { if (ObjectUtil.isNull(liteflowConfig)) { liteflowConfig = new LiteflowConfig(); } - return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), "customer-when-3-thead-"); + return buildDefaultExecutor(liteflowConfig.getGlobalThreadPoolSize(), liteflowConfig.getGlobalThreadPoolSize(), + liteflowConfig.getGlobalThreadPoolQueueSize(), "customer-when-3-thead-"); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELSpringbootTest.java index 5f5f921b4..7778a74e4 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELSpringbootTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELSpringbootTest.java @@ -6,7 +6,6 @@ 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.noear.solon.annotation.Import; import org.noear.solon.annotation.Inject; import org.noear.solon.test.SolonTest; @@ -36,7 +35,7 @@ public class CustomWhenThreadPoolELSpringbootTest extends BaseTest { LiteflowResponse response = flowExecutor.execute2Resp("chain", "arg"); DefaultContext context = response.getFirstContextBean(); Assertions.assertTrue(response.isSuccess()); - Assertions.assertTrue(context.getData("threadName").toString().startsWith("when-thread-1")); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("global-thread-1")); } /** diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parallelLoop/CustomThreadExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parallelLoop/CustomThreadExecutor.java index 72773f38a..f82cf346b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parallelLoop/CustomThreadExecutor.java +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/java/com/yomahub/liteflow/test/parallelLoop/CustomThreadExecutor.java @@ -16,8 +16,8 @@ public class CustomThreadExecutor implements ExecutorBuilder { if (ObjectUtil.isNull(liteflowConfig)) { liteflowConfig = new LiteflowConfig(); } - return buildDefaultExecutor(liteflowConfig.getParallelMaxWorkers(), liteflowConfig.getParallelMaxWorkers(), - liteflowConfig.getParallelQueueLimit(), "customer-loop-thead-"); + return buildDefaultExecutor(liteflowConfig.getGlobalThreadPoolSize(), liteflowConfig.getGlobalThreadPoolSize(), + liteflowConfig.getGlobalThreadPoolQueueSize(), "customer-loop-thead-"); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/chainThreadPool/application.properties b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/chainThreadPool/application.properties new file mode 100644 index 000000000..aad6bd9de --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/chainThreadPool/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=chainThreadPool/flow.el.xml diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/chainThreadPool/application2.properties b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/chainThreadPool/application2.properties new file mode 100644 index 000000000..ecac47dd6 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/chainThreadPool/application2.properties @@ -0,0 +1,2 @@ +liteflow.rule-source=chainThreadPool/flow2.el.xml +liteflow.when-thread-pool-isolate=true diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/chainThreadPool/application3.properties b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/chainThreadPool/application3.properties new file mode 100644 index 000000000..d7ec64e9a --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/chainThreadPool/application3.properties @@ -0,0 +1,4 @@ +liteflow.rule-source=chainThreadPool/flow3.el.xml +liteflow.global-thread-pool-size=16 +liteflow.global-thread-pool-queue-size=512 +liteflow.global-thread-pool-executor-class=com.yomahub.liteflow.test.chainThreadPool.CustomGlobalThreadExecutor \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/chainThreadPool/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/chainThreadPool/flow.el.xml new file mode 100644 index 000000000..502724229 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/chainThreadPool/flow.el.xml @@ -0,0 +1,22 @@ + + + + WHEN(a,b); + + + + FOR(5).parallel(true).DO(THEN(a,f)); + + + + WHILE(z).parallel(true).DO(THEN(w,d)); + + + + ITERATOR(it).parallel(true).DO(THEN(a,i)); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/chainThreadPool/flow2.el.xml b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/chainThreadPool/flow2.el.xml new file mode 100644 index 000000000..741e264ba --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/chainThreadPool/flow2.el.xml @@ -0,0 +1,22 @@ + + + + WHEN(a,b).threadPool("com.yomahub.liteflow.test.chainThreadPool.CustomWhenThreadExecutor"); + + + + FOR(5).parallel(true).DO(THEN(a,f)).threadPool("com.yomahub.liteflow.test.chainThreadPool.CustomLoopThreadExecutor"); + + + + WHILE(z).parallel(true).DO(THEN(w,d)).threadPool("com.yomahub.liteflow.test.chainThreadPool.CustomLoopThreadExecutor"); + + + + ITERATOR(it).parallel(true).DO(THEN(a,i)).threadPool("com.yomahub.liteflow.test.chainThreadPool.CustomLoopThreadExecutor"); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/chainThreadPool/flow3.el.xml b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/chainThreadPool/flow3.el.xml new file mode 100644 index 000000000..a544de8c5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-solon/src/test/resources/chainThreadPool/flow3.el.xml @@ -0,0 +1,19 @@ + + + + WHEN(a,b); + + + + FOR(5).parallel(true).DO(THEN(a,f) + ); + + + + WHILE(z).parallel(true).DO(THEN(w,d)); + + + + ITERATOR(it).parallel(true).DO(THEN(a,i)); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ChainThreadPoolELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ChainThreadPoolELSpringbootTest.java new file mode 100644 index 000000000..3316d4072 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ChainThreadPoolELSpringbootTest.java @@ -0,0 +1,76 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.collection.ListUtil; +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 org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import javax.annotation.Resource; +import java.util.List; + +/** + * springboot环境下chain线程池隔离测试 + */ +@ExtendWith(SpringExtension.class) +@ContextConfiguration(value = "classpath:/chainThreadPool/application.xml") +public class ChainThreadPoolELSpringbootTest extends BaseTest { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Resource + private FlowExecutor flowExecutor; + + /** + * 测试WHEN上全局线程池和chain线程池隔离-优先以chain上为准 + */ + @Test + public void testChainThreadPool() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + } + + /** + * 测试FOR上全局线程池和chain线程池隔离-优先以chain上为准 + */ + @Test + public void testChainThreadPool2() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + } + + /** + * 测试WHILE上全局线程池和chain线程池隔离-优先以chain上为准 + */ + @Test + public void testChainThreadPool3() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + } + + /** + * 测试ITERATOR上全局线程池和chain线程池隔离-优先以chain上为准 + */ + @Test + public void testChainThreadPool4() { + List list = ListUtil.toList("1", "2", "3", "4", "5"); + LiteflowResponse response1 = flowExecutor.execute2Resp("chain4", list); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-chain-thead")); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ConditionThreadPoolELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ConditionThreadPoolELSpringbootTest.java new file mode 100644 index 000000000..7f786ecfb --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/ConditionThreadPoolELSpringbootTest.java @@ -0,0 +1,76 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.collection.ListUtil; +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 org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import javax.annotation.Resource; +import java.util.List; + +/** + * springboot环境下chain线程池隔离测试 + */ +@ExtendWith(SpringExtension.class) +@ContextConfiguration(value = "classpath:/chainThreadPool/application2.xml") +public class ConditionThreadPoolELSpringbootTest extends BaseTest { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Resource + private FlowExecutor flowExecutor; + + /** + * 测试WEHN上condition线程池和chain线程池隔离-优先以WHEN上为准 + */ + @Test + public void testConditionThreadPool() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-when-thead")); + } + + /** + * 测试FOR上condition线程池和chain线程池隔离-优先以FOR上为准 + */ + @Test + public void testConditionThreadPool2() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-loop-thead")); + } + + /** + * 测试WHILE上condition线程池和chain线程池隔离-优先以WHILE上为准 + */ + @Test + public void testConditionThreadPool3() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-loop-thead")); + } + + /** + * 测试ITERATOR上condition线程池和chain线程池隔离-优先以ITERATOR上为准 + */ + @Test + public void testConditionThreadPool4() { + List list = ListUtil.toList("1", "2", "3", "4", "5"); + LiteflowResponse response1 = flowExecutor.execute2Resp("chain4", list); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-loop-thead")); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomChainThreadExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomChainThreadExecutor.java new file mode 100644 index 000000000..cd366a9e2 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomChainThreadExecutor.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomChainThreadExecutor implements ExecutorBuilder { + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(16, 16, + 512, "customer-chain-thead"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomGlobalThreadExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomGlobalThreadExecutor.java new file mode 100644 index 000000000..260f1d97e --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomGlobalThreadExecutor.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomGlobalThreadExecutor implements ExecutorBuilder { + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(16, 16, + 512, "customer-global-thead"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomLoopThreadExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomLoopThreadExecutor.java new file mode 100644 index 000000000..647addafb --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomLoopThreadExecutor.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomLoopThreadExecutor implements ExecutorBuilder { + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(16, 16, + 512, "customer-loop-thead"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomWhenThreadExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomWhenThreadExecutor.java new file mode 100644 index 000000000..b7186db65 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/CustomWhenThreadExecutor.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomWhenThreadExecutor implements ExecutorBuilder { + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + // 只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor(16, 16, + 512, "customer-when-thead"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/GlobalThreadPoolELSpringbootTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/GlobalThreadPoolELSpringbootTest.java new file mode 100644 index 000000000..31bd65784 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/GlobalThreadPoolELSpringbootTest.java @@ -0,0 +1,73 @@ +package com.yomahub.liteflow.test.chainThreadPool; + +import cn.hutool.core.collection.ListUtil; +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 org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import javax.annotation.Resource; +import java.util.List; + +/** + * springboot环境下Global线程池隔离测试 + */ +@ExtendWith(SpringExtension.class) +@ContextConfiguration(value = "classpath:/chainThreadPool/application3.xml") +public class GlobalThreadPoolELSpringbootTest extends BaseTest { + + + @Resource + private FlowExecutor flowExecutor; + + /** + * 测试WHEN上全局线程池 + */ + @Test + public void testGlobalThreadPool() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-global-thead")); + } + + /** + * 测试FOR上全局线程池 + */ + @Test + public void testGlobalThreadPool2() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain2", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-global-thead")); + } + + /** + * 测试WHILE上全局线程池 + */ + @Test + public void testGlobalThreadPool3() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain3", "arg"); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-global-thead")); + } + + /** + * 测试ITERATOR上全局线程池 + */ + @Test + public void testGlobalThreadPool4() { + List list = ListUtil.toList("1", "2", "3", "4", "5"); + LiteflowResponse response1 = flowExecutor.execute2Resp("chain4", list); + DefaultContext context = response1.getFirstContextBean(); + Assertions.assertTrue(response1.isSuccess()); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("customer-global-thead")); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ACmp.java new file mode 100644 index 000000000..da44ef7ab --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ACmp.java @@ -0,0 +1,22 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import org.springframework.stereotype.Component; + +@Component("a") +public class ACmp extends NodeComponent { + + @Override + public void process() { + System.out.println("ACmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/BCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/BCmp.java new file mode 100644 index 000000000..20e6b994f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("b") +public class BCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/DCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/DCmp.java new file mode 100644 index 000000000..d84ae1855 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/DCmp.java @@ -0,0 +1,30 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("d") +public class DCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + String key = "test"; + if (context.hasData(key)) { + int count = context.getData(key); + context.setData(key, ++count); + } else { + context.setData(key, 1); + } + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/FCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/FCmp.java new file mode 100644 index 000000000..471a2f0f2 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/FCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("f") +public class FCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("FCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ICmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ICmp.java new file mode 100644 index 000000000..53a61e93f --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ICmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("i") +public class ICmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("ICmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ITCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ITCmp.java new file mode 100644 index 000000000..660fbaf6b --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ITCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.core.NodeIteratorComponent; +import org.springframework.stereotype.Component; + +import java.util.Iterator; +import java.util.List; + +@Component("it") +public class ITCmp extends NodeIteratorComponent { + + @Override + public Iterator processIterator() throws Exception { + List list = this.getRequestData(); + return list.iterator(); + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/WCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/WCmp.java new file mode 100644 index 000000000..e4e76f4c2 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/WCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("w") +public class WCmp extends NodeComponent { + + @Override + public void process() { + DefaultContext context = this.getFirstContextBean(); + context.setData("threadName", Thread.currentThread().getName()); + System.out.println("WCmp executed!"); + } + +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ZCmp.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ZCmp.java new file mode 100644 index 000000000..4c608f1c0 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/chainThreadPool/cmp/ZCmp.java @@ -0,0 +1,21 @@ +package com.yomahub.liteflow.test.chainThreadPool.cmp; + +import com.yomahub.liteflow.core.NodeBooleanComponent; +import com.yomahub.liteflow.slot.DefaultContext; +import org.springframework.stereotype.Component; + +@Component("z") +public class ZCmp extends NodeBooleanComponent { + + @Override + public boolean processBoolean() throws Exception { + DefaultContext context = this.getFirstContextBean(); + String key = "test"; + if (context.hasData(key)) { + int count = context.getData("test"); + return count < 5; + } else { + return true; + } + } +} diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/config/LiteflowConfigELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/config/LiteflowConfigELSpringTest.java index 8e2d0a813..5b623f618 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/config/LiteflowConfigELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/config/LiteflowConfigELSpringTest.java @@ -11,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; + import javax.annotation.Resource; import java.util.concurrent.TimeUnit; @@ -44,7 +45,7 @@ public class LiteflowConfigELSpringTest extends BaseTest { Assertions.assertFalse(config.getEnableLog()); // Assertions.assertEquals(Runtime.getRuntime().availableProcessors() * 2, // config.getWhenMaxWorkers().longValue()); - Assertions.assertEquals(512, config.getWhenQueueLimit().longValue()); + Assertions.assertEquals(512, config.getGlobalThreadPoolQueueSize().longValue()); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java index be8a3ffcf..0109010a9 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java @@ -16,8 +16,8 @@ public class CustomThreadExecutor1 implements ExecutorBuilder { if (ObjectUtil.isNull(liteflowConfig)) { liteflowConfig = new LiteflowConfig(); } - return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), "customer-when-1-thead-"); + return buildDefaultExecutor(liteflowConfig.getGlobalThreadPoolSize(), liteflowConfig.getGlobalThreadPoolSize(), + liteflowConfig.getGlobalThreadPoolQueueSize(), "customer-when-1-thead-"); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java index f70d4dddb..cd719ca26 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java @@ -16,8 +16,8 @@ public class CustomThreadExecutor2 implements ExecutorBuilder { if (ObjectUtil.isNull(liteflowConfig)) { liteflowConfig = new LiteflowConfig(); } - return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), "customer-when-2-thead-"); + return buildDefaultExecutor(liteflowConfig.getGlobalThreadPoolSize(), liteflowConfig.getGlobalThreadPoolSize(), + liteflowConfig.getGlobalThreadPoolQueueSize(), "customer-when-2-thead-"); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java index 95c13e95a..a42ef0656 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java @@ -16,8 +16,8 @@ public class CustomThreadExecutor3 implements ExecutorBuilder { if (ObjectUtil.isNull(liteflowConfig)) { liteflowConfig = new LiteflowConfig(); } - return buildDefaultExecutor(liteflowConfig.getWhenMaxWorkers(), liteflowConfig.getWhenMaxWorkers(), - liteflowConfig.getWhenQueueLimit(), "customer-when-3-thead-"); + return buildDefaultExecutor(liteflowConfig.getGlobalThreadPoolSize(), liteflowConfig.getGlobalThreadPoolSize(), + liteflowConfig.getGlobalThreadPoolQueueSize(), "customer-when-3-thead-"); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELSpringTest.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELSpringTest.java index 730733f80..3c260b96f 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELSpringTest.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolELSpringTest.java @@ -37,7 +37,7 @@ public class CustomWhenThreadPoolELSpringTest extends BaseTest { LiteflowResponse response = flowExecutor.execute2Resp("chain", "arg"); DefaultContext context = response.getFirstContextBean(); Assertions.assertTrue(response.isSuccess()); - Assertions.assertTrue(context.getData("threadName").toString().startsWith("when-thread-1")); + Assertions.assertTrue(context.getData("threadName").toString().startsWith("global-thread-1")); } /** diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parallelLoop/CustomThreadExecutor.java b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parallelLoop/CustomThreadExecutor.java index 72773f38a..f82cf346b 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parallelLoop/CustomThreadExecutor.java +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/java/com/yomahub/liteflow/test/parallelLoop/CustomThreadExecutor.java @@ -16,8 +16,8 @@ public class CustomThreadExecutor implements ExecutorBuilder { if (ObjectUtil.isNull(liteflowConfig)) { liteflowConfig = new LiteflowConfig(); } - return buildDefaultExecutor(liteflowConfig.getParallelMaxWorkers(), liteflowConfig.getParallelMaxWorkers(), - liteflowConfig.getParallelQueueLimit(), "customer-loop-thead-"); + return buildDefaultExecutor(liteflowConfig.getGlobalThreadPoolSize(), liteflowConfig.getGlobalThreadPoolSize(), + liteflowConfig.getGlobalThreadPoolQueueSize(), "customer-loop-thead-"); } } diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/chainThreadPool/application.xml b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/chainThreadPool/application.xml new file mode 100644 index 000000000..7862ed4b8 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/chainThreadPool/application.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/chainThreadPool/application2.xml b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/chainThreadPool/application2.xml new file mode 100644 index 000000000..8095be38b --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/chainThreadPool/application2.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/chainThreadPool/application3.xml b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/chainThreadPool/application3.xml new file mode 100644 index 000000000..b77c2f9e5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/chainThreadPool/application3.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/chainThreadPool/flow.el.xml b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/chainThreadPool/flow.el.xml new file mode 100644 index 000000000..502724229 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/chainThreadPool/flow.el.xml @@ -0,0 +1,22 @@ + + + + WHEN(a,b); + + + + FOR(5).parallel(true).DO(THEN(a,f)); + + + + WHILE(z).parallel(true).DO(THEN(w,d)); + + + + ITERATOR(it).parallel(true).DO(THEN(a,i)); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/chainThreadPool/flow2.el.xml b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/chainThreadPool/flow2.el.xml new file mode 100644 index 000000000..741e264ba --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/chainThreadPool/flow2.el.xml @@ -0,0 +1,22 @@ + + + + WHEN(a,b).threadPool("com.yomahub.liteflow.test.chainThreadPool.CustomWhenThreadExecutor"); + + + + FOR(5).parallel(true).DO(THEN(a,f)).threadPool("com.yomahub.liteflow.test.chainThreadPool.CustomLoopThreadExecutor"); + + + + WHILE(z).parallel(true).DO(THEN(w,d)).threadPool("com.yomahub.liteflow.test.chainThreadPool.CustomLoopThreadExecutor"); + + + + ITERATOR(it).parallel(true).DO(THEN(a,i)).threadPool("com.yomahub.liteflow.test.chainThreadPool.CustomLoopThreadExecutor"); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/chainThreadPool/flow3.el.xml b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/chainThreadPool/flow3.el.xml new file mode 100644 index 000000000..a544de8c5 --- /dev/null +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/chainThreadPool/flow3.el.xml @@ -0,0 +1,19 @@ + + + + WHEN(a,b); + + + + FOR(5).parallel(true).DO(THEN(a,f) + ); + + + + WHILE(z).parallel(true).DO(THEN(w,d)); + + + + ITERATOR(it).parallel(true).DO(THEN(a,i)); + + \ No newline at end of file diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/parallelLoop/application.xml b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/parallelLoop/application.xml index ee28d7f85..199fed728 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/parallelLoop/application.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/parallelLoop/application.xml @@ -15,9 +15,10 @@ - - - + + + diff --git a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/useTTLInWhen/application.xml b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/useTTLInWhen/application.xml index 5ed240b23..d96fd7bdd 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/useTTLInWhen/application.xml +++ b/liteflow-testcase-el/liteflow-testcase-el-springnative/src/test/resources/useTTLInWhen/application.xml @@ -15,7 +15,7 @@ - +