From 84e22d04158661e5fda442abba7ce72d826bd0a8 Mon Sep 17 00:00:00 2001
From: Pavol Loffay
Date: Thu, 14 Dec 2017 11:32:45 -0600
Subject: [PATCH] MockTracer use text map propag in the default constructor
(#179)
---
.../java/io/opentracing/mock/MockTracer.java | 20 ++++++-------
.../io/opentracing/mock/MockTracerTest.java | 28 +++++++++++++++----
2 files changed, 32 insertions(+), 16 deletions(-)
diff --git a/opentracing-mock/src/main/java/io/opentracing/mock/MockTracer.java b/opentracing-mock/src/main/java/io/opentracing/mock/MockTracer.java
index e6af3df4..50024ab9 100644
--- a/opentracing-mock/src/main/java/io/opentracing/mock/MockTracer.java
+++ b/opentracing-mock/src/main/java/io/opentracing/mock/MockTracer.java
@@ -13,23 +13,23 @@
*/
package io.opentracing.mock;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import io.opentracing.ActiveSpan;
import io.opentracing.ActiveSpanSource;
import io.opentracing.BaseSpan;
-import io.opentracing.noop.NoopActiveSpanSource;
import io.opentracing.References;
import io.opentracing.Span;
import io.opentracing.SpanContext;
import io.opentracing.Tracer;
+import io.opentracing.noop.NoopActiveSpanSource;
import io.opentracing.propagation.Format;
import io.opentracing.propagation.TextMap;
import io.opentracing.util.ThreadLocalActiveSpanSource;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
/**
* MockTracer makes it easy to test the semantics of OpenTracing instrumentation.
*
@@ -39,16 +39,16 @@
* The MockTracerTest has simple usage examples.
*/
public class MockTracer implements Tracer {
- private List finishedSpans = new ArrayList<>();
+ private final List finishedSpans = new ArrayList<>();
private final Propagator propagator;
- private ActiveSpanSource spanSource;
+ private final ActiveSpanSource spanSource;
public MockTracer() {
- this(new ThreadLocalActiveSpanSource(), Propagator.PRINTER);
+ this(new ThreadLocalActiveSpanSource(), Propagator.TEXT_MAP);
}
public MockTracer(ActiveSpanSource spanSource) {
- this(spanSource, Propagator.PRINTER);
+ this(spanSource, Propagator.TEXT_MAP);
}
public MockTracer(ActiveSpanSource spanSource, Propagator propagator) {
diff --git a/opentracing-mock/src/test/java/io/opentracing/mock/MockTracerTest.java b/opentracing-mock/src/test/java/io/opentracing/mock/MockTracerTest.java
index b7960106..e4d8749f 100644
--- a/opentracing-mock/src/test/java/io/opentracing/mock/MockTracerTest.java
+++ b/opentracing-mock/src/test/java/io/opentracing/mock/MockTracerTest.java
@@ -14,20 +14,24 @@
package io.opentracing.mock;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import io.opentracing.References;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import io.opentracing.ActiveSpan;
import io.opentracing.Span;
import io.opentracing.SpanContext;
import io.opentracing.Tracer;
import io.opentracing.propagation.Format;
import io.opentracing.propagation.TextMapExtractAdapter;
import io.opentracing.propagation.TextMapInjectAdapter;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import org.junit.Assert;
-import org.junit.Test;
public class MockTracerTest {
@Test
@@ -277,7 +281,19 @@ public void testNonStandardReference() {
assertEquals(parent.context().spanId(), nextSpan.parentId());
assertEquals(1, nextSpan.references().size());
- assertEquals(nextSpan.references().get(0), new MockSpan.Reference(parent.context(), "a_reference"));
+ assertEquals(nextSpan.references().get(0),
+ new MockSpan.Reference(parent.context(), "a_reference"));
+ }
+
+ @Test
+ public void testDefaultConstructor() {
+ MockTracer mockTracer = new MockTracer();
+ ActiveSpan activeSpan = mockTracer.buildSpan("foo").startActive();
+ assertEquals(activeSpan, mockTracer.activeSpan());
+
+ Map propag = new HashMap<>();
+ mockTracer.inject(activeSpan.context(), Format.Builtin.TEXT_MAP, new TextMapInjectAdapter(propag));
+ assertFalse(propag.isEmpty());
}
@Test