Search in sources :

Example 11 with PipelineContinuationBehavior

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);
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) HttpProcessingState(com.nike.riposte.server.http.HttpProcessingState) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) IncompleteHttpCallTimeoutException(com.nike.riposte.server.error.exception.IncompleteHttpCallTimeoutException) TooManyOpenChannelsException(com.nike.riposte.server.error.exception.TooManyOpenChannelsException) InvalidRipostePipelineException(com.nike.riposte.server.error.exception.InvalidRipostePipelineException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) Test(org.junit.Test)

Example 12 with PipelineContinuationBehavior

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);
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) BiConsumer(java.util.function.BiConsumer) Test(org.junit.Test)

Example 13 with PipelineContinuationBehavior

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());
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) HttpContent(io.netty.handler.codec.http.HttpContent) Test(org.junit.Test)

Example 14 with PipelineContinuationBehavior

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);
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 15 with PipelineContinuationBehavior

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);
}
Also used : ResponseInfo(com.nike.riposte.server.http.ResponseInfo) LastOutboundMessageSendFullResponseInfo(com.nike.riposte.server.channelpipeline.message.LastOutboundMessageSendFullResponseInfo) PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) BiFunction(java.util.function.BiFunction) RequestAndResponseFilter(com.nike.riposte.server.http.filter.RequestAndResponseFilter) RequestInfo(com.nike.riposte.server.http.RequestInfo) Pair(com.nike.internal.util.Pair) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Aggregations

PipelineContinuationBehavior (com.nike.riposte.server.handler.base.PipelineContinuationBehavior)92 Test (org.junit.Test)90 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)26 HttpProcessingState (com.nike.riposte.server.http.HttpProcessingState)11 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)9 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)8 RequestInfo (com.nike.riposte.server.http.RequestInfo)7 Span (com.nike.wingtips.Span)6 IncompleteHttpCallTimeoutException (com.nike.riposte.server.error.exception.IncompleteHttpCallTimeoutException)5 TooManyOpenChannelsException (com.nike.riposte.server.error.exception.TooManyOpenChannelsException)5 ErrorResponseBody (com.nike.riposte.server.error.handler.ErrorResponseBody)5 RequestAndResponseFilter (com.nike.riposte.server.http.filter.RequestAndResponseFilter)5 HttpRequest (io.netty.handler.codec.http.HttpRequest)5 Pair (com.nike.internal.util.Pair)4 LastOutboundMessageSendFullResponseInfo (com.nike.riposte.server.channelpipeline.message.LastOutboundMessageSendFullResponseInfo)4 ResponseInfo (com.nike.riposte.server.http.ResponseInfo)4 ChannelFuture (io.netty.channel.ChannelFuture)4 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)4 InvalidRipostePipelineException (com.nike.riposte.server.error.exception.InvalidRipostePipelineException)3 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)3