Java Code Examples for io.grpc.ClientStreamTracer#streamClosed()

The following examples show how to use io.grpc.ClientStreamTracer#streamClosed() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClientLoadCounterTest.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
@Test
public void loadRecordingStreamTracerFactory_clientSideQueryCountsAggregation() {
  LoadRecordingStreamTracerFactory factory1 =
      new LoadRecordingStreamTracerFactory(counter, NOOP_CLIENT_STREAM_TRACER_FACTORY);
  ClientStreamTracer tracer = factory1.newClientStreamTracer(STREAM_INFO, new Metadata());
  ClientLoadSnapshot snapshot = counter.snapshot();
  assertQueryCounts(snapshot, 0, 1, 0, 1);
  tracer.streamClosed(Status.OK);
  snapshot = counter.snapshot();
  assertQueryCounts(snapshot, 1, 0, 0, 0);

  // Create a second LoadRecordingStreamTracerFactory with the same counter, stats are aggregated
  // together.
  LoadRecordingStreamTracerFactory factory2 =
      new LoadRecordingStreamTracerFactory(counter, NOOP_CLIENT_STREAM_TRACER_FACTORY);
  factory1.newClientStreamTracer(STREAM_INFO, new Metadata()).streamClosed(Status.ABORTED);
  factory2.newClientStreamTracer(STREAM_INFO, new Metadata()).streamClosed(Status.CANCELLED);
  snapshot = counter.snapshot();
  assertQueryCounts(snapshot, 0, 0, 2, 2);
}
 
Example 2
Source File: CensusModulesTest.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
@Test
public void clientBasicTracingDefaultSpan() {
  CensusTracingModule.ClientCallTracer callTracer =
      censusTracing.newClientCallTracer(null, method);
  Metadata headers = new Metadata();
  ClientStreamTracer clientStreamTracer =
      callTracer.newClientStreamTracer(CallOptions.DEFAULT, headers);
  verify(tracer).spanBuilderWithExplicitParent(
      eq("Sent.package1.service2.method3"), isNull(Span.class));
  verify(spyClientSpan, never()).end(any(EndSpanOptions.class));

  clientStreamTracer.outboundMessage(0);
  clientStreamTracer.outboundMessageSent(0, 882, -1);
  clientStreamTracer.inboundMessage(0);
  clientStreamTracer.outboundMessage(1);
  clientStreamTracer.outboundMessageSent(1, -1, 27);
  clientStreamTracer.inboundMessageRead(0, 255, 90);

  clientStreamTracer.streamClosed(Status.OK);
  callTracer.callEnded(Status.OK);

  InOrder inOrder = inOrder(spyClientSpan);
  inOrder.verify(spyClientSpan, times(3)).addMessageEvent(messageEventCaptor.capture());
  List<MessageEvent> events = messageEventCaptor.getAllValues();
  assertEquals(
      MessageEvent.builder(Type.SENT, 0).setCompressedMessageSize(882).build(), events.get(0));
  assertEquals(
      MessageEvent.builder(Type.SENT, 1).setUncompressedMessageSize(27).build(), events.get(1));
  assertEquals(
      MessageEvent.builder(Type.RECEIVED, 0)
          .setCompressedMessageSize(255)
          .setUncompressedMessageSize(90)
          .build(),
      events.get(2));
  inOrder.verify(spyClientSpan).end(
      EndSpanOptions.builder()
          .setStatus(io.opencensus.trace.Status.OK)
          .setSampleToLocalSpanStore(false)
          .build());
  verifyNoMoreInteractions(spyClientSpan);
  verifyNoMoreInteractions(tracer);
}
 
Example 3
Source File: CensusModulesTest.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@Test
public void clientBasicTracingDefaultSpan() {
  CensusTracingModule.ClientCallTracer callTracer =
      censusTracing.newClientCallTracer(null, method);
  Metadata headers = new Metadata();
  ClientStreamTracer clientStreamTracer = callTracer.newClientStreamTracer(STREAM_INFO, headers);
  verify(tracer).spanBuilderWithExplicitParent(
      eq("Sent.package1.service2.method3"), ArgumentMatchers.<Span>isNull());
  verify(spyClientSpan, never()).end(any(EndSpanOptions.class));

  clientStreamTracer.outboundMessage(0);
  clientStreamTracer.outboundMessageSent(0, 882, -1);
  clientStreamTracer.inboundMessage(0);
  clientStreamTracer.outboundMessage(1);
  clientStreamTracer.outboundMessageSent(1, -1, 27);
  clientStreamTracer.inboundMessageRead(0, 255, 90);

  clientStreamTracer.streamClosed(Status.OK);
  callTracer.callEnded(Status.OK);

  InOrder inOrder = inOrder(spyClientSpan);
  inOrder.verify(spyClientSpan, times(3)).addMessageEvent(messageEventCaptor.capture());
  List<MessageEvent> events = messageEventCaptor.getAllValues();
  assertEquals(
      MessageEvent.builder(Type.SENT, 0).setCompressedMessageSize(882).build(), events.get(0));
  assertEquals(
      MessageEvent.builder(Type.SENT, 1).setUncompressedMessageSize(27).build(), events.get(1));
  assertEquals(
      MessageEvent.builder(Type.RECEIVED, 0)
          .setCompressedMessageSize(255)
          .setUncompressedMessageSize(90)
          .build(),
      events.get(2));
  inOrder.verify(spyClientSpan).end(
      EndSpanOptions.builder()
          .setStatus(io.opencensus.trace.Status.OK)
          .setSampleToLocalSpanStore(false)
          .build());
  verifyNoMoreInteractions(spyClientSpan);
  verifyNoMoreInteractions(tracer);
}