Jun Zhuang wrote:
> Hi,
>
> My understanding is I could save an object using props.put() and retrieve it
> later using props.get() but instead I am getting a null, what can be the
> reason?
>
> Following is what I am trying to do:
>
> 1. In a setup thread group, using a Beanshell sampler to create and
> KafkaProducer object, then save the object with props.put("KafkaProducer",
> producer);
>
> within the same sampler, if I do
> log.info(props.get("KafkaProducer").getClass()); I get the expected class.
>
> 2. In a different Beanshell sampler, retrieve the object with
> props.get("KafkaProducer"); but I am getting a null.
>
> What's wrong with this?
>
> Thanks,
> Jun
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
Your understanding is correct and it should work as you described given
the Sampler which is setting the property is executed before the Sampler
which is getting the property.
Check jmeter.log file
<https://jmeter.apache.org/usermanual/get-started.html#logging> for any
suspicious entries, maybe there is a syntax error somewhere which is not
being reported.
Also be informed that starting from JMeter 3.1 it's recommended to use
JSR223 Test Elements and Groovy language for scripting
<https://jmeter.apache.org/usermanual/best-practices.html#bsh_scripting>
as using Beanshell is some form of a performance anti-pattern
<https://jmeter.apache.org/usermanual/best-practices.html#bsh_scripting>
so consider migrating.
And last but not the least in the majority of cases you should be
creating the producer once per thread so it makes sense to go for Once
Only Controller
<https://jmeter.apache.org/usermanual/component_reference.html#Once_Only_Controller>
instead of using setUp Thread Group so it worth checking the setup of
the upstream system you're trying to simulate and replicate its network
footprint with 100% accuracy.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]