pull/11971/head
Phillip Webb 7 years ago
parent a0f4071390
commit 5de46c3186

@ -40,6 +40,7 @@ import org.springframework.kafka.core.KafkaAdmin;
* {@link EnableAutoConfiguration Auto-configuration} for {@link KafkaHealthIndicator}.
*
* @author Juan Rada
* @since 2.0.0
*/
@Configuration
@ConditionalOnClass(KafkaAdmin.class)
@ -55,7 +56,7 @@ public class KafkaHealthIndicatorAutoConfiguration
private final KafkaHealthIndicatorProperties properties;
KafkaHealthIndicatorAutoConfiguration(Map<String, KafkaAdmin> admins,
public KafkaHealthIndicatorAutoConfiguration(Map<String, KafkaAdmin> admins,
KafkaHealthIndicatorProperties properties) {
this.admins = admins;
this.properties = properties;

@ -62,8 +62,8 @@ class MeterRegistryConfigurer {
if (registry instanceof CompositeMeterRegistry) {
return;
}
// Customizers must be applied before binders, as they may add custom tags or
// alter timer or summary configuration.
// Customizers must be applied before binders, as they may add custom
// tags or alter timer or summary configuration.
customize(registry);
addFilters(registry);
addBinders(registry);

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -53,4 +53,5 @@ public class KafkaHealthIndicatorAutoConfigurationTests {
.doesNotHaveBean(KafkaHealthIndicator.class)
.hasSingleBean(ApplicationHealthIndicator.class));
}
}

@ -38,6 +38,7 @@ import org.springframework.util.Assert;
* {@link HealthIndicator} for Kafka cluster.
*
* @author Juan Rada
* @since 2.0.0
*/
public class KafkaHealthIndicator extends AbstractHealthIndicator {

@ -128,11 +128,10 @@ public class WebMvcMetricsFilter extends OncePerRequestFilter {
private Object getHandler(HttpServletRequest request) throws Exception {
HttpServletRequest wrapper = new UnmodifiableAttributesRequestWrapper(request);
for (HandlerMapping handlerMapping : getMappingIntrospector()
.getHandlerMappings()) {
HandlerExecutionChain chain = handlerMapping.getHandler(wrapper);
for (HandlerMapping mapping : getMappingIntrospector().getHandlerMappings()) {
HandlerExecutionChain chain = mapping.getHandler(wrapper);
if (chain != null) {
if (handlerMapping instanceof MatchableHandlerMapping) {
if (mapping instanceof MatchableHandlerMapping) {
return chain.getHandler();
}
return null;
@ -294,8 +293,8 @@ public class WebMvcMetricsFilter extends OncePerRequestFilter {
@Override
public void setAttribute(String name, Object value) {
}
}
}

@ -132,27 +132,32 @@ public class JerseyWebEndpointIntegrationTests extends
protected void doFilterInternal(HttpServletRequest request,
HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
filterChain.doFilter(new HttpServletRequestWrapper(request) {
filterChain.doFilter(new MockPrincipalWrapper(request), response);
}
@Override
public Principal getUserPrincipal() {
};
}
return new Principal() {
}
@Override
public String getName() {
return "Alice";
}
private static class MockPrincipalWrapper extends HttpServletRequestWrapper {
};
public MockPrincipalWrapper(HttpServletRequest request) {
super(request);
}
}
@Override
public Principal getUserPrincipal() {
return new MockPrincipal();
}
}, response);
}
}
};
private static class MockPrincipal implements Principal {
@Override
public String getName() {
return "Alice";
}
}

@ -152,24 +152,34 @@ public class WebFluxEndpointIntegrationTests
@Override
public Mono<Void> filter(ServerWebExchange exchange,
WebFilterChain chain) {
return chain.filter(new ServerWebExchangeDecorator(exchange) {
return chain.filter(
new MockPrincipalServerWebExchangeDecorator(exchange));
}
@Override
public Mono<Principal> getPrincipal() {
return Mono.just(new Principal() {
};
}
@Override
public String getName() {
return "Alice";
}
}
});
}
private static class MockPrincipalServerWebExchangeDecorator
extends ServerWebExchangeDecorator {
});
}
protected MockPrincipalServerWebExchangeDecorator(ServerWebExchange delegate) {
super(delegate);
}
};
@Override
public Mono<Principal> getPrincipal() {
return Mono.just(new MockPrincipal());
}
}
private static class MockPrincipal implements Principal {
@Override
public String getName() {
return "Alice";
}
}

