Class SampleTestRunner

java.lang.Object
io.micrometer.tracing.test.SampleTestRunner

public abstract class SampleTestRunner extends Object
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
  • Constructor Details

    • SampleTestRunner

      public SampleTestRunner(SampleTestRunner.SampleRunnerConfig sampleRunnerConfig)
      Creates a new instance of the SampleTestRunner.
      Parameters:
      sampleRunnerConfig - configuration for the SampleTestRunner
    • SampleTestRunner

      public SampleTestRunner()
      Creates a new instance of the SampleTestRunner with a default configuration.
  • Method Details

    • createMeterRegistry

      protected io.micrometer.core.instrument.MeterRegistry createMeterRegistry()
      Create a new instance of MeterRegistry. Each parameterized test run calls this method to create a new instance. Override this method to use different MeterRegistry implementation.
      Returns:
      a new meter registry
    • getMeterRegistry

      protected io.micrometer.core.instrument.MeterRegistry getMeterRegistry()
      Returns the MeterRegistry instance 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 of ObservationRegistry. Override this method to use different ObservationRegistry implementation.
      Returns:
      a new observation registry
    • getObservationRegistry

      protected io.micrometer.observation.ObservationRegistry getObservationRegistry()
      Returns the ObservationRegistry instance used during each parameterized test run.
      Returns:
      observation registry to be used in tests
    • getSampleRunnerConfig

      protected SampleTestRunner.SampleRunnerConfig getSampleRunnerConfig()
      Override this to resolve the SampleTestRunner.SampleRunnerConfig at runtime. If not overridden * will return the passed MeterRegistry from 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

      public abstract SampleTestRunner.SampleTestRunnerConsumer yourCode() throws Exception
      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

      public SampleTestRunner.TracingSetup[] getTracingSetup()
      Override this to just run a subset of tracing setups to run.
      Returns:
      array of tracing setups to run