@Override public String toString() { return toJson(); }
public MilliSpan build() { return new MilliSpan(this); } }
@Override public synchronized long getAccumulatedMillis() { if (begin == 0) return 0; if (end > 0) return end - begin; return currentTimeMillis() - begin; }
@Test public void testWriteToLocalFile() throws IOException { String traceFileName = LocalFileSpanReceiver.getUniqueLocalTraceFileName(); Tracer tracer = new Tracer.Builder(). name("testWriteToLocalFileTracer"). tracerPool(new TracerPool("testWriteToLocalFile")). conf(HTraceConfiguration.fromKeyValuePairs( "sampler.classes", "AlwaysSampler", "span.receiver.classes", LocalFileSpanReceiver.class.getName(), "local.file.span.receiver.path", traceFileName, "tracer.id", "%{tname}")). build(); TraceScope scope = tracer.newScope("testWriteToLocalFile"); scope.close(); tracer.close(); ObjectMapper mapper = new ObjectMapper(); MilliSpan span = mapper.readValue(new File(traceFileName), MilliSpan.class); assertEquals("testWriteToLocalFile", span.getDescription()); assertEquals("testWriteToLocalFileTracer", span.getTracerId()); } }
@Test public void testJsonSerializationWithRandomLongValue() throws Exception { SpanId parentId = SpanId.fromRandom(); MilliSpan span = new MilliSpan.Builder(). description("foospan"). begin(ThreadLocalRandom.current().nextLong()). end(ThreadLocalRandom.current().nextLong()). parents(new SpanId[] { parentId }). tracerId("b2404.halxg.com:8080"). spanId(parentId.newChildId()). build(); String json = span.toJson(); MilliSpan dspan = MilliSpan.fromJson(json); compareSpans(span, dspan); }
@Test public void testJsonSerializationWithOptionalFields() throws Exception { MilliSpan.Builder builder = new MilliSpan.Builder(). description("foospan"). begin(300). end(400). parents(new SpanId[] { }). tracerId("b2408.halxg.com:8080"). spanId(new SpanId(111111111L, 111111111L)); Map<String, String> traceInfo = new HashMap<String, String>(); traceInfo.put("abc", "123"); traceInfo.put("def", "456"); builder.traceInfo(traceInfo); List<TimelineAnnotation> timeline = new LinkedList<TimelineAnnotation>(); timeline.add(new TimelineAnnotation(310L, "something happened")); timeline.add(new TimelineAnnotation(380L, "something else happened")); timeline.add(new TimelineAnnotation(390L, "more things")); builder.timeline(timeline); MilliSpan span = builder.build(); String json = span.toJson(); MilliSpan dspan = MilliSpan.fromJson(json); compareSpans(span, dspan); }
@Override public String toString() { return toJson(); }
@Override public synchronized long getAccumulatedMillis() { if (begin == 0) return 0; if (end > 0) return end - begin; return currentTimeMillis() - begin; }
public MilliSpan build() { return new MilliSpan(this); } }
@Test public void testJsonSerialization() throws Exception { MilliSpan span = new MilliSpan.Builder(). description("foospan"). begin(123L). end(456L). parents(new SpanId[] { new SpanId(7L, 7L) }). tracerId("b2404.halxg.com:8080"). spanId(new SpanId(7L, 8L)). build(); String json = span.toJson(); MilliSpan dspan = MilliSpan.fromJson(json); compareSpans(span, dspan); }
@Override public String toString() { return toJson(); }
@Override public synchronized long getAccumulatedMillis() { if (begin == 0) return 0; if (end > 0) return end - begin; return currentTimeMillis() - begin; }
public MilliSpan build() { return new MilliSpan(this); } }
@Test public void testJsonSerializationWithNegativeLongValue() throws Exception { MilliSpan span = new MilliSpan.Builder(). description("foospan"). begin(-1L). end(-1L). parents(new SpanId[] { new SpanId(-1L, -1L) }). tracerId("b2404.halxg.com:8080"). spanId(new SpanId(-1L, -2L)). build(); String json = span.toJson(); MilliSpan dspan = MilliSpan.fromJson(json); compareSpans(span, dspan); }