JMeter

About

Download

Documentation

Tutorials (PDF format)

Community


18.1 Samplers

Samplers perform the actual work of JMeter. Each sampler (except Test Action) generates one or more sample results. The sample results have various attributes (success/fail, elapsed time, data size etc) and can be viewed in the various listeners.

18.1.1 FTP Request

This controller lets you send an FTP "retrieve file" or "upload file" request to an FTP server. If you are going to send multiple requests to the same FTP server, consider using a FTP Request Defaults Configuration Element so you do not have to enter the same information for each FTP Request Generative Controller. When downloading a file, it can be stored on disk (Local File) or in the Response Data, or both.

Control Panel

Parameters

AttributeDescriptionRequired
Name Descriptive name for this controller that is shown in the tree. No
Server Name or IP Domain name or IP address of the FTP server. JMeter assumes the FTP server is listening on the default port. Yes
Remote File: File to retrieve or upload. Yes
Local File: File to upload, or destination for downloads. Yes, if uploading
get(RETR) / put(STOR) Whether to retrieve or upload a file. Yes
Use Binary mode ? Check this to use Binary mode (default Ascii) Yes
Save File in Response ? Whether to store contents of retrieved file in response data. If the mode is Ascii, then the contents will be visible in the Tree View Listener. Yes, if downloading
Username FTP account username. Usually
Password FTP account password. N.B. This will be visible in the test plan. Usually

See Also:



18.1.2 HTTP Request

This sampler lets you send an HTTP/HTTPS request to a web server. It also lets you control whether or not JMeter parses HTML files for images and other embedded resources and sends HTTP requests to retrieve them. The following types of embedded resource are retrieved:

  • images
  • applets
  • stylesheets
  • external scripts
  • frames
  • background images (body, table, TD, TR)
  • background sound

The default parser is htmlparser. This can be changed by using the property "htmlparser.classname" - see jmeter.properties for details.

If you are going to send multiple requests to the same web server, consider using an HTTP Request Defaults Configuration Element so you do not have to enter the same information for each HTTP Request.

Or, instead of manually adding HTTP Requests, you may want to use JMeter's HTTP Proxy Server to create them. This can save you time if you have a lot of HTTP requests or requests with many parameters.

There are two versions of the sampler - one uses the default Java HTTP implementation, the other uses Commons HttpClient.

The default (Java) implementation has some limitations:

  • There is no control over how connections are re-used. When a connection is released by JMeter, it may or may not be re-used by the same thread.
  • The API is best suited to single-threaded usage - various settings (e.g. proxy) are defined via system properties, and therefore apply to all connections.
  • There is a bug in the handling of HTTPS via a Proxy (the CONNECT is not handled correctly). See Java bugs 6226610 and 6208335.

Note: the FILE protocol is intended for testing puposes only. It is handled by the same code regardless of which HTTP Sampler is used.

If the request requires server or proxy login authorization (i.e. where a browser would create a pop-up dialog box), you will also have to add an HTTP Authorization Manager Configuration Element. For normal logins (i.e. where the user enters login information in a form), you will need to work out what the form submit button does, and create an HTTP request with the appropriate method (usually POST) and the appropriate parameters from the form definition. If the page uses HTTP, you can use the JMeter Proxy to capture the login sequence.

In versions of JMeter up to 2.2, only a single SSL context was used for all threads and samplers. This did not generate the proper load for multiple users. A separate SSL context is now used for each thread. To revert to the original behaviour, set the JMeter property:

								
https.sessioncontext.shared=true

						

JMeter defaults to the SSL protocol level TLS. If the server needs a different level, e.g. SSLv3, change the JMeter property, for example:

								
https.default.protocol=SSLv3

						

If the request uses cookies, then you will also need an HTTP Cookie Manager . You can add either of these elements to the Thread Group or the HTTP Request. If you have more than one HTTP Request that needs authorizations or cookies, then add the elements to the Thread Group. That way, all HTTP Request controllers will share the same Authorization Manager and Cookie Manager elements.

If the request uses a technique called "URL Rewriting" to maintain sessions, then see section 6.1 Handling User Sessions With URL Rewriting for additional configuration steps.

Control Panel

Parameters

AttributeDescriptionRequired
Name Descriptive name for this controller that is shown in the tree. No
Server Domain name or IP address of the web server. No
Port Port the web server is listening to. Default: 80 No
Protocol HTTP, HTTPS or FILE. Default: HTTP No
Method GET, POST, HEAD, TRACE, OPTIONS, PUT, DELETE Yes
Content Encoding Content encoding to be used (for POST and FILE) No
Redirect Automatically Sets the underlying http protocol handler to automatically follow redirects, so they are not seen by JMeter, and thus will not appear as samples. In versions after 2.2, this is now the default. Warning: see below for information on cookie handling. Yes
Follow Redirects This only has any effect if "Redirect Automatically" is not enabled. If set, the JMeter sampler will check if the response is a redirect and follow it if so. The redirect response will appear as an additional sample. Note that the HttpClient sampler may log the following message:

"Redirect requested but followRedirects is disabled"

