You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Shalin Shekhar Mangar <sh...@gmail.com> on 2015/05/05 18:57:48 UTC

End jmeter test run from a Java sampler

Hello,

I am writing a Java sampler that generates queries from a file to run
against my custom application server. How do I signal to Jmeter that I have
run out of queries and that the test is complete?

I have set the thread group to loop forever. I can of course constrain it
to run only a certain number of times but I'd like to test with many
different query files and I don't want to create different configuration
(loop count, num threads) for each query file.

-- 
Regards,
Shalin Shekhar Mangar.

Re: End jmeter test run from a Java sampler

Posted by Shalin Shekhar Mangar <sh...@gmail.com>.
Thank you, Deepak!

I found that throwing JMeterStopThreadException also stops the thread. This
is the same exception that CSVDataSet throws on EOF if recycle=false.

On Sat, May 9, 2015 at 1:50 AM, Deepak Shetty <sh...@gmail.com> wrote:

>
> https://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterContextService.html
> static method named getContext()
>
> On Fri, May 8, 2015 at 12:32 PM, Shalin Shekhar Mangar <
> shalinmangar@gmail.com> wrote:
>
> > Hi Deepak,
> >
> > I must be missing something obvious. How can my Sampler get access to the
> > the JMeterContextService? I don't see any methods exposed
> > via AbstractJavaSamplerClient or JavaSamplerContext which let me get the
> > JMeterContextService object.
> >
> > On Wed, May 6, 2015 at 7:39 PM, Deepak Shetty <sh...@gmail.com> wrote:
> >
> > > If the CSV reads the field into say a variable called query , then just
> > > define a parameter on the JavaSampler  with a value of ${query}
> > > If you need all defined variables then you can use the same
> > > JMeterContextService --> getJMeterContext() -->getVariables() which
> gives
> > > you the JMeterVariables object on which you can get/set whatever
> > variables
> > > you need.
> > >
> > > On Tue, May 5, 2015 at 11:07 PM, Shalin Shekhar Mangar <
> > > shalinmangar@gmail.com> wrote:
> > >
> > > > Okay, I think I understand your hint about the CSV Data Set Config. I
> > can
> > > > use that and set the "Stop thread on EOF" property to true. So let's
> > say
> > > > that I read a line of my query file using the CSV Data Set Config,
> how
> > > do I
> > > > access that string from inside my Java sampler?
> > > >
> > > > On Wed, May 6, 2015 at 12:31 AM, Deepak Shetty <sh...@gmail.com>
> > > wrote:
> > > >
> > > > > ok try - use JMeterContextService - Get JmeterContext from which
> you
> > > can
> > > > > get the JMeter thread of JMeterThreadGroup and do ask it to stop --
> > > > >
> > > >
> > >
> >
> https://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterContext.html
> > > > > (Note its a different matter that I dont think you should be doing
> > thi
> > > )
> > > > >
> > > > > On Tue, May 5, 2015 at 11:54 AM, Shalin Shekhar Mangar <
> > > > > shalinmangar@gmail.com> wrote:
> > > > >
> > > > > > No, I am reading the file contents myself i.e. with Java code
> > inside
> > > > the
> > > > > > custom sampler.
> > > > > >
> > > > > > On Tue, May 5, 2015 at 11:15 PM, Deepak Shetty <
> shettyd@gmail.com>
> > > > > wrote:
> > > > > >
> > > > > > > Are you using CSV Data Set Config to read the query file?
> > > > > > >
> > > > > > > On Tue, May 5, 2015 at 9:57 AM, Shalin Shekhar Mangar <
> > > > > > > shalinmangar@gmail.com> wrote:
> > > > > > >
> > > > > > > > Hello,
> > > > > > > >
> > > > > > > > I am writing a Java sampler that generates queries from a
> file
> > to
> > > > run
> > > > > > > > against my custom application server. How do I signal to
> Jmeter
> > > > that
> > > > > I
> > > > > > > have
> > > > > > > > run out of queries and that the test is complete?
> > > > > > > >
> > > > > > > > I have set the thread group to loop forever. I can of course
> > > > > constrain
> > > > > > it
> > > > > > > > to run only a certain number of times but I'd like to test
> with
> > > > many
> > > > > > > > different query files and I don't want to create different
> > > > > > configuration
> > > > > > > > (loop count, num threads) for each query file.
> > > > > > > >
> > > > > > > > --
> > > > > > > > Regards,
> > > > > > > > Shalin Shekhar Mangar.
> > > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > > Regards,
> > > > > > Shalin Shekhar Mangar.
> > > > > >
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Regards,
> > > > Shalin Shekhar Mangar.
> > > >
> > >
> >
> >
> >
> > --
> > Regards,
> > Shalin Shekhar Mangar.
> >
>



