JMeter-在变量/属性中存储/更新哈希图对象 [英] JMeter - Store/update a hashmap object in a variable/property
问题描述
我需要在JSR233 sampler
内创建一个哈希映射,其中将包含我将使用Java Request Sampler
调用的外部Java实用程序的某些标头和属性元素.我将需要创建许多哈希图,因为键值对将根据我测试的系统而有所不同.例如,我将不得不为每个哈希映射更改JMSReplyTo
,JMSCorrelationID
,$TextBody:
字段.所有这些都是在一个线程组中完成的,但是我可能还想在以后的其他线程组中实现它.
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.
我应该如何制定测试计划?是否可以创建一个保存哈希图的全局变量?然后在相应的
JSR223 Sampler
中,对于每个测试,修改变量的值?
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?
我不知道何时使用属性和何时使用变量.在这种情况下,我希望1
var或属性在我创建新的哈希映射对象时在整个测试计划中都会改变.我想知道这条路线是否可行,或者是否有其他建议.
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.
我之所以要在JMeter中创建HashMap对象,是因为我不想拥有Java实用程序将为键值对读取和解析的成千上万个txt文件(这些值在中有所不同)每个 txt文件).
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).
相反,我想知道是否有创建该HashMap的方法 Jmeter中的对象并将其存储在可以 在我的
Java Request
中作为参数传递.
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.
推荐答案
而不是使用常规的get put操作
Instead of using regular get put operations
vars.get("map"); vars.put("map", map);
您可以对字符串以外的对象使用get put操作:
You can use get put operations on Objects other than string:
vars.putObject("map", map);
稍后再获取地图:
map = vars.getObject("map");
这篇关于JMeter-在变量/属性中存储/更新哈希图对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!