You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Andrey Beznogov <an...@googlemail.com> on 2008/07/07 14:18:23 UTC

Branching in tests

Hello.

I was trying to prepare some tests using JMeter, and its seems that
existing logic controllers are just not enough.

In my test plan, I wanted to have some branching - i.e. I wanted to
group together some test "branches" (Simple Controllers with some HTTP
Requests inside) under some ControllerX, so that for every iteration
only one of the branches will be ran with some set probability. So,
RandomController may be called a simpler version of such ControllerX -
since it also runs only one of its children, with equal probability
for all of them.

What is the easiest way to implement such a controller in JMeter? As I
can see it now, it may be either done by e.g. using additional Java
code for Java Request Sampler (which will do the random choosing) plus
Switch Controller, or writing a custom Controller as a plugin (which
is most likely much harder). But who knows - maybe it was already done
before. What could you suggest?

Regards,
Andrey

-- 
diem perdidi

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


Re: Branching in tests

Posted by kirk <ki...@gmail.com>.
Hi all,

I just received my copy of Apache JMeter from Packt Publishing. I'll be 
reviewing it for our website, www.javaperformancetuning.com and 
www.theserverside.com. At 108 pages I expect I'll be finished the book 
in a very short, single sitting. Not that I have anything against short 
books, some of the most useful books that I've read have been short.

Does Emily happen to monitor this list? If so, it could be useful to 
have some contact prior to publishing.

Regards,
Kirk Pepperdine

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


Re: Branching in tests

Posted by sebb <se...@gmail.com>.
On 08/07/2008, Andrey Beznogov <an...@googlemail.com> wrote:
> Hi,
>
>  So as I understand, the script will be something like
>
>
>   Random generator = new Random();
>   double myRandom = generator.nextDouble();
>   if (myRandom < 0.9) {
>
>          return 0;
>
>   } else if (myRandom < 0.95) {
>
>          return 1;
>   } else {
>          return 2;
>   }
>
>  instead. But where should I put my BeanShell Sampler then?

In the bin ;-)

> Should I
>  add it to the Switch Controller as a child? How do I show JMeter that
>  the returned value should be passed to the Switch?
>

Switch Value:  ${__BeanShell(script goes here)}

Or you can define a function in the BeanShellFunction.bshrc file and
call the function.

