jmeter-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject Re: unable to share variables
Date Wed, 21 Mar 2012 00:56:34 GMT
On 20 March 2012 20:08,  <Jake_Devore@playstation.sony.com> wrote:
>>This suggests that you are trying to share variables across threads -
>>is that the case?
>
> For testing I only have one thread to cut down time, but I was trying to
> use multiple threads before.
>
>>CSV Dataset or the StringFromFile function might be suitable for
>>reading the file.
>
>>To write to a single file, a Listener would be appropriate.
>
> I added this to my BeanShellSampler.bshrc:
>
> bsh.shared.lock = new ReentrantReadWriteLock();
> bsh.shared.vpaths = new Vector(1000, 1000);
> bsh.shared.index = 0;
>
> I tried declaring the var types before the bsh.shared... with the same
> issues.
>
> I have a beanshell preprocessor outside the threads group with this code:
>
> import java.util.*;
> import java.io.*;
>
> int wm = Integer.parseInt(vars.get("write_mode"));
> if(wm == 0)
> {
>        BufferedReader file = new BufferedReader(new FileReader("paths"));
>        String s;
>        while((s = file.readLine()) != null)
>        {
>                bsh.shared.vpaths.addElement(new String(s));
>        }
>        file.close();
> }
>
> In the thread group I have a loop with this beanshell preprocessor on it:
>
> import java.util.*;
> import java.util.concurrent.locks.ReentrantReadWriteLock;
>
> bsh.shared.lock.readLock().lock();
> vars.put("path", bsh.shared.vpaths.elementAt(bsh.shared.index));
> ++bsh.shared.index
> bsh.shared.lock.readLock().unlock();
>
> The above is on the read type of test.  I've tried forward declarations
> but it seems like beanshell can't tell what type of variables they are, it
> works fine on integers.  I've also tried using putObject and getObject,
> but it seems that the vars are reset each time the shell is invoked, even
> if the reset is set to false.
>
> I was using the BufferedReader before directly in each read or write
> preprocessor, but it only got the first line of the file so I figured a
> string list might work, but it just has different issues.

CSVDataset and StringFromFile are designed for use with JMeter threads.

Given what you have said are the requirements, these are suitable.

If they don't seem to work, then describe what you have tried, what
happened, and what you expected to happen.

> Thanks,
>
> Jake Devore
> SCE WWS OTG Operations Engineering
> (253) 981-4252
>
>
>
> sebb <sebbaz@gmail.com>
> 03/20/2012 12:44 PM
> Please respond to
> "JMeter Users List" <user@jmeter.apache.org>
>
>
> To
> JMeter Users List <user@jmeter.apache.org>
> cc
>
> Subject
> Re: unable to share variables
>
>
>
>
>
>
> On 20 March 2012 19:00,  <Jake_Devore@playstation.sony.com> wrote:
>> So I've tried using the vars.putObject/vars.getObject, the vars always
>> seem to be reset, even when the param to reset is false.  I've tried
>> throwing variables in BeanShellSampler.bshrc in the bsh.shared
> namespace,
>> which had good results, except it only works on ints.
>
> This suggests that you are trying to share variables across threads -
> is that the case?
>
>> Basically I want to be able to open a file and read a single line per
> loop
>> iteration in each thread and be able to do the same with writing to a
>> file.
>
> CSV Dataset or the StringFromFile function might be suitable for
> reading the file.
>
> To write to a single file, a Listener would be appropriate.
>
>> Thanks,
>>
>> Jake Devore
>
> ---------------------------------------------------------------------
> 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


Mime
View raw message