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

The following examples show how to use io.grpc.ClientStreamTracer#inboundMessage() . 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: 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 2
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);
}