Reputation: 71
I have a thread group, which runs multiple threads concurrently. Each thread makes a request using an ID from a csv file. So different threads within the thread group can end up making a request with the same ID over time. I want to use the cookie that is returned, for the specific ID in the request, even though its made by a different thread.
At the moment I have a Regular Expression Extractor pulling the cookie value, which created a variable based on its ID, for example, where ID is 56789 and the cookie is 1234, the variable would be 56789_1234.
I then use ${__V(${id}_g1)}
to pull the cookie, associated with a specific ID for another request.
(Essentially a bunch of variables are created, prefixed with the ID and the last returned cookie value, and each subsequent request can then use the ID for its request to pull out the correct cookie)
And then create the cookie as so:
import org.apache.jmeter.protocol.http.control.CookieManager;
import org.apache.jmeter.protocol.http.control.Cookie;
CookieManager manager = sampler.getCookieManager();
Cookie AWSALB = new Cookie("AWSALB","${cookieVal}","domain","path",false,Long.MAX_VALUE);
manager.add(AWSALB);
(I assign ${__V(${id}_g1)} to 'cookieVal' using jp@gc - Set Variables Action)
However, I still cant share the range of variables that are being created amongst all threads.
I've tried properties, but I believe it only works between Thread Groups, and if the groups run consecutively.
I'd like all threads within the group to be able to read all the variables extracted by other threads.
Upvotes: 1
Views: 1524
Reputation: 71
Although trying properties, I didn't seem to get it to work. Even though the properties were created (as identified in Debug Postprocessor), I still couldn't access them between threads for some reason.
However I solved this by using Beanshell Samplers before and after the request, writing out the single cookie value to an individual txt file per ID, with the txt files name being the ID. Each time any thread makes a request with this ID, it then updates the value in the corresponding txt file, and then before each request, reads the specific txt file for that ID to retrieve the last returned cookie.
UPDATE
As the number of threads increased, so did the possibility of threads becoming blocked when trying to access/write to the same .txt file at the same time.
I switched to using __CSVRead(), which so far has worked well.
Upvotes: 0
Reputation: 168147
Upvotes: 1