Search in sources :

Example 1 with StyxClientException

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));
}
Also used : JustATestException(com.hotels.styx.support.JustATestException) StyxClientException(com.hotels.styx.client.StyxClientException) 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) Test(org.junit.jupiter.api.Test)

Aggregations

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