protected boolean shouldLinkAndUnlinkDistributedTraceInfoForMethod( HandlerMethodToExecute methodToExecute, boolean isDefaultMethodImpl, boolean forceEnableDTraceOnAllMethods, boolean debugHandlerMethodCalls, ChannelHandlerContext ctx, Object msgOrEvt, Throwable cause ) { return (!isDefaultMethodImpl && argsAreEligibleForLinkingAndUnlinkingDistributedTracingInfo(methodToExecute, ctx, msgOrEvt, cause) ) || forceEnableDTraceOnAllMethods || debugHandlerMethodCalls; }
@Override public void channelUnregistered(ChannelHandlerContext ctx) throws Exception { PipelineContinuationBehavior methodExecutionResponse; boolean shouldLinkAndUnlinkDTraceInfo = shouldLinkAndUnlinkDistributedTraceInfoForMethod( DO_CHANNEL_UNREGISTERED, isDefaultDoChannelUnregisteredImpl, forceEnableDTraceOnAllMethods, debugHandlerMethodCalls, ctx, null, null ); Pair<Deque<Span>, Map<String, String>> origThreadInfo = null; try { if (shouldLinkAndUnlinkDTraceInfo) origThreadInfo = linkTracingAndMdcToCurrentThread(ctx); if (debugHandlerMethodCalls) logger.debug("222222222222222 channelUnregistered for {}", this.getClass().getName()); methodExecutionResponse = doChannelUnregistered(ctx); } finally { if (shouldLinkAndUnlinkDTraceInfo) unlinkTracingAndMdcFromCurrentThread(ctx, origThreadInfo); } if (methodExecutionResponse == null || CONTINUE.equals(methodExecutionResponse)) super.channelUnregistered(ctx); }
@Override public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception { PipelineContinuationBehavior methodExecutionResponse; boolean shouldLinkAndUnlinkDTraceInfo = shouldLinkAndUnlinkDistributedTraceInfoForMethod( DO_CHANNEL_WRITABILITY_CHANGED, isDefaultDoChannelWritabilityChangedImpl, forceEnableDTraceOnAllMethods, debugHandlerMethodCalls, ctx, null, null ); Pair<Deque<Span>, Map<String, String>> origThreadInfo = null; try { if (shouldLinkAndUnlinkDTraceInfo) origThreadInfo = linkTracingAndMdcToCurrentThread(ctx); if (debugHandlerMethodCalls) logger.debug("^^^^^^^^^^^^^^^ channelWritabilityChanged for {}", this.getClass().getName()); methodExecutionResponse = doChannelWritabilityChanged(ctx); } finally { if (shouldLinkAndUnlinkDTraceInfo) unlinkTracingAndMdcFromCurrentThread(ctx, origThreadInfo); } if (methodExecutionResponse == null || CONTINUE.equals(methodExecutionResponse)) super.channelWritabilityChanged(ctx); }
@Override public void handlerAdded(ChannelHandlerContext ctx) throws Exception { PipelineContinuationBehavior methodExecutionResponse; boolean shouldLinkAndUnlinkDTraceInfo = shouldLinkAndUnlinkDistributedTraceInfoForMethod( DO_HANDLER_ADDED, isDefaultDoHandlerAddedImpl, forceEnableDTraceOnAllMethods, debugHandlerMethodCalls, ctx, null, null ); Pair<Deque<Span>, Map<String, String>> origThreadInfo = null; try { if (shouldLinkAndUnlinkDTraceInfo) origThreadInfo = linkTracingAndMdcToCurrentThread(ctx); if (debugHandlerMethodCalls) logger.debug("(((((((((((((( handlerAdded for {}", this.getClass().getName()); methodExecutionResponse = doHandlerAdded(ctx); } finally { if (shouldLinkAndUnlinkDTraceInfo) unlinkTracingAndMdcFromCurrentThread(ctx, origThreadInfo); } if (methodExecutionResponse == null || CONTINUE.equals(methodExecutionResponse)) super.handlerAdded(ctx); }
@Test public void channelActive_should_perform_as_expected() throws Exception { verifyMethodBehavior("channelActive", ctxMock); }
private void verifyMethodBehaviorDetails( String methodName, Object[] methodArgs, PipelineContinuationBehavior doMethodReturnValue, boolean shouldExplodeInDoMethod ) throws InvocationTargetException, IllegalAccessException { // Verify all the various sub-combinations that could affect behavior in this case. // Check with debug logging on or off verifyMethodBehaviorDetails(methodName, methodArgs, doMethodReturnValue, true, false, false, true, shouldExplodeInDoMethod); verifyMethodBehaviorDetails(methodName, methodArgs, doMethodReturnValue, true, false, false, false, shouldExplodeInDoMethod); verifyMethodBehaviorDetails(methodName, methodArgs, doMethodReturnValue, false, false, false, true, shouldExplodeInDoMethod); verifyMethodBehaviorDetails(methodName, methodArgs, doMethodReturnValue, false, false, false, false, shouldExplodeInDoMethod); // Check with force-dtrace on or off verifyMethodBehaviorDetails(methodName, methodArgs, doMethodReturnValue, false, true, false, true, shouldExplodeInDoMethod); verifyMethodBehaviorDetails(methodName, methodArgs, doMethodReturnValue, false, true, false, false, shouldExplodeInDoMethod); verifyMethodBehaviorDetails(methodName, methodArgs, doMethodReturnValue, false, false, false, true, shouldExplodeInDoMethod); verifyMethodBehaviorDetails(methodName, methodArgs, doMethodReturnValue, false, false, false, false, shouldExplodeInDoMethod); // Check with isDefaultMethodImpl on or off verifyMethodBehaviorDetails(methodName, methodArgs, doMethodReturnValue, false, false, true, true, shouldExplodeInDoMethod); verifyMethodBehaviorDetails(methodName, methodArgs, doMethodReturnValue, false, false, true, false, shouldExplodeInDoMethod); verifyMethodBehaviorDetails(methodName, methodArgs, doMethodReturnValue, false, false, false, true, shouldExplodeInDoMethod); verifyMethodBehaviorDetails(methodName, methodArgs, doMethodReturnValue, false, false, false, false, shouldExplodeInDoMethod); // Check with argsEligibleForLinkUnlink on or off verifyMethodBehaviorDetails(methodName, methodArgs, doMethodReturnValue, false, false, false, true, shouldExplodeInDoMethod); verifyMethodBehaviorDetails(methodName, methodArgs, doMethodReturnValue, false, false, false, false, shouldExplodeInDoMethod); }
@After public void afterMethod() { resetTracingAndMdc(); }
private HandlerMethodToExecute constructHandlerMethodToExecuteFromMethodName(String methodName) { StringBuilder sb = new StringBuilder(); sb.append("DO_"); for (char c : methodName.toCharArray()) { if (Character.isUpperCase(c)) sb.append("_"); sb.append(Character.toUpperCase(c)); } return HandlerMethodToExecute.valueOf(sb.toString()); }
protected boolean shouldLinkAndUnlinkDistributedTraceInfoForMethod( HandlerMethodToExecute methodToExecute, boolean isDefaultMethodImpl, boolean forceEnableDTraceOnAllMethods, boolean debugHandlerMethodCalls, ChannelHandlerContext ctx, Object msgOrEvt, Throwable cause ) { return (!isDefaultMethodImpl && argsAreEligibleForLinkingAndUnlinkingDistributedTracingInfo(methodToExecute, ctx, msgOrEvt, cause) ) || forceEnableDTraceOnAllMethods || debugHandlerMethodCalls; }
@Test public void channelWritabilityChanged_should_perform_as_expected() throws Exception { verifyMethodBehavior("channelWritabilityChanged", ctxMock); }
@Test public void channelRegistered_should_perform_as_expected() throws Exception { verifyMethodBehavior("channelRegistered", ctxMock); }
@Test public void channelUnregistered_should_perform_as_expected() throws Exception { verifyMethodBehavior("channelUnregistered", ctxMock); }
@Test public void channelReadComplete_should_perform_as_expected() throws Exception { verifyMethodBehavior("channelReadComplete", ctxMock); }
@Test public void handlerAdded_should_perform_as_expected() throws Exception { verifyMethodBehavior("handlerAdded", ctxMock); }
@Test public void handlerRemoved_should_perform_as_expected() throws Exception { verifyMethodBehavior("handlerRemoved", ctxMock); }
@Test public void userEventTriggered_should_perform_as_expected() throws Exception { verifyMethodBehavior("userEventTriggered", ctxMock, null); }
@Test public void channelInactive_should_perform_as_expected() throws Exception { verifyMethodBehavior("channelInactive", ctxMock); }
@Test public void channelRead_should_perform_as_expected() throws Exception { verifyMethodBehavior("channelRead", ctxMock, null); }
@Test public void exceptionCaught_should_perform_as_expected() throws Exception { verifyMethodBehavior("exceptionCaught", ctxMock, null); }