Polish
Closes gh-14049
This commit is contained in:
committed by
Stephane Nicoll
parent
d0f272960e
commit
d5eaaf6e2a
@@ -65,20 +65,15 @@ public class TaskExecutorAutoConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public TaskExecutorBuilder taskExecutorBuilder() {
|
||||
TaskExecutorBuilder builder = new TaskExecutorBuilder();
|
||||
TaskProperties.Pool pool = this.properties.getPool();
|
||||
builder = builder.queueCapacity(pool.getQueueCapacity())
|
||||
return new TaskExecutorBuilder().queueCapacity(pool.getQueueCapacity())
|
||||
.corePoolSize(pool.getCoreSize()).maxPoolSize(pool.getMaxSize())
|
||||
.allowCoreThreadTimeOut(pool.isAllowCoreThreadTimeout())
|
||||
.keepAlive(pool.getKeepAlive());
|
||||
builder = builder.threadNamePrefix(this.properties.getThreadNamePrefix());
|
||||
builder = builder.customizers(
|
||||
this.taskExecutorCustomizers.stream().collect(Collectors.toList()));
|
||||
TaskDecorator taskDecorator = this.taskDecorator.getIfUnique();
|
||||
if (taskDecorator != null) {
|
||||
builder = builder.taskDecorator(taskDecorator);
|
||||
}
|
||||
return builder;
|
||||
.keepAlive(pool.getKeepAlive())
|
||||
.threadNamePrefix(this.properties.getThreadNamePrefix())
|
||||
.customizers(this.taskExecutorCustomizers.stream()
|
||||
.collect(Collectors.toList()))
|
||||
.taskDecorator(this.taskDecorator.getIfUnique());
|
||||
}
|
||||
|
||||
@Bean(name = APPLICATION_TASK_EXECUTOR_BEAN_NAME)
|
||||
|
||||
@@ -50,8 +50,8 @@ public class TaskProperties {
|
||||
public static class Pool {
|
||||
|
||||
/**
|
||||
* Queue capacity. A unbounded capacity does not increase the pool and therefore
|
||||
* ignores the "max-size" parameter.
|
||||
* Queue capacity. An unbounded capacity does not increase the pool and therefore
|
||||
* ignores the "max-size" property.
|
||||
*/
|
||||
private int queueCapacity = Integer.MAX_VALUE;
|
||||
|
||||
|
||||
@@ -109,19 +109,19 @@ public class TaskExecutorAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void taskExecutorWhenHasCustomTaskExecutorShouldBAckOff() {
|
||||
public void taskExecutorWhenHasCustomTaskExecutorShouldBackOff() {
|
||||
this.contextRunner.withUserConfiguration(CustomTaskExecutorConfig.class)
|
||||
.run((context) -> {
|
||||
assertThat(context).hasSingleBean(Executor.class);
|
||||
assertThat(context.getBean(Executor.class))
|
||||
.isSameAs(context.getBean("customTaskExecutorBuilder"));
|
||||
.isSameAs(context.getBean("customTaskExecutor"));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void taskExecutorBuilderShouldApplyCustomizer() {
|
||||
this.contextRunner.withUserConfiguration(CustomTaskExecutorConfig.class,
|
||||
TaskExecutorCustomizerConfig.class).run((context) -> {
|
||||
this.contextRunner.withUserConfiguration(TaskExecutorCustomizerConfig.class)
|
||||
.run((context) -> {
|
||||
TaskExecutorCustomizer customizer = context
|
||||
.getBean(TaskExecutorCustomizer.class);
|
||||
ThreadPoolTaskExecutor executor = context
|
||||
@@ -138,8 +138,8 @@ public class TaskExecutorAutoConfigurationTests {
|
||||
.run((context) -> {
|
||||
assertThat(context).hasSingleBean(TaskExecutor.class);
|
||||
TestBean bean = context.getBean(TestBean.class);
|
||||
String text = bean.echo("test").get();
|
||||
assertThat(text).contains("executor-test-").contains("test");
|
||||
String text = bean.echo("something").get();
|
||||
assertThat(text).contains("executor-test-").contains("something");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -188,7 +188,7 @@ public class TaskExecutorAutoConfigurationTests {
|
||||
static class CustomTaskExecutorConfig {
|
||||
|
||||
@Bean
|
||||
public Executor customTaskExecutorBuilder() {
|
||||
public Executor customTaskExecutor() {
|
||||
return new SyncTaskExecutor();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user