About Overview Download Releases Download Nightly Tarball Changes Known Bugs License TODO Contributors Documentation User Manual Developer Manual JMeter Wiki Community Get Involved Mailing Lists CVS Repositories |
JMeter Extension Scenario
> 2. The purpose of this tutorial is to describe the general steps involved in a JMeter extension scenerio. The JMeter documentation describes what must be done on a microscopic level but does not provide an overall idea of the process. That is the intent of this brief article. The JMeter extension documentation should be consulted for details. The high level procedure followed these steps. Planning Code the configuration object Code the configuration GUI object Code the controller object Code the controller GUI object Code the Sampler object Install your extension Tips ## Planning What you want the sampler to do What information is needed for the sampler to work How the information is to be acquired from the user You'll notice that the coding steps are somewhat backwards from the planning steps (the sampler is coded last). The coding order was determined by which classes could be tested earliest. The config/gui can be tested in isolation. The controller can be tested with the config element. Neither of these requires a Sampler to be present initially. ## Configuration Object `UrlConfig` The configuration object usually inherits from `org.apache.jmeter.config.AbstractConfigElement` . It implements many of the methods of `org.apache.jmeter.gui.JMeterComponentModel` that are needed to effectively interact with JMeter. Constructor - In the constructor you should at least define the name of your configuration element. This is best delegated to the base class's `setName` method. Property Name Strings - You should define a static final string for each property you wish to define. These strings will serve as keys into a hash table maintained by `AbstractConfigElement` . For example:
>        								 public static final HOST_NAME = "hostname";
> 3. would define a property in the hash table for storing a host name. Getters/Setters - For each property name you define in the previous step, define the appropriate accessor methods. The implementation of these accessors should usually delegate to `AbstractConfigElement` . For example:
>        								   public void setHostname(String hostname)
>        	{ setProperty(HOST_NAME, hostname); }

>        	public String getHostname()
>        	{ return (String)getProperty(HOST_NAME); }
> 6. Some accessor implementations may be more complex. See the `UrlConfig` object for a more involved example. `String getClassLabel()` - This is the label that will display in the drop-down menu for adding your configuration element. `clone()` - Your configuration element is expected to be cloneable. `addConfigElement(ConfigElement)` - A typical implementation of this method looks like
>        								   public void addConfigElement(ConfigElement config) {
>        		if (config instanceof MyConfig)
>        			updatePropertyIfAbsent((MyConfig)config);
>        	}
> where `updatePropertyIfAbsent` is handled by the super class. `getGuiClass` - return the name of the this class's corresponding GUI class . ## Configuration GUI Each configuration element you define can have a companion GUI class. It helps to have a little knowledge of Swing for this. Extend Swing's `JPanel` class and implement JMeter's `org.apache.jmeter.gui.ModelSupported` interface. Remember that you can review the `UrlConfigGui` example for hints if you get stuck. Data Members - You should possess at least two data members: a reference to your partner configuration element and a reference to a `org.apache.jmeter.gui.NamePanel` . You will likely have several others depending on how sophisticated your GUI is. Add Panels - The layout manager used for many of the panels used in JMeter is `org.apache.jmeter.gui.VerticalLayout` . As the name implies, it supports arranging other panels in a vertical fashion. You can define each of your panels in a `get` method and add them to the configuration GUI in a method called `init` . Once again, refer to `UrlConfigGui` for an example. Implement Listeners - Implement listeners for your GUI components. The `UrlConfigGui` serves as a satisfactory example. `setModel` - Use this method to have the model data member set on your GUI instance. Run `init` from inside this method also. `updateGui` - Use this method to set the GUI fields from the model. ## Generative Controller `Entry` `createEntry` - This method is the raison d'etre of the `org.apache.jmeter.control.SamplerController` interface. The general idea is to construct an `Entry` object and populate it with config objects. `clone` - After you perform you cloning duties, be sure to pass the cloned instance to the `standardCloneProc` method so that base class cloning activities can complete. `getClassLabel` - This is the label displayed by the drop-down menu for the controller. `getGuiClass` - This should return a Class object for the associated GUI class . ## Generative Controller GUI `JPanel` `ModelSupported` `setModel` ## Sampler
>     								public SampleResult sample(Entry e)
> 3. ## Installation Package the class files into a JAR file. Place the JAR file into the `ext` subdirectory of the JMeter root install directroy. Edit the `bin/jmeter.properties` file of the JMeter installation. Find the `search_paths` entry and add your JAR to the list. It should look like
>        								search_paths=ApacheJMeter.jar;classes;../ext/YourJar.jar
> 1. Run JMeter and watch the magic. ## Tips You might consider using log4j as your logging utility since that's what JMeter uses. It's helpful for figuring out what's going on. Not all JMeter classes have been fully outfitted with logging statements. If things get nasty, you might have to add your own to JMeter and recompile it to see what is happening. If you do decide to use log4j and you set the priority (or level, as it will soon be called) to debug, you will probably see way more than you need to know. You can filter the JMeter stuff by making the following modifications to `log4j.conf` in the JMeter's `bin` directory. The bold text is added/modified
>        									# Set the appenders for the categories
>        	log4j.rootCategory=

>        								info

>        									,Root_Appender

>        								log4j.category.com.myfirm.jmeter=debug,

>        	log4j.category.org.apache.jmeter.control=debug
>        	log4j.category.org.apache.jmeter.gui.tree.NonGuiTree=INFO,File_Appender
Note that the root (default) debugging has been set to info . This eliminates most log4j output from JMeter. The new line specifies the name of the package containing JMeter extensions. ( `com.yourfirm.jmeter` ) in this example. Note that it is not necessary to specify a particular class name. Also, note that no appenders are specified - just the trailing comma. If you specify Root_Appender here you'll see your message appear twice (because you specified the same appender twice). All you really want to do is override the priority. Implement `clone` carefully. This is an often overlooked method for a lot of folks. JMeter makes heavy use of cloning. Check out some of the JMeter coniguration elements and controllers to see how they do it. Notice that in most cases, a special method is usually invoked to perform base class cloning activities. For configuration elements, this is `configureClone` . For controllers, it is `standardCloneProc` .
Copyright © 1999-2001, Apache Software Foundation