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:22:50 UTC

[tomcat] branch 8.5.x updated (cb85254 -> b866eb9)

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

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


    from cb85254  Ignore more IntelliJ files
     new 33e951c  Refactor definition of boolean array to reduce code duplication
     new b866eb9  Additional async dispatch tests

The 2 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/DefaultServletEncodingBaseTest.java   |   2 -
 .../servlets/TestDefaultServletOptions.java        |   1 -
 .../servlets/TestWebdavServletOptions.java         |   1 -
 .../apache/catalina/startup/TomcatBaseTest.java    |   8 +-
 test/org/apache/coyote/http2/TestAsync.java        |   1 -
 7 files changed, 157 insertions(+), 9 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] 02/02: 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 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit b866eb9186e3a97778990212d0d8ff1a93e7c768
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..94cb1f1
--- /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<>();
+
+        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.addServletMappingDecoded("/target", "target");
+
+        Wrapper w2 = Tomcat.addServlet(ctx, "dispatch", new TesterDispatchServlet(dispatchAsyncStart));
+        w2.setAsyncSupported(dispatchAsyncSupported);
+        ctx.addServletMappingDecoded("/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] 01/02: 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 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 33e951c25473d858c1367957c1bfb746c78c8f73
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 --
 .../apache/catalina/servlets/DefaultServletEncodingBaseTest.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              | 8 ++++++--
 test/org/apache/coyote/http2/TestAsync.java                       | 1 -
 6 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/test/javax/servlet/http/TestHttpServletResponseSendError.java b/test/javax/servlet/http/TestHttpServletResponseSendError.java
index 256b536..bfdbf7e 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/DefaultServletEncodingBaseTest.java b/test/org/apache/catalina/servlets/DefaultServletEncodingBaseTest.java
index 6ff4849..6640494 100644
--- a/test/org/apache/catalina/servlets/DefaultServletEncodingBaseTest.java
+++ b/test/org/apache/catalina/servlets/DefaultServletEncodingBaseTest.java
@@ -67,8 +67,6 @@ public abstract class DefaultServletEncodingBaseTest extends TomcatBaseTest {
         String[] targetFiles = new String[] {
                 "cp1252", "ibm850", "iso-8859-1", "utf-8-bom", "utf-8" };
 
-        Boolean[] booleans = new Boolean[] { Boolean.FALSE, Boolean.TRUE };
-
         List<Object[]> parameterSets = new ArrayList<>();
 
         for (String contextResponseEncoding : encodings) {
diff --git a/test/org/apache/catalina/servlets/TestDefaultServletOptions.java b/test/org/apache/catalina/servlets/TestDefaultServletOptions.java
index 98e0829..f4e0f55 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 ed8b776..2ccbbb9 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 0fd2286..b7c5fb4 100644
--- a/test/org/apache/catalina/startup/TomcatBaseTest.java
+++ b/test/org/apache/catalina/startup/TomcatBaseTest.java
@@ -83,12 +83,16 @@ public abstract class TomcatBaseTest extends LoggingBaseTest {
     @SuppressWarnings("unused")
     private static final boolean ignored = TesterSupport.OPENSSL_AVAILABLE;
 
-    private Tomcat tomcat;
-    private boolean accessLogEnabled = false;
+    // 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 = 300_000;
 
     public static final String TEMP_DIR = System.getProperty("java.io.tmpdir");
 
+    private Tomcat tomcat;
+    private boolean accessLogEnabled = false;
+
     /**
      * Make the Tomcat instance available to sub-classes.
      *
diff --git a/test/org/apache/coyote/http2/TestAsync.java b/test/org/apache/coyote/http2/TestAsync.java
index cc74468..83c46ab 100644
--- a/test/org/apache/coyote/http2/TestAsync.java
+++ b/test/org/apache/coyote/http2/TestAsync.java
@@ -58,7 +58,6 @@ public class TestAsync extends Http2TestBase {
             "connectionUnlimited[{1}], streamUnlimited[{2}], useNonContainerThreadForWrite[{3}]," +
             "largeInitialWindow[{4}]")
     public static Collection<Object[]> parameters() {
-        Boolean[] booleans = new Boolean[] { Boolean.FALSE, Boolean.TRUE };
         List<Object[]> parameterSets = new ArrayList<>();
 
         for (Boolean expandConnectionFirst : booleans) {


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