| 网站首页 | 测试咨讯 | 新手入门 | 专注性能 | 测试技术 | 测试管理 | 测试工具 | 开发社区 | 工具下载 | 资料下载 | 测试论坛 | 

[CNTester联盟群]交流群:34446273/21968356/64461572 白盒群:18400216 自动化群:2706508 性能群:4498858 外包群:59649884 管理群(需有管理经验):64442523

新手入门
 入门指南
 经验之谈
测试咨讯
 行业新闻
 网站动态
 人才就业
 CNTester基金
 标准规范
专注性能
 性能测试知识
 性能测试工具
 程序设计性能
 数据库性能
 Web应用服务器性能
 操作系统性能
 服务器与网络性能
测试技术
 用例设计
 性能测试
 自动化测试
 Web测试
 面向对象测试
 综合技术
 阶段性测试
 行业类测试
测试管理
 项目管理
 项目案例
 质量管理
 软件过程
测试工具
 Mercury系列
 Rational系列
 测试管理工具
 性能测试工具
 功能测试工具
 单元测试工具
 其它测试工具
开发社区
 Java技术
 DotNet技术
 C技术
 数据库技术
 操作系统
 服务器与中间件
工具下载
 测试工具
 开发工具
 企业工程
 网络通信
 媒体桌面
 游戏娱乐
 其他工具
资料下载
 测试资料
 程序设计
 数据库
 操作系统
 应用服务器
 电子期刊
 其他资料
 
 
您现在的位置: 中国测试员网站 >> 专注性能 >> 性能测试工具 >> JMeter >> 文章正文
  [推荐]BuildingPlugInWithEclipse           ★★★ 【字体:
BuildingPlugInWithEclipse
作者:DanielGr…    文章来源:apache    点击数:    更新时间:2007-7-6    

Building JMeter plug-in with Eclipse

[WWW] Eclipse is a very popular Java development environment.

Targetted to Eclipse 3.1 and JMeter 2.1 trunk version. JMeter isn't designed to be edited and build from Eclipse IDE (JMeter uses Ant build file and complex path/jar structure with optional dependencies), so some work has to be done before we get wheels running.

NOTE: the JMeter trunk code is very out of date - the current branch is rel-2-2. Also, there is an eclipse.classpath which can be used to set up the appropriate exclusions etc - sebb

Building JMeter from sources with Eclipse

It's useful to have JMeter Eclipse project in hand, since you need to do debugging and possible bug fixing in JMeter itself.

1. Check out JMeter trunk from Subversion

2. Set up jmeter-trunk project

  • Let Eclipse internal compiler handle the building of JMeter, instead of relying on JMeter's own Ant build files. When Eclipse handles building, development work goes more smoothly.

  • Source build paths:

    • Add all paths which contain /org folder

      • src/monitor and src/protocol contain nested levels so be careful choosing the right target folders

      • src/protocol/jndi has a strange directory structure so skip this path

    • Exclude following files from building (they have missing dependencies)

      • org/apache/jmeter/util/JsseSSLManager.java (HTTP security)

      • org/apache/jmeter/util/keystore/DefaultKeyStore.java (HTTP security)

      • org/apache/jmeter/util/keystore/PKCS12KeyStore.java (HTTP security)

      • org/apache/jmeter/protocol/http/sampler/WebServiceSampler (depend on javax.mail)

      • org/apache/jmeter/protocol/http/control/gui/WebServiceSamplerGui (depend on javax.mail)

      • org/apache/jmeter/reporters/ (depend on javax.mail)

    • ...or just copy missing JARs from Internet (Java MAIL API: mailapi.jar, etc.), it's easier

    • ...or just add mailapi.jar from Internet to build path and remove src/protocol/jms and src/htmlparser16 from source folders

    • Add libraries

      • All jar files under lib/ folder

    • Export libraries

      • At least logkit libraries are needed in projects depended on JMeter

      • Export them at order and export tab page in the project properties dialog

    • To make log4j logging to Eclipse console work, you need to change some code. You can find the affected code in the org.apacha.jmeter.jorphan.logging.LoggingManager.initializeLogging(Properties) method. Read more notes about this below.

    public static void initializeLogging(Properties properties) {
        if (logManager == null) {
            logManager = new LoggingManager();
        }

        setFormat(properties);

        setPriority(properties.getProperty(LOG_PRIORITY, "INFO"));

        // Direct to system out

        isWriterSystemOut = true;
        isTargetSystemOut = true;

        WriterTarget wt = new WriterTarget(new OutputStreamWriter(System.out), getFormat());
        Hierarchy.getDefaultHierarchy().setDefaultLogTarget(wt);

        setLoggingLevels(properties);
        
        // if (logManager == null) {
        // logManager = new LoggingManager();
        // }
        //
        // setFormat(properties);
        //
        // // Set the top-level defaults
        // setTarget(makeWriter(properties.getProperty(LOG_FILE, "jmeter.log"), LOG_FILE));
        // setPriority(properties.getProperty(LOG_PRIORITY, "INFO"));
        //
        // setLoggingLevels(properties);
        // // now set the individual categories (if any)
        //
        // setConfig(properties);// Further configuration
    }
  • Now Eclipse should build JMeter without errors (stop icons in source tree)