-- 
Regards,
Shalin Shekhar Mangar.

Re: End jmeter test run from a Java sampler

Posted by Deepak Shetty <sh...@gmail.com>.
https://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterContextService.html
static method named getContext()

On Fri, May 8, 2015 at 12:32 PM, Shalin Shekhar Mangar <
shalinmangar@gmail.com> wrote:

> Hi Deepak,
>
> I must be missing something obvious. How can my Sampler get access to the
> the JMeterContextService? I don't see any methods exposed
> via AbstractJavaSamplerClient or JavaSamplerContext which let me get the
> JMeterContextService object.
>
> On Wed, May 6, 2015 at 7:39 PM, Deepak Shetty <sh...@gmail.com> wrote:
>
> > If the CSV reads the field into say a variable called query , then just
> > define a parameter on the JavaSampler  with a value of ${query}
> > If you need all defined variables then you can use the same
> > JMeterContextService --> getJMeterContext() -->getVariables() which gives
> > you the JMeterVariables object on which you can get/set whatever
> variables
> > you need.
> >
> > On Tue, May 5, 2015 at 11:07 PM, Shalin Shekhar Mangar <
> > shalinmangar@gmail.com> wrote:
> >
> > > Okay, I think I understand your hint about the CSV Data Set Config. I
> can
> > > use that and set the "Stop thread on EOF" property to true. So let's
> say
> > > that I read a line of my query file using the CSV Data Set Config, how
> > do I
> > > access that string from inside my Java sampler?
> > >
> > > On Wed, May 6, 2015 at 12:31 AM, Deepak Shetty <sh...@gmail.com>
> > wrote:
> > >
> > > > ok try - use JMeterContextService - Get JmeterContext from which you
> > can
> > > > get the JMeter thread of JMeterThreadGroup and do ask it to stop --
> > > >
> > >
> >
> https://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterContext.html
> > > > (Note its a different matter that I dont think you should be doing
> thi
> > )
> > > >
> > > > On Tue, May 5, 2015 at 11:54 AM, Shalin Shekhar Mangar <
> > > > shalinmangar@gmail.com> wrote:
> > > >
> > > > > No, I am reading the file contents myself i.e. with Java code
> inside
> > > the
> > > > > custom sampler.
> > > > >
> > > > > On Tue, May 5, 2015 at 11:15 PM, Deepak Shetty <sh...@gmail.com>
> > > > wrote:
> > > > >
> > > > > > Are you using CSV Data Set Config to read the query file?
> > > > > >
> > > > > > On Tue, May 5, 2015 at 9:57 AM, Shalin Shekhar Mangar <
> > > > > > shalinmangar@gmail.com> wrote:
> > > > > >
> > > > > > > Hello,
> > > > > > >
> > > > > > > I am writing a Java sampler that generates queries from a file
> to
> > > run
> > > > > > > against my custom application server. How do I signal to Jmeter
> > > that
> > > > I
> > > > > > have
> > > > > > > run out of queries and that the test is complete?
> > > > > > >
> > > > > > > I have set the thread group to loop forever. I can of course
> > > > constrain
> > > > > it
> > > > > > > to run only a certain number of times but I'd like to test with
> > > many
> > > > > > > different query files and I don't want to create different
> > > > > configuration
> > > > > > > (loop count, num threads) for each query file.
> > > > > > >
> > > > > > > --
> > > > > > > Regards,
> > > > > > > Shalin Shekhar Mangar.
> > > > > > >
> > > > > >
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Regards,
> > > > > Shalin Shekhar Mangar.
> > > > >
> > > >
> > >
> > >
> > >
> > > --
> > > Regards,
> > > Shalin Shekhar Mangar.
> > >
> >
>
>
>
> --
> Regards,
> Shalin Shekhar Mangar.
>

