Skip to content

Commit d82fb91

Browse files
committed
Add UdsIntegrationTests and UdsAsyncIntegrationTests
1 parent fd2870e commit d82fb91

11 files changed

Lines changed: 180 additions & 7 deletions

httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractH2AsyncFundamentalsTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,13 @@
6969
abstract class AbstractH2AsyncFundamentalsTest extends AbstractHttpAsyncFundamentalsTest {
7070

7171
public AbstractH2AsyncFundamentalsTest(final URIScheme scheme, final ClientProtocolLevel clientProtocolLevel, final ServerProtocolLevel serverProtocolLevel) {
72-
super(scheme, clientProtocolLevel, serverProtocolLevel);
72+
this(scheme, clientProtocolLevel, serverProtocolLevel, false);
73+
}
74+
75+
public AbstractH2AsyncFundamentalsTest(final URIScheme scheme, final ClientProtocolLevel clientProtocolLevel,
76+
final ServerProtocolLevel serverProtocolLevel,
77+
final boolean useUnixDomainSocket) {
78+
super(scheme, clientProtocolLevel, serverProtocolLevel, useUnixDomainSocket);
7379
}
7480

7581
@Test
@@ -203,4 +209,4 @@ public void cancelled() {
203209
}
204210
}
205211

206-
}
212+
}

httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttpAsyncFundamentalsTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ protected AbstractHttpAsyncFundamentalsTest(final URIScheme scheme, final Client
6464
super(scheme, clientProtocolLevel, serverProtocolLevel);
6565
}
6666

67+
protected AbstractHttpAsyncFundamentalsTest(final URIScheme scheme, final ClientProtocolLevel clientProtocolLevel,
68+
final ServerProtocolLevel serverProtocolLevel,
69+
final boolean useUnixDomainSocket) {
70+
super(scheme, clientProtocolLevel, serverProtocolLevel, useUnixDomainSocket);
71+
}
72+
6773
@Test
6874
void testSequentialGetRequests() throws Exception {
6975
configureServer(bootstrap -> bootstrap.register("/random/*", AsyncRandomHandler::new));

httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttp1Async.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@
5555
abstract class TestHttp1Async extends AbstractHttpAsyncFundamentalsTest {
5656

5757
public TestHttp1Async(final URIScheme scheme) {
58-
super(scheme, ClientProtocolLevel.STANDARD, ServerProtocolLevel.STANDARD);
58+
this(scheme, false);
59+
}
60+
61+
public TestHttp1Async(final URIScheme scheme, final boolean useUnixDomainSocket) {
62+
super(scheme, ClientProtocolLevel.STANDARD, ServerProtocolLevel.STANDARD, useUnixDomainSocket);
5963
}
6064

6165
@ParameterizedTest(name = "{displayName}; concurrent connections: {0}")
@@ -201,4 +205,4 @@ void testRequestCancellation() throws Exception {
201205
}
202206
}
203207

204-
}
208+
}

httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/TestHttp1RequestReExecution.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@
5050
abstract class TestHttp1RequestReExecution extends AbstractIntegrationTestBase {
5151

5252
public TestHttp1RequestReExecution(final URIScheme scheme) {
53-
super(scheme, ClientProtocolLevel.STANDARD, ServerProtocolLevel.STANDARD);
53+
this(scheme, false);
54+
}
55+
56+
public TestHttp1RequestReExecution(final URIScheme scheme, final boolean useUnixDomainSocket) {
57+
super(scheme, ClientProtocolLevel.STANDARD, ServerProtocolLevel.STANDARD, useUnixDomainSocket);
5458
}
5559

5660
@BeforeEach
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* ====================================================================
3+
* Licensed to the Apache Software Foundation (ASF) under one
4+
* or more contributor license agreements. See the NOTICE file
5+
* distributed with this work for additional information
6+
* regarding copyright ownership. The ASF licenses this file
7+
* to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance
9+
* with the License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing,
14+
* software distributed under the License is distributed on an
15+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
* KIND, either express or implied. See the License for the
17+
* specific language governing permissions and limitations
18+
* under the License.
19+
* ====================================================================
20+
*
21+
* This software consists of voluntary contributions made by many
22+
* individuals on behalf of the Apache Software Foundation. For more
23+
* information on the Apache Software Foundation, please see
24+
* <http://www.apache.org/>.
25+
*
26+
*/
27+
package org.apache.hc.client5.testing.async;
28+
29+
import org.apache.hc.core5.http.URIScheme;
30+
import org.apache.hc.core5.util.VersionInfo;
31+
import org.junit.jupiter.api.DisplayName;
32+
import org.junit.jupiter.api.Nested;
33+
34+
import static org.apache.hc.core5.util.ReflectionUtils.determineJRELevel;
35+
import static org.junit.jupiter.api.Assumptions.assumeFalse;
36+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
37+
38+
class UdsAsyncIntegrationTests {
39+
40+
@Nested
41+
@DisplayName("Fundamentals (HTTP/1.1)")
42+
class Http1 extends TestHttp1Async {
43+
public Http1() {
44+
super(URIScheme.HTTP, true);
45+
checkForUdsSupport();
46+
}
47+
}
48+
49+
@Nested
50+
@DisplayName("Request re-execution (HTTP/1.1)")
51+
class Http1RequestReExecution extends TestHttp1RequestReExecution {
52+
public Http1RequestReExecution() {
53+
super(URIScheme.HTTP, true);
54+
checkForUdsSupport();
55+
}
56+
}
57+
58+
static void checkForUdsSupport() {
59+
assumeTrue(determineJRELevel() >= 16, "Async UDS requires Java 16+");
60+
final String[] components = VersionInfo
61+
.loadVersionInfo("org.apache.hc.core5", UdsAsyncIntegrationTests.class.getClassLoader())
62+
.getRelease()
63+
.split("[-.]");
64+
final int majorVersion = Integer.parseInt(components[0]);
65+
final int minorVersion = Integer.parseInt(components[1]);
66+
assumeFalse(majorVersion <= 5 && minorVersion <= 3, "Async UDS requires HttpCore 5.4+");
67+
}
68+
}

httpclient5-testing/src/test/java/org/apache/hc/client5/testing/extension/async/TestAsyncResources.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ public void afterEach(final ExtensionContext extensionContext) {
8787
client.close(CloseMode.GRACEFUL);
8888
}
8989
if (udsProxy != null) {
90+
// The test harness enables UDS through a default RequestConfig set on the client. If a test case
91+
// overrides the RequestConfig on a given request, it may connect directly to the test server by mistake.
92+
if (udsProxy.getRequestsReceived() == 0) {
93+
throw new AssertionError("The UDS proxy did not receive any requests");
94+
}
9095
udsProxy.close();
9196
}
9297
if (server != null) {

httpclient5-testing/src/test/java/org/apache/hc/client5/testing/extension/sync/TestClientResources.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ public void afterEach(final ExtensionContext extensionContext) {
7676
client.close(CloseMode.GRACEFUL);
7777
}
7878
if (udsProxy != null) {
79+
// The test harness enables UDS through a default RequestConfig set on the client. If a test case
80+
// overrides the RequestConfig on a given request, it may connect directly to the test server by mistake.
81+
if (udsProxy.getRequestsReceived() == 0) {
82+
throw new AssertionError("The UDS proxy did not receive any requests");
83+
}
7984
udsProxy.close();
8085
}
8186
if (server != null) {

httpclient5-testing/src/test/java/org/apache/hc/client5/testing/extension/sync/UnixDomainProxyServer.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.util.concurrent.ExecutorService;
4343
import java.util.concurrent.Executors;
4444
import java.util.concurrent.TimeUnit;
45+
import java.util.concurrent.atomic.AtomicInteger;
4546

4647
import static java.util.concurrent.CompletableFuture.supplyAsync;
4748

@@ -50,6 +51,7 @@ public final class UnixDomainProxyServer {
5051
private final ExecutorService executorService;
5152
private final Path socketPath;
5253
private final CountDownLatch serverReady = new CountDownLatch(1);
54+
private final AtomicInteger requestsReceived = new AtomicInteger(0);
5355
private volatile AFUNIXServerSocket serverSocket;
5456

5557
public UnixDomainProxyServer(final int port) {
@@ -71,6 +73,10 @@ public Path getSocketPath() {
7173
return socketPath;
7274
}
7375

76+
public int getRequestsReceived() {
77+
return requestsReceived.get();
78+
}
79+
7480
public void close() {
7581
try {
7682
serverSocket.close();
@@ -106,6 +112,7 @@ private void runUdsProxy() {
106112
private void serveRequests(final AFUNIXServerSocket server) throws IOException {
107113
while (true) {
108114
final AFUNIXSocket udsClient = server.accept();
115+
requestsReceived.incrementAndGet();
109116
final Socket tcpSocket = new Socket("localhost", port);
110117
final CompletableFuture<Void> f1 = supplyAsync(() -> pipe(udsClient, tcpSocket), executorService);
111118
final CompletableFuture<Void> f2 = supplyAsync(() -> pipe(tcpSocket, udsClient), executorService);

httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestClientRequestExecution.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@
7474
abstract class TestClientRequestExecution extends AbstractIntegrationTestBase {
7575

7676
public TestClientRequestExecution(final URIScheme scheme) {
77-
super(scheme, ClientProtocolLevel.STANDARD);
77+
this(scheme, false);
78+
}
79+
80+
public TestClientRequestExecution(final URIScheme scheme, final boolean useUnixDomainSocket) {
81+
super(scheme, ClientProtocolLevel.STANDARD, useUnixDomainSocket);
7882
}
7983

8084
private static class SimpleService implements HttpRequestHandler {

httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestContentCodings.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@
6666
abstract class TestContentCodings extends AbstractIntegrationTestBase {
6767

6868
protected TestContentCodings(final URIScheme scheme) {
69-
super(scheme, ClientProtocolLevel.STANDARD);
69+
this(scheme, false);
70+
}
71+
72+
protected TestContentCodings(final URIScheme scheme, final boolean useUnixDomainSocket) {
73+
super(scheme, ClientProtocolLevel.STANDARD, useUnixDomainSocket);
7074
}
7175

7276
/**

0 commit comments

Comments
 (0)