>  Regards,
>
> Andrey
>
>
>  On Mon, Jul 7, 2008 at 8:15 PM, sebb <se...@gmail.com> wrote:
>  > On 07/07/2008, Andrey Beznogov <an...@googlemail.com> wrote:
>  >> Hi,
>  >>
>  >>  that worked for sure - thanks for your advice! I guess Ill be using
>  >>  BeanShellSampler and Processors a lot in my tests.
>  >>
>  >>  In my case (3 options in the Switch Controller) I just had to add a
>  >>  simple BeanShell Sampler just before the Switch Controller with some
>  >>  very simple Java code
>  >>
>  >
>  >>  Random generator = new Random();
>  >>  double myRandom = generator.nextDouble();
>  >>  if (myRandom < 0.9) {
>  >>         vars.put("REPORT_SWITCH","0");
>  >>  } else if (myRandom < 0.95) {
>  >>         vars.put("REPORT_SWITCH","1");
>  >>  } else {
>  >>         vars.put("REPORT_SWITCH","2");
>  >>  }
>  >>
>  >>  and then use the ${REPORT_SWITCH} in the following Switch Controller.
>  >
>  > For a short script like this it might be better to use a function
>  > which returns the value directly to the Switch Controller - i.e.
>  > instead of "vars.put()" use "return value".
>  >
>  > You could use BeansShell, Javascript or Jexl.
>  >
>  >
>  >>  Regards,
>  >>  Andrey
>  >>
>  >>
>  >>  On Mon, Jul 7, 2008 at 4:35 PM, Ronan Klyne <ro...@groupbc.com> wrote:
>  >>  > Andrey Beznogov wrote:
>  >>  >>
>  >>  >> Hello.
>  >>  >>
>  >>  >> I was trying to prepare some tests using JMeter, and its seems that
>  >>  >> existing logic controllers are just not enough.
>  >>  >>
>  >>  >> In my test plan, I wanted to have some branching - i.e. I wanted to
>  >>  >> group together some test "branches" (Simple Controllers with some HTTP
>  >>  >> Requests inside) under some ControllerX, so that for every iteration
>  >>  >> only one of the branches will be ran with some set probability. So,
>  >>  >> RandomController may be called a simpler version of such ControllerX -
>  >>  >> since it also runs only one of its children, with equal probability
>  >>  >> for all of them.
>  >>  >>
>  >>  >> What is the easiest way to implement such a controller in JMeter? As I
>  >>  >> can see it now, it may be either done by e.g. using additional Java
>  >>  >> code for Java Request Sampler (which will do the random choosing) plus
>  >>  >> Switch Controller, or writing a custom Controller as a plugin (which
>  >>  >> is most likely much harder). But who knows - maybe it was already done
>  >>  >> before. What could you suggest?
>  >>  >>
>  >>  >> Regards,
>  >>  >> Andrey
>  >>  >>
>  >>  >
>  >>  > I did this with a bit of beanshell to do the weighted random selection and
>  >>  > switch controller to do the actual switch. I'd paste the code in, but
>  >>  > unfortunately I can't find it at present...
>  >>  >
>  >>  >        # r
>  >>  >
>  >>  > --
>  >>  > Ronan Klyne
>  >>  > Business Collaborator Developer
>  >>  > Tel: +44 01189 028518
>  >>  > ronan.klyne@groupbc.com
>  >>  > www.groupbc.com
>  >>  >
>  >>  > ---------------------------------------------------------------------
>  >>  > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>  >>  > For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>  >>  >
>  >>  >
>  >>
>  >>
>  >>
>  >>
>  >> --
>  >>  diem perdidi
>  >>
>  >>
>  >>  ---------------------------------------------------------------------
>  >>  To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>  >>  For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>  >>
>  >>
>  >
>  > ---------------------------------------------------------------------
>  > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>  > For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>  >
>  >
>
>
>
>  --
>  diem perdidi
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>  For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>

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


Re: Branching in tests

Posted by Andrey Beznogov <an...@googlemail.com>.
Hi,

So as I understand, the script will be something like

  Random generator = new Random();
  double myRandom = generator.nextDouble();
  if (myRandom < 0.9) {
         return 0;
  } else if (myRandom < 0.95) {
         return 1;
  } else {
         return 2;
  }

instead. But where should I put my BeanShell Sampler then? Should I
add it to the Switch Controller as a child? How do I show JMeter that
the returned value should be passed to the Switch?

Regards,
Andrey

