Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch back to using containers for ActiveMQ messaging tests #3166

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
55 changes: 4 additions & 51 deletions integration-tests-support/activemq/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,61 +30,14 @@
<name>Camel Quarkus :: Integration Tests :: Support :: ActiveMQ</name>

<dependencies>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-server</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-json_1.0_spec</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss.logmanager</groupId>
<artifactId>jboss-logmanager</artifactId>
</exclusion>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-amqp-protocol</artifactId>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-mqtt-protocol</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-integration-test-support</artifactId>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.jboss.jandex</groupId>
<artifactId>jandex-maven-plugin</artifactId>
<executions>
<execution>
<id>make-index</id>
<goals>
<goal>jandex</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,24 @@
*/
package org.apache.camel.quarkus.test.support.activemq;

import java.nio.file.Paths;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;

import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
import org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ;
import org.apache.camel.quarkus.test.AvailablePortFinder;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.utility.DockerImageName;

public class ActiveMQTestResource implements QuarkusTestResourceLifecycleManager {

private static final Logger LOGGER = LoggerFactory.getLogger(ActiveMQTestResource.class);
private static final String ACTIVEMQ_IMAGE_NAME = System.getProperty("activemq.container.image",
"quay.io/artemiscloud/activemq-artemis-broker:0.1.4");
private static final String ACTIVEMQ_USERNAME = "artemis";
private static final String ACTIVEMQ_PASSWORD = "simetraehcapa";
private static final int ACTIVEMQ_PORT = 61616;

private QuarkusEmbeddedMQ embedded;
private GenericContainer<?> container;
private String[] modules;

@Override
Expand All @@ -48,66 +47,51 @@ public void init(Map<String, String> initArgs) {

@Override
public Map<String, String> start() {
LOGGER.info("start embedded ActiveMQ server");
DockerImageName imageName = DockerImageName.parse(ACTIVEMQ_IMAGE_NAME);
container = new GenericContainer<>(imageName)
.withExposedPorts(ACTIVEMQ_PORT)
.withLogConsumer(frame -> System.out.print(frame.getUtf8String()))
.withEnv("AMQ_USER", ACTIVEMQ_USERNAME)
.withEnv("AMQ_PASSWORD", ACTIVEMQ_PASSWORD)
.waitingFor(Wait.forLogMessage(".*AMQ241001.*", 1));

try {
FileUtils.deleteDirectory(Paths.get("./target/artemis").toFile());
int port = AvailablePortFinder.getNextAvailable();
String brokerUrlTcp = String.format("tcp://127.0.0.1:%d", port);
String brokerUrlWs = String.format("ws://127.0.0.1:%d", port);
String brokerUrlAmqp = String.format("amqp://127.0.0.1:%d", port);
container.start();

embedded = new QuarkusEmbeddedMQ();
int containerPort = container.getMappedPort(ACTIVEMQ_PORT);

embedded.init();
embedded.getActiveMQServer().getConfiguration().addAcceptorConfiguration("activemq", brokerUrlTcp);
embedded.getActiveMQServer().getConfiguration().addConnectorConfiguration("activemq", brokerUrlTcp);
embedded.start();
String brokerUrlTcp = String.format("tcp://127.0.0.1:%d", containerPort);
String brokerUrlWs = String.format("ws://127.0.0.1:%d", containerPort);
String brokerUrlAmqp = String.format("amqp://127.0.0.1:%d", containerPort);

Map<String, String> result = new LinkedHashMap<>();
Map<String, String> result = new LinkedHashMap<>();

if (modules != null) {
Arrays.stream(modules).forEach(module -> {
if (module.equals("quarkus.artemis")) {
LOGGER.info("add module " + module);
result.put("quarkus.artemis.url", brokerUrlTcp);
result.put("quarkus.artemis.username", ACTIVEMQ_USERNAME);
result.put("quarkus.artemis.password", ACTIVEMQ_PASSWORD);
} else if (module.equals("quarkus.qpid-jms")) {
result.put("quarkus.qpid-jms.url", brokerUrlAmqp);
result.put("quarkus.qpid-jms.username", ACTIVEMQ_USERNAME);
result.put("quarkus.qpid-jms.password", ACTIVEMQ_PASSWORD);
} else if (module.startsWith("camel.component")) {
result.put(module + ".brokerUrl", brokerUrlTcp);
result.put(module + ".username", ACTIVEMQ_USERNAME);
result.put(module + ".password", ACTIVEMQ_PASSWORD);
} else if (module.equals("broker-url.ws")) {
result.put("broker-url.ws", brokerUrlWs);
}
});
}

return result;
} catch (Exception e) {
throw new RuntimeException("Could not start embedded ActiveMQ server", e);
if (modules != null) {
Arrays.stream(modules).forEach(module -> {
if (module.equals("quarkus.artemis")) {
result.put("quarkus.artemis.url", brokerUrlTcp);
result.put("quarkus.artemis.username", ACTIVEMQ_USERNAME);
result.put("quarkus.artemis.password", ACTIVEMQ_PASSWORD);
} else if (module.equals("quarkus.qpid-jms")) {
result.put("quarkus.qpid-jms.url", brokerUrlAmqp);
result.put("quarkus.qpid-jms.username", ACTIVEMQ_USERNAME);
result.put("quarkus.qpid-jms.password", ACTIVEMQ_PASSWORD);
} else if (module.startsWith("camel.component")) {
result.put(module + ".brokerUrl", brokerUrlTcp);
result.put(module + ".username", ACTIVEMQ_USERNAME);
result.put(module + ".password", ACTIVEMQ_PASSWORD);
} else if (module.equals("broker-url.ws")) {
result.put("broker-url.ws", brokerUrlWs);
}
});
}

return result;
}

@Override
public void stop() {
if (embedded == null) {
return;
}
try {
embedded.stop();
} catch (Exception e) {
throw new RuntimeException("Could not stop embedded ActiveMQ server", e);
if (container != null) {
container.stop();
}
}
}

class QuarkusEmbeddedMQ extends EmbeddedActiveMQ {
public void init() throws Exception {
super.initStart();
}
}
30 changes: 0 additions & 30 deletions integration-tests-support/activemq/src/main/resources/broker.xml

This file was deleted.