This can be ignored.
Yes
Use KeepAlive JMeter sets the Connection: keep-alive header. This does not work properly with the default HTTP implementation, as connection re-use is not under user-control. It does work with the Jakarta httpClient implementation. Yes
Use multipart/form-data for HTTP POST Use a multipart/form-data or application/x-www-form-urlencoded post request Yes
Path The path to resource (for example, /servlets/myServlet). If the resource requires query string parameters, add them below in the "Send Parameters With the Request" section. Yes
Send Parameters With the Request The query string will be generated from the list of parameters you provide. Each parameter has a name and value , the options to encode the parameter, and an option to include or exclude an equals sign (some applications don't expect an equals when the value is the empty string). The query string will be generated in the correct fashion, depending on the choice of "Method" you made (ie if you chose GET or DELETE, the query string will be appended to the URL, if POST or PUT, then it will be sent separately). Also, if you are sending a file using a multipart form, the query string will be created using the multipart form specifications. See below for some further information on parameter handling.

Additionally, you can specify whether each paramter should be URL encoded. If you are not sure what this means, it is probably best to select it. If your values contain characters such as & or spaces, or question marks, then encoding is usually required.

No
Filename Name of the file to send. If left blank, JMeter does not send a file, if filled in, JMeter automatically sends the request as a multipart form request.

If it is a POST or PUT request and the 'name' atribute (below) are omitted, then the file is sent as the body of the request. This allows arbitrary bodies to be sent. This functionality is present for POST requests after version 2.2, and also for PUT requests after version 2.3. See below for some further information on parameter handling.

No
Value for 'name' attribute Value of the "name" web request parameter. No
MIME Type MIME type (for example, text/plain). If it is a POST or PUT request and either the 'name' atribute (below) are omitted or the request body is constructed from parameter values only, then the value of this field is used as the value of the content-type request header. No
Retrieve All Embedded Resources from HTML Files Tell JMeter to parse the HTML file and send HTTP/HTTPS requests for all images, Java applets, JavaScript files, CSSs, etc. referenced in the file. See below for more details. No
Use as monitor For use with the Monitor Results listener. Yes
Embedded URLs must match: If present, this must be a regular expression that is used to match against any embedded URLs found. So if you only want to download embedded resources from http://server.com/, use the expression: http://server\.com/.* No

N.B. when using automatic redirection, cookies are only sent for the initial URL. This can cause unexpected behaviour for web-sites that redirect to a local server. E.g. if www.example.com redirects to www.example.co.uk. In this case the server will probably return cookies for both URLs, but JMeter will only see the cookies for the last host, i.e. www.example.co.uk. If the next request uses www.example.com, rather than www.example.co.uk, it will not get the correct cookies. This is generally only a problem for manually created test plans, as a test plan created using a recorder would continue from the redirected URL.

Parameter Handling:

For the POST and PUT method, if there is no file to send, and the name(s) of the parameter(s) are omitted, then the body is created by concatenating all the value(s) of the parameters. This allows arbitrary bodies to be sent. The values are encoded if the encoding flag is set (versions of JMeter after 2.3). See also the MIME Type above how you can control the content-type request header that are sent.

For other methods, if the name of the parameter is missing, then the parameter is ignored. This allows the use of optional parameters defined by variables. (versions of JMeter after 2.3)

Method Handling:

The POST and PUT request methods work similar, except that the PUT method does not support multipart requests. The GET and DELETE request methods work similar.

Upto and including JMeter 2.1.1, only responses with the content-type "text/html" were scanned for embedded resources. Other content-types were assumed to be something other than HTML. JMeter 2.1.2 introduces the a new property HTTPResponse.parsers , which is a list of parser ids, e.g. htmlParser and wmlParser . For each id found, JMeter checks two further properties:

  • id.types - a list of content types
  • id.className - the parser to be used to extract the embedded resources

See jmeter.properties file for the details of the settings. If the HTTPResponse.parser property is not set, JMeter reverts to the previous behaviour, i.e. only text/html responses will be scanned

See Also:



18.1.3 JDBC Request

This sampler lets you send an JDBC Request (an SQL query) to a database.

Before using this you need to set up a JDBC Connection Configuration Configuration element

Control Panel

Parameters

AttributeDescriptionRequired
Name Descriptive name for this controller that is shown in the tree. No
Variable Name Name of the JMeter variable that the connection pool is bound to. This must agree with the 'Variable Name' field of a JDBC Connection Configuration. Yes
Query Type Set this according to the statement type:
  • Select Statement
  • Update Statement - use this for Inserts as well
  • Callable Statement
  • Prepared Select Statement
  • Prepared Update Statement - use this for Inserts as well
  • Commit
  • Rollback
  • Autocommit(false)
  • Autocommit(true)
  • Edit - this should be a variable reference that evaluates to one of the above
Yes
SQL Query SQL query. Do not enter a trailing semi-colon. There is generally no need to use { and } to enclose Callable statements; however they mey be used if the database uses a non-standard syntax. [The JDBC driver automatically converts the statement if necessary when it is enclosed in {}]. For example:
  • select * from t_customers where id=23
  • CALL SYSCS_UTIL.SYSCS_EXPORT_TABLE (null,?, ?, null, null, null)
    • Parameter values: tablename,filename
    • Parameter types: VARCHAR,VARCHAR
  • The second example assumes you are using Apache Derby.
Yes
Parameter values Comma-separated list of parameter values. Use ]NULL[ to indicate a NULL parameter. (If required, the null string can be changed by defining the property "jdbcsampler.nullmarker".)

There must be as many values as there are placeholders in the statement.
Yes, if a prepared or callable statement has parameters
Parameter types Comma-separated list of SQL parameter types (e.g. INTEGER, DATE, VARCHAR, DOUBLE). If the callable statement has INOUT or OUT parameters, then these must be indicated by prefixing the appropriate parameter types, e.g. instead of "INTEGER", use "INOUT INTEGER". If not specified, "IN" is assumed, i.e. "DATE" is the same as "IN DATE".

There must be as many values as there are placeholders in the statement.
Yes, if a prepared or callable statement has parameters

See Also:



18.1.4 Java Request

This sampler lets you control a java class that implements the JavaSamplerClient interface. By writing your own implementation of this interface, you can use JMeter to harness multiple threads, input parameter control, and data collection.

The pull-down menu provides the list of all such implementations found by JMeter in its classpath. The parameters can then be specified in the table below - as defined by your implementation. Two simple examples (JavaTest and SleepTest) are provided.

The JavaTest example sampler can be useful for checking test plans, because it allows one to set values in almost all the fields. These can then be used by Assertions, etc. The fields allow variables to be used, so the values of these can readily be seen.

Control Panel

The Add/Delete buttons don't serve any purpose at present.

Parameters

AttributeDescriptionRequired
Name Descriptive name for this sampler that is shown in the tree. No
Classname The specific implementation of the JavaSamplerClient interface to be sampled. Yes
Send Parameters with Request A list of arguments that will be passed to the sampled class. All arguments are sent as Strings. No



The sleep time is calculated as follows:

								
SleepTime is in milliseconds
SleepMask is used to add a "random" element to the time:
totalSleepTime = SleepTime + (System.currentTimeMillis() % SleepMask)

						

18.1.5 SOAP/XML-RPC Request

This sampler lets you send a SOAP request to a webservice. It can also be used to send XML-RPC over HTTP. It creates an HTTP POST request, with the specified XML as the POST content. To change the "Content-type" from the default of "text/html", use a HeaderManager. Note that the sampler will use all the headers from the HeaderManager. If a SOAP action is specified, that will override any SOAPaction in the HeaderManager. The primary difference between the soap sampler and webservice sampler, is the soap sampler uses raw post and does not require conformance to XML.

For versions of JMeter later than 2.2, the sampler no longer uses chunked encoding by default.

For screen input, it now always uses the size of the data.

File input uses the file length as determined by Java.

On some OSes this may not work for all files, in which case add a child Header Manager with Content-Length set to the actual length of the file.

Or set Content-Length to -1 to force chunked encoding.

Control Panel

Parameters

AttributeDescriptionRequired
Name Descriptive name for this sampler that is shown in the tree. No
URL The URL to direct the SOAP request to. Yes
Send SOAP action Send a SOAP action header? (overrides the Header Manager) No
Soap/XML-RPC Data The Soap XML message, or XML-RPC instructions. Not used if the filename is provided. No
Filename If specified, then the contents of the file are sent, and the Data field is ignored No



18.1.6 WebService(SOAP) Request

This sampler has been tested with IIS Webservice running .NET 1.0 and .NET 1.1. It has been tested with SUN JWSDP, IBM webservices, Axis and gSoap toolkit for C/C++. The sampler uses Apache SOAP driver to serialize the message and set the header with the correct SOAPAction. Right now the sampler doesn't support automatic WSDL handling, since Apache SOAP currently does not provide support for it. Both IBM and SUN provide WSDL drivers. There are 3 options for the post data: text area, external file, or directory. If you want the sampler to randomly select a message, use the directory. Otherwise, use the text area or a file. The if either the file or path are set, it will not use the message in the text area. If you need to test a soap service that uses different encoding, use the file or path. If you paste the message in to text area, it will not retain the encoding and will result in errors. Save your message to a file with the proper encoding, and the sampler will read it as java.io.FileInputStream.

The sampler requires mail.jar and activation.jar. This is because Apache SOAP requires the libs. Because mail.jar and activation.jar are distributed by Sun, you have to download it separately.

An important note on the sampler is it will automatically use the proxy host and port passed to JMeter from command line, if thoe fields in the sampler are left blank. If a sampler has values in the proxy host and port text field, it will use the ones provided by the user. This behavior may not be what users expect.

By default, the webservice sampler set SOAPHTTPConnection.setMaintainSession (true). If you need to maintain the session, add a blank Header Manager. The sampler uses the Header Manager to store the SOAPHTTPConnection object, since there apache soap does provide a easy way to get and set the cookies.

Note: If you are using CSVDataSet, do not check "Memory Cache". If memory cache is checked, it will not iterate to the next value. That means all the requests will use the first value.

Make sure you use <soap:Envelope rather than <Envelope. For example:

								
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<foo xmlns="http://clients-xlmns"/>
</soap:Body>
</soap:Envelope>

						

Control Panel

Parameters

AttributeDescriptionRequired
Name Descriptive name for this sampler that is shown in the tree. No
WSDL URL The WSDL URL with the service description. No
Webmethods The WSDL URL with the service description. No
Protocol HTTP or HTTPS are acceptable protocol. Yes
Server Name or IP The hostname or IP address. Yes
Port Number Port Number. Yes
Path Path for the webservice. Yes
SOAPAction The SOAPAction defined in the webservice description or WSDL. Yes
Soap/XML-RPC Data The Soap XML message Yes
Soap file File containing soap message No
Message Folder Folder containing soap files No
Memory cache When using external files, setting this causes the file to be processed once and caches the result. This may use a lot of memory if there are many different large files. Yes
Use HTTP Proxy Check box if http proxy should be used No
Proxy Host Proxy hostname No
Proxy Port Proxy host port No



18.1.7 LDAP Request

This Sampler lets you send a different Ldap request(Add, Modify, Delete and Search) to an LDAP server.

If you are going to send multiple requests to the same LDAP server, consider using an LDAP Request Defaults Configuration Element so you do not have to enter the same information for each LDAP Request.

The same way the Login Config Element also using for Login and password.

Control Panel

There are two ways to create test cases for testing an LDAP Server.

  1. Inbuilt Test cases.
  2. User defined Test cases.

There are four test scenarios of testing LDAP. The tests are given below:

  1. Add Test
    1. Inbuilt test :

      This will add a pre-defined entry in the LDAP Server and calculate the execution time. After execution of the test, the created entry will be deleted from the LDAP Server.

    2. User defined test :

      This will add the entry in the LDAP Server. User has to enter all the attributes in the table.The entries are collected from the table to add. The execution time is calculated. The created entry will not be deleted after the test.

  2. Modify Test
    1. Inbuilt test :

      This will create a pre-defined entry first, then will modify the created entry in the LDAP Server.And calculate the execution time. After execution of the test, the created entry will be deleted from the LDAP Server.

    2. User defined test

      This will modify the entry in the LDAP Server. User has to enter all the attributes in the table. The entries are collected from the table to modify. The execution time is calculated. The entry will not be deleted from the LDAP Server.

  3. Search Test
    1. Inbuilt test :

      This will create the entry first, then will search if the attributes are available. It calculates the execution time of the search query. At the end of the execution,created entry will be deleted from the LDAP Server.

    2. User defined test

      This will search the user defined entry(Search filter) in the Search base (again, defined by the user). The entries should be available in the LDAP Server. The execution time is calculated.

  4. Delete Test
    1. Inbuilt test :

      This will create a pre-defined entry first, then it will be deleted from the LDAP Server. The execution time is calculated.

    2. User defined test

      This will delete the user-defined entry in the LDAP Server. The entries should be available in the LDAP Server. The execution time is calculated.

Parameters

AttributeDescriptionRequired
Name Descriptive name for this controller that is shown in the tree. No
Server Name or IP Domain name or IP address of the LDAP server. JMeter assumes the LDAP server is listening on the default port(389). Yes
Port default port(389). Yes
root DN DN for the server to communicate Yes
Username LDAP server username. Usually
Password LDAP server password. Usually
Entry DN the name of the context to create or Modify; may not be empty Example: do you want to add cn=apache,ou=test you have to add in table name=cn, value=apache yes
Delete the name of the context to Delete; may not be empty yes
Search base the name of the context or object to search yes
Search filter the filter expression to use for the search; may not be null yes
add test this name, value pair to added in the given context object yes
modify test this name, value pair to add or modify in the given context object yes

See Also:



18.1.8 LDAP Extended Request

This Sampler can send all 8 different LDAP request to an LDAP server. It is an extended version of the LDAP sampler, therefore it is harder to configure, but can be made much closer resembling a real LDAP session.

If you are going to send multiple requests to the same LDAP server, consider using an LDAP Extended Request Defaults Configuration Element so you do not have to enter the same information for each LDAP Request.

Control Panel

There are nine test operations defined. These operations are given below:

  1. Thread bind
  2. Any LDAP request is part of an LDAP session, so the first thing that should be done is starting a session to the LDAP server. For starting this session a thread bind is used, which is equal to the LDAP "bind" operation. The user is requested to give a username (Distinguished name) and password, which will be used to initiate a session. When no password, or the wrong password is specified, an anonymous session is started. Take care, omitting the password will not fail this test, a wrong password will.

    Parameters

    AttributeDescriptionRequired
    Name Descriptive name for this sampler that is shown in the tree. No
    Servername The name (or IP-address) of the LDAP server. Yes
    Port The port number that the LDAP server is listening to. If this is omitted JMeter assumes the LDAP server is listening on the default port(389). No
    DN The distinguished name of the base object that will be used for any subsequent operation. It can be used as a starting point for all operations. You cannot start any operation on a higher level than this DN! No
    Username Full distinguished name of the user as which you want to bind. No
    Password Password for the above user. If omitted it will result in an anonymous bind. If is is incorrect, the sampler will return an error and revert to an anonymous bind. No



  3. Thread unbind
  4. This is simply the operation to end a session. It is equal to the LDAP "unbind" operation.

    Parameters

    AttributeDescriptionRequired
    Name Descriptive name for this sampler that is shown in the tree. No



  5. Single bind/unbind
  6. This is a combination of the LDAP "bind" and "unbind" operations. It can be used for an authentication request/password check for any user. It will open an new session, just to check the validity of the user/password combination, and end the session again.

    Parameters

    AttributeDescriptionRequired
    Name Descriptive name for this sampler that is shown in the tree. No
    Username Full distinguished name of the user as which you want to bind. Yes
    Password Password for the above user. If omitted it will result in an anonymous bind. If is is incorrect, the sampler will return an error. No



  7. Rename entry
  8. This is the LDAP "moddn" operation. It can be used to rename an entry, but also for moving an entry or a complete subtree to a different place in the LDAP tree.

    Parameters

    AttributeDescriptionRequired
    Name Descriptive name for this sampler that is shown in the tree. No
    Old entry name The current distinguished name of the object you want to rename or move, relative to the given DN in the thread bind operation. Yes
    New distinguished name The new distinguished name of the object you want to rename or move, relative to the given DN in the thread bind operation. Yes



  9. Add test
  10. This is the ldap "add" operation. It can be used to add any kind of object to the LDAP server.

    Parameters

    AttributeDescriptionRequired
    Name Descriptive name for this sampler that is shown in the tree. No
    Entry DN Distinguished name of the object you want to add, relative to the given DN in the thread bind operation. Yes
    Add test A list of attributes and their values you want to use for the object. If you need to add a multiple value attribute, you need to add the same attribute with their respective values several times to the list. Yes



  11. Delete test
  12. This is the LDAP "delete" operation, it can be used to delete an object from the LDAP tree

    Parameters

    AttributeDescriptionRequired
    Name Descriptive name for this sampler that is shown in the tree. No
    Delete Distinguished name of the object you want to delete, relative to the given DN in the thread bind operation. Yes



  13. Search test
  14. This is the LDAP "search" operation, and will be used for defining searches.

    Parameters

    AttributeDescriptionRequired
    Name Descriptive name for this sampler that is shown in the tree. No
    Search base Distinguished name of the subtree you want your search to look in, relative to the given DN in the thread bind operation. No
    Search Filter searchfilter, must be specified in LDAP syntax. Yes
    Scope Use 0 for baseobject-, 1 for onelevel- and 2 for a subtree search. (Default=0) No
    Size Limit Specify the maximum number of results you want back from the server. (default=0, which means no limit.) When the sampler hits the maximum number of results, it will fail with errorcode 4 No
    Time Limit Specify the maximum amount of (cpu)time (in miliseconds) that the server can spend on your search. Take care, this does not say anything about the responsetime. (default is 0, which means no limit) No
    Attributes Specify the attributes you want to have returned, seperated by a semicolon. An empty field will return all attributes No
    Return object Whether the object will be returned (true) or not (false). Default=false No
    Dereference aliases If true, it will dereference aliases, if false, it will not follow them (default=false) No



  15. Modification test
  16. This is the LDAP "modify" operation. It can be used to modify an object. It can be used to add, delete or replace values of an attribute.

    Parameters

    AttributeDescriptionRequired
    Name Descriptive name for this sampler that is shown in the tree. No
    Entry name Distinguished name of the object you want to modify, relative to the given DN in the thread bind operation Yes
    Modification test The attribute-value-opCode triples. The opCode can be any valid LDAP operationCode (add, delete/remove or replace). If you don't specify a value with a delete operation, all values of the given attribute will be deleted. If you do specify a value in a delete operation, only the given value will be deleted. If this value is non-existent, the sampler will fail the test. Yes



  17. Compare
  18. This is the LDAP "compare" operation. It can be used to compare the value of a given attribute with some already known value. In reality this is mostly used to check whether a given person is a member of some group. In such a case you can compare the DN of the user as a given value, with the values in the attribute "member" of an object of the type groupOfNames. If the compare operation fails, this test fails with errorcode 49.

    Parameters

    AttributeDescriptionRequired
    Name Descriptive name for this sampler that is shown in the tree. No
    Entry DN The current distinguished name of the object of which you want to compare an attribute, relative to the given DN in the thread bind operation. Yes
    Compare filter In the form "attribute=value" Yes

See Also:



18.1.9 Access Log Sampler

(Alpha Code)

AccessLogSampler was designed to read access logs and generate http requests. For those not familiar with the access log, it is the log the webserver maintains of every request it accepted. This means the every image and html file. The current implementation is complete, but some features have not been enabled. There is a filter for the access log parser, but I haven't figured out how to link to the pre-processor. Once I do, changes to the sampler will be made to enable that functionality.

Tomcat uses the common format for access logs. This means any webserver that uses the common log format can use the AccessLogSampler. Server that use common log format include: Tomcat, Resin, Weblogic, and SunOne. Common log format looks like this:

127.0.0.1 - - [21/Oct/2003:05:37:21 -0500] "GET /index.jsp?%2Findex.jsp= HTTP/1.1" 200 8343

The current implemenation of the parser only looks at the text within the quotes. Everything else is stripped out and igored. For example, the response code is completely ignored by the parser. For the future, it might be nice to filter out entries that do not have a response code of 200. Extending the sampler should be fairly simple. There are two interfaces you have to implement.

org.apache.jmeter.protocol.http.util.accesslog.LogParser

org.apache.jmeter.protocol.http.util.accesslog.Generator

The current implementation of AccessLogSampler uses the generator to create a new HTTPSampler. The servername, port and get images are set by AccessLogSampler. Next, the parser is called with integer 1, telling it to parse one entry. After that, HTTPSampler.sample() is called to make the request.

								
            samp = (HTTPSampler) GENERATOR.generateRequest();
            samp.setDomain(this.getDomain());
            samp.setPort(this.getPort());
            samp.setImageParser(this.isImageParser());
            PARSER.parse(1);
            res = samp.sample();
            res.setSampleLabel(samp.toString());

						
The required methods in LogParser are: setGenerator(Generator) and parse(int). Classes implementing Generator interface should provide concrete implementation for all the methods. For an example of how to implement either interface, refer to StandardGenerator and TCLogParser.

Control Panel

Parameters

AttributeDescriptionRequired
Name Descriptive name for this controller that is shown in the tree. No
Server Domain name or IP address of the web server. Yes
Port Port the web server is listening to. No (defaults to 80)
Log parser class The log parser class is responsible for parsing the logs. No (default provided)
Generator class The generator class is responsible for creating HTTPSampler objects. No (default provided)
Location of log file The location of the access log file. Yes



18.1.10 BeanShell Sampler

This sampler allows you to write a sampler using the BeanShell scripting language.

Please note that the BeanShell jar file is not included with JMeter; it needs to be separately downloaded.

For full details on using BeanShell, please see the BeanShell web-site at http://www.beanshell.org/.

The test element supports the ThreadListener and TestListener methods. These should be defined in the initialisation file. See the file BeanShellListeners.bshrc for example definitions.

Control Panel

Parameters

AttributeDescriptionRequired
Name Descriptive name for this controller that is shown in the tree. No
Parameters Parameters to pass to the BeanShell script. The parameters are stored in the following variables:
  • Parameters - string containing the parameters as a single variable
  • bsh.args - String array containing parameters, split on white-space
No
Script file A file containing the BeanShell script to run. No
Script The BeanShell script to run. The return value (if not null) is stored as the sampler result. Yes (unless script file is provided)

N.B. Each Sampler instance has its own BeanShell interpeter, and Samplers are only called from a single thread

If the property "beanshell.sampler.init" is defined, it is passed to the Interpreter as the name of a sourced file. This can be used to define common methods and variables. There is a sample init file in the bin directory: BeanShellSampler.bshrc.

If a script file is supplied, that will be used, otherwise the script will be used.

Before invoking the script, some variables are set up in the BeanShell interpreter:

The contents of the Parameters field is put into the variable "Parameters". The string is also split into separate tokens using a single space as the separator, and the resulting list is stored in the String array bsh.args.

The full list of variables that is set up is as follows:

  • log - the Logger
  • Label - the Sampler label
  • FileName - the file name, if any
  • Parameters - text from the Parameters field
  • bsh.args - the parameters, split as described above
  • SampleResult - pointer to the current SampleResult
  • ResponseCode = 200
  • ResponseMessage = "OK"
  • IsSuccess = true
  • ctx - JMeterContext
  • vars - JMeterVariables - e.g. vars.get("VAR1"); vars.put("VAR2","value"); vars.remove("VAR3"); vars.putObject("OBJ1",new Object());

When the script completes, control is returned to the Sampler, and it copies the contents of the following script variables into the corresponding variables in the SampleResult:

  • ResponseCode - for example 200
  • ResponseMessage - for example "OK"
  • IsSuccess - true/false

The Sampler ResponseData is set from the return value of the script. Since version 2.1.2, if the script returns null, it can set the response directly, by using the method SampleResponse.setResponseData(data), where data is either a String or a byte array. The data type defaults to "text", but can be set to binary by using the method SampleResponse.setDataType(SampleResponse.BINARY).

The SampleResult variable gives the script full access to all the fields and methods in the SampleResult. For example, the script has access to the methods setStopThread(boolean) and setStopTest(boolean). Here is a simple (not very useful!) example script:

								
if (bsh.args[0].equalsIgnoreCase("StopThread")) {
    log.info("Stop Thread detected!");
    SampleResult.setStopThread(true);
}
return "Data from sample with Label "+Label;
//or, since version 2.1.2
SampleResult.setResponseData("My data");
return null;

						

Another example:

ensure that the property beanshell.sampler.init=BeanShellSampler.bshrc is defined in jmeter.properties. The following script will show the values of all the variables in the ResponseData field:

								
return getVariables();

						

For details on the methods available for the various classes (JMeterVariables, SampleResult etc) please check the Javadoc or the source code. Beware however that misuse of any methods can cause subtle faults that may be difficult to find ...



18.1.11 BSF Sampler

This sampler allows you to write a sampler using a BSF scripting language.

See the Apache Bean Scripting Framework website for details of the languages supported. You may need to download the appropriate jars for the language; they should be put in the JMeter lib directory.

Control Panel

Parameters

AttributeDescriptionRequired
Name Descriptive name for this controller that is shown in the tree. No
Scripting Language Name of the BSF scripting language to be used. N.B. Not all the languages in the drop-down list are supported by default. The following are supported: beanshell, jacl, javascript, xslt. Others may be available if the appropriate jar is installed in the JMeter lib directory. Yes
Script File Name of a file to be used as a BSF script No
Parameters List of parameters to be passed to the script file or the script. No
Script Script to be passed to BSF language Yes (unless script file is provided)

If a script file is supplied, that will be used, otherwise the script will be used.

Before invoking the script, some variables are set up:

  • log - the Logger
  • Label - the Sampler label
  • FileName - the file name, if any
  • Parameters - text from the Parameters field
  • args - the parameters, split as described above
  • SampleResult - pointer to the current SampleResult
  • ctx - JMeterContext
  • vars - JMeterVariables - e.g. vars.get("VAR1"); vars.put("VAR2","value"); vars.remove("VAR3"); vars.putObject("OBJ1",new Object());

The Sampler ResponseData is set from the return value of the script. If the script returns null, it can set the response directly, by using the method SampleResponse.setResponseData(data), where data is either a String or a byte array. The data type defaults to "text", but can be set to binary by using the method SampleResponse.setDataType(SampleResponse.BINARY).

The SampleResult variable gives the script full access to all the fields and methods in the SampleResult. For example, the script has access to the methods setStopThread(boolean) and setStopTest(boolean).

Unlike the Beanshell Sampler, the BSF Sampler does not set the ResponseCode, ResponseMessage and sample status via script variables. Currently the only way to changes these is via the SampleResponse methods:

  • SampleResponse.setSuccessful(true/false)
  • SampleResponse.setResponseCode("code")
  • SampleResponse.setResponseMessage("message")



18.1.12 TCP Sampler

ALPHA CODE

The TCP Sampler opens a TCP/IP connection to the specified server. It then sends the text, and waits for a response.

Connections are shared between Samplers in the same thread, provided that the exact same host name string and port are used. To force a different socket to be used, change the hostname by changing the case of one of the letters, e.g. www.apache.org and wWw.apache.org will use different sockets.

If an error is detected, the socket is closed. Another socket will be reopened on the next sample.

The following properties can be used to control its operation:

  • tcp.status.prefix - text that precedes a status number
  • tcp.status.suffix - text that follows a status number
  • tcp.status.properties - name of property file to convert status codes to messages
  • tcp.handler - Name of TCP Handler class (default TCPClientImpl)
  • tcp.eolByte - decimal value. Defines the end of line byte value; used to determine when a response has been received
The class that handles the connection is defined by the property tcp.handler. If not found, the class is then searched for in the package org.apache.jmeter.protocol.tcp.sampler.

Users can provide their own implementation to replace the supplied class TCPClientImpl. The class must extend org.apache.jmeter.protocol.tcp.sampler.TCPClient.

If tcp.status.prefix is defined, then the response message is searched for the text following that up to the suffix. If any such text is found, it is used to set the response code. The response message is then fetched from the properties file (if provided).

For example, if the prefix = "[" and the suffix = "]", then the following repsonse:

[J28] XI123,23,GBP,CR

would have the response code J28.

Response codes in the range "400"-"499" and "500"-"599" are currently regarded as failures; all others are successful. [This needs to be made configurable!]

The login name/password are not used by the supplied TCP implementation.



Sockets are disconnected at the end of a test run.

Control Panel

Parameters

AttributeDescriptionRequired
Name Descriptive name for this element that is shown in the tree. No
Name Descriptive name for this element that is shown in the tree. No
ServerName or IP Name or IP of TCP server Yes
Port Number Port to be used Yes
Timeout (milliseconds) Timeout for replies No
Set Nodelay Should the nodelay property be set? No
Text to Send Text to be sent Yes
Login User User Name No
Password Password No



18.1.13 JMS Publisher

ALPHA CODE

JMS Publisher will publish messages to a given pub/sub topic. For those not familiar with JMS, it is the J2EE specification for messaging. There are numerous JMS servers on the market and several open source options.



JMeter does not include the JMS jar; this must be downloaded and put in the lib directory

Control Panel

Parameters

AttributeDescriptionRequired
Name Descriptive name for this element that is shown in the tree. No
use JNDI properties file use jndi.properties to create topic Yes
JNDI Initial Context Factory Name of the context factory No
Provider URL The URL for the jms provider No
Topic the message topic Yes
Authentication Authentication requirement for the JMS provider Yes
User User Name No
Password Password No
Number of samples to aggregate number of samples to aggregate Yes
configuration setting for the message Yes
Message type text or object message Yes



18.1.14 JMS Subscriber

ALPHA CODE

JMS Publisher will subscribe to messages in a given pub/sub topic. For those not familiar with JMS, it is the J2EE specification for messaging. There are numerous JMS servers on the market and several open source options.



JMeter does not include the JMS jar; this must be downloaded and put in the lib directory

Control Panel

Parameters

AttributeDescriptionRequired
Name Descriptive name for this element that is shown in the tree. No
use JNDI properties file use jndi.properties to create topic Yes
JNDI Initial Context Factory Name of the context factory No
Provider URL The URL for the jms provider No
Topic the message topic Yes
Authentication Authentication requirement for the JMS provider Yes
User User Name No
Password Password No
Number of samples to aggregate number of samples to aggregate Yes
Read response should the sampler read the response Yes
Client Which client to use Yes



18.1.15 JMS Point-to-Point

ALPHA CODE

This sampler sends and optionally receives JMS Messages through point-to-point connections (queues). It is different from pub/sub messages and is generally used for handling transactions.



JMeter does not include the JMS jar; this must be downloaded and put in the lib directory

Control Panel

Parameters

AttributeDescriptionRequired
Name Descriptive name for this element that is shown in the tree. No
QueueConnection Factory The JNDI name of the queue connection factory to use for connecting to the messaging system. Yes
JNDI Name Request queue This is the JNDI name of the queue to which the messages are sent. Yes
JNDI Name Reply queue The JNDI name of the receiving queue. If a value is provided here and the communication style is Request Response this queue will be monitored for responses to the requests sent. No
Communication style The Communication style can be Request Only (also known as Fire and Forget) or Request Reply. Request Only will only sent messages and will not monitor replies. As such it can be used to put load on a system. Request Reply will sent messages and monitor the replies it receives. Behaviour is depended on the value of the JNDI Name Reply Queue. If JNDI Name Reply Queue has a value, this queue is used to monitor the results. Matching of request and reply is done with the message id of the request with the correlation id of the reply. If the JNDI Name Reply Queue is empty, then temporary queues will be used for the communication between the requestor and the server. This is very different from the fixed reply queue. With temporary queues the diffent threads will block until the reply message has been received. Yes
Timeout The timeout in milliseconds for the reply-messages. If a reply has not been received within the specified time, the specific testcase failes and the specific reply message received after the timeout is discarded. Yes
Use non-persistent delivery mode? Whether to set DeliveryMode.NON_PERSISTENT. Yes
Content The content of the message. No
JMS Properties The JMS Properties are properties specific for the underlying messaging system. For example: for WebSphere 5.1 web services you will need to set the JMS Property targetService to test webservices through JMS. No
Initial Context Factory The Initial Context Factory is the factory to be used to look up the JMS Resources. No
JNDI properties The JNDI Properties are the specific properties for the underlying JNDI implementation. No
Provider URL The URL for the jms provider. No



18.1.16 JUnit Request

The current implementation supports standard Junit convention and extensions. It also includes extensions like oneTimeSetUp and oneTimeTearDown. The sampler works like the JavaSampler with some differences.

1. rather than use Jmeter's test interface, it scans the jar files for classes extending junit's TestCase class. That includes any class or subclass.

2. Junit test jar files should be placed in jmeter/lib/junit instead of /lib directory.

3. Junit sampler does not use name/value pairs for configuration like the JavaSampler. The sampler assumes setUp and tearDown will configure the test correctly.

4. The sampler measures the elapsed time only for the test method and does not include setUp and tearDown.

5. Each time the test method is called, Jmeter will pass the result to the listeners.

6. Support for oneTimeSetUp and oneTimeTearDown is done as a method. Since Jmeter is multi-threaded, we cannot call oneTimeSetUp/oneTimeTearDown the same way Maven does it.

7. The sampler reports unexpected exceptions as errors. There are some important differences between standard JUnit test runners and JMeter's implementation. Rather than make a new instance of the class for each test, JMeter creates 1 instance per sampler and reuses it.

The current implementation of the sampler will try to create an instance using the string constructor first. If the test class does not declare a string constructor, the sampler will look for an empty constructor. Example below:

Empty Constructor:
public class myTestCase {
public myTestCase() {}
}

String Constructor:
public class myTestCase {
public myTestCase(String text) {
super(text);
}
}
By default, Jmeter will provide some default values for the success/failure code and message. Users should define a set of unique success and failure codes and use them uniformly across all tests.
General Guidelines

If you use setUp and tearDown, make sure the methods are declared public. If you do not, the test may not run properly.

Here are some general guidelines for writing Junit tests so they work well with Jmeter. Since Jmeter runs multi-threaded, it is important to keep certain things in mind.

1. Write the setUp and tearDown methods so they are thread safe. This generally means avoid using static memebers.
2. Make the test methods discrete units of work and not long sequences of actions. By keeping the test method to a descrete operation, it makes it easier to combine test methods to create new test plans.
3. Avoid making test methods depend on each other. Since Jmeter allows arbitrary sequencing of test methods, the runtime behavior is different than the default Junit behavior.
4. If a test method is configurable, be careful about where the properties are stored. Reading the properties from the Jar file is recommended.
5. Each sampler creates an instance of the test class, so write your test so the setup happens in oneTimeSetUp and oneTimeTearDown.

Control Panel

Parameters

AttributeDescriptionRequired
Name Descriptive name for this element that is shown in the tree. No
Package filter Comma separated list of packages to show. Example, org.apache.jmeter,junit.framework. No
Class name Fully qualified name of the JUnit test class. No
Constructor string String pass to the string constructor. If a string is set, the sampler will use the string constructor instead of the empty constructor. No
Test method The method to test. No
Success message A descriptive message indicating what success means. No
Success code An unique code indicating the test was successful. No
Failure message A descriptive message indicating what failure means. No
Failure code An unique code indicating the test failed. No
Error message A description for errors. No
Error code Some code for errors. Does not need to be unique. No
Do not call setUp and tearDown Set the sampler not to call setUp and tearDown. By default, setUp and tearDown should be called. Not calling those methods could affect the test and make it inaccurate. This option should only be used with calling oneTimeSetUp and oneTimeTearDown. If the selected method is oneTimeSetUp or oneTimeTearDown, this option should be checked. No



18.1.17 Mail Reader Sampler

TBA

Control Panel



18.1.18 Test Action

The Test Action sampler is a sampler that is intended for use in a conditional controller. Rather than generate a sample, the test element eithers pauses - or stops the selected target.

This sampler can also be useful in conjunction with the Transaction Controller, as it allows pauses to be included without needing to generate a sample. For variable delays, set the pause time to zero, and add a Timer as a child.

Control Panel

Parameters

AttributeDescriptionRequired
Name Descriptive name for this element that is shown in the tree. No
Target Current Thread / All Threads (ignored for Pause) Yes
Action Pause / Stop Yes
Duration How long to pause for (milliseconds) Yes



^


18.2 Logic Controllers

Logic Controllers determine the order in which Samplers are processed.

18.2.1 Simple Controller

The Simple Logic Controller lets you organize your Samplers and other Logic Controllers. Unlike other Logic Controllers, this controller provides no functionality beyond that of a storage device.

Control Panel

Parameters

AttributeDescriptionRequired
Name Descriptive name for this controller that is shown in the tree. No

Using the Simple Controller

Download this example (see Figure 6). In this example, we created a Test Plan that sends two Ant HTTP requests and two Log4J HTTP requests. We grouped the Ant and Log4J requests by placing them inside Simple Logic Controllers. Remember, the Simple Logic Controller has no effect on how JMeter processes the controller(s) you add to it. So, in this example, JMeter sends the requests in the following order: Ant Home Page, Ant News Page, Log4J Home Page, Log4J History Page. Note, the File Reporter is configured to store the results in a file named "simple-test.dat" in the current directory.


Figure 6 Simple Controller Example



18.2.2 Loop Controller

If you add Generative or Logic Controllers to a Loop Controller, JMeter will loop through them a certain number of times, in addition to the loop value you specified for the Thread Group. For example, if you add one HTTP Request to a Loop Controller with a loop count of two, and configure the Thread Group loop count to three, JMeter will send a total of 2 * 3 = 6 HTTP Requests.

Control Panel

Parameters

AttributeDescriptionRequired
Name Descriptive name for this controller that is shown in the tree. No
Loop Count The number of times the subelements of this controller will be iterated each time through a test run.

Special Case: The Loop Controller embedded in the Thread Group element behaves slightly differently. Unless set to forever, it stops the test after the given number of iterations have been done.

Yes, unless "Forever" is checked

Looping Example

Download this example (see Figure 4). In this example, we created a Test Plan that sends a particular HTTP Request only once and sends another HTTP Request five times.


Figure 4 - Loop Controller Example

We configured the Thread Group for a single thread and a loop count value of one. Instead of letting the Thread Group control the looping, we used a Loop Controller. You can see that we added one HTTP Request to the Thread Group and another HTTP Request to a Loop Controller. We configured the Loop Controller with a loop count value of five.

JMeter will send the requests in the following order: Home Page, News Page, News Page, News Page, News Page, and News Page. Note, the File Reporter is configured to store the results in a file named "loop-test.dat" in the current directory.



18.2.3 Once Only Controller

The Once Only Logic Controller tells JMeter to process the controller(s) inside it only once, and pass over any requests under it during further iterations through the test plan.

The Once Only Controller will now execute always during the first iteration of any looping parent controller. Thus, if the Once Only Controller is placed under a Loop Controller specified to loop 5 times, then the Once Only Controller will execute only on the first iteration through the Loop Controller (ie, every 5 times). Note this means the Once Only Controller will still behave as previously expected if put under a Thread Group (runs only once per test), but now the user has more flexibility in the use of the Once Only Controller.

For testing that requires a login, consider placing the login request in this controller since each thread only needs to login once to establish a session.

Control Panel

Parameters

AttributeDescriptionRequired
Name Descriptive name for this controller that is shown in the tree. No

Once Only Example

Download this example (see Figure 5). In this example, we created a Test Plan that has two threads that send HTTP request. Each thread sends one request to the Home Page, followed by three requests to the Bug Page. Although we configured the Thread Group to iterate three times, each JMeter thread only sends one request to the Home Page because this request lives inside a Once Only Controller.


Figure 5. Once Only Controller Example

Each JMeter thread will send the requests in the following order: Home Page, Bug Page, Bug Page, Bug Page. Note, the File Reporter is configured to store the results in a file named "loop-test.dat" in the current directory.



18.2.4 Interleave Controller

If you add Generative or Logic Controllers to an Interleave Controller, JMeter will alternate among each of the other controllers for each loop iteration.

Control Panel

Parameters

AttributeDescriptionRequired
name Descriptive name for this controller that is shown in the tree. No
ignore sub-controller blocks If checked, the interleave controller will treat sub-controllers like single request elements and only allow one request per controller at a time. No

Simple Interleave Example

Download this example (see Figure 1). In this example, we configured the Thread Group to have two threads and a loop count of five, for a total of ten requests per thread. See the table below for the sequence JMeter sends the HTTP Requests.


Figure 1 - Interleave Controller Example 1

Loop Iteration Each JMeter Thread Sends These HTTP Requests
1 News Page
2 Log Page
2 FAQ Page
2 Log Page
3 Gump Page
2 Log Page
4 Because there are no more requests in the controller,

JMeter starts over and sends the first HTTP Request, which is the News Page.
2 Log Page
5 FAQ Page
2 Log Page

Useful Interleave Example

Download another example (see Figure 2). In this example, we configured the Thread Group to have a single thread and a loop count of eight. Notice that the Test Plan has an outer Interleave Controller with two Interleave Controllers inside of it.


Figure 2 - Interleave Controller Example 2

The outer Interleave Controller alternates between the two inner ones. Then, each inner Interleave Controller alternates between each of the HTTP Requests. Each JMeter thread will send the requests in the following order: Home Page, Interleaved, Bug Page, Interleaved, CVS Page, Interleaved, and FAQ Page, Interleaved. Note, the File Reporter is configured to store the results in a file named "interleave-test2.dat" in the current directory.


Figure 3 - Interleave Controller Example 3

If the two interleave controllers under the main interleave controller were instead simple controllers, then the order would be: Home Page, CVS Page, Interleaved, Bug Page, FAQ Page, Interleaved. However, if "ignore sub-controller blocks" was checked on the main interleave controller, then the order would be: Home Page, Interleaved, Bug Page, Interleaved, CVS Page, Interleaved, and FAQ Page, Interleaved.