Author: markt Date: Wed Jun 10 20:02:11 2015 New Revision: 1684757 URL: http://svn.apache.org/r1684757 Log: Add a test for closure of idle streams and fix the bugs it identified.
Modified: tomcat/trunk/java/org/apache/coyote/http2/Http2UpgradeHandler.java tomcat/trunk/test/org/apache/coyote/http2/Http2TestBase.java tomcat/trunk/test/org/apache/coyote/http2/TestHttp2Section_5_1.java Modified: tomcat/trunk/java/org/apache/coyote/http2/Http2UpgradeHandler.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http2/Http2UpgradeHandler.java?rev=1684757&r1=1684756&r2=1684757&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/http2/Http2UpgradeHandler.java (original) +++ tomcat/trunk/java/org/apache/coyote/http2/Http2UpgradeHandler.java Wed Jun 10 20:02:11 2015 @@ -119,7 +119,8 @@ public class Http2UpgradeHandler extends private final Map<Integer,Stream> streams = new HashMap<>(); private volatile int activeRemoteStreamCount = 0; private volatile int maxRemoteStreamId = 0; - private volatile int maxActiveRemoteStreamId = 0; + // Start at -1 so the 'add 2' logic in closeIdleStreams() works + private volatile int maxActiveRemoteStreamId = -1; // Tracking for when the connection is blocked (windowSize < 1) private final Object backLogLock = new Object(); @@ -141,6 +142,7 @@ public class Http2UpgradeHandler extends Stream stream = new Stream(key, this, coyoteRequest); streams.put(key, stream); maxRemoteStreamId = 1; + maxActiveRemoteStreamId = 1; activeRemoteStreamCount = 1; } } @@ -803,7 +805,7 @@ public class Http2UpgradeHandler extends private void closeIdleStreams(int newMaxActiveRemoteStreamId) throws Http2Exception { for (int i = maxActiveRemoteStreamId + 2; i < newMaxActiveRemoteStreamId; i += 2) { - Stream stream = getStream(newMaxActiveRemoteStreamId, false); + Stream stream = getStream(i, false); if (stream != null) { stream.closeIfIdle(); } 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=1684757&r1=1684756&r2=1684757&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/coyote/http2/Http2TestBase.java (original) +++ tomcat/trunk/test/org/apache/coyote/http2/Http2TestBase.java Wed Jun 10 20:02:11 2015 @@ -43,7 +43,6 @@ import org.apache.coyote.http2.Http2Pars import org.apache.tomcat.util.codec.binary.Base64; import org.apache.tomcat.util.http.MimeHeaders; - /** * Tests for compliance with the <a href="https://tools.ietf.org/html/rfc7540"> * HTTP/2 specification</a>. @@ -409,6 +408,26 @@ public abstract class Http2TestBase exte os.flush(); } + + void sendPriority(int streamId, int streamDependencyId, int weight) throws IOException { + byte[] priorityFrame = new byte[14]; + // length + ByteUtil.setThreeBytes(priorityFrame, 0, 5); + // type + priorityFrame[3] = FrameType.PRIORITY.getIdByte(); + // No flags + // Stream ID + ByteUtil.set31Bits(priorityFrame, 5, streamId); + + // Payload + ByteUtil.set31Bits(priorityFrame, 9, streamDependencyId); + ByteUtil.setOneBytes(priorityFrame, 13, weight); + + os.write(priorityFrame); + os.flush(); + } + + private static class TestInput implements Http2Parser.Input { private final InputStream is; 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=1684757&r1=1684756&r2=1684757&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 20:02:11 2015 @@ -178,11 +178,31 @@ public class TestHttp2Section_5_1 extend Assert.assertTrue(output.getTrace(), output.getTrace().startsWith("0-Goaway-[2147483647]-[" + Http2Error.PROTOCOL_ERROR.getCode() + "]-[")); - } - // TODO Remaining 5.1.1 tests + @Test + public void testImplicitClose() throws Exception { + hpackEncoder = new HpackEncoder(ConnectionSettings.DEFAULT_HEADER_TABLE_SIZE); + http2Connect(); + + sendPriority(3, 0, 16); + sendPriority(5, 0, 16); + + sendSimpleRequest(5); + readSimpleResponse(); + Assert.assertEquals(getSimpleResponseTrace(5), output.getTrace()); + output.clearTrace(); + + // Should trigger an error since stream 3 should have been implicitly + // closed. + sendSimpleRequest(3); + + parser.readFrame(true); + Assert.assertTrue(output.getTrace(), + output.getTrace().startsWith("0-Goaway-[2147483647]-[" + + Http2Error.PROTOCOL_ERROR.getCode() + "]-[")); + } // TODO 5.1.2 tests } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org