从Java函数和属性运行JMeter脚本时不起作用 [英] When running JMeter script from Java functions and properties do not work

查看:146
本文介绍了从Java函数和属性运行JMeter脚本时不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用

String jmeterHome = "D:/tmp/apache-jmeter-3.3";
StandardJMeterEngine jmeter = new StandardJMeterEngine();
JMeterUtils.loadJMeterProperties(jmeterHome + "/jmeter.properties");
JMeterUtils.setJMeterHome(jmeterHome);
JMeterUtils.initLocale();

SaveService.loadProperties();

File script = new File(jmeterHome + "/http_localhost.jmx");
HashTree testPlanTree = SaveService.loadTree(script);

Summariser summer = null;
String summariserName = JMeterUtils.getPropDefault("summariser.name", "summary");
if (summariserName.length() > 0) {
    summer = new Summariser(summariserName);
}       

String logFile = jmeterHome + "/file.jtl";
ResultCollector logger = new ResultCollector(summer);
logger.setFilename(logFile);
testPlanTree.add(testPlanTree.getArray()[0], logger);

jmeter.configure(testPlanTree);
jmeter.run();

在线程组"配置的JMeter GUI中,我将线程数"设置为"$ {__ P(xxx,20)}".从GUI可以正常工作-我可以执行默认值为"20"的脚本.但是上面的代码不会启动任何线程. Java代码显示它正在尝试启动零个线程.

In JMeter GUI in "Thread Group" configuration I am setting "Number Of Threads" to be "${__P(xxx,20)}". It works fine from the GUI - I can execute script with default value of "20". But the code above does not start any threads. Java code prints that it is trying to start zero threads.

我见过 Jmeter函数没有从Java代码调用时无法执行,而且我的项目中确实有以下依赖项

I have seen Jmeter functions don't executing when calling from java code and I do have following dependencies in my project

        <dependency>
            <groupId>org.apache.jmeter</groupId>
            <artifactId>ApacheJMeter_java</artifactId>
            <version>3.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.jmeter</groupId>
            <artifactId>ApacheJMeter_http</artifactId>
            <version>3.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.jmeter</groupId>
            <artifactId>ApacheJMeter_functions</artifactId>
            <version>3.3</version>
        </dependency>

推荐答案

在Java代码中使用Jmeter函数时,Jmeter尝试将Java类路径中与函数相关的类与'search_path'(从罐子中读取类).因此,只有在两个路径中都存在必需的函数类时,Jmeter函数才起作用( Jmeter对每个函数都有单独的类).

When Jmeter functions are used in the Java code, Jmeter tries to compare the function related classes from java class path with classes from the 'search_path' (Reads classes from the jars). So Jmeter function works only if required function class is present in both the path (Jmeter has seperate class for each function).

这就是为什么我们需要确保在pom中添加'ApacheJMeter_functions' jar(将在类路径中添加 )以及jmeter函数jar的路径设置为'search_path'.两者应具有相同的版本.

This is why we need to make sure the 'ApacheJMeter_functions' jar added in the pom (which will be added in class path ) and the path to jmeter functions jar is set to 'search_path'.Both should have same version.

您可以参考此链接了解更多详情

You can refer this link for more details

这篇关于从Java函数和属性运行JMeter脚本时不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