Search in sources :

Example 11 with SpanHandler

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);
}
Also used : SpanHandler(brave.handler.SpanHandler) Test(org.junit.Test)

Example 12 with SpanHandler

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);
}
Also used : SpanHandler(brave.handler.SpanHandler) Test(org.junit.Test)

Example 13 with SpanHandler

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());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MutableSpan(brave.handler.MutableSpan) TraceContext(brave.propagation.TraceContext) TestSpanHandler(brave.test.TestSpanHandler) SpanHandler(brave.handler.SpanHandler) Clock(brave.Clock) Nullable(brave.internal.Nullable) Before(org.junit.Before)

Example 14 with SpanHandler

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));
}
Also used : TestSpanHandler(brave.test.TestSpanHandler) FinishedSpanHandler(brave.handler.FinishedSpanHandler) SpanHandler(brave.handler.SpanHandler) Test(org.junit.Test)

Example 15 with SpanHandler

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]}");
}
Also used : MutableSpan(brave.handler.MutableSpan) Reporter(zipkin2.reporter.Reporter) StrictCurrentTraceContext(brave.propagation.StrictCurrentTraceContext) CurrentTraceContext(brave.propagation.CurrentTraceContext) TraceContext(brave.propagation.TraceContext) TestSpanHandler(brave.test.TestSpanHandler) SpanHandler(brave.handler.SpanHandler) MutableSpan(brave.handler.MutableSpan) Test(org.junit.Test)

Aggregations

SpanHandler (brave.handler.SpanHandler)15 Test (org.junit.Test)11 MutableSpan (brave.handler.MutableSpan)8 TraceContext (brave.propagation.TraceContext)8 TestSpanHandler (brave.test.TestSpanHandler)6 StrictCurrentTraceContext (brave.propagation.StrictCurrentTraceContext)4 FinishedSpanHandler (brave.handler.FinishedSpanHandler)3 CurrentTraceContext (brave.propagation.CurrentTraceContext)2 ArrayList (java.util.ArrayList)2 ConcurrentLinkedDeque (java.util.concurrent.ConcurrentLinkedDeque)2 Clock (brave.Clock)1 ScopedSpan (brave.ScopedSpan)1 Tracing (brave.Tracing)1 Cause (brave.handler.SpanHandler.Cause)1 Nullable (brave.internal.Nullable)1 Arrays.asList (java.util.Arrays.asList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Before (org.junit.Before)1