Reputation: 119
I have a scenario which I'm having trouble to implement in Jmeter.
Scenario Create 2 threads group.
Thread Group 1: should generate 100+ specific Ids (via a POST) and save the Ids somewhere to be used by other Threads Group.
Thread Group 2: Should be able to read the Ids created in Thread Group 1. The Thread can be set to 10 users, each user accessing 10 Ids from the above. For example user 1 will get the first 10 ids generated in Thread Group 1, so will user 2 and so on.
Problem:
I have managed to create Thread Group 1 which generates 100 specific Ids I can only managed to save a single Id using the BeanShell Assertion using ${__setProperty(Id, ${Id})}.
However I am not sure how to save all those Ids in file or memory so that Thread Group 2 can access.
Also how can I set Thread Group 2 to pick the Ids (i.e. set the Number of Thread Users to 10, then the first user will pick the 10 Ids generated in Thread Group 1 and son on).
Currently I am investigating Jmeter and Gatling and see which tool is capable of solving these type of scenarios.
Thanks
Upvotes: 0
Views: 141
Reputation: 983
First thing, choose option Run Thread Groups consecutively from your test plan so that thread groups start one at a time.
Assuming you are extracting the IDs from thread group 1 using post processor, add a BeanShell PostProcessor as a child of your post request (thread group 1) withe below code in code area
FileWriter fstream = new FileWriter("pathToYourFileDirectory/IDs.csv",true);
BufferedWriter out = new BufferedWriter(fstream);
String Id = vars.get("ID");// ID should be the reference name of your post processor which extract the ID
if(Id.equals("NOT_FOUND")){// NOT_FOUND is the default value for your post processor, in case the post request failed, you will not type anything into the csv file
out.close();
}
else{
out.write(Id);
out.write(System.getProperty("line.separator"));
out.close();
}
The above code will write your IDs into csv file IDs.csv
.
Now add CSV Data Set Config element into your second thread group and fill in the fields as below
IDs.csv
Now you can use Jmeter variable ${Id}
which will hold the ID value.
Upvotes: 2