Merge branch '1.5.x' into 2.0.x

This commit is contained in:
Andy Wilkinson 2018-05-02 12:22:04 +01:00
commit f019d5c85b
5 changed files with 47 additions and 39 deletions

View File

@ -54,8 +54,10 @@ public class MetricsWebFilterTests {
public void filterAddsTagsToRegistry() { public void filterAddsTagsToRegistry() {
MockServerWebExchange exchange = createExchange("/projects/spring-boot", MockServerWebExchange exchange = createExchange("/projects/spring-boot",
"/projects/{project}"); "/projects/{project}");
this.webFilter.filter(exchange, this.webFilter
serverWebExchange -> exchange.getResponse().setComplete()).block(); .filter(exchange,
(serverWebExchange) -> exchange.getResponse().setComplete())
.block();
assertMetricsContainsTag("uri", "/projects/{project}"); assertMetricsContainsTag("uri", "/projects/{project}");
assertMetricsContainsTag("status", "200"); assertMetricsContainsTag("status", "200");
} }
@ -64,9 +66,11 @@ public class MetricsWebFilterTests {
public void filterAddsTagsToRegistryForExceptions() { public void filterAddsTagsToRegistryForExceptions() {
MockServerWebExchange exchange = createExchange("/projects/spring-boot", MockServerWebExchange exchange = createExchange("/projects/spring-boot",
"/projects/{project}"); "/projects/{project}");
this.webFilter.filter(exchange, this.webFilter
serverWebExchange -> Mono.error(new IllegalStateException("test error"))) .filter(exchange,
.onErrorResume(t -> { (serverWebExchange) -> Mono
.error(new IllegalStateException("test error")))
.onErrorResume((t) -> {
exchange.getResponse().setStatusCodeValue(500); exchange.getResponse().setStatusCodeValue(500);
return exchange.getResponse().setComplete(); return exchange.getResponse().setComplete();
}).block(); }).block();
@ -78,14 +82,11 @@ public class MetricsWebFilterTests {
public void filterAddsTagsToRegistryForExceptionsAndCommittedResponse() { public void filterAddsTagsToRegistryForExceptionsAndCommittedResponse() {
MockServerWebExchange exchange = createExchange("/projects/spring-boot", MockServerWebExchange exchange = createExchange("/projects/spring-boot",
"/projects/{project}"); "/projects/{project}");
this.webFilter.filter(exchange, this.webFilter.filter(exchange, (serverWebExchange) -> {
serverWebExchange -> {
exchange.getResponse().setStatusCodeValue(500); exchange.getResponse().setStatusCodeValue(500);
return exchange.getResponse().setComplete() return exchange.getResponse().setComplete()
.then(Mono.error(new IllegalStateException("test error"))); .then(Mono.error(new IllegalStateException("test error")));
}) }).onErrorResume((t) -> Mono.empty()).block();
.onErrorResume(t -> Mono.empty())
.block();
assertMetricsContainsTag("uri", "/projects/{project}"); assertMetricsContainsTag("uri", "/projects/{project}");
assertMetricsContainsTag("status", "500"); assertMetricsContainsTag("status", "500");
} }
@ -94,15 +95,14 @@ public class MetricsWebFilterTests {
PathPatternParser parser = new PathPatternParser(); PathPatternParser parser = new PathPatternParser();
MockServerWebExchange exchange = MockServerWebExchange MockServerWebExchange exchange = MockServerWebExchange
.from(MockServerHttpRequest.get(path).build()); .from(MockServerHttpRequest.get(path).build());
exchange.getAttributes() exchange.getAttributes().put(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE,
.put(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE, parser.parse(pathPattern)); parser.parse(pathPattern));
return exchange; return exchange;
} }
private void assertMetricsContainsTag(String tagKey, String tagValue) { private void assertMetricsContainsTag(String tagKey, String tagValue) {
assertThat(this.registry.get(REQUEST_METRICS_NAME) assertThat(this.registry.get(REQUEST_METRICS_NAME).tag(tagKey, tagValue).timer()
.tag(tagKey, tagValue).timer().count()) .count()).isEqualTo(1);
.isEqualTo(1);
} }
} }

View File

@ -101,22 +101,25 @@ public class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurat
@Test @Test
public void autoConfigWhenSpringSessionTimeoutIsSetShouldUseThat() { public void autoConfigWhenSpringSessionTimeoutIsSetShouldUseThat() {
this.contextRunner.withUserConfiguration(ServerPropertiesConfiguration.class, this.contextRunner
.withUserConfiguration(ServerPropertiesConfiguration.class,
SessionRepositoryConfiguration.class) SessionRepositoryConfiguration.class)
.withPropertyValues("server.servlet.session.timeout=1", .withPropertyValues("server.servlet.session.timeout=1",
"spring.session.timeout=3").run((context) -> "spring.session.timeout=3")
assertThat(context.getBean(SessionProperties.class).getTimeout()) .run((context) -> assertThat(
context.getBean(SessionProperties.class).getTimeout())
.isEqualTo(Duration.ofSeconds(3))); .isEqualTo(Duration.ofSeconds(3)));
} }
@Test @Test
public void autoConfigWhenSpringSessionTimeoutIsNotSetShouldUseServerSessionTimeout() { public void autoConfigWhenSpringSessionTimeoutIsNotSetShouldUseServerSessionTimeout() {
this.contextRunner.withUserConfiguration(ServerPropertiesConfiguration.class, this.contextRunner
.withUserConfiguration(ServerPropertiesConfiguration.class,
SessionRepositoryConfiguration.class) SessionRepositoryConfiguration.class)
.withPropertyValues("server.servlet.session.timeout=3").run((context) -> { .withPropertyValues("server.servlet.session.timeout=3")
assertThat(context.getBean(SessionProperties.class).getTimeout()) .run((context) -> assertThat(
.isEqualTo(Duration.ofSeconds(3)); context.getBean(SessionProperties.class).getTimeout())
}); .isEqualTo(Duration.ofSeconds(3)));
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 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.
@ -136,6 +136,7 @@ public class DependencyFilterMojoTests {
private final ArtifactsFilter[] additionalFilters; private final ArtifactsFilter[] additionalFilters;
@SuppressWarnings("deprecation")
private TestableDependencyFilterMojo(List<Exclude> excludes, private TestableDependencyFilterMojo(List<Exclude> excludes,
String excludeGroupIds, String excludeArtifactIds, String excludeGroupIds, String excludeArtifactIds,
ArtifactsFilter... additionalFilters) { ArtifactsFilter... additionalFilters) {

View File

@ -347,7 +347,8 @@ public class ConfigFileApplicationListener
this.profiles.add(null); this.profiles.add(null);
Set<Profile> activatedViaProperty = getProfilesActivatedViaActiveProfileProperty(); Set<Profile> activatedViaProperty = getProfilesActivatedViaActiveProfileProperty();
processOtherActiveProfiles(activatedViaProperty); processOtherActiveProfiles(activatedViaProperty);
// Any pre-existing active activeProfiles set via property sources (e.g. System // Any pre-existing active activeProfiles set via property sources (e.g.
// System
// properties) take precedence over those added in config files. // properties) take precedence over those added in config files.
addActiveProfiles(activatedViaProperty); addActiveProfiles(activatedViaProperty);
if (this.profiles.size() == 1) { // only has null profile if (this.profiles.size() == 1) { // only has null profile
@ -372,9 +373,10 @@ public class ConfigFileApplicationListener
} }
private void processOtherActiveProfiles(Set<Profile> activatedViaProperty) { private void processOtherActiveProfiles(Set<Profile> activatedViaProperty) {
List<Profile> otherActiveProfiles = Arrays.stream(this.environment.getActiveProfiles()) List<Profile> otherActiveProfiles = Arrays
.map(Profile::new) .stream(this.environment.getActiveProfiles()).map(Profile::new)
.filter(o -> !activatedViaProperty.contains(o)).collect(Collectors.toList()); .filter((o) -> !activatedViaProperty.contains(o))
.collect(Collectors.toList());
this.profiles.addAll(otherActiveProfiles); this.profiles.addAll(otherActiveProfiles);
} }
@ -397,7 +399,8 @@ public class ConfigFileApplicationListener
} }
private void removeUnprocessedDefaultProfiles() { private void removeUnprocessedDefaultProfiles() {
this.profiles.removeIf(profile -> (profile != null && profile.isDefaultProfile())); this.profiles.removeIf(
(profile) -> (profile != null && profile.isDefaultProfile()));
} }
private DocumentFilter getPositiveProfileFilter(Profile profile) { private DocumentFilter getPositiveProfileFilter(Profile profile) {

View File

@ -198,7 +198,7 @@ public class TomcatWebServer implements WebServer {
addPreviouslyRemovedConnectors(); addPreviouslyRemovedConnectors();
Connector connector = this.tomcat.getConnector(); Connector connector = this.tomcat.getConnector();
if (connector != null && this.autoStart) { if (connector != null && this.autoStart) {
startConnector(); performDeferredLoadOnStartup();
} }
checkThatConnectorsHaveStarted(); checkThatConnectorsHaveStarted();
this.started = true; this.started = true;
@ -272,7 +272,7 @@ public class TomcatWebServer implements WebServer {
} }
} }
private void startConnector() { private void performDeferredLoadOnStartup() {
try { try {
for (Container child : this.tomcat.getHost().findChildren()) { for (Container child : this.tomcat.getHost().findChildren()) {
if (child instanceof TomcatEmbeddedContext) { if (child instanceof TomcatEmbeddedContext) {
@ -349,4 +349,5 @@ public class TomcatWebServer implements WebServer {
public Tomcat getTomcat() { public Tomcat getTomcat() {
return this.tomcat; return this.tomcat;
} }
} }