Re: End jmeter test run from a Java sampler

Posted by Shalin Shekhar Mangar <sh...@gmail.com>.
Hi Deepak,

I must be missing something obvious. How can my Sampler get access to the
the JMeterContextService? I don't see any methods exposed
via AbstractJavaSamplerClient or JavaSamplerContext which let me get the
JMeterContextService object.

On Wed, May 6, 2015 at 7:39 PM, Deepak Shetty <sh...@gmail.com> wrote:

> If the CSV reads the field into say a variable called query , then just
> define a parameter on the JavaSampler  with a value of ${query}
> If you need all defined variables then you can use the same
> JMeterContextService --> getJMeterContext() -->getVariables() which gives
> you the JMeterVariables object on which you can get/set whatever variables
> you need.
>
> On Tue, May 5, 2015 at 11:07 PM, Shalin Shekhar Mangar <
> shalinmangar@gmail.com> wrote:
>
> > Okay, I think I understand your hint about the CSV Data Set Config. I can
> > use that and set the "Stop thread on EOF" property to true. So let's say
> > that I read a line of my query file using the CSV Data Set Config, how
> do I
> > access that string from inside my Java sampler?
> >
> > On Wed, May 6, 2015 at 12:31 AM, Deepak Shetty <sh...@gmail.com>
> wrote:
> >
> > > ok try - use JMeterContextService - Get JmeterContext from which you
> can
> > > get the JMeter thread of JMeterThreadGroup and do ask it to stop --
> > >
> >
> https://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterContext.html
> > > (Note its a different matter that I dont think you should be doing thi
> )
> > >
> > > On Tue, May 5, 2015 at 11:54 AM, Shalin Shekhar Mangar <
> > > shalinmangar@gmail.com> wrote:
> > >
> > > > No, I am reading the file contents myself i.e. with Java code inside
> > the
> > > > custom sampler.
> > > >
> > > > On Tue, May 5, 2015 at 11:15 PM, Deepak Shetty <sh...@gmail.com>
> > > wrote:
> > > >
> > > > > Are you using CSV Data Set Config to read the query file?
> > > > >
> > > > > On Tue, May 5, 2015 at 9:57 AM, Shalin Shekhar Mangar <
> > > > > shalinmangar@gmail.com> wrote:
> > > > >
> > > > > > Hello,
> > > > > >
> > > > > > I am writing a Java sampler that generates queries from a file to
> > run
> > > > > > against my custom application server. How do I signal to Jmeter
> > that
> > > I
> > > > > have
> > > > > > run out of queries and that the test is complete?
> > > > > >
> > > > > > I have set the thread group to loop forever. I can of course
> > > constrain
> > > > it
> > > > > > to run only a certain number of times but I'd like to test with
> > many
> > > > > > different query files and I don't want to create different
> > > > configuration
> > > > > > (loop count, num threads) for each query file.
> > > > > >
> > > > > > --
> > > > > > Regards,
> > > > > > Shalin Shekhar Mangar.
> > > > > >
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Regards,
> > > > Shalin Shekhar Mangar.
> > > >
> > >
> >
> >
> >
> > --
> > Regards,
> > Shalin Shekhar Mangar.
> >
>



-- 
Regards,
Shalin Shekhar Mangar.

Re: End jmeter test run from a Java sampler

