Delomboking
This commit is contained in:
@@ -76,10 +76,6 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.kristofa</groupId>
|
||||
<artifactId>brave-core</artifactId>
|
||||
|
||||
@@ -16,14 +16,13 @@
|
||||
|
||||
package sample;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import java.util.Random;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@@ -35,9 +34,8 @@ public class SampleBackground {
|
||||
@Autowired
|
||||
private Random random;
|
||||
|
||||
@SneakyThrows
|
||||
@Async
|
||||
public void background() {
|
||||
public void background() throws InterruptedException {
|
||||
int millis = this.random.nextInt(1000);
|
||||
Thread.sleep(millis);
|
||||
this.tracer.addTag("background-sleep-millis", String.valueOf(millis));
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
package sample;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
@@ -30,10 +29,11 @@ import org.springframework.web.client.RestTemplate;
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
@MessageEndpoint
|
||||
@Slf4j
|
||||
public class SampleService implements
|
||||
@MessageEndpoint public class SampleService implements
|
||||
ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
private static final Logger log = org.slf4j.LoggerFactory
|
||||
.getLogger(SampleService.class);
|
||||
|
||||
@Autowired private RestTemplate restTemplate;
|
||||
private int port;
|
||||
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
package sample;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.integration.annotation.MessageEndpoint;
|
||||
import org.springframework.integration.annotation.ServiceActivator;
|
||||
@@ -28,14 +27,16 @@ import org.springframework.messaging.Message;
|
||||
*
|
||||
*/
|
||||
@MessageEndpoint
|
||||
@Slf4j
|
||||
public class SampleTransformer {
|
||||
|
||||
private static final Logger log = org.slf4j.LoggerFactory
|
||||
.getLogger(SampleTransformer.class);
|
||||
|
||||
@Autowired
|
||||
SampleBackground background;
|
||||
|
||||
@ServiceActivator(inputChannel="xform")
|
||||
public String log(Message<?> message) {
|
||||
public String log(Message<?> message) throws InterruptedException {
|
||||
log.info("Received: " + message);
|
||||
this.background.background();
|
||||
return message.getPayload().toString().toUpperCase();
|
||||
|
||||
@@ -15,22 +15,25 @@
|
||||
*/
|
||||
package integration;
|
||||
|
||||
import lombok.extern.apachecommons.CommonsLog;
|
||||
import org.springframework.cloud.sleuth.zipkin.ZipkinSpanReporter;
|
||||
import zipkin.Span;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.springframework.cloud.sleuth.zipkin.ZipkinSpanReporter;
|
||||
|
||||
import zipkin.Span;
|
||||
|
||||
/**
|
||||
* Span Collector that logs spans and adds Spans to a list
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@CommonsLog
|
||||
public class IntegrationTestZipkinSpanReporter implements ZipkinSpanReporter {
|
||||
|
||||
private static final Log log = org.apache.commons.logging.LogFactory
|
||||
.getLog(IntegrationTestZipkinSpanReporter.class);
|
||||
|
||||
public List<Span> hashedSpans = Collections.synchronizedList(new LinkedList<>());
|
||||
|
||||
@Override
|
||||
|
||||
@@ -60,10 +60,6 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
|
||||
@@ -16,14 +16,13 @@
|
||||
|
||||
package sample;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import java.util.Random;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
* @author Dave Syer
|
||||
@@ -36,15 +35,13 @@ public class SampleController {
|
||||
@Autowired
|
||||
private Random random;
|
||||
|
||||
@SneakyThrows
|
||||
@RequestMapping("/")
|
||||
public String hi() {
|
||||
public String hi() throws InterruptedException {
|
||||
Thread.sleep(this.random.nextInt(1000));
|
||||
String s = this.restTemplate.getForObject("http://zipkin/hi2", String.class);
|
||||
return "hi/" + s;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@RequestMapping("/call")
|
||||
public String traced() {
|
||||
String s = this.restTemplate.getForObject("http://zipkin/call", String.class);
|
||||
|
||||
@@ -64,10 +64,6 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
|
||||
@@ -18,8 +18,6 @@ package sample;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
@@ -34,9 +32,8 @@ public class SampleBackground {
|
||||
@Autowired
|
||||
private Tracer tracer;
|
||||
|
||||
@SneakyThrows
|
||||
@Async
|
||||
public void background() {
|
||||
public void background() throws InterruptedException {
|
||||
final Random random = new Random();
|
||||
int millis = random.nextInt(1000);
|
||||
Thread.sleep(millis);
|
||||
|
||||
@@ -19,8 +19,7 @@ package sample;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
@@ -36,10 +35,12 @@ import org.springframework.web.client.RestTemplate;
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
public class SampleController implements
|
||||
ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
private static final Logger log = org.slf4j.LoggerFactory
|
||||
.getLogger(SampleController.class);
|
||||
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
@Autowired
|
||||
@@ -52,9 +53,8 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
private Random random;
|
||||
private int port;
|
||||
|
||||
@SneakyThrows
|
||||
@RequestMapping("/")
|
||||
public String hi() {
|
||||
public String hi() throws InterruptedException {
|
||||
Thread.sleep(this.random.nextInt(1000));
|
||||
|
||||
String s = this.restTemplate.getForObject("http://localhost:" + this.port
|
||||
@@ -77,23 +77,21 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
}
|
||||
|
||||
@RequestMapping("/async")
|
||||
public String async() {
|
||||
public String async() throws InterruptedException {
|
||||
this.controller.background();
|
||||
return "ho";
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@RequestMapping("/hi2")
|
||||
public String hi2() {
|
||||
public String hi2() throws InterruptedException {
|
||||
int millis = this.random.nextInt(1000);
|
||||
Thread.sleep(millis);
|
||||
this.tracer.addTag("random-sleep-millis", String.valueOf(millis));
|
||||
return "hi2";
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@RequestMapping("/traced")
|
||||
public String traced() {
|
||||
public String traced() throws InterruptedException {
|
||||
Span span = this.tracer.startTrace(new SpanName("http", "customTraceEndpoint"),
|
||||
new AlwaysSampler());
|
||||
int millis = this.random.nextInt(1000);
|
||||
@@ -107,9 +105,8 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
return "traced/" + s;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@RequestMapping("/start")
|
||||
public String start() {
|
||||
public String start() throws InterruptedException {
|
||||
int millis = this.random.nextInt(1000);
|
||||
log.info("Sleeping for {} millis", millis);
|
||||
Thread.sleep(millis);
|
||||
|
||||
@@ -67,10 +67,6 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
*/
|
||||
package tools;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -28,6 +25,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.cloud.sleuth.trace.IntegrationTestSpanContextHolder;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
@@ -39,16 +37,20 @@ import org.springframework.web.client.RestTemplate;
|
||||
import com.jayway.awaitility.Awaitility;
|
||||
import com.jayway.awaitility.core.ConditionFactory;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import zipkin.Codec;
|
||||
import zipkin.Span;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class AbstractIntegrationTest {
|
||||
|
||||
private static final Logger log = org.slf4j.LoggerFactory
|
||||
.getLogger(AbstractIntegrationTest.class);
|
||||
|
||||
protected static int pollInterval = 1;
|
||||
protected static int timeout = 20;
|
||||
protected RestTemplate restTemplate = new AssertingRestTemplate();
|
||||
|
||||
@@ -15,23 +15,29 @@
|
||||
*/
|
||||
package tools;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.client.ClientHttpResponse;
|
||||
import org.springframework.web.client.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.client.ClientHttpResponse;
|
||||
import org.springframework.web.client.DefaultResponseErrorHandler;
|
||||
import org.springframework.web.client.RequestCallback;
|
||||
import org.springframework.web.client.ResponseExtractor;
|
||||
import org.springframework.web.client.RestClientException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
/**
|
||||
*
|
||||
* RestTemplate that logs erroneous responses and throws AssertionsError on any connection issues
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@Slf4j
|
||||
public class AssertingRestTemplate extends RestTemplate {
|
||||
|
||||
private static final Logger log = org.slf4j.LoggerFactory
|
||||
.getLogger(AssertingRestTemplate.class);
|
||||
|
||||
public AssertingRestTemplate() {
|
||||
setErrorHandler(new DefaultResponseErrorHandler() {
|
||||
@Override
|
||||
|
||||
@@ -15,11 +15,10 @@
|
||||
*/
|
||||
package tools;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Random;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
@@ -28,7 +27,7 @@ import org.springframework.http.RequestEntity;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
/**
|
||||
* Runnable that will send a request via the provide rest template to the
|
||||
@@ -36,8 +35,11 @@ import lombok.extern.slf4j.Slf4j;
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@Slf4j
|
||||
public class RequestSendingRunnable implements Runnable {
|
||||
|
||||
private static final Logger log = org.slf4j.LoggerFactory
|
||||
.getLogger(RequestSendingRunnable.class);
|
||||
|
||||
private final RestTemplate restTemplate;
|
||||
private final String url;
|
||||
private final long traceId;
|
||||
|
||||
@@ -54,12 +54,6 @@
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-stream-test-support</artifactId>
|
||||
|
||||
@@ -67,10 +67,6 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
|
||||
@@ -16,14 +16,13 @@
|
||||
|
||||
package sample;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import java.util.Random;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@@ -35,9 +34,8 @@ public class SampleBackground {
|
||||
@Autowired
|
||||
private Random random;
|
||||
|
||||
@SneakyThrows
|
||||
@Async
|
||||
public void background() {
|
||||
public void background() throws InterruptedException {
|
||||
int millis = this.random.nextInt(1000);
|
||||
Thread.sleep(millis);
|
||||
this.tracer.addTag("background-sleep-millis", String.valueOf(millis));
|
||||
|
||||
@@ -19,6 +19,7 @@ package sample;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
@@ -31,16 +32,16 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
public class SampleController implements
|
||||
ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
|
||||
private static final Logger log = org.slf4j.LoggerFactory
|
||||
.getLogger(SampleController.class);
|
||||
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
@Autowired
|
||||
@@ -53,9 +54,8 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
private Random random;
|
||||
private int port;
|
||||
|
||||
@SneakyThrows
|
||||
@RequestMapping("/")
|
||||
public String hi() {
|
||||
public String hi() throws InterruptedException {
|
||||
Thread.sleep(this.random.nextInt(1000));
|
||||
log.info("Home page");
|
||||
String s = this.restTemplate.getForObject("http://localhost:" + this.port
|
||||
@@ -78,15 +78,14 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
}
|
||||
|
||||
@RequestMapping("/async")
|
||||
public String async() {
|
||||
public String async() throws InterruptedException {
|
||||
log.info("async");
|
||||
this.controller.background();
|
||||
return "ho";
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@RequestMapping("/hi2")
|
||||
public String hi2() {
|
||||
public String hi2() throws InterruptedException {
|
||||
log.info("hi2");
|
||||
int millis = this.random.nextInt(1000);
|
||||
Thread.sleep(millis);
|
||||
@@ -94,9 +93,8 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
return "hi2";
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@RequestMapping("/traced")
|
||||
public String traced() {
|
||||
public String traced() throws InterruptedException {
|
||||
Span span = this.tracer.startTrace(new SpanName("http", "customTraceEndpoint"),
|
||||
new AlwaysSampler());
|
||||
int millis = this.random.nextInt(1000);
|
||||
@@ -110,9 +108,8 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
return "traced/" + s;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@RequestMapping("/start")
|
||||
public String start() {
|
||||
public String start() throws InterruptedException {
|
||||
int millis = this.random.nextInt(1000);
|
||||
log.info("Sleeping for {} millis", millis);
|
||||
Thread.sleep(millis);
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package sample;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
@@ -24,17 +25,17 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableAspectJAutoProxy(proxyTargetClass = true)
|
||||
@EnableAsync
|
||||
@Slf4j
|
||||
public class SampleZipkinApplication {
|
||||
|
||||
private static final Logger log = org.slf4j.LoggerFactory
|
||||
.getLogger(SampleZipkinApplication.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SampleZipkinApplication.class, args);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.util.Random;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
@@ -33,8 +34,6 @@ import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import integration.ZipkinTests.WaitUntilZipkinIsUpConfig;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import sample.SampleZipkinApplication;
|
||||
import tools.AbstractIntegrationTest;
|
||||
import zipkin.server.ZipkinServer;
|
||||
@@ -73,10 +72,12 @@ public class ZipkinTests extends AbstractIntegrationTest {
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public static class WaitUntilZipkinIsUpConfig {
|
||||
|
||||
private static final Logger log = org.slf4j.LoggerFactory
|
||||
.getLogger(WaitUntilZipkinIsUpConfig.class);
|
||||
|
||||
@Bean
|
||||
@SneakyThrows
|
||||
public ZipkinSpanReporter spanCollector(final ZipkinProperties zipkin,
|
||||
final SpanReporterService spanReporterService) {
|
||||
await().until(new Runnable() {
|
||||
|
||||
@@ -52,10 +52,6 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
|
||||
@@ -16,14 +16,13 @@
|
||||
|
||||
package sample;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import java.util.Random;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@@ -35,9 +34,8 @@ public class SampleBackground {
|
||||
@Autowired
|
||||
private Random random;
|
||||
|
||||
@SneakyThrows
|
||||
@Async
|
||||
public void background() {
|
||||
public void background() throws InterruptedException {
|
||||
int millis = this.random.nextInt(1000);
|
||||
Thread.sleep(millis);
|
||||
this.tracer.addTag("background-sleep-millis", String.valueOf(millis));
|
||||
|
||||
@@ -19,8 +19,7 @@ package sample;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
@@ -36,10 +35,11 @@ import org.springframework.web.client.RestTemplate;
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
public class SampleController implements
|
||||
ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
private static final Logger log = org.slf4j.LoggerFactory
|
||||
.getLogger(SampleController.class);
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
@Autowired
|
||||
@@ -52,9 +52,8 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
private Random random;
|
||||
private int port;
|
||||
|
||||
@SneakyThrows
|
||||
@RequestMapping("/")
|
||||
public String hi() {
|
||||
public String hi() throws InterruptedException {
|
||||
Thread.sleep(this.random.nextInt(1000));
|
||||
|
||||
String s = this.restTemplate.getForObject("http://localhost:" + this.port
|
||||
@@ -77,23 +76,21 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
}
|
||||
|
||||
@RequestMapping("/async")
|
||||
public String async() {
|
||||
public String async() throws InterruptedException {
|
||||
this.controller.background();
|
||||
return "ho";
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@RequestMapping("/hi2")
|
||||
public String hi2() {
|
||||
public String hi2() throws InterruptedException {
|
||||
int millis = this.random.nextInt(1000);
|
||||
Thread.sleep(millis);
|
||||
this.tracer.addTag("random-sleep-millis", String.valueOf(millis));
|
||||
return "hi2";
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@RequestMapping("/traced")
|
||||
public String traced() {
|
||||
public String traced() throws InterruptedException {
|
||||
Span span = this.tracer.startTrace(new SpanName("http", "customTraceEndpoint"),
|
||||
new AlwaysSampler());
|
||||
int millis = this.random.nextInt(1000);
|
||||
@@ -107,9 +104,8 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
return "traced/" + s;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@RequestMapping("/start")
|
||||
public String start() {
|
||||
public String start() throws InterruptedException {
|
||||
int millis = this.random.nextInt(1000);
|
||||
log.info("Sleeping for {} millis", millis);
|
||||
Thread.sleep(millis);
|
||||
|
||||
Reference in New Issue
Block a user