activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hadr...@apache.org
Subject activemq git commit: Test cleanup: use available port instead of hardcoded
Date Tue, 06 Jan 2015 06:23:20 GMT
Repository: activemq
Updated Branches:
  refs/heads/trunk 4b7131ff8 -> 4bf5d0fc1


Test cleanup: use available port instead of hardcoded


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

Branch: refs/heads/trunk
Commit: 4bf5d0fc132ba4712f89009b4d23a2023f0ccbc1
Parents: 4b7131f
Author: Hadrian Zbarcea <hadrian@apache.org>
Authored: Tue Jan 6 01:23:05 2015 -0500
Committer: Hadrian Zbarcea <hadrian@apache.org>
Committed: Tue Jan 6 01:23:13 2015 -0500

----------------------------------------------------------------------
 .../activemq/transport/ws/WSTransportTest.java  | 34 ++++++++++++++++----
 .../transport/wss/WSSTransportTest.java         |  5 +--
 2 files changed, 31 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/4bf5d0fc/activemq-http/src/test/java/org/apache/activemq/transport/ws/WSTransportTest.java
----------------------------------------------------------------------
diff --git a/activemq-http/src/test/java/org/apache/activemq/transport/ws/WSTransportTest.java
b/activemq-http/src/test/java/org/apache/activemq/transport/ws/WSTransportTest.java
index b133e71..58df4cc 100644
--- a/activemq-http/src/test/java/org/apache/activemq/transport/ws/WSTransportTest.java
+++ b/activemq-http/src/test/java/org/apache/activemq/transport/ws/WSTransportTest.java
@@ -21,11 +21,14 @@ import static org.junit.Assert.assertTrue;
 
 import java.io.File;
 import java.io.IOException;
+import java.net.ServerSocket;
 import java.net.Socket;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.UnknownHostException;
 
+import javax.net.ServerSocketFactory;
+
 import org.apache.activemq.broker.BrokerFactory;
 import org.apache.activemq.broker.BrokerService;
 import org.apache.activemq.spring.SpringSslContext;
@@ -60,6 +63,7 @@ public class WSTransportTest {
     private File profileDir;
 
     private String stompUri;
+    private int proxyPort = 0;
     protected String wsUri;
 
     private StompConnection stompConnection = new StompConnection();
@@ -101,16 +105,33 @@ public class WSTransportTest {
         context.setServer(server);
 
         server.setHandler(context);
-        server.setConnectors(new Connector[] {
-                connector
-        });
+        server.setConnectors(new Connector[] { connector });
         server.start();
         return server;
     }
 
-    protected Connector createJettyConnector() {
+    protected int getProxyPort() {
+        if (proxyPort == 0) {
+            ServerSocket ss = null;
+            try {
+                ss = ServerSocketFactory.getDefault().createServerSocket(0);
+                proxyPort = ss.getLocalPort();
+            } catch (IOException e) { // ignore
+            } finally {
+                try {
+                    if (ss != null ) {
+                        ss.close();
+                    }
+                } catch (IOException e) { // ignore
+                }
+            }
+        }
+        return proxyPort;
+    }
+
+protected Connector createJettyConnector() {
         SelectChannelConnector connector = new SelectChannelConnector();
-        connector.setPort(8080);
+        connector.setPort(getProxyPort());
         return connector;
     }
 
@@ -208,7 +229,8 @@ public class WSTransportTest {
     }
 
     protected String getTestURI() {
-        return "http://localhost:8080/websocket.html#" + wsUri;
+        int port = getProxyPort();
+        return "http://localhost:" + port + "/websocket.html#" + wsUri;
     }
 
     public void doTestWebSockets(WebDriver driver) throws Exception {

http://git-wip-us.apache.org/repos/asf/activemq/blob/4bf5d0fc/activemq-http/src/test/java/org/apache/activemq/transport/wss/WSSTransportTest.java
----------------------------------------------------------------------
diff --git a/activemq-http/src/test/java/org/apache/activemq/transport/wss/WSSTransportTest.java
b/activemq-http/src/test/java/org/apache/activemq/transport/wss/WSSTransportTest.java
index 13fab43..775c0ab 100644
--- a/activemq-http/src/test/java/org/apache/activemq/transport/wss/WSSTransportTest.java
+++ b/activemq-http/src/test/java/org/apache/activemq/transport/wss/WSSTransportTest.java
@@ -30,7 +30,7 @@ public class WSSTransportTest extends WSTransportTest {
         contextFactory.setKeyStorePassword("password");
         contextFactory.setTrustStore("src/test/resources/client.keystore");
         contextFactory.setTrustStorePassword("password");
-        sslConnector.setPort(8080);
+        sslConnector.setPort(getProxyPort());
         return sslConnector;
     }
 
@@ -41,6 +41,7 @@ public class WSSTransportTest extends WSTransportTest {
 
     @Override
     protected String getTestURI() {
-        return "https://localhost:8080/websocket.html#wss://localhost:61623";
+        int port = getProxyPort();
+        return "https://localhost:" + port + "/websocket.html#wss://localhost:61623";
     }
 }


Mime
View raw message