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

jlmonteiro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomee.git


The following commit(s) were added to refs/heads/master by this push:
     new 8c0819090d TOMEE-3976 Make sure ActiveMQ does not always rely on 61616
8c0819090d is described below

commit 8c0819090de18bf6c645812e88eae3202b557f83
Author: Jean-Louis Monteiro <[email protected]>
AuthorDate: Wed Jun 15 23:59:37 2022 +0200

    TOMEE-3976 Make sure ActiveMQ does not always rely on 61616
---
 .../JMS2AMQDefaultConnectionFactoryTest.java       | 16 ++++++++++
 .../classic/ConnectionFactoryJMXTest.java          | 12 +++++++-
 .../core/mdb/MaxInstanceEndpointHandlerTest.java   |  2 ++
 .../java/org/apache/openejb/test/TestServer.java   |  8 ++---
 server/openejb-ejbd/pom.xml                        | 34 +++++++++++++++++-----
 server/openejb-http/pom.xml                        | 25 +++++++++++++++-
 6 files changed, 83 insertions(+), 14 deletions(-)

diff --git 
a/container/openejb-core/src/test/java/org/apache/openejb/activemq/JMS2AMQDefaultConnectionFactoryTest.java
 
b/container/openejb-core/src/test/java/org/apache/openejb/activemq/JMS2AMQDefaultConnectionFactoryTest.java
index d0eeda3f3a..751457da8d 100644
--- 
a/container/openejb-core/src/test/java/org/apache/openejb/activemq/JMS2AMQDefaultConnectionFactoryTest.java
+++ 
b/container/openejb-core/src/test/java/org/apache/openejb/activemq/JMS2AMQDefaultConnectionFactoryTest.java
@@ -18,8 +18,10 @@ package org.apache.openejb.activemq;
 
 import org.apache.openejb.junit.ApplicationComposer;
 import org.apache.openejb.testing.Classes;
+import org.apache.openejb.testing.Configuration;
 import org.apache.openejb.testing.ContainerProperties;
 import org.apache.openejb.testing.SimpleLog;
