コード例 #1
0
  @Test
  public void testSetServerSendInCaseOfThreadDuration() throws UnsupportedEncodingException {
    when(mockServerSpan.getSpan()).thenReturn(mockSpan);
    when(mockServerSpanState.getCurrentServerSpan()).thenReturn(mockServerSpan);
    when(mockServerSpanState.getServerSpanThreadDuration()).thenReturn(DURATION_MS);
    when(mockServerSpanState.getServerEndPoint()).thenReturn(mockEndPoint);
    serverTracer.setServerSend();
    verify(mockServerSpanState, times(3)).getCurrentServerSpan();
    verify(mockServerSpanState, times(2)).getServerEndPoint();

    final Annotation expectedServerSendAnnotation = new Annotation();
    expectedServerSendAnnotation.setHost(mockEndPoint);
    expectedServerSendAnnotation.setValue(zipkinCoreConstants.SERVER_SEND);
    expectedServerSendAnnotation.setTimestamp(CURRENT_TIME_MICROSECONDS);

    final BinaryAnnotation expectedThreadDurationAnnotation = new BinaryAnnotation();
    expectedThreadDurationAnnotation.setAnnotation_type(AnnotationType.STRING);
    expectedThreadDurationAnnotation.setHost(mockEndPoint);
    expectedThreadDurationAnnotation.setKey(BraveAnnotations.THREAD_DURATION);
    final ByteBuffer bb = ByteBuffer.wrap(String.valueOf(DURATION_MS).getBytes("UTF-8"));
    expectedThreadDurationAnnotation.setValue(bb);

    verify(mockSpan).addToAnnotations(expectedServerSendAnnotation);
    verify(mockSpan).addToBinary_annotations(expectedThreadDurationAnnotation);

    verify(mockServerSpanState).getServerSpanThreadDuration();
    verify(mockSpanCollector).collect(mockSpan);
    verify(mockServerSpanState).setCurrentServerSpan(null);
    verifyNoMoreInteractions(mockServerSpanState, mockSpanCollector, mockSpan);
  }
コード例 #2
0
 /**
  * Set start time of Span in milliseconds
  *
  * @param start Start of Span in milliseconds
  * @return this
  */
 public ZipkinSpanBuilder startTimeMs(long start) {
   Annotation annotation = new Annotation();
   // Zipkin uses microseconds
   annotation.setTimestamp(start * 1000);
   annotation.setValue(zipkinCoreConstants.CLIENT_SEND);
   annotation.setHost(endPoint);
   zipkinSpan.addToAnnotations(annotation);
   return this;
 }
コード例 #3
0
  @Test
  public void testSetServerReceived() {
    when(mockServerSpan.getSpan()).thenReturn(mockSpan);
    when(mockServerSpanState.getCurrentServerSpan()).thenReturn(mockServerSpan);
    when(mockServerSpanState.getServerEndPoint()).thenReturn(mockEndPoint);
    serverTracer.setServerReceived();

    final Annotation expectedAnnotation = new Annotation();
    expectedAnnotation.setHost(mockEndPoint);
    expectedAnnotation.setValue(zipkinCoreConstants.SERVER_RECV);
    expectedAnnotation.setTimestamp(CURRENT_TIME_MICROSECONDS);

    verify(mockServerSpanState).getCurrentServerSpan();
    verify(mockServerSpanState).getServerEndPoint();
    verify(mockSpan).addToAnnotations(expectedAnnotation);

    verifyNoMoreInteractions(mockServerSpanState, mockSpan, mockSpanCollector);
  }