Skip to content

Commit bcf2d85

Browse files
committed
Merge pull request #14049 from izeye:polish-20180813
* pr/14049: Polish
2 parents d0f2729 + d5eaaf6 commit bcf2d85

File tree

11 files changed

+38
-46
lines changed

11 files changed

+38
-46
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/task/TaskExecutorAutoConfiguration.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,15 @@ public TaskExecutorAutoConfiguration(TaskProperties properties,
6565
@Bean
6666
@ConditionalOnMissingBean
6767
public TaskExecutorBuilder taskExecutorBuilder() {
68-
TaskExecutorBuilder builder = new TaskExecutorBuilder();
6968
TaskProperties.Pool pool = this.properties.getPool();
70-
builder = builder.queueCapacity(pool.getQueueCapacity())
69+
return new TaskExecutorBuilder().queueCapacity(pool.getQueueCapacity())
7170
.corePoolSize(pool.getCoreSize()).maxPoolSize(pool.getMaxSize())
7271
.allowCoreThreadTimeOut(pool.isAllowCoreThreadTimeout())
73-
.keepAlive(pool.getKeepAlive());
74-
builder = builder.threadNamePrefix(this.properties.getThreadNamePrefix());
75-
builder = builder.customizers(
76-
this.taskExecutorCustomizers.stream().collect(Collectors.toList()));
77-
TaskDecorator taskDecorator = this.taskDecorator.getIfUnique();
78-
if (taskDecorator != null) {
79-
builder = builder.taskDecorator(taskDecorator);
80-
}
81-
return builder;
72+
.keepAlive(pool.getKeepAlive())
73+
.threadNamePrefix(this.properties.getThreadNamePrefix())
74+
.customizers(this.taskExecutorCustomizers.stream()
75+
.collect(Collectors.toList()))
76+
.taskDecorator(this.taskDecorator.getIfUnique());
8277
}
8378

8479
@Bean(name = APPLICATION_TASK_EXECUTOR_BEAN_NAME)

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/task/TaskProperties.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ public void setThreadNamePrefix(String threadNamePrefix) {
5050
public static class Pool {
5151

5252
/**
53-
* Queue capacity. A unbounded capacity does not increase the pool and therefore
54-
* ignores the "max-size" parameter.
53+
* Queue capacity. An unbounded capacity does not increase the pool and therefore
54+
* ignores the "max-size" property.
5555
*/
5656
private int queueCapacity = Integer.MAX_VALUE;
5757

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/task/TaskExecutorAutoConfigurationTests.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,19 @@ public void taskExecutorAutoConfigured() {
109109
}
110110

111111
@Test
112-
public void taskExecutorWhenHasCustomTaskExecutorShouldBAckOff() {
112+
public void taskExecutorWhenHasCustomTaskExecutorShouldBackOff() {
113113
this.contextRunner.withUserConfiguration(CustomTaskExecutorConfig.class)
114114
.run((context) -> {
115115
assertThat(context).hasSingleBean(Executor.class);
116116
assertThat(context.getBean(Executor.class))
117-
.isSameAs(context.getBean("customTaskExecutorBuilder"));
117+
.isSameAs(context.getBean("customTaskExecutor"));
118118
});
119119
}
120120

121121
@Test
122122
public void taskExecutorBuilderShouldApplyCustomizer() {
123-
this.contextRunner.withUserConfiguration(CustomTaskExecutorConfig.class,
124-
TaskExecutorCustomizerConfig.class).run((context) -> {
123+
this.contextRunner.withUserConfiguration(TaskExecutorCustomizerConfig.class)
124+
.run((context) -> {
125125
TaskExecutorCustomizer customizer = context
126126
.getBean(TaskExecutorCustomizer.class);
127127
ThreadPoolTaskExecutor executor = context
@@ -138,8 +138,8 @@ public void enableAsyncUsesAutoConfiguredOneByDefault() {
138138
.run((context) -> {
139139
assertThat(context).hasSingleBean(TaskExecutor.class);
140140
TestBean bean = context.getBean(TestBean.class);
141-
String text = bean.echo("test").get();
142-
assertThat(text).contains("executor-test-").contains("test");
141+
String text = bean.echo("something").get();
142+
assertThat(text).contains("executor-test-").contains("something");
143143
});
144144
}
145145

@@ -188,7 +188,7 @@ public TaskDecorator mockTaskDecorator() {
188188
static class CustomTaskExecutorConfig {
189189

190190
@Bean
191-
public Executor customTaskExecutorBuilder() {
191+
public Executor customTaskExecutor() {
192192
return new SyncTaskExecutor();
193193
}
194194

spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ content into your application. Rather, pick only the properties that you need.
166166
spring.task.pool.core-size=8 # Core number of threads.
167167
spring.task.pool.keep-alive=60s # Time limit for which threads may remain idle before being terminated.
168168
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.
169-
spring.task.pool.queue-capacity= # Queue capacity. A unbounded capacity does not increase the pool and therefore ignores the "max-size" parameter.
169+
spring.task.pool.queue-capacity= # Queue capacity. An unbounded capacity does not increase the pool and therefore ignores the "max-size" property.
170170
spring.task.thread-name-prefix=executor- # Prefix to use for the names of newly created threads.
171171
172172
# ----------------------------------------

spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4638,7 +4638,7 @@ URLs of your server in your application.properties, as shown in the following ex
46384638
If you need to customize connection settings, you can use the `spring.ldap.base` and
46394639
`spring.ldap.base-environment` properties.
46404640

4641-
A `LdapContextSource` is auto-configured based on these settings. If you need to customize
4641+
An `LdapContextSource` is auto-configured based on these settings. If you need to customize
46424642
it, for instance to use a `PooledContextSource`, you can still inject the auto-configured
46434643
`LdapContextSource`. Make sure to flag your customized `ContextSource` as `@Primary` so
46444644
that the auto-configured `LdapTemplate` uses it.
@@ -6156,7 +6156,7 @@ following example:
61566156

61576157
This changes the thread pool to use a bounded queue so that when the queue is full (100
61586158
tasks), the thread pool increases to maximum 16 threads. Shrinking of the pool is more
6159-
aggressive as well as threads are reclaimed when they are idle for 10 seconds (rather than
6159+
aggressive as threads are reclaimed when they are idle for 10 seconds (rather than
61606160
60 seconds by default).
61616161

61626162

@@ -6334,8 +6334,8 @@ web application.
63346334
* `RANDOM_PORT`: Loads a `WebServerApplicationContext` and provides a real web
63356335
environment. Embedded servers are started and listen on a random port.
63366336
* `DEFINED_PORT`: Loads a `WebServerApplicationContext` and provides a real web
6337-
environment. Embedded servers are started and listen on a defined port (from your
6338-
`application.properties` or on the default port of `8080`).
6337+
environment. Embedded servers are started and listen on a defined port (from your
6338+
`application.properties`) or on the default port of `8080`.
63396339
* `NONE`: Loads an `ApplicationContext` by using `SpringApplication` but does not provide
63406340
_any_ web environment (mock or otherwise).
63416341

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/json/JsonParserFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public abstract class JsonParserFactory {
3131

3232
/**
3333
* Static factory for the "best" JSON parser available on the classpath. Tries
34-
* Jackson, then Gson, Snake YAML,and then falls back to the {@link BasicJsonParser}.
34+
* Jackson, then Gson, Snake YAML, and then falls back to the {@link BasicJsonParser}.
3535
* @return a {@link JsonParser}
3636
*/
3737
public static JsonParser getJsonParser() {

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/task/TaskExecutorBuilder.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public TaskExecutorBuilder(Integer queueCapacity, Integer corePoolSize,
9090
}
9191

9292
/**
93-
* Set the capacity of the queue. A unbounded capacity does not increase the pool and
93+
* Set the capacity of the queue. An unbounded capacity does not increase the pool and
9494
* therefore ignores {@link #maxPoolSize(int) maxPoolSize}.
9595
* @param queueCapacity the queue capacity to set
9696
* @return a new builder instance
@@ -134,7 +134,7 @@ public TaskExecutorBuilder maxPoolSize(int maxPoolSize) {
134134
/**
135135
* Set whether core threads are allow to time out. When enabled, this enables dynamic
136136
* growing and shrinking of the pool.
137-
* @param allowCoreThreadTimeOut if core thread are allowed to time out
137+
* @param allowCoreThreadTimeOut if core threads are allowed to time out
138138
* @return a new builder instance
139139
*/
140140
public TaskExecutorBuilder allowCoreThreadTimeOut(boolean allowCoreThreadTimeOut) {
@@ -262,7 +262,7 @@ public ThreadPoolTaskExecutor build() {
262262
* @param <T> the type of task executor
263263
* @param taskExecutorClass the template type to create
264264
* @return a configured {@link ThreadPoolTaskExecutor} instance.
265-
* @see TaskExecutorBuilder#build()
265+
* @see #build()
266266
* @see #configure(ThreadPoolTaskExecutor)
267267
*/
268268
public <T extends ThreadPoolTaskExecutor> T build(Class<T> taskExecutorClass) {
@@ -274,8 +274,8 @@ public <T extends ThreadPoolTaskExecutor> T build(Class<T> taskExecutorClass) {
274274
* @param <T> the type of task executor
275275
* @param taskExecutor the {@link ThreadPoolTaskExecutor} to configure
276276
* @return the task executor instance
277-
* @see TaskExecutorBuilder#build()
278-
* @see TaskExecutorBuilder#build(Class)
277+
* @see #build()
278+
* @see #build(Class)
279279
*/
280280
public <T extends ThreadPoolTaskExecutor> T configure(T taskExecutor) {
281281
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BeanDefinitionOverrideFailureAnalyzerTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
public class BeanDefinitionOverrideFailureAnalyzerTests {
3636

3737
@Test
38-
public void bindExceptionWithFieldErrorsDueToValidationFailure() {
38+
public void analyzeBeanDefinitionOverrideException() {
3939
FailureAnalysis analysis = performAnalysis(BeanOverrideConfiguration.class);
4040
String description = analysis.getDescription();
4141
assertThat(description).contains("The bean 'testBean', defined in "

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/task/TaskExecutorBuilderTests.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ public void createWhenCustomizersAreNullShouldThrowException() {
5656

5757
@Test
5858
public void poolSettingsShouldApply() {
59-
ThreadPoolTaskExecutor executor = this.builder.allowCoreThreadTimeOut(true)
60-
.queueCapacity(10).corePoolSize(4).maxPoolSize(8)
61-
.allowCoreThreadTimeOut(true).keepAlive(Duration.ofMinutes(1)).build();
59+
ThreadPoolTaskExecutor executor = this.builder.queueCapacity(10).corePoolSize(4)
60+
.maxPoolSize(8).allowCoreThreadTimeOut(true)
61+
.keepAlive(Duration.ofMinutes(1)).build();
6262
DirectFieldAccessor dfa = new DirectFieldAccessor(executor);
6363
assertThat(dfa.getPropertyValue("queueCapacity")).isEqualTo(10);
6464
assertThat(executor.getCorePoolSize()).isEqualTo(4);
@@ -107,10 +107,10 @@ public void customizersShouldApply() {
107107
public void customizersShouldBeAppliedLast() {
108108
TaskDecorator taskDecorator = mock(TaskDecorator.class);
109109
ThreadPoolTaskExecutor executor = spy(new ThreadPoolTaskExecutor());
110-
this.builder.allowCoreThreadTimeOut(true).queueCapacity(10).corePoolSize(4)
111-
.maxPoolSize(8).allowCoreThreadTimeOut(true)
112-
.keepAlive(Duration.ofMinutes(1)).threadNamePrefix("test-")
113-
.taskDecorator(taskDecorator).additionalCustomizers((taskExecutor) -> {
110+
this.builder.queueCapacity(10).corePoolSize(4).maxPoolSize(8)
111+
.allowCoreThreadTimeOut(true).keepAlive(Duration.ofMinutes(1))
112+
.threadNamePrefix("test-").taskDecorator(taskDecorator)
113+
.additionalCustomizers((taskExecutor) -> {
114114
verify(taskExecutor).setQueueCapacity(10);
115115
verify(taskExecutor).setCorePoolSize(4);
116116
verify(taskExecutor).setMaxPoolSize(8);

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/RestTemplateBuilderTests.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -440,18 +440,16 @@ public void configureShouldApply() {
440440
public void connectTimeoutCanBeNullToUseDefault() {
441441
ClientHttpRequestFactory requestFactory = this.builder
442442
.requestFactory(SimpleClientHttpRequestFactory.class)
443-
.setConnectTimeout(Duration.ofSeconds(5)).setConnectTimeout(null).build()
444-
.getRequestFactory();
443+
.setConnectTimeout(null).build().getRequestFactory();
445444
assertThat(ReflectionTestUtils.getField(requestFactory, "connectTimeout"))
446445
.isEqualTo(-1);
447446
}
448447

449448
@Test
450449
public void readTimeoutCanBeNullToUseDefault() {
451450
ClientHttpRequestFactory requestFactory = this.builder
452-
.requestFactory(SimpleClientHttpRequestFactory.class)
453-
.setReadTimeout(Duration.ofSeconds(5)).setReadTimeout(null).build()
454-
.getRequestFactory();
451+
.requestFactory(SimpleClientHttpRequestFactory.class).setReadTimeout(null)
452+
.build().getRequestFactory();
455453
assertThat(ReflectionTestUtils.getField(requestFactory, "readTimeout"))
456454
.isEqualTo(-1);
457455
}

spring-boot-samples/spring-boot-sample-kafka/src/test/java/sample/kafka/SampleKafkaApplicationTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ public void testVanillaExchange() throws Exception {
4848
&& System.currentTimeMillis() < end) {
4949
Thread.sleep(250);
5050
}
51-
assertThat(this.outputCapture.toString().contains("A simple test message"))
52-
.isTrue();
51+
assertThat(this.outputCapture.toString()).contains("A simple test message");
5352
}
5453

5554
}

0 commit comments

Comments
 (0)