jmeter sample 取樣器
Control Panel

Attribute | Description | Required |
---|---|---|
Name | Descriptive name for this sampler 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. | Yes (default provided) |
Filter | The filter class is used to filter out certain lines. | No |
Location of log file | The location of the access log file. | Yes |
The TCLogParser processes the access log independently for each thread. The SharedTCLogParser and OrderPreservingLogParser share access to the file, i.e. each thread gets the next entry in the log.
The SessionFilter is intended to handle Cookies across threads. It does not filter out any entries, but modifies the cookie manager so that the cookies for a given IP are processed by a single thread at a time. If two threads try to process samples from the same client IP address, then one will be forced to wait until the other has completed.
The LogFilter is intended to allow access log entries to be filtered by filename and regex, as well as allowing for the replacement of file extensions. However, it is not currently possible to configure this via the GUI, so it cannot really be used.。
pasting
18.1.10 BeanShell Sampler | |||||||||||||||||||
This sampler allows you to write a sampler using the BeanShell scripting language. For full details on using BeanShell, please see the BeanShell website. The test element supports the ThreadListener and TestListener interface methods. These must be defined in the initialisation file. See the file BeanShellListeners.bshrc for example definitions. From JMeter version 2.5.1, the BeanShell sampler also supports the Interruptible interface. The interrupt() method can be defined in the script or the init file. Control Panel ![]()
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 BeanShell variables that is set up is as follows:
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 :
The SampleResult 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 SampleResult.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 SampleResult.setDataType(SampleResult.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: 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.
By default, JMeter supports the following languages:
Control Panel ![]()
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. Note that these are BSF variables - i.e. they can be used directly in the script.
The SampleResult 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 SampleResult.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 SampleResult.setDataType(SampleResult.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 |
18.9.8 Debug Sampler | |||||||||||||||
The Debug Sampler generates a sample containing the values of all JMeter variables and/or properties. The values can be seen in the View Results Tree Listener Response Data pane. Control Panel ![]()
|
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. Latency is set to the time it takes to login (versions of JMeter after 2.3.1). Control Panel ![]()
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:
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(S) Test Script Recorder to create them. This can save you time if you have a lot of HTTP requests or requests with many parameters. There are two different screens for defining the samplers:
The Java HTTP implementation has some limitations:
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=trueBy default, the SSL context is retained for the duration of the test. In versions of JMeter from 2.5.1, the SSL session can be optionally reset for each test iteration. To enable this, set the JMeter property: https.use.cached.ssl.context=falseNote: this does not apply to the Java HTTP implementation.
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
JMeter also allows one to enable additional protocols, by changing the property https.socket.protocols . 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 ![]()
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 in the test plan uses www.example.com, rather than www.example.co.uk, it will not get the correct cookies. Likewise, Headers are sent for the initial request, and won't be sent for the redirect. 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: Since JMeter 2.6, you have the option to switch to Post Body when a request has only unnamed parameters (or no parameters at all). This option is useful in the following cases (amongst others):
In Post Body mode, each line will be sent with CRLF appended, apart from the last line. To send a CRLF after the last line of data, just ensure that there is an empty line following it. (This cannot be seen, except by noting whether the cursor can be placed on the subsequent line.)
Method Handling:
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 andwmlParser . For each id found, JMeter checks two further properties:
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 Emulating slow connections:# Define characters per second > 0 to emulate slow connections #httpclient.socket.http.cps=0 #httpclient.socket.https.cps=0 Response size calculation
Retry handling httpclient4.retrycount=3 httpclient3.retrycount=3
See Also:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
18.1.4 Java Request | ||||||||||||||||||||||||||||||||||||||||||||
This sampler lets you control a java class that implements the 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 following parameters apply to the SleepTest and JavaTest implementations:
The following parameters apply additionaly to the JavaTest implementation:
| ||||||||||||||||||||||||||||||||||||||||||||
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 If the Variable Names list is provided, then for each row returned by a Select statement, the variables are set up with the value of the corresponding column (if a variable name is provided), and the count of rows is also set up. For example, if the Select statement returns 2 rows of 3 columns, and the variable list is A_#=2 (number of rows) A_1=column 1, row 1 A_2=column 1, row 2 C_#=2 (number of rows) C_1=column 3, row 1 C_2=column 3, row 2If the Select statement returns zero rows, then the A_# and C_# variables would be set to 0, and no other variables would be set.
Old variables are cleared if necessary - e.g. if the first select retrieves 6 rows and a second select returns only 3 rows, the additional variables for rows 4, 5 and 6 will be removed. Note: The latency time is set from the time it took to acquire a connection. Control Panel ![]()
See Also:
|
18.1.15 JMS Point-to-Point | ||||||||||||||||||||||||||||||||||||||||||||||||
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. Request Only will typically used to put load on a JMS System. Versions of JMeter after 2.3.2 use the properties java.naming.security.[principal|credentials] - if present - when creating the Queue Connection. If this behaviour is not desired, set the JMeter property JMSSampler.useSecurity.properties=false
Control Panel ![]()
| ||||||||||||||||||||||||||||||||||||||||||||||||
18.1.13 JMS Publisher | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
JMS Publisher will publish messages to a given destination (topic/queue). 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.
Control Panel ![]()
For the MapMessage type, JMeter reads the source as lines of text. Each line must have 3 fields, delimited by commas. The fields are:
name,String,Example size,Integer,1234This is a very simple implementation; it is not intended to support all possible object types.
The following table shows some values which may be useful when configuring JMS:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
18.1.14 JMS Subscriber | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
JMS Publisher will subscribe to messages in a given destination (topic or queue). 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.
Control Panel ![]()
NOTE: JMeter 2.3.4 and earlier used a different strategy for the MessageConsumer.receive() client. Previously this started a background thread which polled for messages. This thread continued when the sampler completed, so the net effect was similar to the MessageListener.onMessage() strategy. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
18.1.11.1 JSR223 Sampler | |||||
The JSR223 Sampler allows JSR223 script code to be used to perform a sample. The JSR223 test elements have a feature (compilation) that can significantly increase performance. To benefit from this feature:
Control Panel ![]()
| |||||
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. In versions of JMeter after 2.3.1, you can also use the "user.classpath" property to specify where to look for TestCase classes. 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. This can be changed with checkbox "Create a new instance per sample". 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 ![]()
The following JUnit4 annotations are recognised:
Note that JMeter currently runs the test methods directly, rather than leaving it to JUnit. This is to allow the setUp/tearDown methods to be excluded from the sample time. | |||||||||||||||||||||||||||||||||||||||||||||||||||
18.4.11 LDAP Request Defaults |
The LDAP Request Defaults component lets you set default values for LDAP testing. See the LDAP Request . Control Panel ![]() |
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.
There are four test scenarios of testing LDAP. The tests are given below:
See Also:
| |||||||||||||||||||||||||||||||||||||||
18.1.17 Mail Reader Sampler | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
The Mail Reader Sampler can read (and optionally delete) mail messages using POP3(S) or IMAP(S) protocols. Control Panel ![]()
Messages are stored as subsamples of the main sampler. In versions of JMeter after 2.3.4, multipart message parts are stored as subsamples of the message. Special handling for "file" protocol: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
18.1.20 OS Process Sampler | |||||||||||||||||||||||||||||||||
The OS Process Sampler is a sampler that can be used to execute commands on the local machine. Note that OS shells generally provide command-line parsing. This varies between OSes, but generally the shell will split parameters on white-space. Some shells expand wild-card file names; some don't. The quoting mechanism also varies between OSes. The sampler deliberately does not do any parsing or quote handling. The command and its parameters must be provided in the form expected by the executable. This means that the sampler settings will not be portable between OSes. Many OSes have some built-in commands which are not provided as separate executables. For example the Windows DIR command is part of the command interpreter (CMD.EXE). These built-ins cannot be run as independent programs, but have to be provided as arguments to the appropriate command interpreter. For example, the Windows command-line: command: CMD Param 1: /C Param 2: DIR Param 3: C:\TEMP
Control Panel ![]()
| |||||||||||||||||||||||||||||||||
18.1.19 SMTP Sampler | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The SMTP Sampler can send mail messages using SMTP/SMTPS protocol. It is possible to set security propocols for the connection (SSL and TLS), as well as user authentication. If a security protocol is used a verification on the server certificate will occur.
Control Panel ![]()
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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/xml", 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 SOAP 1.1.
Control Panel ![]()
| ||||||||||||||||||||||
18.1.12 TCP Sampler | ||||||||||||||||||||||||||||||||||||||||||||||
The TCP Sampler opens a TCP/IP connection to the specified server. It then sends the text, and waits for a response.
Users can provide their own implementation. The class must extend org.apache.jmeter.protocol.tcp.sampler.TCPClient. The following implementations are currently provided.
TCPClientImpl BinaryTCPClientImpl LengthPrefixedBinaryTCPClientImpl Timeout handling If the timeout is set, the read will be terminated when this expires. So if you are using an eolByte/eomByte, make sure the timeout is sufficiently long, otherwise the read will be terminated early. Response handling
Sockets are disconnected at the end of a test run. Control Panel ![]()
| ||||||||||||||||||||||||||||||||||||||||||||||
8.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. The "Stop" action stops the thread or test after completing any samples that are in progress. The "Stop Now" action stops the test without waiting for samples to complete; it will interrupt any active samples. If some threads fail to stop within the 5 second time-limit, a message will be displayed in GUI mode. You can try using the Stop command to see if this will stop the threads, but if not, you should exit JMeter. In non-GUI mode, JMeter will exit if some threads fail to stop within the 5 second time limit. [This can be changed using the JMeter property Control Panel ![]()
| |||||||||||||||
18.1.6 WebService(SOAP) Request (DEPRECATED) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
*** This element is deprecated. Use HTTP_Request instead *** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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. An important note on the sampler is it will automatically use the proxy host and port passed to JMeter from command line, if those 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 sets 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 the version of apache soap does not 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 ![]()
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
posted on 2014-03-05 11:25 順其自然EVO 閱讀(14396) 評論(0) 編輯 收藏 所屬分類: jmeter