diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/IntegrationTestBase.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/IntegrationTestBase.java index 4ba9ce113..31802278f 100644 --- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/IntegrationTestBase.java +++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/IntegrationTestBase.java @@ -30,6 +30,7 @@ package org.apache.hc.client5.testing.async; import java.net.InetSocketAddress; import java.util.concurrent.Future; +import org.apache.hc.client5.http.config.RequestConfig; import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient; import org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder; import org.apache.hc.core5.function.Decorator; @@ -62,7 +63,13 @@ public abstract class IntegrationTestBase extends LocalAsyncServerTestBase { @Override protected void before() throws Throwable { - clientBuilder = HttpAsyncClientBuilder.create().setConnectionManager(connManager); + clientBuilder = HttpAsyncClientBuilder.create() + .setDefaultRequestConfig(RequestConfig.custom() + .setSocketTimeout(TIMEOUT) + .setConnectTimeout(TIMEOUT) + .setConnectionRequestTimeout(TIMEOUT) + .build()) + .setConnectionManager(connManager); } @Override diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/LocalAsyncServerTestBase.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/LocalAsyncServerTestBase.java index 71795ad0c..5ae533c16 100644 --- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/LocalAsyncServerTestBase.java +++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/LocalAsyncServerTestBase.java @@ -37,11 +37,15 @@ import org.apache.hc.core5.http.nio.AsyncServerExchangeHandler; import org.apache.hc.core5.reactor.IOReactorConfig; import org.apache.hc.core5.testing.nio.Http2TestServer; import org.apache.hc.core5.util.TimeValue; +import org.apache.hc.core5.util.Timeout; import org.junit.Rule; import org.junit.rules.ExternalResource; public abstract class LocalAsyncServerTestBase { + public static final Timeout TIMEOUT = Timeout.ofSeconds(30); + public static final Timeout LONG_TIMEOUT = Timeout.ofSeconds(60); + protected final URIScheme scheme; public LocalAsyncServerTestBase(final URIScheme scheme) { @@ -61,7 +65,9 @@ public abstract class LocalAsyncServerTestBase { @Override protected void before() throws Throwable { server = new Http2TestServer( - IOReactorConfig.DEFAULT, + IOReactorConfig.custom() + .setSoTimeout(TIMEOUT) + .build(), scheme == URIScheme.HTTPS ? SSLTestContexts.createServerSSLContext() : null); server.register("/echo/*", new Supplier() { diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestAsyncStatefulConnManagement.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestAsyncStatefulConnManagement.java index 39e675064..4e27593b5 100644 --- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestAsyncStatefulConnManagement.java +++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestAsyncStatefulConnManagement.java @@ -97,7 +97,7 @@ public class TestAsyncStatefulConnManagement extends IntegrationTestBase { worker.start(); } for (final HttpWorker worker : workers) { - worker.join(10000); + worker.join(LONG_TIMEOUT.toMillis()); } for (final HttpWorker worker : workers) { final Exception ex = worker.getException(); diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttpAsyncMinimal.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttpAsyncMinimal.java index 5ae7fe7c3..97e3acb97 100644 --- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttpAsyncMinimal.java +++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttpAsyncMinimal.java @@ -64,6 +64,7 @@ import org.apache.hc.core5.reactor.IOReactorConfig; import org.apache.hc.core5.reactor.ListenerEndpoint; import org.apache.hc.core5.testing.nio.Http2TestServer; import org.apache.hc.core5.util.TimeValue; +import org.apache.hc.core5.util.Timeout; import org.hamcrest.CoreMatchers; import org.junit.Assert; import org.junit.Rule; @@ -75,6 +76,8 @@ import org.junit.runners.Parameterized; @RunWith(Parameterized.class) public class TestHttpAsyncMinimal { + public static final Timeout TIMEOUT = Timeout.ofSeconds(30); + @Parameterized.Parameters(name = "{0} {1}") public static Collection protocols() { return Arrays.asList(new Object[][]{ @@ -102,7 +105,9 @@ public class TestHttpAsyncMinimal { @Override protected void before() throws Throwable { server = new Http2TestServer( - IOReactorConfig.DEFAULT, + IOReactorConfig.custom() + .setSoTimeout(TIMEOUT) + .build(), scheme == URIScheme.HTTPS ? SSLTestContexts.createServerSSLContext() : null); server.register("/echo/*", new Supplier() { @@ -141,7 +146,7 @@ public class TestHttpAsyncMinimal { .setTlsStrategy(new H2TlsStrategy(SSLTestContexts.createClientSSLContext())) .build(); final IOReactorConfig ioReactorConfig = IOReactorConfig.custom() - .setSoTimeout(5, TimeUnit.SECONDS) + .setSoTimeout(TIMEOUT) .build(); if (version.greaterEquals(HttpVersion.HTTP_2)) { httpclient = HttpAsyncClients.createMinimal( diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/LocalServerTestBase.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/LocalServerTestBase.java index 85f8ab2bf..ae71dba69 100644 --- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/LocalServerTestBase.java +++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/LocalServerTestBase.java @@ -28,8 +28,8 @@ package org.apache.hc.client5.testing.sync; import java.io.IOException; -import java.util.concurrent.TimeUnit; +import org.apache.hc.client5.http.config.RequestConfig; import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager; import org.apache.hc.client5.http.impl.sync.CloseableHttpClient; import org.apache.hc.client5.http.impl.sync.HttpClientBuilder; @@ -44,6 +44,7 @@ import org.apache.hc.core5.http.io.HttpServerRequestHandler; import org.apache.hc.core5.http.protocol.HttpProcessor; import org.apache.hc.core5.io.ShutdownType; import org.apache.hc.core5.testing.classic.ClassicTestServer; +import org.apache.hc.core5.util.Timeout; import org.junit.Rule; import org.junit.rules.ExternalResource; @@ -52,6 +53,9 @@ import org.junit.rules.ExternalResource; */ public abstract class LocalServerTestBase { + public static final Timeout TIMEOUT = Timeout.ofSeconds(30); + public static final Timeout LONG_TIMEOUT = Timeout.ofSeconds(60); + public LocalServerTestBase(final URIScheme scheme) { this.scheme = scheme; } @@ -72,7 +76,7 @@ public abstract class LocalServerTestBase { server = new ClassicTestServer( scheme == URIScheme.HTTPS ? SSLTestContexts.createServerSSLContext() : null, SocketConfig.custom() - .setSoTimeout(5, TimeUnit.SECONDS) + .setSoTimeout(TIMEOUT) .build()); server.registerHandler("/echo/*", new EchoHandler()); server.registerHandler("/random/*", new RandomHandler()); @@ -102,9 +106,14 @@ public abstract class LocalServerTestBase { protected void before() throws Throwable { connManager = new PoolingHttpClientConnectionManager(); connManager.setDefaultSocketConfig(SocketConfig.custom() - .setSoTimeout(5, TimeUnit.SECONDS) + .setSoTimeout(TIMEOUT) .build()); clientBuilder = HttpClientBuilder.create() + .setDefaultRequestConfig(RequestConfig.custom() + .setSocketTimeout(TIMEOUT) + .setConnectTimeout(TIMEOUT) + .setConnectionRequestTimeout(TIMEOUT) + .build()) .setConnectionManager(connManager); } diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestStatefulConnManagement.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestStatefulConnManagement.java index 73a36cc56..a31b039f1 100644 --- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestStatefulConnManagement.java +++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestStatefulConnManagement.java @@ -107,7 +107,7 @@ public class TestStatefulConnManagement extends LocalServerTestBase { worker.start(); } for (final HttpWorker worker : workers) { - worker.join(10000); + worker.join(LONG_TIMEOUT.toMillis()); } for (final HttpWorker worker : workers) { final Exception ex = worker.getException();