Using the JMeter load generator
JMeter is another cross-platform tool under the Apache umbrella.
It is typically used as a load testing tool for web applications, although with the integration of different plugins it is possible to extend it to better suit your needs.
JMeter uses a .jmx
extension as the testing plan and we will see how to use NetBeans plugins to create and load those files from within the IDE.
In this recipe we will see how to create and run JMX plans from within the IDE. The creation and configuration of such plans are beyond the scope of this book.
If you wish to know more about Apache JMeter please visit: http://jakarta.apache.org/jmeter/.
We will need two plugins for controlling JMeter from within NetBeans.
These plugins are:
Both can be found from the Plugin Manager:
To do so, follow the below steps:
- Navigate to Tools and then Plugins.
- On the Plugin Manager dialog click on Available Plugins.
- Click on search and type load generator.
- Select both plugins and click on the Install button.
- Accept the license agreement and follow the installation process.
- Close the Plugin Manager.
We will need a Java Web project for this recipe to continue. Follow the steps below for creating one:
- Create a New Project, this can be achieved by either clicking File and then New Project or pressing Ctrl+Shift+N.
- On New Project window on categories side choose Samples and Java Web and on Projects side select Servlet Stateless (Java EE 6) and click Next >.
- Under Name and Location: Leave all the default values and click Finish.
Now we will create a JMeter Plan:
- Right-click on Servlet Stateless node, select New and Other....
- On New File dialog under Categories expand the Load Testing Scripts node and click on the JMeter Plans folder.
- Then on File Types select New JMeter Plan and click Next.
- Under Name and Location: under Script Name type TestingPlan and let the IDE take care of the other fields.
- Click Finish.
With our JMeter plan created, let's load a test script.
- Click on the Services window.
- Expand the Load Generator node, right-click on it and press Start....
- You will be prompted with a File Chooser.
- Navigate to the jmeter folder in the StatelessServlet project and select the .jmx file.
- Click OK.
When loading the JMX file NetBeans will execute it and display the following text on the output window:
Starting JMeter subsystem... Done
Starting JMeter test plan named JMeter Template Plan (/home/user/ NetBeans Cookbook/Chap 11/ServletStateless/jmeter/TestingPlan.jmx)
Simulating 2 users with ramp-up time of 3s
Editing JMX files and another way of using a load generator in NetBeans.
It is also possible to start JMeter by using NetBeans Profiler.
To do this follow the steps below:
- On the toolbar click on Profile... and then Profile Main Project (or press Alt+F2).
- Select the Java SDK used for profiling and press OK.
- On Profile ServletStateless dialog you will notice a checkbox for the LoadGenerator Script, check it.
- The profiler shows the scripts associated with this project.
- To execute the script in conjunction with the profiler click Run.
Right-clicking on the .jmx
and selecting External Editing will bring up the JMeter editor.
This is where you will be able to create the Load Generator Script properly.