Skip to content

Commit

Permalink
add test case for reset tp props with global config
Browse files Browse the repository at this point in the history
  • Loading branch information
yanhom1314 committed Sep 22, 2024
1 parent e05c7d9 commit a80a717
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.dromara.dynamictp.core.support.BinderHelper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
Expand All @@ -43,6 +44,7 @@
factory = YamlPropertySourceFactory.class)
@SpringBootTest(classes = PropertiesBinderTest.class)
@EnableAutoConfiguration
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class PropertiesBinderTest {

@Autowired
Expand Down Expand Up @@ -78,7 +80,36 @@ void testBindDtpPropertiesWithEnvironment() {
Assertions.assertEquals(threadPoolName, dtpProperties.getExecutors().get(0).getThreadPoolName());
String executorType = environment.getProperty("spring.dynamic.tp.globalExecutorProps.executorType");
Assertions.assertEquals(executorType, dtpProperties.getExecutors().get(1).getExecutorType());
}

@Test
void testResetDtpWithGlobalConfig() {
DtpProperties dtpProperties = DtpProperties.getInstance();
BinderHelper.bindDtpProperties(environment, dtpProperties);

Assertions.assertEquals(1, dtpProperties.getExecutors().get(1).getCorePoolSize());
Assertions.assertEquals(18, dtpProperties.getExecutors().get(1).getMaximumPoolSize());
Assertions.assertEquals(201, dtpProperties.getExecutors().get(1).getRunTimeout());
Assertions.assertEquals(80, dtpProperties.getExecutors().get(0).getNotifyItems().get(0).getThreshold());
Assertions.assertEquals(81, dtpProperties.getExecutors().get(1).getNotifyItems().get(0).getThreshold());
}

@Test
void testResetAdapterTpWithGlobalConfig() {
DtpProperties dtpProperties = DtpProperties.getInstance();
BinderHelper.bindDtpProperties(environment, dtpProperties);

Assertions.assertEquals(400, dtpProperties.getUndertowTp().getMaximumPoolSize());
Assertions.assertEquals(201, dtpProperties.getTomcatTp().getRunTimeout());
Assertions.assertEquals(101, dtpProperties.getTomcatTp().getQueueTimeout());
Assertions.assertIterableEquals(Lists.newArrayList("ttl"), dtpProperties.getTomcatTp().getTaskWrapperNames());
Assertions.assertEquals(5, dtpProperties.getTomcatTp().getNotifyItems().size());

Assertions.assertEquals(201, dtpProperties.getRocketMqTp().get(0).getRunTimeout());
Assertions.assertEquals(1, dtpProperties.getRocketMqTp().get(1).getCorePoolSize());

Assertions.assertEquals(81, dtpProperties.getRocketMqTp().get(0).getNotifyItems().get(0).getThreshold());
Assertions.assertEquals(82, dtpProperties.getRocketMqTp().get(1).getNotifyItems().get(0).getThreshold());
}

}
40 changes: 36 additions & 4 deletions test/test-core/src/test/resources/demo-dtp-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,41 @@ spring:
corePoolSize: 200
maximumPoolSize: 400
keepAliveTime: 60
- threadPoolName: group2#topic2
maximumPoolSize: 200
keepAliveTime: 60
notifyItems: # 报警项,不配置自动会按默认值配置(变更通知、容量报警、活性报警、拒绝报警、任务超时报警)
- type: capacity # 报警项类型,查看源码 NotifyTypeEnum枚举类
enabled: true
threshold: 82 # 报警阈值
platforms: [ ding,wechat ] # 可选配置,不配置默认拿上层platforms配置的所以平台
interval: 120 # 报警间隔(单位:s)

globalExecutorProps:
executorType: eager
corePoolSize: 1
waitForTasksToCompleteOnShutdown: false # 参考spring线程池设计,优雅关闭线程池
awaitTerminationSeconds: 5 # 单位(s)
preStartAllCoreThreads: false # 是否预热所有核心线程,默认false
runTimeout: 201 # 任务执行超时阈值,目前只做告警用,单位(ms)
queueTimeout: 101 # 任务在队列等待超时阈值,目前只做告警用,单位(ms)
taskWrapperNames: [ "ttl" ] # 任务包装器名称,集成TaskWrapper接口
notifyItems: # 报警项,不配置自动会按默认值配置(变更通知、容量报警、活性报警、拒绝报警、任务超时报警)
- type: capacity # 报警项类型,查看源码 NotifyTypeEnum枚举类
enabled: true
threshold: 81 # 报警阈值
platforms: [ ding,wechat ] # 可选配置,不配置默认拿上层platforms配置的所以平台
interval: 120 # 报警间隔(单位:s)
- type: change
enabled: true
- type: liveness
enabled: true
threshold: 80
- type: reject
enabled: true
threshold: 1
- type: queue_timeout
enabled: true
threshold: 1
executors: # 动态线程池配置,都有默认值,采用默认值的可以不配置该项,减少配置量
- threadPoolName: dtpExecutor1
executorType: common # 线程池类型common、eager:适用于io密集型
Expand All @@ -70,8 +103,6 @@ spring:
threshold: 80 # 报警阈值
platforms: [ding,wechat] # 可选配置,不配置默认拿上层platforms配置的所以平台
interval: 120 # 报警间隔(单位:s)
countToTrigger: 3
op: >
- type: change
enabled: true
- type: liveness
Expand All @@ -86,4 +117,5 @@ spring:
- type: queue_timeout
enabled: true
threshold: 1
- threadPoolName: dtpExecutor2
- threadPoolName: dtpExecutor2
maximumPoolSize: 18

0 comments on commit a80a717

Please sign in to comment.