Custom Sampler Tutorial

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
24 messages Options
12
E S
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Custom Sampler Tutorial

E S
I'm new to JMeter and am looking for a tutorial on how to write a customer
sampler. I would think this would be a popular topic, but I'm not really
finding much on it. I've seen this document

http://jakarta.apache.org/jmeter/extending/jmeter_tutorial.pdf

and didn't find it terribly helpful. Am I missing something here? Why aren't
there tons of examples on how to do this?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Custom Sampler Tutorial

Bruce Ide
I've written a couple of data elements, a sampler and a post-processor. Most
of what I picked up came from reading the jmeter source code itself. That's
probably the best place to start. I'm still not clear on how some of the UI
stuff works, but that's more due to me not being terribly familiar with
swing than because of jmeter.

--
Bruce Ide
[hidden email]
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

100% cpu utilization on application server

Dcunha, Stephanie
Hi,

            I am performing load test using jmeter on an application hosted on a tomcat server. The problem that I am facing is that the CPU utilization of the application server rises to 100% after a few minutes when a load is put, despite of the number of users.

I need to put up a load for 5000users and the server is getting killed just by a user load of 100.

The server configuration is 32GB of physical memory.

Is it a problem with Jmeter or the app. server ?

Thanks and Regards,
Stephanie D'cunha
Test Engineer
 [hidden email]


Information contained and transmitted by this e-mail is confidential and proprietary to iGATE Patni and its affiliates and is intended for use only by the recipient. If you are not the intended recipient, you are hereby notified that any dissemination, distribution, copying or use of this e-mail is strictly prohibited and you are requested to delete this e-mail immediately and notify the originator or [hidden email]. iGATE Patni does not enter into any agreement with any party by e-mail. Any views expressed by an individual do not necessarily reflect the view of iGATE Patni. iGATE Patni is not responsible for the consequences of any actions taken on the basis of information provided, through this email. The contents of an attachment to this e-mail may contain software viruses, which could damage your own computer system. While iGATE Patni has taken every reasonable precaution to minimise this risk, we cannot accept liability for any damage which you sustain as a result of software viruses. You should carry out your own virus checks before opening an attachment. To know more about iGATE Patni please visit www.igatepatni.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: 100% cpu utilization on application server

suresh_rajachar
App server's CPU is increasing. This nothing to do with Jmeter. This can be a performance bottleneck in the application.
Verify whether you ramp up   the load in a meaningful way.
 -Suresh
Sent using BlackBerry® from Orange

-----Original Message-----
From: "Dcunha, Stephanie" <[hidden email]>
Date: Wed, 15 Jun 2011 16:27:31
To: JMeter Users List<[hidden email]>
Reply-To: "JMeter Users List" <[hidden email]>
Subject: 100% cpu utilization on application server

Hi,

            I am performing load test using jmeter on an application hosted on a tomcat server. The problem that I am facing is that the CPU utilization of the application server rises to 100% after a few minutes when a load is put, despite of the number of users.

I need to put up a load for 5000users and the server is getting killed just by a user load of 100.

The server configuration is 32GB of physical memory.

Is it a problem with Jmeter or the app. server ?

Thanks and Regards,
Stephanie D'cunha
Test Engineer
 [hidden email]


Information contained and transmitted by this e-mail is confidential and proprietary to iGATE Patni and its affiliates and is intended for use only by the recipient. If you are not the intended recipient, you are hereby notified that any dissemination, distribution, copying or use of this e-mail is strictly prohibited and you are requested to delete this e-mail immediately and notify the originator or [hidden email]. iGATE Patni does not enter into any agreement with any party by e-mail. Any views expressed by an individual do not necessarily reflect the view of iGATE Patni. iGATE Patni is not responsible for the consequences of any actions taken on the basis of information provided, through this email. The contents of an attachment to this e-mail may contain software viruses, which could damage your own computer system. While iGATE Patni has taken every reasonable precaution to minimise this risk, we cannot accept liability for any damage which you sustain as a result of software viruses. You should carry out your own virus checks before opening an attachment. To know more about iGATE Patni please visit www.igatepatni.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: 100% cpu utilization on application server

shettyd
In reply to this post by Dcunha, Stephanie
>I need to put up a load for 5000users and the server is getting killed just
by a user load of 100.
Concurrent users? JMeter doesnt pause between requests (by default) so if
you have just set it up as 100 threads , then you actually testing for a
larger number of users.

However it's still possible your server doesnt respond well for higher loads
, and you would then need to profile your application to figure out the
problem.


On Wed, Jun 15, 2011 at 3:57 AM, Dcunha, Stephanie <
[hidden email]> wrote:

> Hi,
>
>            I am performing load test using jmeter on an application hosted
> on a tomcat server. The problem that I am facing is that the CPU utilization
> of the application server rises to 100% after a few minutes when a load is
> put, despite of the number of users.
>
> I need to put up a load for 5000users and the server is getting killed just
> by a user load of 100.
>
> The server configuration is 32GB of physical memory.
>
> Is it a problem with Jmeter or the app. server ?
>
> Thanks and Regards,
> Stephanie D'cunha
> Test Engineer
>  [hidden email]
>
>
> Information contained and transmitted by this e-mail is confidential and
> proprietary to iGATE Patni and its affiliates and is intended for use only
> by the recipient. If you are not the intended recipient, you are hereby
> notified that any dissemination, distribution, copying or use of this e-mail
> is strictly prohibited and you are requested to delete this e-mail
> immediately and notify the originator or [hidden email]. iGATE
> Patni does not enter into any agreement with any party by e-mail. Any views
> expressed by an individual do not necessarily reflect the view of iGATE
> Patni. iGATE Patni is not responsible for the consequences of any actions
> taken on the basis of information provided, through this email. The contents
> of an attachment to this e-mail may contain software viruses, which could
> damage your own computer system. While iGATE Patni has taken every
> reasonable precaution to minimise this risk, we cannot accept liability for
> any damage which you sustain as a result of software viruses. You should
> carry out your own virus checks before opening an attachment. To know more
> about iGATE Patni please visit www.igatepatni.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: 100% cpu utilization on application server

Fazal Syed Ali
In reply to this post by Dcunha, Stephanie
Make sure your Tomcat memory settings are utilizing whole 32G of physical
memory.

Thanks,
Fazal

On Wed, Jun 15, 2011 at 5:57 AM, Dcunha, Stephanie <
[hidden email]> wrote:

> Hi,
>
>            I am performing load test using jmeter on an application hosted
> on a tomcat server. The problem that I am facing is that the CPU utilization
> of the application server rises to 100% after a few minutes when a load is
> put, despite of the number of users.
>
> I need to put up a load for 5000users and the server is getting killed just
> by a user load of 100.
>
> The server configuration is 32GB of physical memory.
>
> Is it a problem with Jmeter or the app. server ?
>
> Thanks and Regards,
> Stephanie D'cunha
> Test Engineer
>  [hidden email]
>
>
> Information contained and transmitted by this e-mail is confidential and
> proprietary to iGATE Patni and its affiliates and is intended for use only
> by the recipient. If you are not the intended recipient, you are hereby
> notified that any dissemination, distribution, copying or use of this e-mail
> is strictly prohibited and you are requested to delete this e-mail
> immediately and notify the originator or [hidden email]. iGATE
> Patni does not enter into any agreement with any party by e-mail. Any views
> expressed by an individual do not necessarily reflect the view of iGATE
> Patni. iGATE Patni is not responsible for the consequences of any actions
> taken on the basis of information provided, through this email. The contents
> of an attachment to this e-mail may contain software viruses, which could
> damage your own computer system. While iGATE Patni has taken every
> reasonable precaution to minimise this risk, we cannot accept liability for
> any damage which you sustain as a result of software viruses. You should
> carry out your own virus checks before opening an attachment. To know more
> about iGATE Patni please visit www.igatepatni.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
Syed Fazal Ali
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Regular expresion to capture multiple lines

Benedict.Nkosi
Hi everyone, I'm trying to correlate a value but the right and left
boundaries are not on the same line.
I want to use "Total Number of Exceptions" as my left boundary and
"</TR>" as my right.

Please help.

return false;">
                        Total Number of Exceptions
                </a>
        </TD>
        <td width=50>
        39
        </td>
   </TR>

   <TR>


Kind Regards
Benedict Nkosi
Performance Tester





---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Regular expresion to capture multiple lines

shettyd
http://jakarta.apache.org/jmeter/usermanual/regular_expressions.html
I believe you need to prefix your regex with(?s) to treat the text as a
single line - however i do not currently have an environment to test
Something like (?is)Total Number of Exceptions(.*?)</TR> - test it and let
us know.

regards
deepak

On Wed, Jun 15, 2011 at 10:39 AM, <[hidden email]> wrote:

> Hi everyone, I'm trying to correlate a value but the right and left
> boundaries are not on the same line.
> I want to use "Total Number of Exceptions" as my left boundary and
> "</TR>" as my right.
>
> Please help.
>
> return false;">
>                        Total Number of Exceptions
>                </a>
>        </TD>
>        <td width=50>
>        39
>        </td>
>   </TR>
>
>   <TR>
>
>
> Kind Regards
> Benedict Nkosi
> Performance Tester
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Regular expresion to capture multiple lines

Oliver Lloyd
Total Number of Exceptions(\n|.)*<\/TD>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Regular expresion to capture multiple lines

Benedict.Nkosi
In reply to this post by shettyd
Hi, I tested it and it doesn't find it. Do you need any other
information from me?

Kind Regards
Benedict Nkosi
Performance Tester


-----Original Message-----
From: Deepak Shetty [mailto:[hidden email]]
Sent: Wednesday, June 15, 2011 12:49 PM
To: JMeter Users List
Subject: Re: Regular expresion to capture multiple lines

http://jakarta.apache.org/jmeter/usermanual/regular_expressions.html
I believe you need to prefix your regex with(?s) to treat the text as a
single line - however i do not currently have an environment to test
Something like (?is)Total Number of Exceptions(.*?)</TR> - test it and
let
us know.

regards
deepak

On Wed, Jun 15, 2011 at 10:39 AM, <[hidden email]> wrote:

> Hi everyone, I'm trying to correlate a value but the right and left
> boundaries are not on the same line.
> I want to use "Total Number of Exceptions" as my left boundary and
> "</TR>" as my right.
>
> Please help.
>
> return false;">
>                        Total Number of Exceptions
>                </a>
>        </TD>
>        <td width=50>
>        39
>        </td>
>   </TR>
>
>   <TR>
>
>
> Kind Regards
> Benedict Nkosi
> Performance Tester
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Regular expresion to capture multiple lines

Oliver Lloyd
In reply to this post by Oliver Lloyd
Ooops, you said 'TR'.

Total Number of Exceptions(\n|.)*<\/TR>

But you could have worked that out yourself I'm sure...

Also, weird thing to match on, why not get the actual value?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Regular expresion to capture multiple lines

Oliver Lloyd
It does work. Try it here or here. Both give correct matches.

Note, I'm only going by what you wrote - check your original post.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Regular expresion to capture multiple lines

Oliver Lloyd
Oh...you're replying to Deepak. I see.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Regular expresion to capture multiple lines

Benedict.Nkosi
In reply to this post by Oliver Lloyd
Hi Lloyd, Thanks a lot, its working.

Kind Regards
Benedict Nkosi
Performance Tester


-----Original Message-----
From: Oliver Lloyd [mailto:[hidden email]]
Sent: Wednesday, June 15, 2011 1:20 PM
To: [hidden email]
Subject: Re: Regular expresion to capture multiple lines

Ooops, you said 'TR'.

Total Number of Exceptions(\n|.)*<\/TR>

But you could have worked that out yourself I'm sure...

Also, weird thing to match on, why not get the actual value?

--
View this message in context:
http://jmeter.512774.n5.nabble.com/Custom-Sampler-Tutorial-tp4490189p449
2154.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]




---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Custom Sampler Tutorial

Barrie Treloar
In reply to this post by Bruce Ide
On Wed, Jun 15, 2011 at 3:41 PM, Bruce Ide <[hidden email]> wrote:
> I've written a couple of data elements, a sampler and a post-processor. Most
> of what I picked up came from reading the jmeter source code itself. That's
> probably the best place to start. I'm still not clear on how some of the UI
> stuff works, but that's more due to me not being terribly familiar with
> swing than because of jmeter.

The reason there are not tons of examples is because most people are using HTTP.
Any other testing and you are in the minority.

As Bruce says,  its hack away.
What type of Custom Sampler are you writing?

If its a JavaSamplerClient, then here are some notes from my hacking.

* Logging is available by

import org.apache.log.Logger;
  private static final Logger LOGGER =
Hierarchy.getDefaultHierarchy().getLoggerFor(<YOUR_CLASS>.class.getName());