Posted by Deepak Shetty <sh...@gmail.com>.
If the CSV reads the field into say a variable called query , then just
define a parameter on the JavaSampler  with a value of ${query}
If you need all defined variables then you can use the same
JMeterContextService --> getJMeterContext() -->getVariables() which gives
you the JMeterVariables object on which you can get/set whatever variables
you need.

On Tue, May 5, 2015 at 11:07 PM, Shalin Shekhar Mangar <
shalinmangar@gmail.com> wrote:

> Okay, I think I understand your hint about the CSV Data Set Config. I can
> use that and set the "Stop thread on EOF" property to true. So let's say
> that I read a line of my query file using the CSV Data Set Config, how do I
> access that string from inside my Java sampler?
>
> On Wed, May 6, 2015 at 12:31 AM, Deepak Shetty <sh...@gmail.com> wrote:
>
> > ok try - use JMeterContextService - Get JmeterContext from which you can
> > get the JMeter thread of JMeterThreadGroup and do ask it to stop --
> >
> https://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterContext.html
> > (Note its a different matter that I dont think you should be doing thi )
> >
> > On Tue, May 5, 2015 at 11:54 AM, Shalin Shekhar Mangar <
> > shalinmangar@gmail.com> wrote:
> >
> > > No, I am reading the file contents myself i.e. with Java code inside
> the
> > > custom sampler.
> > >
> > > On Tue, May 5, 2015 at 11:15 PM, Deepak Shetty <sh...@gmail.com>
> > wrote:
> > >
> > > > Are you using CSV Data Set Config to read the query file?
> > > >
> > > > On Tue, May 5, 2015 at 9:57 AM, Shalin Shekhar Mangar <
> > > > shalinmangar@gmail.com> wrote:
> > > >
> > > > > Hello,
> > > > >
> > > > > I am writing a Java sampler that generates queries from a file to
> run
> > > > > against my custom application server. How do I signal to Jmeter
> that
> > I
> > > > have
> > > > > run out of queries and that the test is complete?
> > > > >
> > > > > I have set the thread group to loop forever. I can of course
> > constrain
> > > it
> > > > > to run only a certain number of times but I'd like to test with
> many
> > > > > different query files and I don't want to create different
> > > configuration
> > > > > (loop count, num threads) for each query file.
> > > > >
> > > > > --
> > > > > Regards,
> > > > > Shalin Shekhar Mangar.
> > > > >
> > > >
> > >
> > >
> > >
> > > --
> > > Regards,
> > > Shalin Shekhar Mangar.
> > >
> >
>
>
>
> --
> Regards,
> Shalin Shekhar Mangar.
>

Re: End jmeter test run from a Java sampler

Posted by Shalin Shekhar Mangar <sh...@gmail.com>.
Okay, I think I understand your hint about the CSV Data Set Config. I can
use that and set the "Stop thread on EOF" property to true. So let's say
that I read a line of my query file using the CSV Data Set Config, how do I
access that string from inside my Java sampler?

On Wed, May 6, 2015 at 12:31 AM, Deepak Shetty <sh...@gmail.com> wrote:

> ok try - use JMeterContextService - Get JmeterContext from which you can
> get the JMeter thread of JMeterThreadGroup and do ask it to stop --
> https://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterContext.html
> (Note its a different matter that I dont think you should be doing thi )
>
> On Tue, May 5, 2015 at 11:54 AM, Shalin Shekhar Mangar <
> shalinmangar@gmail.com> wrote:
>
> > No, I am reading the file contents myself i.e. with Java code inside the
> > custom sampler.
> >
> > On Tue, May 5, 2015 at 11:15 PM, Deepak Shetty <sh...@gmail.com>
> wrote:
> >
> > > Are you using CSV Data Set Config to read the query file?
> > >
> > > On Tue, May 5, 2015 at 9:57 AM, Shalin Shekhar Mangar <
> > > shalinmangar@gmail.com> wrote:
> > >
> > > > Hello,
> > > >
> > > > I am writing a Java sampler that generates queries from a file to run
> > > > against my custom application server. How do I signal to Jmeter that
> I
> > > have
> > > > run out of queries and that the test is complete?
> > > >
> > > > I have set the thread group to loop forever. I can of course
> constrain
> > it
> > > > to run only a certain number of times but I'd like to test with many
> > > > different query files and I don't want to create different
> > configuration
> > > > (loop count, num threads) for each query file.
> > > >
> > > > --
> > > > Regards,
> > > > Shalin Shekhar Mangar.
> > > >
> > >
> >
> >
> >
> > --
> > Regards,
> > Shalin Shekhar Mangar.
> >
>



