Skip to content

Commit

Permalink
docker: polishes integration tests (#243)
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Cole <adrian@tetrate.io>
  • Loading branch information
codefromthecrypt authored Jan 13, 2024
1 parent d97c014 commit 2dbac71
Show file tree
Hide file tree
Showing 18 changed files with 224 additions and 329 deletions.
2 changes: 1 addition & 1 deletion activemq-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<artifactId>junit-jupiter</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2016-2024 The OpenZipkin Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package zipkin2.reporter.activemq;

import java.time.Duration;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.containers.wait.strategy.Wait;

import static org.testcontainers.utility.DockerImageName.parse;

final class ActiveMQContainer extends GenericContainer<ActiveMQContainer> {
static final Logger LOGGER = LoggerFactory.getLogger(ActiveMQContainer.class);
static final int ACTIVEMQ_PORT = 61616;

ActiveMQContainer() {
super(parse("ghcr.io/openzipkin/zipkin-activemq:3.0.2"));
withExposedPorts(ACTIVEMQ_PORT);
waitStrategy = Wait.forListeningPorts(ACTIVEMQ_PORT);
withStartupTimeout(Duration.ofSeconds(60));
withLogConsumer(new Slf4jLogConsumer(LOGGER));
}

ActiveMQSender.Builder newSenderBuilder(String queue) {
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
connectionFactory.setBrokerURL(brokerURL());
return ActiveMQSender.newBuilder().queue(queue).connectionFactory(connectionFactory);
}

String brokerURL() {
return "failover:tcp://" + getHost() + ":" + getMappedPort(ACTIVEMQ_PORT);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
import javax.jms.BytesMessage;
import javax.jms.MessageConsumer;
import javax.jms.Queue;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import zipkin2.Span;
import zipkin2.codec.SpanBytesDecoder;
import zipkin2.reporter.SpanBytesEncoder;
Expand All @@ -36,10 +37,11 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static zipkin2.TestObjects.CLIENT_SPAN;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@Tag("docker")
@Testcontainers(disabledWithoutDocker = true)
@Timeout(60)
class ITActiveMQSender {
@RegisterExtension ActiveMQExtension activemq = new ActiveMQExtension();
@Container ActiveMQContainer activemq = new ActiveMQContainer();

@Test void checkPasses() {
try (ActiveMQSender sender = activemq.newSenderBuilder("checkPasses").build()) {
Expand Down
2 changes: 1 addition & 1 deletion amqp-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<artifactId>junit-jupiter</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
Expand Down
2 changes: 1 addition & 1 deletion amqp-client/src/it/amqp_v4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<artifactId>junit-jupiter</artifactId>
<version>@testcontainers.version@</version>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,27 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Stream;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import zipkin2.Span;
import zipkin2.codec.SpanBytesDecoder;
import zipkin2.reporter.SpanBytesEncoder;
import zipkin2.reporter.Call;
import zipkin2.reporter.Encoding;
import zipkin2.reporter.Sender;
import zipkin2.reporter.SpanBytesEncoder;

import static java.util.stream.Collectors.toList;
import static org.assertj.core.api.Assertions.assertThat;
import static zipkin2.TestObjects.CLIENT_SPAN;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@Tag("docker")
@Testcontainers(disabledWithoutDocker = true)
@Timeout(60)
public class ITRabbitMQSender { // public for use in src/it
@RegisterExtension RabbitMQExtension rabbit = new RabbitMQExtension();
@Container RabbitMQContainer rabbit = new RabbitMQContainer();

@Test void sendsSpans() throws Exception {
try (RabbitMQSender sender = rabbit.newSenderBuilder("sendsSpans").build()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright 2016-2024 The OpenZipkin Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package zipkin2.reporter.amqp;

import java.time.Duration;
import org.opentest4j.TestAbortedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.containers.wait.strategy.Wait;

import static org.testcontainers.utility.DockerImageName.parse;
import static zipkin2.reporter.Call.propagateIfFatal;

final class RabbitMQContainer extends GenericContainer<RabbitMQContainer> {
static final Logger LOGGER = LoggerFactory.getLogger(RabbitMQContainer.class);
static final int RABBIT_PORT = 5672;

RabbitMQContainer() {
super(parse("ghcr.io/openzipkin/zipkin-rabbitmq:3.0.2"));
withExposedPorts(RABBIT_PORT);
waitStrategy = Wait.forLogMessage(".*Server startup complete.*", 1);
withStartupTimeout(Duration.ofSeconds(60));
withLogConsumer(new Slf4jLogConsumer(LOGGER));
}

RabbitMQSender.Builder newSenderBuilder(String queue) {
declareQueue(queue);
return RabbitMQSender.newBuilder().queue(queue).addresses(host() + ":" + port());
}

void declareQueue(String queue) {
ExecResult result;
try {
result = execInContainer("amqp-declare-queue", "-q", queue);
} catch (Throwable e) {
propagateIfFatal(e);
throw new TestAbortedException("Couldn't declare queue " + queue + ": " + e.getMessage(), e);
}
if (result.getExitCode() != 0) {
throw new TestAbortedException("Couldn't declare queue " + queue + ": " + result);
}
}

String host() {
return getHost();
}

int port() {
return getMappedPort(RABBIT_PORT);
}
}

This file was deleted.

2 changes: 1 addition & 1 deletion benchmarks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<artifactId>junit-jupiter</artifactId>
<version>${testcontainers.version}</version>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class KafkaSenderBenchmarks extends SenderBenchmarks {

static final class KafkaContainer extends GenericContainer<KafkaContainer> {
KafkaContainer() {
super(parse("ghcr.io/openzipkin/zipkin-kafka:3.0.1"));
super(parse("ghcr.io/openzipkin/zipkin-kafka:3.0.2"));
waitStrategy = Wait.forHealthcheck();
// Kafka broker listener port (19092) needs to be exposed for test cases to access it.
addFixedExposedPort(KAFKA_PORT, KAFKA_PORT, InternetProtocol.TCP);
Expand Down
2 changes: 1 addition & 1 deletion kafka/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<artifactId>junit-jupiter</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
Expand Down
Loading

0 comments on commit 2dbac71

Please sign in to comment.