Setting up plug-in project

This Eclipse project will build your custom components and launch JMeter with a configuration which will find them classes propeply.

1. Set up your custom plug-in project

  • Create a new Java project

  • Add jmeter-trunk to project dependencies

  • Create bin/ and src/ folders

  • Create the src/jmeter.properties file

    • This defines where JMeter internal class loader looks for classes

    • It should look like this (please note that you have to adapt the first part of the search_paths property so it points to your JMeter Eclipse project!)

# JMeter uses case sensitive string matching to test these paths against absolute class path.
# This is very bad since paths must be *exactly* here as they appear in Java classpath.
# Hopefully this will be fixed in the future versions. Note Windows needs to escape \ character as \\.

search_paths=C:\\icecom\\jmeter-2.2\\bin;.

# File that holds a record of name changes for backward compatibility issues
upgrade_properties=upgrade.properties

# Should JMeter automatically load additional JMeter properties?
# File name to look for (comment to disable)
user.properties=user.properties

# Should JMeter automatically load additional system properties?
# File name to look for (comment to disable)
system.properties=system.properties

log_level.jorphan=WARN

log_level.jmeter.testbeans=WARN

log_level.jmeter.gui=WARN

log_level.jmeter.engine.util=WARN

log_level.jmeter.threads.util=WARN

log_level.fi.xxx=TRACE

# Widen default log output for Eclipse console
log_format=%-6.6{priority} (%-10.10{thread}) [%-25.25{category}] %{message}
                         .

  • Create the src/log4j.conf file

log4j.rootLogger=debug, stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n

2. Setting up a JMeter launcher

  • Set working directory to bin/ in your project

    • JMeter is hard coded to look up jmeter.properties in the launch folder

    • E.g. ${workspace_loc:SIPPerformanceStresser/bin}

  • Copy lib/ from jmeter-trunk to your plug-in project root

    • JMeter is hard coded to look up jars from ../lib

  • Main class: org.apache.jmeter.NewDriver

Creating components

JMeter 2.x uses its internal TestBean-framework for adding new components. For more information, see Tutorial - Making a JMeter TestBean, [WWW] this PDF and JMeter source code

For each component you need

1. An element class which interits from [TestElement, ConfigurationElement, XXXElement] and implements TestBean interface. TestBean interface marks classes which JMeter plug-in class loader loads automatically.

2. Each TestBean class needs BeanInfoSupport class whichs describes the properties of the element class. This class name must be MyTestElement + BeanInfo, e.g. MyTestElementBeanInfo, or the class loader doesn't find it.

3. Properties file which gives out user interface strings for properties. The name of the file must be MyTestElement + Resources.properties, e.g. MyTestElementResources.properties.

JMeter framework doesn't report about missing files, so be careful with the filenames.

Example

Here are some examples with some dummy non-working implemenation details.

Java source fi/xxx/jmeter/sip/core/SIPReceiver

package fi.xxx.jmeter.sip.core;

import org.apache.jmeter.samplers.AbstractSampler;
import org.apache.jmeter.samplers.Entry;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.testbeans.TestBean;

public class SIPReceiver extends AbstractSampler implements TestBean {

        public SampleResult sample(Entry e) {
                return null;
        }

}

Java source fi/xxx/jmeter/sip/core/SIPReceiverBeanInfo

package fi.xxx.jmeter.sip.core;

import java.beans.PropertyDescriptor;

import org.apache.jmeter.config.CSVDataSet;
import org.apache.jmeter.testbeans.BeanInfoSupport;

public class SIPReceiverBeanInfo extends BeanInfoSupport {
        
        public SIPReceiverBeanInfo() {
                super(SIPReceiver.class);
                
                createPropertyGroup("sip_receiver", new String[] { "filename", "variableNames", "delimiter" });
                PropertyDescriptor p = property("filename");
                p.setValue(NOT_UNDEFINED, Boolean.TRUE);
                p.setValue(DEFAULT, "");
                p.setValue(NOT_EXPRESSION, Boolean.TRUE);
                p = property("variableNames");
                p.setValue(NOT_UNDEFINED, Boolean.TRUE);
                p.setValue(DEFAULT, "");
                p.setValue(NOT_EXPRESSION, Boolean.TRUE);
                p = property("delimiter");
                p.setValue(NOT_UNDEFINED, Boolean.TRUE);
                p.setValue(DEFAULT, ",");
                p.setValue(NOT_EXPRESSION, Boolean.TRUE);
        }
}


Properties file fi/xxx/jmeter/sip/core/SIPreceiverResources.properties

