Package io.micrometer.tracing.test
Class SampleTestRunner
java.lang.Object
io.micrometer.tracing.test.SampleTestRunner
Prepares the required tracing setup and reporters / exporters. The user needs to just
provide the code to test and that way all the combinations of tracers and exporters
will be automatically applied. It also sets up the
MeterRegistry in such a way
that it consists all TracingObservationHandler injected into
ObservationRegistry.observationConfig().
When extending this class you can eagerly pass the SampleTestRunner.SampleRunnerConfig by
calling this class' constructors. Different registry instances can be provided by
overriding createMeterRegistry() and/or
createObservationRegistry().
- Since:
- 1.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classSampleTestRunnerconfiguration.static interfaceFunctional interface to run user code.static enumTracing setups. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance of theSampleTestRunnerwith a default configuration.SampleTestRunner(SampleTestRunner.SampleRunnerConfig sampleRunnerConfig) Creates a new instance of theSampleTestRunner. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidCloses meter registry after each test.protected io.micrometer.core.instrument.MeterRegistryCreate a new instance ofMeterRegistry.protected io.micrometer.observation.ObservationRegistryCreate a new instance ofObservationRegistry.BiConsumer<BuildingBlocks,Deque<io.micrometer.observation.ObservationHandler<? extends io.micrometer.observation.Observation.Context>>> Override this to customize the list of timer recording handlers.protected io.micrometer.core.instrument.MeterRegistryReturns theMeterRegistryinstance used during each parameterized test run.protected io.micrometer.observation.ObservationRegistryReturns theObservationRegistryinstance used during each parameterized test run.protected SampleTestRunner.SampleRunnerConfigOverride this to resolve theSampleTestRunner.SampleRunnerConfigat runtime.Override this to just run a subset of tracing setups to run.protected voidSets up registries before each test.yourCode()Code that you want to measure and run.
-
Constructor Details
-
SampleTestRunner
Creates a new instance of theSampleTestRunner.- Parameters:
sampleRunnerConfig- configuration for the SampleTestRunner
-
SampleTestRunner
public SampleTestRunner()Creates a new instance of theSampleTestRunnerwith a default configuration.
-
-
Method Details
-
createMeterRegistry
protected io.micrometer.core.instrument.MeterRegistry createMeterRegistry()Create a new instance ofMeterRegistry. Each parameterized test run calls this method to create a new instance. Override this method to use differentMeterRegistryimplementation.- Returns:
- a new meter registry
-
getMeterRegistry
protected io.micrometer.core.instrument.MeterRegistry getMeterRegistry()Returns theMeterRegistryinstance used during each parameterized test run.- Returns:
- meter registry to be used in tests
-
createObservationRegistry
protected io.micrometer.observation.ObservationRegistry createObservationRegistry()Create a new instance ofObservationRegistry. Override this method to use differentObservationRegistryimplementation.- Returns:
- a new observation registry
-
getObservationRegistry
protected io.micrometer.observation.ObservationRegistry getObservationRegistry()Returns theObservationRegistryinstance used during each parameterized test run.- Returns:
- observation registry to be used in tests
-
getSampleRunnerConfig
Override this to resolve theSampleTestRunner.SampleRunnerConfigat runtime. If not overridden * will return the passedMeterRegistryfrom the constructor.- Returns:
- sampler config to be used in tests
-
setupRegistry
@BeforeEach protected void setupRegistry()Sets up registries before each test. -
closeMeterRegistry
@AfterEach protected void closeMeterRegistry()Closes meter registry after each test. -
yourCode
Code that you want to measure and run.- Returns:
- your code with access to the current tracing and measuring infrastructure
- Throws:
Exception- any exception will be rethrown
-
customizeObservationHandlers
public BiConsumer<BuildingBlocks,Deque<io.micrometer.observation.ObservationHandler<? extends io.micrometer.observation.Observation.Context>>> customizeObservationHandlers()Override this to customize the list of timer recording handlers.- Returns:
- timer recording handler customizing function
-
getTracingSetup
Override this to just run a subset of tracing setups to run.- Returns:
- array of tracing setups to run
-