use of com.hotels.styx.api.ContentOverflowException in project styx by ExpediaGroup.
the class HttpPipelineHandlerTest method responseObservableEmitsContentOverflowExceptionInWaitingForResponseState.
@Test
public void responseObservableEmitsContentOverflowExceptionInWaitingForResponseState() throws Exception {
// In Waiting For Response state,
// When response observable emits ContentOverflowException.
// Then respond with BAD_GATEWAY and close the channel
setupHandlerTo(WAITING_FOR_RESPONSE);
responseObservable.onError(new ContentOverflowException("Request Send Error"));
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(BAD_GATEWAY));
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."));
verify(responseEnhancer).enhance(any(LiveHttpResponse.Transformer.class), eq(request));
writerFuture.complete(null);
verify(statsCollector).onComplete(request.id(), 502);
verify(errorListener).proxyErrorOccurred(any(LiveHttpRequest.class), any(InetSocketAddress.class), eq(BAD_GATEWAY), 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