Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@
abstract class AbstractH2AsyncFundamentalsTest extends AbstractHttpAsyncFundamentalsTest {

public AbstractH2AsyncFundamentalsTest(final URIScheme scheme, final ClientProtocolLevel clientProtocolLevel, final ServerProtocolLevel serverProtocolLevel) {
super(scheme, clientProtocolLevel, serverProtocolLevel);
this(scheme, clientProtocolLevel, serverProtocolLevel, false);
}

public AbstractH2AsyncFundamentalsTest(final URIScheme scheme, final ClientProtocolLevel clientProtocolLevel,
final ServerProtocolLevel serverProtocolLevel,
final boolean useUnixDomainSocket) {
super(scheme, clientProtocolLevel, serverProtocolLevel, useUnixDomainSocket);
}

@Test
Expand Down Expand Up @@ -203,4 +209,4 @@ public void cancelled() {
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ protected AbstractHttpAsyncFundamentalsTest(final URIScheme scheme, final Client
super(scheme, clientProtocolLevel, serverProtocolLevel);
}

protected AbstractHttpAsyncFundamentalsTest(final URIScheme scheme, final ClientProtocolLevel clientProtocolLevel,
final ServerProtocolLevel serverProtocolLevel,
final boolean useUnixDomainSocket) {
super(scheme, clientProtocolLevel, serverProtocolLevel, useUnixDomainSocket);
}

@Test
void testSequentialGetRequests() throws Exception {
configureServer(bootstrap -> bootstrap.register("/random/*", AsyncRandomHandler::new));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@
abstract class TestHttp1Async extends AbstractHttpAsyncFundamentalsTest {

public TestHttp1Async(final URIScheme scheme) {
super(scheme, ClientProtocolLevel.STANDARD, ServerProtocolLevel.STANDARD);
this(scheme, false);
}

public TestHttp1Async(final URIScheme scheme, final boolean useUnixDomainSocket) {
super(scheme, ClientProtocolLevel.STANDARD, ServerProtocolLevel.STANDARD, useUnixDomainSocket);
}

@ParameterizedTest(name = "{displayName}; concurrent connections: {0}")
Expand Down Expand Up @@ -201,4 +205,4 @@ void testRequestCancellation() throws Exception {
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@
abstract class TestHttp1RequestReExecution extends AbstractIntegrationTestBase {

public TestHttp1RequestReExecution(final URIScheme scheme) {
super(scheme, ClientProtocolLevel.STANDARD, ServerProtocolLevel.STANDARD);
this(scheme, false);
}

public TestHttp1RequestReExecution(final URIScheme scheme, final boolean useUnixDomainSocket) {
super(scheme, ClientProtocolLevel.STANDARD, ServerProtocolLevel.STANDARD, useUnixDomainSocket);
}

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* ====================================================================
* 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
* <http://www.apache.org/>.
*
*/
package org.apache.hc.client5.testing.async;

import org.apache.hc.core5.http.URIScheme;
import org.apache.hc.core5.util.VersionInfo;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;

import static org.apache.hc.core5.util.ReflectionUtils.determineJRELevel;
import static org.junit.jupiter.api.Assumptions.assumeFalse;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

class UdsAsyncIntegrationTests {

@Nested
@DisplayName("Fundamentals (HTTP/1.1)")
class Http1 extends TestHttp1Async {
public Http1() {
super(URIScheme.HTTP, true);
checkForUdsSupport();
}
}

@Nested
@DisplayName("Request re-execution (HTTP/1.1)")
class Http1RequestReExecution extends TestHttp1RequestReExecution {
public Http1RequestReExecution() {
super(URIScheme.HTTP, true);
checkForUdsSupport();
}
}

static void checkForUdsSupport() {
assumeTrue(determineJRELevel() >= 16, "Async UDS requires Java 16+");
final String[] components = VersionInfo
.loadVersionInfo("org.apache.hc.core5", UdsAsyncIntegrationTests.class.getClassLoader())
.getRelease()
.split("[-.]");
final int majorVersion = Integer.parseInt(components[0]);
final int minorVersion = Integer.parseInt(components[1]);
assumeFalse(majorVersion <= 5 && minorVersion <= 3, "Async UDS requires HttpCore 5.4+");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ public void afterEach(final ExtensionContext extensionContext) {
client.close(CloseMode.GRACEFUL);
}
if (udsProxy != null) {
// The test harness enables UDS through a default RequestConfig set on the client. If a test case
// overrides the RequestConfig on a given request, it may connect directly to the test server by mistake.
if (udsProxy.getRequestsReceived() == 0) {
throw new AssertionError("The UDS proxy did not receive any requests");
}
udsProxy.close();
}
if (server != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ public void afterEach(final ExtensionContext extensionContext) {
client.close(CloseMode.GRACEFUL);
}
if (udsProxy != null) {
// The test harness enables UDS through a default RequestConfig set on the client. If a test case
// overrides the RequestConfig on a given request, it may connect directly to the test server by mistake.
if (udsProxy.getRequestsReceived() == 0) {
throw new AssertionError("The UDS proxy did not receive any requests");
}
udsProxy.close();
}
if (server != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

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

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

public UnixDomainProxyServer(final int port) {
Expand All @@ -71,6 +73,10 @@ public Path getSocketPath() {
return socketPath;
}

public int getRequestsReceived() {
return requestsReceived.get();
}

public void close() {
try {
serverSocket.close();
Expand Down Expand Up @@ -106,6 +112,7 @@ private void runUdsProxy() {
private void serveRequests(final AFUNIXServerSocket server) throws IOException {
while (true) {
final AFUNIXSocket udsClient = server.accept();
requestsReceived.incrementAndGet();
final Socket tcpSocket = new Socket("localhost", port);
final CompletableFuture<Void> f1 = supplyAsync(() -> pipe(udsClient, tcpSocket), executorService);
final CompletableFuture<Void> f2 = supplyAsync(() -> pipe(tcpSocket, udsClient), executorService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@
abstract class TestClientRequestExecution extends AbstractIntegrationTestBase {

public TestClientRequestExecution(final URIScheme scheme) {
super(scheme, ClientProtocolLevel.STANDARD);
this(scheme, false);
}

public TestClientRequestExecution(final URIScheme scheme, final boolean useUnixDomainSocket) {
super(scheme, ClientProtocolLevel.STANDARD, useUnixDomainSocket);
}

private static class SimpleService implements HttpRequestHandler {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@
abstract class TestContentCodings extends AbstractIntegrationTestBase {

protected TestContentCodings(final URIScheme scheme) {
super(scheme, ClientProtocolLevel.STANDARD);
this(scheme, false);
}

protected TestContentCodings(final URIScheme scheme, final boolean useUnixDomainSocket) {
super(scheme, ClientProtocolLevel.STANDARD, useUnixDomainSocket);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* ====================================================================
* 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
* <http://www.apache.org/>.
*
*/
package org.apache.hc.client5.testing.sync;

import org.apache.hc.core5.http.URIScheme;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;

import static org.junit.jupiter.api.Assumptions.assumeTrue;

class UdsIntegrationTests {
@Nested
@DisplayName("Request execution (HTTP/1.1)")
class RequestExecution extends TestClientRequestExecution {
public RequestExecution() {
super(URIScheme.HTTP, true);
}
}

@Nested
@DisplayName("Request execution (HTTP/1.1, TLS)")
class RequestExecutionTls extends TestClientRequestExecution {
public RequestExecutionTls() {
super(URIScheme.HTTPS, true);
assumeTrue(false, "HTTPS is not currently supported over Unix domain sockets");
}
}

@Nested
@DisplayName("Content coding (HTTP/1.1)")
class ContentCoding extends TestContentCodings {
public ContentCoding() {
super(URIScheme.HTTP, true);
}
}
}