Class HttpQuotaRegistry
LlmQuotaRegistry.
Unlike the probabilistic 429 in HttpChaosProfile
(driven by errorProbability/errorStatus), this is deterministic
and stateful: it counts how many requests have hit a named quota within the
current time window and reports when the limit is exceeded, so a test can drive
an application into a hard rate-limit (e.g. "the 4th call in 60s gets 429").
Quotas are keyed by name, so several expectations that share a quotaName
share one counter (model an upstream account limit), while distinct names are
independent. HTTP and LLM quotas are held in separate registries, so a HTTP and an
LLM expectation that happen to use the same quotaName do not collide. State
is held in a ConcurrentHashMap and each acquire is an atomic per-key update,
safe under concurrent requests.
The time source is injectable so window behaviour is unit-testable without
sleeping; production uses System.currentTimeMillis(). State is cleared on
server reset (see HttpState.reset()).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic HttpQuotaRegistryvoidreset()Clear all quota state.booleantryAcquire(String name, int limit, long windowMillis) Record one request against the named quota and report whether it is allowed.
-
Constructor Details
-
HttpQuotaRegistry
-
-
Method Details
-
getInstance
-
tryAcquire
Record one request against the named quota and report whether it is allowed.Fixed-window semantics: the first request in a window starts it; the window expires
windowMillisafter it started, after which the next request starts a fresh window. A request is allowed when the in-window count (including itself) is at or belowlimit.- Returns:
trueif the request is within the quota,falseif it exceeds the limit for the current window.
-
reset
public void reset()Clear all quota state. Called on server reset and for test isolation.
-