ok2c commented on code in PR #741:
URL:
https://github.com/apache/httpcomponents-core/pull/741#discussion_r4505876453
##########
httpcore5-h2/src/test/java/org/apache/hc/core5/http2/impl/nio/TestAbstractH2StreamMultiplexer.java:
##########
@@ -2547,4 +2547,45 @@ void
testDataOnReservedRemoteStreamIsConnectionProtocolError() throws Exception
ArgumentMatchers.anyBoolean());
}
+
+ @Test
+ void testMalformedSettingsAfterOverheadLimitReportsFrameSizeError() throws
Exception {
+ final AbstractH2StreamMultiplexer mux = new H2StreamMultiplexerImpl(
+ protocolIOSession,
+ FRAME_FACTORY,
+ StreamIdGenerator.ODD,
+ httpProcessor,
+ CharCodingConfig.DEFAULT,
+ H2Config.custom().build(),
+ h2StreamListener,
+ () -> streamHandler);
+
+ // Exhaust the per-connection limiter deterministically without
depending
+ // on test execution speed. TestAbstractH2StreamMultiplexer already
uses
+ // reflection for internal protocol state checks.
+ final Field limiterField = AbstractH2StreamMultiplexer.class
Review Comment:
@arturobernalg Rather make `H2ControlFrameRateLimiter` injectable through
the constructor to avoid having to use reflection. Please also make
`H2ControlFrameRateLimiter` minimally configurable through constructor
parameters..
##########
httpcore5-h2/src/test/java/org/apache/hc/core5/http2/impl/nio/TestH2ControlFrameRateLimiter.java:
##########
@@ -0,0 +1,96 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.core5.http2.impl.nio;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+class TestH2ControlFrameRateLimiter {
+
+ @Test
+ void testBurstAndRejection() {
+ final H2ControlFrameRateLimiter limiter = new
H2ControlFrameRateLimiter();
+ for (int i = 0; i < H2ControlFrameRateLimiter.CAPACITY; i++) {
+ Assertions.assertTrue(limiter.accept(10L));
+ }
+ Assertions.assertFalse(limiter.accept(10L));
+ }
+
+ @Test
+ void testRefillAndRecovery() {
+ final H2ControlFrameRateLimiter limiter = new
H2ControlFrameRateLimiter();
+ for (int i = 0; i < H2ControlFrameRateLimiter.CAPACITY; i++) {
+ Assertions.assertTrue(limiter.accept(1L));
+ }
+ Assertions.assertFalse(limiter.accept(1L));
+ Assertions.assertTrue(limiter.accept(1L + 1_000_000_000L /
H2ControlFrameRateLimiter.REFILL_PER_SECOND));
Review Comment:
@arturobernalg I am still having a hard time validating the algorithm. Could
you use `TimeUnit`s like `TimeUnit.SECONDS.toNanos(1)` to make it a little
easier to understand the expectations of the test case.
##########
httpcore5-h2/src/test/java/org/apache/hc/core5/http2/examples/H2OverheadProtectionExample.java:
##########
@@ -0,0 +1,400 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.http2.examples;
+
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.EOFException;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.nio.charset.StandardCharsets;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.HttpStatus;
+import org.apache.hc.core5.http.Message;
+import org.apache.hc.core5.http.Method;
+import org.apache.hc.core5.http.URIScheme;
+import org.apache.hc.core5.http.impl.bootstrap.HttpAsyncServer;
+import org.apache.hc.core5.http.message.BasicHttpResponse;
+import org.apache.hc.core5.http.nio.support.AsyncServerPipeline;
+import org.apache.hc.core5.http2.HttpVersionPolicy;
+import org.apache.hc.core5.http2.impl.nio.bootstrap.H2ServerBootstrap;
+import org.apache.hc.core5.io.CloseMode;
+import org.apache.hc.core5.reactor.ListenerEndpoint;
+
+public final class H2OverheadProtectionExample {
Review Comment:
@arturobernalg This is too much for an example class, too complex and not
really helpful. Either convert it to a proper integration test or drop it
entirely.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]