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

View File

@ -101,22 +101,25 @@ public class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurat
@Test
public void autoConfigWhenSpringSessionTimeoutIsSetShouldUseThat() {
this.contextRunner.withUserConfiguration(ServerPropertiesConfiguration.class,
SessionRepositoryConfiguration.class)
this.contextRunner
.withUserConfiguration(ServerPropertiesConfiguration.class,
SessionRepositoryConfiguration.class)
.withPropertyValues("server.servlet.session.timeout=1",
"spring.session.timeout=3").run((context) ->
assertThat(context.getBean(SessionProperties.class).getTimeout())
.isEqualTo(Duration.ofSeconds(3)));
"spring.session.timeout=3")
.run((context) -> assertThat(
context.getBean(SessionProperties.class).getTimeout())
.isEqualTo(Duration.ofSeconds(3)));
}
@Test
public void autoConfigWhenSpringSessionTimeoutIsNotSetShouldUseServerSessionTimeout() {
this.contextRunner.withUserConfiguration(ServerPropertiesConfiguration.class,
SessionRepositoryConfiguration.class)
.withPropertyValues("server.servlet.session.timeout=3").run((context) -> {
assertThat(context.getBean(SessionProperties.class).getTimeout())
.isEqualTo(Duration.ofSeconds(3));
});
this.contextRunner
.withUserConfiguration(ServerPropertiesConfiguration.class,
SessionRepositoryConfiguration.class)
.withPropertyValues("server.servlet.session.timeout=3")
.run((context) -> assertThat(
context.getBean(SessionProperties.class).getTimeout())
.isEqualTo(Duration.ofSeconds(3)));
}
@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");
* you may not use this file except in compliance with the License.
@ -136,6 +136,7 @@ public class DependencyFilterMojoTests {
private final ArtifactsFilter[] additionalFilters;
@SuppressWarnings("deprecation")
private TestableDependencyFilterMojo(List<Exclude> excludes,
String excludeGroupIds, String excludeArtifactIds,
ArtifactsFilter... additionalFilters) {

View File

@ -342,15 +342,16 @@ public class ConfigFileApplicationListener
* properties that are already set.
*/
private void initializeProfiles() {
//The default profile for these purposes is represented as null. We add it
// The default profile for these purposes is represented as null. We add it
// first so that it is processed first and has lowest priority.
this.profiles.add(null);
Set<Profile> activatedViaProperty = getProfilesActivatedViaActiveProfileProperty();
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.
addActiveProfiles(activatedViaProperty);
if (this.profiles.size() == 1) { //only has null profile
if (this.profiles.size() == 1) { // only has null profile
for (String defaultProfileName : this.environment.getDefaultProfiles()) {
ConfigFileApplicationListener.Profile defaultProfile = new ConfigFileApplicationListener.Profile(
defaultProfileName, true);
@ -372,9 +373,10 @@ public class ConfigFileApplicationListener
}
private void processOtherActiveProfiles(Set<Profile> activatedViaProperty) {
List<Profile> otherActiveProfiles = Arrays.stream(this.environment.getActiveProfiles())
.map(Profile::new)
.filter(o -> !activatedViaProperty.contains(o)).collect(Collectors.toList());
List<Profile> otherActiveProfiles = Arrays
.stream(this.environment.getActiveProfiles()).map(Profile::new)
.filter((o) -> !activatedViaProperty.contains(o))
.collect(Collectors.toList());
this.profiles.addAll(otherActiveProfiles);
}
@ -397,7 +399,8 @@ public class ConfigFileApplicationListener
}
private void removeUnprocessedDefaultProfiles() {
this.profiles.removeIf(profile -> (profile != null && profile.isDefaultProfile()));
this.profiles.removeIf(
(profile) -> (profile != null && profile.isDefaultProfile()));
}
private DocumentFilter getPositiveProfileFilter(Profile profile) {

View File

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