ZipkinSpanConvertor { public static Span span(zipkin.Span zipkinSpan) { zipkinSpan = ApplyTimestampAndDuration.apply(zipkinSpan); Span span = new Span(binaryAnnotations(zipkinSpan.binaryAnnotations), annotations(zipkinSpan.annotations)); span.setId(parseSpanId(zipkinSpan.id)); span.setTraceId(parseSpanId(zipkinSpan.traceId)); span.setParentId(zipkinSpan.parentId == null ? null : parseSpanId(zipkinSpan.parentId)); span.setName(zipkinSpan.name); span.setDebug(zipkinSpan.debug); span.setTimestamp(zipkinSpan.timestamp); span.setDuration(zipkinSpan.duration == null ? 0 : zipkinSpan.duration); return span; } private  ZipkinSpanConvertor(); static Span span(zipkin.Span zipkinSpan); static Endpoint endpoint(zipkin.Endpoint zipkinEndpoint); static Annotation annotation(zipkin.Annotation zipkinAnnotation); static BinaryAnnotation binaryAnnotation(zipkin.BinaryAnnotation zipkinBinaryAnnotation); static AnnotationType annotationType(zipkin.BinaryAnnotation.Type zipkinType); static List<Annotation> annotations(List<zipkin.Annotation> zipkinAnnotations); static List<BinaryAnnotation> binaryAnnotations(List<zipkin.BinaryAnnotation> zipkinBinAnnotations); static List<Span> spans(List<zipkin.Span> zipkinSpans); static String parseSpanId(long id);  }
@Test public void testConvertSpan() { zipkin.Span zipkinSpan = zipkin.Span.builder() .name("get") .id(1) .traceId(1) .parentId(null) .debug(false) .timestamp(2L) .duration(2L) .addAnnotation(zipkin.Annotation.builder() .timestamp(1) .value("cs") .build()) .addBinaryAnnotation(zipkin.BinaryAnnotation.builder() .key("key") .value("value") .build()) .build(); Span span = ZipkinSpanConvertor.span(zipkinSpan); Assert.assertEquals("get", span.getName()); Assert.assertEquals("0000000000000001", span.getId()); Assert.assertEquals("0000000000000001", span.getTraceId()); Assert.assertNull(span.getParentId()); Assert.assertEquals(false, span.getDebug()); Assert.assertEquals(new Long(2), span.getTimestamp()); Assert.assertEquals(new Long(2), span.getDuration()); Assert.assertEquals(1, span.getAnnotations().size()); Assert.assertEquals(1, span.getBinaryAnnotations().size()); Annotation annotation = span.getAnnotations().get(0); Assert.assertEquals("cs", annotation.getValue()); Assert.assertEquals(1, annotation.getTimestamp()); BinaryAnnotation binaryAnnotation = span.getBinaryAnnotations().get(0); Assert.assertEquals("key", binaryAnnotation.getKey()); Assert.assertEquals("value", binaryAnnotation.getValue()); }
@Test public void testConvertSpanDefaultTimestampAndDuration() { zipkin.Span zipkinSpan = zipkin.Span.builder() .id(1) .traceId(1) .name("get") .build(); Span span = ZipkinSpanConvertor.span(zipkinSpan); Assert.assertEquals(null, span.getTimestamp()); Assert.assertEquals(new Long(0), span.getDuration()); }