Merge branch '2.1.x'

pull/15543/head
Stephane Nicoll 6 years ago
commit 9d67400afa

@ -18,7 +18,6 @@ package org.springframework.boot.actuate.autoconfigure.endpoint.web.documentatio
import io.micrometer.core.instrument.Clock; import io.micrometer.core.instrument.Clock;
import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics; import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics;
import io.micrometer.prometheus.PrometheusConfig;
import io.micrometer.prometheus.PrometheusMeterRegistry; import io.micrometer.prometheus.PrometheusMeterRegistry;
import io.prometheus.client.CollectorRegistry; import io.prometheus.client.CollectorRegistry;
import org.junit.Test; import org.junit.Test;
@ -54,14 +53,7 @@ public class PrometheusScrapeEndpointDocumentationTests
public PrometheusScrapeEndpoint endpoint() { public PrometheusScrapeEndpoint endpoint() {
CollectorRegistry collectorRegistry = new CollectorRegistry(true); CollectorRegistry collectorRegistry = new CollectorRegistry(true);
PrometheusMeterRegistry meterRegistry = new PrometheusMeterRegistry( PrometheusMeterRegistry meterRegistry = new PrometheusMeterRegistry(
new PrometheusConfig() { (key) -> null, collectorRegistry, Clock.SYSTEM);
@Override
public String get(String key) {
return null;
}
}, collectorRegistry, Clock.SYSTEM);
new JvmMemoryMetrics().bindTo(meterRegistry); new JvmMemoryMetrics().bindTo(meterRegistry);
return new PrometheusScrapeEndpoint(collectorRegistry); return new PrometheusScrapeEndpoint(collectorRegistry);
} }

@ -17,7 +17,6 @@
package org.springframework.boot.actuate.autoconfigure.metrics; package org.springframework.boot.actuate.autoconfigure.metrics;
import io.micrometer.core.instrument.Clock; import io.micrometer.core.instrument.Clock;
import io.micrometer.newrelic.NewRelicConfig;
import io.micrometer.newrelic.NewRelicMeterRegistry; import io.micrometer.newrelic.NewRelicMeterRegistry;
import org.junit.Test; import org.junit.Test;
@ -64,14 +63,7 @@ public class MissingRequiredConfigurationFailureAnalyzerTests {
@Bean @Bean
public NewRelicMeterRegistry meterRegistry() { public NewRelicMeterRegistry meterRegistry() {
return new NewRelicMeterRegistry(new NewRelicConfig() { return new NewRelicMeterRegistry((key) -> null, Clock.SYSTEM);
@Override
public String get(String key) {
return null;
}
}, Clock.SYSTEM);
} }
} }

@ -107,14 +107,7 @@ public class AtlasMetricsExportAutoConfigurationTests {
@Bean @Bean
public AtlasConfig customConfig() { public AtlasConfig customConfig() {
return new AtlasConfig() { return (k) -> null;
@Override
public String get(String k) {
return null;
}
};
} }
} }

@ -116,16 +116,11 @@ public class DatadogMetricsExportAutoConfigurationTests {
@Bean @Bean
public DatadogConfig customConfig() { public DatadogConfig customConfig() {
return new DatadogConfig() { return (k) -> {
@Override
public String get(String k) {
if ("datadog.apiKey".equals(k)) { if ("datadog.apiKey".equals(k)) {
return "12345"; return "12345";
} }
return null; return null;
}
}; };
} }

@ -107,14 +107,7 @@ public class GangliaMetricsExportAutoConfigurationTests {
@Bean @Bean
public GangliaConfig customConfig() { public GangliaConfig customConfig() {
return new GangliaConfig() { return (k) -> null;
@Override
public String get(String k) {
return null;
}
};
} }
} }

