You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2022/09/15 07:50:54 UTC

[camel] 01/04: CAMEL-18506: make the websocket client reusable

This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit c750c1ecd43db1d394500231e44549a04d94681d
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Thu Sep 15 07:31:59 2022 +0200

    CAMEL-18506: make the websocket client reusable
---
 .../atmosphere/websocket/WebsocketRouteTest.java          | 15 ++++++++-------
 .../websocket/WebsocketRouteWithInitParamTest.java        | 15 ++++++++-------
 .../camel/test/infra/common/http/WebsocketTestClient.java | 10 +++++-----
 3 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/components/camel-atmosphere-websocket/src/test/java/org/apache/camel/component/atmosphere/websocket/WebsocketRouteTest.java b/components/camel-atmosphere-websocket/src/test/java/org/apache/camel/component/atmosphere/websocket/WebsocketRouteTest.java
index 7aa4ad6292f..312252c1fae 100644
--- a/components/camel-atmosphere-websocket/src/test/java/org/apache/camel/component/atmosphere/websocket/WebsocketRouteTest.java
+++ b/components/camel-atmosphere-websocket/src/test/java/org/apache/camel/component/atmosphere/websocket/WebsocketRouteTest.java
@@ -26,6 +26,7 @@ import java.util.List;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.infra.common.http.WebsocketTestClient;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -38,7 +39,7 @@ public class WebsocketRouteTest extends WebsocketCamelRouterTestSupport {
 
     @Test
     void testWebsocketSingleClient() throws Exception {
-        TestClient wsclient = new TestClient("ws://localhost:" + PORT + "/hola");
+        WebsocketTestClient wsclient = new WebsocketTestClient("ws://localhost:" + PORT + "/hola");
         wsclient.connect();
 
         wsclient.sendTextMessage("Cerveza");
@@ -52,7 +53,7 @@ public class WebsocketRouteTest extends WebsocketCamelRouterTestSupport {
 
     @Test
     void testWebsocketSingleClientForBytes() throws Exception {
-        TestClient wsclient = new TestClient("ws://localhost:" + PORT + "/hola");
+        WebsocketTestClient wsclient = new WebsocketTestClient("ws://localhost:" + PORT + "/hola");
         wsclient.connect();
 
         wsclient.sendBytesMessage("Cerveza".getBytes("UTF-8"));
@@ -66,7 +67,7 @@ public class WebsocketRouteTest extends WebsocketCamelRouterTestSupport {
 
     @Test
     void testWebsocketSingleClientForReader() throws Exception {
-        TestClient wsclient = new TestClient("ws://localhost:" + PORT + "/hola3");
+        WebsocketTestClient wsclient = new WebsocketTestClient("ws://localhost:" + PORT + "/hola3");
         wsclient.connect();
 
         wsclient.sendTextMessage("Cerveza");
@@ -80,7 +81,7 @@ public class WebsocketRouteTest extends WebsocketCamelRouterTestSupport {
 
     @Test
     void testWebsocketSingleClientForInputStream() throws Exception {
-        TestClient wsclient = new TestClient("ws://localhost:" + PORT + "/hola3");
+        WebsocketTestClient wsclient = new WebsocketTestClient("ws://localhost:" + PORT + "/hola3");
         wsclient.connect();
 
         wsclient.sendBytesMessage("Cerveza".getBytes("UTF-8"));
@@ -94,8 +95,8 @@ public class WebsocketRouteTest extends WebsocketCamelRouterTestSupport {
 
     @Test
     void testWebsocketBroadcastClient() throws Exception {
-        TestClient wsclient1 = new TestClient("ws://localhost:" + PORT + "/hola2", 2);
-        TestClient wsclient2 = new TestClient("ws://localhost:" + PORT + "/hola2", 2);
+        WebsocketTestClient wsclient1 = new WebsocketTestClient("ws://localhost:" + PORT + "/hola2", 2);
+        WebsocketTestClient wsclient2 = new WebsocketTestClient("ws://localhost:" + PORT + "/hola2", 2);
         wsclient1.connect();
         wsclient2.connect();
 
@@ -122,7 +123,7 @@ public class WebsocketRouteTest extends WebsocketCamelRouterTestSupport {
 
     @Test
     void testWebsocketEventsResendingDisabled() throws Exception {
-        TestClient wsclient = new TestClient("ws://localhost:" + PORT + "/hola4");
+        WebsocketTestClient wsclient = new WebsocketTestClient("ws://localhost:" + PORT + "/hola4");
         wsclient.connect();
         assertFalse(wsclient.await(10));
         wsclient.close();
diff --git a/components/camel-atmosphere-websocket/src/test/java/org/apache/camel/component/atmosphere/websocket/WebsocketRouteWithInitParamTest.java b/components/camel-atmosphere-websocket/src/test/java/org/apache/camel/component/atmosphere/websocket/WebsocketRouteWithInitParamTest.java
index 3b0a192b492..f5c420ee0e4 100644
--- a/components/camel-atmosphere-websocket/src/test/java/org/apache/camel/component/atmosphere/websocket/WebsocketRouteWithInitParamTest.java
+++ b/components/camel-atmosphere-websocket/src/test/java/org/apache/camel/component/atmosphere/websocket/WebsocketRouteWithInitParamTest.java
@@ -26,6 +26,7 @@ import java.util.concurrent.ExecutionException;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.infra.common.http.WebsocketTestClient;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
@@ -41,7 +42,7 @@ public class WebsocketRouteWithInitParamTest extends WebsocketCamelRouterWithIni
     private static Map<String, String> connectionKeyUserMap = new HashMap<>();
 
     private void runtTest(String s) throws InterruptedException, ExecutionException, IOException {
-        TestClient wsclient = new TestClient("ws://localhost:" + PORT + s);
+        WebsocketTestClient wsclient = new WebsocketTestClient("ws://localhost:" + PORT + s);
         wsclient.connect();
         wsclient.close();
     }
@@ -62,9 +63,9 @@ public class WebsocketRouteWithInitParamTest extends WebsocketCamelRouterWithIni
         final int awaitTime = 5;
         connectionKeyUserMap.clear();
 
-        TestClient wsclient1 = new TestClient("ws://localhost:" + PORT + "/hola2", 2);
-        TestClient wsclient2 = new TestClient("ws://localhost:" + PORT + "/hola2", 2);
-        TestClient wsclient3 = new TestClient("ws://localhost:" + PORT + "/hola2", 2);
+        WebsocketTestClient wsclient1 = new WebsocketTestClient("ws://localhost:" + PORT + "/hola2", 2);
+        WebsocketTestClient wsclient2 = new WebsocketTestClient("ws://localhost:" + PORT + "/hola2", 2);
+        WebsocketTestClient wsclient3 = new WebsocketTestClient("ws://localhost:" + PORT + "/hola2", 2);
 
         wsclient1.connect();
         wsclient1.await(awaitTime);
@@ -109,9 +110,9 @@ public class WebsocketRouteWithInitParamTest extends WebsocketCamelRouterWithIni
         final int awaitTime = 5;
         connectionKeyUserMap.clear();
 
-        TestClient wsclient1 = new TestClient("ws://localhost:" + PORT + "/hola3", 2);
-        TestClient wsclient2 = new TestClient("ws://localhost:" + PORT + "/hola3", 2);
-        TestClient wsclient3 = new TestClient("ws://localhost:" + PORT + "/hola3", 2);
+        WebsocketTestClient wsclient1 = new WebsocketTestClient("ws://localhost:" + PORT + "/hola3", 2);
+        WebsocketTestClient wsclient2 = new WebsocketTestClient("ws://localhost:" + PORT + "/hola3", 2);
+        WebsocketTestClient wsclient3 = new WebsocketTestClient("ws://localhost:" + PORT + "/hola3", 2);
 
         wsclient1.connect();
         wsclient1.await(awaitTime);
diff --git a/components/camel-atmosphere-websocket/src/test/java/org/apache/camel/component/atmosphere/websocket/TestClient.java b/test-infra/camel-test-infra-common/src/test/java/org/apache/camel/test/infra/common/http/WebsocketTestClient.java
similarity index 94%
rename from components/camel-atmosphere-websocket/src/test/java/org/apache/camel/component/atmosphere/websocket/TestClient.java
rename to test-infra/camel-test-infra-common/src/test/java/org/apache/camel/test/infra/common/http/WebsocketTestClient.java
index 236c506e99d..d5ab1bc3003 100644
--- a/components/camel-atmosphere-websocket/src/test/java/org/apache/camel/component/atmosphere/websocket/TestClient.java
+++ b/test-infra/camel-test-infra-common/src/test/java/org/apache/camel/test/infra/common/http/WebsocketTestClient.java
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.component.atmosphere.websocket;
+package org.apache.camel.test.infra.common.http;
 
 import java.net.URI;
 import java.net.http.HttpClient;
@@ -29,8 +29,8 @@ import java.util.concurrent.TimeUnit;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class TestClient {
-    private static final Logger LOG = LoggerFactory.getLogger(TestClient.class);
+public class WebsocketTestClient {
+    private static final Logger LOG = LoggerFactory.getLogger(WebsocketTestClient.class);
 
     private final List<Object> received;
     private final HttpClient modernClient;
@@ -39,11 +39,11 @@ public class TestClient {
     private CountDownLatch latch;
     private WebSocket websocket;
 
-    public TestClient(String url) {
+    public WebsocketTestClient(String url) {
         this(url, 1);
     }
 
-    public TestClient(String url, int count) {
+    public WebsocketTestClient(String url, int count) {
         this.received = new ArrayList<>();
         this.latch = new CountDownLatch(count);
         this.modernClient = HttpClient.newHttpClient();