Refactored code, removed notion of DockerTests
This commit is contained in:
@@ -29,7 +29,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.JdkIdGenerator;
|
||||
import org.springframework.util.StringUtils;
|
||||
import sample.SampleMessagingApplication;
|
||||
import tools.AbstractDockerIntegrationTest;
|
||||
import tools.AbstractIntegrationTest;
|
||||
import tools.IntegrationTestSpanCollector;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -37,11 +37,11 @@ import java.util.Collection;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = { AbstractDockerIntegrationTest.Config.class, SampleMessagingApplication.class })
|
||||
@SpringApplicationConfiguration(classes = { AbstractIntegrationTest.IntegrationSpanCollectorConfig.class, SampleMessagingApplication.class })
|
||||
@WebIntegrationTest
|
||||
@TestPropertySource(properties="sample.zipkin.enabled=true")
|
||||
@Slf4j
|
||||
public class MessagingApplicationDockerTests extends AbstractDockerIntegrationTest {
|
||||
public class MessagingApplicationTests extends AbstractIntegrationTest {
|
||||
|
||||
private static int port = 3381;
|
||||
private static String sampleAppUrl = "http://localhost:" + port;
|
||||
@@ -34,7 +34,6 @@ import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.RequestEntity;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import com.github.kristofa.brave.EmptySpanCollectorMetricsHandler;
|
||||
@@ -53,7 +52,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class AbstractDockerIntegrationTest {
|
||||
public abstract class AbstractIntegrationTest {
|
||||
|
||||
protected static int pollInterval = 1;
|
||||
protected static int timeout = 120;
|
||||
@@ -81,22 +80,6 @@ public abstract class AbstractDockerIntegrationTest {
|
||||
return Long.toHexString(hashedTraceId);
|
||||
}
|
||||
|
||||
public static String getDockerUrl() {
|
||||
URI dockerUri = getDockerURI();
|
||||
if (StringUtils.isEmpty(dockerUri.getScheme())) {
|
||||
return "http://localhost";
|
||||
}
|
||||
return "http://" + dockerUri.getHost();
|
||||
}
|
||||
|
||||
public static URI getDockerURI() {
|
||||
String dockerHost = System.getenv("DOCKER_HOST");
|
||||
if (StringUtils.isEmpty(dockerHost)) {
|
||||
return URI.create("http://localhost");
|
||||
}
|
||||
return URI.create(dockerHost);
|
||||
}
|
||||
|
||||
protected Runnable zipkinQueryServerIsUp() {
|
||||
return checkServerHealth("Zipkin Query Server", this::endpointToCheckZipkinQueryHealth);
|
||||
}
|
||||
@@ -130,12 +113,6 @@ public abstract class AbstractDockerIntegrationTest {
|
||||
return exchangeRequest(uri);
|
||||
}
|
||||
|
||||
protected ResponseEntity<String> endpointToCheckZipkinCollectorHealth() {
|
||||
URI uri = URI.create(getZipkinCollectorHealthUrl());
|
||||
log.info("Sending request to the Zipkin collector service [{}]", uri);
|
||||
return exchangeRequest(uri);
|
||||
}
|
||||
|
||||
protected ResponseEntity<String> checkStateOfTheTraceId(String traceId) {
|
||||
String hexTraceId = zipkinHashedHexStringTraceId(traceId);
|
||||
URI uri = URI.create(getZipkinTraceQueryUrl() + hexTraceId);
|
||||
@@ -150,23 +127,11 @@ public abstract class AbstractDockerIntegrationTest {
|
||||
}
|
||||
|
||||
protected String getZipkinTraceQueryUrl() {
|
||||
return getZipkinRootUrl() + ":9411/api/v1/trace/";
|
||||
}
|
||||
|
||||
protected String getZipkinRootUrl() {
|
||||
return getDockerUrl();
|
||||
return "http://localhost:9411/api/v1/trace/";
|
||||
}
|
||||
|
||||
protected String getZipkinServicesQueryUrl() {
|
||||
return getDockerUrl() + ":9411/api/v1/services";
|
||||
}
|
||||
|
||||
protected String getZipkinServerHealthUrl() {
|
||||
return getDockerUrl() + ":9411/health";
|
||||
}
|
||||
|
||||
protected String getZipkinCollectorHealthUrl() {
|
||||
return getDockerUrl() + ":9900/health";
|
||||
return "http://localhost:9411/api/v1/services";
|
||||
}
|
||||
|
||||
protected Runnable httpMessageWithTraceIdInHeadersIsSuccessfullySent(String endpoint, String traceId) {
|
||||
@@ -237,7 +202,7 @@ public abstract class AbstractDockerIntegrationTest {
|
||||
}
|
||||
|
||||
@Configuration
|
||||
public static class Config {
|
||||
public static class IntegrationSpanCollectorConfig {
|
||||
@Bean
|
||||
SpanCollector integrationTestSpanCollector() {
|
||||
return new IntegrationTestSpanCollector();
|
||||
@@ -246,7 +211,7 @@ public abstract class AbstractDockerIntegrationTest {
|
||||
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public static class ZipkinConfig {
|
||||
public static class WaitUntilZipkinIsUpConfig {
|
||||
@Bean
|
||||
@SneakyThrows
|
||||
public SpanCollector spanCollector(final ZipkinProperties zipkin) {
|
||||
@@ -254,7 +219,7 @@ public abstract class AbstractDockerIntegrationTest {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
ZipkinConfig.this.getSpanCollector(zipkin);
|
||||
WaitUntilZipkinIsUpConfig.this.getSpanCollector(zipkin);
|
||||
} catch (Exception e) {
|
||||
log.error("Exception occurred while trying to connect to zipkin [" + e.getCause() + "]");
|
||||
throw new AssertionError(e);
|
||||
@@ -265,7 +230,7 @@ public abstract class AbstractDockerIntegrationTest {
|
||||
}
|
||||
|
||||
private SpanCollector getSpanCollector(ZipkinProperties zipkin) {
|
||||
String url = "http://" + getDockerURI().getHost() + ":" + zipkin.getPort();
|
||||
String url = "http://localhost:" + zipkin.getPort();
|
||||
// TODO: parameterize this
|
||||
SpanCollectorMetricsHandler metrics = new EmptySpanCollectorMetricsHandler();
|
||||
return HttpSpanCollector.create(url, zipkin.getHttpConfig(), metrics);
|
||||
@@ -26,17 +26,17 @@ import org.springframework.cloud.stream.test.binder.TestSupportBinderAutoConfigu
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.JdkIdGenerator;
|
||||
import tools.AbstractDockerIntegrationTest;
|
||||
import tools.AbstractIntegrationTest;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = { SampleApp.Config.class,
|
||||
AbstractDockerIntegrationTest.ZipkinConfig.class,
|
||||
AbstractIntegrationTest.WaitUntilZipkinIsUpConfig.class,
|
||||
TestSupportBinderAutoConfiguration.class,
|
||||
ZipkinStreamServerApplication.class })
|
||||
@WebIntegrationTest
|
||||
@Slf4j
|
||||
@ActiveProfiles("test")
|
||||
public class ZipkinStreamDockerTests extends AbstractDockerIntegrationTest {
|
||||
public class ZipkinStreamTests extends AbstractIntegrationTest {
|
||||
|
||||
private static int port = 9411;
|
||||
private static String sampleAppUrl = "http://localhost:" + port;
|
||||
@@ -52,8 +52,4 @@ public class ZipkinStreamDockerTests extends AbstractDockerIntegrationTest {
|
||||
await().until(allSpansWereRegisteredInZipkinWithTraceIdEqualTo(traceId));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getZipkinRootUrl() {
|
||||
return "http://localhost";
|
||||
}
|
||||
}
|
||||
@@ -29,17 +29,18 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.JdkIdGenerator;
|
||||
import org.testcontainers.containers.DockerComposeContainer;
|
||||
import sample.SampleZipkinApplication;
|
||||
import tools.AbstractDockerIntegrationTest;
|
||||
import tools.AbstractIntegrationTest;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = { AbstractDockerIntegrationTest.ZipkinConfig.class, SampleZipkinApplication.class })
|
||||
@SpringApplicationConfiguration(classes = { AbstractIntegrationTest.WaitUntilZipkinIsUpConfig.class,
|
||||
SampleZipkinApplication.class })
|
||||
@WebIntegrationTest
|
||||
@TestPropertySource(properties="sample.zipkin.enabled=true")
|
||||
@Slf4j
|
||||
@Ignore("Not passing beacuse of 400 from query")
|
||||
public class ZipkinDockerTests extends AbstractDockerIntegrationTest {
|
||||
public class ZipkinTests extends AbstractIntegrationTest {
|
||||
|
||||
private static final String APP_NAME = "testsleuthzipkin";
|
||||
private static int port = 3380;
|
||||
@@ -48,8 +49,6 @@ public class ZipkinDockerTests extends AbstractDockerIntegrationTest {
|
||||
@ClassRule
|
||||
public static DockerComposeContainer environment =
|
||||
new DockerComposeContainer(new File("src/test/resources/docker-compose.yml"))
|
||||
.withExposedService("rabbitmq_1", 5672)
|
||||
.withExposedService("mysql_1", 3306)
|
||||
.withExposedService("query_1", 9411);
|
||||
|
||||
@Before
|
||||
Reference in New Issue
Block a user