Commit 10c3c080 authored by Stephane Nicoll's avatar Stephane Nicoll

Merge pull request #14212 from izeye:polish-20180828

* pr/14212:
  Polish
parents a86d7cdb cf17106d
...@@ -22,6 +22,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; ...@@ -22,6 +22,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
* Configuration properties for task scheduling. * Configuration properties for task scheduling.
* *
* @author Stephane Nicoll * @author Stephane Nicoll
* @since 2.1.0
*/ */
@ConfigurationProperties("spring.task.scheduling") @ConfigurationProperties("spring.task.scheduling")
public class TaskSchedulingProperties { public class TaskSchedulingProperties {
......
...@@ -96,7 +96,6 @@ org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration,\ ...@@ -96,7 +96,6 @@ org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration,\
org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration,\ org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration,\
org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration,\ org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration,\
org.springframework.boot.autoconfigure.reactor.core.ReactorCoreAutoConfiguration,\ 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.SecurityAutoConfiguration,\
org.springframework.boot.autoconfigure.security.servlet.SecurityRequestMatcherProviderAutoConfiguration,\ org.springframework.boot.autoconfigure.security.servlet.SecurityRequestMatcherProviderAutoConfiguration,\
org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration,\ org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration,\
...@@ -111,6 +110,7 @@ org.springframework.boot.autoconfigure.security.oauth2.resource.servlet.OAuth2Re ...@@ -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.security.oauth2.resource.reactive.ReactiveOAuth2ResourceServerAutoConfiguration,\
org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration,\ org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration,\
org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration,\ org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration,\
org.springframework.boot.autoconfigure.task.TaskSchedulingAutoConfiguration,\
org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration,\ org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration,\
org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration,\ org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration,\
org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration,\ org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration,\
......
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
package org.springframework.boot.autoconfigure.task; package org.springframework.boot.autoconfigure.task;
import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.junit.Test; import org.junit.Test;
...@@ -158,7 +158,7 @@ public class TaskSchedulingAutoConfigurationTests { ...@@ -158,7 +158,7 @@ public class TaskSchedulingAutoConfigurationTests {
static class TestBean { static class TestBean {
private final Set<String> threadNames = new HashSet<>(); private final Set<String> threadNames = ConcurrentHashMap.newKeySet();
@Scheduled(fixedRate = 10) @Scheduled(fixedRate = 10)
public void accumulate() { public void accumulate() {
......
...@@ -517,7 +517,7 @@ public class WebFluxAutoConfigurationTests { ...@@ -517,7 +517,7 @@ public class WebFluxAutoConfigurationTests {
static class CustomRequestMappingHandlerAdapter { static class CustomRequestMappingHandlerAdapter {
@Bean @Bean
public WebFluxRegistrations webMvcRegistrationsHandlerAdapter() { public WebFluxRegistrations webFluxRegistrationsHandlerAdapter() {
return new WebFluxRegistrations() { return new WebFluxRegistrations() {
@Override @Override
...@@ -546,7 +546,7 @@ public class WebFluxAutoConfigurationTests { ...@@ -546,7 +546,7 @@ public class WebFluxAutoConfigurationTests {
static class CustomRequestMappingHandlerMapping { static class CustomRequestMappingHandlerMapping {
@Bean @Bean
public WebFluxRegistrations webMvcRegistrationsHandlerMapping() { public WebFluxRegistrations webFluxRegistrationsHandlerMapping() {
return new WebFluxRegistrations() { return new WebFluxRegistrations() {
@Override @Override
......
...@@ -6201,11 +6201,11 @@ tasks), the thread pool increases to maximum 16 threads. Shrinking of the pool i ...@@ -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 aggressive as threads are reclaimed when they are idle for 10 seconds (rather than
60 seconds by default). 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 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. 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. context if a custom executor or scheduler needs to be created.
......
...@@ -52,7 +52,7 @@ public class PropertyMapperTests { ...@@ -52,7 +52,7 @@ public class PropertyMapperTests {
} }
@Test @Test
public void fromValueAsIntShouldAdaptSupplier() { public void fromValueAsIntShouldAdaptValue() {
Integer result = this.map.from("123").asInt(Long::valueOf) Integer result = this.map.from("123").asInt(Long::valueOf)
.toInstance(Integer::new); .toInstance(Integer::new);
assertThat(result).isEqualTo(123); assertThat(result).isEqualTo(123);
......
...@@ -22,11 +22,14 @@ import java.util.Set; ...@@ -22,11 +22,14 @@ import java.util.Set;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import org.mockito.Mockito;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import static org.assertj.core.api.Assertions.assertThat; 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}. * Tests for {@link TaskSchedulerBuilder}.
...@@ -55,8 +58,9 @@ public class TaskSchedulerBuilderTests { ...@@ -55,8 +58,9 @@ public class TaskSchedulerBuilderTests {
@Test @Test
public void threadNamePrefixShouldApply() { public void threadNamePrefixShouldApply() {
ThreadPoolTaskScheduler executor = this.builder.threadNamePrefix("test-").build(); ThreadPoolTaskScheduler scheduler = this.builder.threadNamePrefix("test-")
assertThat(executor.getThreadNamePrefix()).isEqualTo("test-"); .build();
assertThat(scheduler.getThreadNamePrefix()).isEqualTo("test-");
} }
@Test @Test
...@@ -75,30 +79,30 @@ public class TaskSchedulerBuilderTests { ...@@ -75,30 +79,30 @@ public class TaskSchedulerBuilderTests {
@Test @Test
public void customizersShouldApply() { public void customizersShouldApply() {
TaskSchedulerCustomizer customizer = Mockito.mock(TaskSchedulerCustomizer.class); TaskSchedulerCustomizer customizer = mock(TaskSchedulerCustomizer.class);
ThreadPoolTaskScheduler executor = this.builder.customizers(customizer).build(); ThreadPoolTaskScheduler scheduler = this.builder.customizers(customizer).build();
Mockito.verify(customizer).customize(executor); verify(customizer).customize(scheduler);
} }
@Test @Test
public void customizersShouldBeAppliedLast() { public void customizersShouldBeAppliedLast() {
ThreadPoolTaskScheduler scheduler = Mockito.spy(new ThreadPoolTaskScheduler()); ThreadPoolTaskScheduler scheduler = spy(new ThreadPoolTaskScheduler());
this.builder.poolSize(4).threadNamePrefix("test-") this.builder.poolSize(4).threadNamePrefix("test-")
.additionalCustomizers((taskScheduler) -> { .additionalCustomizers((taskScheduler) -> {
Mockito.verify(taskScheduler).setPoolSize(4); verify(taskScheduler).setPoolSize(4);
Mockito.verify(taskScheduler).setThreadNamePrefix("test-"); verify(taskScheduler).setThreadNamePrefix("test-");
}); });
this.builder.configure(scheduler); this.builder.configure(scheduler);
} }
@Test @Test
public void customizersShouldReplaceExisting() { public void customizersShouldReplaceExisting() {
TaskSchedulerCustomizer customizer1 = Mockito.mock(TaskSchedulerCustomizer.class); TaskSchedulerCustomizer customizer1 = mock(TaskSchedulerCustomizer.class);
TaskSchedulerCustomizer customizer2 = Mockito.mock(TaskSchedulerCustomizer.class); TaskSchedulerCustomizer customizer2 = mock(TaskSchedulerCustomizer.class);
ThreadPoolTaskScheduler executor = this.builder.customizers(customizer1) ThreadPoolTaskScheduler scheduler = this.builder.customizers(customizer1)
.customizers(Collections.singleton(customizer2)).build(); .customizers(Collections.singleton(customizer2)).build();
Mockito.verifyZeroInteractions(customizer1); verifyZeroInteractions(customizer1);
Mockito.verify(customizer2).customize(executor); verify(customizer2).customize(scheduler);
} }
@Test @Test
...@@ -117,12 +121,12 @@ public class TaskSchedulerBuilderTests { ...@@ -117,12 +121,12 @@ public class TaskSchedulerBuilderTests {
@Test @Test
public void additionalCustomizersShouldAddToExisting() { public void additionalCustomizersShouldAddToExisting() {
TaskSchedulerCustomizer customizer1 = Mockito.mock(TaskSchedulerCustomizer.class); TaskSchedulerCustomizer customizer1 = mock(TaskSchedulerCustomizer.class);
TaskSchedulerCustomizer customizer2 = Mockito.mock(TaskSchedulerCustomizer.class); TaskSchedulerCustomizer customizer2 = mock(TaskSchedulerCustomizer.class);
ThreadPoolTaskScheduler scheduler = this.builder.customizers(customizer1) ThreadPoolTaskScheduler scheduler = this.builder.customizers(customizer1)
.additionalCustomizers(customizer2).build(); .additionalCustomizers(customizer2).build();
Mockito.verify(customizer1).customize(scheduler); verify(customizer1).customize(scheduler);
Mockito.verify(customizer2).customize(scheduler); verify(customizer2).customize(scheduler);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment