Commit efc0a7da authored by Stephane Nicoll's avatar Stephane Nicoll

Properly assert that auto-configured TaskExecutor is lazy

This commit fixes a flawed assertion that was relying on a log message
to validate the TaskExecutor is lazy. The level of the log message has
changed in framework and broke the test. We now rather check the bean
definition.
parent eff024b0
/* /*
* Copyright 2012-2020 the original author or authors. * Copyright 2012-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -23,13 +23,13 @@ import java.util.function.Consumer; ...@@ -23,13 +23,13 @@ import java.util.function.Consumer;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.task.TaskExecutorBuilder; import org.springframework.boot.task.TaskExecutorBuilder;
import org.springframework.boot.task.TaskExecutorCustomizer; import org.springframework.boot.task.TaskExecutorCustomizer;
import org.springframework.boot.test.context.assertj.AssertableApplicationContext; import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.test.context.runner.ContextConsumer; import org.springframework.boot.test.context.runner.ContextConsumer;
import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.system.OutputCaptureExtension; import org.springframework.boot.test.system.OutputCaptureExtension;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -96,13 +96,13 @@ class TaskExecutionAutoConfigurationTests { ...@@ -96,13 +96,13 @@ class TaskExecutionAutoConfigurationTests {
} }
@Test @Test
void taskExecutorAutoConfigured(CapturedOutput output) { void taskExecutorAutoConfiguredIsLazy() {
this.contextRunner.run((context) -> { this.contextRunner.run((context) -> {
assertThat(output).doesNotContain("Initializing ExecutorService"); assertThat(context).hasSingleBean(Executor.class).hasBean("applicationTaskExecutor");
assertThat(context).hasSingleBean(Executor.class); BeanDefinition beanDefinition = context.getSourceApplicationContext().getBeanFactory()
assertThat(context).hasBean("applicationTaskExecutor"); .getBeanDefinition("applicationTaskExecutor");
assertThat(beanDefinition.isLazyInit()).isTrue();
assertThat(context).getBean("applicationTaskExecutor").isInstanceOf(ThreadPoolTaskExecutor.class); assertThat(context).getBean("applicationTaskExecutor").isInstanceOf(ThreadPoolTaskExecutor.class);
assertThat(output).contains("Initializing ExecutorService");
}); });
} }
......
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