You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by E S <el...@gmail.com> on 2011/07/19 16:42:48 UTC

Programmatic access to thread group loop count

I have a custom sampler that I'm writing. Is it possible to programmatically
access the thread group's loop count from within the sampler? I can do the
following:

this.getThreadContext().getThreadGroup()

>From that I can get the thread group name, comments, and number of threads
but I don't see a property for the loop count.

Re: Programmatic access to thread group loop count

Posted by sebb <se...@gmail.com>.
On 22 July 2011 21:12, E S <el...@gmail.com> wrote:
> Okay, I see what you mean now. For the sake of posterity, I'll explain it in
> a little more detail. I defined a variable on the test plan, as you said,
> called LOOPS. Then in the Thread Group I set the value in the "Loop Count"
> box to ${LOOPS}. Then in the code, when I want to access this value I use
>
> JMeterVariables vars = getThreadContext().getVariables();
> int numLoops = Integer.parseInt(vars.get("LOOPS"));
>
> To be honest, I think I like the other method better because I don't have to
> maintain the extra variable, but this is a good alternative if it's needed.

Also, you can just use ${LOOPS} in any test element - no need to write
any code in order to retrieve the value.

> Thanks.
>
> On Thu, Jul 21, 2011 at 7:03 PM, sebb <se...@gmail.com> wrote:
>
>> Define a variable for the loop count on the Test Plan.
>>
>> Use that wherever you want to know the loop count.
>>
>> On 21 July 2011 23:59, E S <el...@gmail.com> wrote:
>> > Can you expound on that a little? I'm not sure I follow.
>> >
>> > On Thu, Jul 21, 2011 at 4:09 PM, sebb <se...@gmail.com> wrote:
>> >
>> >> Another way to do this would be to use a variable for the loop count.
>> >>
>> >> On 21 July 2011 20:25, E S <el...@gmail.com> wrote:
>> >> > FYI, it looks like this can be done with the following code within a
>> >> > sampler:
>> >> >
>> >> > Controller ctrl =
>> >> > getThreadContext().getThreadGroup().getSamplerController();
>> >> > LoopController loopCtrl = (LoopController)ctrl;
>> >> > int loopCount = loopCtrl.getLoops();
>> >> >
>> >> > The getSamplerController() method returns a reference to the
>> Controller
>> >> > interface, which doesn't know anything about loops. However, it
>> appears
>> >> that
>> >> > the thread group works with a LoopController by default so the
>> downcast
>> >> > works. I'm not sure what, if anything, can be done to invalidate that
>> >> > assumption.
>> >> >
>> >> > If you select "forever" or use the scheduler feature on the thread
>> group,
>> >> > loop count will be -1.
>> >> >
>> >> >
>> >> > On Tue, Jul 19, 2011 at 9:42 AM, E S <el...@gmail.com>
>> >> wrote:
>> >> >
>> >> >> I have a custom sampler that I'm writing. Is it possible to
>> >> >> programmatically access the thread group's loop count from within the
>> >> >> sampler? I can do the following:
>> >> >>
>> >> >> this.getThreadContext().getThreadGroup()
>> >> >>
>> >> >> From that I can get the thread group name, comments, and number of
>> >> threads
>> >> >> but I don't see a property for the loop count.
>> >> >>
>> >> >
>> >>
>> >> ---------------------------------------------------------------------
>> >> 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
>>
>>
>

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


Re: Programmatic access to thread group loop count

Posted by E S <el...@gmail.com>.
Okay, I see what you mean now. For the sake of posterity, I'll explain it in
a little more detail. I defined a variable on the test plan, as you said,
called LOOPS. Then in the Thread Group I set the value in the "Loop Count"
box to ${LOOPS}. Then in the code, when I want to access this value I use

JMeterVariables vars = getThreadContext().getVariables();
int numLoops = Integer.parseInt(vars.get("LOOPS"));

