use of io.grpc.internal.testing.StatsTestUtils.FakeTagContext in project grpc-java by grpc.
the class AbstractInteropTest method censusContextsPropagated.
@Test(timeout = 10000)
public void censusContextsPropagated() {
Assume.assumeTrue("Skip the test because server is not in the same process.", server != null);
Assume.assumeTrue(customCensusModulePresent());
Span clientParentSpan = Tracing.getTracer().spanBuilder("Test.interopTest").startSpan();
// A valid ID is guaranteed to be unique, so we can verify it is actually propagated.
assertTrue(clientParentSpan.getContext().getTraceId().isValid());
Context ctx = io.opencensus.tags.unsafe.ContextUtils.withValue(Context.ROOT, tagger.emptyBuilder().putLocal(StatsTestUtils.EXTRA_TAG, TagValue.create("extra value")).build());
ctx = ContextUtils.withValue(ctx, clientParentSpan);
Context origCtx = ctx.attach();
try {
blockingStub.unaryCall(SimpleRequest.getDefaultInstance());
Context serverCtx = contextCapture.get();
assertNotNull(serverCtx);
FakeTagContext statsCtx = (FakeTagContext) io.opencensus.tags.unsafe.ContextUtils.getValue(serverCtx);
assertNotNull(statsCtx);
Map<TagKey, TagValue> tags = statsCtx.getTags();
boolean tagFound = false;
for (Map.Entry<TagKey, TagValue> tag : tags.entrySet()) {
if (tag.getKey().equals(StatsTestUtils.EXTRA_TAG)) {
assertEquals(TagValue.create("extra value"), tag.getValue());
tagFound = true;
}
}
assertTrue("tag not found", tagFound);
Span span = ContextUtils.getValue(serverCtx);
assertNotNull(span);
SpanContext spanContext = span.getContext();
assertEquals(clientParentSpan.getContext().getTraceId(), spanContext.getTraceId());
} finally {
ctx.detach(origCtx);
}
}
Aggregations