Closes gh-14049
This commit is contained in:
Johnny Lim 2018-08-13 22:47:04 +09:00 committed by Stephane Nicoll
parent d0f272960e
commit d5eaaf6e2a
11 changed files with 38 additions and 46 deletions

View File

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

View File

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

View File

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

View File

@ -166,7 +166,7 @@ content into your application. Rather, pick only the properties that you need.
spring.task.pool.core-size=8 # Core number of threads.
spring.task.pool.keep-alive=60s # Time limit for which threads may remain idle before being terminated.
spring.task.pool.max-size= # Maximum allowed number of threads. If tasks are filling up the queue, the pool can expand up to that size to accommodate the load. Ignored if the queue is unbounded.
spring.task.pool.queue-capacity= # Queue capacity. A unbounded capacity does not increase the pool and therefore ignores the "max-size" parameter.
spring.task.pool.queue-capacity= # Queue capacity. An unbounded capacity does not increase the pool and therefore ignores the "max-size" property.
spring.task.thread-name-prefix=executor- # Prefix to use for the names of newly created threads.
# ----------------------------------------

View File

@ -4638,7 +4638,7 @@ URLs of your server in your application.properties, as shown in the following ex
If you need to customize connection settings, you can use the `spring.ldap.base` and
`spring.ldap.base-environment` properties.
A `LdapContextSource` is auto-configured based on these settings. If you need to customize
An `LdapContextSource` is auto-configured based on these settings. If you need to customize
it, for instance to use a `PooledContextSource`, you can still inject the auto-configured
`LdapContextSource`. Make sure to flag your customized `ContextSource` as `@Primary` so
that the auto-configured `LdapTemplate` uses it.
@ -6156,7 +6156,7 @@ following example:
This changes the thread pool to use a bounded queue so that when the queue is full (100
tasks), the thread pool increases to maximum 16 threads. Shrinking of the pool is more
aggressive as well as threads are reclaimed when they are idle for 10 seconds (rather than
aggressive as threads are reclaimed when they are idle for 10 seconds (rather than
60 seconds by default).
@ -6334,8 +6334,8 @@ web application.
* `RANDOM_PORT`: Loads a `WebServerApplicationContext` and provides a real web
environment. Embedded servers are started and listen on a random port.
* `DEFINED_PORT`: Loads a `WebServerApplicationContext` and provides a real web
environment. Embedded servers are started and listen on a defined port (from your
`application.properties` or on the default port of `8080`).
environment. Embedded servers are started and listen on a defined port (from your
`application.properties`) or on the default port of `8080`.
* `NONE`: Loads an `ApplicationContext` by using `SpringApplication` but does not provide
_any_ web environment (mock or otherwise).

View File

@ -31,7 +31,7 @@ public abstract class JsonParserFactory {
/**
* Static factory for the "best" JSON parser available on the classpath. Tries
* Jackson, then Gson, Snake YAML,and then falls back to the {@link BasicJsonParser}.
* Jackson, then Gson, Snake YAML, and then falls back to the {@link BasicJsonParser}.
* @return a {@link JsonParser}
*/
public static JsonParser getJsonParser() {

View File

@ -90,7 +90,7 @@ public class TaskExecutorBuilder {
}
/**
* Set the capacity of the queue. A unbounded capacity does not increase the pool and
* Set the capacity of the queue. An unbounded capacity does not increase the pool and
* therefore ignores {@link #maxPoolSize(int) maxPoolSize}.
* @param queueCapacity the queue capacity to set
* @return a new builder instance
@ -134,7 +134,7 @@ public class TaskExecutorBuilder {
/**
* Set whether core threads are allow to time out. When enabled, this enables dynamic
* growing and shrinking of the pool.
* @param allowCoreThreadTimeOut if core thread are allowed to time out
* @param allowCoreThreadTimeOut if core threads are allowed to time out
* @return a new builder instance
*/
public TaskExecutorBuilder allowCoreThreadTimeOut(boolean allowCoreThreadTimeOut) {
@ -262,7 +262,7 @@ public class TaskExecutorBuilder {
* @param <T> the type of task executor
* @param taskExecutorClass the template type to create
* @return a configured {@link ThreadPoolTaskExecutor} instance.
* @see TaskExecutorBuilder#build()
* @see #build()
* @see #configure(ThreadPoolTaskExecutor)
*/
public <T extends ThreadPoolTaskExecutor> T build(Class<T> taskExecutorClass) {
@ -274,8 +274,8 @@ public class TaskExecutorBuilder {
* @param <T> the type of task executor
* @param taskExecutor the {@link ThreadPoolTaskExecutor} to configure
* @return the task executor instance
* @see TaskExecutorBuilder#build()
* @see TaskExecutorBuilder#build(Class)
* @see #build()
* @see #build(Class)
*/
public <T extends ThreadPoolTaskExecutor> T configure(T taskExecutor) {
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();

View File

@ -35,7 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public class BeanDefinitionOverrideFailureAnalyzerTests {
@Test
public void bindExceptionWithFieldErrorsDueToValidationFailure() {
public void analyzeBeanDefinitionOverrideException() {
FailureAnalysis analysis = performAnalysis(BeanOverrideConfiguration.class);
String description = analysis.getDescription();
assertThat(description).contains("The bean 'testBean', defined in "

View File

@ -56,9 +56,9 @@ public class TaskExecutorBuilderTests {
@Test
public void poolSettingsShouldApply() {
ThreadPoolTaskExecutor executor = this.builder.allowCoreThreadTimeOut(true)
.queueCapacity(10).corePoolSize(4).maxPoolSize(8)
.allowCoreThreadTimeOut(true).keepAlive(Duration.ofMinutes(1)).build();
ThreadPoolTaskExecutor executor = this.builder.queueCapacity(10).corePoolSize(4)
.maxPoolSize(8).allowCoreThreadTimeOut(true)
.keepAlive(Duration.ofMinutes(1)).build();
DirectFieldAccessor dfa = new DirectFieldAccessor(executor);
assertThat(dfa.getPropertyValue("queueCapacity")).isEqualTo(10);
assertThat(executor.getCorePoolSize()).isEqualTo(4);
@ -107,10 +107,10 @@ public class TaskExecutorBuilderTests {
public void customizersShouldBeAppliedLast() {
TaskDecorator taskDecorator = mock(TaskDecorator.class);
ThreadPoolTaskExecutor executor = spy(new ThreadPoolTaskExecutor());
this.builder.allowCoreThreadTimeOut(true).queueCapacity(10).corePoolSize(4)
.maxPoolSize(8).allowCoreThreadTimeOut(true)
.keepAlive(Duration.ofMinutes(1)).threadNamePrefix("test-")
.taskDecorator(taskDecorator).additionalCustomizers((taskExecutor) -> {
this.builder.queueCapacity(10).corePoolSize(4).maxPoolSize(8)
.allowCoreThreadTimeOut(true).keepAlive(Duration.ofMinutes(1))
.threadNamePrefix("test-").taskDecorator(taskDecorator)
.additionalCustomizers((taskExecutor) -> {
verify(taskExecutor).setQueueCapacity(10);
verify(taskExecutor).setCorePoolSize(4);
verify(taskExecutor).setMaxPoolSize(8);

View File

@ -440,8 +440,7 @@ public class RestTemplateBuilderTests {
public void connectTimeoutCanBeNullToUseDefault() {
ClientHttpRequestFactory requestFactory = this.builder
.requestFactory(SimpleClientHttpRequestFactory.class)
.setConnectTimeout(Duration.ofSeconds(5)).setConnectTimeout(null).build()
.getRequestFactory();
.setConnectTimeout(null).build().getRequestFactory();
assertThat(ReflectionTestUtils.getField(requestFactory, "connectTimeout"))
.isEqualTo(-1);
}
@ -449,9 +448,8 @@ public class RestTemplateBuilderTests {
@Test
public void readTimeoutCanBeNullToUseDefault() {
ClientHttpRequestFactory requestFactory = this.builder
.requestFactory(SimpleClientHttpRequestFactory.class)
.setReadTimeout(Duration.ofSeconds(5)).setReadTimeout(null).build()
.getRequestFactory();
.requestFactory(SimpleClientHttpRequestFactory.class).setReadTimeout(null)
.build().getRequestFactory();
assertThat(ReflectionTestUtils.getField(requestFactory, "readTimeout"))
.isEqualTo(-1);
}

View File

@ -48,8 +48,7 @@ public class SampleKafkaApplicationTests {
&& System.currentTimeMillis() < end) {
Thread.sleep(250);
}
assertThat(this.outputCapture.toString().contains("A simple test message"))
.isTrue();
assertThat(this.outputCapture.toString()).contains("A simple test message");
}
}