Fixed integration tests to use ZipkinRule

This commit is contained in:
Marcin Grzejszczak
2016-06-27 15:46:54 +02:00
parent c965b82870
commit ed66870290
3 changed files with 10 additions and 53 deletions

View File

@@ -70,10 +70,6 @@ public abstract class AbstractIntegrationTest {
return Awaitility.await().pollInterval(POLL_INTERVAL, SECONDS).atMost(TIMEOUT, SECONDS);
}
protected Runnable zipkinQueryServerIsUp() {
return checkServerHealth("Zipkin Query Server", this::endpointToCheckZipkinQueryHealth);
}
protected Runnable zipkinServerIsUp() {
return checkServerHealth("Zipkin Stream Server", this::endpointToCheckZipkinServerHealth);
}
@@ -91,12 +87,6 @@ public abstract class AbstractIntegrationTest {
ResponseEntity<String> exchange();
}
protected ResponseEntity<String> endpointToCheckZipkinQueryHealth() {
URI uri = URI.create(getZipkinServicesQueryUrl());
log.info(String.format("Sending request to the Zipkin query service [%s]", uri));
return exchangeRequest(uri);
}
protected ResponseEntity<String> endpointToCheckZipkinServerHealth() {
URI uri = URI.create("http://localhost:" +getZipkinServerPort()+"/health");
log.info(String.format("Sending request to the Zipkin Server [%s]", uri));

View File

@@ -102,6 +102,11 @@
<artifactId>zipkin-server</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@@ -18,9 +18,7 @@ package integration;
import java.net.URI;
import java.util.Random;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -29,20 +27,17 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.cloud.sleuth.metric.SpanMetricReporter;
import org.springframework.cloud.sleuth.zipkin.HttpZipkinSpanReporter;
import org.springframework.cloud.sleuth.zipkin.ZipkinProperties;
import org.springframework.cloud.sleuth.zipkin.ZipkinSpanReporter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.SocketUtils;
import integration.ZipkinTests.WaitUntilZipkinIsUpConfig;
import sample.SampleZipkinApplication;
import tools.AbstractIntegrationTest;
import zipkin.junit.ZipkinRule;
import zipkin.server.EnableZipkinServer;
@RunWith(SpringJUnit4ClassRunner.class)
@@ -52,18 +47,14 @@ import zipkin.server.EnableZipkinServer;
@TestPropertySource(properties = {"sample.zipkin.enabled=true"})
public class ZipkinTests extends AbstractIntegrationTest {
@ClassRule public static final ZipkinRule zipkin = new ZipkinRule();
private static final String APP_NAME = "testsleuthzipkin";
@Value("${local.server.port}")
private int port = 3380;
private String sampleAppUrl = "http://localhost:" + this.port;
@Autowired ZipkinProperties zipkinProperties;
@Before
public void setup() {
ZipkinServer.main(new String[] { "--server.port=" + getPortFromProps() });
await().until(zipkinQueryServerIsUp());
}
@Override protected int getZipkinServerPort() {
return getPortFromProps();
}
@@ -90,42 +81,13 @@ public class ZipkinTests extends AbstractIntegrationTest {
@Configuration
public static class WaitUntilZipkinIsUpConfig {
private static final Log log = LogFactory.getLog(WaitUntilZipkinIsUpConfig.class);
@Bean
@Primary
ZipkinProperties testZipkinProperties() {
int freePort = SocketUtils.findAvailableTcpPort();
ZipkinProperties zipkinProperties = new ZipkinProperties();
zipkinProperties.setBaseUrl("http://localhost:" + freePort);
zipkinProperties.setBaseUrl(zipkin.httpUrl());
return zipkinProperties;
}
@Bean
public ZipkinSpanReporter spanCollector(final ZipkinProperties zipkin,
final SpanMetricReporter spanMetricReporter) {
await().until(new Runnable() {
@Override
public void run() {
try {
WaitUntilZipkinIsUpConfig.this.getSpanCollector(zipkin,
spanMetricReporter);
}
catch (Exception e) {
log.error("Exception occurred while trying to connect to zipkin ["
+ e.getCause() + "]");
throw new AssertionError(e);
}
}
});
return getSpanCollector(zipkin, spanMetricReporter);
}
private ZipkinSpanReporter getSpanCollector(ZipkinProperties zipkin,
SpanMetricReporter spanMetricReporter) {
return new HttpZipkinSpanReporter(zipkin.getBaseUrl(), zipkin.getFlushInterval(),
zipkin.getCompression().isEnabled(), spanMetricReporter);
}
}
@SpringBootApplication