Class GrpcChaosProfile
GrpcHealthRegistry).
Profiles are registered in the
GrpcChaosRegistry keyed by gRPC
service name, and applied by the GrpcToHttpRequestHandler Netty
handler before normal gRPC request conversion. A default profile (keyed by
empty string) applies to all services unless overridden by a service-specific
profile.
Count-based stateful fault window: succeedFirst and
failRequestCount define a window over the per-service 1-based
match count where chaos is eligible:
- Matches 1..succeedFirst are NOT eligible (chaos is suppressed).
- Matches (succeedFirst+1)..(succeedFirst+failRequestCount) ARE eligible.
- Matches beyond succeedFirst+failRequestCount recover (no chaos).
null every match is eligible.
Stateful request quota: when quotaName, quotaLimit and
quotaWindowMillis are set, requests beyond quotaLimit within
the window are rejected with RESOURCE_EXHAUSTED — a deterministic, hard
rate limit (see HttpQuotaRegistry).
Determinism: with errorProbability of 1.0 (always) or
0.0/null (never) the error decision is fully deterministic. A
fractional probability draws once per request; set seed to make that
draw reproducible (note: a fixed seed yields the same decision every time).
Follows the model field/withX/getter convention so it round-trips
through Jackson without a bespoke (de)serializer.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancountWindowEligible(int matchCount) Returnstruewhen the given 1-based match count falls within the chaos-eligible window defined bysucceedFirstandfailRequestCount.booleangetSeed()static GrpcChaosProfilebooleanReturnstruewhen this profile has at least one fault-producing field configured: an error probability, an error status code, a latency, quota fields, trailer faults (omit/corrupt/custom), or stream abort.inthashCode()withAbortAfterMessages(Integer abortAfterMessages) Sets the client-streaming message count threshold for abort injection.withCorruptGrpcStatus(Boolean corruptGrpcStatus) withCustomTrailers(Map<String, String> customTrailers) Sets arbitrary trailer key/value pairs to inject on fault responses.withErrorMessage(String errorMessage) withErrorProbability(Double errorProbability) withErrorStatusCode(String errorStatusCode) withFailRequestCount(Integer failRequestCount) withLatencyMs(Long latencyMs) withOmitGrpcStatus(Boolean omitGrpcStatus) withQuotaLimit(Integer quotaLimit) withQuotaName(String quotaName) withQuotaWindowMillis(Long quotaWindowMillis) withSucceedFirst(Integer succeedFirst) Methods inherited from class org.mockserver.model.ObjectWithJsonToString
toStringMethods inherited from class org.mockserver.model.ObjectWithReflectiveEqualsHashCodeToString
fieldsExcludedFromEqualsAndHashCode
-
Constructor Details
-
GrpcChaosProfile
public GrpcChaosProfile()
-
-
Method Details
-
grpcChaosProfile
-
withErrorStatusCode
-
getErrorStatusCode
-
withErrorMessage
-
getErrorMessage
-
withErrorProbability
-
getErrorProbability
-
withSeed
-
getSeed
-
withLatencyMs
-
getLatencyMs
-
withSucceedFirst
-
getSucceedFirst
-
withFailRequestCount
-
getFailRequestCount
-
withQuotaName
-
getQuotaName
-
withQuotaLimit
-
getQuotaLimit
-
withQuotaWindowMillis
-
getQuotaWindowMillis
-
withOmitGrpcStatus
-
getOmitGrpcStatus
-
withCorruptGrpcStatus
-
getCorruptGrpcStatus
-
withCustomTrailers
Sets arbitrary trailer key/value pairs to inject on fault responses. Acceptsnull(meaning "no custom trailers"). Rejects any entry whose key or value contains\ror\n(header/response splitting risk), and rejects null or empty keys.- Throws:
IllegalArgumentException- if any key is null/empty or any key/value contains CR/LF
-
getCustomTrailers
-
withAbortAfterMessages
Sets the client-streaming message count threshold for abort injection. Only meaningful for client-streaming (multi-frame) requests: when the decoded gRPC frame count in the request body is >= this threshold, the handler responds withABORTED. For unary (single-frame) requests the message count is always 1, so setting this to 1 aborts every request while values > 1 only trigger on multi-frame bodies.- Throws:
IllegalArgumentException- if abortAfterMessages is non-null and < 1
-
getAbortAfterMessages
-
countWindowEligible
public boolean countWindowEligible(int matchCount) Returnstruewhen the given 1-based match count falls within the chaos-eligible window defined bysucceedFirstandfailRequestCount. When both fields arenullthis returnstruefor anymatchCount(backward compatible).- Parameters:
matchCount- 1-based match count (0 when unknown)- Returns:
trueif this match is eligible for chaos injection
-
hasAnyFault
public boolean hasAnyFault()Returnstruewhen this profile has at least one fault-producing field configured: an error probability, an error status code, a latency, quota fields, trailer faults (omit/corrupt/custom), or stream abort. -
equals
- Overrides:
equalsin classObjectWithReflectiveEqualsHashCodeToString
-
hashCode
public int hashCode()- Overrides:
hashCodein classObjectWithReflectiveEqualsHashCodeToString
-