Polish "Add service connection from Testcontainers Zipkin"

See gh-35107
pull/35256/head
Moritz Halbritter 2 years ago
parent ad4f6ffeb7
commit 9b5a2643cc

@ -30,9 +30,10 @@ import org.springframework.boot.testcontainers.service.connection.ServiceConnect
* using the {@code "openzipkin/zipkin"} image. * using the {@code "openzipkin/zipkin"} image.
* *
* @author Eddú Meléndez * @author Eddú Meléndez
* @author Moritz Halbritter
*/ */
class ZipkinContainerConnectionDetailsFactory class ZipkinContainerConnectionDetailsFactory
extends ContainerConnectionDetailsFactory<ZipkinConnectionDetails, Container<?>> { extends ContainerConnectionDetailsFactory<Container<?>, ZipkinConnectionDetails> {
private static final int ZIPKIN_PORT = 9411; private static final int ZIPKIN_PORT = 9411;
@ -49,20 +50,17 @@ class ZipkinContainerConnectionDetailsFactory
/** /**
* {@link ZipkinConnectionDetails} backed by a {@link ContainerConnectionSource}. * {@link ZipkinConnectionDetails} backed by a {@link ContainerConnectionSource}.
*/ */
private static class ZipkinContainerConnectionDetails extends ContainerConnectionDetails private static class ZipkinContainerConnectionDetails extends ContainerConnectionDetails<Container<?>>
implements ZipkinConnectionDetails { implements ZipkinConnectionDetails {
private final String endpoint;
ZipkinContainerConnectionDetails(ContainerConnectionSource<Container<?>> source) { ZipkinContainerConnectionDetails(ContainerConnectionSource<Container<?>> source) {
super(source); super(source);
this.endpoint = "http://" + source.getContainer().getHost() + ":"
+ source.getContainer().getMappedPort(ZIPKIN_PORT) + "/api/v2/spans";
} }
@Override @Override
public String getSpanEndpoint() { public String getSpanEndpoint() {
return this.endpoint; return "http://" + getContainer().getHost() + ":" + getContainer().getMappedPort(ZIPKIN_PORT)
+ "/api/v2/spans";
} }
} }

@ -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.actuate.autoconfigure.tracing.zipkin.ZipkinConnectionDetails;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection; import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.boot.testsupport.testcontainers.DockerImageNames;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
@ -35,6 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* Tests for {@link ZipkinContainerConnectionDetailsFactory}. * Tests for {@link ZipkinContainerConnectionDetailsFactory}.
* *
* @author Eddú Meléndez * @author Eddú Meléndez
* @author Moritz Halbritter
*/ */
@SpringJUnitConfig @SpringJUnitConfig
@Testcontainers(disabledWithoutDocker = true) @Testcontainers(disabledWithoutDocker = true)
@ -42,16 +44,16 @@ class ZipkinContainerConnectionDetailsFactoryIntegrationTests {
@Container @Container
@ServiceConnection @ServiceConnection
static final GenericContainer<?> container = new GenericContainer<>("openzipkin/zipkin:2.23.2") static final GenericContainer<?> zipkin = new GenericContainer<>(DockerImageNames.zipkin()).withExposedPorts(9411);
.withExposedPorts(9411);
@Autowired @Autowired(required = false)
private ZipkinConnectionDetails connectionDetails; private ZipkinConnectionDetails connectionDetails;
@Test @Test
void connectionCanBeMadeToRabbitContainer() { void connectionCanBeMadeToZipkinContainer() {
assertThat(this.connectionDetails).isNotNull();
assertThat(this.connectionDetails.getSpanEndpoint()) assertThat(this.connectionDetails.getSpanEndpoint())
.startsWith("http://" + container.getHost() + ":" + container.getMappedPort(9411)); .startsWith("http://" + zipkin.getHost() + ":" + zipkin.getMappedPort(9411));
} }
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)

@ -23,6 +23,7 @@ import org.testcontainers.utility.DockerImageName;
* *
* @author Stephane Nicoll * @author Stephane Nicoll
* @author Eddú Meléndez * @author Eddú Meléndez
* @author Moritz Halbritter
* @since 2.3.6 * @since 2.3.6
*/ */
public final class DockerImageNames { 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 REGISTRY_VERSION = "2.7.1";
private static final String ZIPKIN_VERSION = "2.24.1";
private DockerImageNames() { private DockerImageNames() {
} }
@ -163,4 +166,13 @@ public final class DockerImageNames {
return DockerImageName.parse("registry").withTag(REGISTRY_VERSION); 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);
}
} }

Loading…
Cancel
Save