You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Alexandre Gattiker <ag...@gmail.com> on 2020/03/15 15:22:40 UTC

Run code block only once with JSR223

I'm trying to write a JSR 223 Sampler that sends messages to Kafka,
essentially replicating PepperBox (
https://github.com/GSLabDev/pepper-box/blob/master/src/main/java/com/gslab/pepper/sampler/PepperBoxKafkaSampler.java)
in
Groovy.

Is there a way to replicate the behavior of setupTest(), i.e. run a code
block only once before all iterations (to create the Kafka producer)?

Re: Run code block only once with JSR223

Posted by Mariusz W <ma...@gmail.com>.
Hi,
It's ok - Properties is subclass of Hashtable
https://docs.oracle.com/javase/8/docs/api/java/util/Hashtable.html#put-K-V-
so you can use put method on props in JSR 223 Sampler (
https://jmeter.apache.org/usermanual/component_reference.html#JSR223_Sampler
)

Regards,
Mariusz

On Sun, 15 Mar 2020 at 17:56, Alexandre Gattiker <ag...@gmail.com>
wrote:

> Thanks a lot! I was able to set an object as a property and get this to
> work. It also turns out that KafkaProducer is thread safe, so I only need
> to create one instance in my setUp thread group.
>
> However - this violates the contract of the Properties class, which should
> have only strings as keys and values (
> https://docs.oracle.com/javase/8/docs/api/java/util/Properties.html). Not
> sure it's a proper thing to do.
>
> On Sun, Mar 15, 2020 at 5:37 PM Sergio Boso <se...@bosoconsulting.it>
> wrote:
>
> > Hi Alexandre,
> >
> >
> > never tried this, but I think you can set property objects.
> > Have a look at
> >
> >
> https://jmeter.apache.org/api/org/apache/jmeter/testelement/property/ObjectProperty.html
> >
> > You should be able to get and set properties.
> > Let me know if this is successful!
> >
> > regards
> >
> > Sergio
> >
> > Il 15/03/2020 16:52, Alexandre Gattiker ha scritto:
> > > Thanks Sergio. So I would have to say create 10 Kafka Producers in my
> > setUp Thread Group, and then pass them to my standard Thread
> > > Group? How? As I understand, JMeter variables can't be shared between
> > Thread groups, and Properties can, but are limited to String
> > > values.
> > >
> > > On Sun, Mar 15, 2020 at 4:31 PM Sergio Boso <sergio@bosoconsulting.it
> > <ma...@bosoconsulting.it>> wrote:
> > >
> > >     Hi, you can easily add a "setUp Thread Group" end insert proper
> > samplers below this thread group
> > >
> > >     Regards
> > >     Sergio
> > >
> > >
> > >     Il 15/03/2020 16:22, Alexandre Gattiker ha scritto:
> > >     > I'm trying to write a JSR 223 Sampler that sends messages to
> Kafka,
> > >     > essentially replicating PepperBox (
> > >     >
> >
> https://github.com/GSLabDev/pepper-box/blob/master/src/main/java/com/gslab/pepper/sampler/PepperBoxKafkaSampler.java
> > )
> > >     > in
> > >     > Groovy.
> > >     >
> > >     > Is there a way to replicate the behavior of setupTest(), i.e. run
> > a code
> > >     > block only once before all iterations (to create the Kafka
> > producer)?
> > >     --
> > >
> > >     Ing. Sergio Boso
> > >
> > >
> > >
> >
> >
> > --
> >
> > Ing. Sergio Boso
> >
> >
> >
> >
>

Re: Run code block only once with JSR223

Posted by Alexandre Gattiker <ag...@gmail.com>.
Thanks a lot! I was able to set an object as a property and get this to
work. It also turns out that KafkaProducer is thread safe, so I only need
to create one instance in my setUp thread group.

However - this violates the contract of the Properties class, which should
have only strings as keys and values (
https://docs.oracle.com/javase/8/docs/api/java/util/Properties.html). Not
sure it's a proper thing to do.

On Sun, Mar 15, 2020 at 5:37 PM Sergio Boso <se...@bosoconsulting.it>
wrote:

> Hi Alexandre,
>
>
> never tried this, but I think you can set property objects.
> Have a look at
>
> https://jmeter.apache.org/api/org/apache/jmeter/testelement/property/ObjectProperty.html
>
> You should be able to get and set properties.
> Let me know if this is successful!
>
> regards
>
> Sergio
>
> Il 15/03/2020 16:52, Alexandre Gattiker ha scritto:
> > Thanks Sergio. So I would have to say create 10 Kafka Producers in my
> setUp Thread Group, and then pass them to my standard Thread
> > Group? How? As I understand, JMeter variables can't be shared between
> Thread groups, and Properties can, but are limited to String
> > values.
> >
> > On Sun, Mar 15, 2020 at 4:31 PM Sergio Boso <sergio@bosoconsulting.it
> <ma...@bosoconsulting.it>> wrote:
> >
> >     Hi, you can easily add a "setUp Thread Group" end insert proper
> samplers below this thread group
> >
> >     Regards
> >     Sergio
> >
> >
> >     Il 15/03/2020 16:22, Alexandre Gattiker ha scritto:
> >     > I'm trying to write a JSR 223 Sampler that sends messages to Kafka,
> >     > essentially replicating PepperBox (
> >     >
> https://github.com/GSLabDev/pepper-box/blob/master/src/main/java/com/gslab/pepper/sampler/PepperBoxKafkaSampler.java
> )
> >     > in
> >     > Groovy.
> >     >
> >     > Is there a way to replicate the behavior of setupTest(), i.e. run
> a code
> >     > block only once before all iterations (to create the Kafka
> producer)?
> >     --
> >
> >     Ing. Sergio Boso
> >
> >
> >
>
>
> --
>
> Ing. Sergio Boso
>
>
>
>

Re: Run code block only once with JSR223

Posted by Sergio Boso <se...@bosoconsulting.it>.
Hi Alexandre,


never tried this, but I think you can set property objects.
Have a look at
https://jmeter.apache.org/api/org/apache/jmeter/testelement/property/ObjectProperty.html

You should be able to get and set properties.
Let me know if this is successful!

regards

Sergio

Il 15/03/2020 16:52, Alexandre Gattiker ha scritto:
> Thanks Sergio. So I would have to say create 10 Kafka Producers in my setUp Thread Group, and then pass them to my standard Thread 
> Group? How? As I understand, JMeter variables can't be shared between Thread groups, and Properties can, but are limited to String 
> values.
>
> On Sun, Mar 15, 2020 at 4:31 PM Sergio Boso <sergio@bosoconsulting.it <ma...@bosoconsulting.it>> wrote:
>
>     Hi, you can easily add a "setUp Thread Group" end insert proper samplers below this thread group
>
>     Regards
>     Sergio
>
>
>     Il 15/03/2020 16:22, Alexandre Gattiker ha scritto:
>     > I'm trying to write a JSR 223 Sampler that sends messages to Kafka,
>     > essentially replicating PepperBox (
>     > https://github.com/GSLabDev/pepper-box/blob/master/src/main/java/com/gslab/pepper/sampler/PepperBoxKafkaSampler.java)
>     > in
>     > Groovy.
>     >
>     > Is there a way to replicate the behavior of setupTest(), i.e. run a code
>     > block only once before all iterations (to create the Kafka producer)?
>     -- 
>
>     Ing. Sergio Boso
>
>
>


-- 

Ing. Sergio Boso




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org


Re: Run code block only once with JSR223

Posted by Alexandre Gattiker <ag...@gmail.com>.
Thanks Sergio. So I would have to say create 10 Kafka Producers in my setUp
Thread Group, and then pass them to my standard Thread Group? How? As I
understand, JMeter variables can't be shared between Thread groups, and
Properties can, but are limited to String values.

On Sun, Mar 15, 2020 at 4:31 PM Sergio Boso <se...@bosoconsulting.it>
wrote:

> Hi, you can easily add a "setUp Thread Group" end insert proper samplers
> below this thread group
>
> Regards
> Sergio
>
>
> Il 15/03/2020 16:22, Alexandre Gattiker ha scritto:
> > I'm trying to write a JSR 223 Sampler that sends messages to Kafka,
> > essentially replicating PepperBox (
> >
> https://github.com/GSLabDev/pepper-box/blob/master/src/main/java/com/gslab/pepper/sampler/PepperBoxKafkaSampler.java
> )
> > in
> > Groovy.
> >
> > Is there a way to replicate the behavior of setupTest(), i.e. run a code
> > block only once before all iterations (to create the Kafka producer)?
> --
>
> Ing. Sergio Boso
>
>
>
>

Re: Run code block only once with JSR223

Posted by Sergio Boso <se...@bosoconsulting.it>.
Hi, you can easily add a "setUp Thread Group" end insert proper samplers below this thread group

Regards
Sergio


Il 15/03/2020 16:22, Alexandre Gattiker ha scritto:
> I'm trying to write a JSR 223 Sampler that sends messages to Kafka,
> essentially replicating PepperBox (
> https://github.com/GSLabDev/pepper-box/blob/master/src/main/java/com/gslab/pepper/sampler/PepperBoxKafkaSampler.java)
> in
> Groovy.
>
> Is there a way to replicate the behavior of setupTest(), i.e. run a code
> block only once before all iterations (to create the Kafka producer)?
-- 

Ing. Sergio Boso




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org