Codota Logo
ChannelPipelineFinalizerHandler.doChannelInactive
Code IndexAdd Codota to your IDE (free)

How to use
doChannelInactive
method
in
com.nike.riposte.server.handler.ChannelPipelineFinalizerHandler

Best Java code snippets using com.nike.riposte.server.handler.ChannelPipelineFinalizerHandler.doChannelInactive (Showing top 14 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
Charset c =
  • Codota IconString charsetName;Charset.forName(charsetName)
  • Codota IconCharset.defaultCharset()
  • Codota IconContentType contentType;contentType.getCharset()
  • Smart code suggestions by Codota
}
origin: Nike-Inc/riposte

  @Test
  public void code_coverage_hoops() throws Exception {
    // jump!

    // doChannelInactive() does some debug logging if the logger has debug logging enabled.
    Logger loggerMock = mock(Logger.class);
    doReturn(true).when(loggerMock).isDebugEnabled();
    Whitebox.setInternalState(handler, "logger", loggerMock);
    handler.doChannelInactive(ctxMock);
    doReturn(false).when(loggerMock).isDebugEnabled();
    handler.doChannelInactive(ctxMock);
  }
}
origin: Nike-Inc/riposte

@Test
public void doChannelInactive_does_not_explode_if_crazy_exception_occurs() throws Exception {
  // given
  doThrow(new RuntimeException("kaboom")).when(proxyRouterProcessingStateAttributeMock).get();
  // when
  PipelineContinuationBehavior result = handler.doChannelInactive(ctxMock);
  // then
  Assertions.assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
origin: Nike-Inc/riposte

@Test
public void doChannelInactive_does_not_explode_if_span_is_missing() throws Exception {
  // given
  Assertions.assertThat(state.getDistributedTraceStack()).isNull();
  // when
  PipelineContinuationBehavior result = handler.doChannelInactive(ctxMock);
  // then
  verify(requestInfoMock).releaseAllResources();
  verify(proxyRouterStateMock).cancelRequestStreaming(any(), any());
  verify(proxyRouterStateMock).cancelDownstreamRequest(any());
  Assertions.assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}

origin: Nike-Inc/riposte

@Test
public void doChannelInactive_does_not_propagate_unexpected_exception_while_handling_access_logging(
) throws Exception {
  // given
  HttpProcessingState stateSpy = spy(state);
  doReturn(stateSpy).when(stateAttributeMock).get();
  doThrow(new RuntimeException("intentional exception"))
    .when(accessLoggerMock).log(any(), any(), any(), any());
  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(accessLoggerMock).log(any(), any(), any(), any());
  // Verify that no other finalization logic was impacted.
  Assertions.assertThat(stateSpy.isTraceCompletedOrScheduled()).isTrue();
  Assertions.assertThat(stateSpy.isRequestMetricsRecordedOrScheduled()).isTrue();
  verify(requestInfoMock).releaseAllResources();
  verify(proxyRouterStateMock).cancelRequestStreaming(any(), any());
  verify(proxyRouterStateMock).cancelDownstreamRequest(any());
  Assertions.assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
origin: Nike-Inc/riposte

@DataProvider(value = {
  "true",
  "false"
})
@Test
public void doChannelInactive_completes_metrics_if_necessary_and_HttpProcessingState_is_not_null(
  boolean stateIsNull
) throws Exception {
  // given
  ChannelPipelineFinalizerHandler handlerSpy = spy(handler);
  if (stateIsNull) {
    doReturn(null).when(stateAttributeMock).get();
  }
  // when
  PipelineContinuationBehavior result = handlerSpy.doChannelInactive(ctxMock);
  // then
  if (stateIsNull) {
    verify(handlerSpy, never()).handleMetricsForCompletedRequestIfNotAlreadyDone(any(HttpProcessingState.class));
  }
  else {
    verify(handlerSpy).handleMetricsForCompletedRequestIfNotAlreadyDone(state);
  }
}
origin: Nike-Inc/riposte

@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);
}
origin: Nike-Inc/riposte

@Test
public void doChannelInactive_does_not_propagate_unexpected_exception_while_handling_tracing_completion(
) throws Exception {
  // given
  HttpProcessingState stateSpy = spy(state);
  doReturn(stateSpy).when(stateAttributeMock).get();
  doThrow(new RuntimeException("intentional exception"))
    .when(stateSpy).handleTracingResponseTaggingAndFinalSpanNameIfNotAlreadyDone();
  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(stateSpy).handleTracingResponseTaggingAndFinalSpanNameIfNotAlreadyDone();
  // Verify that no other finalization logic was impacted.
  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);
}
origin: Nike-Inc/riposte

@Test
public void doChannelInactive_does_not_propagate_unexpected_exception_while_releasing_proxy_router_state_resources(
) throws Exception {
  // given
  HttpProcessingState stateSpy = spy(state);
  doReturn(stateSpy).when(stateAttributeMock).get();
  doThrow(new RuntimeException("intentional exception"))
    .when(proxyRouterStateMock).cancelDownstreamRequest(any());
  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);
}
origin: Nike-Inc/riposte

