Refactored code, removed notion of DockerTests
This commit is contained in:
17
README.adoc
17
README.adoc
@@ -113,23 +113,6 @@ rabbit and redis.
|
||||
NOTE: If all else fails, build with the command from `.travis.yml` (usually
|
||||
`./mvnw install`).
|
||||
|
||||
==== Integration tests
|
||||
|
||||
You can run the integration tests that boot up via docker compose the necessary
|
||||
middleware during project building. To do that you need to:
|
||||
|
||||
Set up the DOCKER_HOST environment variable to point to your docker daemon
|
||||
|
||||
----
|
||||
$ export DOCKER_HOST=tcp://127.0.0.1:2376
|
||||
----
|
||||
|
||||
Run Maven with the `integration` profile.
|
||||
|
||||
----
|
||||
$ ./mvnw install -Pintegration
|
||||
----
|
||||
|
||||
=== Documentation
|
||||
|
||||
The spring-cloud-build module has a "docs" profile, and if you switch
|
||||
|
||||
47
pom.xml
47
pom.xml
@@ -89,17 +89,6 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${surefire.plugin.version}</version>
|
||||
<configuration>
|
||||
<useFile>false</useFile>
|
||||
<excludes>
|
||||
<exclude>**/Abstract*.java</exclude>
|
||||
<exclude>**/*DockerTests.java</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
@@ -226,42 +215,6 @@
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>integration</id>
|
||||
<activation>
|
||||
<activeByDefault>false</activeByDefault>
|
||||
</activation>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>${surefire.plugin.version}</version>
|
||||
<configuration>
|
||||
<useFile>false</useFile>
|
||||
<includes>
|
||||
<include>**/*DockerTests.java</include>
|
||||
</includes>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>failsafe-integration-tests</id>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>integration-test</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>failsafe-verify</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>verify</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>ide</id>
|
||||
<activation>
|
||||
|
||||
@@ -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