Add test for 'force' async mode with @Primary custom executor

See gh-44921

Signed-off-by: Dmytro Nosan <dimanosan@gmail.com>
This commit is contained in:
Dmytro Nosan
2025-03-27 21:01:20 +02:00
committed by Stéphane Nicoll
parent e5a05ec7da
commit f312c9083b

View File

@@ -348,6 +348,23 @@ class TaskExecutionAutoConfigurationTests {
});
}
@Test
void enableAsyncUsesAutoConfiguredExecutorWhenModeIsForceAndHasPrimaryCustomTaskExecutor() {
this.contextRunner
.withPropertyValues("spring.task.execution.thread-name-prefix=auto-task-",
"spring.task.execution.mode=force")
.withBean("taskExecutor", Executor.class, () -> createCustomAsyncExecutor("custom-task-"),
(bd) -> bd.setPrimary(true))
.withUserConfiguration(AsyncConfiguration.class, TestBean.class)
.run((context) -> {
assertThat(context).hasSingleBean(AsyncConfigurer.class);
assertThat(context.getBeansOfType(Executor.class)).hasSize(2);
TestBean bean = context.getBean(TestBean.class);
String text = bean.echo("something").get();
assertThat(text).contains("auto-task-").contains("something");
});
}
private Executor createCustomAsyncExecutor(String threadNamePrefix) {
SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor();
executor.setThreadNamePrefix(threadNamePrefix);