Package brave.test
Class IntegrationTestSpanHandler
- java.lang.Object
-
- brave.handler.SpanHandler
-
- brave.test.IntegrationTestSpanHandler
-
- All Implemented Interfaces:
org.junit.rules.TestRule
public final class IntegrationTestSpanHandler extends SpanHandler implements org.junit.rules.TestRule
This is a special span reporter for remote integration tests.Ex. The following is similar to our base test class
ITRemote
:{@code
- Since:
- 5.12
- See Also:
TestSpanHandler
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class brave.handler.SpanHandler
SpanHandler.Cause
-
-
Field Summary
-
Fields inherited from class brave.handler.SpanHandler
NOOP
-
-
Constructor Summary
Constructors Constructor Description IntegrationTestSpanHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.junit.runners.model.Statement
apply(org.junit.runners.model.Statement base, org.junit.runner.Description description)
boolean
begin(TraceContext context, MutableSpan span, TraceContext parent)
boolean
end(TraceContext context, MutableSpan span, SpanHandler.Cause cause)
boolean
handlesAbandoned()
void
ignoreAnySpans()
Call this before throwing anAssumptionViolatedException
, when there's a chance a span was finished.MutableSpan
takeLocalSpan()
Blocks until a local span was finished.MutableSpan
takeRemoteSpan(Span.Kind kind)
Blocks until a remote span was finished.MutableSpan
takeRemoteSpanWithError(Span.Kind kind)
Some frameworks swallow exceptions.MutableSpan
takeRemoteSpanWithError(Span.Kind kind, Throwable error)
LiketakeRemoteSpan(Kind)
except aMutableSpan.error()
must equal the given value.MutableSpan
takeRemoteSpanWithErrorMessage(Span.Kind kind, String errorMessage)
Use instead oftakeRemoteSpanWithError(Kind, Throwable)
when you cannot catch a reference to the actual raised exception during a test.MutableSpan
takeRemoteSpanWithErrorTag(Span.Kind kind, String errorTag)
LiketakeRemoteSpan(Kind)
except an error tag must match the given value.String
toString()
-
-
-
Method Detail
-
ignoreAnySpans
public void ignoreAnySpans()
Call this before throwing anAssumptionViolatedException
, when there's a chance a span was finished.This was made for detecting features in HTTP server testing via 404. When 404 itself is instrumented, post-conditions would otherwise fail from not consuming the associated span.
-
takeLocalSpan
public MutableSpan takeLocalSpan()
Blocks until a local span was finished. This does not verify errors.
-
takeRemoteSpan
public MutableSpan takeRemoteSpan(Span.Kind kind)
Blocks until a remote span was finished. We define a remote span as one with a timestamp, duration and kind.This will fail if there's an
MutableSpan.error()
or an "error" tag. If you expect a failure, usetakeRemoteSpanWithError(Kind, Throwable)
ortakeRemoteSpanWithErrorTag(Kind, String)
instead.
-
takeRemoteSpanWithError
public MutableSpan takeRemoteSpanWithError(Span.Kind kind, Throwable error)
LiketakeRemoteSpan(Kind)
except aMutableSpan.error()
must equal the given value.Note: This enforces there is no "error" tag. If your framework clarifies the "error" tag when there is also an unhandled exception, use
takeRemoteSpanWithErrorTag(Kind, String)
first, then check for error using normal assertions.
-
takeRemoteSpanWithError
public MutableSpan takeRemoteSpanWithError(Span.Kind kind)
Some frameworks swallow exceptions. This tests that either an "error" tag exists orMutableSpan.error()
does, without regards to the value.
-
takeRemoteSpanWithErrorMessage
public MutableSpan takeRemoteSpanWithErrorMessage(Span.Kind kind, String errorMessage)
Use instead oftakeRemoteSpanWithError(Kind, Throwable)
when you cannot catch a reference to the actual raised exception during a test.This is typically used when testing framework errors result in a finished span.
-
takeRemoteSpanWithErrorTag
public MutableSpan takeRemoteSpanWithErrorTag(Span.Kind kind, String errorTag)
LiketakeRemoteSpan(Kind)
except an error tag must match the given value.
-
begin
public boolean begin(TraceContext context, MutableSpan span, @Nullable TraceContext parent)
- Overrides:
begin
in classSpanHandler
-
handlesAbandoned
public boolean handlesAbandoned()
- Overrides:
handlesAbandoned
in classSpanHandler
-
end
public boolean end(TraceContext context, MutableSpan span, SpanHandler.Cause cause)
- Overrides:
end
in classSpanHandler
-
apply
public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runner.Description description)
- Specified by:
apply
in interfaceorg.junit.rules.TestRule
-
-