You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Andrew Melnyk <me...@gmail.com> on 2010/03/29 17:56:21 UTC
BeanShell PreProcessor question
Gentlemen,
I'm seeing an interesting issue I have following code in the
BeanShellPreProcessor :
The idea is to get new random word every time from the array
// array of Strings
String[] args={"Test", "Test1","Test2"};
// This is an random element i'm going to extract from the array
int randomElement = (int)(Math.random() * (args.length - 1));
// This is just for debugging purpose, initialization of test plan variable
vars.put("randomElement", randomElement.toString());
// randomword i'll use in some search scenarios
vars.put("randomword", args[randomElement] );
What i have as result of the code above:
After the BeanShellPreProcessor is executed my variables looks(from Debug
Sampler):
randomElement=1
randomword=Test1 , OK that is what i was looking for
Then in my scripts randomword is used three times in search scenarios:
In first two searches referencing to randomword results a "Test1" string
which is OK but in the third search instead of "Test1" I'm seeing "Test" can
anyone explain why this happens? Or there is something wrong in
implementation?
--
Regards,
Andriy
RE: BeanShell PreProcessor question
Posted by Steve Eckhart <St...@wausaufs.com>.
Andriy,
It appears that on the first iteration your random number had a value between 0.5 and 1 and on the third iteration the random value was less than 0.5. So, on the first iteration with a random value of say 0.75, you get
int randomElement = (int)(Math.random() * (args.length - 1))
evaluates as (int)(0.75*(3-1)) = (int)(1.5) = 1 so you get the second element of the args array. On the third iteration randomElement is evaluating as 0 so you get the first element in the array.
It might help to capture the random value for debugging purposes like
double randomNumber = Math.random();
vars.put("randomNumber", randomNumber.toString());
int randomElement = (int)(randomNumber * (args.length - 1));
Steve Eckhart
Business Analyst/Project Manager
WAUSAU Financial Systems
14010 FNB PKWY STE500
Omaha, NE 68154-5206
Email: steve.eckhart@wausaufs.com
Enterprise Payment Solutions.
CONFIDENTIALITY NOTICE: This electronic transmission (including files attached hereto) is intended only for the use of the individual or entity named above. If the reader of this message is not the intended recipient, you are hereby notified that any disclosure, dissemination, copying, distribution or taking of any action in reliance on the contents of this confidential information is strictly prohibited. If you have received this communication in error, please destroy it and immediately notify us by return email. Thank you.
-----Original Message-----
From: Andrew Melnyk [mailto:melnykenator@gmail.com]
Sent: Monday, March 29, 2010 10:56 AM
To: JMeter Users List
Subject: BeanShell PreProcessor question
Gentlemen,
I'm seeing an interesting issue I have following code in the
BeanShellPreProcessor :
The idea is to get new random word every time from the array
// array of Strings
String[] args={"Test", "Test1","Test2"};
// This is an random element i'm going to extract from the array
int randomElement = (int)(Math.random() * (args.length - 1));
// This is just for debugging purpose, initialization of test plan variable
vars.put("randomElement", randomElement.toString());
// randomword i'll use in some search scenarios
vars.put("randomword", args[randomElement] );
What i have as result of the code above:
After the BeanShellPreProcessor is executed my variables looks(from Debug
Sampler):
randomElement=1
randomword=Test1 , OK that is what i was looking for
Then in my scripts randomword is used three times in search scenarios:
In first two searches referencing to randomword results a "Test1" string
which is OK but in the third search instead of "Test1" I'm seeing "Test" can
anyone explain why this happens? Or there is something wrong in
implementation?
--
Regards,
Andriy
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
Re: BeanShell PreProcessor question
Posted by Andrew Melnyk <me...@gmail.com>.
Thanks Deepak got it working as i was expected.
2010/3/29 Deepak Shetty <sh...@gmail.com>
> Hi
> yep so since your pre processor is a child of the thread group it will be
> executed before element of the threadgroup. You could create it as a child
> of the first http sampler (or a dummy test action sampler which appears
> once).
> There is a section on scoping of various elements etc in the manual ..
> regards
> deepak
>
> On Mon, Mar 29, 2010 at 9:39 AM, Andrew Melnyk <melnykenator@gmail.com
> >wrote:
>
> > I've uploaded both screen shot of the test plan and jmx :
> > The screen shot: http://rapidshare.com/files/369605123/TestPlan.jpg.html
> > The test plan: http://rapidshare.com/files/369605730/BeanShell.jmx.html
> >
> > I'm continuing to play with it.
> >
> > 2010/3/29 Deepak Shetty <sh...@gmail.com>
> >
> > > Attachments dont come through. you will have to upload somewhere and
> post
> > a
> > > link. Like I said you probably need to create this pre processor as a
> > child
> > > of the first sampler..
> > >
> > > regards
> > > deepak
> > >
> > > On Mon, Mar 29, 2010 at 9:27 AM, Andrew Melnyk <melnykenator@gmail.com
> > > >wrote:
> > >
> > > > Deepak you are right, it looks like it is executed for every Sampler
> > in
> > > my
> > > > case for every Search.
> > > > I''ve attached my test plan.
> > > >
> > > > 2010/3/29 Deepak Shetty <sh...@gmail.com>
> > > >
> > > > I think your question is you are using ${randomword} in 3 samplers
> and
> > > the
> > > >> first two are the same but the third one differs and you need to use
> > the
> > > >> same value for all 3 samplers?
> > > >> If so I would assume that your pre processor got executed again . If
> > > your
> > > >> preprocessor is not the child of a sample and is instead the child
> of
> > > some
> > > >> controller it might be getting executed before each sample
> > > >>
> > > >> regards
> > > >> deepak
> > > >>
> > > >> On Mon, Mar 29, 2010 at 8:56 AM, Andrew Melnyk <
> > melnykenator@gmail.com
> > > >> >wrote:
> > > >>
> > > >> > Gentlemen,
> > > >> >
> > > >> > I'm seeing an interesting issue I have following code in the
> > > >> > BeanShellPreProcessor :
> > > >> >
> > > >> > The idea is to get new random word every time from the array
> > > >> >
> > > >> > // array of Strings
> > > >> > String[] args={"Test", "Test1","Test2"};
> > > >> >
> > > >> > // This is an random element i'm going to extract from the array
> > > >> > int randomElement = (int)(Math.random() * (args.length - 1));
> > > >> >
> > > >> > // This is just for debugging purpose, initialization of test plan
> > > >> variable
> > > >> > vars.put("randomElement", randomElement.toString());
> > > >> >
> > > >> > // randomword i'll use in some search scenarios
> > > >> > vars.put("randomword", args[randomElement] );
> > > >> >
> > > >> > What i have as result of the code above:
> > > >> >
> > > >> > After the BeanShellPreProcessor is executed my variables
> looks(from
> > > >> Debug
> > > >> > Sampler):
> > > >> >
> > > >> > randomElement=1
> > > >> > randomword=Test1 , OK that is what i was looking for
> > > >> >
> > > >> > Then in my scripts randomword is used three times in search
> > scenarios:
> > > >> >
> > > >> > In first two searches referencing to randomword results a "Test1"
> > > string
> > > >> > which is OK but in the third search instead of "Test1" I'm seeing
> > > "Test"
> > > >> > can
> > > >> > anyone explain why this happens? Or there is something wrong in
> > > >> > implementation?
> > > >> >
> > > >> > --
> > > >> > Regards,
> > > >> > Andriy
> > > >> >
> > > >>
> > > >
> > > >
> > > >
> > > > --
> > > > Regards,
> > > > Andriy
> > > >
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> > > > For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> > > >
> > >
> >
> >
> >
> > --
> > Regards,
> > Andriy
> >
>
--
Regards,
Andriy
Re: BeanShell PreProcessor question
Posted by Deepak Shetty <sh...@gmail.com>.
Hi
yep so since your pre processor is a child of the thread group it will be
executed before element of the threadgroup. You could create it as a child
of the first http sampler (or a dummy test action sampler which appears
once).
There is a section on scoping of various elements etc in the manual ..
regards
deepak
On Mon, Mar 29, 2010 at 9:39 AM, Andrew Melnyk <me...@gmail.com>wrote:
> I've uploaded both screen shot of the test plan and jmx :
> The screen shot: http://rapidshare.com/files/369605123/TestPlan.jpg.html
> The test plan: http://rapidshare.com/files/369605730/BeanShell.jmx.html
>
> I'm continuing to play with it.
>
> 2010/3/29 Deepak Shetty <sh...@gmail.com>
>
> > Attachments dont come through. you will have to upload somewhere and post
> a
> > link. Like I said you probably need to create this pre processor as a
> child
> > of the first sampler..
> >
> > regards
> > deepak
> >
> > On Mon, Mar 29, 2010 at 9:27 AM, Andrew Melnyk <melnykenator@gmail.com
> > >wrote:
> >
> > > Deepak you are right, it looks like it is executed for every Sampler
> in
> > my
> > > case for every Search.
> > > I''ve attached my test plan.
> > >
> > > 2010/3/29 Deepak Shetty <sh...@gmail.com>
> > >
> > > I think your question is you are using ${randomword} in 3 samplers and
> > the
> > >> first two are the same but the third one differs and you need to use
> the
> > >> same value for all 3 samplers?
> > >> If so I would assume that your pre processor got executed again . If
> > your
> > >> preprocessor is not the child of a sample and is instead the child of
> > some
> > >> controller it might be getting executed before each sample
> > >>
> > >> regards
> > >> deepak
> > >>
> > >> On Mon, Mar 29, 2010 at 8:56 AM, Andrew Melnyk <
> melnykenator@gmail.com
> > >> >wrote:
> > >>
> > >> > Gentlemen,
> > >> >
> > >> > I'm seeing an interesting issue I have following code in the
> > >> > BeanShellPreProcessor :
> > >> >
> > >> > The idea is to get new random word every time from the array
> > >> >
> > >> > // array of Strings
> > >> > String[] args={"Test", "Test1","Test2"};
> > >> >
> > >> > // This is an random element i'm going to extract from the array
> > >> > int randomElement = (int)(Math.random() * (args.length - 1));
> > >> >
> > >> > // This is just for debugging purpose, initialization of test plan
> > >> variable
> > >> > vars.put("randomElement", randomElement.toString());
> > >> >
> > >> > // randomword i'll use in some search scenarios
> > >> > vars.put("randomword", args[randomElement] );
> > >> >
> > >> > What i have as result of the code above:
> > >> >
> > >> > After the BeanShellPreProcessor is executed my variables looks(from
> > >> Debug
> > >> > Sampler):
> > >> >
> > >> > randomElement=1
> > >> > randomword=Test1 , OK that is what i was looking for
> > >> >
> > >> > Then in my scripts randomword is used three times in search
> scenarios:
> > >> >
> > >> > In first two searches referencing to randomword results a "Test1"
> > string
> > >> > which is OK but in the third search instead of "Test1" I'm seeing
> > "Test"
> > >> > can
> > >> > anyone explain why this happens? Or there is something wrong in
> > >> > implementation?
> > >> >
> > >> > --
> > >> > Regards,
> > >> > Andriy
> > >> >
> > >>
> > >
> > >
> > >
> > > --
> > > Regards,
> > > Andriy
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> > >
> >
>
>
>
> --
> Regards,
> Andriy
>
Re: BeanShell PreProcessor question
Posted by Andrew Melnyk <me...@gmail.com>.
I've uploaded both screen shot of the test plan and jmx :
The screen shot: http://rapidshare.com/files/369605123/TestPlan.jpg.html
The test plan: http://rapidshare.com/files/369605730/BeanShell.jmx.html
I'm continuing to play with it.
2010/3/29 Deepak Shetty <sh...@gmail.com>
> Attachments dont come through. you will have to upload somewhere and post a
> link. Like I said you probably need to create this pre processor as a child
> of the first sampler..
>
> regards
> deepak
>
> On Mon, Mar 29, 2010 at 9:27 AM, Andrew Melnyk <melnykenator@gmail.com
> >wrote:
>
> > Deepak you are right, it looks like it is executed for every Sampler in
> my
> > case for every Search.
> > I''ve attached my test plan.
> >
> > 2010/3/29 Deepak Shetty <sh...@gmail.com>
> >
> > I think your question is you are using ${randomword} in 3 samplers and
> the
> >> first two are the same but the third one differs and you need to use the
> >> same value for all 3 samplers?
> >> If so I would assume that your pre processor got executed again . If
> your
> >> preprocessor is not the child of a sample and is instead the child of
> some
> >> controller it might be getting executed before each sample
> >>
> >> regards
> >> deepak
> >>
> >> On Mon, Mar 29, 2010 at 8:56 AM, Andrew Melnyk <melnykenator@gmail.com
> >> >wrote:
> >>
> >> > Gentlemen,
> >> >
> >> > I'm seeing an interesting issue I have following code in the
> >> > BeanShellPreProcessor :
> >> >
> >> > The idea is to get new random word every time from the array
> >> >
> >> > // array of Strings
> >> > String[] args={"Test", "Test1","Test2"};
> >> >
> >> > // This is an random element i'm going to extract from the array
> >> > int randomElement = (int)(Math.random() * (args.length - 1));
> >> >
> >> > // This is just for debugging purpose, initialization of test plan
> >> variable
> >> > vars.put("randomElement", randomElement.toString());
> >> >
> >> > // randomword i'll use in some search scenarios
> >> > vars.put("randomword", args[randomElement] );
> >> >
> >> > What i have as result of the code above:
> >> >
> >> > After the BeanShellPreProcessor is executed my variables looks(from
> >> Debug
> >> > Sampler):
> >> >
> >> > randomElement=1
> >> > randomword=Test1 , OK that is what i was looking for
> >> >
> >> > Then in my scripts randomword is used three times in search scenarios:
> >> >
> >> > In first two searches referencing to randomword results a "Test1"
> string
> >> > which is OK but in the third search instead of "Test1" I'm seeing
> "Test"
> >> > can
> >> > anyone explain why this happens? Or there is something wrong in
> >> > implementation?
> >> >
> >> > --
> >> > Regards,
> >> > Andriy
> >> >
> >>
> >
> >
> >
> > --
> > Regards,
> > Andriy
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> >
>
--
Regards,
Andriy
Re: BeanShell PreProcessor question
Posted by Deepak Shetty <sh...@gmail.com>.
Attachments dont come through. you will have to upload somewhere and post a
link. Like I said you probably need to create this pre processor as a child
of the first sampler..
regards
deepak
On Mon, Mar 29, 2010 at 9:27 AM, Andrew Melnyk <me...@gmail.com>wrote:
> Deepak you are right, it looks like it is executed for every Sampler in my
> case for every Search.
> I''ve attached my test plan.
>
> 2010/3/29 Deepak Shetty <sh...@gmail.com>
>
> I think your question is you are using ${randomword} in 3 samplers and the
>> first two are the same but the third one differs and you need to use the
>> same value for all 3 samplers?
>> If so I would assume that your pre processor got executed again . If your
>> preprocessor is not the child of a sample and is instead the child of some
>> controller it might be getting executed before each sample
>>
>> regards
>> deepak
>>
>> On Mon, Mar 29, 2010 at 8:56 AM, Andrew Melnyk <melnykenator@gmail.com
>> >wrote:
>>
>> > Gentlemen,
>> >
>> > I'm seeing an interesting issue I have following code in the
>> > BeanShellPreProcessor :
>> >
>> > The idea is to get new random word every time from the array
>> >
>> > // array of Strings
>> > String[] args={"Test", "Test1","Test2"};
>> >
>> > // This is an random element i'm going to extract from the array
>> > int randomElement = (int)(Math.random() * (args.length - 1));
>> >
>> > // This is just for debugging purpose, initialization of test plan
>> variable
>> > vars.put("randomElement", randomElement.toString());
>> >
>> > // randomword i'll use in some search scenarios
>> > vars.put("randomword", args[randomElement] );
>> >
>> > What i have as result of the code above:
>> >
>> > After the BeanShellPreProcessor is executed my variables looks(from
>> Debug
>> > Sampler):
>> >
>> > randomElement=1
>> > randomword=Test1 , OK that is what i was looking for
>> >
>> > Then in my scripts randomword is used three times in search scenarios:
>> >
>> > In first two searches referencing to randomword results a "Test1" string
>> > which is OK but in the third search instead of "Test1" I'm seeing "Test"
>> > can
>> > anyone explain why this happens? Or there is something wrong in
>> > implementation?
>> >
>> > --
>> > Regards,
>> > Andriy
>> >
>>
>
>
>
> --
> Regards,
> Andriy
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
Re: BeanShell PreProcessor question
Posted by Andrew Melnyk <me...@gmail.com>.
Deepak you are right, it looks like it is executed for every Sampler in my
case for every Search.
I''ve attached my test plan.
2010/3/29 Deepak Shetty <sh...@gmail.com>
> I think your question is you are using ${randomword} in 3 samplers and the
> first two are the same but the third one differs and you need to use the
> same value for all 3 samplers?
> If so I would assume that your pre processor got executed again . If your
> preprocessor is not the child of a sample and is instead the child of some
> controller it might be getting executed before each sample
>
> regards
> deepak
>
> On Mon, Mar 29, 2010 at 8:56 AM, Andrew Melnyk <melnykenator@gmail.com
> >wrote:
>
> > Gentlemen,
> >
> > I'm seeing an interesting issue I have following code in the
> > BeanShellPreProcessor :
> >
> > The idea is to get new random word every time from the array
> >
> > // array of Strings
> > String[] args={"Test", "Test1","Test2"};
> >
> > // This is an random element i'm going to extract from the array
> > int randomElement = (int)(Math.random() * (args.length - 1));
> >
> > // This is just for debugging purpose, initialization of test plan
> variable
> > vars.put("randomElement", randomElement.toString());
> >
> > // randomword i'll use in some search scenarios
> > vars.put("randomword", args[randomElement] );
> >
> > What i have as result of the code above:
> >
> > After the BeanShellPreProcessor is executed my variables looks(from Debug
> > Sampler):
> >
> > randomElement=1
> > randomword=Test1 , OK that is what i was looking for
> >
> > Then in my scripts randomword is used three times in search scenarios:
> >
> > In first two searches referencing to randomword results a "Test1" string
> > which is OK but in the third search instead of "Test1" I'm seeing "Test"
> > can
> > anyone explain why this happens? Or there is something wrong in
> > implementation?
> >
> > --
> > Regards,
> > Andriy
> >
>
--
Regards,
Andriy
Re: BeanShell PreProcessor question
Posted by Deepak Shetty <sh...@gmail.com>.
I think your question is you are using ${randomword} in 3 samplers and the
first two are the same but the third one differs and you need to use the
same value for all 3 samplers?
If so I would assume that your pre processor got executed again . If your
preprocessor is not the child of a sample and is instead the child of some
controller it might be getting executed before each sample
regards
deepak
On Mon, Mar 29, 2010 at 8:56 AM, Andrew Melnyk <me...@gmail.com>wrote:
> Gentlemen,
>
> I'm seeing an interesting issue I have following code in the
> BeanShellPreProcessor :
>
> The idea is to get new random word every time from the array
>
> // array of Strings
> String[] args={"Test", "Test1","Test2"};
>
> // This is an random element i'm going to extract from the array
> int randomElement = (int)(Math.random() * (args.length - 1));
>
> // This is just for debugging purpose, initialization of test plan variable
> vars.put("randomElement", randomElement.toString());
>
> // randomword i'll use in some search scenarios
> vars.put("randomword", args[randomElement] );
>
> What i have as result of the code above:
>
> After the BeanShellPreProcessor is executed my variables looks(from Debug
> Sampler):
>
> randomElement=1
> randomword=Test1 , OK that is what i was looking for
>
> Then in my scripts randomword is used three times in search scenarios:
>
> In first two searches referencing to randomword results a "Test1" string
> which is OK but in the third search instead of "Test1" I'm seeing "Test"
> can
> anyone explain why this happens? Or there is something wrong in
> implementation?
>
> --
> Regards,
> Andriy
>