From d5eaaf6e2a92f235b2bca87839e4284bebbf7740 Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Mon, 13 Aug 2018 22:47:04 +0900 Subject: [PATCH] Polish Closes gh-14049 --- .../task/TaskExecutorAutoConfiguration.java | 17 ++++++----------- .../boot/autoconfigure/task/TaskProperties.java | 4 ++-- .../TaskExecutorAutoConfigurationTests.java | 14 +++++++------- .../appendix-application-properties.adoc | 2 +- .../src/main/asciidoc/spring-boot-features.adoc | 8 ++++---- .../boot/json/JsonParserFactory.java | 2 +- .../boot/task/TaskExecutorBuilder.java | 10 +++++----- ...nDefinitionOverrideFailureAnalyzerTests.java | 2 +- .../boot/task/TaskExecutorBuilderTests.java | 14 +++++++------- .../web/client/RestTemplateBuilderTests.java | 8 +++----- .../kafka/SampleKafkaApplicationTests.java | 3 +-- 11 files changed, 38 insertions(+), 46 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/task/TaskExecutorAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/task/TaskExecutorAutoConfiguration.java index b3be0b377e3..a5c93e413f6 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/task/TaskExecutorAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/task/TaskExecutorAutoConfiguration.java @@ -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) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/task/TaskProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/task/TaskProperties.java index add12aa1967..84e38a369e8 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/task/TaskProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/task/TaskProperties.java @@ -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; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/task/TaskExecutorAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/task/TaskExecutorAutoConfigurationTests.java index 93c15cb108c..be3a7c9bbbe 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/task/TaskExecutorAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/task/TaskExecutorAutoConfigurationTests.java @@ -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(); } diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index e6aa62eb333..2bbd68963b3 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -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. # ---------------------------------------- diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index 8d39881548d..3788b7230bf 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -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). diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/json/JsonParserFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/json/JsonParserFactory.java index 737af957ef9..208ea227a5d 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/json/JsonParserFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/json/JsonParserFactory.java @@ -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() { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/task/TaskExecutorBuilder.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/task/TaskExecutorBuilder.java index 5c3c7e7b3e2..ca11bb530c1 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/task/TaskExecutorBuilder.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/task/TaskExecutorBuilder.java @@ -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 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 build(Class taskExecutorClass) { @@ -274,8 +274,8 @@ public class TaskExecutorBuilder { * @param 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 configure(T taskExecutor) { PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull(); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BeanDefinitionOverrideFailureAnalyzerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BeanDefinitionOverrideFailureAnalyzerTests.java index 861e52159df..3b55197f056 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BeanDefinitionOverrideFailureAnalyzerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BeanDefinitionOverrideFailureAnalyzerTests.java @@ -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 " diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/task/TaskExecutorBuilderTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/task/TaskExecutorBuilderTests.java index 2f560eb81ee..506fcaa7eb4 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/task/TaskExecutorBuilderTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/task/TaskExecutorBuilderTests.java @@ -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); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/RestTemplateBuilderTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/RestTemplateBuilderTests.java index 7972841fa21..5e0f08f8f88 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/RestTemplateBuilderTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/RestTemplateBuilderTests.java @@ -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); } diff --git a/spring-boot-samples/spring-boot-sample-kafka/src/test/java/sample/kafka/SampleKafkaApplicationTests.java b/spring-boot-samples/spring-boot-sample-kafka/src/test/java/sample/kafka/SampleKafkaApplicationTests.java index 7123c19a30c..72399feefa5 100644 --- a/spring-boot-samples/spring-boot-sample-kafka/src/test/java/sample/kafka/SampleKafkaApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-kafka/src/test/java/sample/kafka/SampleKafkaApplicationTests.java @@ -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"); } }