Author: markt
Date: Fri Jan 10 11:03:33 2014
New Revision: 1557081
URL: http://svn.apache.org/r1557081
Log:
Add tests for setting null and duplicate read and write listeners for
non-blocking IO.
Modified:
tomcat/trunk/test/org/apache/coyote/http11/upgrade/TestUpgrade.java
Modified: tomcat/trunk/test/org/apache/coyote/http11/upgrade/TestUpgrade.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/coyote/http11/upgrade/TestUpgrade.java?rev=1557081&r1=1557080&r2=1557081&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/coyote/http11/upgrade/TestUpgrade.java
(original)
+++ tomcat/trunk/test/org/apache/coyote/http11/upgrade/TestUpgrade.java Fri Jan
10 11:03:33 2014
@@ -23,6 +23,7 @@ import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
+import java.io.Reader;
import java.io.Writer;
import java.net.Socket;
@@ -72,6 +73,37 @@ public class TestUpgrade extends TomcatB
doTestMessages(EchoNonBlocking.class);
}
+ @Test
+ public void testSetNullReadListener() throws Exception {
+ doTestCheckClosed(SetNullReadListener.class);
+ }
+
+ @Test
+ public void testSetNullWriteListener() throws Exception {
+ doTestCheckClosed(SetNullWriteListener.class);
+ }
+
+ @Test
+ public void testSetReadListenerTwice() throws Exception {
+ doTestCheckClosed(SetReadListenerTwice.class);
+ }
+
+ @Test
+ public void testSetWriteListenerTwice() throws Exception {
+ doTestCheckClosed(SetWriteListenerTwice.class);
+ }
+
+ private void doTestCheckClosed(
+ Class<? extends HttpUpgradeHandler> upgradeHandlerClass)
+ throws Exception {
+ UpgradeConnection conn = doUpgrade(upgradeHandlerClass);
+
+ Reader r = conn.getReader();
+ int c = r.read();
+
+ Assert.assertEquals(-1, c);
+ }
+
private void doTestMessages (
Class<? extends HttpUpgradeHandler> upgradeHandlerClass)
throws Exception {
@@ -116,7 +148,7 @@ public class TestUpgrade extends TomcatB
Socket socket =
SocketFactory.getDefault().createSocket("localhost",
getPort());
- socket.setSoTimeout(10000);
+ socket.setSoTimeout(5000);
InputStream is = socket.getInputStream();
OutputStream os = socket.getOutputStream();
@@ -252,6 +284,96 @@ public class TestUpgrade extends TomcatB
}
+ public static class SetNullReadListener implements HttpUpgradeHandler {
+
+ @Override
+ public void init(WebConnection connection) {
+ ServletInputStream sis;
+ try {
+ sis = connection.getInputStream();
+ } catch (IOException ioe) {
+ throw new IllegalStateException(ioe);
+ }
+ sis.setReadListener(null);
+ }
+
+ @Override
+ public void destroy() {
+ // NO-OP
+ }
+ }
+
+
+ public static class SetNullWriteListener implements HttpUpgradeHandler {
+
+ @Override
+ public void init(WebConnection connection) {
+ ServletOutputStream sos;
+ try {
+ sos = connection.getOutputStream();
+ } catch (IOException ioe) {
+ throw new IllegalStateException(ioe);
+ }
+ sos.setWriteListener(null);
+ }
+
+ @Override
+ public void destroy() {
+ // NO-OP
+ }
+ }
+
+
+ public static class SetReadListenerTwice implements HttpUpgradeHandler {
+
+ @Override
+ public void init(WebConnection connection) {
+ ServletInputStream sis;
+ ServletOutputStream sos;
+ try {
+ sis = connection.getInputStream();
+ sos = connection.getOutputStream();
+ } catch (IOException ioe) {
+ throw new IllegalStateException(ioe);
+ }
+ sos.setWriteListener(new NoOpWriteListener());
+ ReadListener rl = new NoOpReadListener();
+ sis.setReadListener(rl);
+ sis.setReadListener(rl);
+ }
+
+ @Override
+ public void destroy() {
+ // NO-OP
+ }
+ }
+
+
+ public static class SetWriteListenerTwice implements HttpUpgradeHandler {
+
+ @Override
+ public void init(WebConnection connection) {
+ ServletInputStream sis;
+ ServletOutputStream sos;
+ try {
+ sis = connection.getInputStream();
+ sos = connection.getOutputStream();
+ } catch (IOException ioe) {
+ throw new IllegalStateException(ioe);
+ }
+ sis.setReadListener(new NoOpReadListener());
+ WriteListener wl = new NoOpWriteListener();
+ sos.setWriteListener(wl);
+ sos.setWriteListener(wl);
+ }
+
+ @Override
+ public void destroy() {
+ // NO-OP
+ }
+ }
+
+
private static class NoOpReadListener implements ReadListener {
@Override
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]