Fixed integration tests to use ZipkinRule

Introduce assertj assertions (#315)

    * Introduce assertJ assertions in some tests
    * Fix code formatting to be inline with Spring rules
This commit is contained in:
Marcin Grzejszczak
2016-06-27 15:47:16 +02:00
parent 32450358bf
commit 98c99db209
3 changed files with 10 additions and 53 deletions

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