use of com.nike.riposte.server.handler.base.PipelineContinuationBehavior in project riposte by Nike-Inc.
the class DTraceStartHandlerTest method doChannelRead_does_not_call_startTrace_if_msg_is_not_HttpRequest_but_it_does_return_CONTINUE.
@Test
public void doChannelRead_does_not_call_startTrace_if_msg_is_not_HttpRequest_but_it_does_return_CONTINUE() throws Exception {
// given
DTraceStartHandler handlerSpy = spy(handler);
// when
PipelineContinuationBehavior result = handlerSpy.doChannelRead(ctxMock, new Object());
// then
verify(handlerSpy, times(0)).startTrace(any(), any());
assertThat(result, is(PipelineContinuationBehavior.CONTINUE));
}
use of com.nike.riposte.server.handler.base.PipelineContinuationBehavior in project riposte by Nike-Inc.
the class DTraceStartHandlerTest method doChannelRead_adds_wire_receive_finish_annotation_whem_msg_is_LastHttpContent_if_desired.
@DataProvider(value = { "true | true | true", "true | false | false", "false | true | false", "false | false | false" }, splitBy = "\\|")
@Test
public void doChannelRead_adds_wire_receive_finish_annotation_whem_msg_is_LastHttpContent_if_desired(boolean addWireReceiveFinishAnnotationConfigValue, boolean overallRequestSpanExists, boolean expectAnnotation) {
// given
DTraceStartHandler handlerSpy = spy(handler);
HttpProcessingState stateSpy = spy(state);
doReturn(stateSpy).when(stateAttributeMock).get();
Span spanMock = (overallRequestSpanExists) ? mock(Span.class) : null;
doReturn(spanMock).when(stateSpy).getOverallRequestSpan();
shouldAddWireReceiveFinishAnnotation = addWireReceiveFinishAnnotationConfigValue;
// when
PipelineContinuationBehavior result = handlerSpy.doChannelRead(ctxMock, new DefaultLastHttpContent());
// then
if (expectAnnotation) {
verify(spanMock).addTimestampedAnnotationForCurrentTime(distributedTracingConfig.getServerSpanNamingAndTaggingStrategy().wireReceiveFinishAnnotationName());
verifyNoMoreInteractions(spanMock);
} else if (spanMock != null) {
verify(spanMock, never()).addTimestampedAnnotationForCurrentTime(anyString());
}
Assertions.assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
use of com.nike.riposte.server.handler.base.PipelineContinuationBehavior in project riposte by Nike-Inc.
the class OpenChannelLimitHandlerTest method doChannelRead_throws_TooManyOpenChannelsException_or_not_depending_on_the_number_of_open_channels.
@DataProvider(value = { "null | false", "-1 | false", "0 | true", "1 | true" }, splitBy = "\\|")
@Test
public void doChannelRead_throws_TooManyOpenChannelsException_or_not_depending_on_the_number_of_open_channels(Integer numOpenChannelsDiffFromMaxThreshold, boolean expectTooManyOpenChannelsException) {
// given
Integer numOpenChannels = (numOpenChannelsDiffFromMaxThreshold == null) ? null : maxOpenChannelsThreshold + numOpenChannelsDiffFromMaxThreshold;
doReturn(numOpenChannels).when(tooManyOpenConnectionsAttributeMock).get();
// when
Throwable ex = null;
PipelineContinuationBehavior result = null;
try {
result = handler.doChannelRead(ctxMock, msg);
} catch (Throwable t) {
ex = t;
}
// then
if (expectTooManyOpenChannelsException) {
assertThat(ex).isInstanceOf(TooManyOpenChannelsException.class);
} else {
assertThat(ex).isNull();
assertThat(result).isEqualTo(CONTINUE);
}
}
use of com.nike.riposte.server.handler.base.PipelineContinuationBehavior in project riposte by Nike-Inc.
the class RequestInfoSetterHandlerTest method doChannelRead_creates_and_sets_RequestInfo_on_state_and_RequestInfo_is_marked_as_complete_with_all_chunks_if_msg_is_FullHttpRequest.
@Test
public void doChannelRead_creates_and_sets_RequestInfo_on_state_and_RequestInfo_is_marked_as_complete_with_all_chunks_if_msg_is_FullHttpRequest() {
// given
FullHttpRequest msgMock = mock(FullHttpRequest.class);
String uri = "/some/url";
HttpHeaders headers = new DefaultHttpHeaders();
doReturn(uri).when(msgMock).uri();
doReturn(headers).when(msgMock).headers();
doReturn(headers).when(msgMock).trailingHeaders();
doReturn(byteBufMock).when(msgMock).content();
doReturn(false).when(byteBufMock).isReadable();
doReturn(HttpVersion.HTTP_1_1).when(msgMock).protocolVersion();
doReturn(null).when(stateMock).getRequestInfo();
// when
PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msgMock);
// then
ArgumentCaptor<RequestInfo> requestInfoArgumentCaptor = ArgumentCaptor.forClass(RequestInfo.class);
verify(stateMock).setRequestInfo(requestInfoArgumentCaptor.capture());
RequestInfo requestInfo = requestInfoArgumentCaptor.getValue();
assertThat(requestInfo.getUri()).isEqualTo(uri);
assertThat(requestInfo.isCompleteRequestWithAllChunks()).isTrue();
assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
use of com.nike.riposte.server.handler.base.PipelineContinuationBehavior in project riposte by Nike-Inc.
the class RequestInfoSetterHandlerTest method doChannelRead_checks_for_fully_send_responses_but_does_nothing_else_if_msg_is_not_HttpRequest_or_HttpContent.
@Test
public void doChannelRead_checks_for_fully_send_responses_but_does_nothing_else_if_msg_is_not_HttpRequest_or_HttpContent() {
// given
HttpObject msgMock = mock(HttpObject.class);
// when
PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msgMock);
// then
verify(ctxMock, times(2)).channel();
verifyNoMoreInteractions(ctxMock);
verify(stateMock).isResponseSendingLastChunkSent();
verifyNoMoreInteractions(stateMock);
verifyNoMoreInteractions(msgMock);
assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
Aggregations