diff --git a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/zipkin/ZipkinContainerConnectionDetailsFactory.java b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/zipkin/ZipkinContainerConnectionDetailsFactory.java index dc58f7bdbf..3fbb5adeb7 100644 --- a/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/zipkin/ZipkinContainerConnectionDetailsFactory.java +++ b/spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/zipkin/ZipkinContainerConnectionDetailsFactory.java @@ -30,9 +30,10 @@ import org.springframework.boot.testcontainers.service.connection.ServiceConnect * using the {@code "openzipkin/zipkin"} image. * * @author Eddú Meléndez + * @author Moritz Halbritter */ class ZipkinContainerConnectionDetailsFactory - extends ContainerConnectionDetailsFactory> { + extends ContainerConnectionDetailsFactory, ZipkinConnectionDetails> { private static final int ZIPKIN_PORT = 9411; @@ -49,20 +50,17 @@ class ZipkinContainerConnectionDetailsFactory /** * {@link ZipkinConnectionDetails} backed by a {@link ContainerConnectionSource}. */ - private static class ZipkinContainerConnectionDetails extends ContainerConnectionDetails + private static class ZipkinContainerConnectionDetails extends ContainerConnectionDetails> implements ZipkinConnectionDetails { - private final String endpoint; - ZipkinContainerConnectionDetails(ContainerConnectionSource> source) { super(source); - this.endpoint = "http://" + source.getContainer().getHost() + ":" - + source.getContainer().getMappedPort(ZIPKIN_PORT) + "/api/v2/spans"; } @Override public String getSpanEndpoint() { - return this.endpoint; + return "http://" + getContainer().getHost() + ":" + getContainer().getMappedPort(ZIPKIN_PORT) + + "/api/v2/spans"; } } diff --git a/spring-boot-project/spring-boot-testcontainers/src/test/java/org/springframework/boot/testcontainers/service/connection/zipkin/ZipkinContainerConnectionDetailsFactoryIntegrationTests.java b/spring-boot-project/spring-boot-testcontainers/src/test/java/org/springframework/boot/testcontainers/service/connection/zipkin/ZipkinContainerConnectionDetailsFactoryIntegrationTests.java index 203248957f..0c9a9d1abe 100644 --- a/spring-boot-project/spring-boot-testcontainers/src/test/java/org/springframework/boot/testcontainers/service/connection/zipkin/ZipkinContainerConnectionDetailsFactoryIntegrationTests.java +++ b/spring-boot-project/spring-boot-testcontainers/src/test/java/org/springframework/boot/testcontainers/service/connection/zipkin/ZipkinContainerConnectionDetailsFactoryIntegrationTests.java @@ -26,6 +26,7 @@ import org.springframework.boot.actuate.autoconfigure.tracing.zipkin.ZipkinAutoC import org.springframework.boot.actuate.autoconfigure.tracing.zipkin.ZipkinConnectionDetails; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.testcontainers.service.connection.ServiceConnection; +import org.springframework.boot.testsupport.testcontainers.DockerImageNames; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; @@ -35,6 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat; * Tests for {@link ZipkinContainerConnectionDetailsFactory}. * * @author Eddú Meléndez + * @author Moritz Halbritter */ @SpringJUnitConfig @Testcontainers(disabledWithoutDocker = true) @@ -42,16 +44,16 @@ class ZipkinContainerConnectionDetailsFactoryIntegrationTests { @Container @ServiceConnection - static final GenericContainer container = new GenericContainer<>("openzipkin/zipkin:2.23.2") - .withExposedPorts(9411); + static final GenericContainer zipkin = new GenericContainer<>(DockerImageNames.zipkin()).withExposedPorts(9411); - @Autowired + @Autowired(required = false) private ZipkinConnectionDetails connectionDetails; @Test - void connectionCanBeMadeToRabbitContainer() { + void connectionCanBeMadeToZipkinContainer() { + assertThat(this.connectionDetails).isNotNull(); assertThat(this.connectionDetails.getSpanEndpoint()) - .startsWith("http://" + container.getHost() + ":" + container.getMappedPort(9411)); + .startsWith("http://" + zipkin.getHost() + ":" + zipkin.getMappedPort(9411)); } @Configuration(proxyBeanMethods = false) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/testcontainers/DockerImageNames.java b/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/testcontainers/DockerImageNames.java index 10684963fa..dd35cc8902 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/testcontainers/DockerImageNames.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/testcontainers/DockerImageNames.java @@ -23,6 +23,7 @@ import org.testcontainers.utility.DockerImageName; * * @author Stephane Nicoll * @author Eddú Meléndez + * @author Moritz Halbritter * @since 2.3.6 */ public final class DockerImageNames { @@ -53,6 +54,8 @@ public final class DockerImageNames { private static final String REGISTRY_VERSION = "2.7.1"; + private static final String ZIPKIN_VERSION = "2.24.1"; + private DockerImageNames() { } @@ -163,4 +166,13 @@ public final class DockerImageNames { return DockerImageName.parse("registry").withTag(REGISTRY_VERSION); } + /** + * Return a {@link DockerImageName} suitable for running Zipkin. + * @return a docker image name for running Zipkin + * @since 3.1.0 + */ + public static DockerImageName zipkin() { + return DockerImageName.parse("openzipkin/zipkin").withTag(ZIPKIN_VERSION); + } + }