Skip to content

Commit 0df139e

Browse files
authored
bug: prevent java.util.ConcurrentModificationException in Transaction (#120)
- copy context set to work on individual entity - updated demo documentation <!-- Please describe your pull request here. --> ## References #119 <!-- References to relevant GitHub issues and pull requests, esp. upstream and downstream changes --> ## Submitter checklist - [x] Recommended: Join [WireMock Slack](https://slack.wiremock.org/) to get any help in `#help-contributing` or a project-specific channel like `#wiremock-java` - [x] The PR request is well described and justified, including the body and the references - [x] The PR title represents the desired changelog entry - [x] The repository's code style is followed (see the contributing guide) - [x] Test coverage that demonstrates that the change works as expected - [x] For new features, there's necessary documentation in this pull request or in a subsequent PR to [wiremock.org](https://github.com/wiremock/wiremock.org) <!-- Put an `x` into the [ ] to show you have filled the information. The template comes from https://github.com/wiremock/.github/blob/main/.github/pull_request_template.md You can override it by creating .github/pull_request_template.md in your own repository -->
1 parent ce9ff80 commit 0df139e

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

demo/README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,31 @@ cd wiremock-state-extension
8989

9090
### Step 2: Build the Project
9191

92+
From directory of this README:
93+
94+
```shell
95+
cd ..
9296
./gradlew build
97+
```
98+
99+
### Step 3: download wiremock standalone
100+
101+
From directory of this README:
102+
103+
```shell
104+
cd ..
105+
curl -o build/libs/wiremock-standalone-3.4.1.jar https://repo1.maven.org/maven2/org/wiremock/wiremock-standalone/3.4.1/wiremock-standalone-3.4.1.jar
106+
```
107+
108+
### Step 4: Start WireMock with the State Extension
93109

94-
### Start WireMock with the State Extension
110+
From directory of this README:
111+
112+
```shell
113+
cd ..
114+
java -cp build/libs/wiremock-state-extension-standalone-0.6.0-SNAPSHOT.jar:build/libs/wiremock-standalone-3.4.1.jar wiremock.Run --verbose --global-response-templating --root-dir demo/stubs
115+
```
95116

96-
java -jar build/libs/wiremock-standalone-*.jar --extensions="com.github.tomakehurst.wiremock.extension.StateExtension"
97117
This command starts WireMock with the State Extension enabled.
98118

99119
### Access the Demo

demo/docker_container_test.http

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
### empty get
2+
3+
POST http://localhost:8080//api/v1/todolist
4+
5+
{
6+
"title": "a",
7+
"description": "as"
8+
}

src/main/java/org/wiremock/extensions/state/extensions/TransactionEventListener.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,5 @@ public void afterComplete(ServeEvent serveEvent, Parameters parameters) {
5454
String requestId = serveEvent.getId().toString();
5555
var contextNames = transactionManager.getContextNamesByRequestId(requestId);
5656
contextNames.forEach((contextName) -> transactionManager.deleteTransaction(requestId, contextName));
57-
5857
}
5958
}

src/main/java/org/wiremock/extensions/state/internal/TransactionManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.wiremock.extensions.state.internal.model.Transaction;
2020

2121
import java.util.HashMap;
22+
import java.util.HashSet;
2223
import java.util.Map;
2324
import java.util.Set;
2425
import java.util.function.Consumer;
@@ -59,7 +60,7 @@ public Set<String> getContextNamesByRequestId(String requestId) {
5960
var transactionKey = createTransactionKey(requestId);
6061
synchronized (store) {
6162
@SuppressWarnings("unchecked") var requestTransactions = store.get(transactionKey).map(it -> (Map<String, Transaction>) it).orElse(new HashMap<>());
62-
return requestTransactions.keySet();
63+
return new HashSet<>(requestTransactions.keySet());
6364
}
6465
}
6566

0 commit comments

Comments
 (0)