activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject activemq git commit: Fix test failure in CI due to fixed port being in use.
Date Tue, 26 May 2015 17:23:27 GMT
Repository: activemq
Updated Branches:
  refs/heads/master 3125caee5 -> 2518ab280


Fix test failure in CI due to fixed port being in use.  

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

Branch: refs/heads/master
Commit: 2518ab280260881eebcf5c5273e3d14d829f3caa
Parents: 3125cae
Author: Timothy Bish <tabish121@gmail.com>
Authored: Tue May 26 13:23:19 2015 -0400
Committer: Timothy Bish <tabish121@gmail.com>
Committed: Tue May 26 13:23:19 2015 -0400

----------------------------------------------------------------------
 .../org/apache/activemq/proxy/AMQ4889Test.java  | 80 +++++++++++++-------
 1 file changed, 54 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/2518ab28/activemq-unit-tests/src/test/java/org/apache/activemq/proxy/AMQ4889Test.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/proxy/AMQ4889Test.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/proxy/AMQ4889Test.java
index 8ee85e0..0b3d7ab 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/proxy/AMQ4889Test.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/proxy/AMQ4889Test.java
@@ -18,10 +18,24 @@
 package org.apache.activemq.proxy;
 
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSSecurityException;
+import javax.jms.Session;
+import javax.net.ServerSocketFactory;
+
 import org.apache.activemq.ActiveMQConnectionFactory;
 import org.apache.activemq.broker.BrokerPlugin;
 import org.apache.activemq.broker.BrokerService;
-import org.apache.activemq.broker.TransportConnector;
 import org.apache.activemq.security.AuthenticationUser;
 import org.apache.activemq.security.SimpleAuthenticationPlugin;
 import org.apache.activemq.util.Wait;
@@ -31,34 +45,29 @@ import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
-import javax.jms.JMSSecurityException;
-import javax.jms.Session;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
 public class AMQ4889Test {
+
     protected static final Logger LOG = LoggerFactory.getLogger(AMQ4889Test.class);
 
     public static final String USER = "user";
     public static final String GOOD_USER_PASSWORD = "password";
     public static final String WRONG_PASSWORD = "wrongPassword";
-    public static final String PROXY_URI = "tcp://localhost:6002";
-    public static final String LOCAL_URI = "tcp://localhost:6001";
+    public static final String PROXY_URI_PREFIX = "tcp://localhost:";
+    public static final String LOCAL_URI_PREFIX = "tcp://localhost:";
 
-    protected BrokerService brokerService;
+    private String proxyURI;
+    private String localURI;
+
+    private BrokerService brokerService;
     private ProxyConnector proxyConnector;
-    protected TransportConnector transportConnector;
-    protected ConnectionFactory connectionFactory;
+    private ConnectionFactory connectionFactory;
 
     private static final Integer ITERATIONS = 100;
 
     protected BrokerService createBroker() throws Exception {
+        proxyURI = PROXY_URI_PREFIX + findOpenPort();
+        localURI = LOCAL_URI_PREFIX + findOpenPort();
+
         brokerService = new BrokerService();
         brokerService.setPersistent(false);
 
@@ -68,11 +77,11 @@ public class AMQ4889Test {
         BrokerPlugin[] array = new BrokerPlugin[plugins.size()];
         brokerService.setPlugins(plugins.toArray(array));
 
-        transportConnector = brokerService.addConnector(LOCAL_URI);
+        brokerService.addConnector(localURI);
         proxyConnector = new ProxyConnector();
         proxyConnector.setName("proxy");
-        proxyConnector.setBind(new URI(PROXY_URI));
-        proxyConnector.setRemote(new URI(LOCAL_URI));
+        proxyConnector.setBind(new URI(proxyURI));
+        proxyConnector.setRemote(new URI(localURI));
         brokerService.addProxyConnector(proxyConnector);
 
         brokerService.start();
@@ -92,7 +101,7 @@ public class AMQ4889Test {
     @Before
     public void setUp() throws Exception {
         brokerService = createBroker();
-        connectionFactory = new ActiveMQConnectionFactory(PROXY_URI);
+        connectionFactory = new ActiveMQConnectionFactory(proxyURI);
     }
 
     @After
@@ -101,8 +110,7 @@ public class AMQ4889Test {
         brokerService.waitUntilStopped();
     }
 
-
-    @Test(timeout = 1 * 60 * 1000)
+    @Test(timeout = 60000)
     public void testForConnectionLeak() throws Exception {
         Integer expectedConnectionCount = 0;
         for (int i=0; i < ITERATIONS; i++) {
@@ -110,15 +118,14 @@ public class AMQ4889Test {
                 if (i % 2 == 0) {
                     LOG.debug("Iteration {} adding bad connection", i);
                     Connection connection = connectionFactory.createConnection(USER, WRONG_PASSWORD);
-                    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+                    connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
                     fail("createSession should fail");
                 } else {
                     LOG.debug("Iteration {} adding good connection", i);
                     Connection connection = connectionFactory.createConnection(USER, GOOD_USER_PASSWORD);
-                    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+                    connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
                     expectedConnectionCount++;
                 }
-                //
             } catch (JMSSecurityException e) {
             }
             LOG.debug("Iteration {} Connections? {}", i, proxyConnector.getConnectionCount());
@@ -132,4 +139,25 @@ public class AMQ4889Test {
         }, 20);
         assertEquals(val, proxyConnector.getConnectionCount());
     }
+
+    protected int findOpenPort() throws IOException {
+        int openPort = 0;
+        ServerSocket ss = null;
+        try {
+            ss = ServerSocketFactory.getDefault().createServerSocket(0);
+            openPort = ss.getLocalPort();
+        } catch (IOException e) {
+            LOG.error("Could not locate an open port: ", e);
+            throw e;
+        } finally {
+            try {
+                if (ss != null ) {
+                    ss.close();
+                }
+            } catch (IOException e) { // ignore
+            }
+        }
+
+        return openPort;
+    }
 }


Mime
View raw message