From cf17106d8ded5f7be4a8920d2ff438404afcd18a Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Tue, 28 Aug 2018 00:15:46 +0900 Subject: [PATCH] Polish Closes gh-14212 --- .../task/TaskSchedulingProperties.java | 1 + .../main/resources/META-INF/spring.factories | 2 +- .../TaskSchedulingAutoConfigurationTests.java | 4 +- .../WebFluxAutoConfigurationTests.java | 4 +- .../main/asciidoc/spring-boot-features.adoc | 4 +- .../properties/PropertyMapperTests.java | 2 +- .../boot/task/TaskSchedulerBuilderTests.java | 40 ++++++++++--------- 7 files changed, 31 insertions(+), 26 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/task/TaskSchedulingProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/task/TaskSchedulingProperties.java index 27ee57c2acf..1edb46bb691 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/task/TaskSchedulingProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/task/TaskSchedulingProperties.java @@ -22,6 +22,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; * Configuration properties for task scheduling. * * @author Stephane Nicoll + * @since 2.1.0 */ @ConfigurationProperties("spring.task.scheduling") public class TaskSchedulingProperties { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories b/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories index cf88c0a33c1..1070f995bd4 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories @@ -96,7 +96,6 @@ org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration,\ org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration,\ org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration,\ org.springframework.boot.autoconfigure.reactor.core.ReactorCoreAutoConfiguration,\ -org.springframework.boot.autoconfigure.task.TaskSchedulingAutoConfiguration,\ org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration,\ org.springframework.boot.autoconfigure.security.servlet.SecurityRequestMatcherProviderAutoConfiguration,\ org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration,\ @@ -111,6 +110,7 @@ org.springframework.boot.autoconfigure.security.oauth2.resource.servlet.OAuth2Re org.springframework.boot.autoconfigure.security.oauth2.resource.reactive.ReactiveOAuth2ResourceServerAutoConfiguration,\ org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration,\ org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration,\ +org.springframework.boot.autoconfigure.task.TaskSchedulingAutoConfiguration,\ org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration,\ org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration,\ org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration,\ diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/task/TaskSchedulingAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/task/TaskSchedulingAutoConfigurationTests.java index 6ce10dcc183..afb863aa287 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/task/TaskSchedulingAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/task/TaskSchedulingAutoConfigurationTests.java @@ -16,8 +16,8 @@ package org.springframework.boot.autoconfigure.task; -import java.util.HashSet; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import org.junit.Test; @@ -158,7 +158,7 @@ public class TaskSchedulingAutoConfigurationTests { static class TestBean { - private final Set threadNames = new HashSet<>(); + private final Set threadNames = ConcurrentHashMap.newKeySet(); @Scheduled(fixedRate = 10) public void accumulate() { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfigurationTests.java index 74cc41e867b..4857f023f11 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfigurationTests.java @@ -517,7 +517,7 @@ public class WebFluxAutoConfigurationTests { static class CustomRequestMappingHandlerAdapter { @Bean - public WebFluxRegistrations webMvcRegistrationsHandlerAdapter() { + public WebFluxRegistrations webFluxRegistrationsHandlerAdapter() { return new WebFluxRegistrations() { @Override @@ -546,7 +546,7 @@ public class WebFluxAutoConfigurationTests { static class CustomRequestMappingHandlerMapping { @Bean - public WebFluxRegistrations webMvcRegistrationsHandlerMapping() { + public WebFluxRegistrations webFluxRegistrationsHandlerMapping() { return new WebFluxRegistrations() { @Override 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 f0bae95a8e0..9b2cd915248 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 @@ -6201,11 +6201,11 @@ tasks), the thread pool increases to maximum 16 threads. Shrinking of the pool i aggressive as threads are reclaimed when they are idle for 10 seconds (rather than 60 seconds by default). -A `ThreadPoolTaskScheduler` can also be auto-configured if need to be to be associated to +A `ThreadPoolTaskScheduler` can also be auto-configured if need to be associated to scheduled task execution (`@EnableScheduling`). The thread pool uses one thread by default and those settings can be fine-tuned using the `spring.task.scheduling` namespace. -Both a `TaskExecutorBuilder` and `TaskSchedulerBuilder` bean are made available in the +Both a `TaskExecutorBuilder` bean and a `TaskSchedulerBuilder` bean are made available in the context if a custom executor or scheduler needs to be created. diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/PropertyMapperTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/PropertyMapperTests.java index 7b0d5ef985e..d0d1760e45c 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/PropertyMapperTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/PropertyMapperTests.java @@ -52,7 +52,7 @@ public class PropertyMapperTests { } @Test - public void fromValueAsIntShouldAdaptSupplier() { + public void fromValueAsIntShouldAdaptValue() { Integer result = this.map.from("123").asInt(Long::valueOf) .toInstance(Integer::new); assertThat(result).isEqualTo(123); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/task/TaskSchedulerBuilderTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/task/TaskSchedulerBuilderTests.java index 839cae4393a..39a9a5bf632 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/task/TaskSchedulerBuilderTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/task/TaskSchedulerBuilderTests.java @@ -22,11 +22,14 @@ import java.util.Set; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.mockito.Mockito; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyZeroInteractions; /** * Tests for {@link TaskSchedulerBuilder}. @@ -55,8 +58,9 @@ public class TaskSchedulerBuilderTests { @Test public void threadNamePrefixShouldApply() { - ThreadPoolTaskScheduler executor = this.builder.threadNamePrefix("test-").build(); - assertThat(executor.getThreadNamePrefix()).isEqualTo("test-"); + ThreadPoolTaskScheduler scheduler = this.builder.threadNamePrefix("test-") + .build(); + assertThat(scheduler.getThreadNamePrefix()).isEqualTo("test-"); } @Test @@ -75,30 +79,30 @@ public class TaskSchedulerBuilderTests { @Test public void customizersShouldApply() { - TaskSchedulerCustomizer customizer = Mockito.mock(TaskSchedulerCustomizer.class); - ThreadPoolTaskScheduler executor = this.builder.customizers(customizer).build(); - Mockito.verify(customizer).customize(executor); + TaskSchedulerCustomizer customizer = mock(TaskSchedulerCustomizer.class); + ThreadPoolTaskScheduler scheduler = this.builder.customizers(customizer).build(); + verify(customizer).customize(scheduler); } @Test public void customizersShouldBeAppliedLast() { - ThreadPoolTaskScheduler scheduler = Mockito.spy(new ThreadPoolTaskScheduler()); + ThreadPoolTaskScheduler scheduler = spy(new ThreadPoolTaskScheduler()); this.builder.poolSize(4).threadNamePrefix("test-") .additionalCustomizers((taskScheduler) -> { - Mockito.verify(taskScheduler).setPoolSize(4); - Mockito.verify(taskScheduler).setThreadNamePrefix("test-"); + verify(taskScheduler).setPoolSize(4); + verify(taskScheduler).setThreadNamePrefix("test-"); }); this.builder.configure(scheduler); } @Test public void customizersShouldReplaceExisting() { - TaskSchedulerCustomizer customizer1 = Mockito.mock(TaskSchedulerCustomizer.class); - TaskSchedulerCustomizer customizer2 = Mockito.mock(TaskSchedulerCustomizer.class); - ThreadPoolTaskScheduler executor = this.builder.customizers(customizer1) + TaskSchedulerCustomizer customizer1 = mock(TaskSchedulerCustomizer.class); + TaskSchedulerCustomizer customizer2 = mock(TaskSchedulerCustomizer.class); + ThreadPoolTaskScheduler scheduler = this.builder.customizers(customizer1) .customizers(Collections.singleton(customizer2)).build(); - Mockito.verifyZeroInteractions(customizer1); - Mockito.verify(customizer2).customize(executor); + verifyZeroInteractions(customizer1); + verify(customizer2).customize(scheduler); } @Test @@ -117,12 +121,12 @@ public class TaskSchedulerBuilderTests { @Test public void additionalCustomizersShouldAddToExisting() { - TaskSchedulerCustomizer customizer1 = Mockito.mock(TaskSchedulerCustomizer.class); - TaskSchedulerCustomizer customizer2 = Mockito.mock(TaskSchedulerCustomizer.class); + TaskSchedulerCustomizer customizer1 = mock(TaskSchedulerCustomizer.class); + TaskSchedulerCustomizer customizer2 = mock(TaskSchedulerCustomizer.class); ThreadPoolTaskScheduler scheduler = this.builder.customizers(customizer1) .additionalCustomizers(customizer2).build(); - Mockito.verify(customizer1).customize(scheduler); - Mockito.verify(customizer2).customize(scheduler); + verify(customizer1).customize(scheduler); + verify(customizer2).customize(scheduler); } }