use of brave.propagation.TraceContext in project brave by openzipkin.
the class ExtraFactoryTest method decorate_extractedExtra_plus_emptyParent.
@Test
public void decorate_extractedExtra_plus_emptyParent() {
TraceContext decorated = propagationFactory.decorate(context);
BasicMapExtra extra1 = decorated.findExtra(BasicMapExtra.class);
BasicMapExtra extracted = factory.create();
extracted.put("2", "three");
context2 = propagationFactory.decorate(context2.toBuilder().addExtra(extra1).addExtra(extracted).build());
BasicMapExtra extra2 = context2.findExtra(BasicMapExtra.class);
// merged
assertThat(context2.extra()).containsExactly(extra2);
assertThat(extra2.get("2")).isEqualTo("three");
assertExtraClaimed(context2);
}
use of brave.propagation.TraceContext in project brave by openzipkin.
the class NoopAwareSpanHandlerTest method doesntCrashOnNonFatalThrowable.
@Test
public void doesntCrashOnNonFatalThrowable() {
Throwable[] toThrow = new Throwable[1];
SpanHandler handler = NoopAwareSpanHandler.create(new SpanHandler[] { new SpanHandler() {
@Override
public boolean end(TraceContext context, MutableSpan span, Cause cause) {
doThrowUnsafely(toThrow[0]);
return true;
}
} }, noop);
toThrow[0] = new RuntimeException();
assertThat(handler.end(context, span, Cause.FINISHED)).isTrue();
toThrow[0] = new Exception();
assertThat(handler.end(context, span, Cause.FINISHED)).isTrue();
toThrow[0] = new Error();
assertThat(handler.end(context, span, Cause.FINISHED)).isTrue();
// fatal
toThrow[0] = new StackOverflowError();
try {
// assertThatThrownBy doesn't work with StackOverflowError
handler.end(context, span, Cause.FINISHED);
failBecauseExceptionWasNotThrown(StackOverflowError.class);
} catch (StackOverflowError e) {
}
}
use of brave.propagation.TraceContext in project brave by openzipkin.
the class PendingSpansTest method noop_afterGC.
@Test
public void noop_afterGC() {
TraceContext context1 = context.toBuilder().spanId(1).build();
pendingSpans.getOrCreate(null, context1, false);
TraceContext context2 = context.toBuilder().spanId(2).build();
pendingSpans.getOrCreate(null, context2, false);
TraceContext context3 = context.toBuilder().spanId(3).build();
pendingSpans.getOrCreate(null, context3, false);
TraceContext context4 = context.toBuilder().spanId(4).build();
pendingSpans.getOrCreate(null, context4, false);
int initialClockVal = clock.get();
pendingSpans.noop.set(true);
// By clearing strong references in this test, we are left with the weak ones in the map
context1 = context2 = null;
pendingSpans.expungeStaleEntries();
// since this is noop, we don't expect any spans to be reported
assertThat(spans).isEmpty();
// we also expect the clock to not have been called
assertThat(clock.get()).isEqualTo(initialClockVal);
}
use of brave.propagation.TraceContext in project brave by openzipkin.
the class PendingSpansTest method orphanContext_includesAllFlags.
@Test
public void orphanContext_includesAllFlags() {
TraceContext context1 = context.toBuilder().sampled(null).sampledLocal(true).shared(true).build();
TraceContext context = context1.toBuilder().build();
pendingSpans.getOrCreate(null, context, false).state().tag("foo", "bar");
// We drop the reference to the context, which means the next GC should attempt to flush it
context = null;
GarbageCollectors.blockOnGC();
pendingSpans.expungeStaleEntries();
assertThat(contexts).hasSize(1);
assertThat(InternalPropagation.instance.flags(contexts.get(0))).isEqualTo(// no flags lost
InternalPropagation.instance.flags(context1));
}
use of brave.propagation.TraceContext in project brave by openzipkin.
the class PendingSpansTest method getOrCreate_reusesClockFromParent.
/**
* Ensure we use the same clock for traces that started in-process
*/
@Test
public void getOrCreate_reusesClockFromParent() {
TraceContext trace = context;
TraceContext traceJoin = trace.toBuilder().shared(true).build();
TraceContext trace2 = context.toBuilder().traceId(2L).build();
TraceContext traceChild = TraceContext.newBuilder().traceId(1L).parentId(trace.spanId()).spanId(3L).build();
PendingSpan traceSpan = pendingSpans.getOrCreate(null, trace, false);
PendingSpan traceJoinSpan = pendingSpans.getOrCreate(trace, traceJoin, false);
PendingSpan trace2Span = pendingSpans.getOrCreate(null, trace2, false);
PendingSpan traceChildSpan = pendingSpans.getOrCreate(trace, traceChild, false);
assertThat(traceSpan.clock).isSameAs(traceChildSpan.clock);
assertThat(traceSpan.clock).isSameAs(traceJoinSpan.clock);
assertThat(traceSpan.clock).isNotSameAs(trace2Span.clock);
}
Aggregations