Author: markt
Date: Sat Feb 9 20:38:46 2013
New Revision: 1444429
URL: http://svn.apache.org/r1444429
Log:
More refactoring for re-use
Added:
tomcat/trunk/test/org/apache/tomcat/websocket/TesterEchoServer.java
- copied, changed from r1444422,
tomcat/trunk/test/org/apache/tomcat/websocket/TesterEcho.java
tomcat/trunk/test/org/apache/tomcat/websocket/TesterSingleMessageClient.java
(with props)
Removed:
tomcat/trunk/test/org/apache/tomcat/websocket/TesterEcho.java
Modified:
tomcat/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java
Modified:
tomcat/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java?rev=1444429&r1=1444428&r2=1444429&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java
(original)
+++ tomcat/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java
Sat Feb 9 20:38:46 2013
@@ -19,7 +19,6 @@ package org.apache.tomcat.websocket;
import java.net.URI;
import java.nio.ByteBuffer;
import java.util.List;
-import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
@@ -27,7 +26,6 @@ import java.util.concurrent.TimeUnit;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
-import javax.websocket.CloseReason;
import javax.websocket.ContainerProvider;
import javax.websocket.DefaultClientConfiguration;
import javax.websocket.DeploymentException;
@@ -47,6 +45,10 @@ import org.apache.catalina.Context;
import org.apache.catalina.startup.Tomcat;
import org.apache.catalina.startup.TomcatBaseTest;
import org.apache.coyote.http11.Http11Protocol;
+import org.apache.tomcat.websocket.TesterSingleMessageClient.BasicBinary;
+import org.apache.tomcat.websocket.TesterSingleMessageClient.BasicHandler;
+import org.apache.tomcat.websocket.TesterSingleMessageClient.BasicText;
+import org.apache.tomcat.websocket.TesterSingleMessageClient.TesterEndpoint;
import org.apache.tomcat.websocket.server.ServerContainerImpl;
import org.apache.tomcat.websocket.server.WsListener;
@@ -73,7 +75,7 @@ public class TestWsWebSocketContainer ex
// Must have a real docBase - just use temp
Context ctx =
tomcat.addContext("", System.getProperty("java.io.tmpdir"));
- ctx.addApplicationListener(TesterEcho.Config.class.getName());
+ ctx.addApplicationListener(TesterEchoServer.Config.class.getName());
tomcat.start();
@@ -81,9 +83,9 @@ public class TestWsWebSocketContainer ex
ContainerProvider.createClientContainer();
Session wsSession = wsContainer.connectToServer(TesterEndpoint.class,
new DefaultClientConfiguration(), new URI("http://localhost:" +
- getPort() + TesterEcho.Config.PATH_ASYNC));
+ getPort() + TesterEchoServer.Config.PATH_ASYNC));
CountDownLatch latch = new CountDownLatch(1);
- TesterMessageHandlerText handler = new TesterMessageHandlerText(latch);
+ BasicText handler = new BasicText(latch);
wsSession.addMessageHandler(handler);
wsSession.getRemote().sendString(MESSAGE_STRING_1);
@@ -103,7 +105,7 @@ public class TestWsWebSocketContainer ex
// Must have a real docBase - just use temp
Context ctx =
tomcat.addContext("", System.getProperty("java.io.tmpdir"));
- ctx.addApplicationListener(TesterEcho.Config.class.getName());
+ ctx.addApplicationListener(TesterEchoServer.Config.class.getName());
tomcat.start();
@@ -111,7 +113,7 @@ public class TestWsWebSocketContainer ex
ContainerProvider.createClientContainer();
wsContainer.connectToServer(TesterEndpoint.class,
new DefaultClientConfiguration(), new URI("ftp://localhost:" +
- getPort() + TesterEcho.Config.PATH_ASYNC));
+ getPort() + TesterEchoServer.Config.PATH_ASYNC));
}
@@ -121,7 +123,7 @@ public class TestWsWebSocketContainer ex
// Must have a real docBase - just use temp
Context ctx =
tomcat.addContext("", System.getProperty("java.io.tmpdir"));
- ctx.addApplicationListener(TesterEcho.Config.class.getName());
+ ctx.addApplicationListener(TesterEchoServer.Config.class.getName());
tomcat.start();
@@ -129,7 +131,7 @@ public class TestWsWebSocketContainer ex
ContainerProvider.createClientContainer();
wsContainer.connectToServer(TesterEndpoint.class,
new DefaultClientConfiguration(),
- new URI("http://" + TesterEcho.Config.PATH_ASYNC));
+ new URI("http://" + TesterEchoServer.Config.PATH_ASYNC));
}
@@ -188,7 +190,7 @@ public class TestWsWebSocketContainer ex
// Must have a real docBase - just use temp
Context ctx =
tomcat.addContext("", System.getProperty("java.io.tmpdir"));
- ctx.addApplicationListener(TesterEcho.Config.class.getName());
+ ctx.addApplicationListener(TesterEchoServer.Config.class.getName());
WebSocketContainer wsContainer =
ContainerProvider.createClientContainer();
@@ -217,14 +219,14 @@ public class TestWsWebSocketContainer ex
Session wsSession = wsContainer.connectToServer(TesterEndpoint.class,
new DefaultClientConfiguration(), new URI("http://localhost:" +
- getPort() + TesterEcho.Config.PATH_BASIC));
- TesterMessageHandler<?> handler;
+ getPort() + TesterEchoServer.Config.PATH_BASIC));
+ BasicHandler<?> handler;
CountDownLatch latch = new CountDownLatch(1);
wsSession.getUserProperties().put("latch", latch);
if (isTextMessage) {
- handler = new TesterMessageHandlerText(latch);
+ handler = new BasicText(latch);
} else {
- handler = new TesterMessageHandlerBinary(latch);
+ handler = new BasicBinary(latch);
}
wsSession.addMessageHandler(handler);
@@ -400,90 +402,6 @@ public class TestWsWebSocketContainer ex
}
- private abstract static class TesterMessageHandler<T>
- implements MessageHandler.Basic<T> {
-
- private final CountDownLatch latch;
-
- private final List<T> messages = new CopyOnWriteArrayList<>();
-
- public TesterMessageHandler(CountDownLatch latch) {
- this.latch = latch;
- }
-
- public CountDownLatch getLatch() {
- return latch;
- }
-
- public List<T> getMessages() {
- return messages;
- }
- }
-
- private static class TesterMessageHandlerText
- extends TesterMessageHandler<String> {
-
-
- public TesterMessageHandlerText(CountDownLatch latch) {
- super(latch);
- }
-
- @Override
- public void onMessage(String message) {
- getMessages().add(message);
- if (getLatch() != null) {
- getLatch().countDown();
- }
- }
- }
-
-
- private static class TesterMessageHandlerBinary
- extends TesterMessageHandler<ByteBuffer> {
-
- public TesterMessageHandlerBinary(CountDownLatch latch) {
- super(latch);
- }
-
- @Override
- public void onMessage(ByteBuffer message) {
- getMessages().add(message);
- if (getLatch() != null) {
- getLatch().countDown();
- }
- }
- }
-
-
- public static class TesterEndpoint extends Endpoint {
-
- @Override
- public void onClose(Session session, CloseReason closeReason) {
- clearLatch(session);
- }
-
- @Override
- public void onError(Session session, Throwable throwable) {
- clearLatch(session);
- }
-
- private void clearLatch(Session session) {
- CountDownLatch latch =
- (CountDownLatch) session.getUserProperties().get("latch");
- if (latch != null) {
- while (latch.getCount() > 0) {
- latch.countDown();
- }
- }
- }
-
- @Override
- public void onOpen(Session session, EndpointConfiguration config) {
- // NO-OP
- }
- }
-
-
public static class BlockingConfig implements ServletContextListener {
public static final String PATH = "/block";
Copied: tomcat/trunk/test/org/apache/tomcat/websocket/TesterEchoServer.java
(from r1444422, tomcat/trunk/test/org/apache/tomcat/websocket/TesterEcho.java)
URL:
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/websocket/TesterEchoServer.java?p2=tomcat/trunk/test/org/apache/tomcat/websocket/TesterEchoServer.java&p1=tomcat/trunk/test/org/apache/tomcat/websocket/TesterEcho.java&r1=1444422&r2=1444429&rev=1444429&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/websocket/TesterEcho.java (original)
+++ tomcat/trunk/test/org/apache/tomcat/websocket/TesterEchoServer.java Sat Feb
9 20:38:46 2013
@@ -26,7 +26,7 @@ import javax.websocket.WebSocketMessage;
import org.apache.tomcat.websocket.server.ServerContainerImpl;
-public class TesterEcho {
+public class TesterEchoServer {
public static class Config implements ServletContextListener {
Added:
tomcat/trunk/test/org/apache/tomcat/websocket/TesterSingleMessageClient.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/websocket/TesterSingleMessageClient.java?rev=1444429&view=auto
==============================================================================
---
tomcat/trunk/test/org/apache/tomcat/websocket/TesterSingleMessageClient.java
(added)
+++
tomcat/trunk/test/org/apache/tomcat/websocket/TesterSingleMessageClient.java
Sat Feb 9 20:38:46 2013
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tomcat.websocket;
+
+import java.nio.ByteBuffer;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.CountDownLatch;
+
+import javax.websocket.CloseReason;
+import javax.websocket.Endpoint;
+import javax.websocket.EndpointConfiguration;
+import javax.websocket.MessageHandler;
+import javax.websocket.Session;
+
+public class TesterSingleMessageClient {
+
+ public static class TesterEndpoint extends Endpoint {
+
+ @Override
+ public void onClose(Session session, CloseReason closeReason) {
+ clearLatch(session);
+ }
+
+ @Override
+ public void onError(Session session, Throwable throwable) {
+ clearLatch(session);
+ }
+
+ private void clearLatch(Session session) {
+ CountDownLatch latch =
+ (CountDownLatch) session.getUserProperties().get("latch");
+ if (latch != null) {
+ while (latch.getCount() > 0) {
+ latch.countDown();
+ }
+ }
+ }
+
+ @Override
+ public void onOpen(Session session, EndpointConfiguration config) {
+ // NO-OP
+ }
+ }
+
+
+ public abstract static class BasicHandler<T>
+ implements MessageHandler.Basic<T> {
+
+ private final CountDownLatch latch;
+
+ private final List<T> messages = new CopyOnWriteArrayList<>();
+
+ public BasicHandler(CountDownLatch latch) {
+ this.latch = latch;
+ }
+
+ public CountDownLatch getLatch() {
+ return latch;
+ }
+
+ public List<T> getMessages() {
+ return messages;
+ }
+ }
+
+ public static class BasicBinary extends BasicHandler<ByteBuffer> {
+
+ public BasicBinary(CountDownLatch latch) {
+ super(latch);
+ }
+
+ @Override
+ public void onMessage(ByteBuffer message) {
+ getMessages().add(message);
+ if (getLatch() != null) {
+ getLatch().countDown();
+ }
+ }
+ }
+
+ public static class BasicText extends BasicHandler<String> {
+
+
+ public BasicText(CountDownLatch latch) {
+ super(latch);
+ }
+
+ @Override
+ public void onMessage(String message) {
+ getMessages().add(message);
+ if (getLatch() != null) {
+ getLatch().countDown();
+ }
+ }
+ }
+}
Propchange:
tomcat/trunk/test/org/apache/tomcat/websocket/TesterSingleMessageClient.java
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]