mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 04:02:09 +08:00
feature #IAPI07 chain维度线程池隔离
This commit is contained in:
@@ -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<String> 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"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<String> 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"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<String> 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"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
*
|
||||
* @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!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
*
|
||||
* @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!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
*
|
||||
* @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!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
*
|
||||
* @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!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<String> list = this.getRequestData();
|
||||
return list.iterator();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
*
|
||||
* @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!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
@@ -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-");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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-");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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-");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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-");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
liteflow.rule-source=chainThreadPool/flow.el.xml
|
||||
@@ -0,0 +1,2 @@
|
||||
liteflow.rule-source=chainThreadPool/flow2.el.xml
|
||||
liteflow.when-thread-pool-isolate=true
|
||||
@@ -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
|
||||
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<flow>
|
||||
<nodes>
|
||||
<node id="a" class="com.yomahub.liteflow.test.chainThreadPool.cmp.ACmp"/>
|
||||
<node id="b" class="com.yomahub.liteflow.test.chainThreadPool.cmp.BCmp"/>
|
||||
<node id="d" class="com.yomahub.liteflow.test.chainThreadPool.cmp.DCmp"/>
|
||||
<node id="f" class="com.yomahub.liteflow.test.chainThreadPool.cmp.FCmp"/>
|
||||
<node id="i" class="com.yomahub.liteflow.test.chainThreadPool.cmp.ICmp"/>
|
||||
<node id="it" class="com.yomahub.liteflow.test.chainThreadPool.cmp.ITCmp"/>
|
||||
<node id="w" class="com.yomahub.liteflow.test.chainThreadPool.cmp.WCmp"/>
|
||||
<node id="z" class="com.yomahub.liteflow.test.chainThreadPool.cmp.ZCmp"/>
|
||||
</nodes>
|
||||
|
||||
<chain name="chain1"
|
||||
thread-pool-executor-class="com.yomahub.liteflow.test.chainThreadPool.CustomChainThreadExecutor">
|
||||
WHEN(a,b);
|
||||
</chain>
|
||||
|
||||
<chain name="chain2"
|
||||
thread-pool-executor-class="com.yomahub.liteflow.test.chainThreadPool.CustomChainThreadExecutor">
|
||||
FOR(5).parallel(true).DO(THEN(a,f));
|
||||
</chain>
|
||||
|
||||
<chain name="chain3"
|
||||
thread-pool-executor-class="com.yomahub.liteflow.test.chainThreadPool.CustomChainThreadExecutor">
|
||||
WHILE(z).parallel(true).DO(THEN(w,d));
|
||||
</chain>
|
||||
|
||||
<chain name="chain4"
|
||||
thread-pool-executor-class="com.yomahub.liteflow.test.chainThreadPool.CustomChainThreadExecutor">
|
||||
ITERATOR(it).parallel(true).DO(THEN(a,i));
|
||||
</chain>
|
||||
</flow>
|
||||
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<flow>
|
||||
<nodes>
|
||||
<node id="a" class="com.yomahub.liteflow.test.chainThreadPool.cmp.ACmp"/>
|
||||
<node id="b" class="com.yomahub.liteflow.test.chainThreadPool.cmp.BCmp"/>
|
||||
<node id="d" class="com.yomahub.liteflow.test.chainThreadPool.cmp.DCmp"/>
|
||||
<node id="f" class="com.yomahub.liteflow.test.chainThreadPool.cmp.FCmp"/>
|
||||
<node id="i" class="com.yomahub.liteflow.test.chainThreadPool.cmp.ICmp"/>
|
||||
<node id="it" class="com.yomahub.liteflow.test.chainThreadPool.cmp.ITCmp"/>
|
||||
<node id="w" class="com.yomahub.liteflow.test.chainThreadPool.cmp.WCmp"/>
|
||||
<node id="z" class="com.yomahub.liteflow.test.chainThreadPool.cmp.ZCmp"/>
|
||||
</nodes>
|
||||
<chain name="chain1"
|
||||
thread-pool-executor-class="com.yomahub.liteflow.test.chainThreadPool.CustomChainThreadExecutor">
|
||||
WHEN(a,b).threadPool("com.yomahub.liteflow.test.chainThreadPool.CustomWhenThreadExecutor");
|
||||
</chain>
|
||||
|
||||
<chain name="chain2"
|
||||
thread-pool-executor-class="com.yomahub.liteflow.test.chainThreadPool.CustomChainThreadExecutor">
|
||||
FOR(5).parallel(true).DO(THEN(a,f)).threadPool("com.yomahub.liteflow.test.chainThreadPool.CustomLoopThreadExecutor");
|
||||
</chain>
|
||||
|
||||
<chain name="chain3"
|
||||
thread-pool-executor-class="com.yomahub.liteflow.test.chainThreadPool.CustomChainThreadExecutor">
|
||||
WHILE(z).parallel(true).DO(THEN(w,d)).threadPool("com.yomahub.liteflow.test.chainThreadPool.CustomLoopThreadExecutor");
|
||||
</chain>
|
||||
|
||||
<chain name="chain4"
|
||||
thread-pool-executor-class="com.yomahub.liteflow.test.chainThreadPool.CustomChainThreadExecutor">
|
||||
ITERATOR(it).parallel(true).DO(THEN(a,i)).threadPool("com.yomahub.liteflow.test.chainThreadPool.CustomLoopThreadExecutor");
|
||||
</chain>
|
||||
</flow>
|
||||
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<flow>
|
||||
<nodes>
|
||||
<node id="a" class="com.yomahub.liteflow.test.chainThreadPool.cmp.ACmp"/>
|
||||
<node id="b" class="com.yomahub.liteflow.test.chainThreadPool.cmp.BCmp"/>
|
||||
<node id="d" class="com.yomahub.liteflow.test.chainThreadPool.cmp.DCmp"/>
|
||||
<node id="f" class="com.yomahub.liteflow.test.chainThreadPool.cmp.FCmp"/>
|
||||
<node id="i" class="com.yomahub.liteflow.test.chainThreadPool.cmp.ICmp"/>
|
||||
<node id="it" class="com.yomahub.liteflow.test.chainThreadPool.cmp.ITCmp"/>
|
||||
<node id="w" class="com.yomahub.liteflow.test.chainThreadPool.cmp.WCmp"/>
|
||||
<node id="z" class="com.yomahub.liteflow.test.chainThreadPool.cmp.ZCmp"/>
|
||||
</nodes>
|
||||
<chain name="chain1">
|
||||
WHEN(a,b);
|
||||
</chain>
|
||||
|
||||
<chain name="chain2">
|
||||
FOR(5).parallel(true).DO(THEN(a,f)
|
||||
);
|
||||
</chain>
|
||||
|
||||
<chain name="chain3">
|
||||
WHILE(z).parallel(true).DO(THEN(w,d));
|
||||
</chain>
|
||||
|
||||
<chain name="chain4">
|
||||
ITERATOR(it).parallel(true).DO(THEN(a,i));
|
||||
</chain>
|
||||
</flow>
|
||||
Reference in New Issue
Block a user