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();
}
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();
}
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();
}
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));
}
Aggregations