Skip to content

Commit

Permalink
Add test which demonstrates what I expect to work
Browse files Browse the repository at this point in the history
  • Loading branch information
SamBarker committed Jul 17, 2024
1 parent 202b625 commit a60dc21
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.net.URI;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.Collections;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -170,6 +172,28 @@ public CompletableFuture<Boolean> afterFailure(BasicBuilder builder, HttpRespons
}
}

@Test
@DisplayName("afterFailure (HTTP), invoked when remote server offline")
public void afterHttpFailureRemoteOffline() {
// Given
server.shutdown();
final HttpClient.Builder builder = getHttpClientFactory().newBuilder()
.connectTimeout(1, TimeUnit.SECONDS)
.addOrReplaceInterceptor("test", new Interceptor() {
@Override
public CompletableFuture<Boolean> afterFailure(BasicBuilder builder, HttpResponse<?> response, RequestTags tags) {
return CompletableFuture.completedFuture(false);
}
});
// When
try (HttpClient client = builder.build()) {
final CompletableFuture<HttpResponse<String>> response = client.sendAsync(client.newHttpRequestBuilder().uri(server.url("/not-found")).build(), String.class);

// Then
assertThat(response).succeedsWithin(Duration.of(10, ChronoUnit.SECONDS));
}
}

@Test
@DisplayName("afterFailure (HTTP), replaces the HttpResponse produced by HttpClient.consumeBytes")
public void afterHttpFailureReplacesResponseInConsumeBytes() throws Exception {
Expand Down

0 comments on commit a60dc21

Please sign in to comment.