Ask a Question

sharing a variable across multiple threads in a load test

vavst4
New Contributor

sharing a variable across multiple threads in a load test

Hi, I'm using SoapUI free edition to run a multithreaded load test.

 

I would like to define a single data structure (e.g., aConcurrentHashMap) that all the test threads access.

If I define this in a test step (as a Groovy script), then each individual thread would create a separate copy of the HashMap, whereas I want each thread to access the same HashMap.

 

Is there any way I can define the HashMap in a global or testsuite scope so that its visible to all the threads?

 

 

 

3 REPLIES 3
vavst4
New Contributor

Re: sharing a variable across multiple threads in a load test

Quick update. I tried defining the hashmap inside my loadtest set up script and then accessing it in the test case, but this isn't working yet. In my loadtest setup script I have the following:

 

import java.util.concurrent.ConcurrentHashMap

ConcurrentHashMap hashmap= new ConcurrentHashMap();
hashmap.put("asdfsdfd", 2000)

context["stringtointmap"] = hashmap;

 

In a test step groovy script, I'm trying to write to this hashmap as follows:

 

ConcurrentHashMap hashmap= context.LoadTestContext["stringtointmap"];

hashmap.put("asdfdf", 2343)

 

When I run this I get an error "Cannot invoke method put on a null object"

 

Can someone explain teh proper way to do this?

nmrao
Community Hero

Re: sharing a variable across multiple threads in a load test

What I believe is that even setup script gets executed in each test run. And each time a new ConcurrentHasMap is getting created in this case. May be you can control the entire test execution from the groovy itself to avoid that which includes running of loadTest, this is what it comes to my head. May be there could be other ways too.


Regards,
Rao.
nmrao
Community Hero

Re: sharing a variable across multiple threads in a load test

Looks like you opened duplicate topic
I would suggest to continue with one thread please, just think of other people time as well. If someone knows answer, anyway he/she replies your question. Strongly discourage to open duplicates(at least of your own). Every question/query always do not take same time to respond, some may be peculiar, need more time to respond for the people on the forum, before that the question needs to be understood with the provided information. Also I understand you were in hurry with your work, but the same is case for others. Please be patient and thank you. Now onwards, please do followup on other thread.



Regards,
Rao.
cancel
Showing results for 
Search instead for 
Did you mean: