mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Polish "Add service connection from Testcontainers Zipkin"
See gh-35107
This commit is contained in:
parent
ad4f6ffeb7
commit
9b5a2643cc
@ -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<ZipkinConnectionDetails, Container<?>> {
|
||||
extends ContainerConnectionDetailsFactory<Container<?>, 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<Container<?>>
|
||||
implements ZipkinConnectionDetails {
|
||||
|
||||
private final String endpoint;
|
||||
|
||||
ZipkinContainerConnectionDetails(ContainerConnectionSource<Container<?>> 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";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user