0
votes

I have created a custom jmeter java sampler that sends requests to an HTTP endpoint in a loop and parses the responses. Multiple threads are expected to run this sampler in a single thread group.

The requests are parameterized with an ID and I need every thread to lookup random name to ID mappings in a hashmap. I would like to load the mapping from a csv file at the beginning of a test.

It was suggested that I might use a beanshell sampler inside of a setup thread group to read from the csv, create the hashmap, and store it in a JMeter property using something like props.put(). Can someone tell me if this is a reasonable approach and if so, how do I access the particular JMeter property inside the custom sampler?

I found this answer: Single thread initialization for Jmeter with multiple sampler which hints at what I'd like to do but does not provide details.

1

1 Answers

-1
votes

It is, however since JMeter 3.1 it is recommended to use JSR223 Test Elements and Groovy language for any form of scripting.

So in JSR223 Sampler you can use props.put('foo', myMap) and in Java Request you can refer it like:

Map myMap = (HashMap)context.getJMeterProperties().get("foo");