camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/2] git commit: Use dynamic port number for camel-websocket tests.
Date Mon, 23 Sep 2013 10:25:03 GMT
Use dynamic port number for camel-websocket tests.


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

Branch: refs/heads/camel-2.11.x
Commit: 4aed32f69869fb7c12852b054ba6ec408c22a574
Parents: 22147c0
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Mon Sep 23 09:32:31 2013 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Mon Sep 23 12:24:36 2013 +0200

----------------------------------------------------------------------
 .../WebsocketClientCamelRouteTest.java          | 16 +++++++++++++++-
 .../WebsocketComponentRouteExampleTest.java     | 15 +++++++++++++--
 .../websocket/WebsocketConsumerRouteTest.java   | 18 ++++++++++++++++--
 .../WebsocketProducerRouteExampleTest.java      | 14 ++++++++++++--
 .../websocket/WebsocketRouteExampleTest.java    | 15 ++++++++++++++-
 ...ebsocketSSLContextInUriRouteExampleTest.java |  6 ++++--
 .../websocket/WebsocketSSLRouteExampleTest.java |  8 ++++++--
 .../WebsocketTwoRoutesExampleTest.java          | 20 ++++++++++++++------
 8 files changed, 94 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/4aed32f6/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketClientCamelRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketClientCamelRouteTest.java
