diff --git a/httpclient-jdk/src/test/java/io/fabric8/kubernetes/client/jdkhttp/JdkHttpClientPutTest.java b/httpclient-jdk/src/test/java/io/fabric8/kubernetes/client/jdkhttp/JdkHttpClientPutTest.java index e7e4054ed5a..a888cab4f13 100644 --- a/httpclient-jdk/src/test/java/io/fabric8/kubernetes/client/jdkhttp/JdkHttpClientPutTest.java +++ b/httpclient-jdk/src/test/java/io/fabric8/kubernetes/client/jdkhttp/JdkHttpClientPutTest.java @@ -18,10 +18,17 @@ import io.fabric8.kubernetes.client.http.AbstractHttpPutTest; import io.fabric8.kubernetes.client.http.HttpClient; +import java.io.IOException; + @SuppressWarnings("java:S2187") public class JdkHttpClientPutTest extends AbstractHttpPutTest { @Override protected HttpClient.Factory getHttpClientFactory() { return new JdkHttpClientFactory(); } + + @Override + protected Class getConnectionFailedExceptionType() { + return IOException.class; + } } diff --git a/httpclient-jetty/src/test/java/io/fabric8/kubernetes/client/jetty/JettyHttpPutTest.java b/httpclient-jetty/src/test/java/io/fabric8/kubernetes/client/jetty/JettyHttpPutTest.java index 59283a0c938..ce4c0465e33 100644 --- a/httpclient-jetty/src/test/java/io/fabric8/kubernetes/client/jetty/JettyHttpPutTest.java +++ b/httpclient-jetty/src/test/java/io/fabric8/kubernetes/client/jetty/JettyHttpPutTest.java @@ -18,10 +18,17 @@ import io.fabric8.kubernetes.client.http.AbstractHttpPutTest; import io.fabric8.kubernetes.client.http.HttpClient; +import java.io.EOFException; + @SuppressWarnings("java:S2187") public class JettyHttpPutTest extends AbstractHttpPutTest { @Override protected HttpClient.Factory getHttpClientFactory() { return new JettyHttpClientFactory(); } + + @Override + protected Class getConnectionFailedExceptionType() { + return EOFException.class; + } } diff --git a/httpclient-okhttp/src/test/java/io/fabric8/kubernetes/client/okhttp/OkHttpPutTest.java b/httpclient-okhttp/src/test/java/io/fabric8/kubernetes/client/okhttp/OkHttpPutTest.java index 4f77fa9e05f..34d5ff00356 100644 --- a/httpclient-okhttp/src/test/java/io/fabric8/kubernetes/client/okhttp/OkHttpPutTest.java +++ b/httpclient-okhttp/src/test/java/io/fabric8/kubernetes/client/okhttp/OkHttpPutTest.java @@ -18,10 +18,17 @@ import io.fabric8.kubernetes.client.http.AbstractHttpPutTest; import io.fabric8.kubernetes.client.http.HttpClient; +import java.net.ConnectException; + @SuppressWarnings("java:S2187") public class OkHttpPutTest extends AbstractHttpPutTest { @Override protected HttpClient.Factory getHttpClientFactory() { return new OkHttpClientFactory(); } + + @Override + protected Class getConnectionFailedExceptionType() { + return ConnectException.class; + } } diff --git a/httpclient-vertx/src/test/java/io/fabric8/kubernetes/client/vertx/VertxHttpClientPutTest.java b/httpclient-vertx/src/test/java/io/fabric8/kubernetes/client/vertx/VertxHttpClientPutTest.java index 5ede5806444..d8ea5075755 100644 --- a/httpclient-vertx/src/test/java/io/fabric8/kubernetes/client/vertx/VertxHttpClientPutTest.java +++ b/httpclient-vertx/src/test/java/io/fabric8/kubernetes/client/vertx/VertxHttpClientPutTest.java @@ -17,6 +17,7 @@ import io.fabric8.kubernetes.client.http.AbstractHttpPutTest; import io.fabric8.kubernetes.client.http.HttpClient; +import io.vertx.core.http.HttpClosedException; @SuppressWarnings("java:S2187") public class VertxHttpClientPutTest extends AbstractHttpPutTest { @@ -24,4 +25,9 @@ public class VertxHttpClientPutTest extends AbstractHttpPutTest { protected HttpClient.Factory getHttpClientFactory() { return new VertxHttpClientFactory(); } + + @Override + protected Class getConnectionFailedExceptionType() { + return HttpClosedException.class; + } } diff --git a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractHttpPutTest.java b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractHttpPutTest.java index 31aa8e0ccb3..65fee35c4d8 100644 --- a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractHttpPutTest.java +++ b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractHttpPutTest.java @@ -24,6 +24,8 @@ import java.io.ByteArrayInputStream; import java.nio.charset.StandardCharsets; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import static org.assertj.core.api.Assertions.assertThat; @@ -44,6 +46,8 @@ static void afterAll() { protected abstract HttpClient.Factory getHttpClientFactory(); + protected abstract Class getConnectionFailedExceptionType(); + @Test @DisplayName("String body, should send a PUT request with body") public void putStringBody() throws Exception { @@ -83,4 +87,23 @@ public void putInputStreamBody() throws Exception { .extracting(rr -> rr.getHeader("Content-Type")).asString() .startsWith("text/plain"); } + + @Test + public void expectFailure() { + server.expect().put().withPath("/put-failing").failure(null, new IllegalStateException("kaboom")).always(); + // When + try (HttpClient client = getHttpClientFactory().newBuilder().build()) { + final CompletableFuture> response = client + .sendAsync(client.newHttpRequestBuilder() + .put("text/plain", new ByteArrayInputStream("A string body".getBytes(StandardCharsets.UTF_8)), -1) + .uri(server.url("/put-failing")) + .timeout(250, TimeUnit.MILLISECONDS) + .build(), String.class); + + // Then + assertThat(response).failsWithin(30, TimeUnit.SECONDS) + .withThrowableOfType(ExecutionException.class) + .withCauseInstanceOf(getConnectionFailedExceptionType()); + } + } }