WIP
This commit is contained in:
6
pom.xml
6
pom.xml
@@ -217,12 +217,6 @@
|
||||
<version>3.0.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.tomakehurst</groupId>
|
||||
<artifactId>wiremock</artifactId>
|
||||
<version>2.6.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>pl.pragmatists</groupId>
|
||||
<artifactId>JUnitParams</artifactId>
|
||||
|
||||
@@ -17,7 +17,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.test.util.EnvironmentTestUtils;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.springframework.cloud.sleuth.stream;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
@@ -8,9 +10,9 @@ import java.util.Date;
|
||||
import org.junit.After;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.autoconfigure.context.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,8 +29,6 @@ import org.springframework.scheduling.TriggerContext;
|
||||
import org.springframework.scheduling.support.PeriodicTrigger;
|
||||
import org.springframework.scheduling.support.SimpleTriggerContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class SleuthStreamAutoConfigurationTest {
|
||||
|
||||
private AnnotationConfigApplicationContext ctx;
|
||||
|
||||
@@ -88,6 +88,11 @@
|
||||
<artifactId>zipkin-junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.awaitility</groupId>
|
||||
<artifactId>awaitility</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- otherwise spring boot's version of okhttp kicks zipkin-junit's deps out of alignment -->
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
package org.springframework.cloud.sleuth.zipkin;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
class ZipkinDiscoveryClientTests {
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package org.springframework.cloud.sleuth.zipkin;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
import static org.springframework.cloud.sleuth.zipkin.ZipkinDiscoveryClientTests.ZIPKIN_RULE;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.assertj.core.api.BDDAssertions;
|
||||
import org.awaitility.Awaitility;
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanReporter;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.util.SocketUtils;
|
||||
|
||||
import zipkin.junit.ZipkinRule;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = ZipkinDiscoveryClientTests.Config.class,
|
||||
properties = "spring.zipkin.baseUrl=http://zipkin/")
|
||||
public class ZipkinDiscoveryClientTests {
|
||||
|
||||
@ClassRule public static ZipkinRule ZIPKIN_RULE = new ZipkinRule();
|
||||
|
||||
@Autowired SpanReporter spanReporter;
|
||||
|
||||
@Test
|
||||
public void shouldUseDiscoveryClientToFindZipkinUrlIfPresent() throws Exception {
|
||||
Span span = Span.builder().traceIdHigh(1L).traceId(2L).spanId(3L).name("foo")
|
||||
.build();
|
||||
|
||||
this.spanReporter.report(span);
|
||||
|
||||
Awaitility.await().untilAsserted(() -> then(ZIPKIN_RULE.httpRequestCount()).isGreaterThan(0));
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
static class Config {
|
||||
@Bean
|
||||
DiscoveryClient client() {
|
||||
return new ZipkinDiscoveryClient();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class ZipkinDiscoveryClient implements DiscoveryClient {
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServiceInstance getLocalServiceInstance() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ServiceInstance> getInstances(String s) {
|
||||
if ("zipkin".equals(s)) {
|
||||
return Collections.singletonList(new ServiceInstance() {
|
||||
@Override
|
||||
public String getServiceId() {
|
||||
return "zipkin";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHost() {
|
||||
return "localhost";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPort() {
|
||||
return URI.create(ZIPKIN_RULE.httpUrl()).getPort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSecure() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getUri() {
|
||||
return URI.create(ZIPKIN_RULE.httpUrl());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getMetadata() {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getServices() {
|
||||
return Collections.singletonList("zipkin");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -66,12 +66,10 @@ public class ZipkinSpanListenerTests {
|
||||
@Autowired ZipkinSpanReporter spanReporter;
|
||||
@Autowired MockEnvironment mockEnvironment;
|
||||
@Autowired EndpointLocator endpointLocator;
|
||||
@Autowired ZipkinDiscoveryClient discoveryClient;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
this.test.zipkinSpans.clear();
|
||||
this.discoveryClient.serviceCalled = false;
|
||||
}
|
||||
|
||||
Span parent = Span.builder().traceId(1L).name("http:parent").remote(true).build();
|
||||
@@ -282,17 +280,6 @@ public class ZipkinSpanListenerTests {
|
||||
assertThat(this.test.zipkinSpans).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void shouldUseDiscoveryClientToFindZipkinUrlIfPresent() {
|
||||
Span span = Span.builder().traceIdHigh(1L).traceId(2L).spanId(3L).name("foo").build();
|
||||
|
||||
this.spanListener.report(span);
|
||||
|
||||
assertThat(this.test.zipkinSpans).isNotEmpty();
|
||||
assertThat(this.discoveryClient.serviceCalled).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldAddClientServiceIdTagWhenSpanContainsRpcEvent() {
|
||||
this.parent.logEvent(Span.CLIENT_SEND);
|
||||
@@ -352,71 +339,6 @@ public class ZipkinSpanListenerTests {
|
||||
return new MockEnvironment();
|
||||
}
|
||||
|
||||
@Bean
|
||||
DiscoveryClient client() {
|
||||
return new ZipkinDiscoveryClient();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ZipkinDiscoveryClient implements DiscoveryClient {
|
||||
|
||||
boolean serviceCalled = false;
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServiceInstance getLocalServiceInstance() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ServiceInstance> getInstances(String s) {
|
||||
if ("zipkin".equals(s)) {
|
||||
this.serviceCalled = true;
|
||||
return Collections.singletonList(new ServiceInstance() {
|
||||
@Override
|
||||
public String getServiceId() {
|
||||
return "zipkin";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHost() {
|
||||
return "1.2.3.4";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPort() {
|
||||
return 1234;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSecure() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getUri() {
|
||||
return URI.create("http://1.2.3.4:1234");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getMetadata() {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getServices() {
|
||||
return Collections.singletonList("zipkin");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user