Skip to content

Commit ba9707a

Browse files
Setup tmp documentation for the API
1 parent 91a31c1 commit ba9707a

File tree

3 files changed

+81
-13
lines changed

3 files changed

+81
-13
lines changed

README.md

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ Here are some scenarios where this kind of tool becomes very handy:
2121
- [x] Add threads
2222
- [x] Remove threads
2323
- [x] Get variables
24-
- [ ] Modify variables
25-
- [ ] Get properties
24+
- [x] Modify variables
25+
- [x] Get properties
2626
- [ ] Modify properties
2727
- [ ] Support for native distributed load testing
2828
- [ ] Support for distributed load testing through multiple injectors executing the same test
29-
- [ ] Document REST API
29+
- [ ] Initial documentation of the REST API
3030
- [ ] Restructure code-base so it's easier to read and maintain
31+
- [ ] Publish version __1.0.0__ to [JMeter-Plugins](https://jmeter-plugins.org/)
3132

3233
## Known issues/limitations
3334

@@ -36,6 +37,69 @@ As of right now, I am aware of a few limitations;
3637
* Of course, everything that's not checked on the roadmap is not working.
3738
* The live changes plugin currently only works with one Thread Group. There seems to be issues when more than one thread groups are involved in a test plan.
3839

40+
## Setup
41+
42+
1. Download the latest JAR from the release section
43+
2. Move the file to your `JMETER_HOME/lib/ext` folder
44+
3. Start JMeter, load your test plan
45+
4. Add the `Live Changes Config` element to your Thread Group
46+
5. Set the port you want to be able to communicate with (defaults to `7566`)
47+
6. Start your test
48+
7. By using any HTTP client (Postman, Insomnia, cURL, etc.) communicate with the REST API to change your test's values
49+
50+
** The API documentation is still under construction **
51+
52+
## Temporary API Doc
53+
54+
`GET /variables`: Retrieves the variables declared for your test
55+
56+
---
57+
58+
`POST /variables`: Send (as JSON) your variables changes.
59+
60+
Example:
61+
```json
62+
{
63+
"myInt": 1,
64+
"myString": "foo"
65+
}
66+
```
67+
68+
---
69+
70+
`GET /threads`: Retrieves the number of active threads.
71+
72+
---
73+
74+
`POST /threads`: Send (as JSON) your new active threads number.
75+
76+
Example:
77+
```json
78+
{
79+
"threadNum": 5
80+
}
81+
```
82+
83+
---
84+
85+
`GET /properties`: Retrieves the properties declared for your test
86+
87+
---
88+
89+
`POST /properties`: Send (as JSON) your properties changes.
90+
91+
Example:
92+
```json
93+
{
94+
"myProp": "bar"
95+
}
96+
```
97+
98+
---
99+
100+
101+
102+
39103
## Contributing
40104
This plugin is licensed under the MIT license.
41105

src/main/java/io/github/delirius325/jmeter/config/livechanges/LiveChanges.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ public void checkForThreadChanges(ThreadGroup threadGroup, LoopIterationEvent ev
7272
if(diff < 0) {
7373
threadGroup.addNewThread(0, new StandardJMeterEngine());
7474
} else {
75-
logger.warn("Stopping: " + threadName + "-" + threadGroup.getNumThreads());
7675
threadGroup.stopThread(threadName + "-" + threadGroup.numberOfActiveThreads(), true);
7776
}
7877
}
@@ -87,11 +86,18 @@ public void checkForThreadChanges(ThreadGroup threadGroup, LoopIterationEvent ev
8786
}
8887

8988
public void checkForVariableChanges(JMeterVariables vars, LoopIterationEvent event) {
90-
jMeterVariables = vars;
91-
JMeterContextService.getContext().setVariables(jMeterVariables);
89+
if(event.getIteration() == 1) {
90+
jMeterVariables = vars;
91+
} else {
92+
JMeterContextService.getContext().setVariables(jMeterVariables);
93+
}
9294
}
9395
public void checkForPropertyChanges(Properties props, LoopIterationEvent event) {
94-
jMeterProperties = props;
96+
if(event.getIteration() == 1) {
97+
jMeterProperties = props;
98+
} else {
99+
// JMeterContextService.getContext().setVariables(jmete);
100+
}
95101
}
96102

97103

src/main/java/io/github/delirius325/jmeter/config/livechanges/api/App.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,14 @@ public void handleHttpRequest(HttpRequest request, HttpResponse response, HttpCo
7676
@Override
7777
public void handleHttpRequest(HttpRequest request, HttpResponse response, HttpControl control) throws Exception {
7878
JSONObject json = new JSONObject(request.body());
79-
JMeterVariables originalVars = LiveChanges.getjMeterVariables();
80-
JMeterVariables newVars = new JMeterVariables();
81-
82-
originalVars.entrySet().forEach(entry -> {
83-
newVars.put(entry.getKey(), entry.getValue().toString());
79+
JMeterVariables vars = LiveChanges.getjMeterVariables();
80+
vars.entrySet().forEach(entry -> {
8481
if(json.has(entry.getKey()) && (json.get(entry.getKey()) != entry.getValue().toString())) {
8582
json.put(entry.getKey(), json.get(entry.getKey()));
83+
vars.put(entry.getKey(), json.get(entry.getKey()).toString());
8684
}
8785
});
88-
LiveChanges.setjMeterVariables(newVars);
86+
LiveChanges.setjMeterVariables(vars);
8987
jsonSetInfo(json, "success", "Variables were changed.");
9088
response.content(json.toString()).header("Content-Type", "application/json").end();
9189
}

0 commit comments

Comments
 (0)