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