Package org.mockserver.mock.action.http
Class ChaosProfileLibrary
java.lang.Object
org.mockserver.mock.action.http.ChaosProfileLibrary
Persisted, named library of reusable chaos experiment profiles.
A "profile" here is simply a saved chaos experiment definition — the exact
same JSON shape that PUT /mockserver/chaosExperiment accepts — stored
under a human-chosen name so it can be re-applied later without re-authoring
the JSON. The library is a template store, not the active-experiment store:
saving a profile does not start it; apply(name) starts it.
Storage: profiles live in the StateBackend's
crudEntities("chaos-profiles") key-value store, keyed by profile name.
This gives two properties for free:
- Survives server reset —
HttpState.reset()clears active chaos (registries, the running experiment) but intentionally does NOT clear this template store, so saved profiles outlive a reset. Unlike the chaos registries (which only attach a backend when clustered), the library always uses the backend store, so the single-node default backend persists profiles across resets too. - Cluster-correct — when the backend is clustered, profile saves/deletes replicate across the fleet via the same CRUD-entity replication used by the chaos registries.
Each stored value is the raw experiment-definition ObjectNode; the
profile name (the store key) overrides any name inside the body so the
saved-under name and the experiment name stay consistent.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringCRUD-entity namespace under which saved profiles are stored. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanRemoves the saved profilename.Optional<com.fasterxml.jackson.databind.node.ObjectNode>Returns the saved profile definition forname, orOptional.empty()if no such profile exists.static booleanisValidName(String name) Validates a profile name.list()Returns the names of all saved profiles, in ascending name order.voidSaves (or replaces) a profile undername.
-
Field Details
-
BACKEND_NAMESPACE
CRUD-entity namespace under which saved profiles are stored.- See Also:
-
-
Constructor Details
-
ChaosProfileLibrary
-
-
Method Details
-
isValidName
Validates a profile name. Returnstruewhen the name is non-null and made up only of letters, digits, space, dot, underscore and hyphen (1–128 characters), with no leading or trailing space. -
save
Saves (or replaces) a profile undername. Thedefinitionis the experiment-definition JSON — the same shape accepted byPUT /mockserver/chaosExperiment. The stored copy'snamefield is normalised tonameso the saved-under name wins.- Throws:
IllegalArgumentException- if the name is invalid or the definition is null
-
get
Returns the saved profile definition forname, orOptional.empty()if no such profile exists. -
list
Returns the names of all saved profiles, in ascending name order. -
delete
Removes the saved profilename. Returnstrueif a profile was present and removed,falseif no such profile existed.
-