In WireMock, which reset call empties the request journal without removing any turbine-status stub?
answer
- four stores, not one bucket
- name the store you dirtied
- the journal is its own store
- narrowest call in the family
- resetRequests(), never resetAll()
basics
~20 sCall resetRequests() on WireMock's WireMockServer, or resetAllRequests() from its static client DSL; over the admin API it is DELETE /__admin/requests. It resets the request journal alone, so stub mappings, scenario state and global settings all survive untouched.
solid answer
~50 sIn WireMock the request journal is a store of its own, and `resetRequests()` on `WireMockServer` is the reset call that touches nothing else -- internally it simply resets the journal. From the static client DSL the same operation is `WireMock.resetAllRequests()`, and over the admin API it is `DELETE /__admin/requests`. Once it returns, every stub mapping you registered is still registered and still answering, every scenario is still on whatever state it had reached, and WireMock's global settings are unchanged; only the record of what arrived is gone. That narrowness is the point. Reaching for `resetAll()` instead would also drop the live stub set and reload the start-up mappings, which is a far larger blast radius than *I want the next turbine-status count to start from zero*. Name the store you dirtied and call the reset named after it.
code
java · 14 linesimport static com.github.tomakehurst.wiremock.client.WireMock.*;
configureFor("localhost", 8080);
stubFor(get(urlPathEqualTo("/turbines/WTG-0417/status"))
.willReturn(aResponse()
.withStatus(200)
.withBody("{\"turbineId\":\"WTG-0417\",\"state\":\"PRODUCING\"}")));
// Journal only. The stub above keeps answering afterwards.
resetAllRequests(); // DELETE /__admin/requests
// Compare: this would drop the stub and reload the start-up mappings.
// reset(); // POST /__admin/resetgo deeper
Know the name and know what it spares. WireMock's resetRequests(), or resetAllRequests() from the static DSL, empties the request journal and leaves every stub mapping in place and answering.
Explain WireMock's stores separately: the stub set, the request journal, scenario state and global settings. Say which reset call maps onto which store, and that resetRequests() reaches only the journal.
Show the diagnostic habit. When a count is wrong, work out whether the journal was cleared or the stub set was rebuilt, because resetAll() does both and only one of the two explains an unmatched request.
Set the default for the organisation. Decide whether the broad reset is allowed at all, and what you require of suites that rely on the narrow calls instead of rebuilding their own fixture each time.
## A WireMock server holds four stores, not one Almost every reset mistake starts from picturing a WireMock server as one undivided bucket of state. It is four, and each reset call is named after the one it touches. - The **stub set** -- the mappings that decide which canned reply a request gets. - The **request journal** -- the record of what actually arrived, in the order it arrived. - **Scenario state** -- how far each stateful sequence has advanced. - **Global settings** -- server-wide values, read and written through `GET /__admin/settings` and `PUT /__admin/settings`. `resetRequests()` is the call named after the journal, and it is the narrowest member of the family. ## What resetRequests() does, precisely `resetRequests()` on WireMock's `WireMockServer` resets the request journal and does nothing else -- internally that is the entire implementation, a single call onto the journal with no second step. After it returns, four things are true. 1. Every stub mapping is still registered and still answering, whether it arrived in the start-up set or from a run-time `stubFor(`. 2. Every scenario is still on whatever state it had reached, so a sequence half-way through stays half-way through. 3. The global settings are unchanged, because no reset call in WireMock touches that store. 4. Only the record of received requests is gone, so anything that reads the journal now reads an empty one. That last point is the whole purpose. If you want the next `/turbines/WTG-0417/status` assertion to count from zero without disturbing the fixture that answers it, this is the call. ## Three doors onto the same operation WireMock exposes this reset three ways, and which one you have depends on how you are addressing the server. - `resetRequests()` on `WireMockServer` -- the instance method, when you hold the server object. - `WireMock.resetAllRequests()` -- the static in the client DSL, after `configureFor(`. - `DELETE /__admin/requests` -- the admin-API form, which is why it reads as a delete on the requests collection rather than as something called a reset. The awkward part is that the instance method and the static do not share a spelling. `resetRequests()` and `resetAllRequests()` are the same operation on different types, and picking the wrong one is a compile error rather than a silent behavioural bug -- which is the good outcome. ## Why the broad reset is not the safer choice There is a reflex that says a bigger reset is a more thorough reset and therefore the conservative option. On WireMock it is the reverse: a broader reset removes state that later cases were relying on, and it removes it silently. | what you actually want | the WireMock call | what it also costs you | |---|---|---| | the recorded requests gone | `resetRequests()` | nothing else changes | | stateful sequences back at the start | `resetScenarios()` | nothing else changes | | the stub set back to the start-up defaults | `resetToDefaultMappings()` | every run-time `stubFor(` registration, and the journal | | all of the above at once | `resetAll()` | the same, because it delegates to `resetToDefaultMappings()` | Read the bottom two rows together: `resetAll()` is not a fifth, stronger option. It is the third row under another name. ## Choosing on a turbine-status suite The decision rule is short: name the store you dirtied, and call the reset named after it. - A case that only sent requests dirtied the journal. `resetRequests()`. - A case that walked a stateful sequence dirtied scenario state. `resetScenarios()`. - A case that registered its own mapping dirtied the stub set, and only then is a mapping-level reset in scope at all. - A case that changed a global setting dirtied a store no reset call reaches, so it has to write the value back itself. ## Where people go wrong - Reaching for `resetAll()` because it sounds like the safe default, and taking out a shared baseline in the process. - Assuming that clearing the journal also rewinds scenario state, then being surprised that a sequence answers from its second step. - Assuming the reverse, that returning scenarios to the beginning also empties the journal. - Reading `resetRequests()` as "remove the stubs that handle requests", which is the opposite of what it does; the word *requests* refers to received requests, not to request patterns. Getting this right is not a micro-optimisation. On a server that several suites share, the difference between the journal-only call and the broad one is the difference between a clean count and a stranded fixture, and the second failure surfaces a long way from the line that caused it.
- Does WireMock's resetRequests() also reset scenario state?No. Those are two stores and two calls. `resetRequests()` resets the request journal, while `resetScenarios()` returns every scenario to its initial state. Emptying the journal has no effect on how far a stateful sequence has advanced, so a scenario sitting on its second step stays on its second step and the next matching request carries on from there.
- What is the admin-API equivalent of WireMock's resetRequests()?`DELETE /__admin/requests`. It is the journal-only door, which is why it is spelled as a delete on the requests collection rather than as a reset. `POST /__admin/reset` is the broad one that delegates to `resetToDefaultMappings()`, and it is not the call you want when only the journal is dirty.
- Why is resetAll() a bad habit even when it happens to work?Because it works by accident. It tears down the live stub set and reloads the start-up mappings, so it only looks harmless while every stub happens to be a start-up default. The first suite-wide `stubFor(` registration turns the same line into a stranded fixture, and nothing about the call site changed to warn you.
saying these in an interview costs you the question
- Reaches for resetAll() to clear only the request journal
- Thinks clearing the journal also removes stub mappings
- Believes scenario state resets when the journal is emptied
- Confuses resetRequests() with removing request-matching stubs
- Assumes WireMock has a single, undivided reset operation