Class AbstractBenchmarkBase
java.lang.Object
de.cuioss.benchmarking.common.base.AbstractBenchmarkBase
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected HttpRequest.BuildercreateBaseRequest(String url) Creates a basic HTTP request builder with common headers.protected HttpRequest.BuildercreateBaseRequest(String baseUrl, String path) Creates a basic HTTP request builder with common headers using a base URL and path.abstract voidExport metrics at the end of benchmark execution.protected voidInitialize the HTTP client.protected abstract voidTemplate method for subclasses to perform additional setup.protected voidTemplate method for subclasses to perform additional teardown.protected HttpResponse<String> sendRequest(HttpRequest request) Sends an HTTP request and returns the response.protected voidBase setup method that initializes common resources.protected voidtearDown()Teardown method called after benchmark execution.protected voidvalidateResponse(HttpResponse<String> response, int expectedStatus) Utility method to handle common error scenarios in benchmarks.
-
Field Details
-
serviceUrl
-
benchmarkResultsDir
-
httpClient
-
-
Constructor Details
-
AbstractBenchmarkBase
public AbstractBenchmarkBase()
-
-
Method Details
-
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
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
Template method for subclasses to perform additional setup. Override this method to add specific initialization logic. -
tearDown
Teardown method called after benchmark execution. Subclasses should call this from their @TearDown method or override to add additional cleanup logic. -
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
Creates a basic HTTP request builder with common headers using a base URL and path.- Parameters:
baseUrl- the base URLpath- the path to append to the base URL- Returns:
- configured request builder
-
sendRequest
protected HttpResponse<String> sendRequest(HttpRequest request) throws IOException, InterruptedException 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 occursInterruptedException- if the operation is interrupted
-
validateResponse
Utility method to handle common error scenarios in benchmarks.- Parameters:
response- the response to checkexpectedStatus- the expected HTTP status code- Throws:
IllegalStateException- if the response status doesn't match expected
-
exportBenchmarkMetrics
Export metrics at the end of benchmark execution. Subclasses should override this method to implement specific metrics export logic.
-