Passing variables to Random function

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

Passing variables to Random function

David Fertig
I have a variable called numFiles, which I can print and verify contains an integer.
Integer numFiles = vars.getObject("numFiles");

I want to make a random number between 0 and that value.  But all of the following fail
${__Random(0,__ ${numFiles},docIndex)};

Integer docIndex  = ${__Random(0,${numFiles})};

${__Random(0,__ numFiles,docIndex)};

Integer docIndex  = ${__Random(0,numFiles)};

All with an errors like:
Uncaught Exception java.lang.NumberFormatException: For input string: "${NUMFILES}". See log file for details.

Uncaught Exception java.lang.NumberFormatException: For input string: "numFiles". See log file for details.

How do I pass a variable into the random() function?



Thank you
David



This email, including attachments, may contain information that is privileged, confidential or is exempt from disclosure under applicable law (including, but not limited to, protected health information). It is not intended for transmission to, or receipt by, any unauthorized persons. If the reader of this message is not the intended recipient, or the employee or agent responsible for delivering the message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you believe this email was sent to you in error, do not read it. Please notify the sender immediately informing them of the error and delete all copies and attachments of the message from your system. Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: Passing variables to Random function

shettyd
${__Random(0,${numFiles},docIndex)} should work Where are you specifying
this ? Note special considerations apply if you are trying this within for
e.g. a beanshell sampler




On Tue, Aug 21, 2018 at 12:32 PM David Fertig <[hidden email]>
wrote:

> I have a variable called numFiles, which I can print and verify contains
> an integer.
> Integer numFiles = vars.getObject("numFiles");
>
> I want to make a random number between 0 and that value.  But all of the
> following fail
> ${__Random(0,__ ${numFiles},docIndex)};
>
> Integer docIndex  = ${__Random(0,${numFiles})};
>
> ${__Random(0,__ numFiles,docIndex)};
>
> Integer docIndex  = ${__Random(0,numFiles)};
>
> All with an errors like:
> Uncaught Exception java.lang.NumberFormatException: For input string:
> "${NUMFILES}". See log file for details.
>
> Uncaught Exception java.lang.NumberFormatException: For input string:
> "numFiles". See log file for details.
>
> How do I pass a variable into the random() function?
>
>
>
> Thank you
> David
>
>
>
> This email, including attachments, may contain information that is
> privileged, confidential or is exempt from disclosure under applicable law
> (including, but not limited to, protected health information). It is not
> intended for transmission to, or receipt by, any unauthorized persons. If
> the reader of this message is not the intended recipient, or the employee
> or agent responsible for delivering the message to the intended recipient,
> you are hereby notified that any dissemination, distribution or copying of
> this communication is strictly prohibited. If you believe this email was
> sent to you in error, do not read it. Please notify the sender immediately
> informing them of the error and delete all copies and attachments of the
> message from your system. Thank you.
>
Reply | Threaded
Open this post in threaded view
|

Re: Passing variables to Random function

Felix Schumacher
In reply to this post by David Fertig


Am 21.08.2018 um 21:32 schrieb David Fertig:

> I have a variable called numFiles, which I can print and verify contains an integer.
> Integer numFiles = vars.getObject("numFiles");
>
> I want to make a random number between 0 and that value.  But all of the following fail
> ${__Random(0,__ ${numFiles},docIndex)};
>
> Integer docIndex  = ${__Random(0,${numFiles})};
>
> ${__Random(0,__ numFiles,docIndex)};
>
> Integer docIndex  = ${__Random(0,numFiles)};
>
> All with an errors like:
> Uncaught Exception java.lang.NumberFormatException: For input string: "${NUMFILES}". See log file for details.
>
> Uncaught Exception java.lang.NumberFormatException: For input string: "numFiles". See log file for details.
>
> How do I pass a variable into the random() function?
It seems that this is a bug. At the moment the Strings given to __Random
will not be evaluated (and therefore the Integer will not be transformed
into a String).

Till the bug is fixed, you will have to transform the Integer into a
String by yourself.

Regards,
  Felix

>
>
>
> Thank you
> David
>
>
>
> This email, including attachments, may contain information that is privileged, confidential or is exempt from disclosure under applicable law (including, but not limited to, protected health information). It is not intended for transmission to, or receipt by, any unauthorized persons. If the reader of this message is not the intended recipient, or the employee or agent responsible for delivering the message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you believe this email was sent to you in error, do not read it. Please notify the sender immediately informing them of the error and delete all copies and attachments of the message from your system. Thank you.
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Passing variables to Random function

Felix Schumacher


Am 22.08.2018 um 17:06 schrieb Felix Schumacher:

>
>
> Am 21.08.2018 um 21:32 schrieb David Fertig:
>> I have a variable called numFiles, which I can print and verify
>> contains an integer.
>> Integer numFiles = vars.getObject("numFiles");
>>
>> I want to make a random number between 0 and that value.  But all of
>> the following fail
>> ${__Random(0,__ ${numFiles},docIndex)};
>>
>> Integer docIndex  = ${__Random(0,${numFiles})};
>>
>> ${__Random(0,__ numFiles,docIndex)};
>>
>> Integer docIndex  = ${__Random(0,numFiles)};
>>
>> All with an errors like:
>> Uncaught Exception java.lang.NumberFormatException: For input string:
>> "${NUMFILES}". See log file for details.
>>
>> Uncaught Exception java.lang.NumberFormatException: For input string:
>> "numFiles". See log file for details.
>>
>> How do I pass a variable into the random() function?
> It seems that this is a bug. At the moment the Strings given to
> __Random will not be evaluated (and therefore the Integer will not be
> transformed into a String).
On second thought "bug" might be a bit harsh, as no function in JMeter
will currently transform those values by itself (yet?).

To answer your question, you could use __evalVar function to convert
your Integer into a String:

${__Random(0,${__evalVar(numFiles)})}

Regards,
  Feli


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Passing variables to Random function

sebb-2-2
On 22 August 2018 at 16:14, Felix Schumacher
<[hidden email]> wrote:

>
>
> Am 22.08.2018 um 17:06 schrieb Felix Schumacher:
>>
>>
>>
>> Am 21.08.2018 um 21:32 schrieb David Fertig:
>>>
>>> I have a variable called numFiles, which I can print and verify contains
>>> an integer.
>>> Integer numFiles = vars.getObject("numFiles");
>>>
>>> I want to make a random number between 0 and that value.  But all of the
>>> following fail
>>> ${__Random(0,__ ${numFiles},docIndex)};
>>>
>>> Integer docIndex  = ${__Random(0,${numFiles})};
>>>
>>> ${__Random(0,__ numFiles,docIndex)};
>>>
>>> Integer docIndex  = ${__Random(0,numFiles)};
>>>
>>> All with an errors like:
>>> Uncaught Exception java.lang.NumberFormatException: For input string:
>>> "${NUMFILES}". See log file for details.
>>>
>>> Uncaught Exception java.lang.NumberFormatException: For input string:
>>> "numFiles". See log file for details.
>>>
>>> How do I pass a variable into the random() function?
>>
>> It seems that this is a bug. At the moment the Strings given to __Random
>> will not be evaluated (and therefore the Integer will not be transformed
>> into a String).
>
> On second thought "bug" might be a bit harsh, as no function in JMeter will
> currently transform those values by itself (yet?).

It's not a bug (or even a feature). It's not supported.

Variables were designed to be used for replacement of fixed text in test plans.
e.g.. instead of

http://a.b.c:80/

one could have the following textual definitions (e.g. on the Test Plan):

HOST=a.b.c
PORT=80

and use the following instead:
http://${HOST}:${PORT}/

It so happens that the variables are stored in a structure that allows
the values to be arbitrary objects.

This proved useful for passing data between scripts
(putObject/getObject), but was never intended for use in the test plan
textual substitution functionality.

Variables that are used in test plan elements must have values that are Strings.

A simple way to fix the errors is to ensure that the script stores the
value as a String (e.g. using a new variable name).

> To answer your question, you could use __evalVar function to convert your
> Integer into a String:
>
> ${__Random(0,${__evalVar(numFiles)})}
>
> Regards,
>  Feli
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Passing variables to Random function

shettyd
In reply to this post by Felix Schumacher
Hi
I initially tried this with a string , but I dont get this issue with an
integer either - How were you able to replicate
Thread group
+Bean Shell sampler // vars.putObject("numFiles",new Integer(10));
+Http Request
++ParamValue - ${__Random(0,${numFiles},docIndex)}

which works fine.

On Wed, Aug 22, 2018 at 8:06 AM Felix Schumacher <
[hidden email]> wrote:

>
>
> Am 21.08.2018 um 21:32 schrieb David Fertig:
> > I have a variable called numFiles, which I can print and verify contains
> an integer.
> > Integer numFiles = vars.getObject("numFiles");
> >
> > I want to make a random number between 0 and that value.  But all of the
> following fail
> > ${__Random(0,__ ${numFiles},docIndex)};
> >
> > Integer docIndex  = ${__Random(0,${numFiles})};
> >
> > ${__Random(0,__ numFiles,docIndex)};
> >
> > Integer docIndex  = ${__Random(0,numFiles)};
> >
> > All with an errors like:
> > Uncaught Exception java.lang.NumberFormatException: For input string:
> "${NUMFILES}". See log file for details.
> >
> > Uncaught Exception java.lang.NumberFormatException: For input string:
> "numFiles". See log file for details.
> >
> > How do I pass a variable into the random() function?
> It seems that this is a bug. At the moment the Strings given to __Random
> will not be evaluated (and therefore the Integer will not be transformed
> into a String).
>
> Till the bug is fixed, you will have to transform the Integer into a
> String by yourself.
>
> Regards,
>   Felix
>
> >
> >
> >
> > Thank you
> > David
> >
> >
> >
> > This email, including attachments, may contain information that is
> privileged, confidential or is exempt from disclosure under applicable law
> (including, but not limited to, protected health information). It is not
> intended for transmission to, or receipt by, any unauthorized persons. If
> the reader of this message is not the intended recipient, or the employee
> or agent responsible for delivering the message to the intended recipient,
> you are hereby notified that any dissemination, distribution or copying of
> this communication is strictly prohibited. If you believe this email was
> sent to you in error, do not read it. Please notify the sender immediately
> informing them of the error and delete all copies and attachments of the
> message from your system. Thank you.
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Passing variables to Random function

Felix Schumacher


Am 23.08.2018 um 03:42 schrieb Deepak Shetty:
> Hi
> I initially tried this with a string , but I dont get this issue with an
> integer either - How were you able to replicate
> Thread group
> +Bean Shell sampler // vars.putObject("numFiles",new Integer(10));
> +Http Request
> ++ParamValue - ${__Random(0,${numFiles},docIndex)}

Try to use the title of a sampler. Parameters seem to be handled
differently.

Felix

>
> which works fine.
>
> On Wed, Aug 22, 2018 at 8:06 AM Felix Schumacher <
> [hidden email]> wrote:
>
>>
>> Am 21.08.2018 um 21:32 schrieb David Fertig:
>>> I have a variable called numFiles, which I can print and verify contains
>> an integer.
>>> Integer numFiles = vars.getObject("numFiles");
>>>
>>> I want to make a random number between 0 and that value.  But all of the
>> following fail
>>> ${__Random(0,__ ${numFiles},docIndex)};
>>>
>>> Integer docIndex  = ${__Random(0,${numFiles})};
>>>
>>> ${__Random(0,__ numFiles,docIndex)};
>>>
>>> Integer docIndex  = ${__Random(0,numFiles)};
>>>
>>> All with an errors like:
>>> Uncaught Exception java.lang.NumberFormatException: For input string:
>> "${NUMFILES}". See log file for details.
>>> Uncaught Exception java.lang.NumberFormatException: For input string:
>> "numFiles". See log file for details.
>>> How do I pass a variable into the random() function?
>> It seems that this is a bug. At the moment the Strings given to __Random
>> will not be evaluated (and therefore the Integer will not be transformed
>> into a String).
>>
>> Till the bug is fixed, you will have to transform the Integer into a
>> String by yourself.
>>
>> Regards,
>>    Felix
>>
>>>
>>>
>>> Thank you
>>> David
>>>
>>>
>>>
>>> This email, including attachments, may contain information that is
>> privileged, confidential or is exempt from disclosure under applicable law
>> (including, but not limited to, protected health information). It is not
>> intended for transmission to, or receipt by, any unauthorized persons. If
>> the reader of this message is not the intended recipient, or the employee
>> or agent responsible for delivering the message to the intended recipient,
>> you are hereby notified that any dissemination, distribution or copying of
>> this communication is strictly prohibited. If you believe this email was
>> sent to you in error, do not read it. Please notify the sender immediately
>> informing them of the error and delete all copies and attachments of the
>> message from your system. Thank you.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Passing variables to Random function

shettyd
Hi
title worked too

regards
deepak

On Thu, Aug 23, 2018 at 1:43 AM Felix Schumacher <
[hidden email]> wrote:

>
>
> Am 23.08.2018 um 03:42 schrieb Deepak Shetty:
> > Hi
> > I initially tried this with a string , but I dont get this issue with an
> > integer either - How were you able to replicate
> > Thread group
> > +Bean Shell sampler // vars.putObject("numFiles",new Integer(10));
> > +Http Request
> > ++ParamValue - ${__Random(0,${numFiles},docIndex)}
>
> Try to use the title of a sampler. Parameters seem to be handled
> differently.
>
> Felix
>
> >
> > which works fine.
> >
> > On Wed, Aug 22, 2018 at 8:06 AM Felix Schumacher <
> > [hidden email]> wrote:
> >
> >>
> >> Am 21.08.2018 um 21:32 schrieb David Fertig:
> >>> I have a variable called numFiles, which I can print and verify
> contains
> >> an integer.
> >>> Integer numFiles = vars.getObject("numFiles");
> >>>
> >>> I want to make a random number between 0 and that value.  But all of
> the
> >> following fail
> >>> ${__Random(0,__ ${numFiles},docIndex)};
> >>>
> >>> Integer docIndex  = ${__Random(0,${numFiles})};
> >>>
> >>> ${__Random(0,__ numFiles,docIndex)};
> >>>
> >>> Integer docIndex  = ${__Random(0,numFiles)};
> >>>
> >>> All with an errors like:
> >>> Uncaught Exception java.lang.NumberFormatException: For input string:
> >> "${NUMFILES}". See log file for details.
> >>> Uncaught Exception java.lang.NumberFormatException: For input string:
> >> "numFiles". See log file for details.
> >>> How do I pass a variable into the random() function?
> >> It seems that this is a bug. At the moment the Strings given to __Random
> >> will not be evaluated (and therefore the Integer will not be transformed
> >> into a String).
> >>
> >> Till the bug is fixed, you will have to transform the Integer into a
> >> String by yourself.
> >>
> >> Regards,
> >>    Felix
> >>
> >>>
> >>>
> >>> Thank you
> >>> David
> >>>
> >>>
> >>>
> >>> This email, including attachments, may contain information that is
> >> privileged, confidential or is exempt from disclosure under applicable
> law
> >> (including, but not limited to, protected health information). It is not
> >> intended for transmission to, or receipt by, any unauthorized persons.
> If
> >> the reader of this message is not the intended recipient, or the
> employee
> >> or agent responsible for delivering the message to the intended
> recipient,
> >> you are hereby notified that any dissemination, distribution or copying
> of
> >> this communication is strictly prohibited. If you believe this email was
> >> sent to you in error, do not read it. Please notify the sender
> immediately
> >> informing them of the error and delete all copies and attachments of the
> >> message from your system. Thank you.
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [hidden email]
> >> For additional commands, e-mail: [hidden email]
> >>
> >>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

RE: Passing variables to Random function

David Fertig
In reply to this post by Felix Schumacher
>${__Random(0,${__evalVar(numFiles)})}

Unfortunately this also does not work.

2018-08-23 11:32:53,096 ERROR o.a.j.JMeter: Uncaught exception: java.lang.NumberFormatException: For input string: ""



-----Original Message-----
From: Felix Schumacher <[hidden email]>
Sent: Wednesday, August 22, 2018 11:14 AM
To: [hidden email]
Subject: Re: Passing variables to Random function



Am 22.08.2018 um 17:06 schrieb Felix Schumacher:

>
>
> Am 21.08.2018 um 21:32 schrieb David Fertig:
>> I have a variable called numFiles, which I can print and verify
>> contains an integer.
>> Integer numFiles = vars.getObject("numFiles");
>>
>> I want to make a random number between 0 and that value.  But all of
>> the following fail ${__Random(0,__ ${numFiles},docIndex)};
>>
>> Integer docIndex  = ${__Random(0,${numFiles})};
>>
>> ${__Random(0,__ numFiles,docIndex)};
>>
>> Integer docIndex  = ${__Random(0,numFiles)};
>>
>> All with an errors like:
>> Uncaught Exception java.lang.NumberFormatException: For input string:
>> "${NUMFILES}". See log file for details.
>>
>> Uncaught Exception java.lang.NumberFormatException: For input string:
>> "numFiles". See log file for details.
>>
>> How do I pass a variable into the random() function?
> It seems that this is a bug. At the moment the Strings given to
> __Random will not be evaluated (and therefore the Integer will not be
> transformed into a String).
On second thought "bug" might be a bit harsh, as no function in JMeter will currently transform those values by itself (yet?).

To answer your question, you could use __evalVar function to convert your Integer into a String:

${__Random(0,${__evalVar(numFiles)})}

Regards,
  Feli


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

This email, including attachments, may contain information that is privileged, confidential or is exempt from disclosure under applicable law (including, but not limited to, protected health information). It is not intended for transmission to, or receipt by, any unauthorized persons. If the reader of this message is not the intended recipient, or the employee or agent responsible for delivering the message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you believe this email was sent to you in error, do not read it. Please notify the sender immediately informing them of the error and delete all copies and attachments of the message from your system. Thank you.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Passing variables to Random function

Felix Schumacher


Am 23.08.2018 um 17:34 schrieb David Fertig:
>> ${__Random(0,${__evalVar(numFiles)})}
> Unfortunately this also does not work.
>
> 2018-08-23 11:32:53,096 ERROR o.a.j.JMeter: Uncaught exception: java.lang.NumberFormatException: For input string: ""
Are you sure, that your variable numFiles is spelled correct? Try to add
a debug sampler to check.

Felix

>
>
>
> -----Original Message-----
> From: Felix Schumacher <[hidden email]>
> Sent: Wednesday, August 22, 2018 11:14 AM
> To: [hidden email]
> Subject: Re: Passing variables to Random function
>
>
>
> Am 22.08.2018 um 17:06 schrieb Felix Schumacher:
>>
>> Am 21.08.2018 um 21:32 schrieb David Fertig:
>>> I have a variable called numFiles, which I can print and verify
>>> contains an integer.
>>> Integer numFiles = vars.getObject("numFiles");
>>>
>>> I want to make a random number between 0 and that value.  But all of
>>> the following fail ${__Random(0,__ ${numFiles},docIndex)};
>>>
>>> Integer docIndex  = ${__Random(0,${numFiles})};
>>>
>>> ${__Random(0,__ numFiles,docIndex)};
>>>
>>> Integer docIndex  = ${__Random(0,numFiles)};
>>>
>>> All with an errors like:
>>> Uncaught Exception java.lang.NumberFormatException: For input string:
>>> "${NUMFILES}". See log file for details.
>>>
>>> Uncaught Exception java.lang.NumberFormatException: For input string:
>>> "numFiles". See log file for details.
>>>
>>> How do I pass a variable into the random() function?
>> It seems that this is a bug. At the moment the Strings given to
>> __Random will not be evaluated (and therefore the Integer will not be
>> transformed into a String).
> On second thought "bug" might be a bit harsh, as no function in JMeter will currently transform those values by itself (yet?).
>
> To answer your question, you could use __evalVar function to convert your Integer into a String:
>
> ${__Random(0,${__evalVar(numFiles)})}
>
> Regards,
>    Feli
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
> This email, including attachments, may contain information that is privileged, confidential or is exempt from disclosure under applicable law (including, but not limited to, protected health information). It is not intended for transmission to, or receipt by, any unauthorized persons. If the reader of this message is not the intended recipient, or the employee or agent responsible for delivering the message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you believe this email was sent to you in error, do not read it. Please notify the sender immediately informing them of the error and delete all copies and attachments of the message from your system. Thank you.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Passing variables to Random function

Felix Schumacher
In reply to this post by shettyd


Am 23.08.2018 um 16:07 schrieb Deepak Shetty:
> Hi
> title worked too
For me now, too.

The test cases I used - and the reported stacktraces - showed that an
Integer will not be converted automatically to a String by the Random
function. And I probably misspelled my variable name and got the error
when I tested it through the GUI. It seems that the GUI is trying harder
to convert the complete function string components to string values
before giving the values to the Random function.

Thanks for your double checking and insistence.
  Felix

>
> regards
> deepak
>
> On Thu, Aug 23, 2018 at 1:43 AM Felix Schumacher <
> [hidden email]> wrote:
>
>>
>> Am 23.08.2018 um 03:42 schrieb Deepak Shetty:
>>> Hi
>>> I initially tried this with a string , but I dont get this issue with an
>>> integer either - How were you able to replicate
>>> Thread group
>>> +Bean Shell sampler // vars.putObject("numFiles",new Integer(10));
>>> +Http Request
>>> ++ParamValue - ${__Random(0,${numFiles},docIndex)}
>> Try to use the title of a sampler. Parameters seem to be handled
>> differently.
>>
>> Felix
>>
>>> which works fine.
>>>
>>> On Wed, Aug 22, 2018 at 8:06 AM Felix Schumacher <
>>> [hidden email]> wrote:
>>>
>>>> Am 21.08.2018 um 21:32 schrieb David Fertig:
>>>>> I have a variable called numFiles, which I can print and verify
>> contains
>>>> an integer.
>>>>> Integer numFiles = vars.getObject("numFiles");
>>>>>
>>>>> I want to make a random number between 0 and that value.  But all of
>> the
>>>> following fail
>>>>> ${__Random(0,__ ${numFiles},docIndex)};
>>>>>
>>>>> Integer docIndex  = ${__Random(0,${numFiles})};
>>>>>
>>>>> ${__Random(0,__ numFiles,docIndex)};
>>>>>
>>>>> Integer docIndex  = ${__Random(0,numFiles)};
>>>>>
>>>>> All with an errors like:
>>>>> Uncaught Exception java.lang.NumberFormatException: For input string:
>>>> "${NUMFILES}". See log file for details.
>>>>> Uncaught Exception java.lang.NumberFormatException: For input string:
>>>> "numFiles". See log file for details.
>>>>> How do I pass a variable into the random() function?
>>>> It seems that this is a bug. At the moment the Strings given to __Random
>>>> will not be evaluated (and therefore the Integer will not be transformed
>>>> into a String).
>>>>
>>>> Till the bug is fixed, you will have to transform the Integer into a
>>>> String by yourself.
>>>>
>>>> Regards,
>>>>     Felix
>>>>
>>>>>
>>>>> Thank you
>>>>> David
>>>>>
>>>>>
>>>>>
>>>>> This email, including attachments, may contain information that is
>>>> privileged, confidential or is exempt from disclosure under applicable
>> law
>>>> (including, but not limited to, protected health information). It is not
>>>> intended for transmission to, or receipt by, any unauthorized persons.
>> If
>>>> the reader of this message is not the intended recipient, or the
>> employee
>>>> or agent responsible for delivering the message to the intended
>> recipient,
>>>> you are hereby notified that any dissemination, distribution or copying
>> of
>>>> this communication is strictly prohibited. If you believe this email was
>>>> sent to you in error, do not read it. Please notify the sender
>> immediately
>>>> informing them of the error and delete all copies and attachments of the
>>>> message from your system. Thank you.
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: [hidden email]
>>>> For additional commands, e-mail: [hidden email]
>>>>
>>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Passing variables to Random function

shettyd
In reply to this post by David Fertig
Hi
here is my example that works

https://onedrive.live.com/?cid=1BD02FE33F80B8AC&id=1BD02FE33F80B8AC%211557&parId=1BD02FE33F80B8AC%21268&o=OneUp

On Thu, Aug 23, 2018 at 8:34 AM David Fertig <[hidden email]>
wrote:

> >${__Random(0,${__evalVar(numFiles)})}
>
> Unfortunately this also does not work.
>
> 2018-08-23 11:32:53,096 ERROR o.a.j.JMeter: Uncaught exception:
> java.lang.NumberFormatException: For input string: ""
>
>
>
> -----Original Message-----
> From: Felix Schumacher <[hidden email]>
> Sent: Wednesday, August 22, 2018 11:14 AM
> To: [hidden email]
> Subject: Re: Passing variables to Random function
>
>
>
> Am 22.08.2018 um 17:06 schrieb Felix Schumacher:
> >
> >
> > Am 21.08.2018 um 21:32 schrieb David Fertig:
> >> I have a variable called numFiles, which I can print and verify
> >> contains an integer.
> >> Integer numFiles = vars.getObject("numFiles");
> >>
> >> I want to make a random number between 0 and that value.  But all of
> >> the following fail ${__Random(0,__ ${numFiles},docIndex)};
> >>
> >> Integer docIndex  = ${__Random(0,${numFiles})};
> >>
> >> ${__Random(0,__ numFiles,docIndex)};
> >>
> >> Integer docIndex  = ${__Random(0,numFiles)};
> >>
> >> All with an errors like:
> >> Uncaught Exception java.lang.NumberFormatException: For input string:
> >> "${NUMFILES}". See log file for details.
> >>
> >> Uncaught Exception java.lang.NumberFormatException: For input string:
> >> "numFiles". See log file for details.
> >>
> >> How do I pass a variable into the random() function?
> > It seems that this is a bug. At the moment the Strings given to
> > __Random will not be evaluated (and therefore the Integer will not be
> > transformed into a String).
> On second thought "bug" might be a bit harsh, as no function in JMeter
> will currently transform those values by itself (yet?).
>
> To answer your question, you could use __evalVar function to convert your
> Integer into a String:
>
> ${__Random(0,${__evalVar(numFiles)})}
>
> Regards,
>   Feli
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
> This email, including attachments, may contain information that is
> privileged, confidential or is exempt from disclosure under applicable law
> (including, but not limited to, protected health information). It is not
> intended for transmission to, or receipt by, any unauthorized persons. If
> the reader of this message is not the intended recipient, or the employee
> or agent responsible for delivering the message to the intended recipient,
> you are hereby notified that any dissemination, distribution or copying of
> this communication is strictly prohibited. If you believe this email was
> sent to you in error, do not read it. Please notify the sender immediately
> informing them of the error and delete all copies and attachments of the
> message from your system. Thank you.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Passing variables to Random function

shettyd
In reply to this post by Felix Schumacher
Thank you for confirming!

On Thu, Aug 23, 2018 at 12:22 PM Felix Schumacher <
[hidden email]> wrote:

>
>
> Am 23.08.2018 um 16:07 schrieb Deepak Shetty:
> > Hi
> > title worked too
> For me now, too.
>
> The test cases I used - and the reported stacktraces - showed that an
> Integer will not be converted automatically to a String by the Random
> function. And I probably misspelled my variable name and got the error
> when I tested it through the GUI. It seems that the GUI is trying harder
> to convert the complete function string components to string values
> before giving the values to the Random function.
>
> Thanks for your double checking and insistence.
>   Felix
>
> >
> > regards
> > deepak
> >
> > On Thu, Aug 23, 2018 at 1:43 AM Felix Schumacher <
> > [hidden email]> wrote:
> >
> >>
> >> Am 23.08.2018 um 03:42 schrieb Deepak Shetty:
> >>> Hi
> >>> I initially tried this with a string , but I dont get this issue with
> an
> >>> integer either - How were you able to replicate
> >>> Thread group
> >>> +Bean Shell sampler // vars.putObject("numFiles",new Integer(10));
> >>> +Http Request
> >>> ++ParamValue - ${__Random(0,${numFiles},docIndex)}
> >> Try to use the title of a sampler. Parameters seem to be handled
> >> differently.
> >>
> >> Felix
> >>
> >>> which works fine.
> >>>
> >>> On Wed, Aug 22, 2018 at 8:06 AM Felix Schumacher <
> >>> [hidden email]> wrote:
> >>>
> >>>> Am 21.08.2018 um 21:32 schrieb David Fertig:
> >>>>> I have a variable called numFiles, which I can print and verify
> >> contains
> >>>> an integer.
> >>>>> Integer numFiles = vars.getObject("numFiles");
> >>>>>
> >>>>> I want to make a random number between 0 and that value.  But all of
> >> the
> >>>> following fail
> >>>>> ${__Random(0,__ ${numFiles},docIndex)};
> >>>>>
> >>>>> Integer docIndex  = ${__Random(0,${numFiles})};
> >>>>>
> >>>>> ${__Random(0,__ numFiles,docIndex)};
> >>>>>
> >>>>> Integer docIndex  = ${__Random(0,numFiles)};
> >>>>>
> >>>>> All with an errors like:
> >>>>> Uncaught Exception java.lang.NumberFormatException: For input string:
> >>>> "${NUMFILES}". See log file for details.
> >>>>> Uncaught Exception java.lang.NumberFormatException: For input string:
> >>>> "numFiles". See log file for details.
> >>>>> How do I pass a variable into the random() function?
> >>>> It seems that this is a bug. At the moment the Strings given to
> __Random
> >>>> will not be evaluated (and therefore the Integer will not be
> transformed
> >>>> into a String).
> >>>>
> >>>> Till the bug is fixed, you will have to transform the Integer into a
> >>>> String by yourself.
> >>>>
> >>>> Regards,
> >>>>     Felix
> >>>>
> >>>>>
> >>>>> Thank you
> >>>>> David
> >>>>>
> >>>>>
> >>>>>
> >>>>> This email, including attachments, may contain information that is
> >>>> privileged, confidential or is exempt from disclosure under applicable
> >> law
> >>>> (including, but not limited to, protected health information). It is
> not
> >>>> intended for transmission to, or receipt by, any unauthorized persons.
> >> If
> >>>> the reader of this message is not the intended recipient, or the
> >> employee
> >>>> or agent responsible for delivering the message to the intended
> >> recipient,
> >>>> you are hereby notified that any dissemination, distribution or
> copying
> >> of
> >>>> this communication is strictly prohibited. If you believe this email
> was
> >>>> sent to you in error, do not read it. Please notify the sender
> >> immediately
> >>>> informing them of the error and delete all copies and attachments of
> the
> >>>> message from your system. Thank you.
> >>>>
> >>>> ---------------------------------------------------------------------
> >>>> To unsubscribe, e-mail: [hidden email]
> >>>> For additional commands, e-mail: [hidden email]
> >>>>
> >>>>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [hidden email]
> >> For additional commands, e-mail: [hidden email]
> >>
> >>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

RE: Passing variables to Random function

LERBSCHER JEAN-PIERRE-2
In reply to this post by David Fertig
Hi,

Is numFiles an expression?

There is a gap in user manual between eval function and evalVar function.


Variables       eval<https://jmeter.apache.org/usermanual/functions.html#__eval>        evaluate a variable expression  2.3.1
Variables       evalVar<https://jmeter.apache.org/usermanual/functions.html#__evalVar>  evaluate an expression stored in a variable     2.3.1



________________________________
De : David Fertig <[hidden email]>
Envoyé : jeudi 23 août 2018 17:34
À : JMeter Users List
Objet : RE: Passing variables to Random function

>${__Random(0,${__evalVar(numFiles)})}

Unfortunately this also does not work.

2018-08-23 11:32:53,096 ERROR o.a.j.JMeter: Uncaught exception: java.lang.NumberFormatException: For input string: ""



-----Original Message-----
From: Felix Schumacher <[hidden email]>
Sent: Wednesday, August 22, 2018 11:14 AM
To: [hidden email]
Subject: Re: Passing variables to Random function



Am 22.08.2018 um 17:06 schrieb Felix Schumacher:

>
>
> Am 21.08.2018 um 21:32 schrieb David Fertig:
>> I have a variable called numFiles, which I can print and verify
>> contains an integer.
>> Integer numFiles = vars.getObject("numFiles");
>>
>> I want to make a random number between 0 and that value.  But all of
>> the following fail ${__Random(0,__ ${numFiles},docIndex)};
>>
>> Integer docIndex  = ${__Random(0,${numFiles})};
>>
>> ${__Random(0,__ numFiles,docIndex)};
>>
>> Integer docIndex  = ${__Random(0,numFiles)};
>>
>> All with an errors like:
>> Uncaught Exception java.lang.NumberFormatException: For input string:
>> "${NUMFILES}". See log file for details.
>>
>> Uncaught Exception java.lang.NumberFormatException: For input string:
>> "numFiles". See log file for details.
>>
>> How do I pass a variable into the random() function?
> It seems that this is a bug. At the moment the Strings given to
> __Random will not be evaluated (and therefore the Integer will not be
> transformed into a String).
On second thought "bug" might be a bit harsh, as no function in JMeter will currently transform those values by itself (yet?).

To answer your question, you could use __evalVar function to convert your Integer into a String:

${__Random(0,${__evalVar(numFiles)})}

