Introduction

Previously, Dennis Chen shared a small talk illustrating how you can execute a loading test with ZK applications using JMeter. Now, in this blog we will introduce how you can use ZK JMeter Plugin to simplify your work. With this JMeter Plugin, you no longer have to set user variables or parameter for each zkau request element.

Version: Applicable to JMeter 2.8+

Prepare a simple IdGenerator

For security reasons, ZK generates ID randomly. However to perform a record & reply test, it is mandatory to fix the IDs of the components. The IdGenerator here is used to create a predictable component id when testing.

public class SimpleIdGenerator implements IdGenerator {

    private static final String PREFIX = "zk_comp_";
    private static final String INDEX_KEY = "Id_Num";

    public String nextComponentUuid(Desktop desktop, Component comp) {
    	int i = Integer.parseInt(desktop.getAttribute(INDEX_KEY).toString());
        i++;// Start from 1
        desktop.setAttribute(INDEX_KEY, String.valueOf(i));

        return PREFIX + i;
    }

    public String nextComponentUuid(Desktop desktop, Component comp,
            ComponentInfo info) {
        return nextComponentUuid(desktop, comp);
    }

    public String nextDesktopId(Desktop desktop) {
    	System.out.println("new Desktop");
        if (desktop.getAttribute(INDEX_KEY) == null) {
            desktop.setAttribute(INDEX_KEY, "0");
        }
        return null;
    }

    public String nextPageUuid(Page page) {
        return null;
    }
}

To use this generator, we have to add a configuration to zk.xml

<system-config>
    <id-generator-class>foo.jmtest.SimpleIdGenerator</id-generator-class>
</system-config>

Install ZK JMeter Plugin

Download zk-jmeter-plugin-0.8.0.jar, then place the jar file in the following folder: JMETER_HOME\lib\ext.

Prepare a Test Plan

  1. Create a Thread Group in Test Group.
  2. Add HTTP Cookie Manager in Thread Group
  3. Add HTTP Request Defaults in Thread Group.
  4. Add Transaction Controller in Thread Group.
  5. Edit HTTP Request Defaults, set the Server Name and Port Number.
  6. Create a ZK HTTP Proxy Server (Add > Non-Test Elements) in WorkBench, and edit it as follows
    • Set Target Controller to Test Plan > Thread Group > Transaction Controller
  7. Start the ZK HTTP Proxy Server

01

Start to Record Testing Scripts

Now, you are ready to record the request of the browser to a test case. Please switch the proxy of your browser to host:port (in this case, proxy is localhost:9999), and link it to the application ( in this case, it is http://localhost:8080/product-app/index.zul) . I did some selection, textbox typing, and button clicking , you will see not only the first zul request was recorded, but also zkau too. After this has been done, switch the proxy off.

Get Adobe Flash player

and we need to tick off a checklist of the record:

  • Check that the uuid of zkau is created by SimpleIdGenerator (it will have prefix zk_comp_)
  • Check that there is no rmDesktop command in the zkau record, if you have one, please remove it. ( It is for removing previous tasks when we recorded the testcase, we don’t need it anymore)
  • Make sure Server Name and Port Number are recorded in zkau since we already set them in HTTP Request Defaults.

ZK JMeter Plugin now comes in and will replace dtid parameter value as ${dtid} automatically, we can then use this script to test ZK application immediately without any further tuning. You no longer need to set user variables or parameter for each zkau request manually.

Monitor Server Memory

This JMeter Plugin can also help you in monitoring Server Memory easily.

  1. Add the following JVM arguments to the server start command, then restart the server.
    • -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=1010 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false
  2. Add JMX Visualizer (Add > Listener) in Thread Group.

02

In this case,  we set JMX remote port as 1010, then we can start to run the JMeter script, after running the JMeter script, the memory usage chart will be plotted.
03

Summary

ZK JMeter Plugin can help you to perform stress tests on your ZK applications with JMeter easily; automating the process of replacing parameter values with user variables. It also provides a JMX Visualizer which can help users to monitor server memory usage during the test.

Resource

  • Download ZK JMeter Plugin here.
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

4 Responses to “ZK JMeter Plugin”

  1. Juan Vicente says:

    Hello , I’m trying to download the plugin with my user , but link always redirects to user/pass screen , despite user and pass are correct (“login succesfully in default screen”), is there any another register?

    Regards!!!

  2. Jimmy says:

    You should be able to download the file after logging into the website with your ZK forum account. To double check if you have successfully logged in, you can go to zk home page: http://www.zkoss.org/, then check the upper right corner and see if your user name is there: see http://screencast.com/t/Jh28gtUO

  3. Bob says:

    What’s the difference between JMeter’s default Proxy server and ZK Proxy server? It records Ajax or only XHR? I read about runing Selenium in JMeter so ZK JMeter plugin will replace all this stuff?

  4. Bilal says:

    Hi Jimmy,

    I tested my simple database application through the steps identified in this blog. I able to create the script and run it. But it is not creating the database record in db, that it is suppose to do through the script.

    Not sure what I am missing.

    Thanks,
    Bilal

Leave a Reply