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/11 13:36:54 UTC

[tomcat] branch 7.0.x updated (89c530d -> 7b37f76)

This is an automated email from the ASF dual-hosted git repository.

markt pushed a change to branch 7.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git.


    from 89c530d  Polish : remove completed TODO
     new 9bd2ec0  Align more closely with 8.5.x to ease back-ports
     new d42e567  Refactor definition of boolean array to reduce code duplication
     new 7b37f76  Additional async dispatch tests

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../http/TestHttpServletResponseSendError.java     |   2 -
 .../core/TestAsyncContextImplDispatch.java         | 151 +++++++++++++++++++++
 .../servlets/TestDefaultServletOptions.java        |   1 -
 .../servlets/TestWebdavServletOptions.java         |   1 -
 .../apache/catalina/startup/TomcatBaseTest.java    |  19 ++-
 5 files changed, 164 insertions(+), 10 deletions(-)
 create mode 100644 test/org/apache/catalina/core/TestAsyncContextImplDispatch.java


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


[tomcat] 01/03: Align more closely with 8.5.x to ease back-ports

Posted by ma...@apache.org.
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 9bd2ec0967840f4a15004ba5a3fa7c43b487c5fe
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Jul 11 14:31:56 2019 +0100

    Align more closely with 8.5.x to ease back-ports
---
 test/org/apache/catalina/startup/TomcatBaseTest.java | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/test/org/apache/catalina/startup/TomcatBaseTest.java b/test/org/apache/catalina/startup/TomcatBaseTest.java
