Skip to content
Merged
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 @@ -18,10 +18,13 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.net.ConnectException;
import java.net.ServerSocket;
import java.net.URI;
import java.security.AccessController;
import java.security.PrivilegedExceptionAction;
Expand All @@ -47,6 +50,7 @@ public void clientWithDefaultSettingAlpn_httpRequest_doesNotThrowUnsupportedOper
assertThat(e.getCause()).hasCauseInstanceOf(ConnectException.class);
assertThat(e.getMessage()).contains("Connection refused");
assertThat(e.getMessage()).doesNotContain("ALPN can only be used with HTTPS, not HTTP. Use ProtocolNegotiation.ASSUME_PROTOCOL instead.");
client.close();
}

@Test
Expand All @@ -62,11 +66,12 @@ public void clientWithUserConfiguredAlpn_httpRequest_throwsUnsupportedOperationE
assertThat(e).hasCauseInstanceOf(SdkClientException.class);
assertThat(e.getCause()).hasCauseInstanceOf(UnsupportedOperationException.class);
assertThat(e.getMessage()).contains("ALPN can only be used with HTTPS, not HTTP. Use ProtocolNegotiation.ASSUME_PROTOCOL instead.");
client.close();
}

private H2AsyncClientBuilder clientBuilderWithHttpEndpoint() {
return H2AsyncClient.builder()
.endpointOverride(URI.create("http://localhost:8080"));
.endpointOverride(URI.create("http://localhost:" + getUnusedPort()));
}

private void makeRequest(H2AsyncClient client) {
Expand All @@ -90,4 +95,13 @@ private static boolean alpnSupported() {
return false;
}
}

private static int getUnusedPort() {
try (ServerSocket socket = new ServerSocket(0)) {
socket.setReuseAddress(true);
return socket.getLocalPort();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
Loading