* Threading model is one "client" per Thread.
  If you need state between threads you need to really think hard
about how to implement it.
  Our problem was we are modelling the a thick Java client that
connects over UDP.
  So something needs to start up a UDP listen port and receive
messages and pass them on to the correct sampler.
  We *BROKE* the JMeter threading model and made the ThreadGroup the
"client".  But we did this knowing the limitations.
  Your mileage may vary...

* getDefaultParameters() defines the complete and final set of
parameters available.
  The UI has an "add" button, but this doesn't actually add a new
parameter to the class.  There is JIRA about removing that button.
  If you want to add a new parameter to your test you must add it to
the Arguments returned by getDefaultParameters().
  My personal preference is to set the default value of the parameter
to "${YOUR_PARAMETER_NAME}"
e.g.
  /**
   * See class Javadoc.
   *
   * @JMeterParameter
   */
  public static final String PARAMETER_TIMEOUT = "timeout";

  public Arguments getDefaultParameters() {
    Arguments arguments = new Arguments();
    arguments.addArgument(PARAMETER_TIMEOUT, "${TIMEOUT}");
    ...

  I also define a constant for the parameter in my Java sampler class
because you will need it to extract the value of the the
JavaSamplerContext in runTest()

  I document in the class javadoc what all the parameters mean and
acceptable values.

* create your own factory method for instantiating SampleResults
  I found I was setting the same values all the time, so a factory
method saved some duplication.

  /**
   * Use UTF-8 for encoding of strings
   */
  public static final String ENCODING = "UTF-8";

  public SampleResult newSampleResult() {
    SampleResult result = new SampleResult();
    result.setDataEncoding(ENCODING);
    result.setDataType(SampleResult.TEXT);
    return result;
  }

* create helper methods for start, success and failure.
  /**
   * Start the sample request and set the <code>samplerData</code> to the
   * requestData.
   *
   * @param result
   *          the sample result to update
   * @param requestData
   *          the request to set as <code>samplerData</code>
   */
  protected void sampleResultStart(SampleResult result, String requestData) {
    result.setSamplerData(requestData);
    result.sampleStart();
  }

  /**
   * Set the sample result as <code>sampleEnd()</code>,
   * <code>setSuccessful(true)</code>, <code>setResponseCode("OK")</code> and if
   * the response is not <code>null</code> then
   * <code>setResponseData(response.toString(), ENCODING)</code> otherwise it is
   * marked as not requiring a response.
   *
   * @param result
   *          sample result to change
   * @param response
   *          the successful result message, may be null.
   */
  protected void sampleResultSuccess(SampleResult result,
      String response) {
    result.sampleEnd();
    result.setSuccessful(true);
    result.setResponseCode("OK");
    if (response != null) {
      result.setResponseData(response, ENCODING);
    }
    else {
      result.setResponseData("No response required", ENCODING);
    }
  }

  /**
   * Mark the sample result as <code>sampleEnd</code>,
   * <code>setSuccessful(false)</code> and the <code>setResponseCode</code> to
   * reason.
   *
   * @param result
   *          the sample result to change
   * @param reason
   *          the failure reason
   */
  protected void sampleResultFailed(SampleResult result, String reason) {
    result.sampleEnd();
    result.setSuccessful(false);
    result.setResponseCode(reason);
  }

  /**
   * Equivalent to
   * <code>sampleResultFailed(result, "Exception raised: " + cause)</code>
   *
   * @param result
   *          the result to modify
   * @param cause
   *          the cause of the failure
   */
  protected void sampleResultFailed(SampleResult result, Exception cause) {
    sampleResultFailed(result, "Exception raised: " + cause);
  }

* If your test has multiple results, you will need to manually create
a parent container SampleResult and determine the success/failure
based on the children.
  (Subresults are inserted via result.addSubResult())

  Something like (NOTE: this assumes there is only a depth of 1 for
the children)

  public SampleResult runTest(JavaSamplerContext context) {
    ...
    } finally {
      SampleResult[] subResults = result.getSubResults();
      boolean isOk = true;
      for (SampleResult sampleResult : subResults) {
        if (!sampleResult.isSuccessful()) {
          isOk = false;
          break;
        }
      }
      result.setSuccessful(isOk);
      result.sampleEnd();
    }

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Regular expresion to capture multiple lines

shettyd
In reply to this post by Benedict.Nkosi
Hi
I tested it and it worked me. However I see you have your solution so we
needn't look further :)

regards
deepak

On Wed, Jun 15, 2011 at 11:15 AM, <[hidden email]> wrote:

> Hi, I tested it and it doesn't find it. Do you need any other
> information from me?
>
> Kind Regards
> Benedict Nkosi
> Performance Tester
>
>
> -----Original Message-----
> From: Deepak Shetty [mailto:[hidden email]]
> Sent: Wednesday, June 15, 2011 12:49 PM
> To: JMeter Users List
> Subject: Re: Regular expresion to capture multiple lines
>
> http://jakarta.apache.org/jmeter/usermanual/regular_expressions.html
> I believe you need to prefix your regex with(?s) to treat the text as a
> single line - however i do not currently have an environment to test
> Something like (?is)Total Number of Exceptions(.*?)</TR> - test it and
> let
> us know.
>
> regards
> deepak
>
> On Wed, Jun 15, 2011 at 10:39 AM, <[hidden email]> wrote:
>
> > Hi everyone, I'm trying to correlate a value but the right and left
> > boundaries are not on the same line.
> > I want to use "Total Number of Exceptions" as my left boundary and
> > "</TR>" as my right.
> >
> > Please help.
> >
> > return false;">
> >                        Total Number of Exceptions
> >                </a>
> >        </TD>
> >        <td width=50>
> >        39
> >        </td>
> >   </TR>
> >
> >   <TR>
> >
> >
> > Kind Regards
> > Benedict Nkosi
> > Performance Tester
> >
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
E S
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Custom Sampler Tutorial

E S
In reply to this post by Barrie Treloar
Barrie,

Thanks for sharing your code. I am also currently using the Http Request
sampler, but I don't know of an easy way to simulate the required use cases
with that sampler in conjunction with other elements like timers. Instead of
repeating the whole problem, I'll just point you to another thread in which
I'm already discussing the issue (and why I'm leaning toward a custom
sampler).

http://mail-archives.apache.org/mod_mbox/jakarta-jmeter-user/201106.mbox/%3CBANLkTikOEj_k-fcigkOhP4RggUkg3JCKVA@...%3E

That's just my original post. There are follow ups as well, but I couldn't
get it to include all those in one link.

Dave

On Wed, Jun 15, 2011 at 6:06 PM, Barrie Treloar <[hidden email]> wrote:

> On Wed, Jun 15, 2011 at 3:41 PM, Bruce Ide <[hidden email]>
> wrote:
> > I've written a couple of data elements, a sampler and a post-processor.
> Most
> > of what I picked up came from reading the jmeter source code itself.
> That's
> > probably the best place to start. I'm still not clear on how some of the
> UI
> > stuff works, but that's more due to me not being terribly familiar with
> > swing than because of jmeter.
>
> The reason there are not tons of examples is because most people are using
> HTTP.
> Any other testing and you are in the minority.
>
> As Bruce says,  its hack away.
> What type of Custom Sampler are you writing?
>
> If its a JavaSamplerClient, then here are some notes from my hacking.
>
> * Logging is available by
>
> import org.apache.log.Logger;
>  private static final Logger LOGGER =
> Hierarchy.getDefaultHierarchy().getLoggerFor(<YOUR_CLASS>.class.getName());
>
> * Threading model is one "client" per Thread.
>  If you need state between threads you need to really think hard
> about how to implement it.
>  Our problem was we are modelling the a thick Java client that
> connects over UDP.
>  So something needs to start up a UDP listen port and receive
> messages and pass them on to the correct sampler.
>  We *BROKE* the JMeter threading model and made the ThreadGroup the
> "client".  But we did this knowing the limitations.
>  Your mileage may vary...
>
> * getDefaultParameters() defines the complete and final set of
> parameters available.
>  The UI has an "add" button, but this doesn't actually add a new
> parameter to the class.  There is JIRA about removing that button.
>  If you want to add a new parameter to your test you must add it to
> the Arguments returned by getDefaultParameters().
>  My personal preference is to set the default value of the parameter
> to "${YOUR_PARAMETER_NAME}"
> e.g.
>  /**
>   * See class Javadoc.
>   *
>   * @JMeterParameter
>   */
>  public static final String PARAMETER_TIMEOUT = "timeout";
>
>  public Arguments getDefaultParameters() {
>    Arguments arguments = new Arguments();
>    arguments.addArgument(PARAMETER_TIMEOUT, "${TIMEOUT}");
>    ...
>
>  I also define a constant for the parameter in my Java sampler class
> because you will need it to extract the value of the the
> JavaSamplerContext in runTest()
>
>  I document in the class javadoc what all the parameters mean and
> acceptable values.
>
> * create your own factory method for instantiating SampleResults
>  I found I was setting the same values all the time, so a factory
> method saved some duplication.
>
>  /**
>   * Use UTF-8 for encoding of strings
>   */
>  public static final String ENCODING = "UTF-8";
>
>  public SampleResult newSampleResult() {
>    SampleResult result = new SampleResult();
>    result.setDataEncoding(ENCODING);
>    result.setDataType(SampleResult.TEXT);
>    return result;
>  }
>
> * create helper methods for start, success and failure.
>  /**
>   * Start the sample request and set the <code>samplerData</code> to the
>   * requestData.
>   *
>   * @param result
>   *          the sample result to update
>   * @param requestData
>   *          the request to set as <code>samplerData</code>
>   */
>  protected void sampleResultStart(SampleResult result, String requestData)
> {
>    result.setSamplerData(requestData);
>    result.sampleStart();
>  }
>
>  /**
>   * Set the sample result as <code>sampleEnd()</code>,
>   * <code>setSuccessful(true)</code>, <code>setResponseCode("OK")</code>
> and if
>   * the response is not <code>null</code> then
>   * <code>setResponseData(response.toString(), ENCODING)</code> otherwise
> it is
>   * marked as not requiring a response.
>   *
>   * @param result
>   *          sample result to change
>   * @param response
>   *          the successful result message, may be null.
>   */
>  protected void sampleResultSuccess(SampleResult result,
>      String response) {
>    result.sampleEnd();
>    result.setSuccessful(true);
>    result.setResponseCode("OK");
>    if (response != null) {
>      result.setResponseData(response, ENCODING);
>    }
>    else {
>      result.setResponseData("No response required", ENCODING);
>    }
>  }
>
>  /**
>   * Mark the sample result as <code>sampleEnd</code>,
>   * <code>setSuccessful(false)</code> and the <code>setResponseCode</code>
> to
>   * reason.
>   *
>   * @param result
>   *          the sample result to change
>   * @param reason
>   *          the failure reason
>   */
>  protected void sampleResultFailed(SampleResult result, String reason) {
>    result.sampleEnd();
>    result.setSuccessful(false);
>    result.setResponseCode(reason);
>  }
>
>  /**
>   * Equivalent to
>   * <code>sampleResultFailed(result, "Exception raised: " + cause)</code>
>   *
>   * @param result
>   *          the result to modify
>   * @param cause
>   *          the cause of the failure
>   */
>  protected void sampleResultFailed(SampleResult result, Exception cause) {
>    sampleResultFailed(result, "Exception raised: " + cause);
>  }
>
> * If your test has multiple results, you will need to manually create
> a parent container SampleResult and determine the success/failure
> based on the children.
>  (Subresults are inserted via result.addSubResult())
>
>  Something like (NOTE: this assumes there is only a depth of 1 for
> the children)
>
>  public SampleResult runTest(JavaSamplerContext context) {
>    ...
>    } finally {
>      SampleResult[] subResults = result.getSubResults();
>      boolean isOk = true;
>      for (SampleResult sampleResult : subResults) {
>        if (!sampleResult.isSuccessful()) {
>          isOk = false;
>          break;
>        }
>      }
>      result.setSuccessful(isOk);
>      result.sampleEnd();
>    }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
E S
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Custom Sampler Tutorial

E S
Barrie,

How did you deploy your sampler so you could actually use it in the JMeter
GUI? I've seen that the guys who wrote jmeter-plugins got it to the point
where you could just drop a jar file into the lib/ext directory and it just
worked. Did you get to the point?

Dave

On Thu, Jun 16, 2011 at 11:17 AM, E S <[hidden email]> wrote:

> Barrie,
>
> Thanks for sharing your code. I am also currently using the Http Request
> sampler, but I don't know of an easy way to simulate the required use cases
> with that sampler in conjunction with other elements like timers. Instead of
> repeating the whole problem, I'll just point you to another thread in which
> I'm already discussing the issue (and why I'm leaning toward a custom
> sampler).
>
>
> http://mail-archives.apache.org/mod_mbox/jakarta-jmeter-user/201106.mbox/%3CBANLkTikOEj_k-fcigkOhP4RggUkg3JCKVA@...%3E
>
> That's just my original post. There are follow ups as well, but I couldn't
> get it to include all those in one link.
>
> Dave
>
>
> On Wed, Jun 15, 2011 at 6:06 PM, Barrie Treloar <[hidden email]>wrote:
>
>> On Wed, Jun 15, 2011 at 3:41 PM, Bruce Ide <[hidden email]>
>> wrote:
>> > I've written a couple of data elements, a sampler and a post-processor.
>> Most
>> > of what I picked up came from reading the jmeter source code itself.
>> That's
>> > probably the best place to start. I'm still not clear on how some of the
>> UI
>> > stuff works, but that's more due to me not being terribly familiar with
>> > swing than because of jmeter.
>>
>> The reason there are not tons of examples is because most people are using
>> HTTP.
>> Any other testing and you are in the minority.
>>
>> As Bruce says,  its hack away.
>> What type of Custom Sampler are you writing?
>>
>> If its a JavaSamplerClient, then here are some notes from my hacking.
>>
>> * Logging is available by
>>
>> import org.apache.log.Logger;
>>  private static final Logger LOGGER =
>>
>> Hierarchy.getDefaultHierarchy().getLoggerFor(<YOUR_CLASS>.class.getName());
>>
>> * Threading model is one "client" per Thread.
>>  If you need state between threads you need to really think hard
>> about how to implement it.
>>  Our problem was we are modelling the a thick Java client that
>> connects over UDP.
>>  So something needs to start up a UDP listen port and receive
>> messages and pass them on to the correct sampler.
>>  We *BROKE* the JMeter threading model and made the ThreadGroup the
>> "client".  But we did this knowing the limitations.
>>  Your mileage may vary...
>>
>> * getDefaultParameters() defines the complete and final set of
>> parameters available.
>>  The UI has an "add" button, but this doesn't actually add a new
>> parameter to the class.  There is JIRA about removing that button.
>>  If you want to add a new parameter to your test you must add it to
>> the Arguments returned by getDefaultParameters().
>>  My personal preference is to set the default value of the parameter
>> to "${YOUR_PARAMETER_NAME}"
>> e.g.
>>  /**
>>   * See class Javadoc.
>>   *
>>   * @JMeterParameter
>>   */
>>  public static final String PARAMETER_TIMEOUT = "timeout";
>>
>>  public Arguments getDefaultParameters() {
>>    Arguments arguments = new Arguments();
>>    arguments.addArgument(PARAMETER_TIMEOUT, "${TIMEOUT}");
>>    ...
>>
>>  I also define a constant for the parameter in my Java sampler class
>> because you will need it to extract the value of the the
>> JavaSamplerContext in runTest()
>>
>>  I document in the class javadoc what all the parameters mean and
>> acceptable values.
>>
>> * create your own factory method for instantiating SampleResults
>>  I found I was setting the same values all the time, so a factory
>> method saved some duplication.
>>
>>  /**
>>   * Use UTF-8 for encoding of strings
>>   */
>>  public static final String ENCODING = "UTF-8";
>>
>>  public SampleResult newSampleResult() {
>>    SampleResult result = new SampleResult();
>>    result.setDataEncoding(ENCODING);
>>    result.setDataType(SampleResult.TEXT);
>>    return result;
>>  }
>>
>> * create helper methods for start, success and failure.
>>  /**
>>   * Start the sample request and set the <code>samplerData</code> to the
>>   * requestData.
>>   *
>>   * @param result
>>   *          the sample result to update
>>   * @param requestData
>>   *          the request to set as <code>samplerData</code>
>>   */
>>  protected void sampleResultStart(SampleResult result, String requestData)
>> {
>>    result.setSamplerData(requestData);
>>    result.sampleStart();
>>  }
>>
>>  /**
>>   * Set the sample result as <code>sampleEnd()</code>,
>>   * <code>setSuccessful(true)</code>, <code>setResponseCode("OK")</code>
>> and if
>>   * the response is not <code>null</code> then
>>   * <code>setResponseData(response.toString(), ENCODING)</code> otherwise
>> it is
>>   * marked as not requiring a response.
>>   *
>>   * @param result
>>   *          sample result to change
>>   * @param response
>>   *          the successful result message, may be null.
>>   */
>>  protected void sampleResultSuccess(SampleResult result,
>>      String response) {
>>    result.sampleEnd();
>>    result.setSuccessful(true);
>>    result.setResponseCode("OK");
>>    if (response != null) {
>>      result.setResponseData(response, ENCODING);
>>    }
>>    else {
>>      result.setResponseData("No response required", ENCODING);
>>    }
>>  }
>>
>>  /**
>>   * Mark the sample result as <code>sampleEnd</code>,
>>   * <code>setSuccessful(false)</code> and the <code>setResponseCode</code>
>> to
>>   * reason.
>>   *
>>   * @param result
>>   *          the sample result to change
>>   * @param reason
>>   *          the failure reason
>>   */
>>  protected void sampleResultFailed(SampleResult result, String reason) {
>>    result.sampleEnd();
>>    result.setSuccessful(false);
>>    result.setResponseCode(reason);
>>  }
>>
>>  /**
>>   * Equivalent to
>>   * <code>sampleResultFailed(result, "Exception raised: " + cause)</code>
>>   *
>>   * @param result
>>   *          the result to modify
>>   * @param cause
>>   *          the cause of the failure
>>   */
>>  protected void sampleResultFailed(SampleResult result, Exception cause) {
>>    sampleResultFailed(result, "Exception raised: " + cause);
>>  }
>>
>> * If your test has multiple results, you will need to manually create
>> a parent container SampleResult and determine the success/failure
>> based on the children.
>>  (Subresults are inserted via result.addSubResult())
>>
>>  Something like (NOTE: this assumes there is only a depth of 1 for
>> the children)
>>
>>  public SampleResult runTest(JavaSamplerContext context) {
>>    ...
>>    } finally {
>>      SampleResult[] subResults = result.getSubResults();
>>      boolean isOk = true;
>>      for (SampleResult sampleResult : subResults) {
>>        if (!sampleResult.isSuccessful()) {
>>          isOk = false;
>>          break;
>>        }
>>      }
>>      result.setSuccessful(isOk);
>>      result.sampleEnd();
>>    }
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Custom Sampler Tutorial

Bruce Ide
You just roll 'em up in a Jar file. I use maven for my builds and it puts a
jar together for me. As long as you implemented the interfaces correctly and
conform to (what I assume are) the bean standards, jmeter just picks your
object up and you get new menu entries in the correct locations and
everything.

If you did something wrong, you either don't get a new menu entry for your
sampler, or you get one but it has the wrong label, or no label. Or it looks
like it's going to work but you can't actually configure the sampler.

It's a good idea to pull in the logging classes earlier rather than later,
and log everything. Then you can look in your jmeter log and see how far
your class got, or if it get anywhere at all.

--
Bruce Ide
[hidden email]
E S
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Custom Sampler Tutorial

E S
Okay, well I got something to deploy and show up in the GUI, but I'm a
little confused on the methodology. The tutorial (
http://jakarta.apache.org/jmeter/extending/jmeter_tutorial.pdf) talks about
defining GUI classes using swing, but then gives an example in which no GUI
classes are defined. Instead it seems to be using the "TestBean framework",
which I can't find much information on but apparently takes the properties
of a class an generates a GUI from them for you. I can see samplers in the
source code that use both methods (the TestAction sampler defined its own
GUI whereas the DebuggerSampler uses the TestBean method). Is one method
preferred over the other or do you use TestBean unless you need more control
over the GUI in which case you define your own?

Sorry if these are basic questions, but I'm having trouble finding much
documentation related to extending the system.

On Thu, Jun 16, 2011 at 4:53 PM, Bruce Ide <[hidden email]>wrote:

> You just roll 'em up in a Jar file. I use maven for my builds and it puts a
> jar together for me. As long as you implemented the interfaces correctly
> and
> conform to (what I assume are) the bean standards, jmeter just picks your
> object up and you get new menu entries in the correct locations and
> everything.
>
> If you did something wrong, you either don't get a new menu entry for your
> sampler, or you get one but it has the wrong label, or no label. Or it
> looks
> like it's going to work but you can't actually configure the sampler.
>
> It's a good idea to pull in the logging classes earlier rather than later,
> and log everything. Then you can look in your jmeter log and see how far
> your class got, or if it get anywhere at all.
>
> --
> Bruce Ide
> [hidden email]
>
12
Loading...