Skip to content

Commit 4fadad4

Browse files
committed
Merge pull request #44921 from nosan
* pr/44921: Add test for 'force' async mode with @primary custom executor Closes gh-44921
2 parents e5a05ec + f312c90 commit 4fadad4

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,23 @@ public Executor getAsyncExecutor() {
348348
});
349349
}
350350

351+
@Test
352+
void enableAsyncUsesAutoConfiguredExecutorWhenModeIsForceAndHasPrimaryCustomTaskExecutor() {
353+
this.contextRunner
354+
.withPropertyValues("spring.task.execution.thread-name-prefix=auto-task-",
355+
"spring.task.execution.mode=force")
356+
.withBean("taskExecutor", Executor.class, () -> createCustomAsyncExecutor("custom-task-"),
357+
(bd) -> bd.setPrimary(true))
358+
.withUserConfiguration(AsyncConfiguration.class, TestBean.class)
359+
.run((context) -> {
360+
assertThat(context).hasSingleBean(AsyncConfigurer.class);
361+
assertThat(context.getBeansOfType(Executor.class)).hasSize(2);
362+
TestBean bean = context.getBean(TestBean.class);
363+
String text = bean.echo("something").get();
364+
assertThat(text).contains("auto-task-").contains("something");
365+
});
366+
}
367+
351368
private Executor createCustomAsyncExecutor(String threadNamePrefix) {
352369
SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor();
353370
executor.setThreadNamePrefix(threadNamePrefix);

0 commit comments

Comments
 (0)