Search in sources :

Example 1 with HttpProcessingState

use of com.nike.riposte.server.http.HttpProcessingState in project riposte by Nike-Inc.

the class ChannelPipelineFinalizerHandlerTest method finalizeChannelPipeline_should_send_event_to_metricsListener_for_failure_response_and_flush_context.

@Test
public void finalizeChannelPipeline_should_send_event_to_metricsListener_for_failure_response_and_flush_context() throws Exception {
    // given
    ChannelFuture responseWriterChannelFuture = mock(ChannelFuture.class);
    state.setResponseWriterFinalChunkChannelFuture(responseWriterChannelFuture);
    HttpProcessingState stateSpy = spy(state);
    doReturn(stateSpy).when(stateAttributeMock).get();
    ChannelFuture responseWriteFutureResult = mock(ChannelFuture.class);
    doReturn(false).when(responseWriteFutureResult).isSuccess();
    Assertions.assertThat(stateSpy.isRequestMetricsRecordedOrScheduled()).isFalse();
    // when
    handler.finalizeChannelPipeline(ctxMock, null, stateSpy, null);
    // then
    ArgumentCaptor<GenericFutureListener> channelFutureListenerArgumentCaptor = ArgumentCaptor.forClass(GenericFutureListener.class);
    verify(responseWriterChannelFuture).addListener(channelFutureListenerArgumentCaptor.capture());
    GenericFutureListener futureListener = channelFutureListenerArgumentCaptor.getValue();
    assertThat(futureListener, notNullValue());
    futureListener.operationComplete(responseWriteFutureResult);
    verify(metricsListenerMock).onEvent(ServerMetricsEvent.RESPONSE_WRITE_FAILED, null);
    verify(ctxMock).flush();
    Assertions.assertThat(stateSpy.isRequestMetricsRecordedOrScheduled()).isTrue();
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) HttpProcessingState(com.nike.riposte.server.http.HttpProcessingState) GenericFutureListener(io.netty.util.concurrent.GenericFutureListener) Test(org.junit.Test)

Example 2 with HttpProcessingState

use of com.nike.riposte.server.http.HttpProcessingState in project riposte by Nike-Inc.

the class ChannelPipelineFinalizerHandlerTest method getStateAndCreateIfNeeded_creates_new_state_if_ctx_state_is_null.

@Test
public void getStateAndCreateIfNeeded_creates_new_state_if_ctx_state_is_null() {
    // given
    doReturn(null).when(stateAttributeMock).get();
    // when
    HttpProcessingState result = handler.getStateAndCreateIfNeeded(ctxMock, null);
    // then
    assertThat(result, notNullValue());
    assertThat(result, not(state));
    verify(stateAttributeMock).set(result);
}
Also used : HttpProcessingState(com.nike.riposte.server.http.HttpProcessingState) Test(org.junit.Test)

Example 3 with HttpProcessingState

use of com.nike.riposte.server.http.HttpProcessingState in project riposte by Nike-Inc.

the class ResponseFilterHandlerTest method beforeMethod.

@Before
public void beforeMethod() {
    channelMock = mock(Channel.class);
    ctxMock = mock(ChannelHandlerContext.class);
    stateAttributeMock = mock(Attribute.class);
    state = new HttpProcessingState();
    requestInfoMock = mock(RequestInfo.class);
    doReturn(channelMock).when(ctxMock).channel();
    doReturn(stateAttributeMock).when(channelMock).attr(ChannelAttributes.HTTP_PROCESSING_STATE_ATTRIBUTE_KEY);
    doReturn(state).when(stateAttributeMock).get();
    chunkedResponseMsg = mock(OutboundMessageSendHeadersChunkFromResponseInfo.class);
    fullResponseMsg = mock(LastOutboundMessageSendFullResponseInfo.class);
    filter1Mock = mock(RequestAndResponseFilter.class);
    filter2Mock = mock(RequestAndResponseFilter.class);
    filtersList = Arrays.asList(filter1Mock, filter2Mock);
    reversedFiltersList = new ArrayList<>(filtersList);
    Collections.reverse(reversedFiltersList);
    handlerSpy = spy(new ResponseFilterHandler(filtersList));
    chunkedResponseInfoMock = mock(ChunkedResponseInfo.class);
    fullResponseInfoMock = mock(FullResponseInfo.class);
    state.setResponseInfo(fullResponseInfoMock);
    state.setRequestInfo(requestInfoMock);
}
Also used : Attribute(io.netty.util.Attribute) OutboundMessageSendHeadersChunkFromResponseInfo(com.nike.riposte.server.channelpipeline.message.OutboundMessageSendHeadersChunkFromResponseInfo) RequestAndResponseFilter(com.nike.riposte.server.http.filter.RequestAndResponseFilter) ChunkedResponseInfo(com.nike.riposte.server.http.impl.ChunkedResponseInfo) Channel(io.netty.channel.Channel) HttpProcessingState(com.nike.riposte.server.http.HttpProcessingState) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) RequestInfo(com.nike.riposte.server.http.RequestInfo) LastOutboundMessageSendFullResponseInfo(com.nike.riposte.server.channelpipeline.message.LastOutboundMessageSendFullResponseInfo) FullResponseInfo(com.nike.riposte.server.http.impl.FullResponseInfo) LastOutboundMessageSendFullResponseInfo(com.nike.riposte.server.channelpipeline.message.LastOutboundMessageSendFullResponseInfo) Before(org.junit.Before)

