Skip to content

Commit 43f88fa

Browse files
committed
Add test which covers future being completed exceptionally with a CompletionException.
This happens in the Jetty implementation but gets wrapped in an IOException by the OkHttp impl but this should be enough for the coverage checker.
1 parent 3d39532 commit 43f88fa

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractInterceptorTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.junit.jupiter.api.DisplayName;
2323
import org.junit.jupiter.api.Test;
2424

25+
import java.io.InputStream;
2526
import java.net.URI;
2627
import java.nio.ByteBuffer;
2728
import java.nio.charset.StandardCharsets;
@@ -31,6 +32,7 @@
3132
import java.util.List;
3233
import java.util.Set;
3334
import java.util.concurrent.CompletableFuture;
35+
import java.util.concurrent.CompletionException;
3436
import java.util.concurrent.ConcurrentHashMap;
3537
import java.util.concurrent.CountDownLatch;
3638
import java.util.concurrent.TimeUnit;
@@ -233,6 +235,37 @@ public void after(HttpRequest request, HttpResponse<?> response, Consumer<List<B
233235
}
234236
}
235237

238+
@Test
239+
@DisplayName("afterConnectionFailure, completionExceptions are passed through")
240+
public void afterConnectionFailureCompletionException() {
241+
// Given
242+
final CountDownLatch connectionFailureCallbackInvoked = new CountDownLatch(1);
243+
final HttpClient.Builder builder = getHttpClientFactory().newBuilder()
244+
.connectTimeout(1, TimeUnit.SECONDS)
245+
.addOrReplaceInterceptor("test", new Interceptor() {
246+
@Override
247+
public void afterConnectionFailure(HttpRequest request, Throwable failure) {
248+
connectionFailureCallbackInvoked.countDown();
249+
}
250+
});
251+
// When
252+
try (HttpClient client = builder.build()) {
253+
final CompletableFuture<HttpResponse<String>> response = client.sendAsync(client.newHttpRequestBuilder()
254+
.timeout(1, TimeUnit.SECONDS)
255+
.uri(server.url("/intercepted-url"))
256+
.method("POST", "application/json", new InputStream() {
257+
@Override
258+
public int read() {
259+
throw new CompletionException("boom time", null); // gets propagated by jetty but gets wrapped by OkHttp
260+
}
261+
}, 1L).build(), String.class);
262+
263+
// Then
264+
assertThat(response).failsWithin(Duration.of(30, ChronoUnit.SECONDS));
265+
assertThat(connectionFailureCallbackInvoked).extracting(CountDownLatch::getCount).isEqualTo(0L);
266+
}
267+
}
268+
236269
@Test
237270
@DisplayName("afterFailure (HTTP), replaces the HttpResponse produced by HttpClient.consumeBytes")
238271
public void afterHttpFailureReplacesResponseInConsumeBytes() throws Exception {

0 commit comments

Comments
 (0)