This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 7.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/7.0.x by this push: new d70a569 Add a standalone server and client for testing connection failures d70a569 is described below commit d70a569f2759138847d0d9448f11694d04aaa6c8 Author: Mark Thomas <ma...@apache.org> AuthorDate: Tue Apr 9 15:51:46 2019 +0100 Add a standalone server and client for testing connection failures --- .../tomcat/websocket/TesterFirehoseServer.java | 100 ++++++++++++++++++++- 1 file changed, 99 insertions(+), 1 deletion(-) diff --git a/test/org/apache/tomcat/websocket/TesterFirehoseServer.java b/test/org/apache/tomcat/websocket/TesterFirehoseServer.java index a4f7fff..222ed05 100644 --- a/test/org/apache/tomcat/websocket/TesterFirehoseServer.java +++ b/test/org/apache/tomcat/websocket/TesterFirehoseServer.java @@ -17,9 +17,18 @@ package org.apache.tomcat.websocket; import java.io.IOException; +import java.net.URI; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Queue; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import javax.servlet.ServletContextEvent; +import javax.websocket.ClientEndpointConfig; +import javax.websocket.ContainerProvider; import javax.websocket.DeploymentException; import javax.websocket.OnClose; import javax.websocket.OnError; @@ -27,11 +36,20 @@ import javax.websocket.OnMessage; import javax.websocket.OnOpen; import javax.websocket.RemoteEndpoint.Basic; import javax.websocket.Session; +import javax.websocket.WebSocketContainer; +import javax.websocket.ClientEndpointConfig.Configurator; import javax.websocket.server.ServerContainer; import javax.websocket.server.ServerEndpoint; +import org.apache.catalina.Context; +import org.apache.catalina.servlets.DefaultServlet; +import org.apache.catalina.startup.Tomcat; +import org.apache.catalina.startup.TomcatBaseTest; +import org.apache.tomcat.websocket.TesterMessageCountClient.BasicText; +import org.apache.tomcat.websocket.TesterMessageCountClient.TesterProgrammaticEndpoint; import org.apache.tomcat.websocket.server.Constants; import org.apache.tomcat.websocket.server.WsContextListener; +import org.junit.Assert; /** * Sends {@link #MESSAGE_COUNT} messages of size {@link #MESSAGE_SIZE} bytes as @@ -39,7 +57,7 @@ import org.apache.tomcat.websocket.server.WsContextListener; */ public class TesterFirehoseServer { - public static final int MESSAGE_COUNT = 100000; + public static final int MESSAGE_COUNT = 1000000; public static final String MESSAGE; public static final int MESSAGE_SIZE = 1024; public static final int WAIT_TIME_MILLIS = 60000; @@ -139,4 +157,84 @@ public class TesterFirehoseServer { openConnectionCount.decrementAndGet(); } } + + + /* + * Run as a stand-alone server for testing over a real network + */ + public static class Standalone extends TomcatBaseTest { + + public static void main(String... args) throws Exception { + Standalone s = new Standalone(); + s.start(); + } + + public void start() throws Exception { + setUpPerTestClass(); + setUp(); + Tomcat tomcat = getTomcatInstance(); + // No file system docBase required + Context ctx = tomcat.addContext("", null); + ctx.addApplicationListener(TesterFirehoseServer.Config.class.getName()); + Tomcat.addServlet(ctx, "default", new DefaultServlet()); + ctx.addServletMapping("/", "default"); + + tomcat.start(); + + while (true) { + Thread.sleep(1000); + } + } + } + + + /* + * Run as a stand-alone client for testing over a real network. + * + * args[0] is host:port + */ + public static class Client { + + public static void main(String... args) throws Exception { + + WebSocketContainer wsContainer = ContainerProvider.getWebSocketContainer(); + + // BZ 62596 + final StringBuilder dummyValue = new StringBuilder(4000); + for (int i = 0; i < 4000; i++) { + dummyValue.append('A'); + } + ClientEndpointConfig clientEndpointConfig = + ClientEndpointConfig.Builder.create().configurator(new Configurator() { + @Override + public void beforeRequest(Map<String, List<String>> headers) { + headers.put("Dummy", Collections.singletonList(dummyValue.toString())); + super.beforeRequest(headers); + } + }).build(); + + Session wsSession = wsContainer.connectToServer( + TesterProgrammaticEndpoint.class, + clientEndpointConfig, + new URI("ws://" + args[0] + TesterFirehoseServer.Config.PATH)); + CountDownLatch latch = new CountDownLatch(TesterFirehoseServer.MESSAGE_COUNT); + BasicText handler = new BasicText(latch); + wsSession.addMessageHandler(handler); + wsSession.getBasicRemote().sendText("Hello"); + + System.out.println("Sent Hello message, waiting for data"); + + // Ignore the latch result as the message count test below will tell us + // if the right number of messages arrived + handler.getLatch().await(TesterFirehoseServer.WAIT_TIME_MILLIS, + TimeUnit.MILLISECONDS); + + Queue<String> messages = handler.getMessages(); + Assert.assertEquals( + TesterFirehoseServer.MESSAGE_COUNT, messages.size()); + for (String message : messages) { + Assert.assertEquals(TesterFirehoseServer.MESSAGE, message); + } + } + } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org