Skip to content

Commit

Permalink
bug: prevent java.util.ConcurrentModificationException in Transaction (
Browse files Browse the repository at this point in the history
…#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
-->
  • Loading branch information
dirkbolte authored Mar 1, 2024
1 parent ce9ff80 commit 0df139e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
24 changes: 22 additions & 2 deletions demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,31 @@ cd wiremock-state-extension

### Step 2: Build the Project

From directory of this README:

```shell
cd ..
./gradlew build
```

### Step 3: download wiremock standalone

From directory of this README:

```shell
cd ..
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
```

### Step 4: Start WireMock with the State Extension

### Start WireMock with the State Extension
From directory of this README:

```shell
cd ..
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
```

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

### Access the Demo
Expand Down
8 changes: 8 additions & 0 deletions demo/docker_container_test.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### empty get

POST http://localhost:8080//api/v1/todolist

{
"title": "a",
"description": "as"
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,5 @@ public void afterComplete(ServeEvent serveEvent, Parameters parameters) {
String requestId = serveEvent.getId().toString();
var contextNames = transactionManager.getContextNamesByRequestId(requestId);
contextNames.forEach((contextName) -> transactionManager.deleteTransaction(requestId, contextName));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.wiremock.extensions.state.internal.model.Transaction;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
Expand Down Expand Up @@ -59,7 +60,7 @@ public Set<String> getContextNamesByRequestId(String requestId) {
var transactionKey = createTransactionKey(requestId);
synchronized (store) {
@SuppressWarnings("unchecked") var requestTransactions = store.get(transactionKey).map(it -> (Map<String, Transaction>) it).orElse(new HashMap<>());
return requestTransactions.keySet();
return new HashSet<>(requestTransactions.keySet());
}
}

Expand Down

0 comments on commit 0df139e

Please sign in to comment.