Regards,
  Feli


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

This email, including attachments, may contain information that is privileged, confidential or is exempt from disclosure under applicable law (including, but not limited to, protected health information). It is not intended for transmission to, or receipt by, any unauthorized persons. If the reader of this message is not the intended recipient, or the employee or agent responsible for delivering the message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you believe this email was sent to you in error, do not read it. Please notify the sender immediately informing them of the error and delete all copies and attachments of the message from your system. Thank you.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

RE: Passing variables to Random function

David Fertig
numFIles is an Integer.

I've made a workaround on this by generating a random 0-1 million, creating a fraction, and then multiplying by my original value.  Just a workout, but works in my case.


-----Original Message-----
From: LERBSCHER JEAN-PIERRE <[hidden email]>
Sent: Monday, August 27, 2018 3:13 AM
To: JMeter Users List <[hidden email]>
Subject: RE: Passing variables to Random function

Hi,

Is numFiles an expression?

There is a gap in user manual between eval function and evalVar function.


Variables       eval<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fjmeter.apache.org%2Fusermanual%2Ffunctions.html%23__eval&amp;data=02%7C01%7CDavid.Fertig%40navihealth.com%7C065d5908de1a45f21ad008d60bec951b%7C6e94af0345c143158632e1c94ce46b97%7C1%7C0%7C636709508094251230&amp;sdata=Sls%2BioMpQ7866EyE%2Falv0A%2Fex7Ix52TzgguUZELRHbU%3D&amp;reserved=0>        evaluate a variable expression  2.3.1
Variables       evalVar<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fjmeter.apache.org%2Fusermanual%2Ffunctions.html%23__evalVar&amp;data=02%7C01%7CDavid.Fertig%40navihealth.com%7C065d5908de1a45f21ad008d60bec951b%7C6e94af0345c143158632e1c94ce46b97%7C1%7C0%7C636709508094251230&amp;sdata=l%2FQaMA6czWkYhHefPHwsM9Wh%2BmlLqTQGOjlgjT5N3VE%3D&amp;reserved=0>  evaluate an expression stored in a variable     2.3.1



________________________________
De : David Fertig <[hidden email]> Envoyé : jeudi 23 août 2018 17:34 À : JMeter Users List Objet : RE: Passing variables to Random function

>${__Random(0,${__evalVar(numFiles)})}

Unfortunately this also does not work.

2018-08-23 11:32:53,096 ERROR o.a.j.JMeter: Uncaught exception: java.lang.NumberFormatException: For input string: ""



-----Original Message-----
From: Felix Schumacher <[hidden email]>
Sent: Wednesday, August 22, 2018 11:14 AM
To: [hidden email]
Subject: Re: Passing variables to Random function



Am 22.08.2018 um 17:06 schrieb Felix Schumacher:

>
>
> Am 21.08.2018 um 21:32 schrieb David Fertig:
>> I have a variable called numFiles, which I can print and verify
>> contains an integer.
>> Integer numFiles = vars.getObject("numFiles");
>>
>> I want to make a random number between 0 and that value.  But all of
>> the following fail ${__Random(0,__ ${numFiles},docIndex)};
>>
>> Integer docIndex  = ${__Random(0,${numFiles})};
>>
>> ${__Random(0,__ numFiles,docIndex)};
>>
>> Integer docIndex  = ${__Random(0,numFiles)};
>>
>> All with an errors like:
>> Uncaught Exception java.lang.NumberFormatException: For input string:
>> "${NUMFILES}". See log file for details.
>>
>> Uncaught Exception java.lang.NumberFormatException: For input string:
>> "numFiles". See log file for details.
>>
>> How do I pass a variable into the random() function?
> It seems that this is a bug. At the moment the Strings given to
> __Random will not be evaluated (and therefore the Integer will not be
> transformed into a String).
On second thought "bug" might be a bit harsh, as no function in JMeter will currently transform those values by itself (yet?).

To answer your question, you could use __evalVar function to convert your Integer into a String:

${__Random(0,${__evalVar(numFiles)})}

Regards,
  Feli


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

This email, including attachments, may contain information that is privileged, confidential or is exempt from disclosure under applicable law (including, but not limited to, protected health information). It is not intended for transmission to, or receipt by, any unauthorized persons. If the reader of this message is not the intended recipient, or the employee or agent responsible for delivering the message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you believe this email was sent to you in error, do not read it. Please notify the sender immediately informing them of the error and delete all copies and attachments of the message from your system. Thank you.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

This email, including attachments, may contain information that is privileged, confidential or is exempt from disclosure under applicable law (including, but not limited to, protected health information). It is not intended for transmission to, or receipt by, any unauthorized persons. If the reader of this message is not the intended recipient, or the employee or agent responsible for delivering the message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you believe this email was sent to you in error, do not read it. Please notify the sender immediately informing them of the error and delete all copies and attachments of the message from your system. Thank you.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]