Closes gh-14212
pull/14213/head
Johnny Lim 6 years ago committed by Stephane Nicoll
parent a86d7cdb97
commit cf17106d8d

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

@ -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,\

@ -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<String> threadNames = new HashSet<>();
private final Set<String> threadNames = ConcurrentHashMap.newKeySet();
@Scheduled(fixedRate = 10)
public void accumulate() {

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

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

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

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

Loading…
Cancel
Save