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 19:57:16 UTC
[tomcat] branch main 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 main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push:
new 0bc1407cdc Refactor HTTP/2 tests to test with and without asyncIO
0bc1407cdc is described below
commit 0bc1407cdc1538f8403d1d22544169287c98ed87
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 | 27 ++++++----
.../apache/coyote/http2/TestStreamQueryString.java | 23 +++++----
4 files changed, 85 insertions(+), 51 deletions(-)
diff --git a/test/org/apache/coyote/http2/Http2TestBase.java b/test/org/apache/coyote/http2/Http2TestBase.java
index 5a1cfaa037..b03576f752 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
@@ -608,6 +628,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 b0b35e0c88..9566bc8af6 100644
--- a/test/org/apache/coyote/http2/TestLargeUpload.java
+++ b/test/org/apache/coyote/http2/TestLargeUpload.java
@@ -47,26 +47,33 @@ import org.apache.tomcat.util.net.TesterSupport;
@RunWith(Parameterized.class)
public class TestLargeUpload extends Http2TestBase {
- @Parameterized.Parameters(name = "{0}")
+ @Parameterized.Parameters(name = "{0}: {1}]")
public static Collection<Object[]> parameters() {
+ Collection<Object[]> baseData = Http2TestBase.data();
+
List<Object[]> parameterSets = new ArrayList<>();
- parameterSets.add(new Object[] {
- "JSSE", Boolean.FALSE, "org.apache.tomcat.util.net.jsse.JSSEImplementation"});
- parameterSets.add(new Object[] {
- "OpenSSL", Boolean.TRUE, "org.apache.tomcat.util.net.openssl.OpenSSLImplementation"});
- parameterSets.add(new Object[] {
- "OpenSSL-Panama", Boolean.FALSE, "org.apache.tomcat.util.net.openssl.panama.OpenSSLImplementation"});
+ 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"});
+ parameterSets.add(new Object[] {
+ base[0], base[1],
+ "OpenSSL-Panama", Boolean.FALSE, "org.apache.tomcat.util.net.openssl.panama.OpenSSLImplementation"});
+ }
return parameterSets;
}
- @Parameter(0)
+ @Parameter(2)
public String connectorName;
- @Parameter(1)
+ @Parameter(3)
public boolean needApr;
- @Parameter(2)
+ @Parameter(4)
public String sslImplementationName;
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
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org