Package org.mockserver.model
Class RateLimit
java.lang.Object
org.mockserver.model.ObjectWithReflectiveEqualsHashCodeToString
org.mockserver.model.ObjectWithJsonToString
org.mockserver.model.RateLimit
Declarative, protocol-agnostic rate-limiting / quota action attached to an
Expectation (a sibling of chaos). When a
matched expectation carries a rateLimit clause and the request is
over-limit for the current window, a deterministic errorStatus
(default 429) response is returned instead of the normal
response, carrying Retry-After and X-RateLimit-* headers; when
the request is within the limit the normal response is returned unchanged.
Counting is backed by a shared, named in-process registry
(RateLimitRegistry): expectations that share
a name share one counter (model an upstream account limit); when
name is null the expectation's own id is used as the counter key so a
single expectation rate-limits in isolation. v1 supports two algorithms:
FIXED_WINDOW— at mostlimitrequests perwindowMillis; the window starts on the first request and resets once it elapses.TOKEN_BUCKET— a bucket of capacityburstrefilling atrefillPerSecondtokens/second; a request is allowed when at least one token is available (and consumes it).
withX/getter convention so it
round-trips without a bespoke (de)serializer.-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionThe effective algorithm, defaulting toRateLimit.Algorithm.FIXED_WINDOWwhen unset.booleangetBurst()getLimit()getName()inthashCode()static RateLimitwithAlgorithm(RateLimit.Algorithm algorithm) withErrorStatus(Integer errorStatus) withRefillPerSecond(Double refillPerSecond) withRetryAfter(String retryAfter) withWindowMillis(Long windowMillis) Methods inherited from class org.mockserver.model.ObjectWithJsonToString
toStringMethods inherited from class org.mockserver.model.ObjectWithReflectiveEqualsHashCodeToString
fieldsExcludedFromEqualsAndHashCode
-
Constructor Details
-
RateLimit
public RateLimit()
-
-
Method Details
-
rateLimit
-
withName
-
getName
-
withAlgorithm
-
getAlgorithm
-
withLimit
-
getLimit
-
withWindowMillis
-
getWindowMillis
-
withBurst
-
getBurst
-
withRefillPerSecond
-
getRefillPerSecond
-
withErrorStatus
-
getErrorStatus
-
withRetryAfter
-
getRetryAfter
-
effectiveAlgorithm
The effective algorithm, defaulting toRateLimit.Algorithm.FIXED_WINDOWwhen unset. -
equals
- Overrides:
equalsin classObjectWithReflectiveEqualsHashCodeToString
-
hashCode
public int hashCode()- Overrides:
hashCodein classObjectWithReflectiveEqualsHashCodeToString
-