This commit is contained in:
Phillip Webb 2017-12-13 13:54:22 -08:00
parent 5ca608330c
commit 3273859fde
26 changed files with 83 additions and 75 deletions

View File

@ -35,8 +35,7 @@ class HealthEndpointConfiguration {
@ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint
public HealthEndpoint healthEndpoint(ApplicationContext applicationContext) {
return new HealthEndpoint(HealthIndicatorBeansComposite.get(
applicationContext));
return new HealthEndpoint(HealthIndicatorBeansComposite.get(applicationContext));
}
}

View File

@ -65,8 +65,7 @@ class HealthEndpointWebExtensionConfiguration {
private final ReactiveHealthIndicator reactiveHealthIndicator;
ReactiveWebHealthConfiguration(
ObjectProvider<HealthAggregator> healthAggregator,
ReactiveWebHealthConfiguration(ObjectProvider<HealthAggregator> healthAggregator,
ObjectProvider<Map<String, ReactiveHealthIndicator>> reactiveHealthIndicators,
ObjectProvider<Map<String, HealthIndicator>> healthIndicators) {
this.reactiveHealthIndicator = new CompositeReactiveHealthIndicatorFactory()

View File

@ -39,9 +39,9 @@ import static org.assertj.core.api.Assertions.assertThat;
public class HealthEndpointWebExtensionTests {
private WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(
HealthIndicatorAutoConfiguration.class,
HealthEndpointAutoConfiguration.class));
.withConfiguration(
AutoConfigurations.of(HealthIndicatorAutoConfiguration.class,
HealthEndpointAutoConfiguration.class));
@Test
public void runShouldCreateExtensionBeans() {

View File

@ -78,8 +78,7 @@ public class ReactiveHealthEndpointWebExtensionTests {
@Test
public void regularAndReactiveHealthIndicatorsMatch() {
this.contextRunner
.withUserConfiguration(HealthIndicatorsConfiguration.class)
this.contextRunner.withUserConfiguration(HealthIndicatorsConfiguration.class)
.run((context) -> {
HealthEndpoint endpoint = context.getBean(HealthEndpoint.class);
ReactiveHealthEndpointWebExtension extension = context

View File

@ -43,7 +43,7 @@ public class MeterRegistryConfigurerTests {
.withPropertyValues("metrics.use-global-registry=false")
.run((context) -> assertThat(context.getBean(MeterRegistry.class)
.find("jvm.memory.used").tags("region", "us-east-1").gauge())
.isPresent());
.isPresent());
}
@Test
@ -55,7 +55,7 @@ public class MeterRegistryConfigurerTests {
.withPropertyValues("metrics.use-global-registry=false")
.run((context) -> assertThat(context.getBean(MeterRegistry.class)
.find("my.thing").tags("region", "us-east-1").gauge())
.isPresent());
.isPresent());
}
static class MeterRegistryConfigurerConfiguration {
@ -65,7 +65,6 @@ public class MeterRegistryConfigurerTests {
return (registry) -> registry.config().commonTags("region", "us-east-1");
}
@Bean
public MyThing myThing(MeterRegistry registry) {
registry.gauge("my.thing", 0);

View File

@ -59,9 +59,10 @@ public class MetricsRestTemplateCustomizer implements RestTemplateCustomizer {
UriTemplateHandler templateHandler = restTemplate.getUriTemplateHandler();
templateHandler = this.interceptor.createUriTemplateHandler(templateHandler);
restTemplate.setUriTemplateHandler(templateHandler);
List<ClientHttpRequestInterceptor> existingInterceptors = restTemplate.getInterceptors();
List<ClientHttpRequestInterceptor> existingInterceptors = restTemplate
.getInterceptors();
if (!existingInterceptors.contains(this.interceptor)) {
List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>();
List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>();
interceptors.add(this.interceptor);
interceptors.addAll(existingInterceptors);
restTemplate.setInterceptors(interceptors);

View File

@ -107,16 +107,16 @@ public class ScheduledTasksEndpoint {
*/
public static abstract class TaskDescription {
private static final Map<Class<? extends Task>, Function<Task, TaskDescription>> describers = new LinkedHashMap<>();
private static final Map<Class<? extends Task>, Function<Task, TaskDescription>> DESCRIBERS = new LinkedHashMap<>();
static {
describers.put(FixedRateTask.class,
DESCRIBERS.put(FixedRateTask.class,
(task) -> new FixedRateTaskDescription((FixedRateTask) task));
describers.put(FixedDelayTask.class,
DESCRIBERS.put(FixedDelayTask.class,
(task) -> new FixedDelayTaskDescription((FixedDelayTask) task));
describers.put(CronTask.class,
DESCRIBERS.put(CronTask.class,
(task) -> new CronTaskDescription((CronTask) task));
describers.put(TriggerTask.class,
DESCRIBERS.put(TriggerTask.class,
(task) -> describeTriggerTask((TriggerTask) task));
}
@ -125,7 +125,7 @@ public class ScheduledTasksEndpoint {
private final RunnableDescription runnable;
private static TaskDescription of(Task task) {
return describers.entrySet().stream()
return DESCRIBERS.entrySet().stream()
.filter((entry) -> entry.getKey().isInstance(task))
.map((entry) -> entry.getValue().apply(task)).findFirst()
.orElse(null);

View File

@ -70,8 +70,8 @@ public class MetricsRestTemplateCustomizerTests {
MockClock.clock(this.registry).add(SimpleConfig.DEFAULT_STEP);
assertThat(this.registry.find("http.client.requests")
.meters()).anySatisfy((m) -> assertThat(
StreamSupport.stream(m.getId().getTags().spliterator(), false)
.map(Tag::getKey)).doesNotContain("bucket"));
StreamSupport.stream(m.getId().getTags().spliterator(), false)
.map(Tag::getKey)).doesNotContain("bucket"));
assertThat(this.registry.find("http.client.requests")
.tags("method", "GET", "uri", "/test/{id}", "status", "200")
.value(Statistic.Count, 1.0).timer()).isPresent();

View File

@ -82,10 +82,9 @@ public class SessionsEndpointWebIntegrationTests {
@Test
public void sessionForIdNotFound() {
client.get()
.uri((builder) -> builder.path(
"/actuator/sessions/session-id-not-found").build())
.exchange().expectStatus().isNotFound();
client.get().uri((builder) -> builder
.path("/actuator/sessions/session-id-not-found").build()).exchange()
.expectStatus().isNotFound();
}
@Configuration

View File

@ -154,6 +154,7 @@ public class SecurityProperties implements SecurityPrerequisite {
public boolean isPasswordGenerated() {
return this.passwordGenerated;
}
}
}

View File

@ -55,11 +55,13 @@ class ReactiveAuthenticationManagerConfiguration {
.getLog(ReactiveAuthenticationManagerConfiguration.class);
@Bean
public MapReactiveUserDetailsService reactiveUserDetailsService(SecurityProperties properties,
public MapReactiveUserDetailsService reactiveUserDetailsService(
SecurityProperties properties,
ObjectProvider<PasswordEncoder> passwordEncoder) {
SecurityProperties.User user = properties.getUser();
if (user.isPasswordGenerated()) {
logger.info(String.format("%n%nUsing default security password: %s%n", user.getPassword()));
logger.info(String.format("%n%nUsing default security password: %s%n",
user.getPassword()));
}
UserDetails userDetails = getUserDetails(user, passwordEncoder);
return new MapReactiveUserDetailsService(userDetails);

View File

@ -568,8 +568,8 @@ public class ServerProperties {
private File basedir;
/**
* Delay between the invocation of backgroundProcess methods. If a
* duration suffix is not specified, seconds will be used.
* Delay between the invocation of backgroundProcess methods. If a duration suffix
* is not specified, seconds will be used.
*/
@DefaultDurationUnit(ChronoUnit.SECONDS)
private Duration backgroundProcessorDelay = Duration.ofSeconds(30);

View File

@ -399,8 +399,8 @@ public class DefaultServletWebServerFactoryCustomizer
private static void customizeUseRelativeRedirects(
TomcatServletWebServerFactory factory,
final boolean useRelativeRedirects) {
factory.addContextCustomizers((context) -> context
.setUseRelativeRedirects(useRelativeRedirects));
factory.addContextCustomizers(
(context) -> context.setUseRelativeRedirects(useRelativeRedirects));
}
private static void customizeStaticResources(Resource resource,

View File

@ -245,7 +245,8 @@ public class RabbitAutoConfigurationTests {
.run((context) -> {
RabbitTemplate rabbitTemplate = context.getBean(RabbitTemplate.class);
assertThat(rabbitTemplate.getExchange()).isEqualTo("my-exchange");
assertThat(rabbitTemplate.getRoutingKey()).isEqualTo("my-routing-key");
assertThat(rabbitTemplate.getRoutingKey())
.isEqualTo("my-routing-key");
});
}

View File

@ -423,8 +423,7 @@ public class DefaultServletWebServerFactoryCustomizerTests {
TomcatWebServer server = (TomcatWebServer) factory.getWebServer();
server.start();
try {
assertThat(server.getTomcat().getConnector().getMaxPostSize())
.isEqualTo(-1);
assertThat(server.getTomcat().getConnector().getMaxPostSize()).isEqualTo(-1);
}
finally {
server.stop();

View File

@ -361,12 +361,17 @@ public class Restarter {
((Set<?>) instance).clear();
}
if (instance instanceof Map) {
Map<?, ?> map = ((Map<?, ?>) instance);
map.keySet().removeIf(value -> value instanceof Class && ((Class<?>) value)
.getClassLoader() instanceof RestartClassLoader);
((Map<?, ?>) instance).keySet().removeIf(this::isFromRestartClassLoader);
}
}
private boolean isFromRestartClassLoader(Object object) {
if (object instanceof Class) {
return ((Class<?>) object).getClassLoader() instanceof RestartClassLoader;
}
return false;
}
/**
* Cleanup any soft/weak references by forcing an {@link OutOfMemoryError} error.
*/
@ -434,8 +439,7 @@ public class Restarter {
}
}
public Object getOrAddAttribute(String name,
final ObjectFactory<?> objectFactory) {
public Object getOrAddAttribute(String name, final ObjectFactory<?> objectFactory) {
synchronized (this.attributes) {
if (!this.attributes.containsKey(name)) {
this.attributes.put(name, objectFactory.getObject());

View File

@ -30,9 +30,9 @@ import org.springframework.cache.CacheManager;
import org.springframework.cache.support.NoOpCacheManager;
/**
* Annotation that can be applied to a test class to configure a test
* {@link CacheManager} if none has been defined yet. By default this
* annotation installs a {@link NoOpCacheManager}.
* Annotation that can be applied to a test class to configure a test {@link CacheManager}
* if none has been defined yet. By default this annotation installs a
* {@link NoOpCacheManager}.
*
* @author Phillip Webb
* @since 1.4.0

View File

@ -192,7 +192,8 @@ public class ApplicationContextAssertProviderTests {
assertThat(context.toString())
.startsWith(
"Started application [ConfigurableApplicationContext.MockitoMock")
.endsWith("id = [null], applicationName = [null], beanDefinitionCount = 0]");
.endsWith(
"id = [null], applicationName = [null], beanDefinitionCount = 0]");
}
@Test

View File

@ -416,14 +416,13 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
if (endpointId == null || "".equals(endpointId)) {
return; // Can't process that endpoint
}
String endpointKey = ItemMetadata.newItemMetadataPrefix(
"management.endpoint.", endpointId);
String endpointKey = ItemMetadata.newItemMetadataPrefix("management.endpoint.",
endpointId);
Boolean enabledByDefault = (Boolean) elementValues.get("enableByDefault");
String type = this.typeUtils.getQualifiedName(element);
this.metadataCollector
.add(ItemMetadata.newGroup(endpointKey, type, type, null));
this.metadataCollector.add(ItemMetadata.newProperty(endpointKey,
"enabled", Boolean.class.getName(), type, null,
this.metadataCollector.add(ItemMetadata.newGroup(endpointKey, type, type, null));
this.metadataCollector.add(ItemMetadata.newProperty(endpointKey, "enabled",
Boolean.class.getName(), type, null,
String.format("Whether to enable the %s endpoint.", endpointId),
(enabledByDefault == null ? true : enabledByDefault), null));
this.metadataCollector.add(ItemMetadata.newProperty(endpointKey,

View File

@ -218,8 +218,8 @@ public final class ItemMetadata implements Comparable<ItemMetadata> {
}
public static String newItemMetadataPrefix(String prefix, String suffix) {
return prefix.toLowerCase(Locale.ENGLISH) +
ConfigurationMetadata.toDashedCase(suffix);
return prefix.toLowerCase(Locale.ENGLISH)
+ ConfigurationMetadata.toDashedCase(suffix);
}
/**

View File

@ -636,9 +636,10 @@ public class ConfigurationMetadataAnnotationProcessorTests {
private Metadata.MetadataItemCondition enabledFlag(String endpointId,
String endpointSuffix, Boolean defaultValue) {
return Metadata.withEnabledFlag("management.endpoint." + endpointSuffix
+ ".enabled").withDefaultValue(defaultValue).withDescription(
String.format("Whether to enable the %s endpoint.", endpointId));
return Metadata
.withEnabledFlag("management.endpoint." + endpointSuffix + ".enabled")
.withDefaultValue(defaultValue).withDescription(
String.format("Whether to enable the %s endpoint.", endpointId));
}
private Metadata.MetadataItemCondition enabledFlag(String endpointId,

View File

@ -55,7 +55,7 @@ import org.springframework.util.Assert;
*/
public class ImageBanner implements Banner {
private static final String BANNER_IMAGE_PREFIX = "spring.banner.image.";
private static final String PROPERTY_PREFIX = "spring.banner.image.";
private static final Log logger = LogFactory.getLog(ImageBanner.class);
@ -100,14 +100,10 @@ public class ImageBanner implements Banner {
private void printBanner(Environment environment, PrintStream out)
throws IOException {
int width = environment.getProperty(BANNER_IMAGE_PREFIX + "width",
Integer.class, 76);
int height = environment.getProperty(BANNER_IMAGE_PREFIX + "height",
Integer.class, 0);
int margin = environment.getProperty(BANNER_IMAGE_PREFIX + "margin",
Integer.class, 2);
boolean invert = environment.getProperty(BANNER_IMAGE_PREFIX + "invert",
Boolean.class, false);
int width = getProperty(environment, "width", Integer.class, 76);
int height = getProperty(environment, "height", Integer.class, 0);
int margin = getProperty(environment, "margin", Integer.class, 2);
boolean invert = getProperty(environment, "invert", Boolean.class, false);
Frame[] frames = readFrames(width, height);
for (int i = 0; i < frames.length; i++) {
if (i > 0) {
@ -118,6 +114,11 @@ public class ImageBanner implements Banner {
}
}
private <T> T getProperty(Environment environment, String name, Class<T> targetType,
T defaultValue) {
return environment.getProperty(PROPERTY_PREFIX + name, targetType, defaultValue);
}
private Frame[] readFrames(int width, int height) throws IOException {
try (InputStream inputStream = this.image.getInputStream()) {
try (ImageInputStream imageStream = ImageIO

View File

@ -57,12 +57,12 @@ public class Binder {
private static final Set<Class<?>> NON_BEAN_CLASSES = Collections
.unmodifiableSet(new HashSet<>(Arrays.asList(Object.class, Class.class)));
private static final List<BeanBinder> beanBinders;
private static final List<BeanBinder> BEAN_BINDERS;
static {
List<BeanBinder> binders = new ArrayList<>();
binders.add(new JavaBeanBinder());
beanBinders = Collections.unmodifiableList(binders);
BEAN_BINDERS = Collections.unmodifiableList(binders);
}
private final Iterable<ConfigurationPropertySource> sources;
@ -317,7 +317,7 @@ public class Binder {
return null;
}
return context.withBean(type, () -> {
Stream<?> boundBeans = beanBinders.stream()
Stream<?> boundBeans = BEAN_BINDERS.stream()
.map((b) -> b.bind(name, target, context, propertyBinder));
return boundBeans.filter(Objects::nonNull).findFirst().orElse(null);
});

View File

@ -112,7 +112,6 @@ public class AtomikosProperties {
private final Recovery recovery = new Recovery();
/**
* Specifies the transaction manager implementation that should be started. There is
* no default value and this must be set. Generally,
@ -243,8 +242,8 @@ public class AtomikosProperties {
}
/**
* Specifies how long should a normal shutdown (no-force) wait for transactions to complete.
* Defaults to {@literal Long.MAX_VALUE}.
* Specifies how long should a normal shutdown (no-force) wait for transactions to
* complete. Defaults to {@literal Long.MAX_VALUE}.
* @param defaultMaxWaitTimeOnShutdown the default max wait time on shutdown
*/
public void setDefaultMaxWaitTimeOnShutdown(long defaultMaxWaitTimeOnShutdown) {

View File

@ -188,7 +188,8 @@ public class SpringApplicationTests {
public void customBanner() {
SpringApplication application = spy(new SpringApplication(ExampleConfig.class));
application.setWebApplicationType(WebApplicationType.NONE);
this.context = application.run("--spring.banner.location=classpath:test-banner.txt");
this.context = application
.run("--spring.banner.location=classpath:test-banner.txt");
assertThat(this.output.toString()).startsWith("Running a Test!");
}

View File

@ -19,8 +19,10 @@ package org.springframework.boot.jdbc;
import java.io.IOException;
import java.sql.Driver;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import javax.sql.XADataSource;
@ -41,9 +43,10 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(Parameterized.class)
public class DatabaseDriverClassNameTests {
private static final EnumSet<DatabaseDriver> excludedDrivers = EnumSet.of(
DatabaseDriver.UNKNOWN, DatabaseDriver.ORACLE, DatabaseDriver.DB2,
DatabaseDriver.DB2_AS400, DatabaseDriver.INFORMIX, DatabaseDriver.TERADATA);
private static final Set<DatabaseDriver> EXCLUDED_DRIVERS = Collections
.unmodifiableSet(EnumSet.of(DatabaseDriver.UNKNOWN, DatabaseDriver.ORACLE,
DatabaseDriver.DB2, DatabaseDriver.DB2_AS400, DatabaseDriver.INFORMIX,
DatabaseDriver.TERADATA));
private final String className;
@ -54,7 +57,7 @@ public class DatabaseDriverClassNameTests {
DatabaseDriver[] databaseDrivers = DatabaseDriver.values();
List<Object[]> parameters = new ArrayList<>();
for (DatabaseDriver databaseDriver : databaseDrivers) {
if (excludedDrivers.contains(databaseDriver)) {
if (EXCLUDED_DRIVERS.contains(databaseDriver)) {
continue;
}
parameters.add(new Object[] { databaseDriver,