diff --git a/httpclient5-testing/pom.xml b/httpclient5-testing/pom.xml
index 87096e00a..e97ae10cf 100644
--- a/httpclient5-testing/pom.xml
+++ b/httpclient5-testing/pom.xml
@@ -84,7 +84,7 @@
org.junit.jupiter
- junit-jupiter-migrationsupport
+ junit-jupiter-params
test
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttp1IntegrationTestBase.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttp1IntegrationTestBase.java
deleted file mode 100644
index 964e1d329..000000000
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttp1IntegrationTestBase.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * ====================================================================
- * 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
- * .
- *
- */
-
-package org.apache.hc.client5.testing.async;
-
-import java.net.InetSocketAddress;
-import java.util.concurrent.Future;
-
-import org.apache.hc.client5.http.config.ConnectionConfig;
-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.client5.http.impl.nio.PoolingAsyncClientConnectionManager;
-import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManagerBuilder;
-import org.apache.hc.client5.http.ssl.DefaultClientTlsStrategy;
-import org.apache.hc.client5.testing.SSLTestContexts;
-import org.apache.hc.core5.function.Decorator;
-import org.apache.hc.core5.http.HttpHost;
-import org.apache.hc.core5.http.URIScheme;
-import org.apache.hc.core5.http.config.Http1Config;
-import org.apache.hc.core5.http.impl.HttpProcessors;
-import org.apache.hc.core5.http.nio.AsyncServerExchangeHandler;
-import org.apache.hc.core5.http.protocol.HttpProcessor;
-import org.apache.hc.core5.io.CloseMode;
-import org.apache.hc.core5.reactor.ListenerEndpoint;
-import org.junit.Rule;
-import org.junit.rules.ExternalResource;
-
-public abstract class AbstractHttp1IntegrationTestBase extends AbstractServerTestBase {
-
- public AbstractHttp1IntegrationTestBase(final URIScheme scheme) {
- super(scheme);
- }
-
- public AbstractHttp1IntegrationTestBase() {
- super(URIScheme.HTTP);
- }
-
- protected HttpAsyncClientBuilder clientBuilder;
- protected PoolingAsyncClientConnectionManager connManager;
- protected CloseableHttpAsyncClient httpclient;
-
- @Rule
- public ExternalResource connManagerResource = new ExternalResource() {
-
- @Override
- protected void before() throws Throwable {
- connManager = PoolingAsyncClientConnectionManagerBuilder.create()
- .setDefaultConnectionConfig(ConnectionConfig.custom()
- .setConnectTimeout(TIMEOUT)
- .setSocketTimeout(TIMEOUT)
- .build())
- .setTlsStrategy(new DefaultClientTlsStrategy(SSLTestContexts.createClientSSLContext()))
- .build();
- }
-
- @Override
- protected void after() {
- if (connManager != null) {
- connManager.close();
- connManager = null;
- }
- }
-
- };
-
- @Rule
- public ExternalResource clientBuilderResource = new ExternalResource() {
-
- @Override
- protected void before() throws Throwable {
- clientBuilder = HttpAsyncClientBuilder.create()
- .setDefaultRequestConfig(RequestConfig.custom()
- .setConnectionRequestTimeout(TIMEOUT)
- .build())
- .setConnectionManager(connManager);
- }
-
- @Override
- protected void after() {
- if (httpclient != null) {
- httpclient.close(CloseMode.GRACEFUL);
- httpclient = null;
- }
- }
-
- };
-
- public HttpHost start(
- final HttpProcessor httpProcessor,
- final Decorator exchangeHandlerDecorator,
- final Http1Config h1Config) throws Exception {
- server.start(httpProcessor, exchangeHandlerDecorator, h1Config);
- final Future endpointFuture = server.listen(new InetSocketAddress(0));
- httpclient = clientBuilder.build();
- httpclient.start();
- final ListenerEndpoint endpoint = endpointFuture.get();
- final InetSocketAddress address = (InetSocketAddress) endpoint.getAddress();
- return new HttpHost(scheme.name(), "localhost", address.getPort());
- }
-
- public HttpHost start(
- final HttpProcessor httpProcessor,
- final Http1Config h1Config) throws Exception {
- return start(httpProcessor, null, h1Config);
- }
-
- public HttpHost start() throws Exception {
- return start(HttpProcessors.server(), Http1Config.DEFAULT);
- }
-
-}
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttpAsyncClientAuthentication.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttpAsyncClientAuthenticationTest.java
similarity index 77%
rename from httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttpAsyncClientAuthentication.java
rename to httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttpAsyncClientAuthenticationTest.java
index 7747b3bc1..3dba15041 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttpAsyncClientAuthentication.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttpAsyncClientAuthenticationTest.java
@@ -35,6 +35,7 @@ import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.Consumer;
import java.util.stream.Collectors;
import org.apache.hc.client5.http.AuthenticationStrategy;
@@ -64,71 +65,63 @@ import org.apache.hc.core5.http.HttpRequestInterceptor;
import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.HttpResponseInterceptor;
import org.apache.hc.core5.http.HttpStatus;
-import org.apache.hc.core5.http.HttpVersion;
import org.apache.hc.core5.http.ProtocolException;
import org.apache.hc.core5.http.URIScheme;
-import org.apache.hc.core5.http.config.Http1Config;
import org.apache.hc.core5.http.config.Lookup;
import org.apache.hc.core5.http.config.Registry;
import org.apache.hc.core5.http.config.RegistryBuilder;
-import org.apache.hc.core5.http.impl.HttpProcessors;
import org.apache.hc.core5.http.nio.AsyncServerExchangeHandler;
import org.apache.hc.core5.http.support.BasicResponseBuilder;
-import org.apache.hc.core5.http2.config.H2Config;
-import org.apache.hc.core5.http2.impl.H2Processors;
import org.apache.hc.core5.net.URIAuthority;
+import org.apache.hc.core5.testing.nio.H2TestServer;
import org.hamcrest.CoreMatchers;
-import org.junit.Test;
import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
-public abstract class AbstractHttpAsyncClientAuthentication extends AbstractIntegrationTestBase {
+public abstract class AbstractHttpAsyncClientAuthenticationTest extends AbstractIntegrationTestBase {
- protected final HttpVersion protocolVersion;
-
- public AbstractHttpAsyncClientAuthentication(final URIScheme scheme, final HttpVersion protocolVersion) {
+ public AbstractHttpAsyncClientAuthenticationTest(final URIScheme scheme) {
super(scheme);
- this.protocolVersion = protocolVersion;
}
- @Override
- public final HttpHost start() throws Exception {
- return start(requestHandler -> new AuthenticatingAsyncDecorator(requestHandler, new BasicTestAuthenticator("test:test", "test realm")));
+ abstract protected H2TestServer startServer(final Decorator exchangeHandlerDecorator) throws Exception;
+
+ protected H2TestServer startServer() throws Exception {
+ return startServer(requestHandler -> new AuthenticatingAsyncDecorator(requestHandler, new BasicTestAuthenticator("test:test", "test realm")));
}
- public final HttpHost start(
- final Decorator exchangeHandlerDecorator) throws Exception {
- if (protocolVersion.greaterEquals(HttpVersion.HTTP_2_0)) {
- return super.start(
- H2Processors.server(),
- exchangeHandlerDecorator,
- H2Config.DEFAULT);
- } else {
- return super.start(
- HttpProcessors.server(),
- exchangeHandlerDecorator,
- Http1Config.DEFAULT);
- }
+ interface TestClientBuilder {
+
+ TestClientBuilder setDefaultAuthSchemeRegistry(Lookup authSchemeRegistry);
+
+ TestClientBuilder setTargetAuthenticationStrategy(AuthenticationStrategy targetAuthStrategy);
+
+ TestClientBuilder addResponseInterceptor(HttpResponseInterceptor responseInterceptor);
+
+ TestClientBuilder addRequestInterceptor(HttpRequestInterceptor requestInterceptor);
+
}
- abstract void setDefaultAuthSchemeRegistry(Lookup authSchemeRegistry);
+ abstract protected T startClientCustom(final Consumer clientCustomizer) throws Exception;
- abstract void setTargetAuthenticationStrategy(AuthenticationStrategy targetAuthStrategy);
-
- abstract void addResponseInterceptor(HttpResponseInterceptor responseInterceptor);
-
- abstract void addRequestInterceptor(final HttpRequestInterceptor requestInterceptor);
+ T startClient() throws Exception {
+ return startClientCustom(c -> {});
+ }
@Test
public void testBasicAuthenticationNoCreds() throws Exception {
+ final H2TestServer server = startServer();
server.register("*", AsyncEchoHandler::new);
- final HttpHost target = start();
+ final HttpHost target = targetHost();
+
+ final T client = startClient();
final CredentialsProvider credsProvider = Mockito.mock(CredentialsProvider.class);
final HttpClientContext context = HttpClientContext.create();
context.setCredentialsProvider(credsProvider);
- final Future future = httpclient.execute(SimpleRequestBuilder.get()
+ final Future future = client.execute(SimpleRequestBuilder.get()
.setHttpHost(target)
.setPath("/")
.build(), context, null);
@@ -142,8 +135,11 @@ public abstract class AbstractHttpAsyncClientAuthentication future = httpclient.execute(SimpleRequestBuilder.get()
+ final Future future = client.execute(SimpleRequestBuilder.get()
.setHttpHost(target)
.setPath("/")
.build(), context, null);
@@ -165,8 +161,11 @@ public abstract class AbstractHttpAsyncClientAuthentication future = httpclient.execute(
+ final Future future = client.execute(
SimpleRequestBuilder.get()
.setHttpHost(target)
.setPath("/")
@@ -189,15 +188,18 @@ public abstract class AbstractHttpAsyncClientAuthentication future = httpclient.execute(
+ final Future future = client.execute(
SimpleRequestBuilder.put()
.setHttpHost(target)
.setPath("/")
@@ -213,8 +215,11 @@ public abstract class AbstractHttpAsyncClientAuthentication future = httpclient.execute(
+ final Future future = client.execute(
SimpleRequestBuilder.put()
.setHttpHost(target)
.setPath("/")
@@ -236,8 +241,11 @@ public abstract class AbstractHttpAsyncClientAuthentication future = httpclient.execute(
+ final Future future = client.execute(
SimpleRequestBuilder.put()
.setHttpHost(target)
.setPath("/")
@@ -261,11 +269,12 @@ public abstract class AbstractHttpAsyncClientAuthentication builder.setTargetAuthenticationStrategy(authStrategy));
final HttpClientContext context = HttpClientContext.create();
context.setCredentialsProvider(CredentialsProviderBuilder.create()
@@ -273,7 +282,7 @@ public abstract class AbstractHttpAsyncClientAuthentication future = httpclient.execute(SimpleRequestBuilder.get()
+ final Future future = client.execute(SimpleRequestBuilder.get()
.setHttpHost(target)
.setPath("/")
.build(), context, null);
@@ -287,15 +296,17 @@ public abstract class AbstractHttpAsyncClientAuthentication responseQueue = new ConcurrentLinkedQueue<>();
- addResponseInterceptor((response, entity, context)
- -> responseQueue.add(BasicResponseBuilder.copy(response).build()));
- final HttpHost target = start();
+ final T client = startClientCustom(builder -> builder
+ .setTargetAuthenticationStrategy(authStrategy)
+ .addResponseInterceptor((response, entity, context)
+ -> responseQueue.add(BasicResponseBuilder.copy(response).build())));
final CredentialsProvider credentialsProvider = CredentialsProviderBuilder.create()
.add(target, "test", "test".toCharArray())
@@ -307,7 +318,7 @@ public abstract class AbstractHttpAsyncClientAuthentication future = httpclient.execute(SimpleRequestBuilder.get()
+ final Future future = client.execute(SimpleRequestBuilder.get()
.setHttpHost(target)
.setPath(requestPath)
.build(), context, null);
@@ -331,7 +342,7 @@ public abstract class AbstractHttpAsyncClientAuthentication future = httpclient.execute(SimpleRequestBuilder.get()
+ final Future future = client.execute(SimpleRequestBuilder.get()
.setHttpHost(target)
.setPath(requestPath)
.build(), context, null);
@@ -350,11 +361,14 @@ public abstract class AbstractHttpAsyncClientAuthentication future = httpclient.execute(SimpleRequestBuilder.get()
+ final Future future = client.execute(SimpleRequestBuilder.get()
.setScheme(target.getSchemeName())
.setAuthority(new URIAuthority("test:test", target.getHostName(), target.getPort()))
.setPath("/")
@@ -365,7 +379,32 @@ public abstract class AbstractHttpAsyncClientAuthentication new AuthenticatingAsyncDecorator(exchangeHandler, authenticator) {
+
+ @Override
+ protected void customizeUnauthorizedResponse(final HttpResponse unauthorized) {
+ unauthorized.removeHeaders(HttpHeaders.WWW_AUTHENTICATE);
+ unauthorized.addHeader(HttpHeaders.WWW_AUTHENTICATE, "MyBasic realm=\"test realm\"");
+ }
+
+ });
server.register("*", AsyncEchoHandler::new);
+ final HttpHost target = targetHost();
+
final CredentialsProvider credsProvider = Mockito.mock(CredentialsProvider.class);
Mockito.when(credsProvider.getCredentials(Mockito.any(), Mockito.any()))
.thenReturn(new UsernamePasswordCredentials("test", "test".toCharArray()));
@@ -382,32 +421,8 @@ public abstract class AbstractHttpAsyncClientAuthentication new AuthenticatingAsyncDecorator(exchangeHandler, authenticator) {
-
- @Override
- protected void customizeUnauthorizedResponse(final HttpResponse unauthorized) {
- unauthorized.removeHeaders(HttpHeaders.WWW_AUTHENTICATE);
- unauthorized.addHeader(HttpHeaders.WWW_AUTHENTICATE, "MyBasic realm=\"test realm\"");
- }
-
- });
+ final T client = startClientCustom(builder -> builder.setDefaultAuthSchemeRegistry(authSchemeRegistry));
final RequestConfig config = RequestConfig.custom()
.setTargetPreferredAuthSchemes(Collections.singletonList("MyBasic"))
@@ -421,7 +436,7 @@ public abstract class AbstractHttpAsyncClientAuthentication future = httpclient.execute(request, context, null);
+ final Future future = client.execute(request, context, null);
final SimpleHttpResponse response = future.get();
Assertions.assertNotNull(response);
Assertions.assertEquals(HttpStatus.SC_OK, response.getCode());
@@ -430,16 +445,18 @@ public abstract class AbstractHttpAsyncClientAuthentication new AuthenticatingAsyncDecorator(exchangeHandler, new BasicTestAuthenticator("test:test", "test realm")) {
+
+ @Override
+ protected void customizeUnauthorizedResponse(final HttpResponse unauthorized) {
+ unauthorized.addHeader(HttpHeaders.WWW_AUTHENTICATE, StandardAuthScheme.DIGEST + " realm=\"test realm\" invalid");
+ }
+
+ });
server.register("*", AsyncEchoHandler::new);
- final HttpHost target = start(
- exchangeHandler -> new AuthenticatingAsyncDecorator(exchangeHandler, new BasicTestAuthenticator("test:test", "test realm")) {
+ final HttpHost target = targetHost();
- @Override
- protected void customizeUnauthorizedResponse(final HttpResponse unauthorized) {
- unauthorized.addHeader(HttpHeaders.WWW_AUTHENTICATE, StandardAuthScheme.DIGEST + " realm=\"test realm\" invalid");
- }
-
- });
+ final T client = startClient();
final CredentialsProvider credsProvider = Mockito.mock(CredentialsProvider.class);
Mockito.when(credsProvider.getCredentials(Mockito.any(), Mockito.any()))
@@ -447,7 +464,7 @@ public abstract class AbstractHttpAsyncClientAuthentication future = httpclient.execute(SimpleRequestBuilder.get()
+ final Future future = client.execute(SimpleRequestBuilder.get()
.setHttpHost(target)
.setPath("/")
.build(), context, null);
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttpAsyncFundamentalsTest.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttpAsyncFundamentalsTest.java
index fd6ceff92..05f818b3e 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttpAsyncFundamentalsTest.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttpAsyncFundamentalsTest.java
@@ -53,20 +53,28 @@ import org.apache.hc.core5.http.nio.entity.AsyncEntityProducers;
import org.apache.hc.core5.http.nio.entity.BasicAsyncEntityConsumer;
import org.apache.hc.core5.http.nio.support.BasicRequestProducer;
import org.apache.hc.core5.http.nio.support.BasicResponseConsumer;
+import org.apache.hc.core5.testing.nio.H2TestServer;
import org.hamcrest.CoreMatchers;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public abstract class AbstractHttpAsyncFundamentalsTest extends AbstractIntegrationTestBase {
+public abstract class AbstractHttpAsyncFundamentalsTest extends AbstractIntegrationTestBase {
- public AbstractHttpAsyncFundamentalsTest(final URIScheme scheme) {
+ protected AbstractHttpAsyncFundamentalsTest(final URIScheme scheme) {
super(scheme);
}
+ abstract protected H2TestServer startServer() throws Exception;
+
+ abstract protected T startClient() throws Exception;
+
@Test
- public void testSequenctialGetRequests() throws Exception {
- final HttpHost target = start();
+ public void testSequentialGetRequests() throws Exception {
+ final H2TestServer server = startServer();
+ server.register("/random/*", AsyncRandomHandler::new);
+ final HttpHost target = targetHost();
+ final T client = startClient();
for (int i = 0; i < 3; i++) {
- final Future future = httpclient.execute(
+ final Future future = client.execute(
SimpleRequestBuilder.get()
.setHttpHost(target)
.setPath("/random/2048")
@@ -81,10 +89,13 @@ public abstract class AbstractHttpAsyncFundamentalsTest future = httpclient.execute(
+ final Future future = client.execute(
SimpleRequestBuilder.head()
.setHttpHost(target)
.setPath("/random/2048")
@@ -98,13 +109,16 @@ public abstract class AbstractHttpAsyncFundamentalsTest> future = httpclient.execute(
+ final Future> future = client.execute(
new BasicRequestProducer(Method.GET, target, "/echo/",
AsyncEntityProducers.create(b1, ContentType.APPLICATION_OCTET_STREAM)),
new BasicResponseConsumer<>(new BasicAsyncEntityConsumer()), HttpClientContext.create(), null);
@@ -119,7 +133,10 @@ public abstract class AbstractHttpAsyncFundamentalsTest>> queue = new LinkedList<>();
for (int i = 0; i < reqCount; i++) {
- final Future> future = httpclient.execute(
+ final Future> future = client.execute(
new BasicRequestProducer(Method.POST, target, "/echo/",
AsyncEntityProducers.create(b1, ContentType.APPLICATION_OCTET_STREAM)),
new BasicResponseConsumer<>(new BasicAsyncEntityConsumer()), HttpClientContext.create(), null);
@@ -148,7 +165,10 @@ public abstract class AbstractHttpAsyncFundamentalsTest resultQueue = new ConcurrentLinkedQueue<>();
@@ -161,7 +181,7 @@ public abstract class AbstractHttpAsyncFundamentalsTest 0) {
- httpclient.execute(
+ client.execute(
SimpleRequestBuilder.get()
.setHttpHost(target)
.setPath("/random/2048")
@@ -188,7 +208,7 @@ public abstract class AbstractHttpAsyncFundamentalsTest {
if (!Thread.currentThread().isInterrupted()) {
- httpclient.execute(
+ client.execute(
SimpleRequestBuilder.get()
.setHttpHost(target)
.setPath("/random/2048")
@@ -213,8 +233,11 @@ public abstract class AbstractHttpAsyncFundamentalsTest future = httpclient.execute(
+ final H2TestServer server = startServer();
+ server.register("/random/*", AsyncRandomHandler::new);
+ final HttpHost target = targetHost();
+ final T client = startClient();
+ final Future future = client.execute(
SimpleRequestBuilder.get()
.setHttpHost(target)
.setPath("/random/boom")
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttpAsyncRedirectsTest.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttpAsyncRedirectsTest.java
index 3bed9ac0d..0f9d97356 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttpAsyncRedirectsTest.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttpAsyncRedirectsTest.java
@@ -63,49 +63,43 @@ import org.apache.hc.core5.http.nio.AsyncServerExchangeHandler;
import org.apache.hc.core5.http.protocol.HttpCoreContext;
import org.apache.hc.core5.http2.config.H2Config;
import org.apache.hc.core5.net.URIBuilder;
-import org.apache.hc.core5.reactive.ReactiveServerExchangeHandler;
import org.apache.hc.core5.reactor.IOReactorConfig;
import org.apache.hc.core5.testing.nio.H2TestServer;
-import org.apache.hc.core5.testing.reactive.ReactiveRandomProcessor;
import org.apache.hc.core5.util.TimeValue;
import org.hamcrest.CoreMatchers;
-import org.junit.Test;
import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
-public abstract class AbstractHttpAsyncRedirectsTest extends AbstractIntegrationTestBase {
+public abstract class AbstractHttpAsyncRedirectsTest extends AbstractIntegrationTestBase {
- protected final HttpVersion version;
+ private final HttpVersion version;
- public AbstractHttpAsyncRedirectsTest(final HttpVersion version, final URIScheme scheme) {
+ public AbstractHttpAsyncRedirectsTest(final URIScheme scheme, final HttpVersion version) {
super(scheme);
this.version = version;
}
- @Override
- public final HttpHost start() throws Exception {
- if (version.greaterEquals(HttpVersion.HTTP_2)) {
- return super.start(null, H2Config.DEFAULT);
- } else {
- return super.start(null, Http1Config.DEFAULT);
- }
+ abstract protected H2TestServer startServer(final Decorator exchangeHandlerDecorator) throws Exception;
+
+ protected H2TestServer startServer() throws Exception {
+ return startServer(null);
}
- public final HttpHost start(final Decorator exchangeHandlerDecorator) throws Exception {
- if (version.greaterEquals(HttpVersion.HTTP_2)) {
- return super.start(null, exchangeHandlerDecorator, H2Config.DEFAULT);
- } else {
- return super.start(null, exchangeHandlerDecorator, Http1Config.DEFAULT);
- }
- }
+ abstract protected T startClient() throws Exception;
@Test
public void testBasicRedirect300() throws Exception {
- final HttpHost target = start(exchangeHandler -> new RedirectingAsyncDecorator(
+ final H2TestServer server = startServer(exchangeHandler -> new RedirectingAsyncDecorator(
exchangeHandler,
new OldPathRedirectResolver("/oldlocation", "/random", HttpStatus.SC_MULTIPLE_CHOICES)));
+ server.register("/random/*", AsyncRandomHandler::new);
+ final HttpHost target = targetHost();
+
+ final T client = startClient();
+
final HttpClientContext context = HttpClientContext.create();
- final Future future = httpclient.execute(
+ final Future future = client.execute(
SimpleRequestBuilder.get()
.setHttpHost(target)
.setPath("/oldlocation/")
@@ -121,11 +115,16 @@ public abstract class AbstractHttpAsyncRedirectsTest new RedirectingAsyncDecorator(
+ final H2TestServer server = startServer(exchangeHandler -> new RedirectingAsyncDecorator(
exchangeHandler,
new OldPathRedirectResolver("/oldlocation", "/random", HttpStatus.SC_MOVED_PERMANENTLY)));
+ server.register("/random/*", AsyncRandomHandler::new);
+ final HttpHost target = targetHost();
+
+ final T client = startClient();
+
final HttpClientContext context = HttpClientContext.create();
- final Future future = httpclient.execute(
+ final Future future = client.execute(
SimpleRequestBuilder.get()
.setHttpHost(target)
.setPath("/oldlocation/100")
@@ -142,11 +141,16 @@ public abstract class AbstractHttpAsyncRedirectsTest new RedirectingAsyncDecorator(
+ final H2TestServer server = startServer(exchangeHandler -> new RedirectingAsyncDecorator(
exchangeHandler,
new OldPathRedirectResolver("/oldlocation", "/random", HttpStatus.SC_MOVED_TEMPORARILY)));
+ server.register("/random/*", AsyncRandomHandler::new);
+ final HttpHost target = targetHost();
+
+ final T client = startClient();
+
final HttpClientContext context = HttpClientContext.create();
- final Future future = httpclient.execute(
+ final Future future = client.execute(
SimpleRequestBuilder.get()
.setHttpHost(target)
.setPath("/oldlocation/123")
@@ -163,7 +167,7 @@ public abstract class AbstractHttpAsyncRedirectsTest new RedirectingAsyncDecorator(
+ final H2TestServer server = startServer(exchangeHandler -> new RedirectingAsyncDecorator(
exchangeHandler,
requestUri -> {
final String path = requestUri.getPath();
@@ -172,8 +176,13 @@ public abstract class AbstractHttpAsyncRedirectsTest future = httpclient.execute(
+ final Future future = client.execute(
SimpleRequestBuilder.get()
.setHttpHost(target)
.setPath("/oldlocation/100")
@@ -189,11 +198,16 @@ public abstract class AbstractHttpAsyncRedirectsTest new RedirectingAsyncDecorator(
+ final H2TestServer server = startServer(exchangeHandler -> new RedirectingAsyncDecorator(
exchangeHandler,
new OldPathRedirectResolver("/oldlocation", "/random", HttpStatus.SC_SEE_OTHER)));
+ server.register("/random/*", AsyncRandomHandler::new);
+ final HttpHost target = targetHost();
+
+ final T client = startClient();
+
final HttpClientContext context = HttpClientContext.create();
- final Future future = httpclient.execute(
+ final Future future = client.execute(
SimpleRequestBuilder.get()
.setHttpHost(target)
.setPath("/oldlocation/123")
@@ -210,6 +224,8 @@ public abstract class AbstractHttpAsyncRedirectsTest new AbstractSimpleServerExchangeHandler() {
@Override
@@ -218,9 +234,12 @@ public abstract class AbstractHttpAsyncRedirectsTest future = httpclient.execute(
+ final Future future = client.execute(
SimpleRequestBuilder.get()
.setHttpHost(target)
.setPath("/oldlocation/")
@@ -236,6 +255,8 @@ public abstract class AbstractHttpAsyncRedirectsTest new AbstractSimpleServerExchangeHandler() {
@Override
@@ -244,9 +265,12 @@ public abstract class AbstractHttpAsyncRedirectsTest future = httpclient.execute(
+ final Future future = client.execute(
SimpleRequestBuilder.get()
.setHttpHost(target)
.setPath("/oldlocation/")
@@ -262,11 +286,16 @@ public abstract class AbstractHttpAsyncRedirectsTest new RedirectingAsyncDecorator(
+ final H2TestServer server = startServer(exchangeHandler -> new RedirectingAsyncDecorator(
exchangeHandler,
new OldPathRedirectResolver("/oldlocation", "/random", HttpStatus.SC_TEMPORARY_REDIRECT)));
+ server.register("/random/*", AsyncRandomHandler::new);
+ final HttpHost target = targetHost();
+
+ final T client = startClient();
+
final HttpClientContext context = HttpClientContext.create();
- final Future future = httpclient.execute(
+ final Future future = client.execute(
SimpleRequestBuilder.get()
.setHttpHost(target)
.setPath("/oldlocation/123")
@@ -283,16 +312,20 @@ public abstract class AbstractHttpAsyncRedirectsTest new RedirectingAsyncDecorator(
+ final H2TestServer server = startServer(exchangeHandler -> new RedirectingAsyncDecorator(
exchangeHandler,
new OldPathRedirectResolver("/circular-oldlocation/", "/circular-oldlocation/",
HttpStatus.SC_MOVED_TEMPORARILY)));
+ server.register("/random/*", AsyncRandomHandler::new);
+ final HttpHost target = targetHost();
+
+ final T client = startClient();
final RequestConfig config = RequestConfig.custom()
.setCircularRedirectsAllowed(true)
.setMaxRedirects(5).build();
final ExecutionException exception = Assertions.assertThrows(ExecutionException.class, () -> {
- final Future future = httpclient.execute(SimpleRequestBuilder.get()
+ final Future future = client.execute(SimpleRequestBuilder.get()
.setHttpHost(target)
.setPath("/circular-oldlocation/")
.setRequestConfig(config)
@@ -304,16 +337,20 @@ public abstract class AbstractHttpAsyncRedirectsTest new RedirectingAsyncDecorator(
+ final H2TestServer server = startServer(exchangeHandler -> new RedirectingAsyncDecorator(
exchangeHandler,
new OldPathRedirectResolver("/circular-oldlocation/", "/circular-oldlocation/",
HttpStatus.SC_MOVED_TEMPORARILY)));
+ server.register("/random/*", AsyncRandomHandler::new);
+ final HttpHost target = targetHost();
+
+ final T client = startClient();
final RequestConfig config = RequestConfig.custom()
.setCircularRedirectsAllowed(false)
.build();
final ExecutionException exception = Assertions.assertThrows(ExecutionException.class, () -> {
- final Future future = httpclient.execute(
+ final Future future = client.execute(
SimpleRequestBuilder.get()
.setHttpHost(target)
.setPath("/circular-oldlocation/")
@@ -326,12 +363,17 @@ public abstract class AbstractHttpAsyncRedirectsTest new RedirectingAsyncDecorator(
+ final H2TestServer server = startServer(exchangeHandler -> new RedirectingAsyncDecorator(
exchangeHandler,
new OldPathRedirectResolver("/oldlocation", "/echo", HttpStatus.SC_TEMPORARY_REDIRECT)));
+ server.register("/echo/*", AsyncEchoHandler::new);
+ final HttpHost target = targetHost();
+
+ final T client = startClient();
+
final HttpClientContext context = HttpClientContext.create();
- final Future future = httpclient.execute(
+ final Future future = client.execute(
SimpleRequestBuilder.post()
.setHttpHost(target)
.setPath("/oldlocation/stuff")
@@ -349,12 +391,17 @@ public abstract class AbstractHttpAsyncRedirectsTest new RedirectingAsyncDecorator(
+ final H2TestServer server = startServer(exchangeHandler -> new RedirectingAsyncDecorator(
exchangeHandler,
new OldPathRedirectResolver("/oldlocation", "/echo", HttpStatus.SC_SEE_OTHER)));
+ server.register("/echo/*", AsyncEchoHandler::new);
+ final HttpHost target = targetHost();
+
+ final T client = startClient();
+
final HttpClientContext context = HttpClientContext.create();
- final Future future = httpclient.execute(
+ final Future future = client.execute(
SimpleRequestBuilder.post()
.setHttpHost(target)
.setPath("/oldlocation/stuff")
@@ -372,7 +419,7 @@ public abstract class AbstractHttpAsyncRedirectsTest new RedirectingAsyncDecorator(
+ final H2TestServer server = startServer(exchangeHandler -> new RedirectingAsyncDecorator(
exchangeHandler,
requestUri -> {
final String path = requestUri.getPath();
@@ -383,9 +430,14 @@ public abstract class AbstractHttpAsyncRedirectsTest future = httpclient.execute(
+ final Future future = client.execute(
SimpleRequestBuilder.get()
.setHttpHost(target)
.setPath("/oldlocation/stuff")
@@ -402,7 +454,7 @@ public abstract class AbstractHttpAsyncRedirectsTest new RedirectingAsyncDecorator(
+ final H2TestServer server = startServer(exchangeHandler -> new RedirectingAsyncDecorator(
exchangeHandler,
requestUri -> {
final String path = requestUri.getPath();
@@ -413,9 +465,14 @@ public abstract class AbstractHttpAsyncRedirectsTest future = httpclient.execute(
+ final Future future = client.execute(
SimpleRequestBuilder.get()
.setHttpHost(target)
.setPath("/random/oldlocation")
@@ -432,7 +489,7 @@ public abstract class AbstractHttpAsyncRedirectsTest new RedirectingAsyncDecorator(
+ final H2TestServer server = startServer(exchangeHandler -> new RedirectingAsyncDecorator(
exchangeHandler,
requestUri -> {
final String path = requestUri.getPath();
@@ -442,9 +499,13 @@ public abstract class AbstractHttpAsyncRedirectsTest {
- final Future future = httpclient.execute(
+ final Future future = client.execute(
SimpleRequestBuilder.get()
.setHttpHost(target)
.setPath("/oldlocation/")
@@ -456,7 +517,7 @@ public abstract class AbstractHttpAsyncRedirectsTest new RedirectingAsyncDecorator(
+ final H2TestServer server = startServer(exchangeHandler -> new RedirectingAsyncDecorator(
exchangeHandler,
requestUri -> {
final String path = requestUri.getPath();
@@ -466,9 +527,13 @@ public abstract class AbstractHttpAsyncRedirectsTest {
- final Future future = httpclient.execute(
+ final Future future = client.execute(
SimpleRequestBuilder.get()
.setHttpHost(target)
.setPath("/oldlocation/")
@@ -480,11 +545,16 @@ public abstract class AbstractHttpAsyncRedirectsTest new RedirectingAsyncDecorator(
+ final H2TestServer server = startServer(exchangeHandler -> new RedirectingAsyncDecorator(
exchangeHandler,
new OldPathRedirectResolver("/oldlocation", "/random", HttpStatus.SC_MOVED_TEMPORARILY)));
final CookieStore cookieStore = new BasicCookieStore();
+ server.register("/random/*", AsyncRandomHandler::new);
+ final HttpHost target = targetHost();
+
+ final T client = startClient();
+
final HttpClientContext context = HttpClientContext.create();
context.setCookieStore(cookieStore);
@@ -494,7 +564,7 @@ public abstract class AbstractHttpAsyncRedirectsTest future = httpclient.execute(
+ final Future future = client.execute(
SimpleRequestBuilder.get()
.setHttpHost(target)
.setPath("/oldlocation/100")
@@ -513,16 +583,11 @@ public abstract class AbstractHttpAsyncRedirectsTest {
- if (isReactive()) {
- return new ReactiveServerExchangeHandler(new ReactiveRandomProcessor());
- } else {
- return new AsyncRandomHandler();
- }
- });
+ secondServer.register("/random/*", AsyncRandomHandler::new);
final InetSocketAddress address2;
if (version.greaterEquals(HttpVersion.HTTP_2)) {
address2 = secondServer.start(H2Config.DEFAULT);
@@ -531,7 +596,7 @@ public abstract class AbstractHttpAsyncRedirectsTest new RedirectingAsyncDecorator(
+ final H2TestServer server = startServer(exchangeHandler -> new RedirectingAsyncDecorator(
exchangeHandler,
requestUri -> {
final String path = requestUri.getPath();
@@ -545,8 +610,13 @@ public abstract class AbstractHttpAsyncRedirectsTest future = httpclient.execute(
+ server.register("/random/*", AsyncRandomHandler::new);
+ final HttpHost target = targetHost();
+
+ final T client = startClient();
+
+ final HttpClientContext context = HttpClientContext.create();
+ final Future future = client.execute(
SimpleRequestBuilder.get()
.setHttpHost(target)
.setPath("/oldlocation")
@@ -560,7 +630,7 @@ public abstract class AbstractHttpAsyncRedirectsTest extends AbstractIntegrationTestBase {
+public abstract class AbstractHttpReactiveFundamentalsTest extends AbstractIntegrationTestBase {
public AbstractHttpReactiveFundamentalsTest(final URIScheme scheme) {
super(scheme);
}
- @Override
- protected final boolean isReactive() {
- return true;
- }
+ abstract protected H2TestServer startServer() throws Exception;
+
+ abstract protected T startClient() throws Exception;
@Test
@Timeout(value = 60_000, unit = MILLISECONDS)
public void testSequentialGetRequests() throws Exception {
- final HttpHost target = start();
+ final H2TestServer server = startServer();
+ server.register("/random/*", () ->
+ new ReactiveServerExchangeHandler(new ReactiveRandomProcessor()));
+ final HttpHost target = targetHost();
+ final T client = startClient();
for (int i = 0; i < 3; i++) {
final ReactiveResponseConsumer consumer = new ReactiveResponseConsumer();
- httpclient.execute(AsyncRequestBuilder.get(target + "/random/2048").build(), consumer, null);
+ client.execute(AsyncRequestBuilder.get(target + "/random/2048").build(), consumer, null);
final Message> response = consumer.getResponseFuture().get();
assertThat(response, CoreMatchers.notNullValue());
@@ -105,11 +112,15 @@ public abstract class AbstractHttpReactiveFundamentalsTest
+ new ReactiveServerExchangeHandler(new ReactiveRandomProcessor()));
+ final HttpHost target = targetHost();
+ final T client = startClient();
for (int i = 0; i < 3; i++) {
final ReactiveResponseConsumer consumer = new ReactiveResponseConsumer();
- httpclient.execute(AsyncRequestBuilder.head(target + "/random/2048").build(), consumer, null);
+ client.execute(AsyncRequestBuilder.head(target + "/random/2048").build(), consumer, null);
final Message> response = consumer.getResponseFuture().get();
assertThat(response, CoreMatchers.notNullValue());
@@ -123,7 +134,11 @@ public abstract class AbstractHttpReactiveFundamentalsTest
+ new ReactiveServerExchangeHandler(new ReactiveEchoProcessor()));
+ final HttpHost target = targetHost();
+ final T client = startClient();
for (int i = 0; i < 3; i++) {
final byte[] b1 = new byte[1024];
final Random rnd = new Random(System.currentTimeMillis());
@@ -134,7 +149,7 @@ public abstract class AbstractHttpReactiveFundamentalsTest>> responseFuture = consumer.getResponseFuture();
final Message> responseMessage = responseFuture.get();
@@ -149,7 +164,11 @@ public abstract class AbstractHttpReactiveFundamentalsTest
+ new ReactiveServerExchangeHandler(new ReactiveEchoProcessor()));
+ final HttpHost target = targetHost();
+ final T client = startClient();
final int reqCount = 500;
final int maxSize = 128 * 1024;
@@ -175,7 +194,7 @@ public abstract class AbstractHttpReactiveFundamentalsTest
+ new ReactiveServerExchangeHandler(new ReactiveRandomProcessor()));
+ final HttpHost target = targetHost();
+ final T client = startClient();
final int requestNum = 50;
final AtomicInteger count = new AtomicInteger(requestNum);
final Queue>> resultQueue = new ConcurrentLinkedQueue<>();
@@ -207,7 +230,7 @@ public abstract class AbstractHttpReactiveFundamentalsTest 0) {
final ReactiveResponseConsumer consumer = new ReactiveResponseConsumer(this);
- httpclient.execute(AsyncRequestBuilder.get(target + "/random/2048").build(), consumer, null);
+ client.execute(AsyncRequestBuilder.get(target + "/random/2048").build(), consumer, null);
}
} finally {
countDownLatch.countDown();
@@ -231,7 +254,7 @@ public abstract class AbstractHttpReactiveFundamentalsTest {
if (!Thread.currentThread().isInterrupted()) {
final ReactiveResponseConsumer consumer = new ReactiveResponseConsumer(callback);
- httpclient.execute(AsyncRequestBuilder.get(target + "/random/2048").build(), consumer, null);
+ client.execute(AsyncRequestBuilder.get(target + "/random/2048").build(), consumer, null);
}
});
}
@@ -252,11 +275,15 @@ public abstract class AbstractHttpReactiveFundamentalsTest
+ new ReactiveServerExchangeHandler(new ReactiveRandomProcessor()));
+ final HttpHost target = targetHost();
+ final T client = startClient();
final AsyncRequestProducer request = AsyncRequestBuilder.get(target + "/random/boom").build();
final ReactiveResponseConsumer consumer = new ReactiveResponseConsumer();
- httpclient.execute(request, consumer, null);
+ client.execute(request, consumer, null);
final Future>> future = consumer.getResponseFuture();
final HttpResponse response = future.get().getHead();
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractIntegrationTestBase.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractIntegrationTestBase.java
index d13a608c9..3e80e3e86 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractIntegrationTestBase.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractIntegrationTestBase.java
@@ -27,10 +27,16 @@
package org.apache.hc.client5.testing.async;
-import java.net.InetSocketAddress;
-import java.util.concurrent.Future;
+import java.util.function.Consumer;
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
+import org.apache.hc.client5.http.impl.async.H2AsyncClientBuilder;
+import org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder;
+import org.apache.hc.client5.http.impl.async.MinimalH2AsyncClient;
+import org.apache.hc.client5.http.impl.async.MinimalHttpAsyncClient;
+import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager;
+import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManagerBuilder;
+import org.apache.hc.client5.testing.async.extension.TestAsyncResources;
import org.apache.hc.core5.function.Decorator;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.URIScheme;
@@ -38,77 +44,79 @@ import org.apache.hc.core5.http.config.Http1Config;
import org.apache.hc.core5.http.nio.AsyncServerExchangeHandler;
import org.apache.hc.core5.http.protocol.HttpProcessor;
import org.apache.hc.core5.http2.config.H2Config;
-import org.apache.hc.core5.io.CloseMode;
-import org.apache.hc.core5.reactor.ListenerEndpoint;
-import org.junit.Rule;
-import org.junit.rules.ExternalResource;
+import org.apache.hc.core5.testing.nio.H2TestServer;
+import org.apache.hc.core5.util.Timeout;
+import org.junit.jupiter.api.extension.RegisterExtension;
-public abstract class AbstractIntegrationTestBase extends AbstractServerTestBase {
+public abstract class AbstractIntegrationTestBase {
- public AbstractIntegrationTestBase(final URIScheme scheme) {
- super(scheme);
+ public static final Timeout TIMEOUT = Timeout.ofMinutes(1);
+
+ @RegisterExtension
+ private final TestAsyncResources testResources;
+
+ protected AbstractIntegrationTestBase(final URIScheme scheme) {
+ this.testResources = new TestAsyncResources(scheme, TIMEOUT);
}
- public AbstractIntegrationTestBase() {
- super(URIScheme.HTTP);
+ public URIScheme scheme() {
+ return testResources.scheme();
}
- protected T httpclient;
-
- protected abstract T createClient() throws Exception;
-
- @Rule
- public ExternalResource clientResource = new ExternalResource() {
-
- @Override
- protected void after() {
- if (httpclient != null) {
- httpclient.close(CloseMode.GRACEFUL);
- httpclient = null;
- }
- }
-
- };
-
- public abstract HttpHost start() throws Exception;
-
- public final HttpHost start(
+ public H2TestServer startServer(
+ final H2Config h2Config,
final HttpProcessor httpProcessor,
- final Decorator exchangeHandlerDecorator,
- final Http1Config h1Config) throws Exception {
- server.start(httpProcessor, exchangeHandlerDecorator, h1Config);
- final Future endpointFuture = server.listen(new InetSocketAddress(0));
- httpclient = createClient();
- httpclient.start();
- final ListenerEndpoint endpoint = endpointFuture.get();
- final InetSocketAddress address = (InetSocketAddress) endpoint.getAddress();
- return new HttpHost(scheme.name(), "localhost", address.getPort());
+ final Decorator exchangeHandlerDecorator) throws Exception {
+ return testResources.startServer(h2Config, httpProcessor, exchangeHandlerDecorator);
}
- public final HttpHost start(
+ public H2TestServer startServer(
+ final Http1Config http1Config,
final HttpProcessor httpProcessor,
- final Http1Config h1Config) throws Exception {
- return start(httpProcessor, null, h1Config);
+ final Decorator exchangeHandlerDecorator) throws Exception {
+ return testResources.startServer(http1Config, httpProcessor, exchangeHandlerDecorator);
}
- public final HttpHost start(
- final HttpProcessor httpProcessor,
- final Decorator exchangeHandlerDecorator,
- final H2Config h2Config) throws Exception {
- server.start(httpProcessor, exchangeHandlerDecorator, h2Config);
- final Future endpointFuture = server.listen(new InetSocketAddress(0));
- httpclient = createClient();
- httpclient.start();
- final ListenerEndpoint endpoint = endpointFuture.get();
- final InetSocketAddress address = (InetSocketAddress) endpoint.getAddress();
- return new HttpHost(scheme.name(), "localhost", address.getPort());
+ public HttpHost targetHost() {
+ return testResources.targetHost();
}
+ public CloseableHttpAsyncClient startClient(
+ final Consumer connManagerCustomizer,
+ final Consumer clientCustomizer) throws Exception {
+ return testResources.startClient(connManagerCustomizer, clientCustomizer);
+ }
- public final HttpHost start(
- final HttpProcessor httpProcessor,
- final H2Config h2Config) throws Exception {
- return start(httpProcessor, null, h2Config);
+ public CloseableHttpAsyncClient startClient(
+ final Consumer clientCustomizer) throws Exception {
+ return testResources.startClient(clientCustomizer);
+ }
+
+ public PoolingAsyncClientConnectionManager connManager() {
+ return testResources.connManager();
+ }
+
+ public CloseableHttpAsyncClient startH2Client(
+ final Consumer clientCustomizer) throws Exception {
+ return testResources.startH2Client(clientCustomizer);
+ }
+
+ public MinimalHttpAsyncClient startMinimalClient(
+ final Http1Config http1Config,
+ final H2Config h2Config,
+ final Consumer connManagerCustomizer) throws Exception {
+ return testResources.startMinimalClient(http1Config, h2Config, connManagerCustomizer);
+ }
+
+ public MinimalHttpAsyncClient startMinimalH2Client(
+ final Http1Config http1Config,
+ final H2Config h2Config,
+ final Consumer connManagerCustomizer) throws Exception {
+ return testResources.startMinimalClient(http1Config, h2Config, connManagerCustomizer);
+ }
+
+ public MinimalH2AsyncClient startMinimalH2Client(final H2Config h2Config) throws Exception {
+ return testResources.startMinimalH2Client(h2Config);
}
}
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractServerTestBase.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractServerTestBase.java
deleted file mode 100644
index 16a3674af..000000000
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractServerTestBase.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * ====================================================================
- * 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
- * .
- *
- */
-
-package org.apache.hc.client5.testing.async;
-
-import org.apache.hc.client5.testing.SSLTestContexts;
-import org.apache.hc.core5.http.URIScheme;
-import org.apache.hc.core5.reactive.ReactiveServerExchangeHandler;
-import org.apache.hc.core5.reactor.IOReactorConfig;
-import org.apache.hc.core5.testing.nio.H2TestServer;
-import org.apache.hc.core5.testing.reactive.ReactiveEchoProcessor;
-import org.apache.hc.core5.testing.reactive.ReactiveRandomProcessor;
-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 AbstractServerTestBase {
-
- public static final Timeout TIMEOUT = Timeout.ofMinutes(1);
- public static final Timeout LONG_TIMEOUT = Timeout.ofMinutes(3);
-
- protected final URIScheme scheme;
-
- public AbstractServerTestBase(final URIScheme scheme) {
- this.scheme = scheme;
- }
-
- public AbstractServerTestBase() {
- this(URIScheme.HTTP);
- }
-
- protected H2TestServer server;
-
- @Rule
- public ExternalResource serverResource = new ExternalResource() {
-
- @Override
- protected void before() throws Throwable {
- server = new H2TestServer(
- IOReactorConfig.custom()
- .setSoTimeout(TIMEOUT)
- .build(),
- scheme == URIScheme.HTTPS ? SSLTestContexts.createServerSSLContext() : null, null, null);
- server.register("/echo/*", () -> {
- if (isReactive()) {
- return new ReactiveServerExchangeHandler(new ReactiveEchoProcessor());
- } else {
- return new AsyncEchoHandler();
- }
- });
- server.register("/random/*", () -> {
- if (isReactive()) {
- return new ReactiveServerExchangeHandler(new ReactiveRandomProcessor());
- } else {
- return new AsyncRandomHandler();
- }
- });
- }
-
- @Override
- protected void after() {
- if (server != null) {
- server.shutdown(TimeValue.ofSeconds(5));
- server = null;
- }
- }
-
- };
-
- protected boolean isReactive() {
- return false;
- }
-}
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/HttpIntegrationTests.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/HttpIntegrationTests.java
new file mode 100644
index 000000000..452919c4d
--- /dev/null
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/HttpIntegrationTests.java
@@ -0,0 +1,216 @@
+/*
+ * ====================================================================
+ * 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
+ * .
+ *
+ */
+package org.apache.hc.client5.testing.async;
+
+import org.apache.hc.core5.http.HttpVersion;
+import org.apache.hc.core5.http.URIScheme;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Nested;
+
+public class HttpIntegrationTests {
+
+ @Nested
+ @DisplayName("Fundamentals (HTTP/1.1)")
+ public class Http1 extends TestHttp1Async {
+
+ public Http1() throws Exception {
+ super(URIScheme.HTTP);
+ }
+
+ }
+
+ @Nested
+ @DisplayName("Fundamentals (HTTP/1.1, TLS)")
+ public class Http1Tls extends TestHttp1Async {
+
+ public Http1Tls() throws Exception {
+ super(URIScheme.HTTPS);
+ }
+
+ }
+
+ @Nested
+ @DisplayName("Fundamentals (HTTP/2)")
+ public class H2 extends TestH2Async {
+
+ public H2() throws Exception {
+ super(URIScheme.HTTP);
+ }
+
+ }
+
+ @Nested
+ @DisplayName("Fundamentals (HTTP/2, TLS)")
+ public class H2Tls extends TestH2Async {
+
+ public H2Tls() throws Exception {
+ super(URIScheme.HTTPS);
+ }
+
+ }
+
+ @Nested
+ @DisplayName("Request re-execution (HTTP/1.1)")
+ public class Http1RequestReExecution extends TestHttp1RequestReExecution {
+
+ public Http1RequestReExecution() throws Exception {
+ super(URIScheme.HTTP);
+ }
+
+ }
+
+ @Nested
+ @DisplayName("Request re-execution (HTTP/1.1, TLS)")
+ public class Http1RequestReExecutionTls extends TestHttp1RequestReExecution {
+
+ public Http1RequestReExecutionTls() throws Exception {
+ super(URIScheme.HTTPS);
+ }
+
+ }
+
+ @Nested
+ @DisplayName("HTTP protocol policy (HTTP/1.1)")
+ public class Http1ProtocolPolicy extends TestHttpAsyncProtocolPolicy {
+
+ public Http1ProtocolPolicy() throws Exception {
+ super(URIScheme.HTTP, HttpVersion.HTTP_1_1);
+ }
+
+ }
+
+ @Nested
+ @DisplayName("HTTP protocol policy (HTTP/1.1, TLS)")
+ public class Http1ProtocolPolicyTls extends TestHttpAsyncProtocolPolicy {
+
+ public Http1ProtocolPolicyTls() throws Exception {
+ super(URIScheme.HTTPS, HttpVersion.HTTP_1_1);
+ }
+
+ }
+
+ @Nested
+ @DisplayName("HTTP protocol policy (HTTP/2)")
+ public class H2ProtocolPolicy extends TestHttpAsyncProtocolPolicy {
+
+ public H2ProtocolPolicy() throws Exception {
+ super(URIScheme.HTTP, HttpVersion.HTTP_2);
+ }
+
+ }
+
+ @Nested
+ @DisplayName("HTTP protocol policy (HTTP/2, TLS)")
+ public class H2ProtocolPolicyTls extends TestHttpAsyncProtocolPolicy {
+
+ public H2ProtocolPolicyTls() throws Exception {
+ super(URIScheme.HTTPS, HttpVersion.HTTP_2);
+ }
+
+ }
+
+ @Nested
+ @DisplayName("Redirects (HTTP/1.1)")
+ public class RedirectsHttp1 extends TestHttp1AsyncRedirects {
+
+ public RedirectsHttp1() throws Exception {
+ super(URIScheme.HTTP);
+ }
+
+ }
+
+ @Nested
+ @DisplayName("Redirects (HTTP/1.1, TLS)")
+ public class RedirectsHttp1Tls extends TestHttp1AsyncRedirects {
+
+ public RedirectsHttp1Tls() throws Exception {
+ super(URIScheme.HTTPS);
+ }
+
+ }
+
+ @Nested
+ @DisplayName("Redirects (HTTP/2)")
+ public class RedirectsH2 extends TestH2AsyncRedirect {
+
+ public RedirectsH2() throws Exception {
+ super(URIScheme.HTTP);
+ }
+
+ }
+
+ @Nested
+ @DisplayName("Redirects (HTTP/2, TLS)")
+ public class RedirectsH2Tls extends TestH2AsyncRedirect {
+
+ public RedirectsH2Tls() throws Exception {
+ super(URIScheme.HTTPS);
+ }
+
+ }
+
+ @Nested
+ @DisplayName("Client authentication (HTTP/1.1)")
+ public class AuthenticationHttp1 extends TestHttp1ClientAuthentication {
+
+ public AuthenticationHttp1() throws Exception {
+ super(URIScheme.HTTP);
+ }
+
+ }
+
+ @Nested
+ @DisplayName("Client authentication (HTTP/1.1, TLS)")
+ public class AuthenticationHttp1Tls extends TestHttp1ClientAuthentication {
+
+ public AuthenticationHttp1Tls() throws Exception {
+ super(URIScheme.HTTPS);
+ }
+
+ }
+
+ @Nested
+ @DisplayName("Client authentication (HTTP/2)")
+ public class AuthenticationH2 extends TestH2ClientAuthentication {
+
+ public AuthenticationH2() throws Exception {
+ super(URIScheme.HTTP);
+ }
+
+ }
+
+ @Nested
+ @DisplayName("Client authentication (HTTP/2, TLS)")
+ public class AuthenticationH2Tls extends TestH2ClientAuthentication {
+
+ public AuthenticationH2Tls() throws Exception {
+ super(URIScheme.HTTPS);
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/HttpMinimalIntegrationTests.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/HttpMinimalIntegrationTests.java
new file mode 100644
index 000000000..fc0169e64
--- /dev/null
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/HttpMinimalIntegrationTests.java
@@ -0,0 +1,75 @@
+/*
+ * ====================================================================
+ * 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
+ * .
+ *
+ */
+package org.apache.hc.client5.testing.async;
+
+import org.apache.hc.core5.http.URIScheme;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Nested;
+
+public class HttpMinimalIntegrationTests {
+
+ @Nested
+ @DisplayName("Fundamentals (HTTP/1.1)")
+ public class Http1 extends TestHttp1AsyncMinimal {
+
+ public Http1() throws Exception {
+ super(URIScheme.HTTP);
+ }
+
+ }
+
+ @Nested
+ @DisplayName("Fundamentals (HTTP/1.1, TLS)")
+ public class Http1Tls extends TestHttp1AsyncMinimal {
+
+ public Http1Tls() throws Exception {
+ super(URIScheme.HTTPS);
+ }
+
+ }
+
+ @Nested
+ @DisplayName("Fundamentals (HTTP/2)")
+ public class H2 extends TestH2AsyncMinimal {
+
+ public H2() throws Exception {
+ super(URIScheme.HTTP);
+ }
+
+ }
+
+ @Nested
+ @DisplayName("Fundamentals (HTTP/2, TLS)")
+ public class H2Tls extends TestH2AsyncMinimal {
+
+ public H2Tls() throws Exception {
+ super(URIScheme.HTTPS);
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/ReactiveIntegrationTests.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/ReactiveIntegrationTests.java
new file mode 100644
index 000000000..81e49b544
--- /dev/null
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/ReactiveIntegrationTests.java
@@ -0,0 +1,75 @@
+/*
+ * ====================================================================
+ * 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
+ * .
+ *
+ */
+package org.apache.hc.client5.testing.async;
+
+import org.apache.hc.core5.http.URIScheme;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Nested;
+
+public class ReactiveIntegrationTests {
+
+ @Nested
+ @DisplayName("Fundamentals (HTTP/1.1)")
+ public class Http1 extends TestHttp1Reactive {
+
+ public Http1() throws Exception {
+ super(URIScheme.HTTP);
+ }
+
+ }
+
+ @Nested
+ @DisplayName("Fundamentals (HTTP/1.1, TLS)")
+ public class Http1Tls extends TestHttp1Reactive {
+
+ public Http1Tls() throws Exception {
+ super(URIScheme.HTTPS);
+ }
+
+ }
+
+ @Nested
+ @DisplayName("Fundamentals (HTTP/2)")
+ public class H2 extends TestH2Reactive {
+
+ public H2() throws Exception {
+ super(URIScheme.HTTP);
+ }
+
+ }
+
+ @Nested
+ @DisplayName("Fundamentals (HTTP/2, TLS)")
+ public class H2Tls extends TestH2Reactive {
+
+ public H2Tls() throws Exception {
+ super(URIScheme.HTTPS);
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/ReactiveMinimalIntegrationTests.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/ReactiveMinimalIntegrationTests.java
new file mode 100644
index 000000000..27a7da833
--- /dev/null
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/ReactiveMinimalIntegrationTests.java
@@ -0,0 +1,75 @@
+/*
+ * ====================================================================
+ * 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
+ * .
+ *
+ */
+package org.apache.hc.client5.testing.async;
+
+import org.apache.hc.core5.http.URIScheme;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Nested;
+
+public class ReactiveMinimalIntegrationTests {
+
+ @Nested
+ @DisplayName("Fundamentals (HTTP/1.1)")
+ public class Http1 extends TestHttp1ReactiveMinimal {
+
+ public Http1() throws Exception {
+ super(URIScheme.HTTP);
+ }
+
+ }
+
+ @Nested
+ @DisplayName("Fundamentals (HTTP/1.1, TLS)")
+ public class Http1Tls extends TestHttp1ReactiveMinimal {
+
+ public Http1Tls() throws Exception {
+ super(URIScheme.HTTPS);
+ }
+
+ }
+
+ @Nested
+ @DisplayName("Fundamentals (HTTP/2)")
+ public class H2 extends TestH2ReactiveMinimal {
+
+ public H2() throws Exception {
+ super(URIScheme.HTTP);
+ }
+
+ }
+
+ @Nested
+ @DisplayName("Fundamentals (HTTP/2, TLS)")
+ public class H2Tls extends TestH2ReactiveMinimal {
+
+ public H2Tls() throws Exception {
+ super(URIScheme.HTTPS);
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestAsyncRequestContext.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestAsyncRequestContext.java
deleted file mode 100644
index 6a8797630..000000000
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestAsyncRequestContext.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * ====================================================================
- * 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
- * .
- *
- */
-package org.apache.hc.client5.testing.async;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.concurrent.Future;
-import java.util.concurrent.atomic.AtomicReference;
-
-import org.apache.hc.client5.http.async.methods.SimpleHttpResponse;
-import org.apache.hc.client5.http.async.methods.SimpleRequestBuilder;
-import org.apache.hc.client5.http.config.ConnectionConfig;
-import org.apache.hc.client5.http.config.RequestConfig;
-import org.apache.hc.client5.http.config.TlsConfig;
-import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
-import org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder;
-import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager;
-import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManagerBuilder;
-import org.apache.hc.client5.http.ssl.DefaultClientTlsStrategy;
-import org.apache.hc.client5.testing.SSLTestContexts;
-import org.apache.hc.core5.http.HttpHost;
-import org.apache.hc.core5.http.HttpVersion;
-import org.apache.hc.core5.http.ProtocolVersion;
-import org.apache.hc.core5.http.URIScheme;
-import org.apache.hc.core5.http.config.Http1Config;
-import org.apache.hc.core5.http2.HttpVersionPolicy;
-import org.apache.hc.core5.http2.config.H2Config;
-import org.hamcrest.CoreMatchers;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport;
-import org.junit.rules.ExternalResource;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
-@EnableRuleMigrationSupport
-@RunWith(Parameterized.class)
-public class TestAsyncRequestContext extends AbstractIntegrationTestBase {
-
- @Parameterized.Parameters(name = "{0} {1}")
- public static Collection