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