+import org.apache.openejb.util.NetworkUtil;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -30,6 +32,8 @@ import jakarta.jms.JMSContext;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 
+import java.util.Properties;
+
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
@@ -45,6 +49,18 @@ public class JMS2AMQDefaultConnectionFactoryTest {
     @Inject
     private JustToGetAJndiContext justToGetAJndiContext;
 
+    @Configuration
+    public Properties config() throws Exception {
+        Properties p = new Properties();
+        p.put("myActiveMQResourceAdapter", 
"new://Resource?type=ActiveMQResourceAdapter");
+        p.put("myActiveMQResourceAdapter.brokerXmlConfig",
+              "broker:(tcp://localhost:" + NetworkUtil.getNextAvailablePort() 
+ ")?useJmx=false");
+        p.put("myActiveMQResourceAdapter.dataSource", "Default Unmanaged JDBC 
Database");
+        p.put("myActiveMQResourceAdapter.serverUrl", 
"vm://localhost?waitForStart=20000&async=true");
+        p.put("myActiveMQResourceAdapter.startupTimeout", "10 seconds");
+        return p;
+    }
+
     @Test
     public void checkCF() throws Exception {
         assertEquals("test", 
defaultContext.createTextMessage("test").getText());
diff --git 
a/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/ConnectionFactoryJMXTest.java
 
b/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/ConnectionFactoryJMXTest.java
index 0bf1e3af7f..61ac8bee4d 100644
--- 
a/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/ConnectionFactoryJMXTest.java
+++ 
b/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/ConnectionFactoryJMXTest.java
@@ -29,6 +29,8 @@ import org.apache.openejb.monitoring.LocalMBeanServer;
 import jakarta.annotation.Resource;
 import jakarta.jms.Connection;
 import jakarta.jms.ConnectionFactory;
+import org.apache.openejb.util.NetworkUtil;
+
 import javax.management.AttributeNotFoundException;
 import javax.management.InstanceNotFoundException;
 import javax.management.IntrospectionException;
@@ -53,8 +55,16 @@ public class ConnectionFactoryJMXTest extends TestCase {
         
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
         
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
 
+        // define props for RA in order to change the default activeMQ port
+        final Properties props = new Properties();
+        final String brokerAddress = NetworkUtil.getLocalAddress("tcp://", "");
+        final String brokerXmlConfig = "broker:(" + brokerAddress + 
")?useJmx=false";
+        props.put("BrokerXmlConfig", brokerXmlConfig);
+        props.put("StartupTimeout", 10000);
+
         // Fake connection factory
-        assembler.createResource(config.configureService("Default JMS Resource 
Adapter", ResourceInfo.class));
+        assembler.createResource(config.configureService(ResourceInfo.class, 
"Default JMS Resource Adapter",
+                 props, "Default JMS Resource Adapter", 
"ActiveMQResourceAdapter"));
         final ResourceInfo resourceInfo = config.configureService("Default JMS 
Connection Factory", ResourceInfo.class);
         resourceInfo.id = "CF";
         resourceInfo.properties.setProperty("TransactionSupport", "xa");
diff --git 
a/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/MaxInstanceEndpointHandlerTest.java
 
b/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/MaxInstanceEndpointHandlerTest.java
index d28fc091e9..1a14318a84 100644
--- 
a/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/MaxInstanceEndpointHandlerTest.java
+++ 
b/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/MaxInstanceEndpointHandlerTest.java
@@ -22,6 +22,7 @@ import org.apache.openejb.monitoring.LocalMBeanServer;
 import org.apache.openejb.testing.Configuration;
 import org.apache.openejb.testing.Module;
 import org.apache.openejb.testng.PropertiesBuilder;
+import org.apache.openejb.util.NetworkUtil;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -52,6 +53,7 @@ public class MaxInstanceEndpointHandlerTest {
 
             .p("sra", "new://Resource?type=ActiveMQResourceAdapter")
             .p("sra.threadPoolSize", "100")
+            .p("sra.brokerXmlConfig", "broker:(tcp://localhost:" + 
NetworkUtil.getNextAvailablePort() + ")?useJmx=false")
 
             .p("mdbs", "new://Container?type=MESSAGE")
             .p("mdbs.ResourceAdapter", "sra")
diff --git 
a/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/TestServer.java
 
b/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/TestServer.java
index 04e1e853b4..1c591e43f4 100644
--- 
a/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/TestServer.java
+++ 
b/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/TestServer.java
@@ -23,12 +23,12 @@ import java.util.Properties;
  */
 public interface TestServer {
 
-    public void init(Properties props);
+    void init(Properties props);
 
-    public void start();
+    void start();
 
-    public void stop();
+    void stop();
 
-    public Properties getContextEnvironment();
+    Properties getContextEnvironment();
 
 }
diff --git a/server/openejb-ejbd/pom.xml b/server/openejb-ejbd/pom.xml
index 9e102d907d..aee3b72b6a 100644
--- a/server/openejb-ejbd/pom.xml
+++ b/server/openejb-ejbd/pom.xml
@@ -61,6 +61,24 @@
           </execution>
         </executions>
       </plugin>
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>build-helper-maven-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>reserve-activemq-port</id>
+            <goals>
+              <goal>reserve-network-port</goal>
+            </goals>
+            <phase>process-resources</phase>
+            <configuration>
+              <portNames>
+                <portName>activemq.port</portName>
+              </portNames>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-surefire-plugin</artifactId>
@@ -72,15 +90,15 @@
             
-Dopenejb.classloader.forced-skip=org.apache.openejb.jee.,org.apache.openejb.api.
             -Dopenejb.classloader.forced-load=org.apache.openejb
           </argLine>
-          <!-- 
-          <systemProperties>
-            <property>
-              <name>openejb.home</name>
-              <value>${project.build.directory}/test-classes</value>
-            </property>
-          </systemProperties>
+          <systemPropertyVariables>
+            
<openejb.home>${project.build.directory}/test-classes</openejb.home>
+            
<myActiveMQResourceAdapter>new://Resource?type=ActiveMQResourceAdapter</myActiveMQResourceAdapter>
+            
<myActiveMQResourceAdapter.brokerXmlConfig>broker:(tcp://localhost:${activemq.port})?useJmx=false</myActiveMQResourceAdapter.brokerXmlConfig>
+            <myActiveMQResourceAdapter.dataSource>Default Unmanaged JDBC 
Database</myActiveMQResourceAdapter.dataSource>
+            
<myActiveMQResourceAdapter.serverUrl>vm://localhost?waitForStart=20000&amp;async=true</myActiveMQResourceAdapter.serverUrl>
+            <myActiveMQResourceAdapter.startupTimeout>10 
seconds</myActiveMQResourceAdapter.startupTimeout>
+          </systemPropertyVariables>
           <basedir>${project.build.directory}</basedir>
-           -->
         </configuration>
       </plugin>
     </plugins>
diff --git a/server/openejb-http/pom.xml b/server/openejb-http/pom.xml
index cd44f6c90e..400c4899ed 100644
--- a/server/openejb-http/pom.xml
+++ b/server/openejb-http/pom.xml
@@ -66,19 +66,42 @@
           </execution>
         </executions>
       </plugin>
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>build-helper-maven-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>reserve-activemq-port</id>
+            <goals>
+              <goal>reserve-network-port</goal>
+            </goals>
+            <phase>process-resources</phase>
+            <configuration>
+              <portNames>
+                <portName>activemq.port</portName>
+              </portNames>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-surefire-plugin</artifactId>
         <configuration>
           <reuseForks>false</reuseForks>
           <!-- DEBUG: Uncomment this line and comment out the next -->
-          <!--<argLine>-Xdebug -Xnoagent -Djava.compiler=NONE 
-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005 
-javaagent:${project.build.directory}/target/openejb-javaagent-${version}.jar=foo=bar</argLine>-->
+          <!--<argLine>-Xdebug -Xnoagent -Djava.compiler=NONE 
-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005 
-javaagent:${project.build.directory}/openejb-javaagent-${version}.jar=foo=bar</argLine>-->
           
<argLine>"-javaagent:${project.build.directory}/openejb-javaagent-${project.version}.jar=foo=bar"
             
-Dopenejb.classloader.forced-skip=org.apache.openejb.jee.,org.apache.openejb.api.
             -Dopenejb.classloader.forced-load=org.apache.openejb
           </argLine>
           <systemPropertyVariables>
             
<openejb.home>${project.build.directory}/test-classes</openejb.home>
+            
<myActiveMQResourceAdapter>new://Resource?type=ActiveMQResourceAdapter</myActiveMQResourceAdapter>
+            
<myActiveMQResourceAdapter.brokerXmlConfig>broker:(tcp://localhost:${activemq.port})?useJmx=false</myActiveMQResourceAdapter.brokerXmlConfig>
+            <myActiveMQResourceAdapter.dataSource>Default Unmanaged JDBC 
Database</myActiveMQResourceAdapter.dataSource>
+            
<myActiveMQResourceAdapter.serverUrl>vm://localhost?waitForStart=20000&amp;async=true</myActiveMQResourceAdapter.serverUrl>
+            <myActiveMQResourceAdapter.startupTimeout>10 
seconds</myActiveMQResourceAdapter.startupTimeout>
           </systemPropertyVariables>
           <basedir>${project.build.directory}</basedir>
         </configuration>

Reply via email to