Interface TokenProvider
- All Known Implementing Classes:
KeycloakTokenRepository
public interface TokenProvider
Common interface for providing JWT tokens for benchmark testing.
This interface abstracts the token provisioning mechanism, allowing for different implementations depending on the benchmark requirements:
MockTokenRepository- Generates tokens in-memory for isolated library benchmarksKeycloakTokenRepository- Fetches real tokens from Keycloak for integration benchmarks
Implementations should provide efficient token rotation to simulate realistic usage patterns and ensure proper cache miss scenarios during benchmarking.
- Author:
- Oliver Wolff
-
Method Summary
Modifier and TypeMethodDescriptionGets the next token from the provider.intReturns the current size of the token pool.voidRefreshes the token pool with new tokens.
-
Method Details
-
getNextToken
Gets the next token from the provider.Implementations should provide round-robin or similar rotation strategy to ensure even distribution of tokens and realistic cache behavior.
- Returns:
- a valid JWT access token
- Throws:
RuntimeException- if a token cannot be provided
-
getTokenPoolSize
int getTokenPoolSize()Returns the current size of the token pool.This method is useful for monitoring and capacity planning during benchmarks.
- Returns:
- the number of tokens currently available in the pool
-
refreshTokens
void refreshTokens()Refreshes the token pool with new tokens.This method allows for token renewal during long-running benchmarks. Implementations may choose to:
- Generate new tokens (mock implementations)
- Fetch fresh tokens from authentication server (real implementations)
- Do nothing if token refresh is not supported
- Throws:
RuntimeException- if the refresh operation fails
-