@Override public PipelineContinuationBehavior doExceptionCaught(ChannelHandlerContext ctx, Throwable cause) { endDtrace(ctx); return PipelineContinuationBehavior.CONTINUE; }
@Override public PipelineContinuationBehavior doExceptionCaught(ChannelHandlerContext ctx, Throwable cause) { endDtrace(ctx); return PipelineContinuationBehavior.CONTINUE; }
@Override public PipelineContinuationBehavior doChannelRead(ChannelHandlerContext ctx, Object msg) { if (shouldHandleDoChannelReadMessage(msg)) endDtrace(ctx); return PipelineContinuationBehavior.CONTINUE; }
@Override public PipelineContinuationBehavior doChannelRead(ChannelHandlerContext ctx, Object msg) { if (shouldHandleDoChannelReadMessage(msg)) endDtrace(ctx); return PipelineContinuationBehavior.CONTINUE; }
@Test public void endDtrace_attempts_to_complete_the_trace_even_if_state_is_null() { // given doReturn(null).when(stateAttributeMock).get(); // when handlerSpy.endDtrace(ctxMock); // then verify(handlerSpy).completeCurrentSpan(); assertThat(currentSpanWhenCompleteCurrentSpanWasCalled, nullValue()); assertThat(currentSpanAfterCompleteCurrentSpanWasCalled, nullValue()); }
@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)); }
@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)); }
@Test public void doExceptionCaught_calls_endDtrace_and_returns_CONTINUE() throws Exception { // when PipelineContinuationBehavior result = handlerSpy.doExceptionCaught(ctxMock, null); // then verify(handlerSpy).endDtrace(ctxMock); assertThat(result, is(PipelineContinuationBehavior.CONTINUE)); }
@Test public void endDtrace_does_nothing_if_state_isTraceCompletedOrScheduled_returns_true() { // given state.setTraceCompletedOrScheduled(true); // when handlerSpy.endDtrace(ctxMock); // then verify(handlerSpy, never()).completeCurrentSpan(); verifyZeroInteractions(lastChunkChannelFutureMock); } }
@Test public void endDtrace_completes_the_trace_immediately_if_state_is_not_null_but_isResponseSendingLastChunkSent_returns_false() { // given assertThat(state.isTraceCompletedOrScheduled(), is(false)); state.setResponseWriterFinalChunkChannelFuture(null); assertThat(state.isResponseSendingLastChunkSent(), is(false)); assertThat(state.getDistributedTraceStack(), nullValue()); Pair<Deque<Span>, Map<String, String>> expectedDtraceInfo = setupStateWithNewSpan("blahTrace"); assertThat(state.getDistributedTraceStack(), notNullValue()); assertThat(state.getDistributedTraceStack(), is(expectedDtraceInfo.getLeft())); assertThat(state.getDistributedTraceStack().size(), is(1)); assertThat(state.isTracingResponseTaggingAndFinalSpanNameCompleted(), is(false)); Span expectedSpan = expectedDtraceInfo.getLeft().peek(); // when handlerSpy.endDtrace(ctxMock); // then verify(handlerSpy).completeCurrentSpan(); assertThat(currentSpanWhenCompleteCurrentSpanWasCalled, is(expectedSpan)); assertThat(currentSpanAfterCompleteCurrentSpanWasCalled, nullValue()); assertThat(state.isTraceCompletedOrScheduled(), is(true)); assertThat(state.isTracingResponseTaggingAndFinalSpanNameCompleted(), is(true)); }
handlerSpy.endDtrace(ctxMock);