Java Ninja Chronicles By Norris Shelton

Things I learned in the pursuit of code

Get JMeter

Download the software from Apache from http://jmeter.apache.org/download_jmeter.cgi. I use IntelliJ. It says to define a JMETER_HOME environment variable. Once you have that, you should be able to create JMeter file times (*.jmx). If you right-click on a *.jmx file, IntelliJ will give you the option to run the file. Running the file will open the JMeter application with the specified file.

Test Plan

The test plan is the first item in the left-hand panel. It looks like a Erlenmeyer flask. This is where you will put the name of your test.

You can create User Defined Variables that can be used in other places in the test. An example a user defined variable with the name host and a value of localhost. It can be used by ${host}. Then later, the value can be changed to test to another server.

Thread Group

You can add a Thread Group by right-clicking on the Test Plan and selecting Threads (Users), then Thread Group. It looks like a spool of thread. The thread group is used to control the load. What should happen if there is a sampler error? Continue and Stop Thread are common options.

There is a Thread Properties box that has most of the options here. You can control how many threads (users) you have, how long it takes to ramp up a thread. One second is the default. You can also specify how many iterations (Loop Count) you should perform.

There is also a Scheduler checkbox. If you select that, then there will be a Scheduler Configuration that will become visible. That is good when you want the test to run for a specified amount of time, instead of iterations. You don’t have to specify the Start Time or the End Time. All you need to specify is the Duration (seconds>. If you want a test to run 5 minutes, specify 300 seconds.

HTTP Request

You can add an HTTP Request by right-clicking on the Thread Group, selecting Add, Sampler, then selecting HTTP Request. It looks like a dropper. The http request is where you can specify and control the http request. Some of the things you can specify:

  • server Name or IP. I would use a User Defined Variable here (e.g. ${host}).
  • port
  • connection and response timeouts
  • protocol (defaults to http)
  • HTTP method (defaults to GET)
  • path
  • URL parameters
  • post body data

Once you have something that can generate results, there are several different ways to be presented the data.

View Results Tree

You can add a View Results Graph by right clicking the HTTP Request, then selecting Add, then Listener, then View Results Tree. The icon looks like a dial meter. The View Results Tree is very helpful in debugging your test. It shows each request and each response. There is also the ability to format the response by type, for example JSON.

One caveat with this is that if you have a very long running test or a lot of data, your JMeter will run out of memory. To counter this, you can have it write the data to a file. I usually just disable the View Results Tree by right-clicking on it and clicking disable.

View Results in Table

You can add a View Results in Table by right clicking the HTTP Request, then selecting Add, then Listener, then View Results in Table. The icon looks like a dial meter. The View Results in Table shows the results in tabular format. It has timing information.

Sample #  Start Time	Thread Name       Label         Sample Time(ms)  Status   Bytes  Latency  Connect Time(ms)
19        08:56:26.194  Thread Group 1-1  HTTP Request  9                Success  383    8        2

This is usually the panel I have open when I am running a test. The panel bottom line shows the average and the standard deviation. You can write the results to a file.

Response Time Graph

You can add a Response Time Graph by right clicking the HTTP Request, then selecting Add, then Listener, then Response Time Graph. The icon looks like a dial meter. The Response Time Graph shows the results in in a graphical format. Typically time horizontally and milliseconds vertically. This can also be written to a file.

Summary Report

You can add a Summary Report by right clicking the HTTP Request, then selecting Add, then Listener, then Summary Report. The icon looks like a dial meter. The Summary Report outputs timing information for each JMeter Sampler (e.g. HttpRequest).

Label         # Samples  Average  Min  Max  Std. Dev.          Error %  Throughput         KB/sec              Avg. Bytes
HTTP Request  45619      22       17   115  6.598780184509035  0.0      387.7254415339373  211.72920469177618  559.1861724281549
TOTAL         45619      22       17   115  6.598780184509035  0.0      387.7254415339373  211.72920469177618  559.1861724281549

Generate Summary Results

You can add a Generate Summary Results by right clicking the HTTP Request, then selecting Add, then Listener, then Generate Summary Results. The icon looks like a dial meter. The Generate Summary Results outputs a summarized timing data to the console. The output is below. Notice that every other line is a summary to that point and the others are deltas.

Generate Summary Results +   3265 in     9s =  366.9/s Avg:    22 Min:    17 Max:   110 Err:     0 (0.00%) Active: 10 Started: 10 Finished: 0
Generate Summary Results +  13024 in    30s =  434.1/s Avg:    22 Min:    17 Max:   110 Err:     0 (0.00%) Active: 10 Started: 10 Finished: 0
Generate Summary Results =  16289 in    39s =  418.7/s Avg:    22 Min:    17 Max:   110 Err:     0 (0.00%)
Generate Summary Results +  11524 in    30s =  384.2/s Avg:    21 Min:    17 Max:   112 Err:     0 (0.00%) Active: 10 Started: 10 Finished: 0
Generate Summary Results =  27813 in    69s =  403.7/s Avg:    22 Min:    17 Max:   112 Err:     0 (0.00%)
Generate Summary Results +  12283 in    30s =  409.4/s Avg:    22 Min:    17 Max:   115 Err:     0 (0.00%) Active: 10 Started: 10 Finished: 0
Generate Summary Results =  40096 in    99s =  405.4/s Avg:    22 Min:    17 Max:   115 Err:     0 (0.00%)
Generate Summary Results +    411 in   1.3s =  324.6/s Avg:    20 Min:    17 Max:    26 Err:     0 (0.00%) Active: 0 Started: 10 Finished: 10
Generate Summary Results =  40507 in 100.2s =  404.4/s Avg:    22 Min:    17 Max:   115 Err:     0 (0.00%)

CSV Data Set Config

Needing to run a data-driven test is very common. How do you get JMeter to use data in it’s tests? Use a CSV, of course. You can add a CSV Data Set Config by right clicking the Thread Group, then selecting Add, then Config Element, then CSV Data Set Config. The icon looks like test tubes in a test tube rack. The CSV Data Set Config has the following fields:

  • Filename – the name of the file containing the data
  • File Encoding – file encoding (optional)
  • Variable names (comma-delimited) – the names of the data fields, in order. These names will be available like User Defined Variables (e.g. id -> ${id}, according to the Sharing Mode described below.
  • Delimeter – “,” or “\t” for tab, etc. or use specified value
  • Allow quoted data? – true or false or use specified value
  • Recycle on EOF ? – true or false or use specified value
  • Stop thread on EOF ? – true or false or use specified value
  • Sharing mode – All threads, current thread group, current thread or use specified value

Once you have this configured, you can use the exposed CSV data just as a User Defined Variable that changes per entry in HTTP Requests, etc. Then you can substitute the value in the Path as a URL parameter or path parameter. You can also use them in the body of the post, etc.

HTTP Header Manager

HTTP Header Manager can be used to inject headers to indicate the Content-Type, Accept, etc. You can add a CSV HTTP Header Manager by right clicking the HTTP Request, then selecting Add, then Config Element, then HTTP Header Manager.

HTTP Authorization Manager

HTTP Authorization Manager can be used to inject authorization header information into a request. You can add a HTTP Authorization Manager by right clicking the HTTP Request, then selecting Add, then Config Element, then HTTP Authorization Manager.
The following fields are available:

  • Base URL – URLs to send the authorization header
  • Username – the username to authorize
  • Password – the unencrypted password value
  • Domain – The domain to use for NTLM
  • Realm – The realm to use for NTLM
  • Mechanism – Type of authorization to perform. This depends on the Sampler Mechanism that is specified on HTTP Request in the Implementation field.
LinkedIn Auto Publish Powered By : XYZScripts.com