diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/reactor/core/ReactorCoreAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/reactor/core/ReactorCoreAutoConfiguration.java index 8daacc4d1b6..0ffd882ad42 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/reactor/core/ReactorCoreAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/reactor/core/ReactorCoreAutoConfiguration.java @@ -39,7 +39,7 @@ public class ReactorCoreAutoConfiguration { @Autowired protected void initialize(ReactorCoreProperties properties) { - if (properties.getStacktraceMode().isEnabled()) { + if (properties.isDebug()) { Hooks.onOperatorDebug(); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/reactor/core/ReactorCoreProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/reactor/core/ReactorCoreProperties.java index dcb5be0f5c2..3a5537508dd 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/reactor/core/ReactorCoreProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/reactor/core/ReactorCoreProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package org.springframework.boot.autoconfigure.reactor.core; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.DeprecatedConfigurationProperty; /** * Properties for Reactor Core. @@ -27,25 +28,36 @@ import org.springframework.boot.context.properties.ConfigurationProperties; @ConfigurationProperties(prefix = "spring.reactor") public class ReactorCoreProperties { + /** + * Whether Reactor should collect stacktrace information at runtime. + */ + private boolean debug; + private final StacktraceMode stacktraceMode = new StacktraceMode(); + public boolean isDebug() { + return this.debug; + } + + public void setDebug(boolean debug) { + this.debug = debug; + } + public StacktraceMode getStacktraceMode() { return this.stacktraceMode; } - public static class StacktraceMode { - - /** - * Whether Reactor should collect stacktrace information at runtime. - */ - private boolean enabled; + public class StacktraceMode { + @DeprecatedConfigurationProperty(replacement = "spring.reactor.debug") + @Deprecated public boolean isEnabled() { - return this.enabled; + return isDebug(); } + @Deprecated public void setEnabled(boolean enabled) { - this.enabled = enabled; + setDebug(enabled); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/reactor/core/ReactorCoreAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/reactor/core/ReactorCoreAutoConfigurationTests.java new file mode 100644 index 00000000000..2d332d48775 --- /dev/null +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/reactor/core/ReactorCoreAutoConfigurationTests.java @@ -0,0 +1,72 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure.reactor.core; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import reactor.core.publisher.Hooks; + +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.assertj.AssertableApplicationContext; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.boot.test.context.runner.ContextConsumer; +import org.springframework.test.util.ReflectionTestUtils; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link ReactorCoreAutoConfiguration}. + * + * @author Stephane Nicoll + */ +class ReactorCoreAutoConfigurationTests { + + private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(ReactorCoreAutoConfiguration.class)); + + @BeforeEach + void resetDebugFlag() { + Hooks.resetOnOperatorDebug(); + } + + @Test + void debugOperatorIsDisabledByDefault() { + this.contextRunner.run(assertDebugOperator(false)); + } + + @Test + void debugOperatorIsSetWithProperty() { + this.contextRunner.withPropertyValues("spring.reactor.debug=true") + .run(assertDebugOperator(true)); + } + + @Test + @Deprecated + void debugOperatorIsSetWithDeprecatedProperty() { + this.contextRunner + .withPropertyValues("spring.reactor.stacktrace-mode.enabled=true") + .run(assertDebugOperator(true)); + } + + private ContextConsumer assertDebugOperator( + boolean expected) { + return (context) -> assertThat( + ReflectionTestUtils.getField(Hooks.class, "GLOBAL_TRACE")) + .isEqualTo(expected); + } + +} diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsPropertyDefaultsPostProcessor.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsPropertyDefaultsPostProcessor.java index f62d5f2e1b8..9d873565199 100755 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsPropertyDefaultsPostProcessor.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsPropertyDefaultsPostProcessor.java @@ -73,7 +73,7 @@ public class DevToolsPropertyDefaultsPostProcessor implements EnvironmentPostPro properties.put("spring.mvc.log-resolved-exception", "true"); properties.put("server.error.include-stacktrace", "ALWAYS"); properties.put("server.servlet.jsp.init-parameters.development", "true"); - properties.put("spring.reactor.stacktrace-mode.enabled", "true"); + properties.put("spring.reactor.debug", "true"); PROPERTIES = Collections.unmodifiableMap(properties); }