Hi Achim,

thanks for the update.

Actually, the problem was not specific to Mac: it was a race issue. The activemq-broker-noweb feature install the activemq-osgi/activemq-blueprint bundles, which start the broker "asynchronously" from the feature installation. It means that it was possible to start to perform the test whereas the broker was not fully started: that's why we got the "Connection refused" (the transport connector was not yet started). So, in the @Before method, before moving forward on the tests themselves, I'm checking that the transport connector port number (61616) is bound.

Regards
JB

On 01/23/2015 11:09 PM, Achim Nierbeck wrote:
Hi JB,

looks like this did the trick for the failing tests on Mac.

regards, Achim


2015-01-23 18:01 GMT+01:00 <[email protected]>:

Repository: karaf
Updated Branches:
   refs/heads/karaf-2.3.x d615d2feb -> 228b7170e


Improve JmsTest itest (waiting the ActiveMQ broker fully started before
starting the tests as it can provide "race" condition)


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/228b7170
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/228b7170
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/228b7170

Branch: refs/heads/karaf-2.3.x
Commit: 228b7170ec1d539d86784cd22f1626869be8e2e2
Parents: d615d2f
Author: Jean-Baptiste Onofré <[email protected]>
Authored: Fri Jan 23 16:19:03 2015 +0100
Committer: Jean-Baptiste Onofré <[email protected]>
Committed: Fri Jan 23 18:01:14 2015 +0100

----------------------------------------------------------------------
  .../java/org/apache/karaf/itests/JmsTest.java   | 25 +++++++++++++++++---
  1 file changed, 22 insertions(+), 3 deletions(-)
----------------------------------------------------------------------



http://git-wip-us.apache.org/repos/asf/karaf/blob/228b7170/itests/src/test/java/org/apache/karaf/itests/JmsTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/JmsTest.java
b/itests/src/test/java/org/apache/karaf/itests/JmsTest.java
index e70a072..e759bcc 100644
--- a/itests/src/test/java/org/apache/karaf/itests/JmsTest.java
+++ b/itests/src/test/java/org/apache/karaf/itests/JmsTest.java
@@ -26,6 +26,7 @@ import static org.junit.Assert.assertEquals;
  import javax.management.MBeanServerConnection;
  import javax.management.ObjectName;
  import javax.management.remote.JMXConnector;
+import java.net.Socket;
  import java.net.URI;
  import java.util.List;

@@ -40,9 +41,21 @@ public class JmsTest extends KarafTestSupport {
          featuresService.addRepository(new
URI("mvn:org.apache.activemq/activemq-karaf/5.10.0/xml/features"));
          featuresService.installFeature("activemq-broker-noweb");
          assertFeatureInstalled("activemq-broker-noweb");
+        // check if ActiveMQ is completely started
+        System.out.println("Waiting for the ActiveMQ transport connector
on 61616 ...");
+        boolean bound = false;
+        while (!bound) {
+            try {
+                Thread.sleep(2000);
+                Socket socket = new Socket("localhost", 61616);
+                bound = true;
+            } catch (Exception e) {
+                // wait the connection
+            }
+        }
      }

-    @Test
+    @Test(timeout = 120000)
      public void testCommands() throws Exception {
          // jms:create command
          System.out.println(executeCommand("jms:create -t ActiveMQ -u
karaf -p karaf --url tcp://localhost:61616 test"));
@@ -91,7 +104,7 @@ public class JmsTest extends KarafTestSupport {
          System.out.println(connectionFactories);
      }

-    @Test
+    @Test(timeout = 120000)
      public void testMBean() throws Exception {
          JMXConnector connector = null;
          try {
@@ -99,20 +112,26 @@ public class JmsTest extends KarafTestSupport {
              MBeanServerConnection connection =
connector.getMBeanServerConnection();
              ObjectName name = new
ObjectName("org.apache.karaf:type=jms,name=root");
              // create operation
+            System.out.println("JMS MBean create operation invocation");
              connection.invoke(name, "create", new String[]{ "testMBean",
"activemq", "tcp://localhost:61616", "karaf", "karaf" }, new String[]{
"java.lang.String", "java.lang.String", "java.lang.String",
"java.lang.String", "java.lang.String" });
              Thread.sleep(5000);
              List<String> connectionFactories = (List<String>)
connection.getAttribute(name, "Connectionfactories");
              assertEquals(true, connectionFactories.size() >= 1);
              // send operation
+            System.out.println("JMS MBean send operation invocation");
              connection.invoke(name, "send", new String[]{ "testMBean",
"queueMBean", "message", null, "karaf", "karaf" }, new String[]{
"java.lang.String", "java.lang.String", "java.lang.String",
"java.lang.String", "java.lang.String", "java.lang.String"});
              // count operation
+            System.out.println("JMS MBean count operation invocation");
              Integer count = (Integer) connection.invoke(name, "count",
new String[]{ "testMBean", "queueMBean", "karaf", "karaf" }, new String[]{
"java.lang.String", "java.lang.String", "java.lang.String",
"java.lang.String"});
              assertEquals(1, count.intValue());
              // queues operation
+            System.out.print("JMS MBean queues operation invocation: ");
              List<String> queues = (List<String>) connection.invoke(name,
"queues", new String[]{ "testMBean", "karaf", "karaf" }, new String[]{
"java.lang.String", "java.lang.String", "java.lang.String"});
+            System.out.println(queues);
              assertTrue(queues.size() >= 1);
              // delete operation
-            connection.invoke(name, "delete", new String[]{ "testMBean"
}, new String[]{ "java.lang.String" });
+            System.out.println("JMS MBean delete operation invocation");
+            connection.invoke(name, "delete", new String[]{"testMBean"},
new String[]{"java.lang.String"});
          } finally {
              if (connector != null) {
                  connector.close();





--
Jean-Baptiste Onofré
[email protected]
http://blog.nanthrax.net
Talend - http://www.talend.com

Reply via email to