You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by CharekC <ch...@gmail.com> on 2007/10/26 17:54:31 UTC

Beanshell to get random csv value

I've been looking at beanshell to get random csv file values.
I have the following code:

ArrayList csv_array=null;

String getCSV_Value() {

        if (csv_array==null)
                // initialize csv_array from file

        if (csv_array.size()>0)
                //return random value from csv_array
        else
                // return error_value

}

I'm running into the problem where each call of
${__BeanShell(getCSV_Value())} initializes the csv_array.
I've tried the following:
1. renamed getCSV_Value() to execute()
2. tried public static ArrayList csv_array=null;
3. Placed the code and referenced it in jmeter.properties
beanshell.function.init=
beanshell.init.file=
       
So how can one make csv_array global and the getCSV_Value() method
synchronized? (Jmeter 2.3RC4)

Thanks
-- 
View this message in context: http://www.nabble.com/Beanshell-to-get-random-csv-value-tf4698152.html#a13430100
Sent from the JMeter - User mailing list archive at Nabble.com.


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


Re: Beanshell to get random csv value

Posted by sebb <se...@gmail.com>.
Each occurrence of a function in a test plan is a separate instance.

Make sure that you only have one function call; you can put this in a
user parameters pre-processor so that each sampler gets a new value.

However, I would probably not do it this way; it's a waste of
resources to do the randomisation at run-time if it can be avoided.
Also, if the file is big, it will take a lot of memory.

I'd create a pre-randomised file and use CSV Dataset or
__StringFromFile() to read it.

On 26/10/2007, CharekC <ch...@gmail.com> wrote:
>
> I've been looking at beanshell to get random csv file values.
> I have the following code:
>
> ArrayList csv_array=null;
>
> String getCSV_Value() {
>
>        if (csv_array==null)
>                // initialize csv_array from file
>
>        if (csv_array.size()>0)
>                //return random value from csv_array
>        else
>                // return error_value
>
> }
>
> I'm running into the problem where each call of
> ${__BeanShell(getCSV_Value())} initializes the csv_array.
> I've tried the following:
> 1. renamed getCSV_Value() to execute()
> 2. tried public static ArrayList csv_array=null;
> 3. Placed the code and referenced it in jmeter.properties
> beanshell.function.init=
> beanshell.init.file=
>
> So how can one make csv_array global and the getCSV_Value() method
> synchronized? (Jmeter 2.3RC4)
>
> Thanks
> --
> View this message in context: http://www.nabble.com/Beanshell-to-get-random-csv-value-tf4698152.html#a13430100
> Sent from the JMeter - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> 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