Search in sources :

Example 1 with ContentOverflowException

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));
}
Also used : LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) InetSocketAddress(java.net.InetSocketAddress) HttpResponse(com.hotels.styx.api.HttpResponse) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) DefaultHttpResponse(io.netty.handler.codec.http.DefaultHttpResponse) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) ContentOverflowException(com.hotels.styx.api.ContentOverflowException) Test(org.junit.jupiter.api.Test)

Aggregations

ContentOverflowException (com.hotels.styx.api.ContentOverflowException)1 HttpResponse (com.hotels.styx.api.HttpResponse)1 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)1 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)1 DefaultHttpResponse (io.netty.handler.codec.http.DefaultHttpResponse)1 InetSocketAddress (java.net.InetSocketAddress)1 Test (org.junit.jupiter.api.Test)1