-
Notifications
You must be signed in to change notification settings - Fork 719
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds better default impl from https://github.com/DistributedTracing/c…
- Loading branch information
Adrian Cole
committed
Mar 22, 2017
1 parent
c05fc37
commit abe3d92
Showing
3 changed files
with
107 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package brave; | ||
|
||
import brave.Tracer.DefaultSpanScoper; | ||
import brave.propagation.SpanScoper; | ||
import brave.propagation.TraceContext; | ||
import org.junit.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class DefaultSpanScoperTest { | ||
DefaultSpanScoper scoper = new DefaultSpanScoper(); | ||
Tracer tracer = Tracer.newBuilder().build(); | ||
TraceContext context = tracer.newTrace().context(); | ||
TraceContext context2 = tracer.newTrace().context(); | ||
|
||
@Test public void currentSpan_defaultsToNull() { | ||
assertThat(scoper.currentSpan()).isNull(); | ||
} | ||
|
||
@Test public void scope_retainsContext() { | ||
try (SpanScoper.SpanInScope scope = scoper.open(context)) { | ||
assertThat(scoper.currentSpan()) | ||
.isEqualTo(context); | ||
} | ||
} | ||
|
||
@Test public void scope_isDefinedPerThread() throws InterruptedException { | ||
final TraceContext[] threadValue = new TraceContext[1]; | ||
|
||
try (SpanScoper.SpanInScope scope = scoper.open(context)) { | ||
Thread t = new Thread(() -> { // inheritable thread local | ||
assertThat(scoper.currentSpan()) | ||
.isEqualTo(context); | ||
|
||
try (SpanScoper.SpanInScope scope2 = scoper.open(context2)) { | ||
assertThat(scoper.currentSpan()) | ||
.isEqualTo(context2); | ||
threadValue[0] = context2; | ||
} | ||
}); | ||
|
||
t.start(); | ||
t.join(); | ||
assertThat(scoper.currentSpan()) | ||
.isEqualTo(context); | ||
assertThat(threadValue[0]) | ||
.isEqualTo(context2); | ||
} | ||
} | ||
|
||
@Test public void instancesAreIndependent() { | ||
DefaultSpanScoper scoper2 = new DefaultSpanScoper(); | ||
|
||
try (SpanScoper.SpanInScope scope1 = scoper.open(context)) { | ||
assertThat(scoper2.currentSpan()).isNull(); | ||
|
||
try (SpanScoper.SpanInScope scope2 = scoper2.open(context2)) { | ||
assertThat(scoper.currentSpan()).isEqualTo(context); | ||
assertThat(scoper2.currentSpan()).isEqualTo(context2); | ||
} | ||
} | ||
} | ||
} |