Search in sources :

Example 1 with PipelineContinuationBehavior

use of com.nike.riposte.server.handler.base.PipelineContinuationBehavior in project riposte by Nike-Inc.

the class RequestInfoSetterHandlerTest method doChannelRead_releases_content_and_returns_do_not_fire_when_state_is_null_or_response_already_sent.

@DataProvider(value = { "true   |   false", "false  |   true", "true   |   true" }, splitBy = "\\|")
@Test
public void doChannelRead_releases_content_and_returns_do_not_fire_when_state_is_null_or_response_already_sent(boolean stateIsNull, boolean responseAlreadySent) {
    // given
    if (stateIsNull)
        doReturn(null).when(stateAttrMock).get();
    if (responseAlreadySent) {
        doReturn(true).when(stateMock).isResponseSendingLastChunkSent();
    }
    // when
    PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, httpContentMock);
    // then
    verify(httpContentMock).release();
    assertThat(result).isEqualTo(PipelineContinuationBehavior.DO_NOT_FIRE_CONTINUE_EVENT);
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 2 with PipelineContinuationBehavior

use of com.nike.riposte.server.handler.base.PipelineContinuationBehavior in project riposte by Nike-Inc.

the class RequestContentValidationHandlerTest method doChannelRead_does_nothing_if_request_getRawContentLengthInBytes_returns_0.

@Test
public void doChannelRead_does_nothing_if_request_getRawContentLengthInBytes_returns_0() throws Exception {
    // given
    doReturn(0).when(requestInfoMock).getRawContentLengthInBytes();
    // when
    PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msg);
    // then
    verifyNoMoreInteractions(requestValidatorMock);
    assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) Test(org.junit.Test)

Example 3 with PipelineContinuationBehavior

use of com.nike.riposte.server.handler.base.PipelineContinuationBehavior in project riposte by Nike-Inc.

the class ResponseSenderHandlerTest method doExceptionCaught_calls_sendResponse_and_returns_CONTINUE.

@Test
public void doExceptionCaught_calls_sendResponse_and_returns_CONTINUE() throws Exception {
    // when
    PipelineContinuationBehavior result = handlerSpy.doExceptionCaught(ctxMock, new Exception("intentional test exception"));
    // then
    verify(handlerSpy).sendResponse(ctxMock, null);
    assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test)

Example 4 with PipelineContinuationBehavior

use of com.nike.riposte.server.handler.base.PipelineContinuationBehavior in project riposte by Nike-Inc.

the class ExceptionHandlingHandlerTest method doExceptionCaught_should_call_getStateAndCreateIfNeeded_and_then_processError_and_then_set_response_on_state_and_return_CONTINUE.

@Test
public void doExceptionCaught_should_call_getStateAndCreateIfNeeded_and_then_processError_and_then_set_response_on_state_and_return_CONTINUE() throws Exception {
    // given
    ExceptionHandlingHandler handlerSpy = spy(handler);
    Throwable cause = new Exception("intentional test exception");
    ResponseInfo<ErrorResponseBody> errorResponseMock = mock(ResponseInfo.class);
    doReturn(errorResponseMock).when(handlerSpy).processError(state, null, cause);
    assertThat(state.getResponseInfo(), nullValue());
    // when
    PipelineContinuationBehavior result = handlerSpy.doExceptionCaught(ctxMock, cause);
    // then
    verify(handlerSpy).getStateAndCreateIfNeeded(ctxMock, cause);
    verify(handlerSpy).processError(state, null, cause);
    assertThat(state.getResponseInfo(), is(errorResponseMock));
    assertThat(result, is(PipelineContinuationBehavior.CONTINUE));
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) 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)

Example 5 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.

@Test
public void doExceptionCaught_should_do_nothing_and_return_DO_NOT_FIRE_CONTINUE_EVENT_if_response_sending_already_started() throws Exception {
    // given
    ExceptionHandlingHandler handlerSpy = spy(handler);
    Throwable cause = new Exception("intentional test exception");
    ResponseInfo<?> responseInfoMock = mock(ResponseInfo.class);
    doReturn(true).when(responseInfoMock).isResponseSendingStarted();
    state.setResponseInfo(responseInfoMock);
    // 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) 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

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