garydgregory commented on code in PR #510:
URL:
https://github.com/apache/httpcomponents-core/pull/510#discussion_r1894412006
##########
httpcore5-h2/src/test/java/org/apache/hc/core5/http2/impl/nio/TestAbstractH2StreamMultiplexer.java:
##########
@@ -270,5 +271,87 @@ void testInputHeaderContinuationFrame() throws
IOException, HttpException {
Mockito.verify(streamHandler).consumeHeader(headersCaptor.capture(),
ArgumentMatchers.eq(false));
Assertions.assertFalse(headersCaptor.getValue().isEmpty());
}
+
+
+ @Test
+ void testUpdateWindowBehaviorComparison() {
+ AtomicInteger window = new AtomicInteger(1); // Start with window at 1
+
+ // Test with new implementation where overflow should be capped at
Integer.MAX_VALUE
+ int resultNew = updateWindowNew(window, Integer.MAX_VALUE);
+ System.out.println("New implementation: Current window size after
attempted overflow: " + resultNew);
+ Assertions.assertEquals(Integer.MAX_VALUE, resultNew, "New
implementation should cap at Integer.MAX_VALUE");
+
+ // Reset for old implementation test
+ window = new AtomicInteger(1);
+
+ // Test with old implementation where an overflow should throw an
ArithmeticException
+ try {
+ updateWindowOld(window, Integer.MAX_VALUE);
+ Assertions.fail("Old implementation should throw
ArithmeticException for overflow");
+ } catch (final ArithmeticException e) {
+ System.out.println("Old implementation: ArithmeticException
caught: " + e.getMessage());
+ }
+
+ // Test non-overflow scenario for both implementations
+ window = new AtomicInteger(1);
+ final int resultNewSafe = updateWindowNew(window, Integer.MAX_VALUE /
2 - 1);
+ System.out.println("New safe update result: " + resultNewSafe);
Review Comment:
I don't think we should write to the console.
--
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]