use of com.nike.riposte.server.handler.base.PipelineContinuationBehavior in project riposte by Nike-Inc.
the class ExceptionHandlingHandlerTest method doExceptionCaught_should_do_nothing_and_return_DO_NOT_FIRE_CONTINUE_EVENT_if_response_sending_already_started.
@DataProvider(value = { "true", "false" })
@Test
public void doExceptionCaught_should_do_nothing_and_return_DO_NOT_FIRE_CONTINUE_EVENT_if_response_sending_already_started(boolean causeIsNullPointerException) {
// given
ExceptionHandlingHandler handlerSpy = spy(handler);
Throwable cause = (causeIsNullPointerException) ? new NullPointerException("intentional NPE") : new Exception("intentional test exception");
ResponseInfo<?> responseInfoMock = mock(ResponseInfo.class);
doReturn(true).when(responseInfoMock).isResponseSendingStarted();
state.setResponseInfo(responseInfoMock, cause);
// when
PipelineContinuationBehavior result = handlerSpy.doExceptionCaught(ctxMock, cause);
// then
verify(handlerSpy, never()).processError(any(HttpProcessingState.class), any(Object.class), any(Throwable.class));
Assertions.assertThat(result).isEqualTo(DO_NOT_FIRE_CONTINUE_EVENT);
}
use of com.nike.riposte.server.handler.base.PipelineContinuationBehavior in project riposte by Nike-Inc.
the class NonblockingEndpointExecutionHandlerTest method doChannelRead_executes_endpoint_and_attaches_completion_logic_and_schedules_timeout_for_result_and_returns_DO_NOT_FIRE_CONTINUE_EVENT_if_endpoint_is_NonblockingEndpoint.
@Test
public void doChannelRead_executes_endpoint_and_attaches_completion_logic_and_schedules_timeout_for_result_and_returns_DO_NOT_FIRE_CONTINUE_EVENT_if_endpoint_is_NonblockingEndpoint() throws Exception {
// when
PipelineContinuationBehavior result = handlerSpy.doChannelRead(ctxMock, msg);
// then
verify(endpointMock).execute(requestInfo, longRunningTaskExecutorMock, ctxMock);
// The 2nd whenComplete is for cancelling the timeout check if the response finishes before the timeout
verify(futureThatWillBeAttachedToSpy, times(2)).whenComplete(any(BiConsumer.class));
verify(eventLoopMock).schedule(any(Runnable.class), any(Long.class), eq(TimeUnit.MILLISECONDS));
verify(handlerSpy).doExecuteEndpointFunction(requestInfo, endpointMock, stateMock.getDistributedTraceStack().peek(), ctxMock);
assertThat(result).isEqualTo(PipelineContinuationBehavior.DO_NOT_FIRE_CONTINUE_EVENT);
}
use of com.nike.riposte.server.handler.base.PipelineContinuationBehavior in project riposte by Nike-Inc.
the class RequestFilterHandlerTest method doChannelRead_does_nothing_and_returns_CONTINUE_when_msg_is_not_first_or_last_chunk.
@Test
public void doChannelRead_does_nothing_and_returns_CONTINUE_when_msg_is_not_first_or_last_chunk() throws Exception {
// given
HttpContent contentChunkMsg = mock(HttpContent.class);
// when
PipelineContinuationBehavior result = handlerSpy.doChannelRead(ctxMock, contentChunkMsg);
// then
assertThat(result).isEqualTo(CONTINUE);
verify(handlerSpy, never()).handleFilterLogic(any(), any(), any(), any(), any());
}
use of com.nike.riposte.server.handler.base.PipelineContinuationBehavior in project riposte by Nike-Inc.
the class RequestFilterHandlerTest method handleFilterLogic_executes_all_filters_and_uses_requestInfo_returned_by_non_short_circuiting_filters.
@DataProvider(value = { "true", "false" }, splitBy = "\\|")
@Test
public void handleFilterLogic_executes_all_filters_and_uses_requestInfo_returned_by_non_short_circuiting_filters(boolean isFirstChunk) {
// given
HandleFilterLogicMethodCallArgs args = new HandleFilterLogicMethodCallArgs(isFirstChunk);
RequestInfo<?> firstFilterResult = mock(RequestInfo.class);
RequestInfo<?> secondFilterResult = mock(RequestInfo.class);
doReturn(firstFilterResult).when(filter1Mock).filterRequestFirstChunkNoPayload(any(), any());
doReturn(firstFilterResult).when(filter1Mock).filterRequestLastChunkWithFullPayload(any(), any());
doReturn(secondFilterResult).when(filter2Mock).filterRequestFirstChunkNoPayload(any(), any());
doReturn(secondFilterResult).when(filter2Mock).filterRequestLastChunkWithFullPayload(any(), any());
// when
PipelineContinuationBehavior result = handlerSpy.handleFilterLogic(ctxMock, args.msg, args.httpState, args.normalFilterCall, args.shortCircuitFilterCall);
// then
assertThat(result).isEqualTo(CONTINUE);
// First filter should have been passed the original request.
if (isFirstChunk)
verify(filter1Mock).filterRequestFirstChunkNoPayload(requestInfoMock, ctxMock);
else
verify(filter1Mock).filterRequestLastChunkWithFullPayload(requestInfoMock, ctxMock);
// Second filter should have been passed the result of the first filter.
if (isFirstChunk)
verify(filter2Mock).filterRequestFirstChunkNoPayload(firstFilterResult, ctxMock);
else
verify(filter2Mock).filterRequestLastChunkWithFullPayload(firstFilterResult, ctxMock);
// The state should have been updated with the result of the second filter.
assertThat(state.getRequestInfo()).isSameAs(secondFilterResult);
}
use of com.nike.riposte.server.handler.base.PipelineContinuationBehavior in project riposte by Nike-Inc.
the class RequestFilterHandlerTest method doChannelRead_delegates_to_handleFilterLogic_with_first_chunk_method_references_when_msg_is_HttpRequest.
@DataProvider(value = { "CONTINUE", "DO_NOT_FIRE_CONTINUE_EVENT" }, splitBy = "\\|")
@Test
public void doChannelRead_delegates_to_handleFilterLogic_with_first_chunk_method_references_when_msg_is_HttpRequest(PipelineContinuationBehavior expectedPipelineContinuationBehavior) throws Exception {
// given
doReturn(expectedPipelineContinuationBehavior).when(handlerSpy).handleFilterLogic(any(), any(), any(), any(), any());
// when
PipelineContinuationBehavior result = handlerSpy.doChannelRead(ctxMock, firstChunkMsgMock);
// then
assertThat(result).isEqualTo(expectedPipelineContinuationBehavior);
ArgumentCaptor<BiFunction> normalFilterCallCaptor = ArgumentCaptor.forClass(BiFunction.class);
ArgumentCaptor<BiFunction> shortCircuitFilterCallCaptor = ArgumentCaptor.forClass(BiFunction.class);
verify(handlerSpy).handleFilterLogic(eq(ctxMock), eq(firstChunkMsgMock), eq(state), normalFilterCallCaptor.capture(), shortCircuitFilterCallCaptor.capture());
BiFunction<RequestAndResponseFilter, RequestInfo, RequestInfo> normalFilterCall = normalFilterCallCaptor.getValue();
BiFunction<RequestAndResponseFilter, RequestInfo, Pair<RequestInfo, Optional<ResponseInfo<?>>>> shortCircuitFilterCall = shortCircuitFilterCallCaptor.getValue();
RequestAndResponseFilter filterForNormalCallMock = mock(RequestAndResponseFilter.class);
normalFilterCall.apply(filterForNormalCallMock, requestInfoMock);
verify(filterForNormalCallMock).filterRequestFirstChunkNoPayload(requestInfoMock, ctxMock);
RequestAndResponseFilter filterForShortCircuitCallMock = mock(RequestAndResponseFilter.class);
shortCircuitFilterCall.apply(filterForShortCircuitCallMock, requestInfoMock);
verify(filterForShortCircuitCallMock).filterRequestFirstChunkWithOptionalShortCircuitResponse(requestInfoMock, ctxMock);
}
Aggregations