Class HttpClientTimingInstrumentationVerificationTests<CLIENT>

java.lang.Object
io.micrometer.core.instrument.HttpClientTimingInstrumentationVerificationTests<CLIENT>

@Incubating(since="1.8.8") public abstract class HttpClientTimingInstrumentationVerificationTests<CLIENT> extends Object
Test suite for HTTP client timing instrumentation that verifies the expected metrics are registered and recorded after different scenarios. Use this suite to ensure that your instrumentation has the expected naming and tags. A locally running server is used to receive real requests from an instrumented HTTP client. In order to make an actual HTTP call use the instrumentedClient(TestType) method that will cache the instrumented instance for a test.
  • Constructor Details

    • HttpClientTimingInstrumentationVerificationTests

      public HttpClientTimingInstrumentationVerificationTests()
  • Method Details

    • clientInstrumentedWithMetrics

      protected abstract CLIENT clientInstrumentedWithMetrics()
      Provide your client with instrumentation required for registering metrics.
      Returns:
      instrumented client
    • clientInstrumentedWithObservations

      @Nullable protected abstract CLIENT clientInstrumentedWithObservations()
      Provide your client with instrumentation required for registering metrics via ObservationRegistry.
      Returns:
      instrumented client or null if instrumentation with Observation is not supported
    • timerName

      protected String timerName()
      A default is provided that should be preferred by new instrumentations. Existing instrumentations that use a different value to maintain backwards compatibility may override this method to run tests with a different name used in assertions.
      Returns:
      name of the Timer meter produced from the timing instrumentation under test
    • sendHttpRequest

      protected abstract void sendHttpRequest(CLIENT instrumentedClient, HttpClientTimingInstrumentationVerificationTests.HttpMethod method, @Nullable byte[] body, URI baseUrl, String templatedPath, String... pathVariables)
      Send an HTTP request using the instrumented HTTP client to the given base URL and path on the locally running server. The HTTP client instrumentation must be configured to tag the templated path to pass this test suite. The templated path will contain path variables surrounded by curly brackets to be substituted. For example, for the full templated URL http://localhost:8080/cart/{cartId} the baseUrl would be http://localhost:8080, the templatedPath would be /cart/{cartId}. One string pathVariables argument is expected for substituting the cartId path variable. The number of pathVariables arguments SHOULD exactly match the number of path variables in the templatedPath.
      Parameters:
      instrumentedClient - instrumented client
      method - http method to use to send the request
      baseUrl - portion of the URL before the path where to send the request
      templatedPath - the path portion of the URL after the baseUrl, starting with a forward slash, and optionally containing path variable placeholders
      pathVariables - optional variables to substitute into the templatedPath
    • substitutePathVariables

      protected String substitutePathVariables(String templatedPath, String... pathVariables)
      Convenience method provided to substitute the template placeholders for the provided path variables. The number of pathVariables argument SHOULD match the number of placeholders in the templatedPath. Substitutions will be made in order.
      Parameters:
      templatedPath - a URL path optionally containing placeholders in curly brackets
      pathVariables - path variable values for which placeholders should be substituted
      Returns:
      path string with substitutions, if any, performed
    • createObservationRegistryWithMetrics

      protected io.micrometer.observation.tck.TestObservationRegistry createObservationRegistryWithMetrics()
      Helper method for creating a TestObservationRegistry to run the tests also using the Observation API.
      Returns:
      a TestObservationRegistry with a DefaultMeterObservationHandler registered
    • observationDocumentation

      @Nullable protected io.micrometer.observation.docs.ObservationDocumentation observationDocumentation()
      If an ObservationDocumentation is provided the tests run will check that the produced instrumentation matches the given ObservationDocumentation.
      Returns:
      the observation documentation to compare results against, or null to do nothing
    • getRegistry

      protected io.micrometer.core.instrument.MeterRegistry getRegistry()
      MeterRegistry to use for instrumentation verification tests.
      Returns:
      registry to use
    • getObservationRegistry

      protected io.micrometer.observation.tck.TestObservationRegistry getObservationRegistry()