displayName=SIP Receiver
sip_receiver.displayName=Configure SIP receiver
filename.displayName=Filename
filename.shortDescription=Name of the file (within your supporting file directory) that holds cvs data
variableNames.displayName=Variable Names (comma-delimited)
variableNames.shortDescription=List your variable names in order to match the order of columns in your csv data.  Separate by commas.
delimiter.displayName=Delimiter (use '\\t' for tab)
delimiter.shortDescription=Enter the delimiter ('\\t' for tab)

Running from command line

When developing your test component, you need to modify your source code often. This leads to restarting the JMeter. JMeter launch tooks a while, killing your productivity.

If you are not developing UI related functionality, create a test plan, save it, and start JMeter from command line without GUI. Put following to your program arguments:

--nongui --testfile C:\zzz\SIPPerformanceStresser\bin\siptest.jmx

Notes

Faulty jorphan logging launcher

I wasted 4 hours trying to get Jorphan (Jmeter component) logging to work. Jorphan overrides log4j normal configuration mechanism, but does it badly, making usage of custom log4j settings impossible. Specifically initializeLogging always overrides previous settings with its own default settings.

1. There is one missing dependency which causes start-up failure with message Caused by: java.lang.NoClassDefFoundError: org/apache/avalon/excalibur/i18n/ResourceManager if you try to configure logger via jmeter.properties. Get the jar file from [WWW] http://mirrors.bevc.net/apache/excalibur/excalibur-i18n/binaries/ and place it to lib/

2. Even after placing a correct logging file through jmeter.properties settings you get this

org.apache.avalon.framework.configuration.ConfigurationException: No log targets configured for the root logger.
        at org.apache.avalon.excalibur.logger.LogKitLoggerManager.setupLoggers(LogKitLoggerManager.java:531)
        at org.apache.avalon.excalibur.logger.LogKitLoggerManager.configure(LogKitLoggerManager.java:407)
        at org.apache.jorphan.logging.LoggingManager.setConfig(LoggingManager.java:148)
        at org.apache.jorphan.logging.LoggingManager.initializeLogging(LoggingManager.java:114)
        at org.apache.jmeter.util.JMeterUtils.getProperties(JMeterUtils.java:133)
        at org.apache.jmeter.JMeter.initializeProperties(JMeter.java:327)
        at org.apache.jmeter.JMeter.start(JMeter.java:242)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.apache.jmeter.NewDriver.main(NewDriver.java:161)

My head was already hurting so badly that I didn't want to debug the problem further. JMeter logging code could have some clean-up work.

Troubleshooting

If you get an NullPointerException about NOT_UNDEFINED property when creating your element in GUI, the BeanInfo class of your component has a wrong filename.

If widget labels are not read from resouces file, your the properties file of your component has a wrong filename

[WWW] Email me

last edited 2006-11-30 10:22:51 by DanielGrob

文章录入:root    责任编辑:root 
  • 上一篇文章:

  • 下一篇文章:
  • 发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
     
    最新热点 最新推荐 相关文章
    · mysql优化基础
    · MySQL服务器安装完之后如何调节性能
    · Mysql数据库管理系统优化方案
    · MySQL Performance Tuning Primer Script
    · MySQL 性能跟踪语句
    · Linux 和对称多处理
    · 应用与数据库性能测试解决方案,QUEST SO
    · 负载、性能测试和容量测试的关系和区别
    · LoadRunner监控Windows和Linux常见问题
    · 31个用来测试网站各项性能的免费工具
    · 应用与数据库性能测试解决方案,QUEST SO
    · 研究项目: JBoss架构分析
    · 如何通过 20% 的工作获得 80% 的性能改善
    · Linux 调度器内幕
    · 在 Linux 上利用数据分区功能提高可伸缩性
    · 降低 Linux 内存开销
    · Linux 和对称多处理 在 SMP 系统上发挥 L
    · 如何提高系统性能指标
    · Java 优化技术 充分挖掘 Java 应用程序性
    · 高速缓存和连接池对访问数据库性能的影响
    JMeter在Web Services性能测
    DB2 基础: 表空间和缓冲池
    洞察 DB2 Universal Databas
    [性能测试工具]测试您的 DB2
    使用JMeter进行性能测试
    JMeter技巧集锦
    org.apache.jmeter.examples
    org.apache.jmeter.engine.e
    [JMeter_UML] org.apache.jm
    [JMeter_UML] org.apache.jm
     
     
     
    ======> [CNTester联盟群]交流群:34446273/21968356/64461572 白盒群:18400216 自动化群:2706508 性能群:4498858 外包群:59649884 管理群(需有管理经验):64442523
    | 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 版权申明 | 网站公告 | 管理登录 | 

    Copyright@2007 by CNTester.com 中国测试员网站 桂ICP备07005590

    本站为开源免费网站,非商业赢利性组织。本站文章部分从网络搜索获取,如果您认为某些侵犯了您的权益,麻烦您联系本站,我们会尽快删除相关内容,同时也希望您的谅解,我们的初衷是为了让更多人去学习这方面的知识,让行业有更好的发展。

    联系电话: 15021358905