diff --git a/src/test/java/com/datadoghq/trace/impl/SpanBuilderTest.java b/src/test/java/com/datadoghq/trace/impl/SpanBuilderTest.java new file mode 100644 index 0000000000..d60f5b7d4e --- /dev/null +++ b/src/test/java/com/datadoghq/trace/impl/SpanBuilderTest.java @@ -0,0 +1,97 @@ +package com.datadoghq.trace.impl; + +import org.assertj.core.data.MapEntry; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import static org.assertj.core.api.Assertions.*; + +public class SpanBuilderTest { + + Tracer tracer; + + @Before + public void setUp() throws Exception { + tracer = new Tracer(); + } + + + @After + public void tearDown() throws Exception { + } + + + @Test + public void shouldBuilSimpleSpan() { + + final String expectedName = "fakeName"; + Span span = (Span) tracer.buildSpan(expectedName).start(); + assertThat(span.getOperationName()).isEqualTo(expectedName); + } + + @Test + public void shouldBuildTaggedSpan() { + + final String expectedName = "fakeName"; + final Map tags = new HashMap() { + { + put("1", true); + put("2", "fakeString"); + put("3", 42.0); + } + }; + + Span span = (Span) tracer + .buildSpan(expectedName) + .withTag("1", (Boolean) tags.get("1")) + .withTag("2", (String) tags.get("2")) + .withTag("3", (Number) tags.get("3")) + .start(); + + assertThat(span.getOperationName()).isEqualTo(expectedName); + assertThat(span.getTags()).containsAllEntriesOf(tags); + + // with no tag provided + + span = (Span) tracer + .buildSpan(expectedName) + .start(); + + assertThat(span.getTags()).isNotNull(); + assertThat(span.getTags()).isEmpty(); + + + } + + @Test + public void shouldBuilSpanTimestampInNano() { + + final long expectedTimestamp = 487517802L * 1000 * 1000; + final String expectedName = "fakeName"; + + Span span = (Span) tracer + .buildSpan(expectedName) + .withStartTimestamp(expectedTimestamp) + .start(); + + assertThat(span.getStartTime()).isEqualTo(expectedTimestamp); + + // auto-timestamp in nanoseconds + long tick = System.nanoTime(); + span = (Span) tracer + .buildSpan(expectedName) + .start(); + + // between now and now + 100ms + assertThat(span.getStartTime()).isBetween(tick, tick * 1000 * 100); + + } + + +} \ No newline at end of file diff --git a/src/test/java/com/datadoghq/trace/impl/SpanTest.java b/src/test/java/com/datadoghq/trace/impl/SpanTest.java new file mode 100644 index 0000000000..1878b690ab --- /dev/null +++ b/src/test/java/com/datadoghq/trace/impl/SpanTest.java @@ -0,0 +1,8 @@ +package com.datadoghq.trace.impl; + +import static org.junit.Assert.*; + + +public class SpanTest { + +} \ No newline at end of file diff --git a/src/test/java/com/datadoghq/trace/impl/TracerTest.java b/src/test/java/com/datadoghq/trace/impl/TracerTest.java new file mode 100644 index 0000000000..b571ee2fca --- /dev/null +++ b/src/test/java/com/datadoghq/trace/impl/TracerTest.java @@ -0,0 +1,19 @@ +package com.datadoghq.trace.impl; + + +import org.junit.Test; + +class TracerTest { + @Test + void buildSpan() { + } + + @Test + void inject() { + } + + @Test + void extract() { + } + +} \ No newline at end of file