@ -124,16 +124,11 @@ public class GraphiteMetricsExportAutoConfigurationTests {
@Bean @Bean
public GraphiteConfig customConfig() { public GraphiteConfig customConfig() {
return new GraphiteConfig() { return (k) -> {
@Override
public String get(String k) {
if ("Graphite.apiKey".equals(k)) { if ("Graphite.apiKey".equals(k)) {
return "12345"; return "12345";
} }
return null; return null;
}
}; };
} }

@ -109,14 +109,7 @@ public class HumioMetricsExportAutoConfigurationTests {
@Bean @Bean
public HumioConfig customConfig() { public HumioConfig customConfig() {
return new HumioConfig() { return (k) -> null;
@Override
public String get(String k) {
return null;
}
};
} }
} }

@ -107,14 +107,7 @@ public class InfluxMetricsExportAutoConfigurationTests {
@Bean @Bean
public InfluxConfig customConfig() { public InfluxConfig customConfig() {
return new InfluxConfig() { return (k) -> null;
@Override
public String get(String k) {
return null;
}
};
} }
} }

@ -129,10 +129,7 @@ public class NewRelicMetricsExportAutoConfigurationTests {
@Bean @Bean
public NewRelicConfig customConfig() { public NewRelicConfig customConfig() {
return new NewRelicConfig() { return (k) -> {
@Override
public String get(String k) {
if ("newrelic.accountId".equals(k)) { if ("newrelic.accountId".equals(k)) {
return "abcde"; return "abcde";
} }
@ -140,8 +137,6 @@ public class NewRelicMetricsExportAutoConfigurationTests {
return "12345"; return "12345";
} }
return null; return null;
}
}; };
} }

@ -157,14 +157,7 @@ public class PrometheusMetricsExportAutoConfigurationTests {
@Bean @Bean
public PrometheusConfig customConfig() { public PrometheusConfig customConfig() {
return new PrometheusConfig() { return (k) -> null;
@Override
public String get(String k) {
return null;
}
};
} }
} }

@ -124,16 +124,11 @@ public class SignalFxMetricsExportAutoConfigurationTests {
@Bean @Bean
public SignalFxConfig customConfig() { public SignalFxConfig customConfig() {
return new SignalFxConfig() { return (k) -> {
@Override
public String get(String k) {
if ("signalfx.accessToken".equals(k)) { if ("signalfx.accessToken".equals(k)) {
return "abcde"; return "abcde";
} }
return null; return null;
}
}; };
} }

@ -90,14 +90,7 @@ public class SimpleMetricsExportAutoConfigurationTests {
@Bean @Bean
public SimpleConfig customConfig() { public SimpleConfig customConfig() {
return new SimpleConfig() { return (k) -> null;
@Override
public String get(String k) {
return null;
}
};
} }
} }

@ -19,7 +19,6 @@ package org.springframework.boot.actuate.endpoint.web.reactive;
import java.util.Arrays; import java.util.Arrays;
import org.junit.Test; import org.junit.Test;
import reactor.core.publisher.Mono;
import org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver; import org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver;
import org.springframework.boot.actuate.endpoint.web.EndpointMapping; import org.springframework.boot.actuate.endpoint.web.EndpointMapping;
@ -44,9 +43,7 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.context.ReactiveSecurityContextHolder; import org.springframework.security.core.context.ReactiveSecurityContextHolder;
import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.reactive.config.EnableWebFlux; import org.springframework.web.reactive.config.EnableWebFlux;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter; import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebFilterChain;
import org.springframework.web.server.adapter.WebHttpHandlerBuilder; import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -148,22 +145,13 @@ public class WebFluxEndpointIntegrationTests extends
@Bean @Bean
public WebFilter webFilter() { public WebFilter webFilter() {
return new WebFilter() { return (exchange, chain) -> chain.filter(exchange)
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(
@Override new UsernamePasswordAuthenticationToken("Alice", "secret",
public Mono<Void> filter(ServerWebExchange exchange,
WebFilterChain chain) {
return chain.filter(exchange).subscriberContext(
ReactiveSecurityContextHolder.withAuthentication(
new UsernamePasswordAuthenticationToken("Alice",
"secret",
Arrays.asList(new SimpleGrantedAuthority( Arrays.asList(new SimpleGrantedAuthority(
"ROLE_ACTUATOR"))))); "ROLE_ACTUATOR")))));
} }
};
}
} }
} }

