Merge pull request #9781 from emacampolo/refactor-and-polish-with-new-idioms
* pr/9781: Simplify comparator implementation Use lambdas when possible Replace try with try-with-resources Collapse catch clauses Replace Collections.sort() with direct sort call Replace explicit generics with diamond operator
This commit is contained in:
@@ -52,8 +52,6 @@ import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
import org.springframework.test.web.servlet.ResultHandler;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -161,32 +159,9 @@ public class EndpointDocumentation {
|
||||
|
||||
@Test
|
||||
public void endpoints() throws Exception {
|
||||
final File docs = new File("src/main/asciidoc");
|
||||
final Map<String, Object> model = new LinkedHashMap<>();
|
||||
final List<EndpointDoc> endpoints = new ArrayList<>();
|
||||
model.put("endpoints", endpoints);
|
||||
for (MvcEndpoint endpoint : getEndpoints()) {
|
||||
final String endpointPath = (StringUtils.hasText(endpoint.getPath())
|
||||
? endpoint.getPath() : "/");
|
||||
if (!SKIPPED.contains(endpointPath)) {
|
||||
String output = endpointPath.substring(1);
|
||||
output = output.length() > 0 ? output : "./";
|
||||
this.mockMvc
|
||||
.perform(get("/application" + endpointPath)
|
||||
.accept(ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON))
|
||||
.andExpect(status().isOk()).andDo(document(output))
|
||||
.andDo(new ResultHandler() {
|
||||
|
||||
@Override
|
||||
public void handle(MvcResult mvcResult) throws Exception {
|
||||
EndpointDoc endpoint = new EndpointDoc(docs,
|
||||
endpointPath);
|
||||
endpoints.add(endpoint);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
File docs = new File("src/main/asciidoc");
|
||||
Map<String, Object> model = new LinkedHashMap<>();
|
||||
model.put("endpoints", getEndpointDocs(docs));
|
||||
File file = new File(RESTDOCS_OUTPUT_DIR + "/endpoints.adoc");
|
||||
file.getParentFile().mkdirs();
|
||||
try (PrintWriter writer = new PrintWriter(file, "UTF-8")) {
|
||||
@@ -196,18 +171,36 @@ public class EndpointDocumentation {
|
||||
}
|
||||
}
|
||||
|
||||
private List<EndpointDoc> getEndpointDocs(File docs) throws Exception {
|
||||
final List<EndpointDoc> endpoints = new ArrayList<>();
|
||||
for (MvcEndpoint endpoint : getEndpoints()) {
|
||||
String path = endpoint.getPath();
|
||||
path = (StringUtils.hasText(path) ? path : "/");
|
||||
if (!SKIPPED.contains(path)) {
|
||||
documentEndpoint(path);
|
||||
endpoints.add(new EndpointDoc(docs, path));
|
||||
}
|
||||
}
|
||||
return endpoints;
|
||||
}
|
||||
|
||||
private Collection<? extends MvcEndpoint> getEndpoints() {
|
||||
List<? extends MvcEndpoint> endpoints = new ArrayList<>(
|
||||
this.mvcEndpoints.getEndpoints());
|
||||
Collections.sort(endpoints, new Comparator<MvcEndpoint>() {
|
||||
@Override
|
||||
public int compare(MvcEndpoint o1, MvcEndpoint o2) {
|
||||
return o1.getPath().compareTo(o2.getPath());
|
||||
}
|
||||
});
|
||||
endpoints.sort(Comparator.comparing(MvcEndpoint::getPath));
|
||||
return endpoints;
|
||||
}
|
||||
|
||||
private String documentEndpoint(final String endpointPath) throws Exception {
|
||||
String output = endpointPath.substring(1);
|
||||
output = (output.length() > 0 ? output : "./");
|
||||
this.mockMvc
|
||||
.perform(get("/application" + endpointPath)
|
||||
.accept(ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON))
|
||||
.andExpect(status().isOk()).andDo(document(output));
|
||||
return output;
|
||||
}
|
||||
|
||||
public static class EndpointDoc {
|
||||
|
||||
private String path;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
@@ -137,15 +137,11 @@ public class CacheStatisticsAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public CacheStatisticsProvider<Cache> noOpCacheStatisticsProvider() {
|
||||
return new CacheStatisticsProvider<Cache>() {
|
||||
@Override
|
||||
public CacheStatistics getCacheStatistics(CacheManager cacheManager,
|
||||
Cache cache) {
|
||||
if (cacheManager instanceof NoOpCacheManager) {
|
||||
return NO_OP_STATS;
|
||||
}
|
||||
return null;
|
||||
return (cacheManager, cache) -> {
|
||||
if (cacheManager instanceof NoOpCacheManager) {
|
||||
return NO_OP_STATS;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -149,7 +149,7 @@ public class EndpointAutoConfiguration {
|
||||
if (this.publicMetrics != null) {
|
||||
publicMetrics.addAll(this.publicMetrics);
|
||||
}
|
||||
Collections.sort(publicMetrics, AnnotationAwareOrderComparator.INSTANCE);
|
||||
publicMetrics.sort(AnnotationAwareOrderComparator.INSTANCE);
|
||||
return new MetricsEndpoint(publicMetrics);
|
||||
}
|
||||
|
||||
|
||||
@@ -120,14 +120,7 @@ public class EndpointWebMvcAutoConfiguration
|
||||
@Bean
|
||||
public ManagementServletContext managementServletContext(
|
||||
final ManagementServerProperties properties) {
|
||||
return new ManagementServletContext() {
|
||||
|
||||
@Override
|
||||
public String getContextPath() {
|
||||
return properties.getContextPath();
|
||||
}
|
||||
|
||||
};
|
||||
return properties::getContextPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -101,14 +101,7 @@ public class EndpointWebMvcHypermediaManagementContextConfiguration {
|
||||
@Bean
|
||||
public ManagementServletContext managementServletContext(
|
||||
final ManagementServerProperties properties) {
|
||||
return new ManagementServletContext() {
|
||||
|
||||
@Override
|
||||
public String getContextPath() {
|
||||
return properties.getContextPath();
|
||||
}
|
||||
|
||||
};
|
||||
return properties::getContextPath;
|
||||
}
|
||||
|
||||
@ConditionalOnEnabledEndpoint("actuator")
|
||||
|
||||
@@ -169,7 +169,7 @@ public class ManagementServerProperties implements SecurityPrerequisite {
|
||||
/**
|
||||
* Comma-separated list of roles that can access the management endpoint.
|
||||
*/
|
||||
private List<String> roles = new ArrayList<String>(
|
||||
private List<String> roles = new ArrayList<>(
|
||||
Collections.singletonList("ACTUATOR"));
|
||||
|
||||
/**
|
||||
|
||||
@@ -107,16 +107,13 @@ public abstract class AbstractJmxCacheStatisticsProvider<C extends Cache>
|
||||
Object attribute = getMBeanServer().getAttribute(objectName, attributeName);
|
||||
return type.cast(attribute);
|
||||
}
|
||||
catch (MBeanException ex) {
|
||||
catch (MBeanException | ReflectionException ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
catch (AttributeNotFoundException ex) {
|
||||
throw new IllegalStateException("Unexpected: MBean with name '" + objectName
|
||||
+ "' " + "does not expose attribute with name " + attributeName, ex);
|
||||
}
|
||||
catch (ReflectionException ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
catch (InstanceNotFoundException ex) {
|
||||
logger.warn("Cache statistics are no longer available", ex);
|
||||
return null;
|
||||
|
||||
@@ -89,7 +89,7 @@ public class EnvironmentEndpoint extends AbstractEndpoint<Map<String, Object>> {
|
||||
}
|
||||
|
||||
private Map<String, PropertySource<?>> getPropertySourcesAsMap() {
|
||||
Map<String, PropertySource<?>> map = new LinkedHashMap<String, PropertySource<?>>();
|
||||
Map<String, PropertySource<?>> map = new LinkedHashMap<>();
|
||||
for (PropertySource<?> source : getPropertySources()) {
|
||||
extract("", map, source);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
@@ -62,23 +62,22 @@ public class ShutdownEndpoint extends AbstractEndpoint<Map<String, Object>>
|
||||
return SHUTDOWN_MESSAGE;
|
||||
}
|
||||
finally {
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(500L);
|
||||
}
|
||||
catch (InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
ShutdownEndpoint.this.context.close();
|
||||
}
|
||||
});
|
||||
Thread thread = new Thread(this::performShutdown);
|
||||
thread.setContextClassLoader(getClass().getClassLoader());
|
||||
thread.start();
|
||||
}
|
||||
}
|
||||
|
||||
private void performShutdown() {
|
||||
try {
|
||||
Thread.sleep(500L);
|
||||
}
|
||||
catch (InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
this.context.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext context) throws BeansException {
|
||||
if (context instanceof ConfigurableApplicationContext) {
|
||||
|
||||
@@ -40,7 +40,7 @@ public class CompositeHealthIndicator implements HealthIndicator {
|
||||
* @param healthAggregator the health aggregator
|
||||
*/
|
||||
public CompositeHealthIndicator(HealthAggregator healthAggregator) {
|
||||
this(healthAggregator, new LinkedHashMap<String, HealthIndicator>());
|
||||
this(healthAggregator, new LinkedHashMap<>());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
@@ -26,7 +26,6 @@ import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.boot.jdbc.DatabaseDriver;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.support.DataAccessUtils;
|
||||
import org.springframework.jdbc.IncorrectResultSetColumnCountException;
|
||||
import org.springframework.jdbc.core.ConnectionCallback;
|
||||
@@ -120,13 +119,11 @@ public class DataSourceHealthIndicator extends AbstractHealthIndicator
|
||||
}
|
||||
|
||||
private String getProduct() {
|
||||
return this.jdbcTemplate.execute(new ConnectionCallback<String>() {
|
||||
@Override
|
||||
public String doInConnection(Connection connection)
|
||||
throws SQLException, DataAccessException {
|
||||
return connection.getMetaData().getDatabaseProductName();
|
||||
}
|
||||
});
|
||||
return this.jdbcTemplate.execute((ConnectionCallback<String>) this::getProduct);
|
||||
}
|
||||
|
||||
private String getProduct(Connection connection) throws SQLException {
|
||||
return connection.getMetaData().getDatabaseProductName();
|
||||
}
|
||||
|
||||
protected String getValidationQuery(String product) {
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.boot.actuate.health;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
@@ -80,7 +79,7 @@ public class OrderedHealthAggregator extends AbstractHealthAggregator {
|
||||
return Status.UNKNOWN;
|
||||
}
|
||||
// Sort given Status instances by configured order
|
||||
Collections.sort(filteredCandidates, new StatusComparator(this.statusOrder));
|
||||
filteredCandidates.sort(new StatusComparator(this.statusOrder));
|
||||
return filteredCandidates.get(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
@@ -16,11 +16,6 @@
|
||||
|
||||
package org.springframework.boot.actuate.health;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.rabbitmq.client.Channel;
|
||||
|
||||
import org.springframework.amqp.rabbit.core.ChannelCallback;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -46,14 +41,8 @@ public class RabbitHealthIndicator extends AbstractHealthIndicator {
|
||||
}
|
||||
|
||||
private String getVersion() {
|
||||
return this.rabbitTemplate.execute(new ChannelCallback<String>() {
|
||||
@Override
|
||||
public String doInRabbit(Channel channel) throws Exception {
|
||||
Map<String, Object> serverProperties = channel.getConnection()
|
||||
.getServerProperties();
|
||||
return serverProperties.get("version").toString();
|
||||
}
|
||||
});
|
||||
return this.rabbitTemplate.execute((channel) -> channel.getConnection()
|
||||
.getServerProperties().get("version").toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.boot.actuate.metrics.buffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -48,7 +47,7 @@ public class BufferMetricReader implements MetricReader, PrefixMetricReader {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Metric<?> findOne(final String name) {
|
||||
public Metric<?> findOne(String name) {
|
||||
Buffer<?> buffer = this.counterBuffers.find(name);
|
||||
if (buffer == null) {
|
||||
buffer = this.gaugeBuffers.find(name);
|
||||
@@ -81,17 +80,10 @@ public class BufferMetricReader implements MetricReader, PrefixMetricReader {
|
||||
private <T extends Number, B extends Buffer<T>> void collectMetrics(
|
||||
Buffers<B> buffers, Predicate<String> predicate,
|
||||
final List<Metric<?>> metrics) {
|
||||
buffers.forEach(predicate, new BiConsumer<String, B>() {
|
||||
|
||||
@Override
|
||||
public void accept(String name, B value) {
|
||||
metrics.add(asMetric(name, value));
|
||||
}
|
||||
|
||||
});
|
||||
buffers.forEach(predicate, (name, value) -> metrics.add(asMetric(name, value)));
|
||||
}
|
||||
|
||||
private <T extends Number> Metric<T> asMetric(final String name, Buffer<T> buffer) {
|
||||
private <T extends Number> Metric<T> asMetric(String name, Buffer<T> buffer) {
|
||||
return new Metric<>(name, buffer.getValue(), new Date(buffer.getTimestamp()));
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.boot.actuate.metrics.buffer;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
@@ -34,20 +33,15 @@ abstract class Buffers<B extends Buffer<?>> {
|
||||
private final ConcurrentHashMap<String, B> buffers = new ConcurrentHashMap<>();
|
||||
|
||||
public void forEach(final Predicate<String> predicate,
|
||||
final BiConsumer<String, B> consumer) {
|
||||
this.buffers.forEach(new BiConsumer<String, B>() {
|
||||
|
||||
@Override
|
||||
public void accept(String name, B value) {
|
||||
if (predicate.test(name)) {
|
||||
consumer.accept(name, value);
|
||||
}
|
||||
BiConsumer<String, B> consumer) {
|
||||
this.buffers.forEach((name, value) -> {
|
||||
if (predicate.test(name)) {
|
||||
consumer.accept(name, value);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public B find(final String name) {
|
||||
public B find(String name) {
|
||||
return this.buffers.get(name);
|
||||
}
|
||||
|
||||
@@ -55,15 +49,10 @@ abstract class Buffers<B extends Buffer<?>> {
|
||||
return this.buffers.size();
|
||||
}
|
||||
|
||||
protected final void doWith(final String name, final Consumer<B> consumer) {
|
||||
protected final void doWith(String name, Consumer<B> consumer) {
|
||||
B buffer = this.buffers.get(name);
|
||||
if (buffer == null) {
|
||||
buffer = this.buffers.computeIfAbsent(name, new Function<String, B>() {
|
||||
@Override
|
||||
public B apply(String name) {
|
||||
return createBuffer();
|
||||
}
|
||||
});
|
||||
buffer = this.buffers.computeIfAbsent(name, (k) -> createBuffer());
|
||||
}
|
||||
consumer.accept(buffer);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.boot.actuate.metrics.buffer;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Fast writes to in-memory metrics store using {@link CounterBuffer}.
|
||||
*
|
||||
@@ -26,27 +24,17 @@ import java.util.function.Consumer;
|
||||
*/
|
||||
public class CounterBuffers extends Buffers<CounterBuffer> {
|
||||
|
||||
public void increment(final String name, final long delta) {
|
||||
doWith(name, new Consumer<CounterBuffer>() {
|
||||
|
||||
@Override
|
||||
public void accept(CounterBuffer buffer) {
|
||||
buffer.setTimestamp(System.currentTimeMillis());
|
||||
buffer.add(delta);
|
||||
}
|
||||
|
||||
public void increment(String name, long delta) {
|
||||
doWith(name, (buffer) -> {
|
||||
buffer.setTimestamp(System.currentTimeMillis());
|
||||
buffer.add(delta);
|
||||
});
|
||||
}
|
||||
|
||||
public void reset(final String name) {
|
||||
doWith(name, new Consumer<CounterBuffer>() {
|
||||
|
||||
@Override
|
||||
public void accept(CounterBuffer buffer) {
|
||||
buffer.setTimestamp(System.currentTimeMillis());
|
||||
buffer.reset();
|
||||
}
|
||||
|
||||
public void reset(String name) {
|
||||
doWith(name, (buffer) -> {
|
||||
buffer.setTimestamp(System.currentTimeMillis());
|
||||
buffer.reset();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.boot.actuate.metrics.buffer;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Fast writes to in-memory metrics store using {@link GaugeBuffer}.
|
||||
*
|
||||
@@ -26,13 +24,10 @@ import java.util.function.Consumer;
|
||||
*/
|
||||
public class GaugeBuffers extends Buffers<GaugeBuffer> {
|
||||
|
||||
public void set(final String name, final double value) {
|
||||
doWith(name, new Consumer<GaugeBuffer>() {
|
||||
@Override
|
||||
public void accept(GaugeBuffer buffer) {
|
||||
buffer.setTimestamp(System.currentTimeMillis());
|
||||
buffer.setValue(value);
|
||||
}
|
||||
public void set(String name, double value) {
|
||||
doWith(name, (buffer) -> {
|
||||
buffer.setTimestamp(System.currentTimeMillis());
|
||||
buffer.setValue(value);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -32,14 +32,7 @@ public interface ReservoirFactory {
|
||||
/**
|
||||
* Default empty {@link ReservoirFactory} implementation.
|
||||
*/
|
||||
ReservoirFactory NONE = new ReservoirFactory() {
|
||||
|
||||
@Override
|
||||
public Reservoir getReservoir(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
ReservoirFactory NONE = (name) -> null;
|
||||
|
||||
/**
|
||||
* Return the {@link Reservoir} instance to use or {@code null} if a custom reservoir
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.boot.actuate.metrics.reader;
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -113,18 +112,15 @@ public class MetricRegistryMetricReader implements MetricReader, MetricRegistryL
|
||||
|
||||
@Override
|
||||
public Iterable<Metric<?>> findAll() {
|
||||
return new Iterable<Metric<?>>() {
|
||||
@Override
|
||||
public Iterator<Metric<?>> iterator() {
|
||||
Set<Metric<?>> metrics = new HashSet<>();
|
||||
for (String name : MetricRegistryMetricReader.this.names.keySet()) {
|
||||
Metric<?> metric = findOne(name);
|
||||
if (metric != null) {
|
||||
metrics.add(metric);
|
||||
}
|
||||
return () -> {
|
||||
Set<Metric<?>> metrics = new HashSet<>();
|
||||
for (String name : MetricRegistryMetricReader.this.names.keySet()) {
|
||||
Metric<?> metric = findOne(name);
|
||||
if (metric != null) {
|
||||
metrics.add(metric);
|
||||
}
|
||||
return metrics.iterator();
|
||||
}
|
||||
return metrics.iterator();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.util.concurrent.ConcurrentNavigableMap;
|
||||
|
||||
import org.springframework.boot.actuate.metrics.Metric;
|
||||
import org.springframework.boot.actuate.metrics.util.SimpleInMemoryRepository;
|
||||
import org.springframework.boot.actuate.metrics.util.SimpleInMemoryRepository.Callback;
|
||||
import org.springframework.boot.actuate.metrics.writer.Delta;
|
||||
|
||||
/**
|
||||
@@ -43,17 +42,12 @@ public class InMemoryMetricRepository implements MetricRepository {
|
||||
final String metricName = delta.getName();
|
||||
final int amount = delta.getValue().intValue();
|
||||
final Date timestamp = delta.getTimestamp();
|
||||
this.metrics.update(metricName, new Callback<Metric<?>>() {
|
||||
|
||||
@Override
|
||||
public Metric<?> modify(Metric<?> current) {
|
||||
if (current != null) {
|
||||
return new Metric<>(metricName, current.increment(amount).getValue(),
|
||||
timestamp);
|
||||
}
|
||||
return new Metric<>(metricName, (long) amount, timestamp);
|
||||
this.metrics.update(metricName, (current) -> {
|
||||
if (current != null) {
|
||||
return new Metric<>(metricName, current.increment(amount).getValue(),
|
||||
timestamp);
|
||||
}
|
||||
|
||||
return new Metric<>(metricName, (long) amount, timestamp);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.boot.actuate.metrics.rich;
|
||||
|
||||
import org.springframework.boot.actuate.metrics.Metric;
|
||||
import org.springframework.boot.actuate.metrics.util.SimpleInMemoryRepository;
|
||||
import org.springframework.boot.actuate.metrics.util.SimpleInMemoryRepository.Callback;
|
||||
import org.springframework.boot.actuate.metrics.writer.Delta;
|
||||
import org.springframework.boot.actuate.metrics.writer.MetricWriter;
|
||||
|
||||
@@ -36,19 +35,14 @@ public class InMemoryRichGaugeRepository implements RichGaugeRepository {
|
||||
private final SimpleInMemoryRepository<RichGauge> repository = new SimpleInMemoryRepository<>();
|
||||
|
||||
@Override
|
||||
public void increment(final Delta<?> delta) {
|
||||
this.repository.update(delta.getName(), new Callback<RichGauge>() {
|
||||
|
||||
@Override
|
||||
public RichGauge modify(RichGauge current) {
|
||||
double value = ((Number) delta.getValue()).doubleValue();
|
||||
if (current == null) {
|
||||
return new RichGauge(delta.getName(), value);
|
||||
}
|
||||
current.set(current.getValue() + value);
|
||||
return current;
|
||||
public void increment(Delta<?> delta) {
|
||||
this.repository.update(delta.getName(), (current) -> {
|
||||
double value = ((Number) delta.getValue()).doubleValue();
|
||||
if (current == null) {
|
||||
return new RichGauge(delta.getName(), value);
|
||||
}
|
||||
|
||||
current.set(current.getValue() + value);
|
||||
return current;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -56,17 +50,12 @@ public class InMemoryRichGaugeRepository implements RichGaugeRepository {
|
||||
public void set(Metric<?> metric) {
|
||||
final String name = metric.getName();
|
||||
final double value = metric.getValue().doubleValue();
|
||||
this.repository.update(name, new Callback<RichGauge>() {
|
||||
|
||||
@Override
|
||||
public RichGauge modify(RichGauge current) {
|
||||
if (current == null) {
|
||||
return new RichGauge(name, value);
|
||||
}
|
||||
current.set(value);
|
||||
return current;
|
||||
this.repository.update(name, (current) -> {
|
||||
if (current == null) {
|
||||
return new RichGauge(name, value);
|
||||
}
|
||||
|
||||
current.set(value);
|
||||
return current;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -191,7 +191,7 @@ public class WebRequestTraceFilter extends OncePerRequestFilter implements Order
|
||||
}
|
||||
|
||||
private Map<String, String[]> getParameterMapCopy(HttpServletRequest request) {
|
||||
return new LinkedHashMap<String, String[]>(request.getParameterMap());
|
||||
return new LinkedHashMap<>(request.getParameterMap());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.boot.actuate.autoconfigure;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
@@ -277,12 +276,9 @@ public class EndpointAutoConfigurationTests {
|
||||
|
||||
@Bean
|
||||
PublicMetrics customPublicMetrics() {
|
||||
return new PublicMetrics() {
|
||||
@Override
|
||||
public Collection<Metric<?>> metrics() {
|
||||
Metric<Integer> metric = new Metric<>("foo", 1);
|
||||
return Collections.<Metric<?>>singleton(metric);
|
||||
}
|
||||
return () -> {
|
||||
Metric<Integer> metric = new Metric<>("foo", 1);
|
||||
return Collections.<Metric<?>>singleton(metric);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -294,12 +290,9 @@ public class EndpointAutoConfigurationTests {
|
||||
@Bean
|
||||
@Order(InfoContributorAutoConfiguration.DEFAULT_ORDER - 1)
|
||||
public InfoContributor myInfoContributor() {
|
||||
return new InfoContributor() {
|
||||
@Override
|
||||
public void contribute(Info.Builder builder) {
|
||||
builder.withDetail("name", "bar");
|
||||
builder.withDetail("version", "1.0");
|
||||
}
|
||||
return (builder) -> {
|
||||
builder.withDetail("name", "bar");
|
||||
builder.withDetail("version", "1.0");
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.endpoint.Endpoint;
|
||||
import org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping;
|
||||
import org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMappingCustomizer;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
@@ -134,14 +133,7 @@ public class EndpointMvcIntegrationTests {
|
||||
|
||||
@Bean
|
||||
public EndpointHandlerMappingCustomizer mappingCustomizer() {
|
||||
return new EndpointHandlerMappingCustomizer() {
|
||||
|
||||
@Override
|
||||
public void customize(EndpointHandlerMapping mapping) {
|
||||
mapping.setInterceptors(interceptor());
|
||||
}
|
||||
|
||||
};
|
||||
return (mapping) -> mapping.setInterceptors(interceptor());
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -808,14 +808,7 @@ public class EndpointWebMvcAutoConfigurationTests {
|
||||
|
||||
@Bean
|
||||
public EndpointHandlerMappingCustomizer mappingCustomizer() {
|
||||
return new EndpointHandlerMappingCustomizer() {
|
||||
|
||||
@Override
|
||||
public void customize(EndpointHandlerMapping mapping) {
|
||||
mapping.setInterceptors(interceptor());
|
||||
}
|
||||
|
||||
};
|
||||
return (mapping) -> mapping.setInterceptors(interceptor());
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -447,12 +447,7 @@ public class HealthIndicatorAutoConfigurationTests {
|
||||
|
||||
@Bean
|
||||
public HealthIndicator customHealthIndicator() {
|
||||
return new HealthIndicator() {
|
||||
@Override
|
||||
public Health health() {
|
||||
return Health.down().build();
|
||||
}
|
||||
};
|
||||
return () -> Health.down().build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -190,10 +190,7 @@ public class InfoContributorAutoConfigurationTests {
|
||||
|
||||
@Bean
|
||||
public InfoContributor customInfoContributor() {
|
||||
return new InfoContributor() {
|
||||
@Override
|
||||
public void contribute(Info.Builder builder) {
|
||||
}
|
||||
return (builder) -> {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -42,8 +42,6 @@ import org.springframework.security.authentication.TestingAuthenticationToken;
|
||||
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
|
||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||
import org.springframework.security.config.annotation.authentication.configuration.EnableGlobalAuthentication;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.AuthorityUtils;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
@@ -284,14 +282,8 @@ public class ManagementWebSecurityAutoConfigurationTests {
|
||||
|
||||
@Bean
|
||||
public AuthenticationManager myAuthenticationManager() {
|
||||
this.authenticationManager = new AuthenticationManager() {
|
||||
|
||||
@Override
|
||||
public Authentication authenticate(Authentication authentication)
|
||||
throws AuthenticationException {
|
||||
return new TestingAuthenticationToken("foo", "bar");
|
||||
}
|
||||
};
|
||||
this.authenticationManager = (
|
||||
authentication) -> new TestingAuthenticationToken("foo", "bar");
|
||||
return this.authenticationManager;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,9 +39,6 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.integration.channel.FixedSubscriberChannel;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.messaging.SubscribableChannel;
|
||||
import org.springframework.scheduling.annotation.SchedulingConfigurer;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
@@ -169,12 +166,7 @@ public class MetricExportAutoConfigurationTests {
|
||||
|
||||
@Bean
|
||||
public SubscribableChannel metricsChannel() {
|
||||
return new FixedSubscriberChannel(new MessageHandler() {
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message<?> message) throws MessagingException {
|
||||
}
|
||||
|
||||
return new FixedSubscriberChannel((message) -> {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -26,8 +26,6 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import org.springframework.boot.actuate.metrics.CounterService;
|
||||
import org.springframework.boot.actuate.metrics.GaugeService;
|
||||
@@ -100,12 +98,9 @@ public class MetricFilterAutoConfigurationTests {
|
||||
"/test/path");
|
||||
final MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
FilterChain chain = mock(FilterChain.class);
|
||||
willAnswer(new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
response.setStatus(200);
|
||||
return null;
|
||||
}
|
||||
willAnswer((invocation) -> {
|
||||
response.setStatus(200);
|
||||
return null;
|
||||
}).given(chain).doFilter(request, response);
|
||||
filter.doFilter(request, response, chain);
|
||||
verify(context.getBean(CounterService.class)).increment("status.200.test.path");
|
||||
@@ -364,12 +359,9 @@ public class MetricFilterAutoConfigurationTests {
|
||||
"/test/path");
|
||||
final MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
FilterChain chain = mock(FilterChain.class);
|
||||
willAnswer(new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
response.setStatus(200);
|
||||
return null;
|
||||
}
|
||||
willAnswer((invocation) -> {
|
||||
response.setStatus(200);
|
||||
return null;
|
||||
}).given(chain).doFilter(request, response);
|
||||
filter.doFilter(request, response, chain);
|
||||
verify(context.getBean(GaugeService.class)).submit(eq("response.test.path"),
|
||||
@@ -395,12 +387,9 @@ public class MetricFilterAutoConfigurationTests {
|
||||
"/test/path");
|
||||
final MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
FilterChain chain = mock(FilterChain.class);
|
||||
willAnswer(new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
response.setStatus(200);
|
||||
return null;
|
||||
}
|
||||
willAnswer((invocation) -> {
|
||||
response.setStatus(200);
|
||||
return null;
|
||||
}).given(chain).doFilter(request, response);
|
||||
filter.doFilter(request, response, chain);
|
||||
verify(context.getBean(GaugeService.class), never()).submit(anyString(),
|
||||
@@ -420,13 +409,10 @@ public class MetricFilterAutoConfigurationTests {
|
||||
"/test/path");
|
||||
final MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
FilterChain chain = mock(FilterChain.class);
|
||||
willAnswer(new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
response.setStatus(200);
|
||||
response.setCommitted(true);
|
||||
throw new IOException();
|
||||
}
|
||||
willAnswer((invocation) -> {
|
||||
response.setStatus(200);
|
||||
response.setCommitted(true);
|
||||
throw new IOException();
|
||||
}).given(chain).doFilter(request, response);
|
||||
try {
|
||||
filter.doFilter(request, response, chain);
|
||||
@@ -505,16 +491,12 @@ public class MetricFilterAutoConfigurationTests {
|
||||
@RequestMapping("create")
|
||||
public DeferredResult<ResponseEntity<String>> create() {
|
||||
final DeferredResult<ResponseEntity<String>> result = new DeferredResult<>();
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
MetricFilterTestController.this.latch.await();
|
||||
result.setResult(
|
||||
new ResponseEntity<>("Done", HttpStatus.CREATED));
|
||||
}
|
||||
catch (InterruptedException ex) {
|
||||
}
|
||||
new Thread(() -> {
|
||||
try {
|
||||
MetricFilterTestController.this.latch.await();
|
||||
result.setResult(new ResponseEntity<>("Done", HttpStatus.CREATED));
|
||||
}
|
||||
catch (InterruptedException ex) {
|
||||
}
|
||||
}).start();
|
||||
return result;
|
||||
@@ -523,16 +505,12 @@ public class MetricFilterAutoConfigurationTests {
|
||||
@RequestMapping("createFailure")
|
||||
public DeferredResult<ResponseEntity<String>> createFailure() {
|
||||
final DeferredResult<ResponseEntity<String>> result = new DeferredResult<>();
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
MetricFilterTestController.this.latch.await();
|
||||
result.setErrorResult(new Exception("It failed"));
|
||||
}
|
||||
catch (InterruptedException ex) {
|
||||
|
||||
}
|
||||
new Thread(() -> {
|
||||
try {
|
||||
MetricFilterTestController.this.latch.await();
|
||||
result.setErrorResult(new Exception("It failed"));
|
||||
}
|
||||
catch (InterruptedException ex) {
|
||||
}
|
||||
}).start();
|
||||
return result;
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.boot.actuate.autoconfigure;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -54,7 +53,6 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.jdbc.core.ConnectionCallback;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
@@ -140,18 +138,10 @@ public class PublicMetricsAutoConfigurationTests {
|
||||
Collection<Metric<?>> metrics = bean.metrics();
|
||||
assertMetrics(metrics, "datasource.tomcat.active", "datasource.tomcat.usage",
|
||||
"datasource.commonsDbcp.active", "datasource.commonsDbcp.usage");
|
||||
|
||||
// Hikari won't work unless a first connection has been retrieved
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(
|
||||
this.context.getBean("hikariDS", DataSource.class));
|
||||
jdbcTemplate.execute(new ConnectionCallback<Void>() {
|
||||
@Override
|
||||
public Void doInConnection(Connection connection)
|
||||
throws SQLException, DataAccessException {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
jdbcTemplate.execute((ConnectionCallback<Void>) (connection) -> null);
|
||||
Collection<Metric<?>> anotherMetrics = bean.metrics();
|
||||
assertMetrics(anotherMetrics, "datasource.tomcat.active",
|
||||
"datasource.tomcat.usage", "datasource.hikariDS.active",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
@@ -26,7 +26,6 @@ import org.springframework.boot.actuate.endpoint.mvc.AbstractEndpointHandlerMapp
|
||||
import org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter;
|
||||
import org.springframework.boot.actuate.endpoint.mvc.HalJsonMvcEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.mvc.ManagementServletContext;
|
||||
import org.springframework.boot.actuate.endpoint.mvc.NamedMvcEndpoint;
|
||||
import org.springframework.boot.actuate.health.HealthIndicator;
|
||||
import org.springframework.boot.actuate.health.OrderedHealthAggregator;
|
||||
@@ -118,14 +117,7 @@ public class CloudFoundryEndpointHandlerMappingTests
|
||||
private static class TestHalJsonMvcEndpoint extends HalJsonMvcEndpoint {
|
||||
|
||||
TestHalJsonMvcEndpoint() {
|
||||
super(new ManagementServletContext() {
|
||||
|
||||
@Override
|
||||
public String getContextPath() {
|
||||
return "";
|
||||
}
|
||||
|
||||
});
|
||||
super(() -> "");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ import static org.assertj.core.api.Assertions.entry;
|
||||
*/
|
||||
public class CachePublicMetricsTests {
|
||||
|
||||
private Map<String, CacheManager> cacheManagers = new HashMap<String, CacheManager>();
|
||||
private Map<String, CacheManager> cacheManagers = new HashMap<>();
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
@@ -98,7 +98,7 @@ public class CachePublicMetricsTests {
|
||||
private Map<String, Number> metrics(CachePublicMetrics cpm) {
|
||||
Collection<Metric<?>> metrics = cpm.metrics();
|
||||
assertThat(metrics).isNotNull();
|
||||
Map<String, Number> result = new HashMap<String, Number>();
|
||||
Map<String, Number> result = new HashMap<>();
|
||||
for (Metric<?> metric : metrics) {
|
||||
result.put(metric.getName(), metric.getValue());
|
||||
}
|
||||
|
||||
@@ -435,9 +435,9 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
|
||||
|
||||
public static class InitializedMapAndListProperties extends Foo {
|
||||
|
||||
private Map<String, Boolean> map = new HashMap<String, Boolean>();
|
||||
private Map<String, Boolean> map = new HashMap<>();
|
||||
|
||||
private List<String> list = new ArrayList<String>();
|
||||
private List<String> list = new ArrayList<>();
|
||||
|
||||
public Map<String, Boolean> getMap() {
|
||||
return this.map;
|
||||
|
||||
@@ -268,7 +268,7 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
MutablePropertySources propertySources = this.context.getEnvironment()
|
||||
.getPropertySources();
|
||||
Map<String, Object> source = new HashMap<String, Object>();
|
||||
Map<String, Object> source = new HashMap<>();
|
||||
source.put("foo", Collections.singletonMap("bar", "baz"));
|
||||
propertySources.addFirst(new MapPropertySource("test", source));
|
||||
this.context.register(Config.class);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
@@ -61,13 +61,7 @@ public class HealthEndpointTests extends AbstractEndpointTests<HealthEndpoint> {
|
||||
|
||||
@Bean
|
||||
public HealthIndicator statusHealthIndicator() {
|
||||
return new HealthIndicator() {
|
||||
|
||||
@Override
|
||||
public Health health() {
|
||||
return new Health.Builder().status("FINE").build();
|
||||
}
|
||||
};
|
||||
return () -> new Health.Builder().status("FINE").build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
@@ -21,7 +21,6 @@ import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.actuate.info.Info;
|
||||
import org.springframework.boot.actuate.info.InfoContributor;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -54,14 +53,7 @@ public class InfoEndpointTests extends AbstractEndpointTests<InfoEndpoint> {
|
||||
|
||||
@Bean
|
||||
public InfoContributor infoContributor() {
|
||||
return new InfoContributor() {
|
||||
|
||||
@Override
|
||||
public void contribute(Info.Builder builder) {
|
||||
builder.withDetail("key1", "value1");
|
||||
}
|
||||
|
||||
};
|
||||
return (builder) -> builder.withDetail("key1", "value1");
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -100,14 +100,8 @@ public class MetricsEndpointTests extends AbstractEndpointTests<MetricsEndpoint>
|
||||
|
||||
@Bean
|
||||
public MetricsEndpoint endpoint() {
|
||||
final Metric<Float> metric = new Metric<>("a", 0.5f);
|
||||
PublicMetrics metrics = new PublicMetrics() {
|
||||
@Override
|
||||
public Collection<Metric<?>> metrics() {
|
||||
return Collections.<Metric<?>>singleton(metric);
|
||||
}
|
||||
};
|
||||
return new MetricsEndpoint(metrics);
|
||||
Metric<?> metric = new Metric<>("a", 0.5f);
|
||||
return new MetricsEndpoint(() -> Collections.singleton(metric));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
@@ -88,15 +88,10 @@ public class ShutdownEndpointTests extends AbstractEndpointTests<ShutdownEndpoin
|
||||
|
||||
@Bean
|
||||
public ApplicationListener<ContextClosedEvent> listener() {
|
||||
return new ApplicationListener<ContextClosedEvent>() {
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ContextClosedEvent event) {
|
||||
Config.this.threadContextClassLoader = Thread.currentThread()
|
||||
.getContextClassLoader();
|
||||
Config.this.latch.countDown();
|
||||
}
|
||||
|
||||
return (event) -> {
|
||||
this.threadContextClassLoader = Thread.currentThread()
|
||||
.getContextClassLoader();
|
||||
this.latch.countDown();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -89,12 +89,7 @@ public class ShutdownParentEndpointTests {
|
||||
|
||||
@Bean
|
||||
public ApplicationListener<ContextClosedEvent> listener() {
|
||||
return new ApplicationListener<ContextClosedEvent>() {
|
||||
@Override
|
||||
public void onApplicationEvent(ContextClosedEvent event) {
|
||||
Config.this.latch.countDown();
|
||||
}
|
||||
};
|
||||
return (event) -> this.latch.countDown();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -142,7 +142,7 @@ public class EnvironmentMvcEndpointTests {
|
||||
@Test
|
||||
public void nestedPathWhenPlaceholderCannotBeResolvedShouldReturnUnresolvedProperty()
|
||||
throws Exception {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("my.foo", "${my.bar}");
|
||||
((ConfigurableEnvironment) this.context.getEnvironment()).getPropertySources()
|
||||
.addFirst(new MapPropertySource("unresolved-placeholder", map));
|
||||
@@ -152,7 +152,7 @@ public class EnvironmentMvcEndpointTests {
|
||||
|
||||
@Test
|
||||
public void nestedPathWithSensitivePlaceholderShouldSanitize() throws Exception {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("my.foo", "${my.password}");
|
||||
map.put("my.password", "hello");
|
||||
((ConfigurableEnvironment) this.context.getEnvironment()).getPropertySources()
|
||||
@@ -165,7 +165,7 @@ public class EnvironmentMvcEndpointTests {
|
||||
public void propertyWithTypeOtherThanStringShouldNotFail() throws Exception {
|
||||
MutablePropertySources propertySources = ((ConfigurableEnvironment) this.context
|
||||
.getEnvironment()).getPropertySources();
|
||||
Map<String, Object> source = new HashMap<String, Object>();
|
||||
Map<String, Object> source = new HashMap<>();
|
||||
source.put("foo", Collections.singletonMap("bar", "baz"));
|
||||
propertySources.addFirst(new MapPropertySource("test", source));
|
||||
this.mvc.perform(get("/application/env/foo.*")).andExpect(status().isOk())
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.boot.actuate.endpoint.mvc;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -110,24 +109,17 @@ public class HeapdumpMvcEndpointSecureOptionsTests {
|
||||
|
||||
@Override
|
||||
protected HeapDumper createHeapDumper() {
|
||||
return new HeapDumper() {
|
||||
|
||||
@Override
|
||||
public void dumpHeap(File file, boolean live)
|
||||
throws IOException, InterruptedException {
|
||||
if (!TestHeapdumpMvcEndpoint.this.available) {
|
||||
throw new HeapDumperUnavailableException("Not available", null);
|
||||
}
|
||||
if (TestHeapdumpMvcEndpoint.this.locked) {
|
||||
throw new InterruptedException();
|
||||
}
|
||||
if (file.exists()) {
|
||||
throw new IOException("File exists");
|
||||
}
|
||||
FileCopyUtils.copy(TestHeapdumpMvcEndpoint.this.heapDump.getBytes(),
|
||||
file);
|
||||
return (file, live) -> {
|
||||
if (!TestHeapdumpMvcEndpoint.this.available) {
|
||||
throw new HeapDumperUnavailableException("Not available", null);
|
||||
}
|
||||
|
||||
if (TestHeapdumpMvcEndpoint.this.locked) {
|
||||
throw new InterruptedException();
|
||||
}
|
||||
if (file.exists()) {
|
||||
throw new IOException("File exists");
|
||||
}
|
||||
FileCopyUtils.copy(this.heapDump.getBytes(), file);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.boot.actuate.endpoint.mvc;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
@@ -150,24 +149,17 @@ public class HeapdumpMvcEndpointTests {
|
||||
|
||||
@Override
|
||||
protected HeapDumper createHeapDumper() {
|
||||
return new HeapDumper() {
|
||||
|
||||
@Override
|
||||
public void dumpHeap(File file, boolean live)
|
||||
throws IOException, InterruptedException {
|
||||
if (!TestHeapdumpMvcEndpoint.this.available) {
|
||||
throw new HeapDumperUnavailableException("Not available", null);
|
||||
}
|
||||
if (TestHeapdumpMvcEndpoint.this.locked) {
|
||||
throw new InterruptedException();
|
||||
}
|
||||
if (file.exists()) {
|
||||
throw new IOException("File exists");
|
||||
}
|
||||
FileCopyUtils.copy(TestHeapdumpMvcEndpoint.this.heapDump.getBytes(),
|
||||
file);
|
||||
return (file, live) -> {
|
||||
if (!TestHeapdumpMvcEndpoint.this.available) {
|
||||
throw new HeapDumperUnavailableException("Not available", null);
|
||||
}
|
||||
|
||||
if (TestHeapdumpMvcEndpoint.this.locked) {
|
||||
throw new InterruptedException();
|
||||
}
|
||||
if (file.exists()) {
|
||||
throw new IOException("File exists");
|
||||
}
|
||||
FileCopyUtils.copy(this.heapDump.getBytes(), file);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.autoconfigure.AuditAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration;
|
||||
import org.springframework.boot.actuate.endpoint.InfoEndpoint;
|
||||
import org.springframework.boot.actuate.info.Info;
|
||||
import org.springframework.boot.actuate.info.InfoContributor;
|
||||
import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
|
||||
@@ -110,28 +109,21 @@ public class InfoMvcEndpointTests {
|
||||
|
||||
@Bean
|
||||
public InfoContributor beanName1() {
|
||||
return new InfoContributor() {
|
||||
|
||||
@Override
|
||||
public void contribute(Info.Builder builder) {
|
||||
Map<String, Object> content = new LinkedHashMap<>();
|
||||
content.put("key11", "value11");
|
||||
content.put("key12", "value12");
|
||||
builder.withDetail("beanName1", content);
|
||||
}
|
||||
return (builder) -> {
|
||||
Map<String, Object> content = new LinkedHashMap<>();
|
||||
content.put("key11", "value11");
|
||||
content.put("key12", "value12");
|
||||
builder.withDetail("beanName1", content);
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
public InfoContributor beanName2() {
|
||||
return new InfoContributor() {
|
||||
@Override
|
||||
public void contribute(Info.Builder builder) {
|
||||
Map<String, Object> content = new LinkedHashMap<>();
|
||||
content.put("key21", "value21");
|
||||
content.put("key22", "value22");
|
||||
builder.withDetail("beanName2", content);
|
||||
}
|
||||
return (builder) -> {
|
||||
Map<String, Object> content = new LinkedHashMap<>();
|
||||
content.put("key21", "value21");
|
||||
content.put("key22", "value22");
|
||||
builder.withDetail("beanName2", content);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.boot.actuate.endpoint.mvc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -28,7 +27,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.autoconfigure.AuditAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration;
|
||||
import org.springframework.boot.actuate.endpoint.MetricsEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.PublicMetrics;
|
||||
import org.springframework.boot.actuate.metrics.Metric;
|
||||
import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
|
||||
@@ -182,21 +180,16 @@ public class MetricsMvcEndpointTests {
|
||||
|
||||
@Bean
|
||||
public MetricsEndpoint endpoint() {
|
||||
return new MetricsEndpoint(new PublicMetrics() {
|
||||
|
||||
@Override
|
||||
public Collection<Metric<?>> metrics() {
|
||||
ArrayList<Metric<?>> metrics = new ArrayList<>();
|
||||
metrics.add(new Metric<>("foo", 1));
|
||||
metrics.add(new Metric<>("bar.png", 1));
|
||||
metrics.add(new Metric<>("group1.a", 1));
|
||||
metrics.add(new Metric<>("group1.b", 1));
|
||||
metrics.add(new Metric<>("group2.a", 1));
|
||||
metrics.add(new Metric<>("group2_a", 1));
|
||||
metrics.add(new Metric<Integer>("baz", null));
|
||||
return Collections.unmodifiableList(metrics);
|
||||
}
|
||||
|
||||
return new MetricsEndpoint(() -> {
|
||||
ArrayList<Metric<?>> metrics = new ArrayList<>();
|
||||
metrics.add(new Metric<>("foo", 1));
|
||||
metrics.add(new Metric<>("bar.png", 1));
|
||||
metrics.add(new Metric<>("group1.a", 1));
|
||||
metrics.add(new Metric<>("group1.b", 1));
|
||||
metrics.add(new Metric<>("group2.a", 1));
|
||||
metrics.add(new Metric<>("group2_a", 1));
|
||||
metrics.add(new Metric<Integer>("baz", null));
|
||||
return Collections.unmodifiableList(metrics);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@ import org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions
|
||||
import org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathRunner;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.request.RequestPostProcessor;
|
||||
@@ -93,16 +92,10 @@ public class NoSpringSecurityHealthMvcEndpointIntegrationTests {
|
||||
}
|
||||
|
||||
private RequestPostProcessor getRequestPostProcessor() {
|
||||
return new RequestPostProcessor() {
|
||||
|
||||
@Override
|
||||
public MockHttpServletRequest postProcessRequest(
|
||||
MockHttpServletRequest request) {
|
||||
Principal principal = mock(Principal.class);
|
||||
request.setUserPrincipal(principal);
|
||||
return request;
|
||||
}
|
||||
|
||||
return (request) -> {
|
||||
Principal principal = mock(Principal.class);
|
||||
request.setUserPrincipal(principal);
|
||||
return request;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -115,14 +108,7 @@ public class NoSpringSecurityHealthMvcEndpointIntegrationTests {
|
||||
|
||||
@Bean
|
||||
public HealthIndicator testHealthIndicator() {
|
||||
return new HealthIndicator() {
|
||||
|
||||
@Override
|
||||
public Health health() {
|
||||
return Health.up().withDetail("hello", "world").build();
|
||||
}
|
||||
|
||||
};
|
||||
return () -> Health.up().withDetail("hello", "world").build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,8 +22,6 @@ import java.util.concurrent.TimeUnit;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -123,14 +121,9 @@ public class ShutdownMvcEndpointTests {
|
||||
throws BeansException {
|
||||
ConfigurableApplicationContext mockContext = mock(
|
||||
ConfigurableApplicationContext.class);
|
||||
willAnswer(new Answer<Void>() {
|
||||
|
||||
@Override
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||
TestShutdownEndpoint.this.contextCloseLatch.countDown();
|
||||
return null;
|
||||
}
|
||||
|
||||
willAnswer((invocation) -> {
|
||||
TestShutdownEndpoint.this.contextCloseLatch.countDown();
|
||||
return null;
|
||||
}).given(mockContext).close();
|
||||
super.setApplicationContext(mockContext);
|
||||
}
|
||||
|
||||
@@ -26,8 +26,6 @@ import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.atomic.DoubleAdder;
|
||||
import java.util.concurrent.atomic.LongAdder;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
@@ -38,7 +36,6 @@ import org.junit.experimental.theories.Theory;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.boot.actuate.metrics.GaugeService;
|
||||
import org.springframework.boot.actuate.metrics.Metric;
|
||||
import org.springframework.util.StopWatch;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -79,7 +76,7 @@ public class BufferGaugeServiceSpeedTests {
|
||||
@BeforeClass
|
||||
public static void prime() throws FileNotFoundException {
|
||||
err = new NullPrintWriter();
|
||||
final Random random = new Random();
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
sample[i] = names[random.nextInt(names.length)];
|
||||
}
|
||||
@@ -98,21 +95,11 @@ public class BufferGaugeServiceSpeedTests {
|
||||
watch.start("readRaw" + count);
|
||||
for (String name : names) {
|
||||
this.gauges.forEach(Pattern.compile(name).asPredicate(),
|
||||
new BiConsumer<String, GaugeBuffer>() {
|
||||
@Override
|
||||
public void accept(String name, GaugeBuffer value) {
|
||||
err.println(name + "=" + value);
|
||||
}
|
||||
});
|
||||
(key, value) -> err.println(key + "=" + value));
|
||||
}
|
||||
final DoubleAdder total = new DoubleAdder();
|
||||
DoubleAdder total = new DoubleAdder();
|
||||
this.gauges.forEach(Pattern.compile(".*").asPredicate(),
|
||||
new BiConsumer<String, GaugeBuffer>() {
|
||||
@Override
|
||||
public void accept(String name, GaugeBuffer value) {
|
||||
total.add(value.getValue());
|
||||
}
|
||||
});
|
||||
(name, value) -> total.add(value.getValue()));
|
||||
watch.stop();
|
||||
System.err.println("Read(" + count + ")=" + watch.getLastTaskTimeMillis() + "ms");
|
||||
assertThat(number * threadCount < total.longValue()).isTrue();
|
||||
@@ -124,19 +111,9 @@ public class BufferGaugeServiceSpeedTests {
|
||||
double rate = number / watch.getLastTaskTimeMillis() * 1000;
|
||||
System.err.println("Rate(" + count + ")=" + rate + ", " + watch);
|
||||
watch.start("readReader" + count);
|
||||
this.reader.findAll().forEach(new Consumer<Metric<?>>() {
|
||||
@Override
|
||||
public void accept(Metric<?> metric) {
|
||||
err.println(metric);
|
||||
}
|
||||
});
|
||||
final LongAdder total = new LongAdder();
|
||||
this.reader.findAll().forEach(new Consumer<Metric<?>>() {
|
||||
@Override
|
||||
public void accept(Metric<?> value) {
|
||||
total.add(value.getValue().intValue());
|
||||
}
|
||||
});
|
||||
this.reader.findAll().forEach((metric) -> err.println(metric));
|
||||
LongAdder total = new LongAdder();
|
||||
this.reader.findAll().forEach((value) -> total.add(value.getValue().intValue()));
|
||||
watch.stop();
|
||||
System.err.println("Read(" + count + ")=" + watch.getLastTaskTimeMillis() + "ms");
|
||||
assertThat(0 < total.longValue()).isTrue();
|
||||
@@ -145,13 +122,10 @@ public class BufferGaugeServiceSpeedTests {
|
||||
private void iterate(String taskName) throws Exception {
|
||||
watch.start(taskName + count++);
|
||||
ExecutorService pool = Executors.newFixedThreadPool(threadCount);
|
||||
Runnable task = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (int i = 0; i < number; i++) {
|
||||
String name = sample[i % sample.length];
|
||||
BufferGaugeServiceSpeedTests.this.service.submit(name, count + i);
|
||||
}
|
||||
Runnable task = () -> {
|
||||
for (int i = 0; i < number; i++) {
|
||||
String name = sample[i % sample.length];
|
||||
BufferGaugeServiceSpeedTests.this.service.submit(name, count + i);
|
||||
}
|
||||
};
|
||||
Collection<Future<?>> futures = new HashSet<>();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.boot.actuate.metrics.buffer;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -36,23 +34,15 @@ public class CounterBuffersTests {
|
||||
@Test
|
||||
public void inAndOut() {
|
||||
this.buffers.increment("foo", 2);
|
||||
this.buffers.doWith("foo", new Consumer<CounterBuffer>() {
|
||||
@Override
|
||||
public void accept(CounterBuffer buffer) {
|
||||
CounterBuffersTests.this.value = buffer.getValue();
|
||||
}
|
||||
});
|
||||
this.buffers.doWith("foo",
|
||||
(buffer) -> CounterBuffersTests.this.value = buffer.getValue());
|
||||
assertThat(this.value).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNonExistent() {
|
||||
this.buffers.doWith("foo", new Consumer<CounterBuffer>() {
|
||||
@Override
|
||||
public void accept(CounterBuffer buffer) {
|
||||
CounterBuffersTests.this.value = buffer.getValue();
|
||||
}
|
||||
});
|
||||
this.buffers.doWith("foo",
|
||||
(buffer) -> CounterBuffersTests.this.value = buffer.getValue());
|
||||
assertThat(this.value).isEqualTo(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,8 +25,6 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.atomic.LongAdder;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
@@ -37,7 +35,6 @@ import org.junit.experimental.theories.Theory;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.boot.actuate.metrics.CounterService;
|
||||
import org.springframework.boot.actuate.metrics.Metric;
|
||||
import org.springframework.util.StopWatch;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -78,7 +75,7 @@ public class CounterServiceSpeedTests {
|
||||
@BeforeClass
|
||||
public static void prime() throws FileNotFoundException {
|
||||
err = new NullPrintWriter();
|
||||
final Random random = new Random();
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
sample[i] = names[random.nextInt(names.length)];
|
||||
}
|
||||
@@ -97,21 +94,11 @@ public class CounterServiceSpeedTests {
|
||||
watch.start("readRaw" + count);
|
||||
for (String name : names) {
|
||||
this.counters.forEach(Pattern.compile(name).asPredicate(),
|
||||
new BiConsumer<String, CounterBuffer>() {
|
||||
@Override
|
||||
public void accept(String name, CounterBuffer value) {
|
||||
err.println(name + "=" + value);
|
||||
}
|
||||
});
|
||||
(key, value) -> err.println(key + "=" + value));
|
||||
}
|
||||
final LongAdder total = new LongAdder();
|
||||
LongAdder total = new LongAdder();
|
||||
this.counters.forEach(Pattern.compile(".*").asPredicate(),
|
||||
new BiConsumer<String, CounterBuffer>() {
|
||||
@Override
|
||||
public void accept(String name, CounterBuffer value) {
|
||||
total.add(value.getValue());
|
||||
}
|
||||
});
|
||||
(name, value) -> total.add(value.getValue()));
|
||||
watch.stop();
|
||||
System.err.println("Read(" + count + ")=" + watch.getLastTaskTimeMillis() + "ms");
|
||||
assertThat(total.longValue()).isEqualTo(number * threadCount);
|
||||
@@ -123,19 +110,9 @@ public class CounterServiceSpeedTests {
|
||||
double rate = number / watch.getLastTaskTimeMillis() * 1000;
|
||||
System.err.println("Rate(" + count + ")=" + rate + ", " + watch);
|
||||
watch.start("readReader" + count);
|
||||
this.reader.findAll().forEach(new Consumer<Metric<?>>() {
|
||||
@Override
|
||||
public void accept(Metric<?> metric) {
|
||||
err.println(metric);
|
||||
}
|
||||
});
|
||||
final LongAdder total = new LongAdder();
|
||||
this.reader.findAll().forEach(new Consumer<Metric<?>>() {
|
||||
@Override
|
||||
public void accept(Metric<?> value) {
|
||||
total.add(value.getValue().intValue());
|
||||
}
|
||||
});
|
||||
this.reader.findAll().forEach(err::println);
|
||||
LongAdder total = new LongAdder();
|
||||
this.reader.findAll().forEach((value) -> total.add(value.getValue().intValue()));
|
||||
watch.stop();
|
||||
System.err.println("Read(" + count + ")=" + watch.getLastTaskTimeMillis() + "ms");
|
||||
assertThat(total.longValue()).isEqualTo(number * threadCount);
|
||||
@@ -144,13 +121,10 @@ public class CounterServiceSpeedTests {
|
||||
private void iterate(String taskName) throws Exception {
|
||||
watch.start(taskName + count++);
|
||||
ExecutorService pool = Executors.newFixedThreadPool(threadCount);
|
||||
Runnable task = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (int i = 0; i < number; i++) {
|
||||
String name = sample[i % sample.length];
|
||||
CounterServiceSpeedTests.this.service.increment(name);
|
||||
}
|
||||
Runnable task = () -> {
|
||||
for (int i = 0; i < number; i++) {
|
||||
String name = sample[i % sample.length];
|
||||
CounterServiceSpeedTests.this.service.increment(name);
|
||||
}
|
||||
};
|
||||
Collection<Future<?>> futures = new HashSet<>();
|
||||
|
||||
@@ -25,7 +25,6 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.atomic.LongAdder;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.experimental.theories.DataPoints;
|
||||
@@ -34,7 +33,6 @@ import org.junit.experimental.theories.Theory;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.boot.actuate.metrics.CounterService;
|
||||
import org.springframework.boot.actuate.metrics.Metric;
|
||||
import org.springframework.boot.actuate.metrics.reader.MetricReader;
|
||||
import org.springframework.boot.actuate.metrics.repository.InMemoryMetricRepository;
|
||||
import org.springframework.boot.actuate.metrics.writer.DefaultCounterService;
|
||||
@@ -87,13 +85,10 @@ public class DefaultCounterServiceSpeedTests {
|
||||
public void counters(String input) throws Exception {
|
||||
watch.start("counters" + count++);
|
||||
ExecutorService pool = Executors.newFixedThreadPool(threadCount);
|
||||
Runnable task = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (int i = 0; i < number; i++) {
|
||||
String name = sample[i % sample.length];
|
||||
DefaultCounterServiceSpeedTests.this.counterService.increment(name);
|
||||
}
|
||||
Runnable task = () -> {
|
||||
for (int i = 0; i < number; i++) {
|
||||
String name = sample[i % sample.length];
|
||||
DefaultCounterServiceSpeedTests.this.counterService.increment(name);
|
||||
}
|
||||
};
|
||||
Collection<Future<?>> futures = new HashSet<>();
|
||||
@@ -107,19 +102,9 @@ public class DefaultCounterServiceSpeedTests {
|
||||
double rate = number / watch.getLastTaskTimeMillis() * 1000;
|
||||
System.err.println("Counters rate(" + count + ")=" + rate + ", " + watch);
|
||||
watch.start("read" + count);
|
||||
this.reader.findAll().forEach(new Consumer<Metric<?>>() {
|
||||
@Override
|
||||
public void accept(Metric<?> metric) {
|
||||
err.println(metric);
|
||||
}
|
||||
});
|
||||
final LongAdder total = new LongAdder();
|
||||
this.reader.findAll().forEach(new Consumer<Metric<?>>() {
|
||||
@Override
|
||||
public void accept(Metric<?> value) {
|
||||
total.add(value.getValue().intValue());
|
||||
}
|
||||
});
|
||||
this.reader.findAll().forEach(err::println);
|
||||
LongAdder total = new LongAdder();
|
||||
this.reader.findAll().forEach((value) -> total.add(value.getValue().intValue()));
|
||||
watch.stop();
|
||||
System.err.println("Read(" + count + ")=" + watch.getLastTaskTimeMillis() + "ms");
|
||||
assertThat(total.longValue()).isEqualTo(number * threadCount);
|
||||
|
||||
@@ -25,7 +25,6 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.atomic.LongAdder;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.experimental.theories.DataPoints;
|
||||
@@ -34,7 +33,6 @@ import org.junit.experimental.theories.Theory;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.boot.actuate.metrics.GaugeService;
|
||||
import org.springframework.boot.actuate.metrics.Metric;
|
||||
import org.springframework.boot.actuate.metrics.reader.MetricReader;
|
||||
import org.springframework.boot.actuate.metrics.repository.InMemoryMetricRepository;
|
||||
import org.springframework.boot.actuate.metrics.writer.DefaultGaugeService;
|
||||
@@ -77,7 +75,7 @@ public class DefaultGaugeServiceSpeedTests {
|
||||
@BeforeClass
|
||||
public static void prime() throws FileNotFoundException {
|
||||
err = new NullPrintWriter();
|
||||
final Random random = new Random();
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
sample[i] = names[random.nextInt(names.length)];
|
||||
}
|
||||
@@ -87,14 +85,10 @@ public class DefaultGaugeServiceSpeedTests {
|
||||
public void gauges(String input) throws Exception {
|
||||
watch.start("gauges" + count++);
|
||||
ExecutorService pool = Executors.newFixedThreadPool(threadCount);
|
||||
Runnable task = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (int i = 0; i < number; i++) {
|
||||
String name = sample[i % sample.length];
|
||||
DefaultGaugeServiceSpeedTests.this.gaugeService.submit(name,
|
||||
count + i);
|
||||
}
|
||||
Runnable task = () -> {
|
||||
for (int i = 0; i < number; i++) {
|
||||
String name = sample[i % sample.length];
|
||||
DefaultGaugeServiceSpeedTests.this.gaugeService.submit(name, count + i);
|
||||
}
|
||||
};
|
||||
Collection<Future<?>> futures = new HashSet<>();
|
||||
@@ -108,19 +102,9 @@ public class DefaultGaugeServiceSpeedTests {
|
||||
double rate = number / watch.getLastTaskTimeMillis() * 1000;
|
||||
System.err.println("Gauges rate(" + count + ")=" + rate + ", " + watch);
|
||||
watch.start("read" + count);
|
||||
this.reader.findAll().forEach(new Consumer<Metric<?>>() {
|
||||
@Override
|
||||
public void accept(Metric<?> metric) {
|
||||
err.println(metric);
|
||||
}
|
||||
});
|
||||
final LongAdder total = new LongAdder();
|
||||
this.reader.findAll().forEach(new Consumer<Metric<?>>() {
|
||||
@Override
|
||||
public void accept(Metric<?> value) {
|
||||
total.add(value.getValue().intValue());
|
||||
}
|
||||
});
|
||||
this.reader.findAll().forEach(err::println);
|
||||
LongAdder total = new LongAdder();
|
||||
this.reader.findAll().forEach((value) -> total.add(value.getValue().intValue()));
|
||||
watch.stop();
|
||||
System.err.println("Read(" + count + ")=" + watch.getLastTaskTimeMillis() + "ms");
|
||||
assertThat(0 < total.longValue()).isTrue();
|
||||
|
||||
@@ -25,7 +25,6 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.atomic.LongAdder;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import org.junit.BeforeClass;
|
||||
@@ -35,7 +34,6 @@ import org.junit.experimental.theories.Theory;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.boot.actuate.metrics.CounterService;
|
||||
import org.springframework.boot.actuate.metrics.Metric;
|
||||
import org.springframework.boot.actuate.metrics.dropwizard.DropwizardMetricServices;
|
||||
import org.springframework.boot.actuate.metrics.reader.MetricReader;
|
||||
import org.springframework.boot.actuate.metrics.reader.MetricRegistryMetricReader;
|
||||
@@ -79,7 +77,7 @@ public class DropwizardCounterServiceSpeedTests {
|
||||
@BeforeClass
|
||||
public static void prime() throws FileNotFoundException {
|
||||
err = new NullPrintWriter();
|
||||
final Random random = new Random();
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
sample[i] = names[random.nextInt(names.length)];
|
||||
}
|
||||
@@ -89,14 +87,10 @@ public class DropwizardCounterServiceSpeedTests {
|
||||
public void counters(String input) throws Exception {
|
||||
watch.start("counters" + count++);
|
||||
ExecutorService pool = Executors.newFixedThreadPool(threadCount);
|
||||
Runnable task = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (int i = 0; i < number; i++) {
|
||||
String name = sample[i % sample.length];
|
||||
DropwizardCounterServiceSpeedTests.this.counterService
|
||||
.increment(name);
|
||||
}
|
||||
Runnable task = () -> {
|
||||
for (int i = 0; i < number; i++) {
|
||||
String name = sample[i % sample.length];
|
||||
DropwizardCounterServiceSpeedTests.this.counterService.increment(name);
|
||||
}
|
||||
};
|
||||
Collection<Future<?>> futures = new HashSet<>();
|
||||
@@ -110,19 +104,9 @@ public class DropwizardCounterServiceSpeedTests {
|
||||
double rate = number / watch.getLastTaskTimeMillis() * 1000;
|
||||
System.err.println("Counters rate(" + count + ")=" + rate + ", " + watch);
|
||||
watch.start("read" + count);
|
||||
this.reader.findAll().forEach(new Consumer<Metric<?>>() {
|
||||
@Override
|
||||
public void accept(Metric<?> metric) {
|
||||
err.println(metric);
|
||||
}
|
||||
});
|
||||
final LongAdder total = new LongAdder();
|
||||
this.reader.findAll().forEach(new Consumer<Metric<?>>() {
|
||||
@Override
|
||||
public void accept(Metric<?> value) {
|
||||
total.add(value.getValue().intValue());
|
||||
}
|
||||
});
|
||||
this.reader.findAll().forEach(err::println);
|
||||
LongAdder total = new LongAdder();
|
||||
this.reader.findAll().forEach((value) -> total.add(value.getValue().intValue()));
|
||||
watch.stop();
|
||||
System.err.println("Read(" + count + ")=" + watch.getLastTaskTimeMillis() + "ms");
|
||||
assertThat(total.longValue()).isEqualTo(number * threadCount);
|
||||
|
||||
@@ -41,14 +41,7 @@ public class MetricRegistryMetricReaderTests {
|
||||
|
||||
@Test
|
||||
public void nonNumberGaugesAreTolerated() {
|
||||
this.metricRegistry.register("test", new Gauge<Set<String>>() {
|
||||
|
||||
@Override
|
||||
public Set<String> getValue() {
|
||||
return new HashSet<>();
|
||||
}
|
||||
|
||||
});
|
||||
this.metricRegistry.register("test", (Gauge<Set<String>>) HashSet::new);
|
||||
assertThat(this.metricReader.findOne("test")).isNull();
|
||||
this.metricRegistry.remove("test");
|
||||
assertThat(this.metricReader.findOne("test")).isNull();
|
||||
@@ -57,14 +50,7 @@ public class MetricRegistryMetricReaderTests {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void numberGauge() {
|
||||
this.metricRegistry.register("test", new Gauge<Number>() {
|
||||
|
||||
@Override
|
||||
public Number getValue() {
|
||||
return Integer.valueOf(5);
|
||||
}
|
||||
|
||||
});
|
||||
this.metricRegistry.register("test", (Gauge<Number>) () -> Integer.valueOf(5));
|
||||
Metric<Integer> metric = (Metric<Integer>) this.metricReader.findOne("test");
|
||||
assertThat(metric.getValue()).isEqualTo(Integer.valueOf(5));
|
||||
this.metricRegistry.remove("test");
|
||||
|
||||
@@ -97,7 +97,7 @@ public class StatsdMetricWriterTests {
|
||||
|
||||
@Test
|
||||
public void incrementMetricWithInvalidCharsInName() throws Exception {
|
||||
this.writer.increment(new Delta<Long>("counter.fo:o", 3L));
|
||||
this.writer.increment(new Delta<>("counter.fo:o", 3L));
|
||||
this.server.waitForMessage();
|
||||
assertThat(this.server.messagesReceived().get(0))
|
||||
.isEqualTo("me.counter.fo-o:3|c");
|
||||
@@ -105,7 +105,7 @@ public class StatsdMetricWriterTests {
|
||||
|
||||
@Test
|
||||
public void setMetricWithInvalidCharsInName() throws Exception {
|
||||
this.writer.set(new Metric<Long>("gauge.f:o:o", 3L));
|
||||
this.writer.set(new Metric<>("gauge.f:o:o", 3L));
|
||||
this.server.waitForMessage();
|
||||
assertThat(this.server.messagesReceived().get(0)).isEqualTo("me.gauge.f-o-o:3|g");
|
||||
}
|
||||
|
||||
@@ -27,8 +27,6 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.actuate.metrics.util.SimpleInMemoryRepository.Callback;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
@@ -49,23 +47,13 @@ public class SimpleInMemoryRepositoryTests {
|
||||
@Test
|
||||
public void updateExisting() {
|
||||
this.repository.set("foo", "spam");
|
||||
this.repository.update("foo", new Callback<String>() {
|
||||
@Override
|
||||
public String modify(String current) {
|
||||
return "bar";
|
||||
}
|
||||
});
|
||||
this.repository.update("foo", (current) -> "bar");
|
||||
assertThat(this.repository.findOne("foo")).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateNonexistent() {
|
||||
this.repository.update("foo", new Callback<String>() {
|
||||
@Override
|
||||
public String modify(String current) {
|
||||
return "bar";
|
||||
}
|
||||
});
|
||||
this.repository.update("foo", (current) -> "bar");
|
||||
assertThat(this.repository.findOne("foo")).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@@ -114,16 +102,11 @@ public class SimpleInMemoryRepositoryTests {
|
||||
|
||||
@Override
|
||||
public Boolean call() throws Exception {
|
||||
this.repository.update("foo", new Callback<Integer>() {
|
||||
|
||||
@Override
|
||||
public Integer modify(Integer current) {
|
||||
if (current == null) {
|
||||
return RepositoryUpdate.this.delta;
|
||||
}
|
||||
return current + RepositoryUpdate.this.delta;
|
||||
this.repository.update("foo", (current) -> {
|
||||
if (current == null) {
|
||||
return RepositoryUpdate.this.delta;
|
||||
}
|
||||
|
||||
return current + RepositoryUpdate.this.delta;
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -20,8 +20,6 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import org.springframework.boot.actuate.metrics.Metric;
|
||||
import org.springframework.messaging.Message;
|
||||
@@ -51,15 +49,10 @@ public class MessageChannelMetricWriterTests {
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
given(this.channel.send(any(Message.class))).willAnswer(new Answer<Object>() {
|
||||
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
MessageChannelMetricWriterTests.this.handler
|
||||
.handleMessage(invocation.getArgument(0));
|
||||
return true;
|
||||
}
|
||||
|
||||
given(this.channel.send(any(Message.class))).willAnswer((invocation) -> {
|
||||
MessageChannelMetricWriterTests.this.handler
|
||||
.handleMessage(invocation.getArgument(0));
|
||||
return true;
|
||||
});
|
||||
this.writer = new MessageChannelMetricWriter(this.channel);
|
||||
this.handler = new MetricWriterMessageHandler(this.observer);
|
||||
|
||||
@@ -69,7 +69,7 @@ public class MockServletWebServerFactory extends AbstractServletWebServerFactory
|
||||
|
||||
public MockServletWebServer(ServletContextInitializer[] initializers, int port) {
|
||||
super(Arrays.stream(initializers)
|
||||
.map((i) -> (Initializer) (s) -> i.onStartup(s))
|
||||
.map((initializer) -> (Initializer) initializer::onStartup)
|
||||
.toArray(Initializer[]::new), port);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,10 +24,7 @@ import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -93,30 +90,17 @@ public class WebRequestTraceFilterTests {
|
||||
request.setPathInfo(url);
|
||||
tmp.deleteOnExit();
|
||||
request.setAuthType("authType");
|
||||
Principal principal = new Principal() {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "principalTest";
|
||||
}
|
||||
|
||||
};
|
||||
Principal principal = () -> "principalTest";
|
||||
request.setUserPrincipal(principal);
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
response.addHeader("Content-Type", "application/json");
|
||||
response.addHeader("Set-Cookie", "a=b");
|
||||
this.filter.doFilterInternal(request, response, new FilterChain() {
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response)
|
||||
throws IOException, ServletException {
|
||||
BufferedReader bufferedReader = request.getReader();
|
||||
while (bufferedReader.readLine() != null) {
|
||||
// read the contents as normal (forces cache to fill up)
|
||||
}
|
||||
response.getWriter().println("Goodbye, World!");
|
||||
this.filter.doFilterInternal(request, response, (req, resp) -> {
|
||||
BufferedReader bufferedReader = req.getReader();
|
||||
while (bufferedReader.readLine() != null) {
|
||||
// read the contents as normal (forces cache to fill up)
|
||||
}
|
||||
|
||||
resp.getWriter().println("Goodbye, World!");
|
||||
});
|
||||
assertThat(this.repository.findAll()).hasSize(1);
|
||||
Map<String, Object> trace = this.repository.findAll().iterator().next().getInfo();
|
||||
@@ -146,11 +130,7 @@ public class WebRequestTraceFilterTests {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
response.addHeader("Content-Type", "application/json");
|
||||
this.filter.doFilterInternal(request, response, new FilterChain() {
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response)
|
||||
throws IOException, ServletException {
|
||||
}
|
||||
this.filter.doFilterInternal(request, response, (req, resp) -> {
|
||||
});
|
||||
Map<String, Object> info = this.repository.findAll().iterator().next().getInfo();
|
||||
Map<String, Object> headers = (Map<String, Object>) info.get("headers");
|
||||
@@ -177,13 +157,7 @@ public class WebRequestTraceFilterTests {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
|
||||
request.addHeader("Authorization", "my-auth-header");
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
this.filter.doFilterInternal(request, response, new FilterChain() {
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response)
|
||||
throws IOException, ServletException {
|
||||
}
|
||||
|
||||
this.filter.doFilterInternal(request, response, (req, resp) -> {
|
||||
});
|
||||
Map<String, Object> info = this.repository.findAll().iterator().next().getInfo();
|
||||
Map<String, Object> headers = (Map<String, Object>) info.get("headers");
|
||||
@@ -199,13 +173,7 @@ public class WebRequestTraceFilterTests {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
|
||||
request.addHeader("Authorization", "my-auth-header");
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
this.filter.doFilterInternal(request, response, new FilterChain() {
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response)
|
||||
throws IOException, ServletException {
|
||||
}
|
||||
|
||||
this.filter.doFilterInternal(request, response, (req, resp) -> {
|
||||
});
|
||||
Map<String, Object> info = this.repository.findAll().iterator().next().getInfo();
|
||||
Map<String, Object> headers = (Map<String, Object>) info.get("headers");
|
||||
@@ -279,14 +247,8 @@ public class WebRequestTraceFilterTests {
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
|
||||
try {
|
||||
this.filter.doFilterInternal(request, response, new FilterChain() {
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response)
|
||||
throws IOException, ServletException {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
this.filter.doFilterInternal(request, response, (req, resp) -> {
|
||||
throw new RuntimeException();
|
||||
});
|
||||
fail("Exception was swallowed");
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
@@ -60,15 +59,10 @@ class AutoConfigurationSorter {
|
||||
// Initially sort alphabetically
|
||||
Collections.sort(orderedClassNames);
|
||||
// Then sort by order
|
||||
Collections.sort(orderedClassNames, new Comparator<String>() {
|
||||
|
||||
@Override
|
||||
public int compare(String o1, String o2) {
|
||||
int i1 = classes.get(o1).getOrder();
|
||||
int i2 = classes.get(o2).getOrder();
|
||||
return (i1 < i2) ? -1 : (i1 > i2) ? 1 : 0;
|
||||
}
|
||||
|
||||
orderedClassNames.sort((o1, o2) -> {
|
||||
int i1 = classes.get(o1).getOrder();
|
||||
int i2 = classes.get(o2).getOrder();
|
||||
return (i1 < i2) ? -1 : (i1 > i2) ? 1 : 0;
|
||||
});
|
||||
// Then respect @AutoConfigureBefore @AutoConfigureAfter
|
||||
orderedClassNames = sortByAnnotation(classes, orderedClassNames);
|
||||
|
||||
@@ -134,7 +134,7 @@ class ImportAutoConfigurationImportSelector extends AutoConfigurationImportSelec
|
||||
AnnotationMetadata metadata) {
|
||||
MultiValueMap<Class<?>, Annotation> annotations = new LinkedMultiValueMap<>();
|
||||
Class<?> source = ClassUtils.resolveClassName(metadata.getClassName(), null);
|
||||
collectAnnotations(source, annotations, new HashSet<Class<?>>());
|
||||
collectAnnotations(source, annotations, new HashSet<>());
|
||||
return Collections.unmodifiableMap(annotations);
|
||||
}
|
||||
|
||||
|
||||
@@ -255,10 +255,7 @@ class OnBeanCondition extends SpringBootCondition implements ConfigurationCondit
|
||||
ClassUtils.forName(type, classLoader), considerHierarchy);
|
||||
return result;
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
catch (NoClassDefFoundError ex) {
|
||||
catch (ClassNotFoundException | NoClassDefFoundError ex) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,15 +253,8 @@ class OnClassCondition extends SpringBootCondition
|
||||
private volatile ConditionOutcome[] outcomes;
|
||||
|
||||
private ThreadedOutcomesResolver(final OutcomesResolver outcomesResolver) {
|
||||
this.thread = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
ThreadedOutcomesResolver.this.outcomes = outcomesResolver
|
||||
.resolveOutcomes();
|
||||
}
|
||||
|
||||
});
|
||||
this.thread = new Thread(
|
||||
() -> this.outcomes = outcomesResolver.resolveOutcomes());
|
||||
this.thread.start();
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ public class JestProperties {
|
||||
/**
|
||||
* Comma-separated list of the Elasticsearch instances to use.
|
||||
*/
|
||||
private List<String> uris = new ArrayList<String>(
|
||||
private List<String> uris = new ArrayList<>(
|
||||
Collections.singletonList("http://localhost:9200"));
|
||||
|
||||
/**
|
||||
|
||||
@@ -73,7 +73,7 @@ public class FlywayProperties {
|
||||
* SQL statements to execute to initialize a connection immediately after obtaining
|
||||
* it.
|
||||
*/
|
||||
private List<String> initSqls = new ArrayList<String>();
|
||||
private List<String> initSqls = new ArrayList<>();
|
||||
|
||||
public void setLocations(List<String> locations) {
|
||||
this.locations = locations;
|
||||
|
||||
@@ -41,7 +41,7 @@ public class FreeMarkerTemplateAvailabilityProvider
|
||||
static final class FreeMarkerTemplateAvailabilityProperties
|
||||
extends TemplateAvailabilityProperties {
|
||||
|
||||
private List<String> templateLoaderPath = new ArrayList<String>(
|
||||
private List<String> templateLoaderPath = new ArrayList<>(
|
||||
Arrays.asList(FreeMarkerProperties.DEFAULT_TEMPLATE_LOADER_PATH));
|
||||
|
||||
FreeMarkerTemplateAvailabilityProperties() {
|
||||
|
||||
@@ -41,7 +41,7 @@ public class GroovyTemplateAvailabilityProvider
|
||||
static final class GroovyTemplateAvailabilityProperties
|
||||
extends TemplateAvailabilityProperties {
|
||||
|
||||
private List<String> resourceLoaderPath = new ArrayList<String>(
|
||||
private List<String> resourceLoaderPath = new ArrayList<>(
|
||||
Arrays.asList(GroovyTemplateProperties.DEFAULT_RESOURCE_LOADER_PATH));
|
||||
|
||||
GroovyTemplateAvailabilityProperties() {
|
||||
|
||||
@@ -240,10 +240,7 @@ public class HttpMessageConverters implements Iterable<HttpMessageConverter<?>>
|
||||
try {
|
||||
list.add(Class.forName(className));
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
// Ignore
|
||||
}
|
||||
catch (NoClassDefFoundError ex) {
|
||||
catch (ClassNotFoundException | NoClassDefFoundError ex) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.jdbc.metadata;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import org.apache.commons.dbcp2.BasicDataSource;
|
||||
|
||||
@@ -41,16 +39,12 @@ public class DataSourcePoolMetadataProvidersConfiguration {
|
||||
|
||||
@Bean
|
||||
public DataSourcePoolMetadataProvider tomcatPoolDataSourceMetadataProvider() {
|
||||
return new DataSourcePoolMetadataProvider() {
|
||||
@Override
|
||||
public DataSourcePoolMetadata getDataSourcePoolMetadata(
|
||||
DataSource dataSource) {
|
||||
if (dataSource instanceof org.apache.tomcat.jdbc.pool.DataSource) {
|
||||
return new TomcatDataSourcePoolMetadata(
|
||||
(org.apache.tomcat.jdbc.pool.DataSource) dataSource);
|
||||
}
|
||||
return null;
|
||||
return (dataSource) -> {
|
||||
if (dataSource instanceof org.apache.tomcat.jdbc.pool.DataSource) {
|
||||
return new TomcatDataSourcePoolMetadata(
|
||||
(org.apache.tomcat.jdbc.pool.DataSource) dataSource);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -62,16 +56,12 @@ public class DataSourcePoolMetadataProvidersConfiguration {
|
||||
|
||||
@Bean
|
||||
public DataSourcePoolMetadataProvider hikariPoolDataSourceMetadataProvider() {
|
||||
return new DataSourcePoolMetadataProvider() {
|
||||
@Override
|
||||
public DataSourcePoolMetadata getDataSourcePoolMetadata(
|
||||
DataSource dataSource) {
|
||||
if (dataSource instanceof HikariDataSource) {
|
||||
return new HikariDataSourcePoolMetadata(
|
||||
(HikariDataSource) dataSource);
|
||||
}
|
||||
return null;
|
||||
return (dataSource) -> {
|
||||
if (dataSource instanceof HikariDataSource) {
|
||||
return new HikariDataSourcePoolMetadata(
|
||||
(HikariDataSource) dataSource);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -83,16 +73,12 @@ public class DataSourcePoolMetadataProvidersConfiguration {
|
||||
|
||||
@Bean
|
||||
public DataSourcePoolMetadataProvider commonsDbcp2PoolDataSourceMetadataProvider() {
|
||||
return new DataSourcePoolMetadataProvider() {
|
||||
@Override
|
||||
public DataSourcePoolMetadata getDataSourcePoolMetadata(
|
||||
DataSource dataSource) {
|
||||
if (dataSource instanceof BasicDataSource) {
|
||||
return new CommonsDbcp2DataSourcePoolMetadata(
|
||||
(BasicDataSource) dataSource);
|
||||
}
|
||||
return null;
|
||||
return (dataSource) -> {
|
||||
if (dataSource instanceof BasicDataSource) {
|
||||
return new CommonsDbcp2DataSourcePoolMetadata(
|
||||
(BasicDataSource) dataSource);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -243,13 +243,10 @@ public class JerseyAutoConfiguration implements ServletContextAware {
|
||||
public ResourceConfigCustomizer resourceConfigCustomizer(
|
||||
final ObjectMapper objectMapper) {
|
||||
addJaxbAnnotationIntrospectorIfPresent(objectMapper);
|
||||
return new ResourceConfigCustomizer() {
|
||||
@Override
|
||||
public void customize(ResourceConfig config) {
|
||||
config.register(JacksonFeature.class);
|
||||
config.register(new ObjectMapperContextResolver(objectMapper),
|
||||
ContextResolver.class);
|
||||
}
|
||||
return (ResourceConfig config) -> {
|
||||
config.register(JacksonFeature.class);
|
||||
config.register(new ObjectMapperContextResolver(objectMapper),
|
||||
ContextResolver.class);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -181,8 +181,7 @@ public class EmbeddedLdapAutoConfiguration {
|
||||
private Map<String, Object> getLdapPorts(MutablePropertySources sources) {
|
||||
PropertySource<?> propertySource = sources.get(PROPERTY_SOURCE_NAME);
|
||||
if (propertySource == null) {
|
||||
propertySource = new MapPropertySource(PROPERTY_SOURCE_NAME,
|
||||
new HashMap<String, Object>());
|
||||
propertySource = new MapPropertySource(PROPERTY_SOURCE_NAME, new HashMap<>());
|
||||
sources.addFirst(propertySource);
|
||||
}
|
||||
return (Map<String, Object>) propertySource.getSource();
|
||||
|
||||
@@ -179,8 +179,7 @@ public class EmbeddedMongoAutoConfiguration {
|
||||
private Map<String, Object> getMongoPorts(MutablePropertySources sources) {
|
||||
PropertySource<?> propertySource = sources.get("mongo.ports");
|
||||
if (propertySource == null) {
|
||||
propertySource = new MapPropertySource("mongo.ports",
|
||||
new HashMap<String, Object>());
|
||||
propertySource = new MapPropertySource("mongo.ports", new HashMap<>());
|
||||
sources.addFirst(propertySource);
|
||||
}
|
||||
return (Map<String, Object>) propertySource.getSource();
|
||||
|
||||
@@ -20,8 +20,6 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
@@ -230,12 +228,7 @@ public class SpringBootWebSecurityConfiguration {
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http.requestMatcher(new RequestMatcher() {
|
||||
@Override
|
||||
public boolean matches(HttpServletRequest request) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
http.requestMatcher(request -> false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -140,12 +140,7 @@ public class SocialWebAutoConfiguration {
|
||||
|
||||
@Override
|
||||
public UserIdSource getUserIdSource() {
|
||||
return new UserIdSource() {
|
||||
@Override
|
||||
public String getUserId() {
|
||||
return "anonymous";
|
||||
}
|
||||
};
|
||||
return () -> "anonymous";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,10 +23,7 @@ import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.SessionCookieConfig;
|
||||
|
||||
import io.undertow.Undertow;
|
||||
import io.undertow.UndertowOptions;
|
||||
import org.apache.catalina.Context;
|
||||
import org.apache.catalina.connector.Connector;
|
||||
import org.apache.catalina.valves.AccessLogValve;
|
||||
import org.apache.catalina.valves.RemoteIpValve;
|
||||
import org.apache.coyote.AbstractProtocol;
|
||||
@@ -47,10 +44,7 @@ import org.springframework.boot.autoconfigure.web.ServerProperties.Session;
|
||||
import org.springframework.boot.cloud.CloudPlatform;
|
||||
import org.springframework.boot.web.embedded.jetty.JettyServerCustomizer;
|
||||
import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory;
|
||||
import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;
|
||||
import org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer;
|
||||
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
|
||||
import org.springframework.boot.web.embedded.undertow.UndertowBuilderCustomizer;
|
||||
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
|
||||
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
||||
import org.springframework.boot.web.servlet.ServletContextInitializer;
|
||||
@@ -269,49 +263,34 @@ public class DefaultServletWebServerFactoryCustomizer
|
||||
|
||||
private static void customizeAcceptCount(TomcatServletWebServerFactory factory,
|
||||
final int acceptCount) {
|
||||
factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
|
||||
|
||||
@Override
|
||||
public void customize(Connector connector) {
|
||||
ProtocolHandler handler = connector.getProtocolHandler();
|
||||
if (handler instanceof AbstractProtocol) {
|
||||
AbstractProtocol<?> protocol = (AbstractProtocol<?>) handler;
|
||||
protocol.setAcceptCount(acceptCount);
|
||||
}
|
||||
factory.addConnectorCustomizers((connector) -> {
|
||||
ProtocolHandler handler = connector.getProtocolHandler();
|
||||
if (handler instanceof AbstractProtocol) {
|
||||
AbstractProtocol<?> protocol = (AbstractProtocol<?>) handler;
|
||||
protocol.setAcceptCount(acceptCount);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private static void customizeMaxConnections(TomcatServletWebServerFactory factory,
|
||||
final int maxConnections) {
|
||||
factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
|
||||
|
||||
@Override
|
||||
public void customize(Connector connector) {
|
||||
ProtocolHandler handler = connector.getProtocolHandler();
|
||||
if (handler instanceof AbstractProtocol) {
|
||||
AbstractProtocol<?> protocol = (AbstractProtocol<?>) handler;
|
||||
protocol.setMaxConnections(maxConnections);
|
||||
}
|
||||
factory.addConnectorCustomizers((connector) -> {
|
||||
ProtocolHandler handler = connector.getProtocolHandler();
|
||||
if (handler instanceof AbstractProtocol) {
|
||||
AbstractProtocol<?> protocol = (AbstractProtocol<?>) handler;
|
||||
protocol.setMaxConnections(maxConnections);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private static void customizeConnectionTimeout(
|
||||
TomcatServletWebServerFactory factory, final int connectionTimeout) {
|
||||
factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
|
||||
|
||||
@Override
|
||||
public void customize(Connector connector) {
|
||||
ProtocolHandler handler = connector.getProtocolHandler();
|
||||
if (handler instanceof AbstractProtocol) {
|
||||
AbstractProtocol<?> protocol = (AbstractProtocol<?>) handler;
|
||||
protocol.setConnectionTimeout(connectionTimeout);
|
||||
}
|
||||
factory.addConnectorCustomizers((connector) -> {
|
||||
ProtocolHandler handler = connector.getProtocolHandler();
|
||||
if (handler instanceof AbstractProtocol) {
|
||||
AbstractProtocol<?> protocol = (AbstractProtocol<?>) handler;
|
||||
protocol.setConnectionTimeout(connectionTimeout);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@@ -342,16 +321,11 @@ public class DefaultServletWebServerFactoryCustomizer
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static void customizeMaxThreads(TomcatServletWebServerFactory factory,
|
||||
final int maxThreads) {
|
||||
factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
|
||||
@Override
|
||||
public void customize(Connector connector) {
|
||||
|
||||
ProtocolHandler handler = connector.getProtocolHandler();
|
||||
if (handler instanceof AbstractProtocol) {
|
||||
AbstractProtocol protocol = (AbstractProtocol) handler;
|
||||
protocol.setMaxThreads(maxThreads);
|
||||
}
|
||||
|
||||
factory.addConnectorCustomizers((connector) -> {
|
||||
ProtocolHandler handler = connector.getProtocolHandler();
|
||||
if (handler instanceof AbstractProtocol) {
|
||||
AbstractProtocol protocol = (AbstractProtocol) handler;
|
||||
protocol.setMaxThreads(maxThreads);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -359,16 +333,11 @@ public class DefaultServletWebServerFactoryCustomizer
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static void customizeMinThreads(TomcatServletWebServerFactory factory,
|
||||
final int minSpareThreads) {
|
||||
factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
|
||||
@Override
|
||||
public void customize(Connector connector) {
|
||||
|
||||
ProtocolHandler handler = connector.getProtocolHandler();
|
||||
if (handler instanceof AbstractProtocol) {
|
||||
AbstractProtocol protocol = (AbstractProtocol) handler;
|
||||
protocol.setMinSpareThreads(minSpareThreads);
|
||||
}
|
||||
|
||||
factory.addConnectorCustomizers((connector) -> {
|
||||
ProtocolHandler handler = connector.getProtocolHandler();
|
||||
if (handler instanceof AbstractProtocol) {
|
||||
AbstractProtocol protocol = (AbstractProtocol) handler;
|
||||
protocol.setMinSpareThreads(minSpareThreads);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -376,30 +345,19 @@ public class DefaultServletWebServerFactoryCustomizer
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static void customizeMaxHttpHeaderSize(
|
||||
TomcatServletWebServerFactory factory, final int maxHttpHeaderSize) {
|
||||
factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
|
||||
|
||||
@Override
|
||||
public void customize(Connector connector) {
|
||||
ProtocolHandler handler = connector.getProtocolHandler();
|
||||
if (handler instanceof AbstractHttp11Protocol) {
|
||||
AbstractHttp11Protocol protocol = (AbstractHttp11Protocol) handler;
|
||||
protocol.setMaxHttpHeaderSize(maxHttpHeaderSize);
|
||||
}
|
||||
factory.addConnectorCustomizers((connector) -> {
|
||||
ProtocolHandler handler = connector.getProtocolHandler();
|
||||
if (handler instanceof AbstractHttp11Protocol) {
|
||||
AbstractHttp11Protocol protocol = (AbstractHttp11Protocol) handler;
|
||||
protocol.setMaxHttpHeaderSize(maxHttpHeaderSize);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private static void customizeMaxHttpPostSize(
|
||||
TomcatServletWebServerFactory factory, final int maxHttpPostSize) {
|
||||
factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
|
||||
|
||||
@Override
|
||||
public void customize(Connector connector) {
|
||||
connector.setMaxPostSize(maxHttpPostSize);
|
||||
}
|
||||
|
||||
});
|
||||
factory.addConnectorCustomizers(
|
||||
(connector) -> connector.setMaxPostSize(maxHttpPostSize));
|
||||
}
|
||||
|
||||
private static void customizeAccessLog(ServerProperties.Tomcat tomcatProperties,
|
||||
@@ -422,14 +380,8 @@ public class DefaultServletWebServerFactoryCustomizer
|
||||
private static void customizeRedirectContextRoot(
|
||||
TomcatServletWebServerFactory factory,
|
||||
final boolean redirectContextRoot) {
|
||||
factory.addContextCustomizers(new TomcatContextCustomizer() {
|
||||
|
||||
@Override
|
||||
public void customize(Context context) {
|
||||
context.setMapperContextRootRedirectEnabled(redirectContextRoot);
|
||||
}
|
||||
|
||||
});
|
||||
factory.addContextCustomizers((context) -> context
|
||||
.setMapperContextRootRedirectEnabled(redirectContextRoot));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -482,39 +434,20 @@ public class DefaultServletWebServerFactoryCustomizer
|
||||
|
||||
private static void customizeConnectionTimeout(
|
||||
UndertowServletWebServerFactory factory, final int connectionTimeout) {
|
||||
factory.addBuilderCustomizers(new UndertowBuilderCustomizer() {
|
||||
@Override
|
||||
public void customize(Undertow.Builder builder) {
|
||||
builder.setSocketOption(UndertowOptions.NO_REQUEST_TIMEOUT,
|
||||
connectionTimeout);
|
||||
}
|
||||
});
|
||||
factory.addBuilderCustomizers((builder) -> builder.setSocketOption(
|
||||
UndertowOptions.NO_REQUEST_TIMEOUT, connectionTimeout));
|
||||
}
|
||||
|
||||
private static void customizeMaxHttpHeaderSize(
|
||||
UndertowServletWebServerFactory factory, final int maxHttpHeaderSize) {
|
||||
factory.addBuilderCustomizers(new UndertowBuilderCustomizer() {
|
||||
|
||||
@Override
|
||||
public void customize(Undertow.Builder builder) {
|
||||
builder.setServerOption(UndertowOptions.MAX_HEADER_SIZE,
|
||||
maxHttpHeaderSize);
|
||||
}
|
||||
|
||||
});
|
||||
factory.addBuilderCustomizers((builder) -> builder
|
||||
.setServerOption(UndertowOptions.MAX_HEADER_SIZE, maxHttpHeaderSize));
|
||||
}
|
||||
|
||||
private static void customizeMaxHttpPostSize(
|
||||
UndertowServletWebServerFactory factory, final long maxHttpPostSize) {
|
||||
factory.addBuilderCustomizers(new UndertowBuilderCustomizer() {
|
||||
|
||||
@Override
|
||||
public void customize(Undertow.Builder builder) {
|
||||
builder.setServerOption(UndertowOptions.MAX_ENTITY_SIZE,
|
||||
maxHttpPostSize);
|
||||
}
|
||||
|
||||
});
|
||||
factory.addBuilderCustomizers((builder -> builder
|
||||
.setServerOption(UndertowOptions.MAX_ENTITY_SIZE, maxHttpPostSize)));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -551,19 +484,13 @@ public class DefaultServletWebServerFactoryCustomizer
|
||||
|
||||
private static void customizeConnectionTimeout(
|
||||
JettyServletWebServerFactory factory, final int connectionTimeout) {
|
||||
factory.addServerCustomizers(new JettyServerCustomizer() {
|
||||
|
||||
@Override
|
||||
public void customize(Server server) {
|
||||
for (org.eclipse.jetty.server.Connector connector : server
|
||||
.getConnectors()) {
|
||||
if (connector instanceof AbstractConnector) {
|
||||
((AbstractConnector) connector)
|
||||
.setIdleTimeout(connectionTimeout);
|
||||
}
|
||||
factory.addServerCustomizers((server) -> {
|
||||
for (org.eclipse.jetty.server.Connector connector : server
|
||||
.getConnectors()) {
|
||||
if (connector instanceof AbstractConnector) {
|
||||
((AbstractConnector) connector).setIdleTimeout(connectionTimeout);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -16,10 +16,8 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.websocket.reactive;
|
||||
|
||||
import org.apache.catalina.Context;
|
||||
import org.apache.tomcat.websocket.server.WsContextListener;
|
||||
|
||||
import org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer;
|
||||
import org.springframework.boot.web.embedded.tomcat.TomcatReactiveWebServerFactory;
|
||||
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
||||
import org.springframework.core.Ordered;
|
||||
@@ -35,14 +33,8 @@ public class TomcatWebSocketReactiveWebServerCustomizer
|
||||
|
||||
@Override
|
||||
public void customize(TomcatReactiveWebServerFactory factory) {
|
||||
factory.addContextCustomizers(new TomcatContextCustomizer() {
|
||||
|
||||
@Override
|
||||
public void customize(Context context) {
|
||||
context.addApplicationListener(WsContextListener.class.getName());
|
||||
}
|
||||
|
||||
});
|
||||
factory.addContextCustomizers((context) -> context
|
||||
.addApplicationListener(WsContextListener.class.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -249,15 +249,7 @@ public class AutoConfigurationImportSelectorTests {
|
||||
@Override
|
||||
protected List<AutoConfigurationImportListener> getAutoConfigurationImportListeners() {
|
||||
return Collections.<AutoConfigurationImportListener>singletonList(
|
||||
new AutoConfigurationImportListener() {
|
||||
|
||||
@Override
|
||||
public void onAutoConfigurationImportEvent(
|
||||
AutoConfigurationImportEvent event) {
|
||||
TestAutoConfigurationImportSelector.this.lastEvent = event;
|
||||
}
|
||||
|
||||
});
|
||||
(event) -> this.lastEvent = event);
|
||||
}
|
||||
|
||||
public AutoConfigurationImportEvent getLastEvent() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
@@ -23,7 +23,6 @@ import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.JobParametersBuilder;
|
||||
import org.springframework.batch.core.Step;
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
import org.springframework.batch.core.configuration.annotation.BatchConfigurer;
|
||||
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
|
||||
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
|
||||
@@ -35,9 +34,7 @@ import org.springframework.batch.core.launch.support.RunIdIncrementer;
|
||||
import org.springframework.batch.core.launch.support.SimpleJobLauncher;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean;
|
||||
import org.springframework.batch.core.scope.context.ChunkContext;
|
||||
import org.springframework.batch.core.step.tasklet.Tasklet;
|
||||
import org.springframework.batch.repeat.RepeatStatus;
|
||||
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -80,13 +77,8 @@ public class JobLauncherCommandLineRunnerTests {
|
||||
PlatformTransactionManager transactionManager = this.context
|
||||
.getBean(PlatformTransactionManager.class);
|
||||
this.steps = new StepBuilderFactory(jobRepository, transactionManager);
|
||||
this.step = this.steps.get("step").tasklet(new Tasklet() {
|
||||
@Override
|
||||
public RepeatStatus execute(StepContribution contribution,
|
||||
ChunkContext chunkContext) throws Exception {
|
||||
return null;
|
||||
}
|
||||
}).build();
|
||||
Tasklet tasklet = (contribution, chunkContext) -> null;
|
||||
this.step = this.steps.get("step").tasklet(tasklet).build();
|
||||
this.job = this.jobs.get("job").start(this.step).build();
|
||||
this.jobExplorer = this.context.getBean(JobExplorer.class);
|
||||
this.runner = new JobLauncherCommandLineRunner(this.jobLauncher,
|
||||
@@ -115,13 +107,8 @@ public class JobLauncherCommandLineRunnerTests {
|
||||
@Test
|
||||
public void retryFailedExecution() throws Exception {
|
||||
this.job = this.jobs.get("job")
|
||||
.start(this.steps.get("step").tasklet(new Tasklet() {
|
||||
@Override
|
||||
public RepeatStatus execute(StepContribution contribution,
|
||||
ChunkContext chunkContext) throws Exception {
|
||||
throw new RuntimeException("Planned");
|
||||
}
|
||||
}).build()).incrementer(new RunIdIncrementer()).build();
|
||||
.start(this.steps.get("step").tasklet(throwingTasklet()).build())
|
||||
.incrementer(new RunIdIncrementer()).build();
|
||||
this.runner.execute(this.job, new JobParameters());
|
||||
this.runner.execute(this.job, new JobParameters());
|
||||
assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(1);
|
||||
@@ -130,13 +117,8 @@ public class JobLauncherCommandLineRunnerTests {
|
||||
@Test
|
||||
public void retryFailedExecutionOnNonRestartableJob() throws Exception {
|
||||
this.job = this.jobs.get("job").preventRestart()
|
||||
.start(this.steps.get("step").tasklet(new Tasklet() {
|
||||
@Override
|
||||
public RepeatStatus execute(StepContribution contribution,
|
||||
ChunkContext chunkContext) throws Exception {
|
||||
throw new RuntimeException("Planned");
|
||||
}
|
||||
}).build()).incrementer(new RunIdIncrementer()).build();
|
||||
.start(this.steps.get("step").tasklet(throwingTasklet()).build())
|
||||
.incrementer(new RunIdIncrementer()).build();
|
||||
this.runner.execute(this.job, new JobParameters());
|
||||
this.runner.execute(this.job, new JobParameters());
|
||||
// A failed job that is not restartable does not re-use the job params of
|
||||
@@ -147,13 +129,8 @@ public class JobLauncherCommandLineRunnerTests {
|
||||
@Test
|
||||
public void retryFailedExecutionWithNonIdentifyingParameters() throws Exception {
|
||||
this.job = this.jobs.get("job")
|
||||
.start(this.steps.get("step").tasklet(new Tasklet() {
|
||||
@Override
|
||||
public RepeatStatus execute(StepContribution contribution,
|
||||
ChunkContext chunkContext) throws Exception {
|
||||
throw new RuntimeException("Planned");
|
||||
}
|
||||
}).build()).incrementer(new RunIdIncrementer()).build();
|
||||
.start(this.steps.get("step").tasklet(throwingTasklet()).build())
|
||||
.incrementer(new RunIdIncrementer()).build();
|
||||
JobParameters jobParameters = new JobParametersBuilder().addLong("id", 1L, false)
|
||||
.addLong("foo", 2L, false).toJobParameters();
|
||||
this.runner.execute(this.job, jobParameters);
|
||||
@@ -161,6 +138,12 @@ public class JobLauncherCommandLineRunnerTests {
|
||||
assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(1);
|
||||
}
|
||||
|
||||
private Tasklet throwingTasklet() {
|
||||
return (contribution, chunkContext) -> {
|
||||
throw new RuntimeException("Planned");
|
||||
};
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableBatchProcessing
|
||||
protected static class BatchConfiguration implements BatchConfigurer {
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.boot.autoconfigure.cache;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -69,7 +68,6 @@ import org.springframework.cache.caffeine.CaffeineCacheManager;
|
||||
import org.springframework.cache.concurrent.ConcurrentMapCache;
|
||||
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
|
||||
import org.springframework.cache.ehcache.EhCacheCacheManager;
|
||||
import org.springframework.cache.interceptor.CacheOperationInvocationContext;
|
||||
import org.springframework.cache.interceptor.CacheResolver;
|
||||
import org.springframework.cache.jcache.JCacheCacheManager;
|
||||
import org.springframework.cache.support.NoOpCacheManager;
|
||||
@@ -965,16 +963,13 @@ public class CacheAutoConfigurationTests {
|
||||
|
||||
@Bean
|
||||
JCacheManagerCustomizer myCustomizer() {
|
||||
return new JCacheManagerCustomizer() {
|
||||
@Override
|
||||
public void customize(javax.cache.CacheManager cacheManager) {
|
||||
MutableConfiguration<?, ?> config = new MutableConfiguration<>();
|
||||
config.setExpiryPolicyFactory(
|
||||
CreatedExpiryPolicy.factoryOf(Duration.TEN_MINUTES));
|
||||
config.setStatisticsEnabled(true);
|
||||
cacheManager.createCache("custom1", config);
|
||||
cacheManager.destroyCache("bar");
|
||||
}
|
||||
return (cacheManager) -> {
|
||||
MutableConfiguration<?, ?> config = new MutableConfiguration<>();
|
||||
config.setExpiryPolicyFactory(
|
||||
CreatedExpiryPolicy.factoryOf(Duration.TEN_MINUTES));
|
||||
config.setStatisticsEnabled(true);
|
||||
cacheManager.createCache("custom1", config);
|
||||
cacheManager.destroyCache("bar");
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1053,15 +1048,7 @@ public class CacheAutoConfigurationTests {
|
||||
@Bean
|
||||
// The @Bean annotation is important, see CachingConfigurerSupport Javadoc
|
||||
public CacheResolver cacheResolver() {
|
||||
return new CacheResolver() {
|
||||
|
||||
@Override
|
||||
public Collection<? extends Cache> resolveCaches(
|
||||
CacheOperationInvocationContext<?> context) {
|
||||
return Collections.singleton(mock(Cache.class));
|
||||
}
|
||||
|
||||
};
|
||||
return (context) -> Collections.singleton(mock(Cache.class));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -27,9 +27,6 @@ import javax.cache.configuration.Configuration;
|
||||
import javax.cache.configuration.OptionalFeature;
|
||||
import javax.cache.spi.CachingProvider;
|
||||
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
@@ -52,24 +49,17 @@ public class MockCachingProvider implements CachingProvider {
|
||||
given(cacheManager.getClassLoader()).willReturn(classLoader);
|
||||
final Map<String, Cache> caches = new HashMap<>();
|
||||
given(cacheManager.getCacheNames()).willReturn(caches.keySet());
|
||||
given(cacheManager.getCache(anyString())).willAnswer(new Answer<Cache>() {
|
||||
@Override
|
||||
public Cache answer(InvocationOnMock invocationOnMock) throws Throwable {
|
||||
String cacheName = (String) invocationOnMock.getArguments()[0];
|
||||
return caches.get(cacheName);
|
||||
}
|
||||
given(cacheManager.getCache(anyString())).willAnswer((invocation) -> {
|
||||
String cacheName = (String) invocation.getArguments()[0];
|
||||
return caches.get(cacheName);
|
||||
});
|
||||
given(cacheManager.createCache(anyString(), any(Configuration.class)))
|
||||
.will(new Answer<Cache>() {
|
||||
@Override
|
||||
public Cache answer(InvocationOnMock invocationOnMock)
|
||||
throws Throwable {
|
||||
String cacheName = (String) invocationOnMock.getArguments()[0];
|
||||
Cache cache = mock(Cache.class);
|
||||
given(cache.getName()).willReturn(cacheName);
|
||||
caches.put(cacheName, cache);
|
||||
return cache;
|
||||
}
|
||||
.will((invocation) -> {
|
||||
String cacheName = (String) invocation.getArguments()[0];
|
||||
Cache cache = mock(Cache.class);
|
||||
given(cache.getName()).willReturn(cacheName);
|
||||
caches.put(cacheName, cache);
|
||||
return cache;
|
||||
});
|
||||
return cacheManager;
|
||||
}
|
||||
|
||||
@@ -143,12 +143,7 @@ public class CassandraAutoConfigurationTests {
|
||||
|
||||
@Bean
|
||||
public ClusterBuilderCustomizer customizer() {
|
||||
return new ClusterBuilderCustomizer() {
|
||||
@Override
|
||||
public void customize(Cluster.Builder clusterBuilder) {
|
||||
clusterBuilder.withClusterName("overridden-name");
|
||||
}
|
||||
};
|
||||
return (clusterBuilder) -> clusterBuilder.withClusterName("overridden-name");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.UnsatisfiedDependencyException;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurationPackages;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.data.mongo.city.City;
|
||||
@@ -135,9 +134,6 @@ public class MongoDataAutoConfigurationTests {
|
||||
fail("Create FieldNamingStrategy interface should fail");
|
||||
}
|
||||
// We seem to have an inconsistent exception, accept either
|
||||
catch (UnsatisfiedDependencyException ex) {
|
||||
// Expected
|
||||
}
|
||||
catch (BeanCreationException ex) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import com.google.gson.Gson;
|
||||
import io.searchbox.action.Action;
|
||||
import io.searchbox.client.JestClient;
|
||||
import io.searchbox.client.JestResult;
|
||||
import io.searchbox.client.config.HttpClientConfig;
|
||||
import io.searchbox.client.http.JestHttpClient;
|
||||
import io.searchbox.core.Index;
|
||||
import io.searchbox.core.Search;
|
||||
@@ -183,14 +182,7 @@ public class JestAutoConfigurationTests {
|
||||
|
||||
@Bean
|
||||
public HttpClientConfigBuilderCustomizer customizer() {
|
||||
return new HttpClientConfigBuilderCustomizer() {
|
||||
|
||||
@Override
|
||||
public void customize(HttpClientConfig.Builder builder) {
|
||||
builder.gson(BuilderCustomizer.this.gson);
|
||||
}
|
||||
|
||||
};
|
||||
return (builder) -> builder.gson(BuilderCustomizer.this.gson);
|
||||
}
|
||||
|
||||
Gson getGson() {
|
||||
|
||||
@@ -533,13 +533,7 @@ public class JacksonAutoConfigurationTests {
|
||||
|
||||
@Bean
|
||||
public Jackson2ObjectMapperBuilderCustomizer customDateFormat() {
|
||||
return new Jackson2ObjectMapperBuilderCustomizer() {
|
||||
@Override
|
||||
public void customize(
|
||||
Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder) {
|
||||
jackson2ObjectMapperBuilder.dateFormat(new MyDateFormat());
|
||||
}
|
||||
};
|
||||
return (builder) -> builder.dateFormat(new MyDateFormat());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -350,14 +350,8 @@ public class DataSourceInitializerTests {
|
||||
@Override
|
||||
public Resource[] getResources(String locationPattern) throws IOException {
|
||||
Resource[] resources = this.resolver.getResources(locationPattern);
|
||||
Arrays.sort(resources, new Comparator<Resource>() {
|
||||
|
||||
@Override
|
||||
public int compare(Resource r1, Resource r2) {
|
||||
return r2.getFilename().compareTo(r1.getFilename());
|
||||
}
|
||||
|
||||
});
|
||||
Arrays.sort(resources,
|
||||
Comparator.comparing(Resource::getFilename).reversed());
|
||||
return resources;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
@@ -16,13 +16,9 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.jdbc.metadata;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.jdbc.core.ConnectionCallback;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
@@ -57,13 +53,7 @@ public abstract class AbstractDataSourcePoolMetadataTests<D extends AbstractData
|
||||
// Make sure the pool is initialized
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(
|
||||
getDataSourceMetadata().getDataSource());
|
||||
jdbcTemplate.execute(new ConnectionCallback<Void>() {
|
||||
@Override
|
||||
public Void doInConnection(Connection connection)
|
||||
throws SQLException, DataAccessException {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
jdbcTemplate.execute((ConnectionCallback<Void>) (connection) -> null);
|
||||
assertThat(getDataSourceMetadata().getActive()).isEqualTo(Integer.valueOf(0));
|
||||
assertThat(getDataSourceMetadata().getUsage()).isEqualTo(Float.valueOf(0));
|
||||
}
|
||||
@@ -72,16 +62,10 @@ public abstract class AbstractDataSourcePoolMetadataTests<D extends AbstractData
|
||||
public void getPoolSizeOneConnection() {
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(
|
||||
getDataSourceMetadata().getDataSource());
|
||||
jdbcTemplate.execute(new ConnectionCallback<Void>() {
|
||||
@Override
|
||||
public Void doInConnection(Connection connection)
|
||||
throws SQLException, DataAccessException {
|
||||
assertThat(getDataSourceMetadata().getActive())
|
||||
.isEqualTo(Integer.valueOf(1));
|
||||
assertThat(getDataSourceMetadata().getUsage())
|
||||
.isEqualTo(Float.valueOf(0.5F));
|
||||
return null;
|
||||
}
|
||||
jdbcTemplate.execute((ConnectionCallback<Void>) (connection) -> {
|
||||
assertThat(getDataSourceMetadata().getActive()).isEqualTo(Integer.valueOf(1));
|
||||
assertThat(getDataSourceMetadata().getUsage()).isEqualTo(Float.valueOf(0.5F));
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -89,25 +73,13 @@ public abstract class AbstractDataSourcePoolMetadataTests<D extends AbstractData
|
||||
public void getPoolSizeTwoConnections() {
|
||||
final JdbcTemplate jdbcTemplate = new JdbcTemplate(
|
||||
getDataSourceMetadata().getDataSource());
|
||||
jdbcTemplate.execute(new ConnectionCallback<Void>() {
|
||||
|
||||
@Override
|
||||
public Void doInConnection(Connection connection)
|
||||
throws SQLException, DataAccessException {
|
||||
jdbcTemplate.execute(new ConnectionCallback<Void>() {
|
||||
|
||||
@Override
|
||||
public Void doInConnection(Connection connection)
|
||||
throws SQLException, DataAccessException {
|
||||
assertThat(getDataSourceMetadata().getActive()).isEqualTo(2);
|
||||
assertThat(getDataSourceMetadata().getUsage()).isEqualTo(1.0f);
|
||||
return null;
|
||||
}
|
||||
|
||||
});
|
||||
jdbcTemplate.execute((ConnectionCallback<Void>) (connection) -> {
|
||||
jdbcTemplate.execute((ConnectionCallback<Void>) connection1 -> {
|
||||
assertThat(getDataSourceMetadata().getActive()).isEqualTo(2);
|
||||
assertThat(getDataSourceMetadata().getUsage()).isEqualTo(1.0f);
|
||||
return null;
|
||||
}
|
||||
|
||||
});
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ import java.util.UUID;
|
||||
import javax.jms.Destination;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Message;
|
||||
import javax.jms.Session;
|
||||
import javax.jms.TextMessage;
|
||||
|
||||
import org.apache.activemq.artemis.api.core.TransportConfiguration;
|
||||
@@ -336,25 +335,22 @@ public class ArtemisAutoConfigurationTests {
|
||||
|
||||
public void checkDestination(final String name, final boolean pubSub,
|
||||
final boolean shouldExist) {
|
||||
this.jmsTemplate.execute(new SessionCallback<Void>() {
|
||||
@Override
|
||||
public Void doInJms(Session session) throws JMSException {
|
||||
try {
|
||||
Destination destination = DestinationChecker.this.destinationResolver
|
||||
.resolveDestinationName(session, name, pubSub);
|
||||
if (!shouldExist) {
|
||||
throw new IllegalStateException("Destination '" + name
|
||||
+ "' was not expected but got " + destination);
|
||||
}
|
||||
this.jmsTemplate.execute((SessionCallback<Void>) (session) -> {
|
||||
try {
|
||||
Destination destination = this.destinationResolver
|
||||
.resolveDestinationName(session, name, pubSub);
|
||||
if (!shouldExist) {
|
||||
throw new IllegalStateException("Destination '" + name
|
||||
+ "' was not expected but got " + destination);
|
||||
}
|
||||
catch (JMSException e) {
|
||||
if (shouldExist) {
|
||||
throw new IllegalStateException("Destination '" + name
|
||||
+ "' was expected but got " + e.getMessage());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
catch (JMSException ex) {
|
||||
if (shouldExist) {
|
||||
throw new IllegalStateException("Destination '" + name
|
||||
+ "' was expected but got " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -408,13 +404,9 @@ public class ArtemisAutoConfigurationTests {
|
||||
|
||||
@Bean
|
||||
public ArtemisConfigurationCustomizer myArtemisCustomize() {
|
||||
return new ArtemisConfigurationCustomizer() {
|
||||
@Override
|
||||
public void customize(
|
||||
org.apache.activemq.artemis.core.config.Configuration configuration) {
|
||||
configuration.setClusterPassword("Foobar");
|
||||
configuration.setName("customFooBar");
|
||||
}
|
||||
return (configuration) -> {
|
||||
configuration.setClusterPassword("Foobar");
|
||||
configuration.setName("customFooBar");
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -62,9 +62,8 @@ public class AutoConfigurationReportLoggingInitializerTests {
|
||||
this.initializer.initialize(context);
|
||||
context.register(Config.class);
|
||||
context.refresh();
|
||||
withDebugLogging(() -> {
|
||||
this.initializer.onApplicationEvent(new ContextRefreshedEvent(context));
|
||||
});
|
||||
withDebugLogging(() -> this.initializer
|
||||
.onApplicationEvent(new ContextRefreshedEvent(context)));
|
||||
assertThat(this.outputCapture.toString()).contains("AUTO-CONFIGURATION REPORT");
|
||||
}
|
||||
|
||||
@@ -78,10 +77,9 @@ public class AutoConfigurationReportLoggingInitializerTests {
|
||||
fail("Did not error");
|
||||
}
|
||||
catch (Exception ex) {
|
||||
withDebugLogging(() -> {
|
||||
this.initializer.onApplicationEvent(new ApplicationFailedEvent(
|
||||
new SpringApplication(), new String[0], context, ex));
|
||||
});
|
||||
withDebugLogging(
|
||||
() -> this.initializer.onApplicationEvent(new ApplicationFailedEvent(
|
||||
new SpringApplication(), new String[0], context, ex)));
|
||||
}
|
||||
assertThat(this.outputCapture.toString()).contains("AUTO-CONFIGURATION REPORT");
|
||||
}
|
||||
@@ -112,9 +110,8 @@ public class AutoConfigurationReportLoggingInitializerTests {
|
||||
ConditionEvaluationReport.get(context.getBeanFactory())
|
||||
.recordExclusions(Arrays.asList("com.foo.Bar"));
|
||||
context.refresh();
|
||||
withDebugLogging(() -> {
|
||||
this.initializer.onApplicationEvent(new ContextRefreshedEvent(context));
|
||||
});
|
||||
withDebugLogging(() -> this.initializer
|
||||
.onApplicationEvent(new ContextRefreshedEvent(context)));
|
||||
assertThat(this.outputCapture.toString())
|
||||
.contains("not a servlet web application (OnWebApplicationCondition)");
|
||||
}
|
||||
|
||||
@@ -50,7 +50,6 @@ import org.springframework.security.config.annotation.authentication.configurers
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.security.core.authority.AuthorityUtils;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
@@ -407,14 +406,8 @@ public class SecurityAutoConfigurationTests {
|
||||
|
||||
@Bean
|
||||
public AuthenticationManager myAuthenticationManager() {
|
||||
this.authenticationManager = new AuthenticationManager() {
|
||||
|
||||
@Override
|
||||
public Authentication authenticate(Authentication authentication)
|
||||
throws AuthenticationException {
|
||||
return new TestingAuthenticationToken("foo", "bar");
|
||||
}
|
||||
};
|
||||
this.authenticationManager = (
|
||||
authentication) -> new TestingAuthenticationToken("foo", "bar");
|
||||
return this.authenticationManager;
|
||||
}
|
||||
|
||||
@@ -446,14 +439,8 @@ public class SecurityAutoConfigurationTests {
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
this.authenticationManager = new AuthenticationManager() {
|
||||
@Override
|
||||
public Authentication authenticate(Authentication authentication)
|
||||
throws AuthenticationException {
|
||||
return WorkaroundSecurityCustomizer.this.builder.getOrBuild()
|
||||
.authenticate(authentication);
|
||||
}
|
||||
};
|
||||
this.authenticationManager = (authentication) -> this.builder.getOrBuild()
|
||||
.authenticate(authentication);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,10 +16,6 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.security.oauth2.resource;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@@ -45,14 +41,9 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.StandardEnvironment;
|
||||
import org.springframework.http.HttpRequest;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.client.ClientHttpRequestExecution;
|
||||
import org.springframework.http.client.ClientHttpRequestInterceptor;
|
||||
import org.springframework.http.client.ClientHttpResponse;
|
||||
import org.springframework.mock.http.client.MockClientHttpResponse;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.AuthorityUtils;
|
||||
import org.springframework.security.oauth2.client.OAuth2RestTemplate;
|
||||
import org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeResourceDetails;
|
||||
@@ -299,16 +290,8 @@ public class ResourceServerTokenServicesConfigurationTests {
|
||||
|
||||
@Bean
|
||||
AuthoritiesExtractor authoritiesExtractor() {
|
||||
return new AuthoritiesExtractor() {
|
||||
|
||||
@Override
|
||||
public List<GrantedAuthority> extractAuthorities(
|
||||
Map<String, Object> map) {
|
||||
return AuthorityUtils
|
||||
.commaSeparatedStringToAuthorityList("ROLE_ADMIN");
|
||||
}
|
||||
|
||||
};
|
||||
return (map) -> AuthorityUtils
|
||||
.commaSeparatedStringToAuthorityList("ROLE_ADMIN");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -318,14 +301,7 @@ public class ResourceServerTokenServicesConfigurationTests {
|
||||
|
||||
@Bean
|
||||
PrincipalExtractor principalExtractor() {
|
||||
return new PrincipalExtractor() {
|
||||
|
||||
@Override
|
||||
public Object extractPrincipal(Map<String, Object> map) {
|
||||
return "boot";
|
||||
}
|
||||
|
||||
};
|
||||
return (map) -> "boot";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -372,15 +348,8 @@ public class ResourceServerTokenServicesConfigurationTests {
|
||||
|
||||
@Override
|
||||
public void customize(OAuth2RestTemplate template) {
|
||||
template.getInterceptors().add(new ClientHttpRequestInterceptor() {
|
||||
|
||||
@Override
|
||||
public ClientHttpResponse intercept(HttpRequest request, byte[] body,
|
||||
ClientHttpRequestExecution execution) throws IOException {
|
||||
return execution.execute(request, body);
|
||||
}
|
||||
|
||||
});
|
||||
template.getInterceptors()
|
||||
.add((request, body, execution) -> execution.execute(request, body));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -434,18 +403,12 @@ public class ResourceServerTokenServicesConfigurationTests {
|
||||
|
||||
@Override
|
||||
public void customize(RestTemplate template) {
|
||||
template.getInterceptors().add(new ClientHttpRequestInterceptor() {
|
||||
|
||||
@Override
|
||||
public ClientHttpResponse intercept(HttpRequest request, byte[] body,
|
||||
ClientHttpRequestExecution execution) throws IOException {
|
||||
String payload = "{\"value\":\"FOO\"}";
|
||||
MockClientHttpResponse response = new MockClientHttpResponse(
|
||||
payload.getBytes(), HttpStatus.OK);
|
||||
response.getHeaders().setContentType(MediaType.APPLICATION_JSON);
|
||||
return response;
|
||||
}
|
||||
|
||||
template.getInterceptors().add((request, body, execution) -> {
|
||||
String payload = "{\"value\":\"FOO\"}";
|
||||
MockClientHttpResponse response = new MockClientHttpResponse(
|
||||
payload.getBytes(), HttpStatus.OK);
|
||||
response.getHeaders().setContentType(MediaType.APPLICATION_JSON);
|
||||
return response;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ public class UserInfoTokenServicesTests {
|
||||
public void init() {
|
||||
this.resource.setClientId("foo");
|
||||
given(this.template.getForEntity(any(String.class), eq(Map.class)))
|
||||
.willReturn(new ResponseEntity<Map>(this.map, HttpStatus.OK));
|
||||
.willReturn(new ResponseEntity<>(this.map, HttpStatus.OK));
|
||||
given(this.template.getAccessToken())
|
||||
.willReturn(new DefaultOAuth2AccessToken("FOO"));
|
||||
given(this.template.getResource()).willReturn(this.resource);
|
||||
|
||||
@@ -120,7 +120,7 @@ public class ServerPropertiesTests {
|
||||
|
||||
@Test
|
||||
public void redirectContextRootIsNotConfiguredByDefault() throws Exception {
|
||||
bind(new HashMap<String, String>());
|
||||
bind(new HashMap<>());
|
||||
ServerProperties.Tomcat tomcat = this.properties.getTomcat();
|
||||
assertThat(tomcat.getRedirectContextRoot()).isNull();
|
||||
}
|
||||
@@ -164,7 +164,7 @@ public class ServerPropertiesTests {
|
||||
|
||||
@Test
|
||||
public void testCustomizeJettyAccessLog() throws Exception {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("server.jetty.accesslog.enabled", "true");
|
||||
map.put("server.jetty.accesslog.filename", "foo.txt");
|
||||
map.put("server.jetty.accesslog.file-date-format", "yyyymmdd");
|
||||
|
||||
@@ -154,13 +154,8 @@ public class RestTemplateAutoConfigurationTests {
|
||||
}
|
||||
|
||||
private void breakBuilderOnNextCall(RestTemplateBuilder builder) {
|
||||
builder.additionalCustomizers(new RestTemplateCustomizer() {
|
||||
|
||||
@Override
|
||||
public void customize(RestTemplate restTemplate) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
builder.additionalCustomizers((restTemplate) -> {
|
||||
throw new IllegalStateException();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ public class DefaultServletWebServerFactoryCustomizerTests {
|
||||
@Test
|
||||
public void tomcatAccessLogFileDateFormatByDefault() {
|
||||
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("server.tomcat.accesslog.enabled", "true");
|
||||
bindProperties(map);
|
||||
this.customizer.customize(factory);
|
||||
@@ -118,7 +118,7 @@ public class DefaultServletWebServerFactoryCustomizerTests {
|
||||
@Test
|
||||
public void tomcatAccessLogFileDateFormatCanBeRedefined() {
|
||||
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("server.tomcat.accesslog.enabled", "true");
|
||||
map.put("server.tomcat.accesslog.file-date-format", "yyyy-MM-dd.HH");
|
||||
bindProperties(map);
|
||||
@@ -397,7 +397,7 @@ public class DefaultServletWebServerFactoryCustomizerTests {
|
||||
|
||||
@Test
|
||||
public void customTomcatDisableMaxHttpPostSize() {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("server.tomcat.max-http-post-size", "-1");
|
||||
bindProperties(map);
|
||||
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(0);
|
||||
|
||||
@@ -69,7 +69,7 @@ public class MockServletWebServerFactory extends AbstractServletWebServerFactory
|
||||
|
||||
public MockServletWebServer(ServletContextInitializer[] initializers, int port) {
|
||||
super(Arrays.stream(initializers)
|
||||
.map((i) -> (Initializer) (s) -> i.onStartup(s))
|
||||
.map((initializer) -> (Initializer) initializer::onStartup)
|
||||
.toArray(Initializer[]::new), port);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.boot.cli.infrastructure;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -71,14 +70,8 @@ public final class CommandLineInvoker {
|
||||
private File findLaunchScript() throws IOException {
|
||||
File unpacked = new File("target/unpacked-cli");
|
||||
if (!unpacked.isDirectory()) {
|
||||
File zip = new File("target").listFiles(new FileFilter() {
|
||||
|
||||
@Override
|
||||
public boolean accept(File pathname) {
|
||||
return pathname.getName().endsWith("-bin.zip");
|
||||
}
|
||||
|
||||
})[0];
|
||||
File zip = new File("target")
|
||||
.listFiles((pathname) -> pathname.getName().endsWith("-bin.zip"))[0];
|
||||
try (ZipInputStream input = new ZipInputStream(new FileInputStream(zip))) {
|
||||
ZipEntry entry;
|
||||
while ((entry = input.getNextEntry()) != null) {
|
||||
|
||||
@@ -57,9 +57,7 @@ import org.springframework.boot.cli.compiler.RepositoryConfigurationFactory;
|
||||
import org.springframework.boot.cli.compiler.grape.RepositoryConfiguration;
|
||||
import org.springframework.boot.loader.tools.JarWriter;
|
||||
import org.springframework.boot.loader.tools.Layout;
|
||||
import org.springframework.boot.loader.tools.Libraries;
|
||||
import org.springframework.boot.loader.tools.Library;
|
||||
import org.springframework.boot.loader.tools.LibraryCallback;
|
||||
import org.springframework.boot.loader.tools.LibraryScope;
|
||||
import org.springframework.boot.loader.tools.Repackager;
|
||||
import org.springframework.core.io.Resource;
|
||||
@@ -198,13 +196,9 @@ abstract class ArchiveCommand extends OptionParsingCommand {
|
||||
libraries.addAll(createLibraries(dependencies));
|
||||
Repackager repackager = new Repackager(file);
|
||||
repackager.setMainClass(PackagedSpringApplicationLauncher.class.getName());
|
||||
repackager.repackage(new Libraries() {
|
||||
|
||||
@Override
|
||||
public void doWithLibraries(LibraryCallback callback) throws IOException {
|
||||
for (Library library : libraries) {
|
||||
callback.library(library);
|
||||
}
|
||||
repackager.repackage((callback) -> {
|
||||
for (Library library : libraries) {
|
||||
callback.library(library);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -94,12 +94,7 @@ class ServiceCapabilitiesReportGenerator {
|
||||
|
||||
private List<Dependency> getSortedDependencies(InitializrServiceMetadata metadata) {
|
||||
ArrayList<Dependency> dependencies = new ArrayList<>(metadata.getDependencies());
|
||||
Collections.sort(dependencies, new Comparator<Dependency>() {
|
||||
@Override
|
||||
public int compare(Dependency o1, Dependency o2) {
|
||||
return o1.getId().compareTo(o2.getId());
|
||||
}
|
||||
});
|
||||
dependencies.sort(Comparator.comparing(Dependency::getId));
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
@@ -108,15 +103,7 @@ class ServiceCapabilitiesReportGenerator {
|
||||
report.append("Available project types:" + NEW_LINE);
|
||||
report.append("------------------------" + NEW_LINE);
|
||||
SortedSet<Entry<String, ProjectType>> entries = new TreeSet<>(
|
||||
new Comparator<Entry<String, ProjectType>>() {
|
||||
|
||||
@Override
|
||||
public int compare(Entry<String, ProjectType> o1,
|
||||
Entry<String, ProjectType> o2) {
|
||||
return o1.getKey().compareTo(o2.getKey());
|
||||
}
|
||||
|
||||
});
|
||||
Comparator.comparing(Entry::getKey));
|
||||
entries.addAll(metadata.getProjectTypes().entrySet());
|
||||
for (Entry<String, ProjectType> entry : entries) {
|
||||
ProjectType type = entry.getValue();
|
||||
|
||||
@@ -130,17 +130,10 @@ public class OptionHandler {
|
||||
|
||||
@Override
|
||||
public String format(Map<String, ? extends OptionDescriptor> options) {
|
||||
Comparator<OptionDescriptor> comparator = new Comparator<OptionDescriptor>() {
|
||||
@Override
|
||||
public int compare(OptionDescriptor first, OptionDescriptor second) {
|
||||
return first.options().iterator().next()
|
||||
.compareTo(second.options().iterator().next());
|
||||
}
|
||||
};
|
||||
|
||||
Comparator<OptionDescriptor> comparator = Comparator.comparing(
|
||||
(optionDescriptor) -> optionDescriptor.options().iterator().next());
|
||||
Set<OptionDescriptor> sorted = new TreeSet<>(comparator);
|
||||
sorted.addAll(options.values());
|
||||
|
||||
for (OptionDescriptor descriptor : sorted) {
|
||||
if (!descriptor.representsNonOptions()) {
|
||||
this.help.add(new OptionHelpAdapter(descriptor));
|
||||
|
||||
@@ -119,12 +119,7 @@ public class Shell {
|
||||
}
|
||||
|
||||
private void attachSignalHandler() {
|
||||
SignalUtils.attachSignalHandler(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
handleSigInt();
|
||||
}
|
||||
});
|
||||
SignalUtils.attachSignalHandler(this::handleSigInt);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user