Package org.mockserver.load
Class LoadScenarioFromRecording
java.lang.Object
org.mockserver.load.LoadScenarioFromRecording
Seeds an editable, runnable
LoadScenario from traffic previously recorded by MockServer in
proxy/recording mode (the RECEIVED_REQUEST entries returned by
MockServerEventLog.retrieveRequests(org.mockserver.verify.Verification, java.lang.String, java.util.function.Consumer<java.util.List<org.mockserver.model.RequestDefinition>>)).
This is the "record-to-load" flagship: capture real traffic through the proxy, then replay its
shape as a load test. Two modes control how the recorded requests become LoadSteps:
LoadScenarioFromRecording.Mode.VERBATIM(default) — oneLoadStepper recorded request, in recorded order, preserving the concrete path, body and headers. An optionalmaxStepstruncates to the first N recorded requests (the orchestrator'sloadGenerationMaxStepsalso caps).LoadScenarioFromRecording.Mode.TEMPLATIZED— recorded requests are deduplicated by(method, templatised-path)using the SHAREDMetricLabels.routeOf(String)templatizer (e.g./orders/123and/orders/456collapse to one/orders/{id}route), keeping one representative example per unique route, ordered by descending hit frequency (most-hit routes first). OneLoadStepis emitted per unique route, each carrying that route's observed hit COUNT as itsweight, and the generated scenario is markedWEIGHTEDso each iteration picks a route in proportion to its recorded frequency — reproducing the recorded traffic MIX.
Target precedence for where each generated request is sent (carried as the request's
Host header and secure flag, the routing surface every load step uses):
- an explicit
LoadScenarioFromRecording.Targetsupplied by the caller (applied to every step), else - each recorded request's existing routing is left untouched — recorded proxied requests already carry their upstream target (Host header / secure flag).
When the caller supplies no LoadProfile the same conservative default as
LoadScenarioFromOpenAPI is applied — a single short constant-VU stage — so the generated
scenario is immediately runnable yet safe; the operator is expected to edit the profile afterward.
This is a pure generator: it produces a LoadScenario object and drives no traffic.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumHow recorded requests are turned into load steps.static classAn explicit network target for the generated steps, applied to every step. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic LoadScenariogenerate(String name, List<? extends RequestDefinition> recordedRequests, LoadScenarioFromRecording.Mode mode, Integer maxSteps, LoadScenarioFromRecording.Target target, LoadProfile profile) Generates aLoadScenariofrom recorded requests.
-
Constructor Details
-
LoadScenarioFromRecording
public LoadScenarioFromRecording()
-
-
Method Details
-
generate
public static LoadScenario generate(String name, List<? extends RequestDefinition> recordedRequests, LoadScenarioFromRecording.Mode mode, Integer maxSteps, LoadScenarioFromRecording.Target target, LoadProfile profile) Generates aLoadScenariofrom recorded requests.- Parameters:
name- the generated scenario namerecordedRequests- the recorded requests, as returned byMockServerEventLog.retrieveRequests(org.mockserver.verify.Verification, java.lang.String, java.util.function.Consumer<java.util.List<org.mockserver.model.RequestDefinition>>)mode-LoadScenarioFromRecording.Mode.VERBATIM(default when null) orLoadScenarioFromRecording.Mode.TEMPLATIZEDmaxSteps- optional cap on VERBATIM steps — keeps the first N recorded requests (ignored when null/<=0; TEMPLATIZED is naturally bounded by route count)target- explicit network target applied to every step (may be null — see class-level precedence)profile- explicit load profile (may be null — a conservative default is applied)- Returns:
- the generated, editable
LoadScenario - Throws:
IllegalArgumentException- if there are no recorded requests to convert
-