You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2019/07/24 14:51:31 UTC

[tomcat] 11/11: Align with 8.5.x to fix failing test

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

commit 7bbfa2c5b3fe75958266d44d2e496730d96647aa
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Jul 24 12:23:40 2019 +0100

    Align with 8.5.x to fix failing test
---
 .../catalina/core/TestSwallowAbortedUploads.java   | 47 ++++++++++------------
 1 file changed, 22 insertions(+), 25 deletions(-)

diff --git a/test/org/apache/catalina/core/TestSwallowAbortedUploads.java b/test/org/apache/catalina/core/TestSwallowAbortedUploads.java
index 650e81d..b8f71ed 100644
--- a/test/org/apache/catalina/core/TestSwallowAbortedUploads.java
+++ b/test/org/apache/catalina/core/TestSwallowAbortedUploads.java
@@ -39,6 +39,7 @@ import org.junit.Test;
 
 import org.apache.catalina.Context;
 import org.apache.catalina.Wrapper;
+import org.apache.catalina.connector.Connector;
 import org.apache.catalina.startup.SimpleHttpClient;
 import org.apache.catalina.startup.Tomcat;
 import org.apache.catalina.startup.TomcatBaseTest;
@@ -49,7 +50,7 @@ public class TestSwallowAbortedUploads extends TomcatBaseTest {
 
     private static Log log = LogFactory.getLog(TestSwallowAbortedUploads.class);
 
-    /**
+    /*
      * Test whether size limited uploads correctly handle connection draining.
      */
     public Exception doAbortedUploadTest(AbortedUploadClient client, boolean limited,
@@ -67,7 +68,7 @@ public class TestSwallowAbortedUploads extends TomcatBaseTest {
         return ex;
     }
 
-    /**
+    /*
      * Test whether aborted POST correctly handle connection draining.
      */
     public Exception doAbortedPOSTTest(AbortedPOSTClient client, int status,
@@ -127,7 +128,7 @@ public class TestSwallowAbortedUploads extends TomcatBaseTest {
         AbortedUploadClient client = new AbortedUploadClient();
         Exception ex = doAbortedUploadTest(client, true, false);
         Assert.assertTrue("Limited upload with swallow disabled does not generate client exception",
-                   ex != null && ex instanceof java.net.SocketException);
+                   ex instanceof java.net.SocketException);
         client.reset();
     }
 
@@ -173,7 +174,7 @@ public class TestSwallowAbortedUploads extends TomcatBaseTest {
         AbortedPOSTClient client = new AbortedPOSTClient();
         Exception ex = doAbortedPOSTTest(client, HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE, false);
         Assert.assertTrue("Limited upload with swallow disabled does not generate client exception",
-                   ex != null && ex instanceof java.net.SocketException);
+                   ex instanceof java.net.SocketException);
         client.reset();
     }
 
@@ -227,15 +228,12 @@ public class TestSwallowAbortedUploads extends TomcatBaseTest {
         private static final String URI = "/uploadAborted";
         private static final String servletName = "uploadAborted";
         private static final int limitSize = 100;
-        private static final int hugeSize = 2000000;
+        private static final int hugeSize = 10000000;
 
-        private boolean init;
         private Context context;
 
         private synchronized void init(boolean limited, boolean swallow)
                 throws Exception {
-            if (init)
-                return;
 
             Tomcat tomcat = getTomcatInstance();
             context = tomcat.addContext("", TEMP_DIR);
@@ -254,10 +252,12 @@ public class TestSwallowAbortedUploads extends TomcatBaseTest {
             context.addServletMapping(URI, servletName);
             context.setSwallowAbortedUploads(swallow);
 
-            tomcat.start();
-            setPort(tomcat.getConnector().getLocalPort());
+            Connector c = tomcat.getConnector();
+            c.setMaxPostSize(2 * hugeSize);
+            c.setProperty("maxSwallowSize", Integer.toString(hugeSize));
 
-            init = true;
+            tomcat.start();
+            setPort(c.getLocalPort());
         }
 
         private Exception doRequest(boolean limited, boolean swallow) {
@@ -294,7 +294,7 @@ public class TestSwallowAbortedUploads extends TomcatBaseTest {
                         "ASCII");
 
                 request = new String[] { "POST http://localhost:" + getPort() + URI + " HTTP/1.1" + CRLF
-                        + "Host: localhost" + CRLF
+                        + "Host: localhost:" + getPort() + CRLF
                         + "Connection: close" + CRLF
                         + "Content-Type: multipart/form-data; boundary=" + boundary + CRLF
                         + "Content-Length: " + content.length() + CRLF
@@ -322,9 +322,9 @@ public class TestSwallowAbortedUploads extends TomcatBaseTest {
 
         private static final long serialVersionUID = 1L;
 
-        private int status = 200;
+        private final int status;
 
-        public void setStatus(int status) {
+        public AbortedPOSTServlet(int status) {
             this.status = status;
         }
 
@@ -348,30 +348,27 @@ public class TestSwallowAbortedUploads extends TomcatBaseTest {
 
         private static final String URI = "/uploadAborted";
         private static final String servletName = "uploadAborted";
-        private static final int hugeSize = 2000000;
+        private static final int hugeSize = 10000000;
 
-        private boolean init;
         private Context context;
 
         private synchronized void init(int status, boolean swallow)
                 throws Exception {
-            if (init)
-                return;
 
             Tomcat tomcat = getTomcatInstance();
             context = tomcat.addContext("", TEMP_DIR);
-            AbortedPOSTServlet servlet = new AbortedPOSTServlet();
-            servlet.setStatus(status);
-            Tomcat.addServlet(context, servletName,
-                              servlet);
+            AbortedPOSTServlet servlet = new AbortedPOSTServlet(status);
+            Tomcat.addServlet(context, servletName, servlet);
             context.addServletMapping(URI, servletName);
             context.setSwallowAbortedUploads(swallow);
 
             tomcat.start();
 
-            setPort(tomcat.getConnector().getLocalPort());
+            Connector c = tomcat.getConnector();
+            c.setMaxPostSize(2 * hugeSize);
+            c.setProperty("maxSwallowSize", Integer.toString(hugeSize));
 
-            init = true;
+            setPort(c.getLocalPort());
         }
 
         private Exception doRequest(int status, boolean swallow) {
@@ -390,7 +387,7 @@ public class TestSwallowAbortedUploads extends TomcatBaseTest {
                 String content = new String(body);
 
                 request = new String[] { "POST http://localhost:" + getPort() + URI + " HTTP/1.1" + CRLF
-                        + "Host: localhost" + CRLF
+                        + "Host: localhost:" + getPort() + CRLF
                         + "Connection: close" + CRLF
                         + "Content-Length: " + content.length() + CRLF
                         + CRLF


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org