问题
I need to create a hash-map inside of a JSR233 sampler
that will contain certain headers and properties elements for an external java utility that I will call using a Java Request Sampler
. I am going to need to create many hashmaps as the key-value pairs will vary based on the systems I am testing. For example, I am going to have to change the JMSReplyTo
, the JMSCorrelationID
, $TextBody:
fields for every hash-map. All of this is done inside one thread group, but I may also want to implement it in other thread groups down the road.
How should I structure my Test Plan? Is it possible to create a global variable that will hold the hash-map? And then inside the respective
JSR223 Sampler
, for each test, modify the value of the variable?
I don't know when to use properties and when to use variables. In this case I would like 1
var or property that will change throughout my test-plan whenever I create a new hash-map object. I would like to know if this route is feasible, or if an alternative is advised.
The reason I would like to create a HashMap object in JMeter is because I don't want to have thousands of txt files that the Java utility will read and parse for the key-value pairs (those values vary in every txt file).
Instead I was wondering if there was a way to create this HashMap object in Jmeter and store it in a variable/property object that can be passed as a parameter in my
Java Request
.
I would appreciate it if someone guide me in the right direction.
回答1:
Instead of using regular get put operations
vars.get("map"); vars.put("map", map);
You can use get put operations on Objects other than string:
vars.putObject("map", map);
And get map later:
map = vars.getObject("map");
回答2:
- JMeter Variables are local to each JMeter Thread, cannot be shared between different Thread Groups. Used to hold user-specific values. Can be accessed as
vars
from JSR223 Elements, see JavaDoc for all available methods and fields. - JMeter Properties are "normal" Java properties, they are global for the whole JVM and can be accessed from any Thread in any Thread Group.
Assuming the above if you have many user-specific HashMaps - go for JMeter Variables. If you have one global HashMap and/or you need to access it from different Thread Groups - go for properties.
来源:https://stackoverflow.com/questions/45696945/jmeter-store-update-a-hashmap-object-in-a-variable-property