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

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


The following commit(s) were added to refs/heads/10.0.x by this push:
     new 6809a1b824 Refactor HTTP/2 tests to test with and without asyncIO
6809a1b824 is described below

commit 6809a1b8241d6ce00c4c420b6aabdaa270bd9477
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Jun 23 20:56:43 2022 +0100

    Refactor HTTP/2 tests to test with and without asyncIO
    
    There are now a small number of classes with parameterization in the
    class and super class. This requires a little work to keep the
    sub-classes in sync if additional parameters are added to the super
    class. This will be obvious as JUnit will complain if they are not in
    sync.
---
 test/org/apache/coyote/http2/Http2TestBase.java    | 29 +++++++++--
 test/org/apache/coyote/http2/TestAsync.java        | 57 ++++++++++++----------
 test/org/apache/coyote/http2/TestLargeUpload.java  | 56 +++++++++++++++++++++
 .../apache/coyote/http2/TestStreamQueryString.java | 23 +++++----
 test/org/apache/tomcat/util/net/TesterSupport.java | 10 ++++
 5 files changed, 134 insertions(+), 41 deletions(-)

diff --git a/test/org/apache/coyote/http2/Http2TestBase.java 
b/test/org/apache/coyote/http2/Http2TestBase.java
index acf2d91b37..b4ffe42120 100644
--- a/test/org/apache/coyote/http2/Http2TestBase.java
+++ b/test/org/apache/coyote/http2/Http2TestBase.java
@@ -28,6 +28,7 @@ import java.net.SocketException;
 import java.nio.ByteBuffer;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -42,6 +43,10 @@ import jakarta.servlet.http.HttpServletResponse;
 
 import org.junit.Assert;
 import org.junit.Assume;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+import org.junit.runners.Parameterized.Parameters;
 
 import org.apache.catalina.Context;
 import org.apache.catalina.LifecycleException;
@@ -63,14 +68,29 @@ import org.apache.tomcat.util.net.TesterSupport;
  * Tests for compliance with the <a href="https://tools.ietf.org/html/rfc7540";>
  * HTTP/2 specification</a>.
  */
