Use lambdas when possible
Replace anonymous inner classes with lambda declarations (when possible using method references). See gh-9781
This commit is contained in:
committed by
Phillip Webb
parent
d16af43664
commit
2626a3a795
@@ -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());
|
||||
endpoints.sort(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;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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(() -> "");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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
|
||||
orderedClassNames.sort(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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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,11 +94,7 @@ class ServiceCapabilitiesReportGenerator {
|
||||
|
||||
private List<Dependency> getSortedDependencies(InitializrServiceMetadata metadata) {
|
||||
ArrayList<Dependency> dependencies = new ArrayList<>(metadata.getDependencies());
|
||||
dependencies.sort(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;
|
||||
}
|
||||
|
||||
@@ -107,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 = (first, second) -> first.options()
|
||||
.iterator().next().compareTo(second.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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -122,23 +122,23 @@ public class ExtendedGroovyClassLoader extends GroovyClassLoader {
|
||||
|
||||
@Override
|
||||
public ClassCollector createCollector(CompilationUnit unit, SourceUnit su) {
|
||||
InnerLoader loader = AccessController
|
||||
.doPrivileged(new PrivilegedAction<InnerLoader>() {
|
||||
@Override
|
||||
public InnerLoader run() {
|
||||
return new InnerLoader(ExtendedGroovyClassLoader.this) {
|
||||
// Don't return URLs from the inner loader so that Tomcat only
|
||||
// searches the parent. Fixes 'TLD skipped' issues
|
||||
@Override
|
||||
public URL[] getURLs() {
|
||||
return NO_URLS;
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
InnerLoader loader = AccessController.doPrivileged(getInnerLoader());
|
||||
return new ExtendedClassCollector(loader, unit, su);
|
||||
}
|
||||
|
||||
private PrivilegedAction<InnerLoader> getInnerLoader() {
|
||||
return () -> new InnerLoader(ExtendedGroovyClassLoader.this) {
|
||||
|
||||
// Don't return URLs from the inner loader so that Tomcat only
|
||||
// searches the parent. Fixes 'TLD skipped' issues
|
||||
@Override
|
||||
public URL[] getURLs() {
|
||||
return NO_URLS;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
public CompilerConfiguration getConfiguration() {
|
||||
return this.configuration;
|
||||
}
|
||||
|
||||
@@ -100,19 +100,11 @@ public class AetherGrapeEngine implements GrapeEngine {
|
||||
|| Boolean.getBoolean("groovy.grape.report.downloads")) {
|
||||
return new DetailedProgressReporter(session, System.out);
|
||||
}
|
||||
else if ("none".equals(progressReporter)) {
|
||||
return new ProgressReporter() {
|
||||
|
||||
@Override
|
||||
public void finished() {
|
||||
|
||||
}
|
||||
|
||||
if ("none".equals(progressReporter)) {
|
||||
return () -> {
|
||||
};
|
||||
}
|
||||
else {
|
||||
return new SummaryProgressReporter(session, System.out);
|
||||
}
|
||||
return new SummaryProgressReporter(session, System.out);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -26,7 +26,6 @@ import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -105,25 +104,22 @@ public class CliTester implements TestRule {
|
||||
String... args) {
|
||||
clearUrlHandler();
|
||||
final String[] sources = getSources(args);
|
||||
return Executors.newSingleThreadExecutor().submit(new Callable<T>() {
|
||||
@Override
|
||||
public T call() throws Exception {
|
||||
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
||||
System.setProperty("server.port", "0");
|
||||
System.setProperty("spring.application.class.name",
|
||||
"org.springframework.boot.cli.CliTesterSpringApplication");
|
||||
System.setProperty("portfile",
|
||||
new File("target/server.port").getAbsolutePath());
|
||||
try {
|
||||
command.run(sources);
|
||||
return command;
|
||||
}
|
||||
finally {
|
||||
System.clearProperty("server.port");
|
||||
System.clearProperty("spring.application.class.name");
|
||||
System.clearProperty("portfile");
|
||||
Thread.currentThread().setContextClassLoader(loader);
|
||||
}
|
||||
return Executors.newSingleThreadExecutor().submit(() -> {
|
||||
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
||||
System.setProperty("server.port", "0");
|
||||
System.setProperty("spring.application.class.name",
|
||||
"org.springframework.boot.cli.CliTesterSpringApplication");
|
||||
System.setProperty("portfile",
|
||||
new File("target/server.port").getAbsolutePath());
|
||||
try {
|
||||
command.run(sources);
|
||||
return command;
|
||||
}
|
||||
finally {
|
||||
System.clearProperty("server.port");
|
||||
System.clearProperty("spring.application.class.name");
|
||||
System.clearProperty("portfile");
|
||||
Thread.currentThread().setContextClassLoader(loader);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -36,69 +36,53 @@ public class RepositoryConfigurationFactoryTests {
|
||||
|
||||
@Test
|
||||
public void defaultRepositories() {
|
||||
SystemProperties.doWithSystemProperties(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
List<RepositoryConfiguration> repositoryConfiguration = RepositoryConfigurationFactory
|
||||
.createDefaultRepositoryConfiguration();
|
||||
assertRepositoryConfiguration(repositoryConfiguration, "central", "local",
|
||||
"spring-snapshot", "spring-milestone");
|
||||
}
|
||||
SystemProperties.doWithSystemProperties(() -> {
|
||||
List<RepositoryConfiguration> repositoryConfiguration = RepositoryConfigurationFactory
|
||||
.createDefaultRepositoryConfiguration();
|
||||
assertRepositoryConfiguration(repositoryConfiguration, "central", "local",
|
||||
"spring-snapshot", "spring-milestone");
|
||||
}, "user.home:src/test/resources/maven-settings/basic");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void snapshotRepositoriesDisabled() {
|
||||
SystemProperties.doWithSystemProperties(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
List<RepositoryConfiguration> repositoryConfiguration = RepositoryConfigurationFactory
|
||||
.createDefaultRepositoryConfiguration();
|
||||
assertRepositoryConfiguration(repositoryConfiguration, "central",
|
||||
"local");
|
||||
}
|
||||
SystemProperties.doWithSystemProperties(() -> {
|
||||
List<RepositoryConfiguration> repositoryConfiguration = RepositoryConfigurationFactory
|
||||
.createDefaultRepositoryConfiguration();
|
||||
assertRepositoryConfiguration(repositoryConfiguration, "central", "local");
|
||||
}, "user.home:src/test/resources/maven-settings/basic",
|
||||
"disableSpringSnapshotRepos:true");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void activeByDefaultProfileRepositories() {
|
||||
SystemProperties.doWithSystemProperties(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
List<RepositoryConfiguration> repositoryConfiguration = RepositoryConfigurationFactory
|
||||
.createDefaultRepositoryConfiguration();
|
||||
assertRepositoryConfiguration(repositoryConfiguration, "central", "local",
|
||||
"spring-snapshot", "spring-milestone", "active-by-default");
|
||||
}
|
||||
SystemProperties.doWithSystemProperties(() -> {
|
||||
List<RepositoryConfiguration> repositoryConfiguration = RepositoryConfigurationFactory
|
||||
.createDefaultRepositoryConfiguration();
|
||||
assertRepositoryConfiguration(repositoryConfiguration, "central", "local",
|
||||
"spring-snapshot", "spring-milestone", "active-by-default");
|
||||
}, "user.home:src/test/resources/maven-settings/active-profile-repositories");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void activeByPropertyProfileRepositories() {
|
||||
SystemProperties.doWithSystemProperties(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
List<RepositoryConfiguration> repositoryConfiguration = RepositoryConfigurationFactory
|
||||
.createDefaultRepositoryConfiguration();
|
||||
assertRepositoryConfiguration(repositoryConfiguration, "central", "local",
|
||||
"spring-snapshot", "spring-milestone", "active-by-property");
|
||||
}
|
||||
SystemProperties.doWithSystemProperties(() -> {
|
||||
List<RepositoryConfiguration> repositoryConfiguration = RepositoryConfigurationFactory
|
||||
.createDefaultRepositoryConfiguration();
|
||||
assertRepositoryConfiguration(repositoryConfiguration, "central", "local",
|
||||
"spring-snapshot", "spring-milestone", "active-by-property");
|
||||
}, "user.home:src/test/resources/maven-settings/active-profile-repositories",
|
||||
"foo:bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void interpolationProfileRepositories() {
|
||||
SystemProperties.doWithSystemProperties(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
List<RepositoryConfiguration> repositoryConfiguration = RepositoryConfigurationFactory
|
||||
.createDefaultRepositoryConfiguration();
|
||||
assertRepositoryConfiguration(repositoryConfiguration, "central", "local",
|
||||
"spring-snapshot", "spring-milestone", "interpolate-releases",
|
||||
"interpolate-snapshots");
|
||||
}
|
||||
SystemProperties.doWithSystemProperties(() -> {
|
||||
List<RepositoryConfiguration> repositoryConfiguration = RepositoryConfigurationFactory
|
||||
.createDefaultRepositoryConfiguration();
|
||||
assertRepositoryConfiguration(repositoryConfiguration, "central", "local",
|
||||
"spring-snapshot", "spring-milestone", "interpolate-releases",
|
||||
"interpolate-snapshots");
|
||||
}, "user.home:src/test/resources/maven-settings/active-profile-repositories",
|
||||
"interpolate:true");
|
||||
}
|
||||
|
||||
@@ -72,54 +72,32 @@ public class AetherGrapeEngineTests {
|
||||
|
||||
@Test
|
||||
public void proxySelector() {
|
||||
doWithCustomUserHome(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
AetherGrapeEngine grapeEngine = createGrapeEngine();
|
||||
|
||||
DefaultRepositorySystemSession session = (DefaultRepositorySystemSession) ReflectionTestUtils
|
||||
.getField(grapeEngine, "session");
|
||||
|
||||
assertThat(session.getProxySelector() instanceof CompositeProxySelector)
|
||||
.isTrue();
|
||||
}
|
||||
doWithCustomUserHome(() -> {
|
||||
AetherGrapeEngine grapeEngine = createGrapeEngine();
|
||||
DefaultRepositorySystemSession session = (DefaultRepositorySystemSession) ReflectionTestUtils
|
||||
.getField(grapeEngine, "session");
|
||||
|
||||
assertThat(session.getProxySelector() instanceof CompositeProxySelector)
|
||||
.isTrue();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repositoryMirrors() {
|
||||
doWithCustomUserHome(new Runnable() {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void run() {
|
||||
AetherGrapeEngine grapeEngine = createGrapeEngine();
|
||||
|
||||
List<RemoteRepository> repositories = (List<RemoteRepository>) ReflectionTestUtils
|
||||
.getField(grapeEngine, "repositories");
|
||||
assertThat(repositories).hasSize(1);
|
||||
assertThat(repositories.get(0).getId()).isEqualTo("central-mirror");
|
||||
}
|
||||
doWithCustomUserHome(() -> {
|
||||
List<RemoteRepository> repositories = getRepositories();
|
||||
assertThat(repositories).hasSize(1);
|
||||
assertThat(repositories.get(0).getId()).isEqualTo("central-mirror");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repositoryAuthentication() {
|
||||
doWithCustomUserHome(new Runnable() {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void run() {
|
||||
AetherGrapeEngine grapeEngine = createGrapeEngine();
|
||||
|
||||
List<RemoteRepository> repositories = (List<RemoteRepository>) ReflectionTestUtils
|
||||
.getField(grapeEngine, "repositories");
|
||||
assertThat(repositories).hasSize(1);
|
||||
Authentication authentication = repositories.get(0).getAuthentication();
|
||||
assertThat(authentication).isNotNull();
|
||||
}
|
||||
doWithCustomUserHome(() -> {
|
||||
List<RemoteRepository> repositories = getRepositories();
|
||||
assertThat(repositories).hasSize(1);
|
||||
Authentication authentication = repositories.get(0).getAuthentication();
|
||||
assertThat(authentication).isNotNull();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -216,6 +194,13 @@ public class AetherGrapeEngineTests {
|
||||
assertThat(urls[0].toExternalForm().endsWith("-sources.jar")).isTrue();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<RemoteRepository> getRepositories() {
|
||||
AetherGrapeEngine grapeEngine = createGrapeEngine();
|
||||
return (List<RemoteRepository>) ReflectionTestUtils.getField(grapeEngine,
|
||||
"repositories");
|
||||
}
|
||||
|
||||
private Map<String, Object> createDependency(String group, String module,
|
||||
String version) {
|
||||
Map<String, Object> dependency = new HashMap<>();
|
||||
|
||||
@@ -59,21 +59,12 @@ public class GrapeRootRepositorySystemSessionAutoConfigurationTests {
|
||||
@Test
|
||||
public void noLocalRepositoryWhenNoGrapeRoot() {
|
||||
given(this.repositorySystem.newLocalRepositoryManager(eq(this.session),
|
||||
any(LocalRepository.class)))
|
||||
.willAnswer(new Answer<LocalRepositoryManager>() {
|
||||
|
||||
@Override
|
||||
public LocalRepositoryManager answer(
|
||||
InvocationOnMock invocation) throws Throwable {
|
||||
LocalRepository localRepository = invocation
|
||||
.getArgument(1);
|
||||
return new SimpleLocalRepositoryManagerFactory()
|
||||
.newInstance(
|
||||
GrapeRootRepositorySystemSessionAutoConfigurationTests.this.session,
|
||||
localRepository);
|
||||
}
|
||||
|
||||
});
|
||||
any(LocalRepository.class))).willAnswer((invocation) -> {
|
||||
LocalRepository localRepository = invocation.getArgument(1);
|
||||
return new SimpleLocalRepositoryManagerFactory().newInstance(
|
||||
GrapeRootRepositorySystemSessionAutoConfigurationTests.this.session,
|
||||
localRepository);
|
||||
});
|
||||
new GrapeRootRepositorySystemSessionAutoConfiguration().apply(this.session,
|
||||
this.repositorySystem);
|
||||
verify(this.repositorySystem, times(0))
|
||||
|
||||
@@ -26,7 +26,6 @@ import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
|
||||
import org.eclipse.aether.repository.Authentication;
|
||||
import org.eclipse.aether.repository.AuthenticationContext;
|
||||
import org.eclipse.aether.repository.LocalRepository;
|
||||
import org.eclipse.aether.repository.LocalRepositoryManager;
|
||||
import org.eclipse.aether.repository.Proxy;
|
||||
import org.eclipse.aether.repository.RemoteRepository;
|
||||
import org.junit.Before;
|
||||
@@ -35,8 +34,6 @@ import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import org.springframework.boot.cli.testutil.SystemProperties;
|
||||
|
||||
@@ -78,28 +75,17 @@ public class SettingsXmlRepositorySystemSessionAutoConfigurationTests {
|
||||
final DefaultRepositorySystemSession session = MavenRepositorySystemUtils
|
||||
.newSession();
|
||||
given(this.repositorySystem.newLocalRepositoryManager(eq(session),
|
||||
any(LocalRepository.class)))
|
||||
.willAnswer(new Answer<LocalRepositoryManager>() {
|
||||
|
||||
@Override
|
||||
public LocalRepositoryManager answer(
|
||||
InvocationOnMock invocation) throws Throwable {
|
||||
LocalRepository localRepository = invocation
|
||||
.getArgument(1);
|
||||
return new SimpleLocalRepositoryManagerFactory()
|
||||
.newInstance(session, localRepository);
|
||||
}
|
||||
});
|
||||
|
||||
SystemProperties.doWithSystemProperties(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
new SettingsXmlRepositorySystemSessionAutoConfiguration().apply(session,
|
||||
SettingsXmlRepositorySystemSessionAutoConfigurationTests.this.repositorySystem);
|
||||
}
|
||||
}, "user.home:src/test/resources/maven-settings/property-interpolation",
|
||||
any(LocalRepository.class))).willAnswer((invocation) -> {
|
||||
LocalRepository localRepository = invocation.getArgument(1);
|
||||
return new SimpleLocalRepositoryManagerFactory().newInstance(session,
|
||||
localRepository);
|
||||
});
|
||||
SystemProperties.doWithSystemProperties(
|
||||
() -> new SettingsXmlRepositorySystemSessionAutoConfiguration().apply(
|
||||
session,
|
||||
SettingsXmlRepositorySystemSessionAutoConfigurationTests.this.repositorySystem),
|
||||
"user.home:src/test/resources/maven-settings/property-interpolation",
|
||||
"foo:bar");
|
||||
|
||||
assertThat(session.getLocalRepository().getBasedir().getAbsolutePath())
|
||||
.endsWith(File.separatorChar + "bar" + File.separatorChar + "repository");
|
||||
}
|
||||
@@ -107,14 +93,11 @@ public class SettingsXmlRepositorySystemSessionAutoConfigurationTests {
|
||||
private void assertSessionCustomization(String userHome) {
|
||||
final DefaultRepositorySystemSession session = MavenRepositorySystemUtils
|
||||
.newSession();
|
||||
SystemProperties.doWithSystemProperties(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
new SettingsXmlRepositorySystemSessionAutoConfiguration().apply(session,
|
||||
SettingsXmlRepositorySystemSessionAutoConfigurationTests.this.repositorySystem);
|
||||
}
|
||||
}, "user.home:" + userHome);
|
||||
|
||||
SystemProperties.doWithSystemProperties(
|
||||
() -> new SettingsXmlRepositorySystemSessionAutoConfiguration().apply(
|
||||
session,
|
||||
SettingsXmlRepositorySystemSessionAutoConfigurationTests.this.repositorySystem),
|
||||
"user.home:" + userHome);
|
||||
RemoteRepository repository = new RemoteRepository.Builder("my-server", "default",
|
||||
"http://maven.example.com").build();
|
||||
assertMirrorSelectorConfiguration(session, repository);
|
||||
|
||||
@@ -136,14 +136,7 @@ public class LocalDevToolsAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public FileSystemWatcherFactory fileSystemWatcherFactory() {
|
||||
return new FileSystemWatcherFactory() {
|
||||
|
||||
@Override
|
||||
public FileSystemWatcher getFileSystemWatcher() {
|
||||
return newFileSystemWatcher();
|
||||
}
|
||||
|
||||
};
|
||||
return this::newFileSystemWatcher;
|
||||
}
|
||||
|
||||
private FileSystemWatcher newFileSystemWatcher() {
|
||||
|
||||
@@ -89,14 +89,7 @@ public class LiveReloadServer {
|
||||
* @param port the listen port
|
||||
*/
|
||||
public LiveReloadServer(int port) {
|
||||
this(port, new ThreadFactory() {
|
||||
|
||||
@Override
|
||||
public Thread newThread(Runnable runnable) {
|
||||
return new Thread(runnable);
|
||||
}
|
||||
|
||||
});
|
||||
this(port, Thread::new);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,14 +114,7 @@ public class LiveReloadServer {
|
||||
logger.debug("Starting live reload server on port " + this.port);
|
||||
this.serverSocket = new ServerSocket(this.port);
|
||||
int localPort = this.serverSocket.getLocalPort();
|
||||
this.listenThread = this.threadFactory.newThread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
acceptConnections();
|
||||
}
|
||||
|
||||
});
|
||||
this.listenThread = this.threadFactory.newThread(this::acceptConnections);
|
||||
this.listenThread.setDaemon(true);
|
||||
this.listenThread.setName("Live Reload Server");
|
||||
this.listenThread.start();
|
||||
|
||||
@@ -194,14 +194,7 @@ public class RemoteClientConfiguration {
|
||||
|
||||
@Bean
|
||||
public FileSystemWatcherFactory getFileSystemWatcherFactory() {
|
||||
return new FileSystemWatcherFactory() {
|
||||
|
||||
@Override
|
||||
public FileSystemWatcher getFileSystemWatcher() {
|
||||
return newFileSystemWatcher();
|
||||
}
|
||||
|
||||
};
|
||||
return this::newFileSystemWatcher;
|
||||
}
|
||||
|
||||
private FileSystemWatcher newFileSystemWatcher() {
|
||||
|
||||
@@ -30,14 +30,7 @@ public interface AccessManager {
|
||||
/**
|
||||
* {@link AccessManager} that permits all requests.
|
||||
*/
|
||||
AccessManager PERMIT_ALL = new AccessManager() {
|
||||
|
||||
@Override
|
||||
public boolean isAllowed(ServerHttpRequest request) {
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
AccessManager PERMIT_ALL = (request) -> true;
|
||||
|
||||
/**
|
||||
* Determine if the specific request is allowed to be handled by the
|
||||
|
||||
@@ -28,14 +28,7 @@ public interface FailureHandler {
|
||||
/**
|
||||
* {@link FailureHandler} that always aborts.
|
||||
*/
|
||||
FailureHandler NONE = new FailureHandler() {
|
||||
|
||||
@Override
|
||||
public Outcome handle(Throwable failure) {
|
||||
return Outcome.ABORT;
|
||||
}
|
||||
|
||||
};
|
||||
FailureHandler NONE = (failure) -> Outcome.ABORT;
|
||||
|
||||
/**
|
||||
* Handle a run failure. Implementations may block, for example to wait until specific
|
||||
|
||||
@@ -31,14 +31,7 @@ public interface RestartInitializer {
|
||||
/**
|
||||
* {@link RestartInitializer} that doesn't return any URLs.
|
||||
*/
|
||||
RestartInitializer NONE = new RestartInitializer() {
|
||||
|
||||
@Override
|
||||
public URL[] getInitialUrls(Thread thread) {
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
RestartInitializer NONE = (thread) -> null;
|
||||
|
||||
/**
|
||||
* Return the initial set of URLs for the {@link Restarter} or {@code null} if no
|
||||
|
||||
@@ -167,15 +167,10 @@ public class Restarter {
|
||||
|
||||
private void immediateRestart() {
|
||||
try {
|
||||
getLeakSafeThread().callAndWait(new Callable<Void>() {
|
||||
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
start(FailureHandler.NONE);
|
||||
cleanupCaches();
|
||||
return null;
|
||||
}
|
||||
|
||||
getLeakSafeThread().callAndWait(() -> {
|
||||
start(FailureHandler.NONE);
|
||||
cleanupCaches();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
catch (Exception ex) {
|
||||
@@ -251,15 +246,10 @@ public class Restarter {
|
||||
return;
|
||||
}
|
||||
this.logger.debug("Restarting application");
|
||||
getLeakSafeThread().call(new Callable<Void>() {
|
||||
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
Restarter.this.stop();
|
||||
Restarter.this.start(failureHandler);
|
||||
return null;
|
||||
}
|
||||
|
||||
getLeakSafeThread().call(() -> {
|
||||
Restarter.this.stop();
|
||||
Restarter.this.start(failureHandler);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -641,15 +631,10 @@ public class Restarter {
|
||||
|
||||
@Override
|
||||
public Thread newThread(final Runnable runnable) {
|
||||
return getLeakSafeThread().callAndWait(new Callable<Thread>() {
|
||||
|
||||
@Override
|
||||
public Thread call() throws Exception {
|
||||
Thread thread = new Thread(runnable);
|
||||
thread.setContextClassLoader(Restarter.this.applicationClassLoader);
|
||||
return thread;
|
||||
}
|
||||
|
||||
return getLeakSafeThread().callAndWait(() -> {
|
||||
Thread thread = new Thread(runnable);
|
||||
thread.setContextClassLoader(Restarter.this.applicationClassLoader);
|
||||
return thread;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -31,14 +31,7 @@ public interface ClassLoaderFileRepository {
|
||||
/**
|
||||
* Empty {@link ClassLoaderFileRepository} implementation.
|
||||
*/
|
||||
ClassLoaderFileRepository NONE = new ClassLoaderFileRepository() {
|
||||
|
||||
@Override
|
||||
public ClassLoaderFile getFile(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
ClassLoaderFileRepository NONE = (name) -> null;
|
||||
|
||||
/**
|
||||
* Return a {@link ClassLoaderFile} for the given name or {@code null} if no file is
|
||||
|
||||
@@ -126,12 +126,8 @@ public class RestartClassLoader extends URLClassLoader implements SmartClassLoad
|
||||
if (file.getKind() == Kind.DELETED) {
|
||||
return null;
|
||||
}
|
||||
return AccessController.doPrivileged(new PrivilegedAction<URL>() {
|
||||
@Override
|
||||
public URL run() {
|
||||
return createFileUrl(name, file);
|
||||
}
|
||||
});
|
||||
return AccessController
|
||||
.doPrivileged((PrivilegedAction<URL>) () -> createFileUrl(name, file));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -167,12 +163,9 @@ public class RestartClassLoader extends URLClassLoader implements SmartClassLoad
|
||||
if (file.getKind() == Kind.DELETED) {
|
||||
throw new ClassNotFoundException(name);
|
||||
}
|
||||
return AccessController.doPrivileged(new PrivilegedAction<Class<?>>() {
|
||||
@Override
|
||||
public Class<?> run() {
|
||||
byte[] bytes = file.getContents();
|
||||
return defineClass(name, bytes, 0, bytes.length);
|
||||
}
|
||||
return AccessController.doPrivileged((PrivilegedAction<Class<?>>) () -> {
|
||||
byte[] bytes = file.getContents();
|
||||
return defineClass(name, bytes, 0, bytes.length);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import org.springframework.boot.devtools.filewatch.ChangedFile;
|
||||
import org.springframework.boot.devtools.filewatch.FileSystemWatcher;
|
||||
import org.springframework.boot.devtools.filewatch.FileSystemWatcherFactory;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
@@ -113,14 +112,7 @@ public class ClassPathFileSystemWatcherTests {
|
||||
|
||||
@Bean
|
||||
public ClassPathRestartStrategy restartStrategy() {
|
||||
return new ClassPathRestartStrategy() {
|
||||
|
||||
@Override
|
||||
public boolean isRestartRequired(ChangedFile file) {
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
return (file) -> false;
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.boot.devtools.filewatch;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -221,12 +220,7 @@ public class FileSystemWatcherTests {
|
||||
File folder = this.temp.newFolder();
|
||||
final Set<ChangedFiles> listener2Changes = new LinkedHashSet<>();
|
||||
this.watcher.addSourceFolder(folder);
|
||||
this.watcher.addListener(new FileChangeListener() {
|
||||
@Override
|
||||
public void onChange(Set<ChangedFiles> changeSet) {
|
||||
listener2Changes.addAll(changeSet);
|
||||
}
|
||||
});
|
||||
this.watcher.addListener(listener2Changes::addAll);
|
||||
this.watcher.start();
|
||||
File file = touch(new File(folder, "test.txt"));
|
||||
this.watcher.stopAfter(1);
|
||||
@@ -262,14 +256,8 @@ public class FileSystemWatcherTests {
|
||||
File file = touch(new File(folder, "file.txt"));
|
||||
File trigger = touch(new File(folder, "trigger.txt"));
|
||||
this.watcher.addSourceFolder(folder);
|
||||
this.watcher.setTriggerFilter(new FileFilter() {
|
||||
|
||||
@Override
|
||||
public boolean accept(File file) {
|
||||
return file.getName().equals("trigger.txt");
|
||||
}
|
||||
|
||||
});
|
||||
this.watcher.setTriggerFilter(
|
||||
(candidate) -> candidate.getName().equals("trigger.txt"));
|
||||
this.watcher.start();
|
||||
FileCopyUtils.copy("abc".getBytes(), file);
|
||||
Thread.sleep(100);
|
||||
@@ -285,12 +273,8 @@ public class FileSystemWatcherTests {
|
||||
|
||||
private void setupWatcher(long pollingInterval, long quietPeriod) {
|
||||
this.watcher = new FileSystemWatcher(false, pollingInterval, quietPeriod);
|
||||
this.watcher.addListener(new FileChangeListener() {
|
||||
@Override
|
||||
public void onChange(Set<ChangedFiles> changeSet) {
|
||||
FileSystemWatcherTests.this.changes.add(changeSet);
|
||||
}
|
||||
});
|
||||
this.watcher.addListener(
|
||||
(changeSet) -> FileSystemWatcherTests.this.changes.add(changeSet));
|
||||
}
|
||||
|
||||
private File startWithNewFolder() throws IOException {
|
||||
|
||||
@@ -55,12 +55,7 @@ public class MainMethodTests {
|
||||
|
||||
@Test
|
||||
public void validMainMethod() throws Exception {
|
||||
MainMethod method = new TestThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Valid.main();
|
||||
}
|
||||
}).test();
|
||||
MainMethod method = new TestThread(Valid::main).test();
|
||||
assertThat(method.getMethod()).isEqualTo(this.actualMain);
|
||||
assertThat(method.getDeclaringClassName())
|
||||
.isEqualTo(this.actualMain.getDeclaringClass().getName());
|
||||
@@ -70,24 +65,14 @@ public class MainMethodTests {
|
||||
public void missingArgsMainMethod() throws Exception {
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage("Unable to find main method");
|
||||
new TestThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MissingArgs.main();
|
||||
}
|
||||
}).test();
|
||||
new TestThread(MissingArgs::main).test();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonStatic() throws Exception {
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage("Unable to find main method");
|
||||
new TestThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
new NonStaticMain().main();
|
||||
}
|
||||
}).test();
|
||||
new TestThread(() -> new NonStaticMain().main()).test();
|
||||
}
|
||||
|
||||
private static class TestThread extends Thread {
|
||||
|
||||
@@ -19,13 +19,10 @@ package org.springframework.boot.devtools.restart;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
|
||||
import org.junit.rules.TestRule;
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runners.model.Statement;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import org.springframework.beans.factory.ObjectFactory;
|
||||
|
||||
@@ -64,30 +61,17 @@ public class MockRestarter implements TestRule {
|
||||
Restarter.setInstance(this.mock);
|
||||
given(this.mock.getInitialUrls()).willReturn(new URL[] {});
|
||||
given(this.mock.getOrAddAttribute(anyString(), (ObjectFactory) any()))
|
||||
.willAnswer(new Answer<Object>() {
|
||||
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
String name = (String) invocation.getArguments()[0];
|
||||
ObjectFactory factory = (ObjectFactory) invocation
|
||||
.getArguments()[1];
|
||||
Object attribute = MockRestarter.this.attributes.get(name);
|
||||
if (attribute == null) {
|
||||
attribute = factory.getObject();
|
||||
MockRestarter.this.attributes.put(name, attribute);
|
||||
}
|
||||
return attribute;
|
||||
.willAnswer((invocation) -> {
|
||||
String name = (String) invocation.getArguments()[0];
|
||||
ObjectFactory factory = (ObjectFactory) invocation.getArguments()[1];
|
||||
Object attribute = MockRestarter.this.attributes.get(name);
|
||||
if (attribute == null) {
|
||||
attribute = factory.getObject();
|
||||
MockRestarter.this.attributes.put(name, attribute);
|
||||
}
|
||||
|
||||
return attribute;
|
||||
});
|
||||
given(this.mock.getThreadFactory()).willReturn(new ThreadFactory() {
|
||||
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
return new Thread(r);
|
||||
}
|
||||
|
||||
});
|
||||
given(this.mock.getThreadFactory()).willReturn(Thread::new);
|
||||
}
|
||||
|
||||
private void cleanup() {
|
||||
|
||||
@@ -67,14 +67,7 @@ public class OnInitializedRestarterConditionTests {
|
||||
|
||||
@Test
|
||||
public void initialized() throws Exception {
|
||||
Thread thread = new Thread() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
TestInitialized.main();
|
||||
};
|
||||
|
||||
};
|
||||
Thread thread = new Thread(TestInitialized::main);
|
||||
thread.start();
|
||||
synchronized (wait) {
|
||||
wait.wait();
|
||||
|
||||
@@ -28,7 +28,6 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.ObjectFactory;
|
||||
import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile;
|
||||
import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile.Kind;
|
||||
@@ -84,14 +83,7 @@ public class RestarterTests {
|
||||
@Test
|
||||
public void testRestart() throws Exception {
|
||||
Restarter.clearInstance();
|
||||
Thread thread = new Thread() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
SampleApplication.main();
|
||||
};
|
||||
|
||||
};
|
||||
Thread thread = new Thread(SampleApplication::main);
|
||||
thread.start();
|
||||
Thread.sleep(2600);
|
||||
String output = this.out.toString();
|
||||
@@ -150,12 +142,7 @@ public class RestarterTests {
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void getOrAddAttributeWithExistingAttribute() throws Exception {
|
||||
Restarter.getInstance().getOrAddAttribute("x", new ObjectFactory<String>() {
|
||||
@Override
|
||||
public String getObject() throws BeansException {
|
||||
return "abc";
|
||||
}
|
||||
});
|
||||
Restarter.getInstance().getOrAddAttribute("x", () -> "abc");
|
||||
ObjectFactory objectFactory = mock(ObjectFactory.class);
|
||||
Object attribute = Restarter.getInstance().getOrAddAttribute("x", objectFactory);
|
||||
assertThat(attribute).isEqualTo("abc");
|
||||
@@ -166,19 +153,16 @@ public class RestarterTests {
|
||||
public void getThreadFactory() throws Exception {
|
||||
final ClassLoader parentLoader = Thread.currentThread().getContextClassLoader();
|
||||
final ClassLoader contextClassLoader = new URLClassLoader(new URL[0]);
|
||||
Thread thread = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
Runnable runnable = mock(Runnable.class);
|
||||
Thread regular = new Thread();
|
||||
ThreadFactory factory = Restarter.getInstance().getThreadFactory();
|
||||
Thread viaFactory = factory.newThread(runnable);
|
||||
// Regular threads will inherit the current thread
|
||||
assertThat(regular.getContextClassLoader()).isEqualTo(contextClassLoader);
|
||||
// Factory threads should inherit from the initial thread
|
||||
assertThat(viaFactory.getContextClassLoader()).isEqualTo(parentLoader);
|
||||
};
|
||||
};
|
||||
Thread thread = new Thread(() -> {
|
||||
Runnable runnable = mock(Runnable.class);
|
||||
Thread regular = new Thread();
|
||||
ThreadFactory factory = Restarter.getInstance().getThreadFactory();
|
||||
Thread viaFactory = factory.newThread(runnable);
|
||||
// Regular threads will inherit the current thread
|
||||
assertThat(regular.getContextClassLoader()).isEqualTo(contextClassLoader);
|
||||
// Factory threads should inherit from the initial thread
|
||||
assertThat(viaFactory.getContextClassLoader()).isEqualTo(parentLoader);
|
||||
});
|
||||
thread.setContextClassLoader(contextClassLoader);
|
||||
thread.start();
|
||||
thread.join();
|
||||
|
||||
@@ -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.
|
||||
@@ -81,12 +81,8 @@ public class SilentExitExceptionHandlerTests {
|
||||
private Throwable thrown;
|
||||
|
||||
TestThread() {
|
||||
setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
|
||||
@Override
|
||||
public void uncaughtException(Thread t, Throwable e) {
|
||||
TestThread.this.thrown = e;
|
||||
}
|
||||
});
|
||||
setUncaughtExceptionHandler(
|
||||
(thread, exception) -> TestThread.this.thrown = exception);
|
||||
}
|
||||
|
||||
public Throwable getThrown() {
|
||||
@@ -119,21 +115,16 @@ public class SilentExitExceptionHandlerTests {
|
||||
@Override
|
||||
protected Thread[] getAllThreads() {
|
||||
final CountDownLatch threadRunning = new CountDownLatch(1);
|
||||
Thread daemonThread = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (TestSilentExitExceptionHandler.this.monitor) {
|
||||
threadRunning.countDown();
|
||||
try {
|
||||
TestSilentExitExceptionHandler.this.monitor.wait();
|
||||
}
|
||||
catch (InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
Thread daemonThread = new Thread(() -> {
|
||||
synchronized (TestSilentExitExceptionHandler.this.monitor) {
|
||||
threadRunning.countDown();
|
||||
try {
|
||||
TestSilentExitExceptionHandler.this.monitor.wait();
|
||||
}
|
||||
catch (InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
daemonThread.setDaemon(true);
|
||||
daemonThread.start();
|
||||
|
||||
@@ -33,8 +33,6 @@ import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import org.springframework.boot.devtools.tunnel.payload.HttpTunnelPayload;
|
||||
import org.springframework.boot.devtools.tunnel.server.HttpTunnelServer.HttpConnection;
|
||||
@@ -90,13 +88,10 @@ public class HttpTunnelServerTests {
|
||||
public void setup() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
this.server = new HttpTunnelServer(this.serverConnection);
|
||||
given(this.serverConnection.open(anyInt())).willAnswer(new Answer<ByteChannel>() {
|
||||
@Override
|
||||
public ByteChannel answer(InvocationOnMock invocation) throws Throwable {
|
||||
MockServerChannel channel = HttpTunnelServerTests.this.serverChannel;
|
||||
channel.setTimeout((Integer) invocation.getArguments()[0]);
|
||||
return channel;
|
||||
}
|
||||
given(this.serverConnection.open(anyInt())).willAnswer((invocation) -> {
|
||||
MockServerChannel channel = HttpTunnelServerTests.this.serverChannel;
|
||||
channel.setTimeout((Integer) invocation.getArguments()[0]);
|
||||
return channel;
|
||||
});
|
||||
this.servletRequest = new MockHttpServletRequest();
|
||||
this.servletRequest.setAsyncSupported(true);
|
||||
@@ -311,15 +306,10 @@ public class HttpTunnelServerTests {
|
||||
.willThrow(new IllegalArgumentException());
|
||||
final HttpConnection connection = new HttpConnection(request, this.response);
|
||||
final AtomicBoolean responded = new AtomicBoolean();
|
||||
Thread connectionThread = new Thread() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
connection.waitForResponse();
|
||||
responded.set(true);
|
||||
}
|
||||
|
||||
};
|
||||
Thread connectionThread = new Thread(() -> {
|
||||
connection.waitForResponse();
|
||||
responded.set(true);
|
||||
});
|
||||
connectionThread.start();
|
||||
assertThat(responded.get()).isFalse();
|
||||
Thread.sleep(sleepBeforeResponse);
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.boot.launchscript;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -27,8 +26,6 @@ import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.ws.rs.client.ClientRequestContext;
|
||||
import javax.ws.rs.client.ClientRequestFilter;
|
||||
import javax.ws.rs.client.Entity;
|
||||
import javax.ws.rs.client.WebTarget;
|
||||
|
||||
@@ -449,15 +446,9 @@ public class SysVinitLaunchScriptIT {
|
||||
extends DockerCmdExecFactoryImpl {
|
||||
|
||||
private SpringBootDockerCmdExecFactory() {
|
||||
withClientRequestFilters(new ClientRequestFilter() {
|
||||
|
||||
@Override
|
||||
public void filter(ClientRequestContext requestContext)
|
||||
throws IOException {
|
||||
// Workaround for https://go-review.googlesource.com/#/c/3821/
|
||||
requestContext.getHeaders().add("Connection", "close");
|
||||
}
|
||||
|
||||
withClientRequestFilters((requestContext) -> {
|
||||
// Workaround for https://go-review.googlesource.com/#/c/3821/
|
||||
requestContext.getHeaders().add("Connection", "close");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user