You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by rs...@apache.org on 2025/12/27 05:55:36 UTC

(httpcomponents-client) branch master updated (bbc3ac34a -> e30b8670f)

This is an automated email from the ASF dual-hosted git repository.

rschmitt pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git


    from bbc3ac34a Fix NPE in connection evictor setup (#774)
     new 43d35fc1d Bind test servers to loopback address
     new e30b8670f TestValidateAfterInactivity: Use closeQuietly

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../HttpClientObservationSupportTest.java          |  2 ++
 .../impl/ObservationAsyncExecInterceptorTest.java  |  2 ++
 .../ObservationClassicExecInterceptorTest.java     |  2 ++
 .../interceptors/AsyncTimerExecTest.java           |  2 ++
 .../interceptors/IoByteCounterExecTest.java        |  2 ++
 .../observation/interceptors/TimerExecTest.java    |  2 ++
 .../testing/TestValidateAfterInactivity.java       | 10 +++-----
 .../testing/sync/TestCookieVirtualHost.java        |  2 ++
 .../testing/sync/TestDefaultClientTlsStrategy.java | 28 +++++++++++++++-------
 .../sync/TestFutureRequestExecutionService.java    |  2 ++
 .../testing/sync/TestMalformedServerResponse.java  |  2 ++
 .../examples/AsyncClientEarlyHintsEndToEnd.java    |  1 +
 .../examples/AsyncClientServerBrotliRoundTrip.java |  2 ++
 .../examples/AsyncClientServerZstdExample.java     |  2 ++
 .../AsyncClientZstdCompressionExample.java         |  2 ++
 .../examples/ClientServerCompressionExample.java   |  2 ++
 16 files changed, 49 insertions(+), 16 deletions(-)


(httpcomponents-client) 01/02: Bind test servers to loopback address

Posted by rs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rschmitt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git

commit 43d35fc1db9f6531f0e33ec81a29899c61667c2c
Author: Ryan Schmitt <rs...@apache.org>
AuthorDate: Fri Dec 26 17:16:37 2025 -0500

    Bind test servers to loopback address
    
    Binding to 0.0.0.0 is not guaranteed to result in a socket that is
    reachable via the loopback address, even when requesting an ephemeral
    port assignment by binding to port 0. It is possible for another process
    on the system to bind to the loopback address at that same port, and
    then client requests will go to that process instead of the test server,
    resulting in occasional cryptic test failures.
    
    By instead binding to the loopback address specifically, rather than the
    wildcard address, we can prevent binding to a port that is already in
    use. This significantly improves the reliability of the test suite.
---
 .../HttpClientObservationSupportTest.java          |  2 ++
 .../impl/ObservationAsyncExecInterceptorTest.java  |  2 ++
 .../ObservationClassicExecInterceptorTest.java     |  2 ++
 .../interceptors/AsyncTimerExecTest.java           |  2 ++
 .../interceptors/IoByteCounterExecTest.java        |  2 ++
 .../observation/interceptors/TimerExecTest.java    |  2 ++
 .../testing/sync/TestCookieVirtualHost.java        |  2 ++
 .../testing/sync/TestDefaultClientTlsStrategy.java | 28 +++++++++++++++-------
 .../sync/TestFutureRequestExecutionService.java    |  2 ++
 .../testing/sync/TestMalformedServerResponse.java  |  2 ++
 .../examples/AsyncClientEarlyHintsEndToEnd.java    |  1 +
 .../examples/AsyncClientServerBrotliRoundTrip.java |  2 ++
 .../examples/AsyncClientServerZstdExample.java     |  2 ++
 .../AsyncClientZstdCompressionExample.java         |  2 ++
 .../examples/ClientServerCompressionExample.java   |  2 ++
 15 files changed, 46 insertions(+), 9 deletions(-)

diff --git a/httpclient5-observation/src/test/java/org/apache/hc/client5/http/observation/HttpClientObservationSupportTest.java b/httpclient5-observation/src/test/java/org/apache/hc/client5/http/observation/HttpClientObservationSupportTest.java
index 025fc3aa6..152818fe5 100644
--- a/httpclient5-observation/src/test/java/org/apache/hc/client5/http/observation/HttpClientObservationSupportTest.java
+++ b/httpclient5-observation/src/test/java/org/apache/hc/client5/http/observation/HttpClientObservationSupportTest.java
@@ -29,6 +29,7 @@
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 
+import java.net.InetAddress;
 import java.util.EnumSet;
 
 import io.micrometer.core.instrument.MeterRegistry;
@@ -66,6 +67,7 @@ void shutDown() {
     void basicIoAndPoolMetricsRecorded() throws Exception {
         // Register handler FOR THE HOST WE'LL USE ("localhost")
         server = ServerBootstrap.bootstrap()
+                .setLocalAddress(InetAddress.getLoopbackAddress())
                 .setListenerPort(0)
                 .register("localhost", "/get", (request, response, context) -> {
                     response.setCode(HttpStatus.SC_OK);
diff --git a/httpclient5-observation/src/test/java/org/apache/hc/client5/http/observation/impl/ObservationAsyncExecInterceptorTest.java b/httpclient5-observation/src/test/java/org/apache/hc/client5/http/observation/impl/ObservationAsyncExecInterceptorTest.java
index cfaaef024..72a5b20ab 100644
--- a/httpclient5-observation/src/test/java/org/apache/hc/client5/http/observation/impl/ObservationAsyncExecInterceptorTest.java
+++ b/httpclient5-observation/src/test/java/org/apache/hc/client5/http/observation/impl/ObservationAsyncExecInterceptorTest.java
@@ -28,6 +28,7 @@
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
+import java.net.InetAddress;
 import java.util.EnumSet;
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
@@ -88,6 +89,7 @@ void tearDown() {
     void emitsObservationAroundAsyncCall() throws Exception {
         // 1) Bind handler to the *localhost* vhost to avoid 421
         server = ServerBootstrap.bootstrap()
+                .setLocalAddress(InetAddress.getLoopbackAddress())
                 .setListenerPort(0)
                 .register("localhost", "/get", (request, response, context) -> {
                     response.setCode(HttpStatus.SC_OK);
diff --git a/httpclient5-observation/src/test/java/org/apache/hc/client5/http/observation/impl/ObservationClassicExecInterceptorTest.java b/httpclient5-observation/src/test/java/org/apache/hc/client5/http/observation/impl/ObservationClassicExecInterceptorTest.java
index 4a7df7b83..a69cb2b58 100644
--- a/httpclient5-observation/src/test/java/org/apache/hc/client5/http/observation/impl/ObservationClassicExecInterceptorTest.java
+++ b/httpclient5-observation/src/test/java/org/apache/hc/client5/http/observation/impl/ObservationClassicExecInterceptorTest.java
@@ -28,6 +28,7 @@
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
+import java.net.InetAddress;
 import java.util.EnumSet;
 import java.util.concurrent.atomic.AtomicInteger;
 
@@ -84,6 +85,7 @@ void tearDown() {
     void emitsObservationAroundClassicCall() throws Exception {
         // Start an in-process HTTP server and register handler for the exact host we’ll use: "localhost"
         server = ServerBootstrap.bootstrap()
+                .setLocalAddress(InetAddress.getLoopbackAddress())
                 .setListenerPort(0)
                 .register("localhost", "/get", (request, response, context) -> {
                     response.setCode(HttpStatus.SC_OK);
diff --git a/httpclient5-observation/src/test/java/org/apache/hc/client5/http/observation/interceptors/AsyncTimerExecTest.java b/httpclient5-observation/src/test/java/org/apache/hc/client5/http/observation/interceptors/AsyncTimerExecTest.java
index 8dfa57650..e0d152bd9 100644
--- a/httpclient5-observation/src/test/java/org/apache/hc/client5/http/observation/interceptors/AsyncTimerExecTest.java
+++ b/httpclient5-observation/src/test/java/org/apache/hc/client5/http/observation/interceptors/AsyncTimerExecTest.java
@@ -30,6 +30,7 @@
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
+import java.net.InetAddress;
 import java.util.EnumSet;
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
@@ -68,6 +69,7 @@ void tearDown() {
     void recordsAsyncLatencyAndCounter() throws Exception {
         // Local classic server (async client can talk to it)
         server = ServerBootstrap.bootstrap()
+                .setLocalAddress(InetAddress.getLoopbackAddress())
                 .setListenerPort(0)
                 .register("localhost", "/get", (request, response, context) -> {
                     response.setCode(HttpStatus.SC_OK);
diff --git a/httpclient5-observation/src/test/java/org/apache/hc/client5/http/observation/interceptors/IoByteCounterExecTest.java b/httpclient5-observation/src/test/java/org/apache/hc/client5/http/observation/interceptors/IoByteCounterExecTest.java
index 1280fe685..b13a0ee89 100644
--- a/httpclient5-observation/src/test/java/org/apache/hc/client5/http/observation/interceptors/IoByteCounterExecTest.java
+++ b/httpclient5-observation/src/test/java/org/apache/hc/client5/http/observation/interceptors/IoByteCounterExecTest.java
@@ -30,6 +30,7 @@
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
+import java.net.InetAddress;
 import java.util.EnumSet;
 
 import io.micrometer.core.instrument.MeterRegistry;
@@ -68,6 +69,7 @@ void tearDown() {
     void countsRequestAndResponseBytes() throws Exception {
         // Echo-like handler with known response size
         server = ServerBootstrap.bootstrap()
+                .setLocalAddress(InetAddress.getLoopbackAddress())
                 .setListenerPort(0)
                 .register("localhost", "/echo", (request, response, context) -> {
                     response.setCode(HttpStatus.SC_OK);
diff --git a/httpclient5-observation/src/test/java/org/apache/hc/client5/http/observation/interceptors/TimerExecTest.java b/httpclient5-observation/src/test/java/org/apache/hc/client5/http/observation/interceptors/TimerExecTest.java
index 97e760576..bd01b37ac 100644
--- a/httpclient5-observation/src/test/java/org/apache/hc/client5/http/observation/interceptors/TimerExecTest.java
+++ b/httpclient5-observation/src/test/java/org/apache/hc/client5/http/observation/interceptors/TimerExecTest.java
@@ -30,6 +30,7 @@
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
+import java.net.InetAddress;
 import java.util.EnumSet;
 
 import io.micrometer.core.instrument.MeterRegistry;
@@ -68,6 +69,7 @@ void tearDown() {
     void recordsLatencyAndCounter() throws Exception {
         // Local classic server
         server = ServerBootstrap.bootstrap()
+                .setLocalAddress(InetAddress.getLoopbackAddress())
                 .setListenerPort(0)
                 .register("localhost", "/get", (request, response, context) -> {
                     response.setCode(HttpStatus.SC_OK);
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestCookieVirtualHost.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestCookieVirtualHost.java
index 8e5eced0a..c57d188e6 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestCookieVirtualHost.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestCookieVirtualHost.java
@@ -26,6 +26,7 @@
  */
 package org.apache.hc.client5.testing.sync;
 
+import java.net.InetAddress;
 import java.net.URI;
 import java.util.List;
 
@@ -64,6 +65,7 @@ void shutDown() {
     @Test
     void testCookieMatchingWithVirtualHosts() throws Exception {
         server = ServerBootstrap.bootstrap()
+                .setLocalAddress(InetAddress.getLoopbackAddress())
                 .register("app.mydomain.fr", "*", (request, response, context) -> {
 
                     final int n = Integer.parseInt(request.getFirstHeader("X-Request").getValue());
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestDefaultClientTlsStrategy.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestDefaultClientTlsStrategy.java
index 6cc605094..74305be44 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestDefaultClientTlsStrategy.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestDefaultClientTlsStrategy.java
@@ -96,6 +96,7 @@ public boolean isFired() {
     void testBasicSSL() throws Exception {
         // @formatter:off
         this.server = ServerBootstrap.bootstrap()
+                .setLocalAddress(InetAddress.getLoopbackAddress())
                 .setSslContext(SSLTestContexts.createServerSSLContext())
                 .setRequestRouter((r, c) -> null)
                 .create();
@@ -126,6 +127,7 @@ void testBasicSSL() throws Exception {
     void testBasicDefaultHostnameVerifier() throws Exception {
         // @formatter:off
         this.server = ServerBootstrap.bootstrap()
+                .setLocalAddress(InetAddress.getLoopbackAddress())
                 .setSslContext(SSLTestContexts.createServerSSLContext())
                 .setRequestRouter((r, c) -> null)
                 .create();
@@ -153,6 +155,7 @@ void testBasicDefaultHostnameVerifier() throws Exception {
     void testClientAuthSSL() throws Exception {
         // @formatter:off
         this.server = ServerBootstrap.bootstrap()
+                .setLocalAddress(InetAddress.getLoopbackAddress())
                 .setSslContext(SSLTestContexts.createServerSSLContext())
                 .setRequestRouter((r, c) -> null)
                 .create();
@@ -183,6 +186,7 @@ void testClientAuthSSL() throws Exception {
     void testClientAuthSSLFailure() throws Exception {
         // @formatter:off
         this.server = ServerBootstrap.bootstrap()
+                .setLocalAddress(InetAddress.getLoopbackAddress())
                 .setSslContext(SSLTestContexts.createServerSSLContext())
                 .setSslSetupHandler(sslParameters -> sslParameters.setNeedClientAuth(true))
                 .setRequestRouter((r, c) -> null)
@@ -217,6 +221,7 @@ void testClientAuthSSLFailure() throws Exception {
     void testSSLTrustVerification() throws Exception {
         // @formatter:off
         this.server = ServerBootstrap.bootstrap()
+                .setLocalAddress(InetAddress.getLoopbackAddress())
                 .setSslContext(SSLTestContexts.createServerSSLContext())
                 .setRequestRouter((r, c) -> null)
                 .create();
@@ -251,6 +256,7 @@ private void testSSLTrustVerificationOverride(final TrustStrategy trustStrategy)
             throws Exception {
         // @formatter:off
         this.server = ServerBootstrap.bootstrap()
+                .setLocalAddress(InetAddress.getLoopbackAddress())
                 .setSslContext(SSLTestContexts.createServerSSLContext())
                 .setRequestRouter((r, c) -> null)
                 .create();
@@ -284,6 +290,7 @@ private void testSSLTrustVerificationOverride(final TrustStrategy trustStrategy)
     void testSSLDisabledByDefault() throws Exception {
         // @formatter:off
         this.server = ServerBootstrap.bootstrap()
+                .setLocalAddress(InetAddress.getLoopbackAddress())
                 .setSslContext(SSLTestContexts.createServerSSLContext())
                 .setSslSetupHandler(sslParameters -> sslParameters.setProtocols(new String[] {"SSLv3"}))
                 .setRequestRouter((r, c) -> null)
@@ -337,6 +344,7 @@ void testWeakCiphersDisabledByDefault() {
     private void testWeakCipherDisabledByDefault(final String cipherSuite) throws Exception {
         // @formatter:off
         this.server = ServerBootstrap.bootstrap()
+                .setLocalAddress(InetAddress.getLoopbackAddress())
                 .setSslContext(SSLTestContexts.createServerSSLContext())
                 .setSslSetupHandler(sslParameters -> sslParameters.setProtocols(new String[] {cipherSuite}))
                 .setRequestRouter((r, c) -> null)
@@ -362,15 +370,16 @@ private void testWeakCipherDisabledByDefault(final String cipherSuite) throws Ex
     void testHostnameVerificationClient() throws Exception {
         // @formatter:off
         this.server = ServerBootstrap.bootstrap()
+                .setLocalAddress(InetAddress.getLoopbackAddress())
                 .setSslContext(SSLTestContexts.createServerSSLContext())
                 .setRequestRouter((r, c) -> null)
                 .create();
         // @formatter:on
         this.server.start();
 
-        final HttpHost target1 = new HttpHost("https", "localhost", server.getLocalPort());
+        final HttpHost target1 = new HttpHost("https", InetAddress.getLoopbackAddress(), "localhost", server.getLocalPort());
 
-        try (final Socket socket = new Socket(InetAddress.getLocalHost(), server.getLocalPort())) {
+        try (final Socket socket = new Socket(InetAddress.getLoopbackAddress(), server.getLocalPort())) {
             final TlsSocketStrategy tlsStrategy = new DefaultClientTlsStrategy(
                     SSLTestContexts.createClientSSLContext(),
                     HostnameVerificationPolicy.CLIENT,
@@ -386,9 +395,9 @@ void testHostnameVerificationClient() throws Exception {
             MatcherAssert.assertThat(Objects.toString(session.getPeerPrincipal()), Matchers.startsWith("CN=localhost"));
         }
 
-        final HttpHost target2 = new HttpHost("https", "some-other-host", server.getLocalPort());
+        final HttpHost target2 = new HttpHost("https", InetAddress.getLoopbackAddress(), "some-other-host", server.getLocalPort());
 
-        try (final Socket socket = new Socket(InetAddress.getLocalHost(), server.getLocalPort())) {
+        try (final Socket socket = new Socket(InetAddress.getLoopbackAddress(), server.getLocalPort())) {
             final TlsSocketStrategy tlsStrategy = new DefaultClientTlsStrategy(
                     SSLTestContexts.createClientSSLContext(),
                     HostnameVerificationPolicy.CLIENT,
@@ -403,7 +412,7 @@ void testHostnameVerificationClient() throws Exception {
                             context));
         }
 
-        try (final Socket socket = new Socket(InetAddress.getLocalHost(), server.getLocalPort())) {
+        try (final Socket socket = new Socket(InetAddress.getLoopbackAddress(), server.getLocalPort())) {
             final TlsSocketStrategy tlsStrategy = new DefaultClientTlsStrategy(
                     SSLTestContexts.createClientSSLContext(),
                     HostnameVerificationPolicy.CLIENT,
@@ -424,15 +433,16 @@ void testHostnameVerificationClient() throws Exception {
     void testHostnameVerificationBuiltIn() throws Exception {
         // @formatter:off
         this.server = ServerBootstrap.bootstrap()
+                .setLocalAddress(InetAddress.getLoopbackAddress())
                 .setSslContext(SSLTestContexts.createServerSSLContext())
                 .setRequestRouter((r, c) -> null)
                 .create();
         // @formatter:on
         this.server.start();
 
-        final HttpHost target1 = new HttpHost("https", "localhost", server.getLocalPort());
+        final HttpHost target1 = new HttpHost("https", InetAddress.getLoopbackAddress(), "localhost", server.getLocalPort());
 
-        try (final Socket socket = new Socket(InetAddress.getLocalHost(), server.getLocalPort())) {
+        try (final Socket socket = new Socket(InetAddress.getLoopbackAddress(), server.getLocalPort())) {
             final TlsSocketStrategy tlsStrategy = new DefaultClientTlsStrategy(
                     SSLTestContexts.createClientSSLContext(),
                     HostnameVerificationPolicy.BUILTIN,
@@ -448,9 +458,9 @@ void testHostnameVerificationBuiltIn() throws Exception {
             MatcherAssert.assertThat(Objects.toString(session.getPeerPrincipal()), Matchers.startsWith("CN=localhost"));
         }
 
-        final HttpHost target2 = new HttpHost("https", "some-other-host", server.getLocalPort());
+        final HttpHost target2 = new HttpHost("https", InetAddress.getLoopbackAddress(), "some-other-host", server.getLocalPort());
 
-        try (final Socket socket = new Socket(InetAddress.getLocalHost(), server.getLocalPort())) {
+        try (final Socket socket = new Socket(InetAddress.getLoopbackAddress(), server.getLocalPort())) {
             final TlsSocketStrategy tlsStrategy = new DefaultClientTlsStrategy(
                     SSLTestContexts.createClientSSLContext(),
                     HostnameVerificationPolicy.BUILTIN,
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestFutureRequestExecutionService.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestFutureRequestExecutionService.java
index 1a67f2949..6f302c3ff 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestFutureRequestExecutionService.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestFutureRequestExecutionService.java
@@ -28,6 +28,7 @@
 
 import static org.hamcrest.MatcherAssert.assertThat;
 
+import java.net.InetAddress;
 import java.util.LinkedList;
 import java.util.Queue;
 import java.util.concurrent.CancellationException;
@@ -72,6 +73,7 @@ class TestFutureRequestExecutionService {
     @BeforeEach
     void before() throws Exception {
         this.localServer = ServerBootstrap.bootstrap()
+                .setLocalAddress(InetAddress.getLoopbackAddress())
                 .setCanonicalHostName("localhost")
                 .register("/wait", (request, response, context) -> {
                     try {
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestMalformedServerResponse.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestMalformedServerResponse.java
index 21b034bde..91ea8a347 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestMalformedServerResponse.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestMalformedServerResponse.java
@@ -27,6 +27,7 @@
 package org.apache.hc.client5.testing.sync;
 
 import java.io.IOException;
+import java.net.InetAddress;
 import java.net.Socket;
 
 import org.apache.hc.client5.http.classic.methods.HttpGet;
@@ -97,6 +98,7 @@ public DefaultBHttpServerConnection createConnection(final Socket socket) throws
     @Test
     void testNoContentResponseWithGarbage() throws Exception {
         server = ServerBootstrap.bootstrap()
+                .setLocalAddress(InetAddress.getLoopbackAddress())
                 .setCanonicalHostName("localhost")
                 .setConnectionFactory(new BrokenServerConnectionFactory())
                 .register("/nostuff", (request, response, context) -> response.setCode(HttpStatus.SC_NO_CONTENT))
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientEarlyHintsEndToEnd.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientEarlyHintsEndToEnd.java
index 4e03ee09b..8a32b5776 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientEarlyHintsEndToEnd.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientEarlyHintsEndToEnd.java
@@ -82,6 +82,7 @@ public class AsyncClientEarlyHintsEndToEnd {
     public static void main(final String[] args) throws Exception {
         // --- Start minimal async server that sends 103 then 200
         final HttpAsyncServer server = AsyncServerBootstrap.bootstrap()
+                // .setLocalAddress(InetAddress.getLoopbackAddress())
                 .setCanonicalHostName("localhost")
                 .register("/eh", () -> new AsyncServerExchangeHandler() {
 
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientServerBrotliRoundTrip.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientServerBrotliRoundTrip.java
index 74f522f78..2924bc556 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientServerBrotliRoundTrip.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientServerBrotliRoundTrip.java
@@ -30,6 +30,7 @@
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.InetAddress;
 import java.nio.charset.StandardCharsets;
 import java.util.concurrent.Future;
 
@@ -85,6 +86,7 @@ public final class AsyncClientServerBrotliRoundTrip {
 
     public static void main(final String[] args) throws Exception {
         final HttpServer server = ServerBootstrap.bootstrap()
+                .setLocalAddress(InetAddress.getLoopbackAddress())
                 .setListenerPort(0)
                 .setCanonicalHostName("localhost")
                 .register("/echo", new EchoHandler())
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientServerZstdExample.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientServerZstdExample.java
index 3eb4894ed..74c2fdbef 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientServerZstdExample.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientServerZstdExample.java
@@ -30,6 +30,7 @@
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.InetAddress;
 import java.nio.charset.StandardCharsets;
 import java.util.concurrent.Future;
 
@@ -100,6 +101,7 @@ public final class AsyncClientServerZstdExample {
 
     public static void main(final String[] args) throws Exception {
         final HttpServer server = ServerBootstrap.bootstrap()
+                .setLocalAddress(InetAddress.getLoopbackAddress())
                 .setListenerPort(0)
                 .setCanonicalHostName("localhost")
                 .register("/echo", new EchoHandler())
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientZstdCompressionExample.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientZstdCompressionExample.java
index 5da9d741f..58ad574e4 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientZstdCompressionExample.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientZstdCompressionExample.java
@@ -30,6 +30,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.net.InetAddress;
 import java.nio.charset.StandardCharsets;
 import java.util.concurrent.Future;
 
@@ -113,6 +114,7 @@ public final class AsyncClientZstdCompressionExample {
     public static void main(final String[] args) throws Exception {
         // --- tiny classic server that decodes zstd requests and echoes plain text ---
         final HttpServer server = ServerBootstrap.bootstrap()
+                .setLocalAddress(InetAddress.getLoopbackAddress())
                 .setListenerPort(0)
                 .setCanonicalHostName("localhost")
                 .register("/echo", new EchoHandler())
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientServerCompressionExample.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientServerCompressionExample.java
index 4656cf88d..76a579bb8 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientServerCompressionExample.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientServerCompressionExample.java
@@ -31,6 +31,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.net.InetAddress;
 import java.nio.charset.StandardCharsets;
 
 import org.apache.commons.compress.compressors.CompressorException;
@@ -88,6 +89,7 @@ public static void main(final String[] args) throws Exception {
             port = Integer.parseInt(args[0]);
         }
         final HttpServer server = ServerBootstrap.bootstrap()
+                .setLocalAddress(InetAddress.getLoopbackAddress())
                 .setListenerPort(port)
                 .setCanonicalHostName("localhost")
                 .register("/echo", new EchoHandler())


(httpcomponents-client) 02/02: TestValidateAfterInactivity: Use closeQuietly

Posted by rs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rschmitt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git

commit e30b8670f45ba4ad516f49474aa0a0b55ade5eac
Author: Ryan Schmitt <rs...@apache.org>
AuthorDate: Fri Dec 26 22:32:01 2025 -0500

    TestValidateAfterInactivity: Use closeQuietly
---
 .../apache/hc/client5/testing/TestValidateAfterInactivity.java | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/TestValidateAfterInactivity.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/TestValidateAfterInactivity.java
index 38e949b69..800732e15 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/TestValidateAfterInactivity.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/TestValidateAfterInactivity.java
@@ -27,6 +27,7 @@
 
 package org.apache.hc.client5.testing;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
 import org.apache.hc.client5.http.async.methods.SimpleHttpResponse;
 import org.apache.hc.client5.http.async.methods.SimpleRequestBuilder;
@@ -90,13 +91,8 @@ void setup() throws Exception {
     @AfterEach
     void tearDown() throws Exception {
         final SocketChannel socket = currentConnection.getAndSet(null);
-        if (socket != null) {
-            socket.close();
-        }
-
-        if (serverSocket != null) {
-            serverSocket.close();
-        }
+        IOUtils.closeQuietly(socket);
+        IOUtils.closeQuietly(serverSocket);
         if (serverThread != null) {
             serverThread.interrupt();
             serverThread.join(1000);