use of com.hotels.styx.client.StyxClientException in project styx by ExpediaGroup.
the class HttpPipelineHandlerTest method mapsStyxClientExceptionToInternalServerErrorInWaitingForResponseState.
@Test
public void mapsStyxClientExceptionToInternalServerErrorInWaitingForResponseState() throws Exception {
// In Waiting For Response state,
// The response observable emits a StyxClientException.
// Then, respond with INTERNAL_SERVER_ERROR and close the channel.
setupHandlerTo(WAITING_FOR_RESPONSE);
responseObservable.onError(new StyxClientException("Client error occurred", new JustATestException()));
assertThat(responseUnsubscribed.get(), is(true));
ArgumentCaptor<LiveHttpResponse> captor = ArgumentCaptor.forClass(LiveHttpResponse.class);
verify(responseWriter).write(captor.capture());
HttpResponse response = Mono.from(captor.getValue().aggregate(100)).block();
assertThat(response.status(), is(INTERNAL_SERVER_ERROR));
assertThat(response.header(CONNECTION), is(Optional.of("close")));
assertThat(response.header(CONTENT_LENGTH), is(Optional.of("29")));
assertThat(response.bodyAs(UTF_8), is("Site temporarily unavailable."));
writerFuture.complete(null);
verify(statsCollector).onComplete(request.id(), 500);
verify(errorListener).proxyErrorOccurred(any(LiveHttpRequest.class), any(InetSocketAddress.class), eq(INTERNAL_SERVER_ERROR), any(RuntimeException.class));
// NOTE: channel closure is not verified. This is because cannot mock channel future.
verify(ctx).close();
assertThat(handler.state(), is(TERMINATED));
}
Aggregations