-@org.junit.runner.RunWith(org.junit.runners.Parameterized.class)
+@RunWith(Parameterized.class)
 public abstract class Http2TestBase extends TomcatBaseTest {
 
-    @org.junit.runners.Parameterized.Parameters
-    public static Object[][] data() {
-        return new Object[Integer.getInteger("tomcat.test.http2.loopCount", 
1).intValue()][0];
+    @Parameters(name = "{index}: loop [{0}], useAsyncIO[{1}]")
+    public static Collection<Object[]> data() {
+        int loopCount = Integer.getInteger("tomcat.test.http2.loopCount", 
1).intValue();
+        List<Object[]> parameterSets = new ArrayList<>();
+
+        for (int loop = 0; loop < loopCount; loop++) {
+            for (Boolean useAsyncIO : TomcatBaseTest.booleans) {
+                parameterSets.add(new Object[] { Integer.valueOf(loop), 
useAsyncIO });
+            }
+        }
+
+        return parameterSets;
     }
 
+    @Parameter(0)
+    public int loop;
+
+    @Parameter(1)
+    public boolean useAsyncIO;
+
     // Nothing special about this date apart from it being the date I ran the
     // test that demonstrated that most HTTP/2 tests were failing because the
     // response now included a date header
@@ -580,6 +600,7 @@ public abstract class Http2TestBase extends TomcatBaseTest {
     protected void enableHttp2(long maxConcurrentStreams, boolean tls) {
         Tomcat tomcat = getTomcatInstance();
         Connector connector = tomcat.getConnector();
+        Assert.assertTrue(connector.setProperty("useAsyncIO", 
Boolean.toString(useAsyncIO)));
         http2Protocol = new UpgradableHttp2Protocol();
         // Short timeouts for now. May need to increase these for CI systems.
         http2Protocol.setReadTimeout(10000);
diff --git a/test/org/apache/coyote/http2/TestAsync.java 
b/test/org/apache/coyote/http2/TestAsync.java
index 50cdaac349..f5265c872a 100644
--- a/test/org/apache/coyote/http2/TestAsync.java
+++ b/test/org/apache/coyote/http2/TestAsync.java
@@ -38,6 +38,7 @@ 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;
@@ -54,21 +55,25 @@ public class TestAsync extends Http2TestBase {
 
     private static final int BLOCK_SIZE = 0x8000;
 
-    @Parameterized.Parameters(name = "{index}: expandConnectionFirst[{0}], " +
-            "connectionUnlimited[{1}], streamUnlimited[{2}], 
useNonContainerThreadForWrite[{3}]," +
-            "largeInitialWindow[{4}]")
+    @Parameterized.Parameters(name = "{index}: loop[{0}], useAsyncIO[{1}], 
expandConnectionFirst[{1}], " +
+            "connectionUnlimited[{2}], streamUnlimited[{3}], 
useNonContainerThreadForWrite[{4}]," +
+            "largeInitialWindow[{5}]")
     public static Collection<Object[]> parameters() {
         List<Object[]> parameterSets = new ArrayList<>();
-
-        for (Boolean expandConnectionFirst : booleans) {
-            for (Boolean connectionUnlimited : booleans) {
-                for (Boolean streamUnlimited : booleans) {
-                    for (Boolean useNonContainerThreadForWrite : booleans) {
-                        for (Boolean largeInitialWindow : booleans) {
-                            parameterSets.add(new Object[] {
-                                    expandConnectionFirst, 
connectionUnlimited, streamUnlimited,
-                                    useNonContainerThreadForWrite, 
largeInitialWindow
-                            });
+        Collection<Object[]> baseData = Http2TestBase.data();
+
+        for (Object[] base : baseData) {
+            for (Boolean expandConnectionFirst : booleans) {
+                for (Boolean connectionUnlimited : booleans) {
+                    for (Boolean streamUnlimited : booleans) {
+                        for (Boolean useNonContainerThreadForWrite : booleans) 
{
+                            for (Boolean largeInitialWindow : booleans) {
+                                parameterSets.add(new Object[] {
+                                        base[0], base[1],
+                                        expandConnectionFirst, 
connectionUnlimited, streamUnlimited,
+                                        useNonContainerThreadForWrite, 
largeInitialWindow
+                                });
+                            }
                         }
                     }
                 }
@@ -78,22 +83,20 @@ public class TestAsync extends Http2TestBase {
     }
 
 
-    private final boolean expandConnectionFirst;
-    private final boolean connectionUnlimited;
-    private final boolean streamUnlimited;
-    private final boolean useNonContainerThreadForWrite;
-    private final boolean largeInitialWindow;
+    @Parameter(2)
+    public boolean expandConnectionFirst;
 
+    @Parameter(3)
+    public boolean connectionUnlimited;
 
-    public TestAsync(boolean expandConnectionFirst, boolean 
connectionUnlimited,
-            boolean streamUnlimited, boolean useNonContainerThreadForWrite,
-            boolean largeInitialWindow) {
-        this.expandConnectionFirst = expandConnectionFirst;
-        this.connectionUnlimited = connectionUnlimited;
-        this.streamUnlimited = streamUnlimited;
-        this.useNonContainerThreadForWrite = useNonContainerThreadForWrite;
-        this.largeInitialWindow = largeInitialWindow;
-    }
+    @Parameter(4)
+    public boolean streamUnlimited;
+
+    @Parameter(5)
+    public boolean useNonContainerThreadForWrite;
+
+    @Parameter(6)
+    public boolean largeInitialWindow;
 
 
     @Test
diff --git a/test/org/apache/coyote/http2/TestLargeUpload.java 
b/test/org/apache/coyote/http2/TestLargeUpload.java
index 5049293f24..b56509979e 100644
--- a/test/org/apache/coyote/http2/TestLargeUpload.java
+++ b/test/org/apache/coyote/http2/TestLargeUpload.java
@@ -20,6 +20,9 @@ import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
 import java.util.concurrent.CountDownLatch;
 
 import jakarta.servlet.ServletException;
@@ -27,15 +30,51 @@ import jakarta.servlet.http.HttpServletRequest;
 import jakarta.servlet.http.HttpServletResponse;
 
 import org.junit.Assert;
+import org.junit.Assume;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+import org.junit.runners.Parameterized.Parameters;
 
 import org.apache.catalina.Context;
 import org.apache.catalina.LifecycleException;
+import org.apache.catalina.core.AprLifecycleListener;
+import org.apache.catalina.core.StandardServer;
 import org.apache.catalina.startup.Tomcat;
 import org.apache.coyote.http11.AbstractHttp11Protocol;
+import org.apache.tomcat.util.net.TesterSupport;
 
+@RunWith(Parameterized.class)
 public class TestLargeUpload extends Http2TestBase {
 
+    @Parameters(name = "{0}: {1}]")
+    public static Collection<Object[]> parameters() {
+        Collection<Object[]> baseData = Http2TestBase.data();
+
+        List<Object[]> parameterSets = new ArrayList<>();
+        for (Object[] base : baseData) {
+            parameterSets.add(new Object[] {
+                    base[0], base[1],
+                    "JSSE", Boolean.FALSE, 
"org.apache.tomcat.util.net.jsse.JSSEImplementation"});
+            parameterSets.add(new Object[] {
+                    base[0], base[1],
+                    "OpenSSL", Boolean.TRUE, 
"org.apache.tomcat.util.net.openssl.OpenSSLImplementation"});
+        }
+
+        return parameterSets;
+    }
+
+    @Parameter(2)
+    public String connectorName;
+
+    @Parameter(3)
+    public boolean needApr;
+
+    @Parameter(4)
+    public String sslImplementationName;
+
+
     int bodySize = 13107;
     int bodyCount = 5;
 
@@ -115,4 +154,21 @@ public class TestLargeUpload extends Http2TestBase {
             }
         }
     }
+
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+
+        Tomcat tomcat = getTomcatInstance();
+
+        TesterSupport.configureSSLImplementation(tomcat, 
sslImplementationName);
+
+        if (needApr) {
+            AprLifecycleListener listener = new AprLifecycleListener();
+            Assume.assumeTrue(AprLifecycleListener.isAprAvailable());
+            StandardServer server = (StandardServer) tomcat.getServer();
+            server.addLifecycleListener(listener);
+        }
+    }
 }
diff --git a/test/org/apache/coyote/http2/TestStreamQueryString.java 
b/test/org/apache/coyote/http2/TestStreamQueryString.java
index e1ccd79046..154231b4e2 100644
--- a/test/org/apache/coyote/http2/TestStreamQueryString.java
+++ b/test/org/apache/coyote/http2/TestStreamQueryString.java
@@ -34,6 +34,7 @@ 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.junit.runners.Parameterized.Parameters;
 
 import org.apache.catalina.Context;
@@ -49,20 +50,22 @@ public class TestStreamQueryString extends Http2TestBase {
     @Parameters
     public static Collection<Object[]> inputs() {
         List<Object[]> result = new ArrayList<>();
-        // Test ASCII characters from 32 to 126 inclusive
-        for (int i = 32; i < 128; i++) {
-            result.add(new String[] { "%" + HexUtils.toHexString(new byte[] { 
(byte) i})});
+        Collection<Object[]> baseData = Http2TestBase.data();
+
+        for (Object[] base : baseData) {
+            // Test ASCII characters from 32 to 126 inclusive
+            for (int i = 32; i < 128; i++) {
+                result.add(new Object[] {
+                        base[0], base[1],
+                       "%" + HexUtils.toHexString(new byte[] { (byte) i})});
+            }
         }
+
         return result;
     }
 
-
-    private final String queryValueToTest;
-
-
-    public TestStreamQueryString(String queryValueToTest) {
-        this.queryValueToTest = queryValueToTest;
-    }
+    @Parameter(2)
+    public String queryValueToTest;
 
 
     @Test
diff --git a/test/org/apache/tomcat/util/net/TesterSupport.java 
b/test/org/apache/tomcat/util/net/TesterSupport.java
index 093c430795..7bc5febff4 100644
--- a/test/org/apache/tomcat/util/net/TesterSupport.java
+++ b/test/org/apache/tomcat/util/net/TesterSupport.java
@@ -49,6 +49,7 @@ import jakarta.servlet.http.HttpServletRequest;
 import jakarta.servlet.http.HttpServletResponse;
 
 import org.junit.Assert;
+import org.junit.Assume;
 
 import org.apache.catalina.Context;
 import org.apache.catalina.authenticator.SSLAuthenticator;
@@ -255,6 +256,15 @@ public final class TesterSupport {
         return true;
     }
 
+    public static void configureSSLImplementation(Tomcat tomcat, String 
sslImplementationName) {
+        try {
+            Class.forName(sslImplementationName);
+        } catch (Exception e) {
+            Assume.assumeNoException(e);
+        }
+        
Assert.assertTrue(tomcat.getConnector().setProperty("sslImplementationName", 
sslImplementationName));
+    }
+
     public static void configureClientCertContext(Tomcat tomcat) {
         TesterSupport.initSsl(tomcat);
 


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

Reply via email to