use of brave.handler.SpanHandler in project brave by openzipkin.
the class NoopAwareSpanHandlerTest method multiple_abandoned.
@Test
public void multiple_abandoned() {
SpanHandler[] handlers = new SpanHandler[3];
handlers[0] = one;
handlers[1] = two;
handlers[2] = three;
when(two.handlesAbandoned()).thenReturn(true);
SpanHandler handler = NoopAwareSpanHandler.create(handlers, noop);
assertThat(handler.handlesAbandoned()).isTrue();
handler.end(context, span, Cause.ABANDONED);
verify(one, never()).end(context, span, Cause.ABANDONED);
verify(two).end(context, span, Cause.ABANDONED);
verify(three, never()).end(context, span, Cause.FINISHED);
}
use of brave.handler.SpanHandler in project brave by openzipkin.
the class NoopAwareSpanHandlerTest method multiple_callInSequence.
@Test
public void multiple_callInSequence() {
SpanHandler[] handlers = new SpanHandler[2];
handlers[0] = one;
handlers[1] = two;
SpanHandler handler = NoopAwareSpanHandler.create(handlers, noop);
when(one.begin(eq(context), eq(span), isNull())).thenReturn(true);
when(one.end(eq(context), eq(span), eq(Cause.FINISHED))).thenReturn(true);
handler.begin(context, span, null);
handler.end(context, span, Cause.FINISHED);
verify(one).begin(context, span, null);
verify(two).begin(context, span, null);
verify(two).end(context, span, Cause.FINISHED);
verify(one).end(context, span, Cause.FINISHED);
}
use of brave.handler.SpanHandler in project brave by openzipkin.
the class PendingSpansTest method init.
@Before
public void init() {
MutableSpan defaultSpan = new MutableSpan();
defaultSpan.localServiceName("favistar");
defaultSpan.localIp("1.2.3.4");
Clock clock = () -> this.clock.incrementAndGet() * 1000L;
SpanHandler orphanTracker = OrphanTracker.newBuilder().defaultSpan(defaultSpan).clock(clock).build();
pendingSpans = new PendingSpans(defaultSpan, clock, new SpanHandler() {
@Override
public boolean begin(TraceContext ctx, MutableSpan span, @Nullable TraceContext parent) {
contexts.add(ctx);
return orphanTracker.begin(ctx, span, parent);
}
@Override
public boolean end(TraceContext ctx, MutableSpan span, Cause cause) {
orphanTracker.end(ctx, span, cause);
spans.end(ctx, span, cause);
return true;
}
}, new AtomicBoolean());
}
use of brave.handler.SpanHandler in project brave by openzipkin.
the class TracingTest method spanHandlers_clearAndAdd.
@Test
public void spanHandlers_clearAndAdd() {
SpanHandler one = mock(SpanHandler.class);
SpanHandler two = mock(SpanHandler.class);
SpanHandler three = mock(SpanHandler.class);
Tracing.Builder builder = Tracing.newBuilder().addSpanHandler(one).addSpanHandler(two).addSpanHandler(three);
Set<SpanHandler> spanHandlers = builder.spanHandlers();
builder.clearSpanHandlers();
spanHandlers.forEach(builder::addSpanHandler);
assertThat(builder).usingRecursiveComparison().isEqualTo(Tracing.newBuilder().addSpanHandler(one).addSpanHandler(two).addSpanHandler(three));
}
use of brave.handler.SpanHandler in project brave by openzipkin.
the class TracerTest method toString_withSpanReporter.
@Test
public void toString_withSpanReporter() {
tracer = Tracing.newBuilder().addSpanHandler(new SpanHandler() {
@Override
public boolean end(TraceContext context, MutableSpan span, Cause cause) {
return true;
}
@Override
public String toString() {
return "MyHandler";
}
}).spanReporter(new Reporter<zipkin2.Span>() {
@Override
public void report(zipkin2.Span span) {
}
@Override
public String toString() {
return "MyReporter";
}
}).build().tracer();
assertThat(tracer).hasToString("Tracer{spanHandler=[MyHandler, MyReporter]}");
}
Aggregations