You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by esc <es...@informatik.uni-kiel.de> on 2014/03/15 11:13:43 UTC

Passing Parameters to Java Requests

Hello,

I am currently struggling with the Java Request Sampler of JMeter, and there 
is still an unsolved problem for me. The idea is as follows:

My Test Plan is intended to send several Java requests, each one targeting a 
different service method of the Java application under test. That is, a 
(unique) Java Sampler retrieves an information about the service to be 
invoked next and executes the related method. Therefore, a sub-class of 
AbstractJavaSamplerClient gets a default parameter named "service", which 
indicates some name of a service method to be called by the Sampler. The 
getDefaultParameters() method of AbstractJavaSamplerClient has been 
overwritten as follows:


    [...]

    @Override
    public Arguments getDefaultParameters() {

        Arguments defaultParameters = new Arguments();

        defaultParameters.addArgument("service", "${service}");
        return defaultParameters;
    }

    [...]


The core challenge for me is to pass an individual "service" parameter value 
for each Java Request, keeping the constant parameter name "service".

How can this be achieved?

The scope of User Defined Variables ranges obviously over the full Thread 
Group. In particular, setting a newly defined "service" variable above each 
Java Request does not help, since the last defined value will be always 
taken.

Is is possible to pass an individual parameter value to each Java Sampler, 
so that an execution sequence like


  Test Plan
    Thread Group
      Java Request <with ${service} = "s7">
      Java Request <with ${service} = "s2">
      Java Request <with ${service} = "s5">

      [...]


can be achieved? If yes, which JMeter Configuration Element can be used for 
it (the Java Request Sampler itself does not provide it, obviously)?


Thank you very much in advance! 


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


Re: Passing Parameters to Java Requests

Posted by esc <es...@informatik.uni-kiel.de>.
I just noticed that it -is- possible to pass the required parameters via 
Java Sampler GUI in JMeter (which one would expect); I was just confused 
about the ${}-notation in the examples of the JMeter Component Reference, 
which made me think that parameter values need to be defined via User 
Defined Variables elements.

Problem solved! :-)


--------------------------------------------------
From: "esc" <es...@informatik.uni-kiel.de>
Sent: Saturday, March 15, 2014 11:13 AM
To: "JMeter User List" <us...@jmeter.apache.org>
Subject: Passing Parameters to Java Requests

> Hello,
>
> I am currently struggling with the Java Request Sampler of JMeter, and 
> there is still an unsolved problem for me. The idea is as follows:
>
> My Test Plan is intended to send several Java requests, each one targeting 
> a different service method of the Java application under test. That is, a 
> (unique) Java Sampler retrieves an information about the service to be 
> invoked next and executes the related method. Therefore, a sub-class of 
> AbstractJavaSamplerClient gets a default parameter named "service", which 
> indicates some name of a service method to be called by the Sampler. The 
> getDefaultParameters() method of AbstractJavaSamplerClient has been 
> overwritten as follows:
>
>
>    [...]
>
>    @Override
>    public Arguments getDefaultParameters() {
>
>        Arguments defaultParameters = new Arguments();
>
>        defaultParameters.addArgument("service", "${service}");
>        return defaultParameters;
>    }
>
>    [...]
>
>
> The core challenge for me is to pass an individual "service" parameter 
> value for each Java Request, keeping the constant parameter name 
> "service".
>
> How can this be achieved?
>
> The scope of User Defined Variables ranges obviously over the full Thread 
> Group. In particular, setting a newly defined "service" variable above 
> each Java Request does not help, since the last defined value will be 
> always taken.
>
> Is is possible to pass an individual parameter value to each Java Sampler, 
> so that an execution sequence like
>
>
>  Test Plan
>    Thread Group
>      Java Request <with ${service} = "s7">
>      Java Request <with ${service} = "s2">
>      Java Request <with ${service} = "s5">
>
>      [...]
>
>
> can be achieved? If yes, which JMeter Configuration Element can be used 
> for it (the Java Request Sampler itself does not provide it, obviously)?
>
>
> Thank you very much in advance!
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
> For additional commands, e-mail: user-help@jmeter.apache.org
>
> 

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


Re: Passing Parameters to Java Requests

Posted by esc <es...@informatik.uni-kiel.de>.
Yes, I just noticed that :-) Thank you very much for your hint with the 
SleepTest.java example!


--------------------------------------------------
From: "sebb" <se...@gmail.com>
Sent: Saturday, March 15, 2014 11:43 AM
To: "JMeter Users List" <us...@jmeter.apache.org>
Subject: Re: Passing Parameters to Java Requests

> On 15 March 2014 10:13, esc <es...@informatik.uni-kiel.de> wrote:
>> Hello,
>>
>> I am currently struggling with the Java Request Sampler of JMeter, and 
>> there
>> is still an unsolved problem for me. The idea is as follows:
>>
>> My Test Plan is intended to send several Java requests, each one 
>> targeting a
>> different service method of the Java application under test. That is, a
>> (unique) Java Sampler retrieves an information about the service to be
>> invoked next and executes the related method. Therefore, a sub-class of
>> AbstractJavaSamplerClient gets a default parameter named "service", which
>> indicates some name of a service method to be called by the Sampler. The
>> getDefaultParameters() method of AbstractJavaSamplerClient has been
>> overwritten as follows:
>>
>>
>>    [...]
>>
>>    @Override
>>    public Arguments getDefaultParameters() {
>>
>>        Arguments defaultParameters = new Arguments();
>>
>>        defaultParameters.addArgument("service", "${service}");
>
> The second parameter should be a fixed default value.
> If there is none, use the empty String.
>
>>        return defaultParameters;
>>    }
>>
>>    [...]
>>
>>
>> The core challenge for me is to pass an individual "service" parameter 
>> value
>> for each Java Request, keeping the constant parameter name "service".
>>
>> How can this be achieved?
>
> Just configure your Java Sampler with the relevant value.
>
>> The scope of User Defined Variables ranges obviously over the full Thread
>> Group. In particular, setting a newly defined "service" variable above 
>> each
>> Java Request does not help, since the last defined value will be always
>> taken.
>
> You could use
>
> http://jmeter.apache.org/usermanual/component_reference.html#User_Parameters
>
> However, that is completely unnecessary.
>
>> Is is possible to pass an individual parameter value to each Java 
>> Sampler,
>
> Yes, you can configure this on your Java Sampler GUI.
>
>> so that an execution sequence like
>>
>>
>>  Test Plan
>>    Thread Group
>>      Java Request <with ${service} = "s7">
>>      Java Request <with ${service} = "s2">
>>      Java Request <with ${service} = "s5">
>>
>>      [...]
>>
>>
>> can be achieved? If yes, which JMeter Configuration Element can be used 
>> for
>> it (the Java Request Sampler itself does not provide it, obviously)?
>>
>>
>> Thank you very much in advance!
>
> Have a look a the code for SleepTest.java and look at how this class
> appears in the GUI.
>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
>> For additional commands, e-mail: user-help@jmeter.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
> For additional commands, e-mail: user-help@jmeter.apache.org
>
> 

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


Re: Passing Parameters to Java Requests

Posted by sebb <se...@gmail.com>.
On 15 March 2014 10:13, esc <es...@informatik.uni-kiel.de> wrote:
> Hello,
>
> I am currently struggling with the Java Request Sampler of JMeter, and there
> is still an unsolved problem for me. The idea is as follows:
>
> My Test Plan is intended to send several Java requests, each one targeting a
> different service method of the Java application under test. That is, a
> (unique) Java Sampler retrieves an information about the service to be
> invoked next and executes the related method. Therefore, a sub-class of
> AbstractJavaSamplerClient gets a default parameter named "service", which
> indicates some name of a service method to be called by the Sampler. The
> getDefaultParameters() method of AbstractJavaSamplerClient has been
> overwritten as follows:
>
>
>    [...]
>
>    @Override
>    public Arguments getDefaultParameters() {
>
>        Arguments defaultParameters = new Arguments();
>
>        defaultParameters.addArgument("service", "${service}");

The second parameter should be a fixed default value.
If there is none, use the empty String.

>        return defaultParameters;
>    }
>
>    [...]
>
>
> The core challenge for me is to pass an individual "service" parameter value
> for each Java Request, keeping the constant parameter name "service".
>
> How can this be achieved?

Just configure your Java Sampler with the relevant value.

> The scope of User Defined Variables ranges obviously over the full Thread
> Group. In particular, setting a newly defined "service" variable above each
> Java Request does not help, since the last defined value will be always
> taken.

You could use

http://jmeter.apache.org/usermanual/component_reference.html#User_Parameters

However, that is completely unnecessary.

> Is is possible to pass an individual parameter value to each Java Sampler,

Yes, you can configure this on your Java Sampler GUI.

> so that an execution sequence like
>
>
>  Test Plan
>    Thread Group
>      Java Request <with ${service} = "s7">
>      Java Request <with ${service} = "s2">
>      Java Request <with ${service} = "s5">
>
>      [...]
>
>
> can be achieved? If yes, which JMeter Configuration Element can be used for
> it (the Java Request Sampler itself does not provide it, obviously)?
>
>
> Thank you very much in advance!

Have a look a the code for SleepTest.java and look at how this class
appears in the GUI.

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

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