Author: kkolinko Date: Sat Mar 15 15:18:42 2014 New Revision: 1577877 URL: http://svn.apache.org/r1577877 Log: Backport of r1577073 from tomcat/trunk: Split the test SSL/non-SSL.
Added: tomcat/tc7.0.x/trunk/test/org/apache/tomcat/websocket/TestWebSocketFrameClientSSL.java - copied, changed from r1577876, tomcat/trunk/test/org/apache/tomcat/websocket/TestWebSocketFrameClientSSL.java Modified: tomcat/tc7.0.x/trunk/test/org/apache/tomcat/websocket/TestWebSocketFrameClient.java Modified: tomcat/tc7.0.x/trunk/test/org/apache/tomcat/websocket/TestWebSocketFrameClient.java URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/tomcat/websocket/TestWebSocketFrameClient.java?rev=1577877&r1=1577876&r2=1577877&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/test/org/apache/tomcat/websocket/TestWebSocketFrameClient.java (original) +++ tomcat/tc7.0.x/trunk/test/org/apache/tomcat/websocket/TestWebSocketFrameClient.java Sat Mar 15 15:18:42 2014 @@ -16,16 +16,13 @@ */ package org.apache.tomcat.websocket; -import java.io.File; import java.net.URI; -import java.net.URL; import java.util.Queue; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import javax.websocket.ClientEndpointConfig; import javax.websocket.ContainerProvider; -import javax.websocket.MessageHandler; import javax.websocket.Session; import javax.websocket.WebSocketContainer; @@ -37,9 +34,7 @@ import org.apache.catalina.deploy.Applic import org.apache.catalina.servlets.DefaultServlet; import org.apache.catalina.startup.Tomcat; import org.apache.catalina.startup.TomcatBaseTest; -import org.apache.tomcat.util.net.TesterSupport; import org.apache.tomcat.websocket.TesterMessageCountClient.BasicText; -import org.apache.tomcat.websocket.TesterMessageCountClient.SleepingText; import org.apache.tomcat.websocket.TesterMessageCountClient.TesterProgrammaticEndpoint; public class TestWebSocketFrameClient extends TomcatBaseTest { @@ -87,127 +82,4 @@ public class TestWebSocketFrameClient ex Assert.assertEquals(TesterFirehoseServer.MESSAGE, message); } } - - - @Test - public void testConnectToServerEndpointSSL() throws Exception { - - Tomcat tomcat = getTomcatInstance(); - // Must have a real docBase - just use temp - Context ctx = - tomcat.addContext("", System.getProperty("java.io.tmpdir")); - ctx.addApplicationListener(new ApplicationListener( - TesterFirehoseServer.Config.class.getName(), false)); - Tomcat.addServlet(ctx, "default", new DefaultServlet()); - ctx.addServletMapping("/", "default"); - - - TesterSupport.initSsl(tomcat); - - tomcat.start(); - - WebSocketContainer wsContainer = - ContainerProvider.getWebSocketContainer(); - ClientEndpointConfig clientEndpointConfig = - ClientEndpointConfig.Builder.create().build(); - URL truststoreUrl = this.getClass().getClassLoader().getResource( - "org/apache/tomcat/util/net/ca.jks"); - File truststoreFile = new File(truststoreUrl.toURI()); - clientEndpointConfig.getUserProperties().put( - WsWebSocketContainer.SSL_TRUSTSTORE_PROPERTY, - truststoreFile.getAbsolutePath()); - Session wsSession = wsContainer.connectToServer( - TesterProgrammaticEndpoint.class, - clientEndpointConfig, - new URI("wss://localhost:" + getPort() + - 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); - } - } - - - @Test - public void testBug56032() throws Exception { - // TODO Investigate options to get this test to pass with the HTTP BIO - // connector. - if (getTomcatInstance().getConnector().getProtocol().equals("HTTP/1.1")) { - return; - } - - Tomcat tomcat = getTomcatInstance(); - // Must have a real docBase - just use temp - Context ctx = - tomcat.addContext("", System.getProperty("java.io.tmpdir")); - ctx.addApplicationListener(new ApplicationListener( - TesterFirehoseServer.Config.class.getName(), false)); - Tomcat.addServlet(ctx, "default", new DefaultServlet()); - ctx.addServletMapping("/", "default"); - - TesterSupport.initSsl(tomcat); - - tomcat.start(); - - WebSocketContainer wsContainer = - ContainerProvider.getWebSocketContainer(); - ClientEndpointConfig clientEndpointConfig = - ClientEndpointConfig.Builder.create().build(); - clientEndpointConfig.getUserProperties().put( - WsWebSocketContainer.SSL_TRUSTSTORE_PROPERTY, - "test/org/apache/tomcat/util/net/ca.jks"); - Session wsSession = wsContainer.connectToServer( - TesterProgrammaticEndpoint.class, - clientEndpointConfig, - new URI("wss://localhost:" + getPort() + - TesterFirehoseServer.Config.PATH)); - - // Process incoming messages very slowly - MessageHandler handler = new SleepingText(5000); - wsSession.addMessageHandler(handler); - wsSession.getBasicRemote().sendText("Hello"); - - // Wait long enough for the buffers to fill and the send to timeout - int count = 0; - int limit = TesterFirehoseServer.WAIT_TIME_MILLIS / 100; - - System.err.println("Waiting for server to report an error"); - while (TesterFirehoseServer.Endpoint.getErrorCount() == 0 && count < limit) { - Thread.sleep(100); - count ++; - } - - if (TesterFirehoseServer.Endpoint.getErrorCount() == 0) { - Assert.fail("No error reported by Endpoint when timeout was expected"); - } - - // Wait up to another 20 seconds for the connection to be closed - System.err.println("Waiting for connection to be closed"); - count = 0; - limit = (TesterFirehoseServer.SEND_TIME_OUT_MILLIS * 4) / 100; - while (TesterFirehoseServer.Endpoint.getOpenConnectionCount() != 0 && count < limit) { - Thread.sleep(100); - count ++; - } - - int openConnectionCount = TesterFirehoseServer.Endpoint.getOpenConnectionCount(); - if (openConnectionCount != 0) { - Assert.fail("There are [" + openConnectionCount + "] connections still open"); - } - } } Copied: tomcat/tc7.0.x/trunk/test/org/apache/tomcat/websocket/TestWebSocketFrameClientSSL.java (from r1577876, tomcat/trunk/test/org/apache/tomcat/websocket/TestWebSocketFrameClientSSL.java) URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/tomcat/websocket/TestWebSocketFrameClientSSL.java?p2=tomcat/tc7.0.x/trunk/test/org/apache/tomcat/websocket/TestWebSocketFrameClientSSL.java&p1=tomcat/trunk/test/org/apache/tomcat/websocket/TestWebSocketFrameClientSSL.java&r1=1577876&r2=1577877&rev=1577877&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/tomcat/websocket/TestWebSocketFrameClientSSL.java (original) +++ tomcat/tc7.0.x/trunk/test/org/apache/tomcat/websocket/TestWebSocketFrameClientSSL.java Sat Mar 15 15:18:42 2014 @@ -16,7 +16,9 @@ */ package org.apache.tomcat.websocket; +import java.io.File; import java.net.URI; +import java.net.URL; import java.util.Queue; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -28,14 +30,13 @@ import javax.websocket.Session; import javax.websocket.WebSocketContainer; import org.junit.Assert; -import org.junit.Assume; import org.junit.Test; import org.apache.catalina.Context; +import org.apache.catalina.deploy.ApplicationListener; import org.apache.catalina.servlets.DefaultServlet; import org.apache.catalina.startup.Tomcat; import org.apache.catalina.startup.TomcatBaseTest; -import org.apache.tomcat.util.descriptor.web.ApplicationListener; import org.apache.tomcat.util.net.TesterSupport; import org.apache.tomcat.websocket.TesterMessageCountClient.BasicText; import org.apache.tomcat.websocket.TesterMessageCountClient.SleepingText; @@ -45,15 +46,7 @@ public class TestWebSocketFrameClientSSL @Test - public void testConnectToServerEndpoint() throws Exception { - // FIXME Skip NIO2 since its CPU use on non blocking writes to - // do the encryption inline apparently messes up - // the websockets writes, which deadlock until timedout. - // Reenable later when investigated and fixed. - Assume.assumeFalse( - "Skip this test on NIO2. FIXME: investigate.", - getTomcatInstance().getConnector().getProtocol() - .equals("org.apache.coyote.http11.Http11Nio2Protocol")); + public void testConnectToServerEndpointSSL() throws Exception { Tomcat tomcat = getTomcatInstance(); // Must have a real docBase - just use temp @@ -64,6 +57,7 @@ public class TestWebSocketFrameClientSSL Tomcat.addServlet(ctx, "default", new DefaultServlet()); ctx.addServletMapping("/", "default"); + TesterSupport.initSsl(tomcat); tomcat.start(); @@ -72,9 +66,12 @@ public class TestWebSocketFrameClientSSL ContainerProvider.getWebSocketContainer(); ClientEndpointConfig clientEndpointConfig = ClientEndpointConfig.Builder.create().build(); + URL truststoreUrl = this.getClass().getClassLoader().getResource( + "org/apache/tomcat/util/net/ca.jks"); + File truststoreFile = new File(truststoreUrl.toURI()); clientEndpointConfig.getUserProperties().put( WsWebSocketContainer.SSL_TRUSTSTORE_PROPERTY, - "test/org/apache/tomcat/util/net/ca.jks"); + truststoreFile.getAbsolutePath()); Session wsSession = wsContainer.connectToServer( TesterProgrammaticEndpoint.class, clientEndpointConfig, @@ -106,10 +103,9 @@ public class TestWebSocketFrameClientSSL public void testBug56032() throws Exception { // TODO Investigate options to get this test to pass with the HTTP BIO // connector. - Assume.assumeFalse( - "Skip this test on BIO. TODO: investigate options to make it pass with HTTP BIO connector", - getTomcatInstance().getConnector().getProtocol() - .equals("org.apache.coyote.http11.Http11Protocol")); + if (getTomcatInstance().getConnector().getProtocol().equals("HTTP/1.1")) { + return; + } Tomcat tomcat = getTomcatInstance(); // Must have a real docBase - just use temp @@ -146,7 +142,7 @@ public class TestWebSocketFrameClientSSL int count = 0; int limit = TesterFirehoseServer.WAIT_TIME_MILLIS / 100; - System.out.println("Waiting for server to report an error"); + System.err.println("Waiting for server to report an error"); while (TesterFirehoseServer.Endpoint.getErrorCount() == 0 && count < limit) { Thread.sleep(100); count ++; @@ -156,11 +152,10 @@ public class TestWebSocketFrameClientSSL Assert.fail("No error reported by Endpoint when timeout was expected"); } - // Wait up to another 10 seconds for the connection to be closed - - // should be a lot faster. - System.out.println("Waiting for connection to be closed"); + // Wait up to another 20 seconds for the connection to be closed + System.err.println("Waiting for connection to be closed"); count = 0; - limit = (TesterFirehoseServer.SEND_TIME_OUT_MILLIS * 2) / 100; + limit = (TesterFirehoseServer.SEND_TIME_OUT_MILLIS * 4) / 100; while (TesterFirehoseServer.Endpoint.getOpenConnectionCount() != 0 && count < limit) { Thread.sleep(100); count ++; @@ -171,4 +166,5 @@ public class TestWebSocketFrameClientSSL Assert.fail("There are [" + openConnectionCount + "] connections still open"); } } + } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org