-- 
Regards,
Shalin Shekhar Mangar.

Re: End jmeter test run from a Java sampler

Posted by Deepak Shetty <sh...@gmail.com>.
ok try - use JMeterContextService - Get JmeterContext from which you can
get the JMeter thread of JMeterThreadGroup and do ask it to stop --
https://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterContext.html
(Note its a different matter that I dont think you should be doing thi )

On Tue, May 5, 2015 at 11:54 AM, Shalin Shekhar Mangar <
shalinmangar@gmail.com> wrote:

> No, I am reading the file contents myself i.e. with Java code inside the
> custom sampler.
>
> On Tue, May 5, 2015 at 11:15 PM, Deepak Shetty <sh...@gmail.com> wrote:
>
> > Are you using CSV Data Set Config to read the query file?
> >
> > On Tue, May 5, 2015 at 9:57 AM, Shalin Shekhar Mangar <
> > shalinmangar@gmail.com> wrote:
> >
> > > Hello,
> > >
> > > I am writing a Java sampler that generates queries from a file to run
> > > against my custom application server. How do I signal to Jmeter that I
> > have
> > > run out of queries and that the test is complete?
> > >
> > > I have set the thread group to loop forever. I can of course constrain
> it
> > > to run only a certain number of times but I'd like to test with many
> > > different query files and I don't want to create different
> configuration
> > > (loop count, num threads) for each query file.
> > >
> > > --
> > > Regards,
> > > Shalin Shekhar Mangar.
> > >
> >
>
>
>
> --
> Regards,
> Shalin Shekhar Mangar.
>

Re: End jmeter test run from a Java sampler

Posted by Shalin Shekhar Mangar <sh...@gmail.com>.
No, I am reading the file contents myself i.e. with Java code inside the
custom sampler.

On Tue, May 5, 2015 at 11:15 PM, Deepak Shetty <sh...@gmail.com> wrote:

> Are you using CSV Data Set Config to read the query file?
>
> On Tue, May 5, 2015 at 9:57 AM, Shalin Shekhar Mangar <
> shalinmangar@gmail.com> wrote:
>
> > Hello,
> >
> > I am writing a Java sampler that generates queries from a file to run
> > against my custom application server. How do I signal to Jmeter that I
> have
> > run out of queries and that the test is complete?
> >
> > I have set the thread group to loop forever. I can of course constrain it
> > to run only a certain number of times but I'd like to test with many
> > different query files and I don't want to create different configuration
> > (loop count, num threads) for each query file.
> >
> > --
> > Regards,
> > Shalin Shekhar Mangar.
> >
>



-- 
Regards,
Shalin Shekhar Mangar.

Re: End jmeter test run from a Java sampler

Posted by Deepak Shetty <sh...@gmail.com>.
Are you using CSV Data Set Config to read the query file?

On Tue, May 5, 2015 at 9:57 AM, Shalin Shekhar Mangar <
shalinmangar@gmail.com> wrote:

> Hello,
>
> I am writing a Java sampler that generates queries from a file to run
> against my custom application server. How do I signal to Jmeter that I have
> run out of queries and that the test is complete?
>
> I have set the thread group to loop forever. I can of course constrain it
> to run only a certain number of times but I'd like to test with many
> different query files and I don't want to create different configuration
> (loop count, num threads) for each query file.
>
> --
> Regards,
> Shalin Shekhar Mangar.
>