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 2022/06/23 20:16:51 UTC
[tomcat] branch 9.0.x updated: Refactor HTTP/2 tests to test with and without asyncIO
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new 1f5f3aae75 Refactor HTTP/2 tests to test with and without asyncIO
1f5f3aae75 is described below
commit 1f5f3aae756c4217ac79558f96ba448b910477ee
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 03ac865093..7cd29174ec 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;
@@ -41,6 +42,10 @@ import javax.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;
@@ -61,14 +66,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
@@ -578,6 +598,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 e01bb7efd0..43820f7f26 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 ac38b92406..ab67b6035a 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 javax.servlet.ServletException;
@@ -27,15 +30,51 @@ import javax.servlet.http.HttpServletRequest;
import javax.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 b1749e9e99..abffb06e95 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 b4f7cc3f09..f903c70666 100644
--- a/test/org/apache/tomcat/util/net/TesterSupport.java
+++ b/test/org/apache/tomcat/util/net/TesterSupport.java
@@ -48,6 +48,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.junit.Assert;
+import org.junit.Assume;
import org.apache.catalina.Context;
import org.apache.catalina.authenticator.SSLAuthenticator;
@@ -254,6 +255,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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org