This is an automated email from the ASF dual-hosted git repository.

jamesnetherton pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git


The following commit(s) were added to refs/heads/main by this push:
     new c1fd5eb  Switch back to using containers for ActiveMQ messaging tests
c1fd5eb is described below

commit c1fd5ebbfbba7bb44bed791eb2acae84bb1bc065
Author: James Netherton <[email protected]>
AuthorDate: Thu Oct 7 08:10:08 2021 +0100

    Switch back to using containers for ActiveMQ messaging tests
---
 integration-tests-support/activemq/pom.xml         |  55 +-----------
 .../support/activemq/ActiveMQTestResource.java     | 100 +++++++++------------
 .../activemq/src/main/resources/broker.xml         |  30 -------
 3 files changed, 46 insertions(+), 139 deletions(-)

diff --git a/integration-tests-support/activemq/pom.xml 
b/integration-tests-support/activemq/pom.xml
index 948e051..cb921a2 100644
--- a/integration-tests-support/activemq/pom.xml
+++ b/integration-tests-support/activemq/pom.xml
@@ -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>
-
diff --git 
a/integration-tests-support/activemq/src/main/java/org/apache/camel/quarkus/test/support/activemq/ActiveMQTestResource.java
 
b/integration-tests-support/activemq/src/main/java/org/apache/camel/quarkus/test/support/activemq/ActiveMQTestResource.java
index 57b6647..7caab1d 100644
--- 
a/integration-tests-support/activemq/src/main/java/org/apache/camel/quarkus/test/support/activemq/ActiveMQTestResource.java
+++ 
b/integration-tests-support/activemq/src/main/java/org/apache/camel/quarkus/test/support/activemq/ActiveMQTestResource.java
@@ -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
@@ -48,66 +47,51 @@ public class ActiveMQTestResource implements 
QuarkusTestResourceLifecycleManager
 
     @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();
-    }
-}
diff --git a/integration-tests-support/activemq/src/main/resources/broker.xml 
b/integration-tests-support/activemq/src/main/resources/broker.xml
deleted file mode 100644
index 2e49f53..0000000
--- a/integration-tests-support/activemq/src/main/resources/broker.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-<!--
-
-    Licensed to the Apache Software Foundation (ASF) under one or more
-    contributor license agreements.  See the NOTICE file distributed with
-    this work for additional information regarding copyright ownership.
-    The ASF licenses this file to You 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.
-
--->
-<configuration xmlns="urn:activemq" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="urn:activemq /schema/artemis-configuration.xsd">
-    <core xmlns="urn:activemq:core">
-        <paging-directory>./target/artemis/paging</paging-directory>
-        <bindings-directory>./target/artemis/bindings</bindings-directory>
-        <journal-directory>./target/artemis/journal</journal-directory>
-        
<large-messages-directory>./target/artemis/large-messages</large-messages-directory>
-
-        <max-disk-usage>-1</max-disk-usage>
-        <security-enabled>false</security-enabled>
-
-    </core>
-</configuration>

Reply via email to