To be honest, I think I like the other method better because I don't have to
maintain the extra variable, but this is a good alternative if it's needed.

Thanks.

On Thu, Jul 21, 2011 at 7:03 PM, sebb <se...@gmail.com> wrote:

> Define a variable for the loop count on the Test Plan.
>
> Use that wherever you want to know the loop count.
>
> On 21 July 2011 23:59, E S <el...@gmail.com> wrote:
> > Can you expound on that a little? I'm not sure I follow.
> >
> > On Thu, Jul 21, 2011 at 4:09 PM, sebb <se...@gmail.com> wrote:
> >
> >> Another way to do this would be to use a variable for the loop count.
> >>
> >> On 21 July 2011 20:25, E S <el...@gmail.com> wrote:
> >> > FYI, it looks like this can be done with the following code within a
> >> > sampler:
> >> >
> >> > Controller ctrl =
> >> > getThreadContext().getThreadGroup().getSamplerController();
> >> > LoopController loopCtrl = (LoopController)ctrl;
> >> > int loopCount = loopCtrl.getLoops();
> >> >
> >> > The getSamplerController() method returns a reference to the
> Controller
> >> > interface, which doesn't know anything about loops. However, it
> appears
> >> that
> >> > the thread group works with a LoopController by default so the
> downcast
> >> > works. I'm not sure what, if anything, can be done to invalidate that
> >> > assumption.
> >> >
> >> > If you select "forever" or use the scheduler feature on the thread
> group,
> >> > loop count will be -1.
> >> >
> >> >
> >> > On Tue, Jul 19, 2011 at 9:42 AM, E S <el...@gmail.com>
> >> wrote:
> >> >
> >> >> I have a custom sampler that I'm writing. Is it possible to
> >> >> programmatically access the thread group's loop count from within the
> >> >> sampler? I can do the following:
> >> >>
> >> >> this.getThreadContext().getThreadGroup()
> >> >>
> >> >> From that I can get the thread group name, comments, and number of
> >> threads
> >> >> but I don't see a property for the loop count.
> >> >>
> >> >
> >>
> >> ---------------------------------------------------------------------
> >> 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
>
>

Re: Programmatic access to thread group loop count

Posted by sebb <se...@gmail.com>.
Define a variable for the loop count on the Test Plan.

Use that wherever you want to know the loop count.

On 21 July 2011 23:59, E S <el...@gmail.com> wrote:
> Can you expound on that a little? I'm not sure I follow.
>
> On Thu, Jul 21, 2011 at 4:09 PM, sebb <se...@gmail.com> wrote:
>
>> Another way to do this would be to use a variable for the loop count.
>>
>> On 21 July 2011 20:25, E S <el...@gmail.com> wrote:
>> > FYI, it looks like this can be done with the following code within a
>> > sampler:
>> >
>> > Controller ctrl =
>> > getThreadContext().getThreadGroup().getSamplerController();
>> > LoopController loopCtrl = (LoopController)ctrl;
>> > int loopCount = loopCtrl.getLoops();
>> >
>> > The getSamplerController() method returns a reference to the Controller
>> > interface, which doesn't know anything about loops. However, it appears
>> that
>> > the thread group works with a LoopController by default so the downcast
>> > works. I'm not sure what, if anything, can be done to invalidate that
>> > assumption.
>> >
>> > If you select "forever" or use the scheduler feature on the thread group,
>> > loop count will be -1.
>> >
>> >
>> > On Tue, Jul 19, 2011 at 9:42 AM, E S <el...@gmail.com>
>> wrote:
>> >
>> >> I have a custom sampler that I'm writing. Is it possible to
>> >> programmatically access the thread group's loop count from within the
>> >> sampler? I can do the following:
>> >>
>> >> this.getThreadContext().getThreadGroup()
>> >>
>> >> From that I can get the thread group name, comments, and number of
>> threads
>> >> but I don't see a property for the loop count.
>> >>
>> >
>>
>> ---------------------------------------------------------------------
>> 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


