Package org.mockserver.model
Class TcpChaosProfile
java.lang.Object
org.mockserver.model.ObjectWithReflectiveEqualsHashCodeToString
org.mockserver.model.ObjectWithJsonToString
org.mockserver.model.TcpChaosProfile
Declarative TCP-layer fault/chaos injection profile, applied at the raw byte
level before HTTP decoding. Each fault type mirrors one of
Toxiproxy's named toxics:
- latency — delay all inbound data by
latencyMsmilliseconds - down — silently drop all inbound data (service appears down)
- bandwidth — throttle inbound data to
bandwidthBytesPerSec - slow_close — delay the TCP FIN by 2 seconds
- timeout — never send FIN; connection hangs on close
- reset_peer — send TCP RST and close immediately
- slicer — fragment inbound data into chunks of
slicerChunkSizebytes - limit_data — close the connection after
limitDataBytesbytes received
Profiles are registered in the TcpChaosRegistry
and applied by the TcpChaosHandler Netty handler. When multiple faults are
configured on the same profile, they are evaluated in priority order: down, resetPeer,
limitData, slicer, bandwidth, latency.
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 TypeMethodDescriptionbooleangetDown()booleanReturnstruewhen at least one fault is configured (non-null and meaningful).inthashCode()static TcpChaosProfilewithBandwidthBytesPerSec(Long bandwidthBytesPerSec) withHttp2GoAway(Boolean http2GoAway) When true and the connection is HTTP/2, a GOAWAY frame is emitted on the response path so the client stops opening new streams and drains — the graceful "this connection is going away" signal.withHttp2GoAwayErrorCode(Long http2GoAwayErrorCode) HTTP/2 error code carried on the GOAWAY frame.withHttp2GoAwayLastStreamId(Long http2GoAwayLastStreamId) ThelastStreamIdcarried on the GOAWAY frame.withLatencyMs(Long latencyMs) withLimitDataBytes(Long limitDataBytes) withResetAfterResponseChunks(Integer resetAfterResponseChunks) Number of response body chunks to write before the mid-response RST.withResetMidResponse(Boolean resetMidResponse) When true, after the response head is written the socket is forced to RST (SO_LINGER 0 + forced close) instead of a clean FIN, so the client sees the connection reset mid-stream — the "server crashed while replying" fault.withResetPeer(Boolean resetPeer) withSlicerChunkSize(Integer slicerChunkSize) withSlowClose(Boolean slowClose) withSlowCloseDelay(Delay slowCloseDelay) Host-scoped (optionally jittered) delay applied before the socket FIN on the response path, even whenConnectionOptions.closeSocketDelayis null.withTimeout(Boolean timeout) Methods inherited from class org.mockserver.model.ObjectWithJsonToString
toStringMethods inherited from class org.mockserver.model.ObjectWithReflectiveEqualsHashCodeToString
fieldsExcludedFromEqualsAndHashCode
-
Constructor Details
-
TcpChaosProfile
public TcpChaosProfile()
-
-
Method Details
-
tcpChaosProfile
-
getLatencyMs
-
withLatencyMs
-
getDown
-
withDown
-
getBandwidthBytesPerSec
-
withBandwidthBytesPerSec
-
getSlowClose
-
withSlowClose
-
getTimeout
-
withTimeout
-
getResetPeer
-
withResetPeer
-
getSlicerChunkSize
-
withSlicerChunkSize
-
getLimitDataBytes
-
withLimitDataBytes
-
getResetMidResponse
-
withResetMidResponse
When true, after the response head is written the socket is forced to RST (SO_LINGER 0 + forced close) instead of a clean FIN, so the client sees the connection reset mid-stream — the "server crashed while replying" fault. Applied in the response writer, not at connect time. -
getResetAfterResponseChunks
-
withResetAfterResponseChunks
Number of response body chunks to write before the mid-response RST.null(or 0) means "reset after the head". v1 only honours the "after head" semantics precisely; values > 0 for non-chunked bodies are deferred and treated as "after head". -
getSlowCloseDelay
-
withSlowCloseDelay
Host-scoped (optionally jittered) delay applied before the socket FIN on the response path, even whenConnectionOptions.closeSocketDelayis null. Lets a host be made to linger on close without a per-expectation connection option. -
getHttp2GoAway
-
withHttp2GoAway
When true and the connection is HTTP/2, a GOAWAY frame is emitted on the response path so the client stops opening new streams and drains — the graceful "this connection is going away" signal. HTTP/1.1 has no GOAWAY and degrades toConnection: close+ 503 elsewhere. -
getHttp2GoAwayErrorCode
-
withHttp2GoAwayErrorCode
HTTP/2 error code carried on the GOAWAY frame.nulldefaults to 0 (NO_ERROR), the graceful-shutdown code. -
getHttp2GoAwayLastStreamId
-
withHttp2GoAwayLastStreamId
ThelastStreamIdcarried on the GOAWAY frame.nullmeans "use the current / last-processed stream id" (resolved at emit time by the connection handler). -
hasAnyFault
public boolean hasAnyFault()Returnstruewhen at least one fault is configured (non-null and meaningful). -
equals
- Overrides:
equalsin classObjectWithReflectiveEqualsHashCodeToString
-
hashCode
public int hashCode()- Overrides:
hashCodein classObjectWithReflectiveEqualsHashCodeToString
-