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/.

Getting ready

We will need two plugins for controlling JMeter from within NetBeans.

These plugins are:

  • JMeter Kit
  • Load Generator

Both can be found from the Plugin Manager:

To do so, follow the below steps:

  1. Navigate to Tools and then Plugins.
  2. On the Plugin Manager dialog click on Available Plugins.
  3. Click on search and type load generator.
    Getting ready
  4. Select both plugins and click on the Install button.
  5. Accept the license agreement and follow the installation process.
  6. Close the Plugin Manager.

We will need a Java Web project for this recipe to continue. Follow the steps below for creating one:

  1. Create a New Project, this can be achieved by either clicking File and then New Project or pressing Ctrl+Shift+N.
  2. 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 >.
  3. Under Name and Location: Leave all the default values and click Finish.

How to do it...

Now we will create a JMeter Plan:

  1. Right-click on Servlet Stateless node, select New and Other....
  2. On New File dialog under Categories expand the Load Testing Scripts node and click on the JMeter Plans folder.
    How to do it...
  3. Then on File Types select New JMeter Plan and click Next.
  4. Under Name and Location: under Script Name type TestingPlan and let the IDE take care of the other fields.
  5. Click Finish.

With our JMeter plan created, let's load a test script.

  1. Click on the Services window.
  2. Expand the Load Generator node, right-click on it and press Start....
    How to do it...
  3. You will be prompted with a File Chooser.
  4. Navigate to the jmeter folder in the StatelessServlet project and select the .jmx file.
  5. Click OK.

How it works...

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

JMeter test plan running

JMeter test plan stopped

There's more...

Editing JMX files and another way of using a load generator in NetBeans.

JMeter+NetBeans profiler

It is also possible to start JMeter by using NetBeans Profiler.

To do this follow the steps below:

  1. On the toolbar click on Profile... and then Profile Main Project (or press Alt+F2).
  2. Select the Java SDK used for profiling and press OK.
  3. On Profile ServletStateless dialog you will notice a checkbox for the LoadGenerator Script, check it.
    JMeter+NetBeans profiler
  4. The profiler shows the scripts associated with this project.
  5. To execute the script in conjunction with the profiler click Run.

Editing the JMX file

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.119.206