Package org.mockserver.mock.action.http
Class TcpChaosRegistry
java.lang.Object
org.mockserver.mock.action.http.TcpChaosRegistry
Process-wide registry of TCP-layer chaos profiles, keyed by host. These
profiles are applied by the
TcpChaosHandler Netty handler at the
raw byte level before HTTP decoding, injecting transport-layer faults such
as latency, connection drops, bandwidth throttling, TCP RST, data slicing,
and data limits.
The design mirrors ServiceChaosRegistry — a singleton backed by
a ConcurrentHashMap, with optional TTL-based auto-expiry, host
normalisation (case-insensitive, port-stripped), and lazy eviction on
lookup.
State is cleared on server reset (see HttpState.reset()).
Fleet-awareness (G11): when a clustered StateBackend is
wired via setStateBackend(StateBackend), mutations are replicated
via the backend's crudEntities("chaos-tcp") store, and an
InvalidationListener rebuilds the node-local map on remote writes.
The get(String) path remains purely node-local. When no backend is
set or the backend is not clustered, behaviour is identical to the pre-G11
node-local-only registry.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintReturns the number of non-expired entries.For each fault type, the number of currently-active (non-expired) registrations whose profile includes that fault.entries()Returns a snapshot copy of the current, non-expired host to profile mappings.Returns the TCP chaos profile registered for the given host, ornullif none (or it has expired — an expired entry is removed lazily here).static TcpChaosRegistrypatch(String host, TcpChaosProfile partial) Applies JSON Merge Patch semantics to the TCP chaos profile for the given host.voidput(String host, TcpChaosProfile profile) Register (or replace) the TCP chaos profile for the given host with no expiry.voidput(String host, TcpChaosProfile profile, long ttlMillis) Register (or replace) the TCP chaos profile for the given host, optionally with a time-to-live after which it auto-expires.voidRebuilds the node-local map from the backend store.voidRemoves the TCP chaos profile for the given host (no-op if absent).voidreset()Clear all TCP-layer chaos.voidsetStateBackend(StateBackend backend) Wires the clustered state backend for fleet-wide chaos replication.Returns, for each currently-active registration that carries a TTL, the remaining milliseconds until it auto-reverts.
-
Field Details
-
FAULT_TYPES
The TCP chaos fault types reported byactiveCountByFaultType().
-
-
Constructor Details
-
TcpChaosRegistry
-
-
Method Details
-
getInstance
-
setStateBackend
Wires the clustered state backend for fleet-wide chaos replication. When the backendisClustered(), mutations are replicated via the backend's CRUD entity store, and anInvalidationListeneris registered to rebuild the node-local map on remote writes. When the backend is not clustered, this method is a no-op — the registry stays purely node-local. -
put
Register (or replace) the TCP chaos profile for the given host with no expiry. -
put
Register (or replace) the TCP chaos profile for the given host, optionally with a time-to-live after which it auto-expires.- Parameters:
ttlMillis- milliseconds until the profile auto-expires;<= 0means no expiry
-
get
Returns the TCP chaos profile registered for the given host, ornullif none (or it has expired — an expired entry is removed lazily here). -
patch
Applies JSON Merge Patch semantics to the TCP chaos profile for the given host. Only non-null fields frompartialare applied to the existing profile; unset fields in the partial are left unchanged. -
remove
Removes the TCP chaos profile for the given host (no-op if absent). -
entries
Returns a snapshot copy of the current, non-expired host to profile mappings. -
ttlRemainingMillis
Returns, for each currently-active registration that carries a TTL, the remaining milliseconds until it auto-reverts. -
activeCountByFaultType
For each fault type, the number of currently-active (non-expired) registrations whose profile includes that fault. -
activeCount
public int activeCount()Returns the number of non-expired entries. -
reset
public void reset()Clear all TCP-layer chaos. Called on server reset and for test isolation. -
reconcileFromBackend
public void reconcileFromBackend()Rebuilds the node-local map from the backend store. Called by theInvalidationListenerwhen a remote write is detected.
-