From 4becfa2b0f4229bc1b75fac5198477fd4b569d16 Mon Sep 17 00:00:00 2001 From: sullis Date: Wed, 25 Nov 2026 13:12:40 -0800 Subject: [PATCH 1/2] Strengthen LargeResponseTest assertions --- .../asynchttpclient/LargeResponseTest.java | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/client/src/test/java/org/asynchttpclient/LargeResponseTest.java b/client/src/test/java/org/asynchttpclient/LargeResponseTest.java index 5651ebb84..3622b0fe5 100644 --- a/client/src/test/java/org/asynchttpclient/LargeResponseTest.java +++ b/client/src/test/java/org/asynchttpclient/LargeResponseTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2025 AsyncHttpClient Project. All rights reserved. + * Copyright (c) 2026 AsyncHttpClient Project. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,9 @@ import java.time.Duration; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.atomic.AtomicReference; import org.apache.commons.io.FileUtils; import org.jetbrains.annotations.Nullable; import org.junit.jupiter.api.AfterAll; @@ -38,6 +40,8 @@ import org.slf4j.LoggerFactory; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; @ExtendWith(NettyLeakDetectorExtension.class) @@ -94,7 +98,9 @@ static void stopServer() { @Test void handleLargeResponse() throws Throwable { AtomicInteger status = new AtomicInteger(-1); - AtomicInteger throwableCount = new AtomicInteger(); + AtomicReference failure = new AtomicReference<>(); + AtomicBoolean headersReceived = new AtomicBoolean(); + AtomicBoolean completed = new AtomicBoolean(); AtomicLong bytesReceived = new AtomicLong(); AtomicLong bodyPartCount = new AtomicLong(); @@ -113,6 +119,7 @@ public State onStatusReceived(HttpResponseStatus responseStatus) @Override public State onHeadersReceived(HttpHeaders headers) throws Exception { + headersReceived.set(true); return State.CONTINUE; } @@ -122,24 +129,18 @@ public State onBodyPartReceived(HttpResponseBodyPart bodyPart) bodyPartCount.incrementAndGet(); bytesReceived.addAndGet(bodyPart.length()); - /* - LOG.info("onBodyPartReceived: " - + "bodyPartCount=" + bodyPartCount.get() - + " bodyPartLength: " - + FileUtils.byteCountToDisplaySize(bodyPart.length())); - */ - return State.CONTINUE; } @Override public void onThrowable(Throwable t) { - throwableCount.incrementAndGet(); + failure.compareAndSet(null, t); } @Override public @Nullable Object onCompleted() throws Exception { + completed.set(true); return null; } }); @@ -147,7 +148,10 @@ public void onThrowable(Throwable t) { future.get(1, TimeUnit.MINUTES); assertEquals(200, status.get()); - assertEquals(0, throwableCount.get()); + assertNull(failure.get(), "unexpected failure: " + failure.get()); + assertTrue(headersReceived.get(), "headers were not received"); + assertTrue(completed.get(), "onCompleted was not called"); + assertTrue(bodyPartCount.get() > 0, "no body parts received"); assertEquals(responseSize, bytesReceived.get()); LOG.info("Body part count: " + bodyPartCount); From 59893e09ac38c90e60b6f92b8c351322c577077b Mon Sep 17 00:00:00 2001 From: Aayush Atharva <24762260+hyperxpro@users.noreply.github.com> Date: Fri, 27 Nov 2026 20:46:31 +0530 Subject: [PATCH 2/2] Update client/src/test/java/org/asynchttpclient/LargeResponseTest.java --- client/src/test/java/org/asynchttpclient/LargeResponseTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/test/java/org/asynchttpclient/LargeResponseTest.java b/client/src/test/java/org/asynchttpclient/LargeResponseTest.java index 3622b0fe5..41853bfd4 100644 --- a/client/src/test/java/org/asynchttpclient/LargeResponseTest.java +++ b/client/src/test/java/org/asynchttpclient/LargeResponseTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2026 AsyncHttpClient Project. All rights reserved. + * Copyright (c) 2015-2025 AsyncHttpClient Project. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.