activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject activemq git commit: Find a free port instead of assuming the local port is free. Should address CI failure.
Date Wed, 01 Jul 2015 20:54:27 GMT
Repository: activemq
Updated Branches:
  refs/heads/master a53d4cf7b -> 60ca85c92


Find a free port instead of assuming the local port is free.  Should
address CI failure.

Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/60ca85c9
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/60ca85c9
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/60ca85c9

Branch: refs/heads/master
Commit: 60ca85c92be91fe2ade93ee9eea89d0711a0a9a6
Parents: a53d4cf
Author: Timothy Bish <tabish121@gmail.com>
Authored: Wed Jul 1 16:54:09 2015 -0400
Committer: Timothy Bish <tabish121@gmail.com>
Committed: Wed Jul 1 16:54:09 2015 -0400

----------------------------------------------------------------------
 .../activemq/ActiveMQConnectionFactoryTest.java | 34 +++++++++++++++-----
 1 file changed, 26 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/60ca85c9/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQConnectionFactoryTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQConnectionFactoryTest.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQConnectionFactoryTest.java
index f8c6176..b2725bf 100755
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQConnectionFactoryTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQConnectionFactoryTest.java
@@ -18,14 +18,17 @@ package org.apache.activemq;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
+import java.net.ServerSocket;
 import java.net.URI;
 import java.net.URISyntaxException;
 
 import javax.jms.ExceptionListener;
 import javax.jms.JMSException;
 import javax.jms.Session;
+import javax.net.ServerSocketFactory;
 
 import org.apache.activemq.broker.BrokerRegistry;
 import org.apache.activemq.broker.BrokerService;
@@ -154,15 +157,15 @@ public class ActiveMQConnectionFactoryTest extends CombinationTestSupport
{
         broker.setUseJmx(false);
         broker.addConnector("tcp://localhost:61610?wireFormat.tcpNoDelayEnabled=true");
         broker.start();
+        broker.waitUntilStarted();
+
+        int localPort = getFreePort(51610);
 
         // This should create the connection.
-        ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61610/localhost:51610");
+        ActiveMQConnectionFactory cf =
+            new ActiveMQConnectionFactory("tcp://localhost:61610/localhost:" + localPort);
         connection = (ActiveMQConnection)cf.createConnection();
         assertNotNull(connection);
-
-        connection.close();
-
-        broker.stop();
     }
 
     public void testConnectionFailsToConnectToVMBrokerThatIsNotRunning() throws Exception
{
@@ -212,10 +215,8 @@ public class ActiveMQConnectionFactoryTest extends CombinationTestSupport
{
 
         assertEquals(exListener, cf.getExceptionListener());
         connection.close();
-
     }
 
-
     public void testSetClientInternalExceptionListener() throws Exception {
         ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
         connection = (ActiveMQConnection)cf.createConnection();
@@ -239,7 +240,6 @@ public class ActiveMQConnectionFactoryTest extends CombinationTestSupport
{
         assertEquals(listener, connection.getClientInternalExceptionListener());
         assertEquals(listener, cf.getClientInternalExceptionListener());
         connection.close();
-
     }
 
     protected void assertCreateConnection(String uri) throws Exception {
@@ -271,4 +271,22 @@ public class ActiveMQConnectionFactoryTest extends CombinationTestSupport
{
         assertNotNull(connection);
     }
 
+    private int getFreePort(final int fallback) {
+        int freePort = fallback;
+        ServerSocket ss = null;
+        try {
+            ss = ServerSocketFactory.getDefault().createServerSocket(0);
+            freePort = ss.getLocalPort();
+        } catch (IOException e) { // ignore
+        } finally {
+            try {
+                if (ss != null ) {
+                    ss.close();
+                }
+            } catch (IOException e) { // ignore
+            }
+        }
+
+        return freePort;
+    }
 }


Mime
View raw message