|
|
|
|
@ -17,8 +17,10 @@
@@ -17,8 +17,10 @@
|
|
|
|
|
package org.springframework.boot.autoconfigure.netty; |
|
|
|
|
|
|
|
|
|
import io.netty.util.ResourceLeakDetector; |
|
|
|
|
import org.junit.jupiter.api.AfterEach; |
|
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
|
|
|
|
|
|
import org.springframework.boot.LazyInitializationBeanFactoryPostProcessor; |
|
|
|
|
import org.springframework.boot.autoconfigure.AutoConfigurations; |
|
|
|
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner; |
|
|
|
|
|
|
|
|
|
@ -34,13 +36,26 @@ class NettyAutoConfigurationTests {
@@ -34,13 +36,26 @@ class NettyAutoConfigurationTests {
|
|
|
|
|
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() |
|
|
|
|
.withConfiguration(AutoConfigurations.of(NettyAutoConfiguration.class)); |
|
|
|
|
|
|
|
|
|
@AfterEach |
|
|
|
|
void resetResourceLeakDetector() { |
|
|
|
|
ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.DISABLED); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void leakDetectionShouldBeConfigured() { |
|
|
|
|
this.contextRunner.withPropertyValues("spring.netty.leak-detection=paranoid").run((context) -> { |
|
|
|
|
assertThat(ResourceLeakDetector.getLevel()).isEqualTo(ResourceLeakDetector.Level.PARANOID); |
|
|
|
|
// reset configuration for the following tests.
|
|
|
|
|
ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.DISABLED); |
|
|
|
|
}); |
|
|
|
|
this.contextRunner.withPropertyValues("spring.netty.leak-detection=paranoid") |
|
|
|
|
.run((context) -> assertThat(ResourceLeakDetector.getLevel()) |
|
|
|
|
.isEqualTo(ResourceLeakDetector.Level.PARANOID)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void leakDetectionShouldBeConfiguredWhenLazyInitializationIsEnabled() { |
|
|
|
|
this.contextRunner |
|
|
|
|
.withInitializer( |
|
|
|
|
(context) -> context.addBeanFactoryPostProcessor(new LazyInitializationBeanFactoryPostProcessor())) |
|
|
|
|
.withPropertyValues("spring.netty.leak-detection=advanced") |
|
|
|
|
.run((context) -> assertThat(ResourceLeakDetector.getLevel()) |
|
|
|
|
.isEqualTo(ResourceLeakDetector.Level.ADVANCED)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|