Search in sources :

Example 76 with PipelineContinuationBehavior

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

the class ExceptionHandlingHandlerTest method doExceptionCaught_should_setForceConnectionCloseAfterResponseSent_to_true_on_request_when_exception_matches_certain_types.

@UseDataProvider("exceptionsThatShouldForceCloseConnection")
@Test
public void doExceptionCaught_should_setForceConnectionCloseAfterResponseSent_to_true_on_request_when_exception_matches_certain_types(Throwable exThatShouldForceCloseConnection) throws Exception {
    // given
    ExceptionHandlingHandler handlerSpy = spy(handler);
    ResponseInfo<ErrorResponseBody> errorResponseMock = mock(ResponseInfo.class);
    doReturn(errorResponseMock).when(handlerSpy).processError(state, null, exThatShouldForceCloseConnection);
    assertThat(state.getResponseInfo(), nullValue());
    // when
    PipelineContinuationBehavior result = handlerSpy.doExceptionCaught(ctxMock, exThatShouldForceCloseConnection);
    // then
    verify(errorResponseMock).setForceConnectionCloseAfterResponseSent(true);
    verify(handlerSpy).getStateAndCreateIfNeeded(ctxMock, exThatShouldForceCloseConnection);
    verify(handlerSpy).processError(state, null, exThatShouldForceCloseConnection);
    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) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 77 with PipelineContinuationBehavior

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

the class ExceptionHandlingHandlerTest method doChannelRead_should_call_processUnhandledError_and_set_response_on_state_and_return_CONTINUE_if_request_has_not_been_handled.

@Test
public void doChannelRead_should_call_processUnhandledError_and_set_response_on_state_and_return_CONTINUE_if_request_has_not_been_handled() throws Exception {
    // given
    ExceptionHandlingHandler handlerSpy = spy(handler);
    ResponseInfo<ErrorResponseBody> errorResponseMock = mock(ResponseInfo.class);
    Object msg = new Object();
    doReturn(errorResponseMock).when(handlerSpy).processUnhandledError(eq(state), eq(msg), any(Throwable.class));
    assertThat(state.isRequestHandled(), is(false));
    // when
    PipelineContinuationBehavior result = handlerSpy.doChannelRead(ctxMock, msg);
    // then
    verify(handlerSpy).processUnhandledError(eq(state), eq(msg), any(Throwable.class));
    assertThat(state.getResponseInfo(), is(errorResponseMock));
    Assertions.assertThat(state.getErrorThatTriggeredThisResponse()).isInstanceOf(InvalidRipostePipelineException.class);
    verify(handlerSpy).addErrorAnnotationToOverallRequestSpan(state, errorResponseMock, state.getErrorThatTriggeredThisResponse());
    assertThat(result, is(PipelineContinuationBehavior.CONTINUE));
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) ErrorResponseBody(com.nike.riposte.server.error.handler.ErrorResponseBody) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Test(org.junit.Test)

Example 78 with PipelineContinuationBehavior

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

the class NonblockingEndpointExecutionHandlerTest method doChannelRead_does_nothing_and_returns_CONTINUE_if_endpoint_is_null.

@Test
public void doChannelRead_does_nothing_and_returns_CONTINUE_if_endpoint_is_null() throws Exception {
    // given
    doReturn(null).when(stateMock).getEndpointForExecution();
    // when
    PipelineContinuationBehavior result = handlerSpy.doChannelRead(ctxMock, msg);
    // then
    verifyNoMoreInteractions(endpointMock);
    assertThat(futureThatWillBeAttachedToSpy).isNull();
    verifyNoMoreInteractions(eventLoopMock);
    assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) Test(org.junit.Test)

Example 79 with PipelineContinuationBehavior

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

the class NonblockingEndpointExecutionHandlerTest method doChannelRead_does_nothing_and_returns_CONTINUE_if_msg_is_not_HttpObject.

@Test
public void doChannelRead_does_nothing_and_returns_CONTINUE_if_msg_is_not_HttpObject() throws Exception {
    // given
    Object badMsg = new Object();
    // when
    PipelineContinuationBehavior result = handlerSpy.doChannelRead(ctxMock, badMsg);
    // then
    verifyNoInteractions(endpointMock, eventLoopMock);
    assertThat(futureThatWillBeAttachedToSpy).isNull();
    assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) Test(org.junit.Test)

Example 80 with PipelineContinuationBehavior

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

the class ChannelPipelineFinalizerHandlerTest method doChannelInactive_does_not_propagate_unexpected_exception_while_releasing_request_resources.

@Test
public void doChannelInactive_does_not_propagate_unexpected_exception_while_releasing_request_resources() throws Exception {
    // given
    HttpProcessingState stateSpy = spy(state);
    doReturn(stateSpy).when(stateAttributeMock).get();
    doThrow(new RuntimeException("intentional exception")).when(requestInfoMock).releaseAllResources();
    Assertions.assertThat(stateSpy.isTraceCompletedOrScheduled()).isFalse();
    Assertions.assertThat(stateSpy.isAccessLogCompletedOrScheduled()).isFalse();
    Assertions.assertThat(stateSpy.isRequestMetricsRecordedOrScheduled()).isFalse();
    verify(requestInfoMock, never()).releaseAllResources();
    verify(proxyRouterStateMock, never()).cancelRequestStreaming(any(), any());
    verify(proxyRouterStateMock, never()).cancelDownstreamRequest(any());
    // when
    PipelineContinuationBehavior result = handler.doChannelInactive(ctxMock);
    // then
    // Verify that the exception was thrown.
    verify(requestInfoMock).releaseAllResources();
    // Verify that no other finalization logic was impacted.
    Assertions.assertThat(stateSpy.isTraceCompletedOrScheduled()).isTrue();
    Assertions.assertThat(stateSpy.isAccessLogCompletedOrScheduled()).isTrue();
    Assertions.assertThat(stateSpy.isRequestMetricsRecordedOrScheduled()).isTrue();
    verify(requestInfoMock).releaseAllResources();
    verify(proxyRouterStateMock).cancelRequestStreaming(any(), any());
    verify(proxyRouterStateMock).cancelDownstreamRequest(any());
    Assertions.assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) HttpProcessingState(com.nike.riposte.server.http.HttpProcessingState) 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