Author: markt
Date: Wed Jun 10 21:56:27 2015
New Revision: 1684771
URL: http://svn.apache.org/r1684771
Log:
Add a test for maxConcurrentStreams
Also expands capabilities of Http2TestBase to include
- large requests
- setting maxConcurrentStreams
Modified:
tomcat/trunk/test/org/apache/coyote/http2/Http2TestBase.java
tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_5_1.java
Modified: tomcat/trunk/test/org/apache/coyote/http2/Http2TestBase.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/coyote/http2/Http2TestBase.java?rev=1684771&r1=1684770&r2=1684771&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/coyote/http2/Http2TestBase.java (original)
+++ tomcat/trunk/test/org/apache/coyote/http2/Http2TestBase.java Wed Jun 10
21:56:27 2015
@@ -114,10 +114,30 @@ public abstract class Http2TestBase exte
}
+ protected void sendLargeRequest(int streamId) throws IOException {
+ byte[] frameHeader = new byte[9];
+ ByteBuffer headersPayload = ByteBuffer.allocate(128);
+
+ buildLargeRequest(frameHeader, headersPayload, streamId);
+ writeFrame(frameHeader, headersPayload);
+ }
+
+
protected void buildSimpleRequest(byte[] frameHeader, ByteBuffer
headersPayload, int streamId) {
+ buildRequest(frameHeader, headersPayload, streamId, "/simple");
+ }
+
+
+ protected void buildLargeRequest(byte[] frameHeader, ByteBuffer
headersPayload, int streamId) {
+ buildRequest(frameHeader, headersPayload, streamId, "/large");
+ }
+
+
+ protected void buildRequest(byte[] frameHeader, ByteBuffer headersPayload,
int streamId,
+ String url) {
MimeHeaders headers = new MimeHeaders();
headers.addValue(":method").setString("GET");
- headers.addValue(":path").setString("/any");
+ headers.addValue(":path").setString(url);
headers.addValue(":authority").setString("localhost:" + getPort());
hpackEncoder.encode(headers, headersPayload);
@@ -137,7 +157,7 @@ public abstract class Http2TestBase exte
int streamId) {
MimeHeaders headers = new MimeHeaders();
headers.addValue(":method").setString("GET");
- headers.addValue(":path").setString("/any");
+ headers.addValue(":path").setString("/simple");
hpackEncoder.encode(headers, headersPayload);
headersPayload.flip();
@@ -204,12 +224,17 @@ public abstract class Http2TestBase exte
protected void enableHttp2() {
+ enableHttp2(200);
+ }
+
+ protected void enableHttp2(long maxConcurrentStreams) {
Connector connector = getTomcatInstance().getConnector();
Http2Protocol http2Protocol = new Http2Protocol();
// Short timeouts for now. May need to increase these for CI systems.
http2Protocol.setReadTimeout(2000);
http2Protocol.setKeepAliveTimeout(5000);
http2Protocol.setWriteTimeout(2000);
+ http2Protocol.setMaxConcurrentStreams(maxConcurrentStreams);
connector.addUpgradeProtocol(http2Protocol);
}
@@ -219,7 +244,9 @@ public abstract class Http2TestBase exte
Context ctxt = tomcat.addContext("", null);
Tomcat.addServlet(ctxt, "simple", new SimpleServlet());
- ctxt.addServletMapping("/*", "simple");
+ ctxt.addServletMapping("/simple", "simple");
+ Tomcat.addServlet(ctxt, "large", new LargeServlet());
+ ctxt.addServletMapping("/large", "large");
tomcat.start();
}
@@ -245,7 +272,7 @@ public abstract class Http2TestBase exte
protected void doHttpUpgrade(String connection, String upgrade, String
settings,
boolean validate) throws IOException {
- byte[] upgradeRequest = ("GET / HTTP/1.1\r\n" +
+ byte[] upgradeRequest = ("GET /simple HTTP/1.1\r\n" +
"Host: localhost:" + getPort() + "\r\n" +
"Connection: "+ connection + "\r\n" +
"Upgrade: " + upgrade + "\r\n" +
@@ -606,6 +633,32 @@ public abstract class Http2TestBase exte
// Two bytes per entry
resp.setContentLengthLong(count * 2);
+ OutputStream os = resp.getOutputStream();
+ byte[] data = new byte[2];
+ for (int i = 0; i < count; i++) {
+ data[0] = (byte) (i & 0xFF);
+ data[1] = (byte) ((i >> 8) & 0xFF);
+ os.write(data);
+ }
+ }
+ }
+
+
+ private static class LargeServlet extends HttpServlet {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException {
+ // Generate content with a simple known format that will exceed the
+ // default flow control window for a stream.
+ resp.setContentType("application/octet-stream");
+
+ int count = 128 * 1024;
+ // Two bytes per entry
+ resp.setContentLengthLong(count * 2);
+
OutputStream os = resp.getOutputStream();
byte[] data = new byte[2];
for (int i = 0; i < count; i++) {
Modified: tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_5_1.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_5_1.java?rev=1684771&r1=1684770&r2=1684771&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_5_1.java
(original)
+++ tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_5_1.java Wed Jun
10 21:56:27 2015
@@ -204,5 +204,44 @@ public class TestHttp2Section_5_1 extend
output.getTrace().startsWith("0-Goaway-[2147483647]-[" +
Http2Error.PROTOCOL_ERROR.getCode() + "]-["));
}
- // TODO 5.1.2 tests
+
+
+ @Test
+ public void testExceedMaxActiveStreams() throws Exception {
+ hpackEncoder = new
HpackEncoder(ConnectionSettings.DEFAULT_HEADER_TABLE_SIZE);
+
+ // http2Connect() - modified
+ enableHttp2(1);
+ configureAndStartWebApplication();
+ openClientConnection();
+ doHttpUpgrade();
+ sendClientPreface();
+ validateHttp2InitialResponse();
+
+ sendLargeRequest(3);
+
+ sendSimpleRequest(5);
+
+ // 1 * headers
+ // 64k of body (8 * 8k)
+ // 1 * error (could be in any order)
+ for (int i = 0; i < 9; i++) {
+ parser.readFrame(true);
+ }
+ parser.readFrame(true);
+
+ // Release the remaining body
+ sendWindowUpdate(0, (1 << 31) - 1);
+ sendWindowUpdate(3, (1 << 31) - 1);
+
+ // 192k of body (24 * 8k)
+ // 1 * error (could be in any order)
+ for (int i = 0; i < 24; i++) {
+ parser.readFrame(true);
+ }
+
+ Assert.assertTrue(output.getTrace(),
+ output.getTrace().contains("5-RST-[" +
+ Http2Error.REFUSED_STREAM.getCode() + "]"));
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]