index a4fc307..0b77e9f 100644
--- a/test/org/apache/catalina/startup/TomcatBaseTest.java
+++ b/test/org/apache/catalina/startup/TomcatBaseTest.java
@@ -60,14 +60,18 @@ import org.apache.tomcat.util.buf.ByteChunk;
  * don't have to keep writing the cleanup code.
  */
 public abstract class TomcatBaseTest extends LoggingBaseTest {
-    private Tomcat tomcat;
-    private boolean accessLogEnabled = false;
+
     protected static final int DEFAULT_CLIENT_TIMEOUT_MS = 300000;
 
     public static final String TEMP_DIR = System.getProperty("java.io.tmpdir");
 
+    private Tomcat tomcat;
+    private boolean accessLogEnabled = false;
+
     /**
-     * Make Tomcat instance accessible to sub-classes.
+     * Make the Tomcat instance available to sub-classes.
+     *
+     * @return A Tomcat instance without any pre-configured web applications
      */
     public Tomcat getTomcatInstance() {
         return tomcat;
@@ -80,7 +84,7 @@ public abstract class TomcatBaseTest extends LoggingBaseTest {
         return tomcat.getConnector().getLocalPort();
     }
 
-    /**
+    /*
      * Sub-classes may want to check, whether an AccessLogValve is active
      */
     public boolean isAccessLogEnabled() {
@@ -407,12 +411,12 @@ public abstract class TomcatBaseTest extends LoggingBaseTest {
             StringBuilder value;
             Object attribute;
 
+            response.setContentType("text/plain");
+
             ServletContext ctx = this.getServletContext();
             HttpSession session = request.getSession(false);
             PrintWriter out = response.getWriter();
 
-            response.setContentType("text/plain");
-
             out.println("CONTEXT-NAME: " + ctx.getServletContextName());
             out.println("CONTEXT-PATH: " + ctx.getContextPath());
             out.println("CONTEXT-MAJOR-VERSION: " + ctx.getMajorVersion());


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


[tomcat] 03/03: Additional async dispatch tests

Posted by ma...@apache.org.
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 7b37f7679ee47214ac409ea7a8ab012bc54f51f0
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Jul 11 14:19:50 2019 +0100

    Additional async dispatch tests
---
 .../core/TestAsyncContextImplDispatch.java         | 151 +++++++++++++++++++++
 1 file changed, 151 insertions(+)

diff --git a/test/org/apache/catalina/core/TestAsyncContextImplDispatch.java b/test/org/apache/catalina/core/TestAsyncContextImplDispatch.java
new file mode 100644
index 0000000..b98f9d9
--- /dev/null
+++ b/test/org/apache/catalina/core/TestAsyncContextImplDispatch.java
@@ -0,0 +1,151 @@
+/*
+ *  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.catalina.core;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.servlet.AsyncContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+
+import org.apache.catalina.Context;
+import org.apache.catalina.Wrapper;
+import org.apache.catalina.startup.Tomcat;
+import org.apache.catalina.startup.TomcatBaseTest;
+import org.apache.tomcat.util.buf.ByteChunk;
+
+/**
+ * Written for the specific test case of async Servlet, dispatches to sync
+ * Servlet that then tries to call startAsync() but covers all combinations
+ * for completeness.
+ */
+@RunWith(Parameterized.class)
+public class TestAsyncContextImplDispatch extends TomcatBaseTest {
+
+    @Parameterized.Parameters(name = "{index}: tgt-sup [{0}], dis-sup [{1}], dis-st [{2}]")
+    public static Collection<Object[]> parameters() {
+        List<Object[]> parameterSets = new ArrayList<Object[]>();
+
+        for (Boolean targetAsyncSupported : booleans) {
+            for (Boolean dispatchAsyncSupported : booleans) {
+                for (Boolean dispatchAsyncStart : booleans) {
+                    Boolean allowed = Boolean.valueOf(!dispatchAsyncStart.booleanValue() ||
+                            targetAsyncSupported.booleanValue() && dispatchAsyncSupported.booleanValue() &&
+                                    dispatchAsyncStart.booleanValue());
+
+                    parameterSets.add(new Object[] { targetAsyncSupported, dispatchAsyncSupported, dispatchAsyncStart, allowed} );
+                }
+            }
+        }
+
+        return parameterSets;
+    }
+
+    @Parameter(0)
+    public boolean targetAsyncSupported;
+    @Parameter(1)
+    public boolean dispatchAsyncSupported;
+    @Parameter(2)
+    public boolean dispatchAsyncStart;
+    @Parameter(3)
+    public boolean allowed;
+
+
+    @Test
+    public void testSendError() throws Exception {
+        // Setup Tomcat instance
+        Tomcat tomcat = getTomcatInstance();
+
+        // No file system docBase required
+        Context ctx = tomcat.addContext("", null);
+
+        Wrapper w1 = Tomcat.addServlet(ctx, "target", new TesterServlet());
+        w1.setAsyncSupported(targetAsyncSupported);
+        ctx.addServletMapping("/target", "target");
+
+        Wrapper w2 = Tomcat.addServlet(ctx, "dispatch", new TesterDispatchServlet(dispatchAsyncStart));
+        w2.setAsyncSupported(dispatchAsyncSupported);
+        ctx.addServletMapping("/dispatch", "dispatch");
+
+        tomcat.start();
+
+        ByteChunk bc = new ByteChunk();
+        int rc;
+
+        rc = getUrl("http://localhost:" + getPort() + "/target", bc, null, null);
+
+        String body = bc.toString();
+
+        if (allowed) {
+            Assert.assertEquals(200, rc);
+            Assert.assertEquals("OK", body);
+        } else {
+            Assert.assertEquals(500, rc);
+        }
+    }
+
+
+    public static class TesterServlet extends HttpServlet {
+
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+                throws ServletException, IOException {
+
+            req.getRequestDispatcher("/dispatch").forward(req, resp);
+        }
+    }
+
+
+    public static class TesterDispatchServlet extends HttpServlet {
+
+        private static final long serialVersionUID = 1L;
+
+        private final  boolean start;
+
+        public TesterDispatchServlet(boolean start) {
+            this.start = start;
+        }
+
+
+        @Override
+        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+                throws ServletException, IOException {
+
+            if (start) {
+                AsyncContext ac = req.startAsync();
+                ac.complete();
+            }
+
+            resp.setContentType("text/plain");
+            resp.setCharacterEncoding("UTF-8");
+            resp.getWriter().write("OK");
+        }
+    }
+}


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


[tomcat] 02/03: Refactor definition of boolean array to reduce code duplication

Posted by ma...@apache.org.
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 d42e567794f86e409ae43e74a926b00445c82f1b
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Jul 11 11:30:49 2019 +0100

    Refactor definition of boolean array to reduce code duplication
---
 test/javax/servlet/http/TestHttpServletResponseSendError.java    | 2 --
 test/org/apache/catalina/servlets/TestDefaultServletOptions.java | 1 -
 test/org/apache/catalina/servlets/TestWebdavServletOptions.java  | 1 -
 test/org/apache/catalina/startup/TomcatBaseTest.java             | 3 +++
 4 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/test/javax/servlet/http/TestHttpServletResponseSendError.java b/test/javax/servlet/http/TestHttpServletResponseSendError.java
index 8e0e89e..b4865e9 100644
--- a/test/javax/servlet/http/TestHttpServletResponseSendError.java
+++ b/test/javax/servlet/http/TestHttpServletResponseSendError.java
@@ -59,8 +59,6 @@ public class TestHttpServletResponseSendError extends TomcatBaseTest {
      *     - dispatch
      */
 
-    private static final Boolean[] booleans = new Boolean[] { Boolean.FALSE, Boolean.TRUE };
-
     private enum AsyncErrorPoint {
         /*
          * Thread A is the container thread the processes the original request.
diff --git a/test/org/apache/catalina/servlets/TestDefaultServletOptions.java b/test/org/apache/catalina/servlets/TestDefaultServletOptions.java
index 8db6c90..b7708b8 100644
--- a/test/org/apache/catalina/servlets/TestDefaultServletOptions.java
+++ b/test/org/apache/catalina/servlets/TestDefaultServletOptions.java
@@ -31,7 +31,6 @@ public class TestDefaultServletOptions extends ServletOptionsBaseTest {
 
     @Parameters
     public static Collection<Object[]> inputs() {
-        Boolean[] booleans = new Boolean[] { Boolean.FALSE, Boolean.TRUE };
         String[] urls = new String[] { COLLECTION_NAME, FILE_NAME, UNKNOWN_NAME };
         String[] methods = new String[] { "GET", "POST", "HEAD", "TRACE", "PUT", "DELETE" };
 
diff --git a/test/org/apache/catalina/servlets/TestWebdavServletOptions.java b/test/org/apache/catalina/servlets/TestWebdavServletOptions.java
index e55aeed..4407f6c 100644
--- a/test/org/apache/catalina/servlets/TestWebdavServletOptions.java
+++ b/test/org/apache/catalina/servlets/TestWebdavServletOptions.java
@@ -31,7 +31,6 @@ public class TestWebdavServletOptions extends ServletOptionsBaseTest {
 
     @Parameters
     public static Collection<Object[]> inputs() {
-        Boolean[] booleans = new Boolean[] { Boolean.FALSE, Boolean.TRUE };
         String[] urls = new String[] { COLLECTION_NAME, FILE_NAME, UNKNOWN_NAME };
         String[] methods = new String[] { "GET", "POST", "HEAD", "TRACE", "PUT", "DELETE",
                 "MKCOL", "LOCK", "UNLOCK", "COPY", "MOVE", "PROPFIND", "PROPPATCH" };
diff --git a/test/org/apache/catalina/startup/TomcatBaseTest.java b/test/org/apache/catalina/startup/TomcatBaseTest.java
index 0b77e9f..e234d67 100644
--- a/test/org/apache/catalina/startup/TomcatBaseTest.java
+++ b/test/org/apache/catalina/startup/TomcatBaseTest.java
@@ -61,6 +61,9 @@ import org.apache.tomcat.util.buf.ByteChunk;
  */
 public abstract class TomcatBaseTest extends LoggingBaseTest {
 
+    // Used by parameterized tests. Defined here to reduce duplication.
+    protected static final Boolean[] booleans = new Boolean[] { Boolean.FALSE, Boolean.TRUE };
+
     protected static final int DEFAULT_CLIENT_TIMEOUT_MS = 300000;
 
     public static final String TEMP_DIR = System.getProperty("java.io.tmpdir");


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