Example 4 with HttpProcessingState

use of com.nike.riposte.server.http.HttpProcessingState in project riposte by Nike-Inc.

the class RequestFilterHandlerTest method beforeMethod.

@Before
public void beforeMethod() {
    channelMock = mock(Channel.class);
    ctxMock = mock(ChannelHandlerContext.class);
    stateAttributeMock = mock(Attribute.class);
    state = new HttpProcessingState();
    doReturn(channelMock).when(ctxMock).channel();
    doReturn(stateAttributeMock).when(channelMock).attr(ChannelAttributes.HTTP_PROCESSING_STATE_ATTRIBUTE_KEY);
    doReturn(state).when(stateAttributeMock).get();
    firstChunkMsgMock = mock(HttpRequest.class);
    lastChunkMsgMock = mock(LastHttpContent.class);
    filter1Mock = mock(RequestAndResponseFilter.class);
    filter2Mock = mock(RequestAndResponseFilter.class);
    filtersList = Arrays.asList(filter1Mock, filter2Mock);
    handlerSpy = spy(new RequestFilterHandler(filtersList));
    requestInfoMock = mock(RequestInfo.class);
    state.setRequestInfo(requestInfoMock);
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) Attribute(io.netty.util.Attribute) RequestAndResponseFilter(com.nike.riposte.server.http.filter.RequestAndResponseFilter) Channel(io.netty.channel.Channel) HttpProcessingState(com.nike.riposte.server.http.HttpProcessingState) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) RequestInfo(com.nike.riposte.server.http.RequestInfo) Before(org.junit.Before)

Example 5 with HttpProcessingState

use of com.nike.riposte.server.http.HttpProcessingState in project riposte by Nike-Inc.

the class RequestHasBeenHandledVerificationHandlerTest method beforeMethod.

@Before
public void beforeMethod() {
    channelMock = mock(Channel.class);
    ctxMock = mock(ChannelHandlerContext.class);
    stateAttributeMock = mock(Attribute.class);
    state = new HttpProcessingState();
    responseInfoMock = mock(ResponseInfo.class);
    doReturn(channelMock).when(ctxMock).channel();
    doReturn(stateAttributeMock).when(channelMock).attr(ChannelAttributes.HTTP_PROCESSING_STATE_ATTRIBUTE_KEY);
    doReturn(state).when(stateAttributeMock).get();
    state.setResponseInfo(responseInfoMock);
    handler = new RequestHasBeenHandledVerificationHandler();
    msg = mock(LastOutboundMessageSendFullResponseInfo.class);
}
Also used : ResponseInfo(com.nike.riposte.server.http.ResponseInfo) LastOutboundMessageSendFullResponseInfo(com.nike.riposte.server.channelpipeline.message.LastOutboundMessageSendFullResponseInfo) Attribute(io.netty.util.Attribute) Channel(io.netty.channel.Channel) HttpProcessingState(com.nike.riposte.server.http.HttpProcessingState) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) LastOutboundMessageSendFullResponseInfo(com.nike.riposte.server.channelpipeline.message.LastOutboundMessageSendFullResponseInfo) Before(org.junit.Before)

Aggregations

HttpProcessingState (com.nike.riposte.server.http.HttpProcessingState)54 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)22 Before (org.junit.Before)20 Channel (io.netty.channel.Channel)19 Attribute (io.netty.util.Attribute)19 RequestInfo (com.nike.riposte.server.http.RequestInfo)14 ResponseInfo (com.nike.riposte.server.http.ResponseInfo)11 Test (org.junit.Test)9 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)8 ErrorResponseBody (com.nike.riposte.server.error.handler.ErrorResponseBody)8 Endpoint (com.nike.riposte.server.http.Endpoint)6 ProxyRouterProcessingState (com.nike.riposte.server.http.ProxyRouterProcessingState)6 Span (com.nike.wingtips.Span)5 ChannelFuture (io.netty.channel.ChannelFuture)5 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)5 LastOutboundMessageSendFullResponseInfo (com.nike.riposte.server.channelpipeline.message.LastOutboundMessageSendFullResponseInfo)4 IncompleteHttpCallTimeoutException (com.nike.riposte.server.error.exception.IncompleteHttpCallTimeoutException)4 TooManyOpenChannelsException (com.nike.riposte.server.error.exception.TooManyOpenChannelsException)4 RequestAndResponseFilter (com.nike.riposte.server.http.filter.RequestAndResponseFilter)4 HttpRequest (io.netty.handler.codec.http.HttpRequest)4