Ejemplo n.º 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);
  }
Ejemplo n.º 2
0
  @Test
  public void testSubmitBinaryAnnotationInt() {
    when(mockServerSpan.getSpan()).thenReturn(mockSpan);
    when(mockServerSpanState.getCurrentServerSpan()).thenReturn(mockServerSpan);
    when(mockServerSpanState.getEndPoint()).thenReturn(mockEndPoint);
    serverTracer.submitBinaryAnnotation(KEY, INT_VALUE);
    verify(mockServerSpanState).getCurrentServerSpan();
    verify(mockServerSpanState).getEndPoint();

    verify(mockAnnotationSubmitter).submitBinaryAnnotation(mockSpan, mockEndPoint, KEY, INT_VALUE);
    verifyNoMoreInteractions(mockServerSpanState, mockSpanCollector, mockAnnotationSubmitter);
  }
Ejemplo n.º 3
0
  @Test
  public void testSubmitAnnotationString() {
    when(mockServerSpan.getSpan()).thenReturn(mockSpan);
    when(mockServerSpanState.getCurrentServerSpan()).thenReturn(mockServerSpan);
    when(mockServerSpanState.getEndPoint()).thenReturn(mockEndPoint);
    serverTracer.submitAnnotation(ANNOTATION_NAME);
    verify(mockServerSpanState).getCurrentServerSpan();
    verify(mockServerSpanState).getEndPoint();

    verify(mockAnnotationSubmitter).submitAnnotation(mockSpan, mockEndPoint, ANNOTATION_NAME);
    verifyNoMoreInteractions(mockServerSpanState, mockSpanCollector, mockAnnotationSubmitter);
  }
Ejemplo n.º 4
0
  @Test
  public void testSetServerReceived() {
    when(mockServerSpan.getSpan()).thenReturn(mockSpan);
    when(mockServerSpanState.getCurrentServerSpan()).thenReturn(mockServerSpan);
    when(mockServerSpanState.getEndPoint()).thenReturn(mockEndPoint);
    serverTracer.setServerReceived();
    verify(mockServerSpanState).getCurrentServerSpan();
    verify(mockServerSpanState).getEndPoint();

    verify(mockAnnotationSubmitter)
        .submitAnnotation(mockSpan, mockEndPoint, zipkinCoreConstants.SERVER_RECV);

    verifyNoMoreInteractions(mockServerSpanState, mockSpanCollector, mockAnnotationSubmitter);
  }
Ejemplo n.º 5
0
  @Test
  public void testGetThreadDuration() {
    when(mockServerSpanState.getServerSpanThreadDuration()).thenReturn(DURATION_MS);
    assertEquals(DURATION_MS, serverTracer.getThreadDuration());

    verify(mockServerSpanState).getServerSpanThreadDuration();
    verifyNoMoreInteractions(mockServerSpanState, mockSpanCollector);
  }
Ejemplo n.º 6
0
 @Test
 public void testSubmitAnnotationWithStartEndDateNoServerSpan() {
   when(mockServerSpanState.getCurrentServerSpan()).thenReturn(mockServerSpan);
   when(mockServerSpan.getSpan()).thenReturn(null);
   serverTracer.submitAnnotation(ANNOTATION_NAME, START_DATE, END_DATE);
   verify(mockServerSpanState).getCurrentServerSpan();
   verifyNoMoreInteractions(mockServerSpanState, mockSpanCollector, mockAnnotationSubmitter);
 }
Ejemplo n.º 7
0
  @Test
  public void testSetServerSendShouldNoServerSpan() {

    when(mockServerSpanState.getCurrentServerSpan()).thenReturn(mockServerSpan);
    when(mockServerSpan.getSpan()).thenReturn(null);
    serverTracer.setServerSend();
    verify(mockServerSpanState).getCurrentServerSpan();
    verifyNoMoreInteractions(mockServerSpanState, mockSpanCollector, mockSpan);
  }
Ejemplo n.º 8
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);
  }
Ejemplo n.º 9
0
  @Test
  public void testSetServerReceivedNoServerSpan() {

    when(mockServerSpanState.getCurrentServerSpan()).thenReturn(mockServerSpan);
    when(mockServerSpan.getSpan()).thenReturn(null);
    serverTracer.setServerReceived();
    verify(mockServerSpanState).getCurrentServerSpan();
    verifyNoMoreInteractions(mockServerSpanState, mockSpanCollector, mockAnnotationSubmitter);
  }
Ejemplo n.º 10
0
  @Test
  public void testSetServerSendInCaseOfThreadDuration() {
    when(mockServerSpan.getSpan()).thenReturn(mockSpan);
    when(mockServerSpanState.getCurrentServerSpan()).thenReturn(mockServerSpan);
    when(mockServerSpanState.getServerSpanThreadDuration()).thenReturn(DURATION_MS);
    when(mockServerSpanState.getEndPoint()).thenReturn(mockEndPoint);
    serverTracer.setServerSend();
    verify(mockServerSpanState).getCurrentServerSpan();
    verify(mockServerSpanState, times(2)).getEndPoint();

    verify(mockAnnotationSubmitter)
        .submitAnnotation(mockSpan, mockEndPoint, zipkinCoreConstants.SERVER_SEND);
    verify(mockAnnotationSubmitter)
        .submitBinaryAnnotation(
            mockSpan, mockEndPoint, BraveAnnotations.THREAD_DURATION, String.valueOf(DURATION_MS));
    verify(mockServerSpanState).getServerSpanThreadDuration();
    verify(mockSpanCollector).collect(mockSpan);
    verify(mockServerSpanState).setCurrentServerSpan(null);
    verifyNoMoreInteractions(mockServerSpanState, mockSpanCollector, mockAnnotationSubmitter);
  }