@ -146,27 +146,32 @@ public class MvcWebEndpointIntegrationTests extends
protected void doFilterInternal(HttpServletRequest request,
HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
filterChain.doFilter(new HttpServletRequestWrapper(request) {
filterChain.doFilter(new MockPrincipalWrapper(request), response);
}
@Override
public Principal getUserPrincipal() {
};
}
return new Principal() {
}
@Override
public String getName() {
return "Alice";
}
private static class MockPrincipalWrapper extends HttpServletRequestWrapper {
};
public MockPrincipalWrapper(HttpServletRequest request) {
super(request);
}
}
@Override
public Principal getUserPrincipal() {
return new MockPrincipal();
}
}, response);
}
}
};
private static class MockPrincipal implements Principal {
@Override
public String getName() {
return "Alice";
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -6152,6 +6152,8 @@ NOTE: While Spring's test framework caches application contexts between tests an
a context for tests sharing the same configuration, the use of `@MockBean` or `@SpyBean`
influences the cache key, which will most likely increase the number of contexts.
[[boot-features-testing-spring-boot-applications-testing-autoconfigured-tests]]
==== Auto-configured Tests
Spring Boot's auto-configuration system works well for applications but can sometimes be

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -127,27 +127,25 @@ class JavaBeanBinder implements BeanBinder {
int parameterCount = method.getParameterCount();
if (name.startsWith("get") && parameterCount == 0) {
name = Introspector.decapitalize(name.substring(3));
this.properties
.computeIfAbsent(name,
(n) -> new BeanProperty(n, this.resolvableType))
this.properties.computeIfAbsent(name, this::getBeanProperty)
.addGetter(method);
}
else if (name.startsWith("is") && parameterCount == 0) {
name = Introspector.decapitalize(name.substring(2));
this.properties
.computeIfAbsent(name,
(n) -> new BeanProperty(n, this.resolvableType))
this.properties.computeIfAbsent(name, this::getBeanProperty)
.addGetter(method);
}
else if (name.startsWith("set") && parameterCount == 1) {
name = Introspector.decapitalize(name.substring(3));
this.properties
.computeIfAbsent(name,
(n) -> new BeanProperty(n, this.resolvableType))
this.properties.computeIfAbsent(name, this::getBeanProperty)
.addSetter(method);
}
}
private BeanProperty getBeanProperty(String name) {
return new BeanProperty(name, this.resolvableType);
}
private void addField(Field field) {
BeanProperty property = this.properties.get(field.getName());
if (property != null) {

@ -107,8 +107,7 @@ public class ApplicationHome {
try {
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
for (int i = stackTrace.length - 1; i >= 0; i--) {
StackTraceElement element = stackTrace[i];
if (element.getClassName().startsWith("org.junit.")) {
if (stackTrace[i].getClassName().startsWith("org.junit.")) {
return true;
}
}

@ -370,6 +370,7 @@ public class BinderTests {
public void setBar(T bar) {
this.bar = bar;
}
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<!-- Your own application should inherit from spring-boot-starter-parent -->
@ -11,11 +11,9 @@
<artifactId>spring-boot-sample-kafka</artifactId>
<name>Spring Boot Kafka Sample</name>
<description>Spring Boot Kafka Sample</description>
<properties>
<main.basedir>${basedir}/../..</main.basedir>
</properties>
<dependencies>
<!-- Compile -->
<dependency>
@ -38,7 +36,6 @@
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package sample.kafka;
import org.springframework.kafka.annotation.KafkaListener;
@ -26,4 +27,4 @@ class Consumer {
System.out.println("Received sample message [" + message + "]");
}
}
}

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package sample.kafka;
import org.springframework.kafka.core.KafkaTemplate;
@ -32,4 +33,4 @@ public class Producer {
System.out.println("Sent sample message [" + message + "]");
}
}
}

@ -13,12 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package sample.kafka;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.Bean;
@SpringBootApplication

@ -41,11 +41,7 @@ public class SampleMessage {
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("SampleMessage{");
sb.append("id=").append(this.id);
sb.append(", message='").append(this.message).append('\'');
sb.append('}');
return sb.toString();
return "SampleMessage{id=" + this.id + ", message='" + this.message + "'}";
}
}

@ -22,7 +22,6 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.test.rule.OutputCapture;
@ -64,11 +63,13 @@ public class SampleKafkaApplicationTests {
@Bean
public Consumer consumer() {
return new Consumer() {
@Override
public void processMessage(SampleMessage message) {
super.processMessage(message);
latch.countDown();
}
};
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

Loading…
Cancel
Save