On Mon, Jul 7, 2008 at 8:15 PM, sebb <se...@gmail.com> wrote:
> On 07/07/2008, Andrey Beznogov <an...@googlemail.com> wrote:
>> Hi,
>>
>>  that worked for sure - thanks for your advice! I guess Ill be using
>>  BeanShellSampler and Processors a lot in my tests.
>>
>>  In my case (3 options in the Switch Controller) I just had to add a
>>  simple BeanShell Sampler just before the Switch Controller with some
>>  very simple Java code
>>
>
>>  Random generator = new Random();
>>  double myRandom = generator.nextDouble();
>>  if (myRandom < 0.9) {
>>         vars.put("REPORT_SWITCH","0");
>>  } else if (myRandom < 0.95) {
>>         vars.put("REPORT_SWITCH","1");
>>  } else {
>>         vars.put("REPORT_SWITCH","2");
>>  }
>>
>>  and then use the ${REPORT_SWITCH} in the following Switch Controller.
>
> For a short script like this it might be better to use a function
> which returns the value directly to the Switch Controller - i.e.
> instead of "vars.put()" use "return value".
>
> You could use BeansShell, Javascript or Jexl.
>
>
>>  Regards,
>>  Andrey
>>
>>
>>  On Mon, Jul 7, 2008 at 4:35 PM, Ronan Klyne <ro...@groupbc.com> wrote:
>>  > Andrey Beznogov wrote:
>>  >>
>>  >> Hello.
>>  >>
>>  >> I was trying to prepare some tests using JMeter, and its seems that
>>  >> existing logic controllers are just not enough.
>>  >>
>>  >> In my test plan, I wanted to have some branching - i.e. I wanted to
>>  >> group together some test "branches" (Simple Controllers with some HTTP
>>  >> Requests inside) under some ControllerX, so that for every iteration
>>  >> only one of the branches will be ran with some set probability. So,
>>  >> RandomController may be called a simpler version of such ControllerX -
>>  >> since it also runs only one of its children, with equal probability
>>  >> for all of them.
>>  >>
>>  >> What is the easiest way to implement such a controller in JMeter? As I
>>  >> can see it now, it may be either done by e.g. using additional Java
>>  >> code for Java Request Sampler (which will do the random choosing) plus
>>  >> Switch Controller, or writing a custom Controller as a plugin (which
>>  >> is most likely much harder). But who knows - maybe it was already done
>>  >> before. What could you suggest?
>>  >>
>>  >> Regards,
>>  >> Andrey
>>  >>
>>  >
>>  > I did this with a bit of beanshell to do the weighted random selection and
>>  > switch controller to do the actual switch. I'd paste the code in, but
>>  > unfortunately I can't find it at present...
>>  >
>>  >        # r
>>  >
>>  > --
>>  > Ronan Klyne
>>  > Business Collaborator Developer
>>  > Tel: +44 01189 028518
>>  > ronan.klyne@groupbc.com
>>  > www.groupbc.com
>>  >
>>  > ---------------------------------------------------------------------
>>  > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>>  > For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>  >
>>  >
>>
>>
>>
>>
>> --
>>  diem perdidi
>>
>>
>>  ---------------------------------------------------------------------
>>  To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>>  For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>



-- 
diem perdidi

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


Re: Branching in tests

Posted by sebb <se...@gmail.com>.
On 07/07/2008, Andrey Beznogov <an...@googlemail.com> wrote:
> Hi,
>
>  that worked for sure - thanks for your advice! I guess Ill be using
>  BeanShellSampler and Processors a lot in my tests.
>
>  In my case (3 options in the Switch Controller) I just had to add a
>  simple BeanShell Sampler just before the Switch Controller with some
>  very simple Java code
>

>  Random generator = new Random();
>  double myRandom = generator.nextDouble();
>  if (myRandom < 0.9) {
>         vars.put("REPORT_SWITCH","0");
>  } else if (myRandom < 0.95) {
>         vars.put("REPORT_SWITCH","1");
>  } else {
>         vars.put("REPORT_SWITCH","2");
>  }
>
>  and then use the ${REPORT_SWITCH} in the following Switch Controller.

For a short script like this it might be better to use a function
which returns the value directly to the Switch Controller - i.e.
instead of "vars.put()" use "return value".

You could use BeansShell, Javascript or Jexl.


>  Regards,
>  Andrey
>
>
>  On Mon, Jul 7, 2008 at 4:35 PM, Ronan Klyne <ro...@groupbc.com> wrote:
>  > Andrey Beznogov wrote:
>  >>
>  >> Hello.
>  >>
>  >> I was trying to prepare some tests using JMeter, and its seems that
>  >> existing logic controllers are just not enough.
>  >>
>  >> In my test plan, I wanted to have some branching - i.e. I wanted to
>  >> group together some test "branches" (Simple Controllers with some HTTP
>  >> Requests inside) under some ControllerX, so that for every iteration
>  >> only one of the branches will be ran with some set probability. So,
>  >> RandomController may be called a simpler version of such ControllerX -
>  >> since it also runs only one of its children, with equal probability
>  >> for all of them.
>  >>
>  >> What is the easiest way to implement such a controller in JMeter? As I
>  >> can see it now, it may be either done by e.g. using additional Java
>  >> code for Java Request Sampler (which will do the random choosing) plus
>  >> Switch Controller, or writing a custom Controller as a plugin (which
>  >> is most likely much harder). But who knows - maybe it was already done
>  >> before. What could you suggest?
>  >>
>  >> Regards,
>  >> Andrey
>  >>
>  >
>  > I did this with a bit of beanshell to do the weighted random selection and
>  > switch controller to do the actual switch. I'd paste the code in, but
>  > unfortunately I can't find it at present...
>  >
>  >        # r
>  >
>  > --
>  > Ronan Klyne
>  > Business Collaborator Developer
>  > Tel: +44 01189 028518
>  > ronan.klyne@groupbc.com
>  > www.groupbc.com
>  >
>  > ---------------------------------------------------------------------
>  > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>  > For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>  >
>  >
>
>
>
>
> --
>  diem perdidi
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>  For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>

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