Re: Programmatic access to thread group loop count

Posted by E S <el...@gmail.com>.
Can you expound on that a little? I'm not sure I follow.

On Thu, Jul 21, 2011 at 4:09 PM, sebb <se...@gmail.com> wrote:

> Another way to do this would be to use a variable for the loop count.
>
> On 21 July 2011 20:25, E S <el...@gmail.com> wrote:
> > FYI, it looks like this can be done with the following code within a
> > sampler:
> >
> > Controller ctrl =
> > getThreadContext().getThreadGroup().getSamplerController();
> > LoopController loopCtrl = (LoopController)ctrl;
> > int loopCount = loopCtrl.getLoops();
> >
> > The getSamplerController() method returns a reference to the Controller
> > interface, which doesn't know anything about loops. However, it appears
> that
> > the thread group works with a LoopController by default so the downcast
> > works. I'm not sure what, if anything, can be done to invalidate that
> > assumption.
> >
> > If you select "forever" or use the scheduler feature on the thread group,
> > loop count will be -1.
> >
> >
> > On Tue, Jul 19, 2011 at 9:42 AM, E S <el...@gmail.com>
> wrote:
> >
> >> I have a custom sampler that I'm writing. Is it possible to
> >> programmatically access the thread group's loop count from within the
> >> sampler? I can do the following:
> >>
> >> this.getThreadContext().getThreadGroup()
> >>
> >> From that I can get the thread group name, comments, and number of
> threads
> >> but I don't see a property for the loop count.
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>

Re: Programmatic access to thread group loop count

Posted by sebb <se...@gmail.com>.
Another way to do this would be to use a variable for the loop count.

On 21 July 2011 20:25, E S <el...@gmail.com> wrote:
> FYI, it looks like this can be done with the following code within a
> sampler:
>
> Controller ctrl =
> getThreadContext().getThreadGroup().getSamplerController();
> LoopController loopCtrl = (LoopController)ctrl;
> int loopCount = loopCtrl.getLoops();
>
> The getSamplerController() method returns a reference to the Controller
> interface, which doesn't know anything about loops. However, it appears that
> the thread group works with a LoopController by default so the downcast
> works. I'm not sure what, if anything, can be done to invalidate that
> assumption.
>
> If you select "forever" or use the scheduler feature on the thread group,
> loop count will be -1.
>
>
> On Tue, Jul 19, 2011 at 9:42 AM, E S <el...@gmail.com> wrote:
>
>> I have a custom sampler that I'm writing. Is it possible to
>> programmatically access the thread group's loop count from within the
>> sampler? I can do the following:
>>
>> this.getThreadContext().getThreadGroup()
>>
>> From that I can get the thread group name, comments, and number of threads
>> but I don't see a property for the loop count.
>>
>

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


Re: Programmatic access to thread group loop count

Posted by E S <el...@gmail.com>.
FYI, it looks like this can be done with the following code within a
sampler:

Controller ctrl =
getThreadContext().getThreadGroup().getSamplerController();
LoopController loopCtrl = (LoopController)ctrl;
int loopCount = loopCtrl.getLoops();

The getSamplerController() method returns a reference to the Controller
interface, which doesn't know anything about loops. However, it appears that
the thread group works with a LoopController by default so the downcast
works. I'm not sure what, if anything, can be done to invalidate that
assumption.

If you select "forever" or use the scheduler feature on the thread group,
loop count will be -1.


On Tue, Jul 19, 2011 at 9:42 AM, E S <el...@gmail.com> wrote:

> I have a custom sampler that I'm writing. Is it possible to
> programmatically access the thread group's loop count from within the
> sampler? I can do the following:
>
> this.getThreadContext().getThreadGroup()
>
> From that I can get the thread group name, comments, and number of threads
> but I don't see a property for the loop count.
>