PipelineContinuationBehavior result = handler.doChannelInactive(ctxMock);
origin: Nike-Inc/riposte

@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
  Assertions.assertThat(span.isCompleted()).isTrue(); // no change
  Assertions.assertThat(span.getDurationNanos()).isEqualTo(durationNanosBefore);
  verify(requestInfoMock).releaseAllResources();
  verify(proxyRouterStateMock).cancelRequestStreaming(any(), any());
  verify(proxyRouterStateMock).cancelDownstreamRequest(any());
  Assertions.assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
origin: Nike-Inc/riposte

@DataProvider(value = {
  "true   |   true",
  "false  |   true",
  "true   |   false",
  "false  |   false"
}, splitBy = "\\|")
@Test
public void doChannelInactive_completes_releases_resources_and_completes_tracing_if_necessary(
  boolean tracingAlreadyDone, boolean responseSendingCompleted
) throws Exception {
  // given
  Span span = setupTracingForChannelInactive(tracingAlreadyDone);
  doReturn(responseSendingCompleted).when(responseInfoMock).isResponseSendingLastChunkSent();
  if (responseSendingCompleted) {
    state.setResponseWriterFinalChunkChannelFuture(mock(ChannelFuture.class));
  }
  // when
  PipelineContinuationBehavior result = handler.doChannelInactive(ctxMock);
  // then
  Assertions.assertThat(span.isCompleted()).isEqualTo(!tracingAlreadyDone);
  Assertions.assertThat(state.isTraceCompletedOrScheduled()).isTrue();
  verify(requestInfoMock).releaseAllResources();
  verify(proxyRouterStateMock).cancelRequestStreaming(any(), any());
  verify(proxyRouterStateMock).cancelDownstreamRequest(any());
  Assertions.assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
origin: Nike-Inc/riposte

@DataProvider(value = {
  "true   |   false",
  "false  |   true"
}, splitBy = "\\|")
@Test
public void doChannelInactive_should_not_call_accessLogger_if_accessLogger_is_null_or_access_logging_already_scheduled(
  boolean accessLoggerIsNull, boolean accessLoggingAlreadyScheduled
) throws Exception {
  // given
  if (accessLoggerIsNull)
    Whitebox.setInternalState(handler, "accessLogger", null);
  state.setAccessLogCompletedOrScheduled(accessLoggingAlreadyScheduled);
  // when
  handler.doChannelInactive(ctxMock);
  // then
  verifyZeroInteractions(accessLoggerMock);
  Assertions.assertThat(state.isAccessLogCompletedOrScheduled()).isEqualTo(accessLoggingAlreadyScheduled);
}
origin: Nike-Inc/riposte

handler.doChannelInactive(ctxMock);
origin: Nike-Inc/riposte

@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, 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).cancelRequestStreaming(any(), any());
  verify(proxyRouterStateMock).cancelDownstreamRequest(any());
  Assertions.assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
com.nike.riposte.server.handlerChannelPipelineFinalizerHandlerdoChannelInactive

Javadoc

This method is used as the final cleanup safety net for when a channel is closed. It guarantees that any ByteBufs being held by RequestInfo or ProxyRouterProcessingState are ByteBuf#release()d so that we don't end up with a memory leak.

Note that we can't use ChannelOutboundHandler#close(ChannelHandlerContext,ChannelPromise) for this purpose as it is only called if we close the connection in our application code. It won't be triggered if (for example) the caller closes the connection, and we need it to *always* run for *every* closed connection, no matter the source of the close. ChannelInboundHandler#channelInactive(ChannelHandlerContext) is always called, so we're using that.

Popular methods of ChannelPipelineFinalizerHandler

  • <init>
  • finalizeChannelPipeline
    This will first check the given state to see if a response was sent to the user. If not then this me
  • getStateAndCreateIfNeeded
    Returns the given context's channel's state. We expect the state to exist, so if it doesn't this met
  • handleMetricsForCompletedRequestIfNotAlreadyDone
  • logErrorWithTracing
  • releaseProxyRouterStateResources
    Tell the ProxyRouterProcessingState that the request streaming is cancelled so that it will trigger
  • argsAreEligibleForLinkingAndUnlinkingDistributedTracingInfo
  • doChannelRead
  • doExceptionCaught

Popular in Java

  • Running tasks concurrently on multiple threads
  • onCreateOptionsMenu (Activity)
  • getResourceAsStream (ClassLoader)
    Returns a stream for the resource with the specified name. See #getResource(String) for a descriptio
  • getExternalFilesDir (Context)
  • BorderLayout (java.awt)
    A border layout lays out a container, arranging and resizing its components to fit in five regions:
  • Color (java.awt)
    The Color class is used encapsulate colors in the default sRGB color space or colors in arbitrary co
  • FileOutputStream (java.io)
    A file output stream is an output stream for writing data to aFile or to a FileDescriptor. Whether
  • IOException (java.io)
    Signals that an I/O exception of some sort has occurred. This class is the general class of exceptio
  • Thread (java.lang)
    A thread is a thread of execution in a program. The Java Virtual Machine allows an application to ha
  • Project (org.apache.tools.ant)
    Central representation of an Ant project. This class defines an Ant project with all of its targets,
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now