@ -33,9 +33,7 @@ import org.springframework.boot.actuate.trace.http.Include;
import org.springframework.boot.actuate.web.trace.reactive.HttpTraceWebFilter; import org.springframework.boot.actuate.web.trace.reactive.HttpTraceWebFilter;
import org.springframework.mock.http.server.reactive.MockServerHttpRequest; import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
import org.springframework.mock.web.server.MockServerWebExchange; import org.springframework.mock.web.server.MockServerWebExchange;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.ServerWebExchangeDecorator; import org.springframework.web.server.ServerWebExchangeDecorator;
import org.springframework.web.server.WebFilterChain;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
@ -62,14 +60,7 @@ public class HttpTraceWebFilterTests {
this.filter.filter( this.filter.filter(
MockServerWebExchange MockServerWebExchange
.from(MockServerHttpRequest.get("https://api.example.com")), .from(MockServerHttpRequest.get("https://api.example.com")),
new WebFilterChain() { (exchange) -> Mono.empty()).block(Duration.ofSeconds(30));
@Override
public Mono<Void> filter(ServerWebExchange exchange) {
return Mono.empty();
}
}).block(Duration.ofSeconds(30));
assertThat(this.repository.findAll()).hasSize(1); assertThat(this.repository.findAll()).hasSize(1);
} }
@ -79,15 +70,10 @@ public class HttpTraceWebFilterTests {
this.filter.filter( this.filter.filter(
MockServerWebExchange MockServerWebExchange
.from(MockServerHttpRequest.get("https://api.example.com")), .from(MockServerHttpRequest.get("https://api.example.com")),
new WebFilterChain() { (exchange) -> {
exchange.getSession().block(Duration.ofSeconds(30)).getAttributes()
@Override .put("a", "alpha");
public Mono<Void> filter(ServerWebExchange exchange) {
exchange.getSession().block(Duration.ofSeconds(30))
.getAttributes().put("a", "alpha");
return Mono.empty(); return Mono.empty();
}
}).block(Duration.ofSeconds(30)); }).block(Duration.ofSeconds(30));
assertThat(this.repository.findAll()).hasSize(1); assertThat(this.repository.findAll()).hasSize(1);
Session session = this.repository.findAll().get(0).getSession(); Session session = this.repository.findAll().get(0).getSession();
@ -101,14 +87,9 @@ public class HttpTraceWebFilterTests {
this.filter.filter( this.filter.filter(
MockServerWebExchange MockServerWebExchange
.from(MockServerHttpRequest.get("https://api.example.com")), .from(MockServerHttpRequest.get("https://api.example.com")),
new WebFilterChain() { (exchange) -> {
@Override
public Mono<Void> filter(ServerWebExchange exchange) {
exchange.getSession().block(Duration.ofSeconds(30)); exchange.getSession().block(Duration.ofSeconds(30));
return Mono.empty(); return Mono.empty();
}
}).block(Duration.ofSeconds(30)); }).block(Duration.ofSeconds(30));
assertThat(this.repository.findAll()).hasSize(1); assertThat(this.repository.findAll()).hasSize(1);
Session session = this.repository.findAll().get(0).getSession(); Session session = this.repository.findAll().get(0).getSession();
@ -127,15 +108,10 @@ public class HttpTraceWebFilterTests {
return Mono.just(principal); return Mono.just(principal);
} }
}, new WebFilterChain() { }, (exchange) -> {
exchange.getSession().block(Duration.ofSeconds(30)).getAttributes().put("a",
@Override "alpha");
public Mono<Void> filter(ServerWebExchange exchange) {
exchange.getSession().block(Duration.ofSeconds(30)).getAttributes()
.put("a", "alpha");
return Mono.empty(); return Mono.empty();
}
}).block(Duration.ofSeconds(30)); }).block(Duration.ofSeconds(30));
assertThat(this.repository.findAll()).hasSize(1); assertThat(this.repository.findAll()).hasSize(1);
org.springframework.boot.actuate.trace.http.HttpTrace.Principal tracedPrincipal = this.repository org.springframework.boot.actuate.trace.http.HttpTrace.Principal tracedPrincipal = this.repository
@ -148,17 +124,11 @@ public class HttpTraceWebFilterTests {
public void statusIsAssumedToBe500WhenChainFails() public void statusIsAssumedToBe500WhenChainFails()
throws ServletException, IOException { throws ServletException, IOException {
try { try {
this.filter.filter( this.filter
MockServerWebExchange .filter(MockServerWebExchange
.from(MockServerHttpRequest.get("https://api.example.com")), .from(MockServerHttpRequest.get("https://api.example.com")),
new WebFilterChain() { (exchange) -> Mono.error(new RuntimeException()))
.block(Duration.ofSeconds(30));
@Override
public Mono<Void> filter(ServerWebExchange exchange) {
return Mono.error(new RuntimeException());
}
}).block(Duration.ofSeconds(30));
fail(); fail();
} }
catch (Exception ex) { catch (Exception ex) {

@ -19,7 +19,6 @@ package org.springframework.boot.autoconfigure.security.reactive;
import java.time.Duration; import java.time.Duration;
import org.junit.Test; import org.junit.Test;
import reactor.core.publisher.Mono;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.security.SecurityProperties; import org.springframework.boot.autoconfigure.security.SecurityProperties;
@ -30,7 +29,6 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.security.authentication.ReactiveAuthenticationManager; import org.springframework.security.authentication.ReactiveAuthenticationManager;
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity; import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.MapReactiveUserDetailsService; import org.springframework.security.core.userdetails.MapReactiveUserDetailsService;
import org.springframework.security.core.userdetails.ReactiveUserDetailsService; import org.springframework.security.core.userdetails.ReactiveUserDetailsService;
import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.User;
@ -156,12 +154,7 @@ public class ReactiveUserDetailsServiceAutoConfigurationTests {
@Bean @Bean
public ReactiveAuthenticationManager reactiveAuthenticationManager() { public ReactiveAuthenticationManager reactiveAuthenticationManager() {
return new ReactiveAuthenticationManager() { return (authentication) -> null;
@Override
public Mono<Authentication> authenticate(Authentication authentication) {
return null;
}
};
} }
} }

@ -26,7 +26,6 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import javax.servlet.ServletContext;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -276,13 +275,9 @@ public class ServerPropertiesTests {
@Test @Test
public void jettyMaxHttpPostSizeMatchesDefault() throws Exception { public void jettyMaxHttpPostSizeMatchesDefault() throws Exception {
JettyServletWebServerFactory jettyFactory = new JettyServletWebServerFactory(0); JettyServletWebServerFactory jettyFactory = new JettyServletWebServerFactory(0);
JettyWebServer jetty = (JettyWebServer) jettyFactory JettyWebServer jetty = (JettyWebServer) jettyFactory.getWebServer(
.getWebServer(new ServletContextInitializer() { (ServletContextInitializer) (servletContext) -> servletContext
.addServlet("formPost", new HttpServlet() {
@Override
public void onStartup(ServletContext servletContext)
throws ServletException {
servletContext.addServlet("formPost", new HttpServlet() {
@Override @Override
protected void doPost(HttpServletRequest req, protected void doPost(HttpServletRequest req,
@ -291,10 +286,7 @@ public class ServerPropertiesTests {
req.getParameterMap(); req.getParameterMap();
} }
}).addMapping("/form"); }).addMapping("/form"));
}
});
jetty.start(); jetty.start();
org.eclipse.jetty.server.Connector connector = jetty.getServer() org.eclipse.jetty.server.Connector connector = jetty.getServer()
.getConnectors()[0]; .getConnectors()[0];

@ -669,25 +669,17 @@ public class SpringApplicationTests {
CommandLineRunner commandLineRunner = mock(CommandLineRunner.class); CommandLineRunner commandLineRunner = mock(CommandLineRunner.class);
application.addInitializers((context) -> { application.addInitializers((context) -> {
ConfigurableListableBeanFactory beanFactory = context.getBeanFactory(); ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
beanFactory.registerSingleton("commandLineRunner", new CommandLineRunner() { beanFactory.registerSingleton("commandLineRunner",
(CommandLineRunner) (args) -> {
@Override
public void run(String... args) throws Exception {
assertThat(SpringApplicationTests.this.output.toString()) assertThat(SpringApplicationTests.this.output.toString())
.contains("Started"); .contains("Started");
commandLineRunner.run(args); commandLineRunner.run(args);
}
}); });
beanFactory.registerSingleton("applicationRunner", new ApplicationRunner() { beanFactory.registerSingleton("applicationRunner",
(ApplicationRunner) (args) -> {
@Override
public void run(ApplicationArguments args) throws Exception {
assertThat(SpringApplicationTests.this.output.toString()) assertThat(SpringApplicationTests.this.output.toString())
.contains("Started"); .contains("Started");
applicationRunner.run(args); applicationRunner.run(args);
}
}); });
}); });
application.setWebApplicationType(WebApplicationType.NONE); application.setWebApplicationType(WebApplicationType.NONE);

@ -301,10 +301,7 @@ public class JettyServletWebServerFactoryTests
@Test @Test
public void faultyListenerCausesStartFailure() throws Exception { public void faultyListenerCausesStartFailure() throws Exception {
JettyServletWebServerFactory factory = getFactory(); JettyServletWebServerFactory factory = getFactory();
factory.addServerCustomizers(new JettyServerCustomizer() { factory.addServerCustomizers((JettyServerCustomizer) (server) -> {
@Override
public void customize(Server server) {
Collection<WebAppContext> contexts = server.getBeans(WebAppContext.class); Collection<WebAppContext> contexts = server.getBeans(WebAppContext.class);
contexts.iterator().next().addEventListener(new ServletContextListener() { contexts.iterator().next().addEventListener(new ServletContextListener() {
@ -318,8 +315,6 @@ public class JettyServletWebServerFactoryTests
} }
}); });
}
}); });
assertThatExceptionOfType(WebServerException.class).isThrownBy(() -> { assertThatExceptionOfType(WebServerException.class).isThrownBy(() -> {
JettyWebServer jettyWebServer = (JettyWebServer) factory.getWebServer(); JettyWebServer jettyWebServer = (JettyWebServer) factory.getWebServer();

@ -38,11 +38,9 @@ import org.mockito.Captor;
import org.mockito.InOrder; import org.mockito.InOrder;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.springframework.beans.BeansException;
import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.ConstructorArgumentValues; import org.springframework.beans.factory.config.ConstructorArgumentValues;
import org.springframework.beans.factory.config.Scope; import org.springframework.beans.factory.config.Scope;
@ -475,16 +473,10 @@ public class ServletWebServerApplicationContextTests {
beanDefinition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR); beanDefinition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR);
this.context.registerBeanDefinition("withAutowiredServletRequest", this.context.registerBeanDefinition("withAutowiredServletRequest",
beanDefinition); beanDefinition);
this.context.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() { this.context.addBeanFactoryPostProcessor((beanFactory) -> {
@Override
public void postProcessBeanFactory(
ConfigurableListableBeanFactory beanFactory) throws BeansException {
WithAutowiredServletRequest bean = beanFactory WithAutowiredServletRequest bean = beanFactory
.getBean(WithAutowiredServletRequest.class); .getBean(WithAutowiredServletRequest.class);
assertThat(bean.getRequest()).isNotNull(); assertThat(bean.getRequest()).isNotNull();
}
}); });
this.context.refresh(); this.context.refresh();
String output = this.output.toString().substring(initialOutputLength); String output = this.output.toString().substring(initialOutputLength);

Loading…
Cancel
Save