Search in sources :

Example 61 with PipelineContinuationBehavior

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

the class ChannelPipelineFinalizerHandlerTest method doChannelInactive_does_not_try_to_recomplete_span_if_already_completed.

@Test
public void doChannelInactive_does_not_try_to_recomplete_span_if_already_completed() throws Exception {
    // given
    Span span = setupTracingForChannelInactive(false);
    Deque<Span> deque = new LinkedList<>();
    deque.add(span);
    Tracer.getInstance().registerWithThread(deque);
    Tracer.getInstance().completeRequestSpan();
    Assertions.assertThat(span.isCompleted()).isTrue();
    long durationNanosBefore = span.getDurationNanos();
    // when
    PipelineContinuationBehavior result = handler.doChannelInactive(ctxMock);
    // then
    // no change
    Assertions.assertThat(span.isCompleted()).isTrue();
    Assertions.assertThat(span.getDurationNanos()).isEqualTo(durationNanosBefore);
    verify(requestInfoMock).releaseAllResources();
    verify(proxyRouterStateMock).setStreamingFailed();
    verify(proxyRouterStateMock).triggerStreamingChannelErrorForChunks(any(Throwable.class));
    Assertions.assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) Span(com.nike.wingtips.Span) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 62 with PipelineContinuationBehavior

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

the class DTraceEndHandlerTest method doChannelRead_calls_endDtrace_and_returns_CONTINUE_if_msg_is_LastOutboundMessage.

@Test
public void doChannelRead_calls_endDtrace_and_returns_CONTINUE_if_msg_is_LastOutboundMessage() throws Exception {
    // given
    LastOutboundMessage msg = mock(LastOutboundMessage.class);
    // when
    PipelineContinuationBehavior result = handlerSpy.doChannelRead(ctxMock, msg);
    // then
    verify(handlerSpy).endDtrace(ctxMock);
    assertThat(result, is(PipelineContinuationBehavior.CONTINUE));
}
Also used : LastOutboundMessage(com.nike.riposte.server.channelpipeline.message.LastOutboundMessage) PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) Test(org.junit.Test)

Example 63 with PipelineContinuationBehavior

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

the class DTraceEndHandlerTest method doChannelRead_does_nothing_and_returns_CONTINUE_if_msg_is_not_LastOutboundMessage.

@Test
public void doChannelRead_does_nothing_and_returns_CONTINUE_if_msg_is_not_LastOutboundMessage() throws Exception {
    // given
    Object msg = new Object();
    // when
    PipelineContinuationBehavior result = handlerSpy.doChannelRead(ctxMock, msg);
    // then
    verify(handlerSpy, times(0)).endDtrace(ctxMock);
    assertThat(result, is(PipelineContinuationBehavior.CONTINUE));
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) Test(org.junit.Test)

Example 64 with PipelineContinuationBehavior

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

the class ChannelPipelineFinalizerHandlerTest method doExceptionCaught_gets_state_from_getStateAndCreateIfNeeded_method_and_then_calls_finalizeChannelPipeline_and_then_returns_DO_NOT_FIRE_CONTINUE_EVENT.

@Test
public void doExceptionCaught_gets_state_from_getStateAndCreateIfNeeded_method_and_then_calls_finalizeChannelPipeline_and_then_returns_DO_NOT_FIRE_CONTINUE_EVENT() throws Exception {
    // given
    ChannelPipelineFinalizerHandler handlerSpy = spy(handler);
    Exception cause = new Exception("intentional test exception");
    state.setResponseWriterFinalChunkChannelFuture(mock(ChannelFuture.class));
    // when
    PipelineContinuationBehavior result = handlerSpy.doExceptionCaught(ctxMock, cause);
    // then
    verify(handlerSpy).getStateAndCreateIfNeeded(ctxMock, cause);
    verify(handlerSpy).finalizeChannelPipeline(ctxMock, null, state, cause);
    assertThat(result, is(PipelineContinuationBehavior.DO_NOT_FIRE_CONTINUE_EVENT));
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test)

Example 65 with PipelineContinuationBehavior

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

the class ChannelPipelineFinalizerHandlerTest method doChannelInactive_does_what_it_can_when_the_RequestInfo_or_ResponseInfo_is_null.

@DataProvider(value = { "true   |   false", "false  |   true", "true   |   true" }, splitBy = "\\|")
@Test
public void doChannelInactive_does_what_it_can_when_the_RequestInfo_or_ResponseInfo_is_null(boolean requestInfoIsNull, boolean responseInfoIsNull) throws Exception {
    // given
    Span span = setupTracingForChannelInactive(false);
    if (requestInfoIsNull)
        state.setRequestInfo(null);
    if (responseInfoIsNull)
        state.setResponseInfo(null);
    // when
    PipelineContinuationBehavior result = handler.doChannelInactive(ctxMock);
    // then
    Assertions.assertThat(span.isCompleted()).isTrue();
    Assertions.assertThat(state.isTraceCompletedOrScheduled()).isTrue();
    if (requestInfoIsNull)
        verifyZeroInteractions(requestInfoMock);
    else
        verify(requestInfoMock).releaseAllResources();
    verify(proxyRouterStateMock).setStreamingFailed();
    verify(proxyRouterStateMock).triggerStreamingChannelErrorForChunks(any(Throwable.class));
    Assertions.assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) Span(com.nike.wingtips.Span) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Aggregations

PipelineContinuationBehavior (com.nike.riposte.server.handler.base.PipelineContinuationBehavior)75 Test (org.junit.Test)73 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)20 RequestInfo (com.nike.riposte.server.http.RequestInfo)5 Span (com.nike.wingtips.Span)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 LastOutboundMessageSendFullResponseInfo (com.nike.riposte.server.channelpipeline.message.LastOutboundMessageSendFullResponseInfo)4 HttpProcessingState (com.nike.riposte.server.http.HttpProcessingState)4 ResponseInfo (com.nike.riposte.server.http.ResponseInfo)4 RequestAndResponseFilter (com.nike.riposte.server.http.filter.RequestAndResponseFilter)4 ChannelFuture (io.netty.channel.ChannelFuture)4 HttpObject (io.netty.handler.codec.http.HttpObject)4 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)4 Pair (com.nike.internal.util.Pair)3 HttpContent (io.netty.handler.codec.http.HttpContent)3 ChannelAttributes (com.nike.riposte.server.channelpipeline.ChannelAttributes)2 OutboundMessage (com.nike.riposte.server.channelpipeline.message.OutboundMessage)2 OutboundMessageSendHeadersChunkFromResponseInfo (com.nike.riposte.server.channelpipeline.message.OutboundMessageSendHeadersChunkFromResponseInfo)2 IncompleteHttpCallTimeoutException (com.nike.riposte.server.error.exception.IncompleteHttpCallTimeoutException)2 TooManyOpenChannelsException (com.nike.riposte.server.error.exception.TooManyOpenChannelsException)2