|
28 | 28 | import reactor.core.publisher.Mono;
|
29 | 29 | import reactor.util.context.Context;
|
30 | 30 |
|
| 31 | +import org.springframework.boot.LazyInitializationBeanFactoryPostProcessor; |
31 | 32 | import org.springframework.boot.autoconfigure.AutoConfigurations;
|
32 | 33 | import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
33 | 34 |
|
@@ -81,13 +82,26 @@ void shouldNotConfigurePropagationByDefault() {
|
81 | 82 | @Test
|
82 | 83 | void shouldConfigurePropagationIfSetToAuto() {
|
83 | 84 | AtomicReference<String> threadLocalValue = new AtomicReference<>();
|
84 |
| - this.contextRunner.withPropertyValues("spring.reactor.context-propagation=auto").run((applicationContext) -> { |
85 |
| - Mono.just("test") |
86 |
| - .doOnNext((element) -> threadLocalValue.set(THREADLOCAL_VALUE.get())) |
87 |
| - .contextWrite(Context.of(THREADLOCAL_KEY, "updated")) |
88 |
| - .block(); |
89 |
| - assertThat(threadLocalValue.get()).isEqualTo("updated"); |
90 |
| - }); |
| 85 | + this.contextRunner.withPropertyValues("spring.reactor.context-propagation=auto") |
| 86 | + .run((applicationContext) -> assertThatPropagationIsWorking(threadLocalValue)); |
| 87 | + } |
| 88 | + |
| 89 | + @Test |
| 90 | + void shouldConfigurePropagationIfSetToAutoAndLazyInitializationIsEnabled() { |
| 91 | + AtomicReference<String> threadLocalValue = new AtomicReference<>(); |
| 92 | + this.contextRunner |
| 93 | + .withInitializer( |
| 94 | + (context) -> context.addBeanFactoryPostProcessor(new LazyInitializationBeanFactoryPostProcessor())) |
| 95 | + .withPropertyValues("spring.reactor.context-propagation=auto") |
| 96 | + .run((context) -> assertThatPropagationIsWorking(threadLocalValue)); |
| 97 | + } |
| 98 | + |
| 99 | + private void assertThatPropagationIsWorking(AtomicReference<String> threadLocalValue) { |
| 100 | + Mono.just("test") |
| 101 | + .doOnNext((element) -> threadLocalValue.set(THREADLOCAL_VALUE.get())) |
| 102 | + .contextWrite(Context.of(THREADLOCAL_KEY, "updated")) |
| 103 | + .block(); |
| 104 | + assertThat(threadLocalValue.get()).isEqualTo("updated"); |
91 | 105 | }
|
92 | 106 |
|
93 | 107 | }
|
0 commit comments