@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); }
@Test public void testGetThreadDuration() { when(mockServerSpanState.getServerSpanThreadDuration()).thenReturn(DURATION_MS); assertEquals(DURATION_MS, serverTracer.getThreadDuration()); verify(mockServerSpanState).getServerSpanThreadDuration(); verifyNoMoreInteractions(mockServerSpanState, mockSpanCollector); }
@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); }