Package brave.test
Class ITRemote
- java.lang.Object
-
- brave.test.ITRemote
-
public abstract class ITRemote extends Object
This is the base class for remote integration tests. It has a few features to ensure tests cover common instrumentation bugs. Most of this optimizes for instrumentation occurring on a different thread than main (which does the assertions).StrictCurrentTraceContextdouble-checks threads don't leak contextsIntegrationTestSpanHandlerhelps avoid race conditions or accidental errors
-
-
Field Summary
Fields Modifier and Type Field Description static BaggageFieldBAGGAGE_FIELDstatic StringBAGGAGE_FIELD_KEYSets a propagation key forBAGGAGE_FIELD, which can work with JMS (that prohibits the '-' character).protected CurrentTraceContextcurrentTraceContextorg.junit.rules.TestRuleglobalTimeoutWe use a global rule instead of surefire config as this could be executed in gradle, sbt, etc.protected Propagation.FactorypropagationFactoryorg.junit.rules.TestNametestNameIntegrationTestSpanHandlertestSpanHandlerprotected Tracingtracing
-
Constructor Summary
Constructors Modifier Constructor Description protectedITRemote()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidassertChildOf(MutableSpan child, MutableSpan parent)protected voidassertChildOf(MutableSpan child, TraceContext parent)protected voidassertChildOf(TraceContext child, TraceContext parent)protected voidassertNoError(MutableSpan result)protected voidassertNoErrorTag(MutableSpan result)protected voidassertSameIds(MutableSpan span, TraceContext parent)Useful for checking server spans whenTracing.Builder.supportsJoin(boolean).protected voidassertSequential(MutableSpan span1, MutableSpan span2)Ensures the first finished before the other started.protected voidassertSpanInInterval(MutableSpan span, long startTimestamp, long finishTimestamp)Ensures the inputs are parent and child, the parent starts before the child, and the duration of the child is inside the parent's duration.protected voidcheckForLeakedScopes()Override to disable scope leak enforcement.voidclose()This closes the current instance of tracing, to prevent it from being accidentally visible to other test classes which callTracing.current().protected CurrentTraceContext.BuildercurrentTraceContextBuilder()Subclass to override the builder.protected TraceContextnewTraceContext(SamplingFlags flags)Returns a trace context for use in propagation tests.protected Tracing.BuildertracingBuilder(Sampler sampler)
-
-
-
Field Detail
-
BAGGAGE_FIELD
public static final BaggageField BAGGAGE_FIELD
-
BAGGAGE_FIELD_KEY
public static final String BAGGAGE_FIELD_KEY
Sets a propagation key forBAGGAGE_FIELD, which can work with JMS (that prohibits the '-' character).Note: If we didn't do this, it would be propagated all lowercase, ex "userid", which is harmless. We reset this for two reasons:
- Ensures
BaggagePropagationConfig.SingleBaggageField.keyNames()are used on the wire, instead ofBaggageField.name() - Warn maintainers about JMS related naming choices.
- See Also:
- Constant Field Values
- Ensures
-
globalTimeout
public org.junit.rules.TestRule globalTimeout
We use a global rule instead of surefire config as this could be executed in gradle, sbt, etc. This way, there's visibility on which method hung without asking the end users to edit build config.Normal tests will pass in less than 5 seconds. This timeout is set to 20 to be higher than needed even in a an overloaded CI server or extreme garbage collection pause.
-
testSpanHandler
public IntegrationTestSpanHandler testSpanHandler
-
testName
public org.junit.rules.TestName testName
-
currentTraceContext
protected final CurrentTraceContext currentTraceContext
-
propagationFactory
protected final Propagation.Factory propagationFactory
-
tracing
protected Tracing tracing
-
-
Method Detail
-
newTraceContext
protected TraceContext newTraceContext(SamplingFlags flags)
Returns a trace context for use in propagation tests.
-
currentTraceContextBuilder
protected CurrentTraceContext.Builder currentTraceContextBuilder()
Subclass to override the builder. The result will haveStrictScopeDecoratoradded
-
tracingBuilder
protected Tracing.Builder tracingBuilder(Sampler sampler)
-
close
public void close() throws ExceptionThis closes the current instance of tracing, to prevent it from being accidentally visible to other test classes which callTracing.current().This also checks for scope leaks. It is important that you have closed all resources prior to this method call. Otherwise, in-flight request cleanup may be mistaken for scope leaks. This may involve blocking on completion, if using executors.
Ex.
{@code- Throws:
Exception
-
checkForLeakedScopes
protected void checkForLeakedScopes() throws IOExceptionOverride to disable scope leak enforcement.- Throws:
IOException
-
assertSpanInInterval
protected void assertSpanInInterval(MutableSpan span, long startTimestamp, long finishTimestamp)
Ensures the inputs are parent and child, the parent starts before the child, and the duration of the child is inside the parent's duration.
-
assertSequential
protected void assertSequential(MutableSpan span1, MutableSpan span2)
Ensures the first finished before the other started.
-
assertSameIds
protected void assertSameIds(MutableSpan span, TraceContext parent)
Useful for checking server spans whenTracing.Builder.supportsJoin(boolean).
-
assertChildOf
protected void assertChildOf(TraceContext child, TraceContext parent)
-
assertChildOf
protected void assertChildOf(MutableSpan child, TraceContext parent)
-
assertChildOf
protected void assertChildOf(MutableSpan child, MutableSpan parent)
-
assertNoError
protected void assertNoError(MutableSpan result)
-
assertNoErrorTag
protected void assertNoErrorTag(MutableSpan result)
-
-