Search in sources :

Example 51 with HttpProcessingState

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

the class DTraceEndHandlerTest method beforeMethod.

@Before
public void beforeMethod() {
    handlerSpy = spy(new DTraceEndHandler());
    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();
    resetTracingAndMdc();
    responseInfoMock = mock(ResponseInfo.class);
    doReturn(true).when(responseInfoMock).isResponseSendingLastChunkSent();
    state.setResponseInfo(responseInfoMock);
    lastChunkChannelFutureMock = mock(ChannelFuture.class);
    state.setResponseWriterFinalChunkChannelFuture(lastChunkChannelFutureMock);
    doAnswer(invocation -> {
        currentSpanWhenCompleteCurrentSpanWasCalled = Tracer.getInstance().getCurrentSpan();
        invocation.callRealMethod();
        currentSpanAfterCompleteCurrentSpanWasCalled = Tracer.getInstance().getCurrentSpan();
        return null;
    }).when(handlerSpy).completeCurrentSpan();
}
Also used : ResponseInfo(com.nike.riposte.server.http.ResponseInfo) ChannelFuture(io.netty.channel.ChannelFuture) Attribute(io.netty.util.Attribute) Channel(io.netty.channel.Channel) HttpProcessingState(com.nike.riposte.server.http.HttpProcessingState) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Before(org.junit.Before)

Example 52 with HttpProcessingState

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

the class ChannelPipelineFinalizerHandlerTest method beforeMethod.

@Before
public void beforeMethod() {
    exceptionHandlingHandlerMock = mock(ExceptionHandlingHandler.class);
    responseSenderMock = mock(ResponseSender.class);
    metricsListenerMock = mock(MetricsListener.class);
    handler = new ChannelPipelineFinalizerHandler(exceptionHandlingHandlerMock, responseSenderMock, metricsListenerMock, workerChannelIdleTimeoutMillis);
    channelMock = mock(Channel.class);
    ctxMock = mock(ChannelHandlerContext.class);
    pipelineMock = mock(ChannelPipeline.class);
    stateAttributeMock = mock(Attribute.class);
    proxyRouterProcessingStateAttributeMock = mock(Attribute.class);
    state = new HttpProcessingState();
    proxyRouterStateMock = mock(ProxyRouterProcessingState.class);
    responseInfoMock = mock(ResponseInfo.class);
    requestInfoMock = mock(RequestInfo.class);
    doReturn(channelMock).when(ctxMock).channel();
    doReturn(pipelineMock).when(ctxMock).pipeline();
    doReturn(stateAttributeMock).when(channelMock).attr(ChannelAttributes.HTTP_PROCESSING_STATE_ATTRIBUTE_KEY);
    doReturn(state).when(stateAttributeMock).get();
    doReturn(proxyRouterStateMock).when(proxyRouterProcessingStateAttributeMock).get();
    doReturn(proxyRouterProcessingStateAttributeMock).when(channelMock).attr(ChannelAttributes.PROXY_ROUTER_PROCESSING_STATE_ATTRIBUTE_KEY);
    doReturn(requestInfoMock).when(exceptionHandlingHandlerMock).getRequestInfo(any(HttpProcessingState.class), any(Object.class));
    doReturn(true).when(responseInfoMock).isResponseSendingStarted();
    doReturn(true).when(responseInfoMock).isResponseSendingLastChunkSent();
    state.setResponseInfo(responseInfoMock);
    state.setRequestInfo(requestInfoMock);
    if (Tracer.getInstance().getCurrentSpan() != null)
        Tracer.getInstance().completeRequestSpan();
}
Also used : ResponseInfo(com.nike.riposte.server.http.ResponseInfo) Attribute(io.netty.util.Attribute) Channel(io.netty.channel.Channel) HttpProcessingState(com.nike.riposte.server.http.HttpProcessingState) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ProxyRouterProcessingState(com.nike.riposte.server.http.ProxyRouterProcessingState) RequestInfo(com.nike.riposte.server.http.RequestInfo) ResponseSender(com.nike.riposte.server.http.ResponseSender) ChannelPipeline(io.netty.channel.ChannelPipeline) MetricsListener(com.nike.riposte.metrics.MetricsListener) Matchers.anyObject(org.mockito.Matchers.anyObject) Before(org.junit.Before)

Example 53 with HttpProcessingState

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

the class ExceptionHandlingHandlerTest method beforeMethod.

@Before
public void beforeMethod() {
    riposteErrorHandlerMock = mock(RiposteErrorHandler.class);
    riposteUnhandledErrorHandlerMock = mock(RiposteUnhandledErrorHandler.class);
    handler = new ExceptionHandlingHandler(riposteErrorHandlerMock, riposteUnhandledErrorHandlerMock);
    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();
}
Also used : RiposteUnhandledErrorHandler(com.nike.riposte.server.error.handler.RiposteUnhandledErrorHandler) Attribute(io.netty.util.Attribute) Channel(io.netty.channel.Channel) HttpProcessingState(com.nike.riposte.server.http.HttpProcessingState) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) RiposteErrorHandler(com.nike.riposte.server.error.handler.RiposteErrorHandler) Before(org.junit.Before)

Example 54 with HttpProcessingState

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

the class ExceptionHandlingHandlerTest method processError_returns_value_of_processUnhandledError_if_riposteErrorHandler_returns_null.

@Test
public void processError_returns_value_of_processUnhandledError_if_riposteErrorHandler_returns_null() throws UnexpectedMajorErrorHandlingError, JsonProcessingException {
    // given
    HttpProcessingState stateMock = mock(HttpProcessingState.class);
    Object msg = new Object();
    Throwable cause = new Exception();
    ExceptionHandlingHandler handlerSpy = spy(handler);
    ResponseInfo<ErrorResponseBody> responseInfoMockFromCatchallMethod = mock(ResponseInfo.class);
    doReturn(null).when(riposteErrorHandlerMock).maybeHandleError(any(), any());
    doReturn(responseInfoMockFromCatchallMethod).when(handlerSpy).processUnhandledError(stateMock, msg, cause);
    // when
    ResponseInfo<ErrorResponseBody> response = handlerSpy.processError(stateMock, msg, cause);
    // then
    verify(riposteErrorHandlerMock).maybeHandleError(any(), any());
    assertThat(response, is(responseInfoMockFromCatchallMethod));
}
Also used : HttpProcessingState(com.nike.riposte.server.http.HttpProcessingState) ErrorResponseBody(com.nike.riposte.server.error.handler.ErrorResponseBody) IncompleteHttpCallTimeoutException(com.nike.riposte.server.error.exception.IncompleteHttpCallTimeoutException) TooManyOpenChannelsException(com.nike.riposte.server.error.exception.TooManyOpenChannelsException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test)

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