Class AbstractBenchmarkBase

java.lang.Object
de.cuioss.benchmarking.common.base.AbstractBenchmarkBase

public abstract class AbstractBenchmarkBase extends Object
Abstract base class for all benchmarks in the OAuth Sheriff project. Provides common functionality and fields to reduce code duplication across different benchmark implementations.

This class provides:

  • Logging infrastructure
  • HTTP client management
  • Common configuration fields
  • Utility methods for HTTP operations
  • Metrics export hooks
Author:
Oliver Wolff
  • Field Details

  • Constructor Details

  • Method Details

    • setupBase

      protected void setupBase()
      Base setup method that initializes common resources. Subclasses should call this from their @Setup method.

      This method:

      • Initializes the benchmark results directory
      • Performs additional setup via template method
      • Creates the HTTP client after serviceUrl is set
      • Performs post-initialization setup after HTTP client is ready
    • initializeHttpClient

      protected void initializeHttpClient()
      Initialize the HTTP client. This is called after performAdditionalSetup() to allow serviceUrl to be set first for URL-based client caching. Subclasses can override this to customize HTTP client initialization.
    • performAdditionalSetup

      protected abstract void performAdditionalSetup()
      Template method for subclasses to perform additional setup. Override this method to add specific initialization logic.
    • tearDown

      protected void tearDown()
      Teardown method called after benchmark execution. Subclasses should call this from their @TearDown method or override to add additional cleanup logic.
    • performAdditionalTeardown

      protected void performAdditionalTeardown()
      Template method for subclasses to perform additional teardown. Override this method to add specific cleanup logic.
    • createBaseRequest

      Creates a basic HTTP request builder with common headers.
      Parameters:
      url - the full URL to send the request to
      Returns:
      configured request builder
    • createBaseRequest

      protected HttpRequest.Builder createBaseRequest(String baseUrl, String path)
      Creates a basic HTTP request builder with common headers using a base URL and path.
      Parameters:
      baseUrl - the base URL
      path - the path to append to the base URL
      Returns:
      configured request builder
    • sendRequest

      Sends an HTTP request and returns the response.
      Parameters:
      request - the request to send
      Returns:
      the HTTP response
      Throws:
      IOException - if an I/O error occurs
      InterruptedException - if the operation is interrupted
    • validateResponse

      protected void validateResponse(HttpResponse<String> response, int expectedStatus)
      Utility method to handle common error scenarios in benchmarks.
      Parameters:
      response - the response to check
      expectedStatus - the expected HTTP status code
      Throws:
      IllegalStateException - if the response status doesn't match expected
    • exportBenchmarkMetrics

      public abstract void exportBenchmarkMetrics()
      Export metrics at the end of benchmark execution. Subclasses should override this method to implement specific metrics export logic.