Class HttpClientTimingInstrumentationVerificationTests

java.lang.Object
io.micrometer.core.instrument.HttpClientTimingInstrumentationVerificationTests

@Incubating(since="1.8.8") public abstract class HttpClientTimingInstrumentationVerificationTests 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.
  • Constructor Details

    • HttpClientTimingInstrumentationVerificationTests

      public HttpClientTimingInstrumentationVerificationTests()
  • Method Details

    • 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 meter timing http client requests
    • sendHttpRequest

      protected abstract void sendHttpRequest(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:
      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
    • getRegistry

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