b/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketClientCamelRouteTest.java
index 2bbfde3..2f860d8 100644
--- a/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketClientCamelRouteTest.java
+++ b/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketClientCamelRouteTest.java
@@ -26,7 +26,9 @@ import com.ning.http.client.websocket.WebSocket;
 import com.ning.http.client.websocket.WebSocketTextListener;
 import com.ning.http.client.websocket.WebSocketUpgradeHandler;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.AvailablePortFinder;
 import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Before;
 import org.junit.Test;
 
 public class WebsocketClientCamelRouteTest extends CamelTestSupport {
@@ -34,11 +36,20 @@ public class WebsocketClientCamelRouteTest extends CamelTestSupport {
     private static List<String> received = new ArrayList<String>();
     private static CountDownLatch latch = new CountDownLatch(10);
 
+    protected int port;
+
+    @Override
+    @Before
+    public void setUp() throws Exception {
+        port = AvailablePortFinder.getNextAvailable(16200);
+        super.setUp();
+    }
+
     @Test
     public void testWSHttpCall() throws Exception {
         AsyncHttpClient c = new AsyncHttpClient();
 
-        WebSocket websocket = c.prepareGet("ws://127.0.0.1:9292/test").execute(
+        WebSocket websocket = c.prepareGet("ws://127.0.0.1:" + port + "/test").execute(
             new WebSocketUpgradeHandler.Builder()
                 .addWebSocketListener(new WebSocketTextListener() {
                     @Override
@@ -86,6 +97,9 @@ public class WebsocketClientCamelRouteTest extends CamelTestSupport {
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() {
+                WebsocketComponent websocketComponent = getContext().getComponent("websocket",
WebsocketComponent.class);
+                websocketComponent.setPort(port);
+
                 from("websocket://test")
                         .log(">>> Message received from WebSocket Client : ${body}")
                         .to("mock:client")

http://git-wip-us.apache.org/repos/asf/camel/blob/4aed32f6/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketComponentRouteExampleTest.java
----------------------------------------------------------------------
diff --git a/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketComponentRouteExampleTest.java
b/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketComponentRouteExampleTest.java
index 28a5eea..d4bcabe 100644
--- a/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketComponentRouteExampleTest.java
+++ b/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketComponentRouteExampleTest.java
@@ -26,7 +26,9 @@ import com.ning.http.client.websocket.WebSocket;
 import com.ning.http.client.websocket.WebSocketTextListener;
 import com.ning.http.client.websocket.WebSocketUpgradeHandler;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.AvailablePortFinder;
 import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Before;
 import org.junit.Test;
 
 public class WebsocketComponentRouteExampleTest extends CamelTestSupport {
@@ -34,11 +36,20 @@ public class WebsocketComponentRouteExampleTest extends CamelTestSupport
{
     private static List<String> received = new ArrayList<String>();
     private static CountDownLatch latch = new CountDownLatch(1);
 
+    protected int port;
+
+    @Override
+    @Before
+    public void setUp() throws Exception {
+        port = AvailablePortFinder.getNextAvailable(16200);
+        super.setUp();
+    }
+
     @Test
     public void testWSHttpCall() throws Exception {
         AsyncHttpClient c = new AsyncHttpClient();
 
-        WebSocket websocket = c.prepareGet("ws://localhost:9494/echo").execute(
+        WebSocket websocket = c.prepareGet("ws://localhost:" +port + "/echo").execute(
             new WebSocketUpgradeHandler.Builder()
                 .addWebSocketListener(new WebSocketTextListener() {
                     @Override
@@ -83,7 +94,7 @@ public class WebsocketComponentRouteExampleTest extends CamelTestSupport
{
 
                 WebsocketComponent websocketComponent = getContext().getComponent("websocket",
WebsocketComponent.class);
                 websocketComponent.setHost("localhost");
-                websocketComponent.setPort(9494);
+                websocketComponent.setPort(port);
 
                 from("websocket://echo")
                     .log(">>> Message received from WebSocket Client : ${body}")

http://git-wip-us.apache.org/repos/asf/camel/blob/4aed32f6/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketConsumerRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketConsumerRouteTest.java
b/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketConsumerRouteTest.java
index 2d8c539..64693dd 100644
--- a/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketConsumerRouteTest.java
+++ b/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketConsumerRouteTest.java
@@ -23,16 +23,27 @@ import com.ning.http.client.websocket.WebSocketUpgradeHandler;
 
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.AvailablePortFinder;
 import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Before;
 import org.junit.Test;
 
 public class WebsocketConsumerRouteTest extends CamelTestSupport {
-    
+
+    protected int port;
+
+    @Override
+    @Before
+    public void setUp() throws Exception {
+        port = AvailablePortFinder.getNextAvailable(16200);
+        super.setUp();
+    }
+
     @Test
     public void testWSHttpCall() throws Exception {
         AsyncHttpClient c = new AsyncHttpClient();
 
-        WebSocket websocket = c.prepareGet("ws://127.0.0.1:9292/echo").execute(
+        WebSocket websocket = c.prepareGet("ws://127.0.0.1:" + port + "/echo").execute(
             new WebSocketUpgradeHandler.Builder()
                 .addWebSocketListener(new WebSocketTextListener() {
                     @Override
@@ -73,6 +84,9 @@ public class WebsocketConsumerRouteTest extends CamelTestSupport {
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() {
+                WebsocketComponent websocketComponent = (WebsocketComponent) context.getComponent("websocket");
+                websocketComponent.setPort(port);
+
                 from("websocket://echo")
                     .log(">>> Message received from WebSocket Client : ${body}")
                     .to("mock:result");

http://git-wip-us.apache.org/repos/asf/camel/blob/4aed32f6/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketProducerRouteExampleTest.java
----------------------------------------------------------------------
diff --git a/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketProducerRouteExampleTest.java
b/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketProducerRouteExampleTest.java
index 51eb809..5271512 100644
--- a/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketProducerRouteExampleTest.java
+++ b/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketProducerRouteExampleTest.java
@@ -28,22 +28,32 @@ import com.ning.http.client.websocket.WebSocketUpgradeHandler;
 import org.apache.camel.Produce;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.AvailablePortFinder;
 import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Before;
 import org.junit.Test;
 
 public class WebsocketProducerRouteExampleTest extends CamelTestSupport {
 
     private static List<String> received = new ArrayList<String>();
     private static CountDownLatch latch = new CountDownLatch(1);
+    protected int port;
 
     @Produce(uri = "direct:shop")
     private ProducerTemplate producer;
 
+    @Override
+    @Before
+    public void setUp() throws Exception {
+        port = AvailablePortFinder.getNextAvailable(16200);
+        super.setUp();
+    }
+
     @Test
     public void testWSHttpCall() throws Exception {
         AsyncHttpClient c = new AsyncHttpClient();
 
-        WebSocket websocket = c.prepareGet("ws://127.0.0.1:9292/shop").execute(
+        WebSocket websocket = c.prepareGet("ws://127.0.0.1:" + port +"/shop").execute(
             new WebSocketUpgradeHandler.Builder()
                 .addWebSocketListener(new WebSocketTextListener() {
                     @Override
@@ -89,7 +99,7 @@ public class WebsocketProducerRouteExampleTest extends CamelTestSupport
{
             public void configure() {
                 from("direct:shop")
                     .log(">>> Message received from Shopping center : ${body}")
-                    .to("websocket://localhost:9292/shop");
+                    .to("websocket://localhost:" + port + "/shop");
             }
         };
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/4aed32f6/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketRouteExampleTest.java
----------------------------------------------------------------------
diff --git a/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketRouteExampleTest.java
b/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketRouteExampleTest.java
index 7bb7dea..a15173b 100644
--- a/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketRouteExampleTest.java
+++ b/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketRouteExampleTest.java
@@ -26,19 +26,29 @@ import com.ning.http.client.websocket.WebSocket;
 import com.ning.http.client.websocket.WebSocketTextListener;
 import com.ning.http.client.websocket.WebSocketUpgradeHandler;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.AvailablePortFinder;
 import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Before;
 import org.junit.Test;
 
 public class WebsocketRouteExampleTest extends CamelTestSupport {
 
     private static List<String> received = new ArrayList<String>();
     private static CountDownLatch latch = new CountDownLatch(1);
+    protected int port;
+
+    @Override
+    @Before
+    public void setUp() throws Exception {
+        port = AvailablePortFinder.getNextAvailable(16200);
+        super.setUp();
+    }
 
     @Test
     public void testWSHttpCall() throws Exception {
         AsyncHttpClient c = new AsyncHttpClient();
 
-        WebSocket websocket = c.prepareGet("ws://127.0.0.1:9292/echo").execute(
+        WebSocket websocket = c.prepareGet("ws://127.0.0.1:" + port + "/echo").execute(
             new WebSocketUpgradeHandler.Builder()
                 .addWebSocketListener(new WebSocketTextListener() {
                     @Override
@@ -80,6 +90,9 @@ public class WebsocketRouteExampleTest extends CamelTestSupport {
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() {
+                WebsocketComponent websocketComponent = (WebsocketComponent) context.getComponent("websocket");
+                websocketComponent.setPort(port);
+
                 // START SNIPPET: e1
                 // expose a echo websocket client, that sends back an echo
                 from("websocket://echo")

http://git-wip-us.apache.org/repos/asf/camel/blob/4aed32f6/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketSSLContextInUriRouteExampleTest.java
----------------------------------------------------------------------
diff --git a/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketSSLContextInUriRouteExampleTest.java
b/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketSSLContextInUriRouteExampleTest.java
index be28c6f..dec0b17 100644
--- a/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketSSLContextInUriRouteExampleTest.java
+++ b/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketSSLContextInUriRouteExampleTest.java
@@ -33,6 +33,7 @@ import com.ning.http.client.websocket.WebSocketUpgradeHandler;
 
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.test.AvailablePortFinder;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.apache.camel.util.jsse.ClientAuthentication;
 import org.apache.camel.util.jsse.KeyManagersParameters;
@@ -52,11 +53,12 @@ public class WebsocketSSLContextInUriRouteExampleTest extends CamelTestSupport
{
     private String pwd = "changeit";
     private String uri;
     private String server = "127.0.0.1";
-    private int port = 8443;
+    private int port;
 
     @Override
     @Before
     public void setUp() throws Exception {
+        port = AvailablePortFinder.getNextAvailable(16300);
 
         URL trustStoreUrl = this.getClass().getClassLoader().getResource("jsse/localhost.ks");
         setSystemProp("javax.net.ssl.trustStore", trustStoreUrl.toURI().getPath());
@@ -138,7 +140,7 @@ public class WebsocketSSLContextInUriRouteExampleTest extends CamelTestSupport
{
     public void testWSHttpCall() throws Exception {
 
         AsyncHttpClient c = createAsyncHttpSSLClient();
-        WebSocket websocket = c.prepareGet("wss://127.0.0.1:8443/test").execute(
+        WebSocket websocket = c.prepareGet("wss://127.0.0.1:" + port + "/test").execute(
                 new WebSocketUpgradeHandler.Builder()
                         .addWebSocketListener(new WebSocketTextListener() {
                             @Override

http://git-wip-us.apache.org/repos/asf/camel/blob/4aed32f6/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketSSLRouteExampleTest.java
----------------------------------------------------------------------
diff --git a/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketSSLRouteExampleTest.java
b/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketSSLRouteExampleTest.java
index 466fbae..2a8265d 100644
--- a/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketSSLRouteExampleTest.java
+++ b/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketSSLRouteExampleTest.java
@@ -31,6 +31,7 @@ import com.ning.http.client.websocket.WebSocket;
 import com.ning.http.client.websocket.WebSocketTextListener;
 import com.ning.http.client.websocket.WebSocketUpgradeHandler;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.AvailablePortFinder;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.apache.camel.util.jsse.ClientAuthentication;
 import org.apache.camel.util.jsse.KeyManagersParameters;
@@ -48,10 +49,13 @@ public class WebsocketSSLRouteExampleTest extends CamelTestSupport {
     private static CountDownLatch latch = new CountDownLatch(10);
     protected Properties originalValues = new Properties();
     protected String pwd = "changeit";
+    protected int port;
 
     @Override
     @Before
     public void setUp() throws Exception {
+        port = AvailablePortFinder.getNextAvailable(16200);
+
         super.setUp();
 
         URL trustStoreUrl = this.getClass().getClassLoader().getResource("jsse/localhost.ks");
@@ -109,7 +113,7 @@ public class WebsocketSSLRouteExampleTest extends CamelTestSupport {
     public void testWSHttpCall() throws Exception {
 
         AsyncHttpClient c = createAsyncHttpSSLClient();
-        WebSocket websocket = c.prepareGet("wss://127.0.0.1:8443/test").execute(
+        WebSocket websocket = c.prepareGet("wss://127.0.0.1:" + port + "/test").execute(
                 new WebSocketUpgradeHandler.Builder()
                         .addWebSocketListener(new WebSocketTextListener() {
                             @Override
@@ -160,7 +164,7 @@ public class WebsocketSSLRouteExampleTest extends CamelTestSupport {
 
                 WebsocketComponent websocketComponent = (WebsocketComponent) context.getComponent("websocket");
                 websocketComponent.setSslContextParameters(defineSSLContextParameters());
-                websocketComponent.setPort(8443);
+                websocketComponent.setPort(port);
 
                 from("websocket://test")
                         .log(">>> Message received from WebSocket Client : ${body}")

http://git-wip-us.apache.org/repos/asf/camel/blob/4aed32f6/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketTwoRoutesExampleTest.java
----------------------------------------------------------------------
diff --git a/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketTwoRoutesExampleTest.java
b/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketTwoRoutesExampleTest.java
index c69b788..64bc0f5 100644
--- a/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketTwoRoutesExampleTest.java
+++ b/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketTwoRoutesExampleTest.java
@@ -26,6 +26,7 @@ import com.ning.http.client.websocket.WebSocket;
 import com.ning.http.client.websocket.WebSocketTextListener;
 import com.ning.http.client.websocket.WebSocketUpgradeHandler;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.AvailablePortFinder;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
 
@@ -33,6 +34,13 @@ public class WebsocketTwoRoutesExampleTest extends CamelTestSupport {
 
     private static List<String> received = new ArrayList<String>();
     private static CountDownLatch latch;
+    private int port;
+
+    @Override
+    public void setUp() throws Exception {
+        port = AvailablePortFinder.getNextAvailable(16310);
+        super.setUp();
+    }
 
     @Test
     public void testWSHttpCallEcho() throws Exception {
@@ -43,7 +51,7 @@ public class WebsocketTwoRoutesExampleTest extends CamelTestSupport {
 
         AsyncHttpClient c = new AsyncHttpClient();
 
-        WebSocket websocket = c.prepareGet("ws://127.0.0.1:9292/bar").execute(
+        WebSocket websocket = c.prepareGet("ws://127.0.0.1:" + port + "/bar").execute(
             new WebSocketUpgradeHandler.Builder()
                 .addWebSocketListener(new WebSocketTextListener() {
                     @Override
@@ -86,7 +94,7 @@ public class WebsocketTwoRoutesExampleTest extends CamelTestSupport {
 
         c = new AsyncHttpClient();
 
-        websocket = c.prepareGet("ws://127.0.0.1:9292/pub").execute(
+        websocket = c.prepareGet("ws://127.0.0.1:" + port + "/pub").execute(
                 new WebSocketUpgradeHandler.Builder()
                         .addWebSocketListener(new WebSocketTextListener() {
                             @Override
@@ -129,15 +137,15 @@ public class WebsocketTwoRoutesExampleTest extends CamelTestSupport
{
         return new RouteBuilder() {
             public void configure() {
 
-                from("websocket://localhost:9292/bar")
+                from("websocket://localhost:" + port + "/bar")
                     .log(">>> Message received from BAR WebSocket Client : ${body}")
                     .transform().simple("The bar has ${body}")
-                    .to("websocket://localhost:9292/bar");
+                    .to("websocket://localhost:" + port + "/bar");
 
-                from("websocket://localhost:9292/pub")
+                from("websocket://localhost:" + port + "/pub")
                         .log(">>> Message received from PUB WebSocket Client : ${body}")
                         .transform().simple("The pub has ${body}")
-                        .to("websocket://localhost:9292/pub");
+                        .to("websocket://localhost:" + port + "/pub");
             }
         };
     }


Mime
View raw message