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

查看:31
本文介绍了从 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' (从 jars 中读取类).因此 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天全站免登陆