Should be working
This commit is contained in:
@@ -31,8 +31,8 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
|
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
|
||||
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
|
||||
import org.springframework.boot.web.servlet.context.ServletWebServerInitializedEvent;
|
||||
import org.springframework.cloud.sleuth.Sampler;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
@@ -57,7 +57,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@RestController
|
||||
@EnableAsync
|
||||
public class SleuthBenchmarkingSpringApp implements
|
||||
ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
ApplicationListener<ServletWebServerInitializedEvent> {
|
||||
|
||||
private static final Log log = LogFactory.getLog(SleuthBenchmarkingSpringApp.class);
|
||||
|
||||
@@ -97,8 +97,8 @@ public class SleuthBenchmarkingSpringApp implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(EmbeddedServletContainerInitializedEvent event) {
|
||||
this.port = event.getEmbeddedServletContainer().getPort();
|
||||
public void onApplicationEvent(ServletWebServerInitializedEvent event) {
|
||||
this.port = event.getSource().getPort();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -16,12 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.sleuth.instrument.web;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
import java.util.Vector;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -30,6 +24,13 @@ import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Random;
|
||||
import java.util.Vector;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.springframework.cloud.sleuth.assertions.SleuthAssertions.then;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@@ -43,6 +44,9 @@ public class HttpServletRequestExtractorTests {
|
||||
public void setup() {
|
||||
BDDMockito.given(this.request.getRequestURI()).willReturn("http://foo.com");
|
||||
BDDMockito.given(this.request.getContextPath()).willReturn("/");
|
||||
BDDMockito.given(this.request.getHeaderNames())
|
||||
.willReturn(new Vector<>(Arrays.asList("invalid", Span.TRACE_ID_NAME,
|
||||
Span.SPAN_ID_NAME, Span.PARENT_ID_NAME)).elements());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -52,6 +56,8 @@ public class HttpServletRequestExtractorTests {
|
||||
|
||||
@Test
|
||||
public void should_set_random_traceid_if_header_value_is_invalid() {
|
||||
BDDMockito.given(this.request.getHeaderNames())
|
||||
.willReturn(new Vector<>(Collections.singletonList(Span.TRACE_ID_NAME)).elements());
|
||||
BDDMockito.given(this.request.getHeader(Span.TRACE_ID_NAME))
|
||||
.willReturn("invalid");
|
||||
|
||||
@@ -60,6 +66,9 @@ public class HttpServletRequestExtractorTests {
|
||||
|
||||
@Test
|
||||
public void should_set_random_spanid_if_header_value_is_invalid() {
|
||||
BDDMockito.given(this.request.getHeaderNames())
|
||||
.willReturn(new Vector<>(Arrays.asList(Span.TRACE_ID_NAME,
|
||||
Span.SPAN_ID_NAME)).elements());
|
||||
BDDMockito.given(this.request.getHeader(Span.TRACE_ID_NAME))
|
||||
.willReturn(String.valueOf(new Random().nextLong()));
|
||||
BDDMockito.given(this.request.getHeader(Span.SPAN_ID_NAME))
|
||||
@@ -70,6 +79,9 @@ public class HttpServletRequestExtractorTests {
|
||||
|
||||
@Test
|
||||
public void should_not_throw_exception_if_parent_id_is_invalid() {
|
||||
BDDMockito.given(this.request.getHeaderNames())
|
||||
.willReturn(new Vector<>(Arrays.asList(Span.TRACE_ID_NAME,
|
||||
Span.SPAN_ID_NAME, Span.PARENT_ID_NAME)).elements());
|
||||
BDDMockito.given(this.request.getHeader(Span.TRACE_ID_NAME))
|
||||
.willReturn(String.valueOf(new Random().nextLong()));
|
||||
BDDMockito.given(this.request.getHeader(Span.SPAN_ID_NAME))
|
||||
|
||||
@@ -16,18 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.sleuth.instrument.web;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
import static org.springframework.cloud.sleuth.assertions.SleuthAssertions.then;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import com.jayway.awaitility.Awaitility;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -44,18 +33,25 @@ import org.springframework.cloud.sleuth.util.ArrayListSpanAccumulator;
|
||||
import org.springframework.cloud.sleuth.util.ExceptionUtils;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
|
||||
import org.springframework.hateoas.Resources;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.hateoas.PagedResources;
|
||||
import org.springframework.http.RequestEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import com.jayway.awaitility.Awaitility;
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import java.net.URI;
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
import static org.springframework.cloud.sleuth.assertions.SleuthAssertions.then;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
@@ -81,9 +77,9 @@ public class SpringDataInstrumentationTests {
|
||||
|
||||
@Test
|
||||
public void should_create_span_instrumented_by_a_handler_interceptor() {
|
||||
Collection<String> names = names();
|
||||
long noOfNames = namesCount();
|
||||
|
||||
then(names).isNotEmpty();
|
||||
then(noOfNames).isEqualTo(8);
|
||||
then(this.arrayListSpanAccumulator.getSpans()).isNotEmpty();
|
||||
Awaitility.await().until(() -> {
|
||||
then(new ListOfSpans(this.arrayListSpanAccumulator.getSpans()))
|
||||
@@ -95,14 +91,11 @@ public class SpringDataInstrumentationTests {
|
||||
then(new ListOfSpans(this.arrayListSpanAccumulator.getSpans())).hasRpcTagsInProperOrder();
|
||||
}
|
||||
|
||||
Collection<String> names() {
|
||||
ParameterizedTypeReference<Resources<Reservation>> ptr = new ParameterizedTypeReference<Resources<Reservation>>() {
|
||||
};
|
||||
ResponseEntity<Resources<Reservation>> responseEntity = this.restTemplate
|
||||
.exchange("http://localhost:" + port() + "/reservations", HttpMethod.GET,
|
||||
null, ptr);
|
||||
return responseEntity.getBody().getContent().stream()
|
||||
.map(Reservation::getReservationName).collect(Collectors.toList());
|
||||
long namesCount() {
|
||||
return
|
||||
this.restTemplate.exchange(RequestEntity
|
||||
.get(URI.create("http://localhost:" + port() + "/reservations")).build(), PagedResources.class)
|
||||
.getBody().getMetadata().getTotalElements();
|
||||
}
|
||||
|
||||
private int port() {
|
||||
@@ -134,13 +127,13 @@ class ReservationServiceApplication {
|
||||
Sampler alwaysSampler() {
|
||||
return new AlwaysSampler();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class SampleRecords {
|
||||
|
||||
private final ReservationRepository reservationRepository;
|
||||
|
||||
@Autowired
|
||||
public SampleRecords(ReservationRepository reservationRepository) {
|
||||
this.reservationRepository = reservationRepository;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.springframework.cloud.sleuth.instrument.web.client.feign;
|
||||
|
||||
import org.junit.Before;
|
||||
import feign.Client;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
@@ -9,10 +9,7 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
|
||||
import feign.Client;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -25,11 +22,6 @@ public class TraceFeignObjectWrapperTests {
|
||||
@Mock BeanFactory beanFactory;
|
||||
@InjectMocks TraceFeignObjectWrapper traceFeignObjectWrapper;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
given(this.beanFactory.getBean(Tracer.class)).willReturn(this.tracer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_wrap_a_client_into_trace_client() throws Exception {
|
||||
then(this.traceFeignObjectWrapper.wrap(mock(Client.class))).isExactlyInstanceOf(TraceFeignClient.class);
|
||||
|
||||
@@ -16,15 +16,13 @@
|
||||
|
||||
package org.springframework.cloud.sleuth.instrument.zuul;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.netflix.zuul.context.RequestContext;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
|
||||
import org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandContext;
|
||||
import org.springframework.cloud.netflix.zuul.filters.route.RibbonCommandFactory;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
@@ -35,12 +33,9 @@ import org.springframework.cloud.sleuth.trace.TestSpanContextHolder;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
|
||||
import com.netflix.niws.client.http.RestClient;
|
||||
import com.netflix.zuul.context.RequestContext;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.springframework.cloud.sleuth.assertions.SleuthAssertions.then;
|
||||
|
||||
/**
|
||||
@@ -50,7 +45,6 @@ import static org.springframework.cloud.sleuth.assertions.SleuthAssertions.then;
|
||||
public class TraceRibbonCommandFactoryTest {
|
||||
|
||||
@Mock Tracer tracer;
|
||||
@Mock SpringClientFactory springClientFactory;
|
||||
HttpTraceKeysInjector httpTraceKeysInjector;
|
||||
@Mock RibbonCommandFactory ribbonCommandFactory;
|
||||
TraceRibbonCommandFactory traceRibbonCommandFactory;
|
||||
@@ -64,10 +58,7 @@ public class TraceRibbonCommandFactoryTest {
|
||||
this.traceRibbonCommandFactory = new TraceRibbonCommandFactory(
|
||||
this.ribbonCommandFactory, this.tracer,
|
||||
httpTraceKeysInjector);
|
||||
given(this.springClientFactory.getClient(anyString(), any(Class.class)))
|
||||
.willReturn(new RestClient());
|
||||
given(this.tracer.getCurrentSpan()).willReturn(span);
|
||||
given(this.tracer.isTracing()).willReturn(true);
|
||||
}
|
||||
|
||||
@After
|
||||
|
||||
@@ -19,7 +19,7 @@ package sample;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
|
||||
import org.springframework.boot.web.servlet.context.ServletWebServerInitializedEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.integration.annotation.MessageEndpoint;
|
||||
import org.springframework.integration.annotation.ServiceActivator;
|
||||
@@ -31,7 +31,7 @@ import org.springframework.web.client.RestTemplate;
|
||||
*
|
||||
*/
|
||||
@MessageEndpoint public class SampleService implements
|
||||
ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
ApplicationListener<ServletWebServerInitializedEvent> {
|
||||
private static final Log log = LogFactory.getLog(SampleService.class);
|
||||
|
||||
@Autowired private RestTemplate restTemplate;
|
||||
@@ -43,8 +43,7 @@ import org.springframework.web.client.RestTemplate;
|
||||
this.restTemplate.getForObject("http://localhost:" + this.port + "/foo", String.class);
|
||||
}
|
||||
|
||||
@Override public void onApplicationEvent(
|
||||
EmbeddedServletContainerInitializedEvent event) {
|
||||
this.port = event.getEmbeddedServletContainer().getPort();
|
||||
@Override public void onApplicationEvent(ServletWebServerInitializedEvent event) {
|
||||
this.port = event.getSource().getPort();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,13 +16,10 @@
|
||||
|
||||
package sample;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
|
||||
import org.springframework.boot.web.servlet.context.ServletWebServerInitializedEvent;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanAccessor;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
@@ -32,12 +29,15 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@RestController
|
||||
public class SampleController
|
||||
implements ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
implements ApplicationListener<ServletWebServerInitializedEvent> {
|
||||
private static final Log log = LogFactory.getLog(SampleController.class);
|
||||
|
||||
@Autowired
|
||||
@@ -118,7 +118,7 @@ public class SampleController
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(EmbeddedServletContainerInitializedEvent event) {
|
||||
this.port = event.getEmbeddedServletContainer().getPort();
|
||||
public void onApplicationEvent(ServletWebServerInitializedEvent event) {
|
||||
this.port = event.getSource().getPort();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,33 +15,23 @@
|
||||
*/
|
||||
package tools;
|
||||
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.jayway.awaitility.Awaitility;
|
||||
import com.jayway.awaitility.core.ConditionFactory;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.springframework.cloud.sleuth.trace.IntegrationTestSpanContextHolder;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.RequestEntity;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import zipkin.Codec;
|
||||
import zipkin.Span;
|
||||
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.net.URI;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
@@ -71,15 +61,15 @@ public abstract class AbstractIntegrationTest {
|
||||
}
|
||||
|
||||
protected Runnable zipkinServerIsUp() {
|
||||
return checkServerHealth("Zipkin Stream Server", this::endpointToCheckZipkinServerHealth);
|
||||
return checkServerHealth(this::endpointToCheckZipkinServerHealth);
|
||||
}
|
||||
|
||||
protected Runnable checkServerHealth(String appName, RequestExchanger requestExchanger) {
|
||||
protected Runnable checkServerHealth(RequestExchanger requestExchanger) {
|
||||
return () -> {
|
||||
ResponseEntity<String> response = requestExchanger.exchange();
|
||||
log.info(String.format("Response from the [%s] health endpoint is [%s]", appName, response));
|
||||
log.info(String.format("Response from the [%s] health endpoint is [%s]", "Zipkin Stream Server", response));
|
||||
then(response.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
log.info(String.format("[%s] is up!", appName));
|
||||
log.info(String.format("[%s] is up!", "Zipkin Stream Server"));
|
||||
};
|
||||
}
|
||||
|
||||
@@ -88,7 +78,7 @@ public abstract class AbstractIntegrationTest {
|
||||
}
|
||||
|
||||
protected ResponseEntity<String> endpointToCheckZipkinServerHealth() {
|
||||
URI uri = URI.create("http://localhost:" +getZipkinServerPort()+"/health");
|
||||
URI uri = URI.create("http://localhost:" +getZipkinServerPort()+"/application/health");
|
||||
log.info(String.format("Sending request to the Zipkin Server [%s]", uri));
|
||||
return exchangeRequest(uri);
|
||||
}
|
||||
|
||||
@@ -16,13 +16,10 @@
|
||||
|
||||
package sample;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
|
||||
import org.springframework.boot.web.servlet.context.ServletWebServerInitializedEvent;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanAccessor;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
@@ -32,12 +29,15 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@RestController
|
||||
public class SampleController implements
|
||||
ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
ApplicationListener<ServletWebServerInitializedEvent> {
|
||||
|
||||
private static final Log log = LogFactory.getLog(SampleController.class);
|
||||
|
||||
@@ -120,7 +120,7 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(EmbeddedServletContainerInitializedEvent event) {
|
||||
this.port = event.getEmbeddedServletContainer().getPort();
|
||||
public void onApplicationEvent(ServletWebServerInitializedEvent event) {
|
||||
this.port = event.getSource().getPort();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ spring:
|
||||
application:
|
||||
# This ends up as the service name in zipkin
|
||||
name: testsleuthzipkin
|
||||
zipkin:
|
||||
#zipkin:
|
||||
# Uncomment to send to zipkin, replacing 192.168.99.100 with your zipkin IP address
|
||||
# baseUrl: http://192.168.99.100:9411/
|
||||
sleuth:
|
||||
|
||||
@@ -16,13 +16,10 @@
|
||||
|
||||
package sample;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
|
||||
import org.springframework.boot.web.servlet.context.ServletWebServerInitializedEvent;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanAccessor;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
@@ -32,12 +29,15 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@RestController
|
||||
public class SampleController
|
||||
implements ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
implements ApplicationListener<ServletWebServerInitializedEvent > {
|
||||
private static final Log log = LogFactory.getLog(SampleController.class);
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
@@ -117,7 +117,7 @@ public class SampleController
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(EmbeddedServletContainerInitializedEvent event) {
|
||||
this.port = event.getEmbeddedServletContainer().getPort();
|
||||
public void onApplicationEvent(ServletWebServerInitializedEvent event) {
|
||||
this.port = event.getSource().getPort();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,12 +16,10 @@
|
||||
|
||||
package org.springframework.cloud.sleuth.stream;
|
||||
|
||||
import java.lang.invoke.MethodHandles;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
|
||||
import org.springframework.boot.web.servlet.context.ServletWebServerInitializedEvent;
|
||||
import org.springframework.cloud.commons.util.InetUtils;
|
||||
import org.springframework.cloud.commons.util.InetUtilsProperties;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
@@ -29,6 +27,8 @@ import org.springframework.context.event.EventListener;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.lang.invoke.MethodHandles;
|
||||
|
||||
/**
|
||||
* A {@link HostLocator} that retrieves:
|
||||
*
|
||||
@@ -79,9 +79,9 @@ public class ServerPropertiesHostLocator implements HostLocator {
|
||||
return new Host(serviceName, address, port);
|
||||
}
|
||||
|
||||
@EventListener(EmbeddedServletContainerInitializedEvent.class)
|
||||
public void grabPort(EmbeddedServletContainerInitializedEvent event) {
|
||||
this.port = event.getEmbeddedServletContainer().getPort();
|
||||
@EventListener(ServletWebServerInitializedEvent.class)
|
||||
public void onApplicationEvent(ServletWebServerInitializedEvent event) {
|
||||
this.port = event.getSource().getPort();
|
||||
}
|
||||
|
||||
private Integer getPort() {
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
package org.springframework.cloud.sleuth.stream;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.cloud.commons.util.UtilAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.test.util.EnvironmentTestUtils;
|
||||
import org.springframework.cloud.commons.util.UtilAutoConfiguration;
|
||||
import org.springframework.cloud.sleuth.autoconfig.TraceAutoConfiguration;
|
||||
import org.springframework.cloud.sleuth.log.NoOpSpanLogger;
|
||||
import org.springframework.cloud.sleuth.log.SpanLogger;
|
||||
@@ -27,6 +22,11 @@ import org.springframework.scheduling.TriggerContext;
|
||||
import org.springframework.scheduling.support.PeriodicTrigger;
|
||||
import org.springframework.scheduling.support.SimpleTriggerContext;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class SleuthStreamAutoConfigurationTest {
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.metrics.CounterService;
|
||||
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
import org.springframework.cloud.commons.util.UtilAutoConfiguration;
|
||||
|
||||
@@ -16,19 +16,18 @@
|
||||
|
||||
package org.springframework.cloud.sleuth.zipkin;
|
||||
|
||||
import zipkin.Endpoint;
|
||||
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
|
||||
import org.springframework.boot.web.servlet.context.ServletWebServerInitializedEvent;
|
||||
import org.springframework.cloud.commons.util.InetUtils;
|
||||
import org.springframework.cloud.commons.util.InetUtilsProperties;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.util.StringUtils;
|
||||
import zipkin.Endpoint;
|
||||
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* {@link EndpointLocator} implementation that:
|
||||
@@ -84,9 +83,9 @@ public class ServerPropertiesEndpointLocator implements EndpointLocator {
|
||||
.build();
|
||||
}
|
||||
|
||||
@EventListener(EmbeddedServletContainerInitializedEvent.class)
|
||||
public void grabPort(EmbeddedServletContainerInitializedEvent event) {
|
||||
this.port = event.getEmbeddedServletContainer().getPort();
|
||||
@EventListener(ServletWebServerInitializedEvent.class)
|
||||
public void onApplicationEvent(ServletWebServerInitializedEvent event) {
|
||||
this.port = event.getSource().getPort();
|
||||
}
|
||||
|
||||
private Integer getPort() {
|
||||
|
||||
@@ -44,7 +44,6 @@ public class FallbackHavingEndpointLocatorTests {
|
||||
@Test
|
||||
public void should_use_discovery_client_locator_by_default() {
|
||||
given(this.discoveryClientEndpointLocator.local()).willReturn(this.expectedEndpoint);
|
||||
given(this.serverPropertiesEndpointLocator.local()).willThrow(new RuntimeException());
|
||||
FallbackHavingEndpointLocator sut = new FallbackHavingEndpointLocator(this.discoveryClientEndpointLocator,
|
||||
this.serverPropertiesEndpointLocator);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user