001/* 002 * Copyright © 2025 CUI-OpenSource-Software (info@cuioss.de) 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package de.cuioss.benchmarking.common.token; 017 018/** 019 * Common interface for providing JWT tokens for benchmark testing. 020 * <p> 021 * This interface abstracts the token provisioning mechanism, allowing for different 022 * implementations depending on the benchmark requirements: 023 * <ul> 024 * <li>{@code MockTokenRepository} - Generates tokens in-memory for isolated library benchmarks</li> 025 * <li>{@code KeycloakTokenRepository} - Fetches real tokens from Keycloak for integration benchmarks</li> 026 * </ul> 027 * <p> 028 * Implementations should provide efficient token rotation to simulate realistic usage patterns 029 * and ensure proper cache miss scenarios during benchmarking. 030 * </p> 031 * 032 * @author Oliver Wolff 033 */ 034public interface TokenProvider { 035 036 /** 037 * Gets the next token from the provider. 038 * <p> 039 * Implementations should provide round-robin or similar rotation strategy 040 * to ensure even distribution of tokens and realistic cache behavior. 041 * </p> 042 * 043 * @return a valid JWT access token 044 * @throws RuntimeException if a token cannot be provided 045 */ 046 String getNextToken(); 047 048 /** 049 * Returns the current size of the token pool. 050 * <p> 051 * This method is useful for monitoring and capacity planning during benchmarks. 052 * </p> 053 * 054 * @return the number of tokens currently available in the pool 055 */ 056 int getTokenPoolSize(); 057 058 /** 059 * Refreshes the token pool with new tokens. 060 * <p> 061 * This method allows for token renewal during long-running benchmarks. 062 * Implementations may choose to: 063 * <ul> 064 * <li>Generate new tokens (mock implementations)</li> 065 * <li>Fetch fresh tokens from authentication server (real implementations)</li> 066 * <li>Do nothing if token refresh is not supported</li> 067 * </ul> 068 * 069 * @throws RuntimeException if the refresh operation fails 070 */ 071 void refreshTokens(); 072}