- Я проверил, что API отвечает вызовом Curl в течение 10 мс.
Код: Выделить всё
curl --max-time 0.01 http://localhost:8000/
Код: Выделить всё
@Test
public void testHTTPClient() throws URISyntaxException, IOException, InterruptedException {
HttpClient client = HttpClient.newBuilder().build().newHttpClient();
java.net.URI uri = new URI("http://localhost:8000/");
HttpRequest req = HttpRequest.newBuilder(uri).GET().timeout(Duration.ofMillis(100)).build();
long start = Instant.now().toEpochMilli();
try {
java.net.http.HttpResponse response = client.send(req, java.net.http.HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
} catch (HttpTimeoutException e) {
System.out.println("Time taken " + (Instant.now().toEpochMilli() - start));
e.printStackTrace();
}
}
Код: Выделить всё
Time taken 159
java.net.http.HttpTimeoutException: request timed out
at java.net.http/jdk.internal.net.http.HttpClientImpl.send(HttpClientImpl.java:559)
at java.net.http/jdk.internal.net.http.HttpClientFacade.send(HttpClientFacade.java:119)