Re: Branching in tests

Posted by Andrey Beznogov <an...@googlemail.com>.
Hi,

that worked for sure - thanks for your advice! I guess Ill be using
BeanShellSampler and Processors a lot in my tests.

In my case (3 options in the Switch Controller) I just had to add a
simple BeanShell Sampler just before the Switch Controller with some
very simple Java code

Random generator = new Random();
double myRandom = generator.nextDouble();
if (myRandom < 0.9) {
	vars.put("REPORT_SWITCH","0");
} else if (myRandom < 0.95) {
	vars.put("REPORT_SWITCH","1");
} else {
	vars.put("REPORT_SWITCH","2");
}

and then use the ${REPORT_SWITCH} in the following Switch Controller.

Regards,
Andrey

On Mon, Jul 7, 2008 at 4:35 PM, Ronan Klyne <ro...@groupbc.com> wrote:
> Andrey Beznogov wrote:
>>
>> Hello.
>>
>> I was trying to prepare some tests using JMeter, and its seems that
>> existing logic controllers are just not enough.
>>
>> In my test plan, I wanted to have some branching - i.e. I wanted to
>> group together some test "branches" (Simple Controllers with some HTTP
>> Requests inside) under some ControllerX, so that for every iteration
>> only one of the branches will be ran with some set probability. So,
>> RandomController may be called a simpler version of such ControllerX -
>> since it also runs only one of its children, with equal probability
>> for all of them.
>>
>> What is the easiest way to implement such a controller in JMeter? As I
>> can see it now, it may be either done by e.g. using additional Java
>> code for Java Request Sampler (which will do the random choosing) plus
>> Switch Controller, or writing a custom Controller as a plugin (which
>> is most likely much harder). But who knows - maybe it was already done
>> before. What could you suggest?
>>
>> Regards,
>> Andrey
>>
>
> I did this with a bit of beanshell to do the weighted random selection and
> switch controller to do the actual switch. I'd paste the code in, but
> unfortunately I can't find it at present...
>
>        # r
>
> --
> Ronan Klyne
> Business Collaborator Developer
> Tel: +44 01189 028518
> ronan.klyne@groupbc.com
> www.groupbc.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>



-- 
diem perdidi

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


Re: Branching in tests

Posted by Ronan Klyne <ro...@groupbc.com>.
Andrey Beznogov wrote:
> Hello.
> 
> I was trying to prepare some tests using JMeter, and its seems that
> existing logic controllers are just not enough.
> 
> In my test plan, I wanted to have some branching - i.e. I wanted to
> group together some test "branches" (Simple Controllers with some HTTP
> Requests inside) under some ControllerX, so that for every iteration
> only one of the branches will be ran with some set probability. So,
> RandomController may be called a simpler version of such ControllerX -
> since it also runs only one of its children, with equal probability
> for all of them.
> 
> What is the easiest way to implement such a controller in JMeter? As I
> can see it now, it may be either done by e.g. using additional Java
> code for Java Request Sampler (which will do the random choosing) plus
> Switch Controller, or writing a custom Controller as a plugin (which
> is most likely much harder). But who knows - maybe it was already done
> before. What could you suggest?
> 
> Regards,
> Andrey
> 

I did this with a bit of beanshell to do the weighted random selection 
and switch controller to do the actual switch. I'd paste the code in, 
but unfortunately I can't find it at present...

	# r

-- 
Ronan Klyne
Business Collaborator Developer
Tel: +44 01189 028518
ronan.klyne@groupbc.com
www.groupbc.com

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