gpt4 book ai didi

java 运行 jmx 禁用操作

转载 作者:行者123 更新时间:2023-12-02 03:11:32 24 4
gpt4 key购买 nike

我正在使用 java 运行 jmx 文件,该文件已禁用采样器。所以我认为它不会运行禁用的采样器,但它确实如此。这是 jmx 文件代码:如您所见 enabled="false"

<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="Edit User All Parameters" enabled="false">

我使用org.apache.jmeter.save.SaveService;类来加载文件内容:

 File jmxFile = new File(jmxFilePath);
HashTree testPlanTree = null;
try{
testPlanTree = SaveService. loadTree(jmxFile);
}catch(IOException ex){}

知道如何解决这个问题吗?

最佳答案

我的期望是您的代码丢失 JMeter.convertSubTree()方法,根据 JavaDoc

convertSubTree

public static void convertSubTree(HashTree tree)

Remove disabled elements Replace the ReplaceableController with the target subtree

因此请确保在运行测试之前调用它

示例代码(以防万一您仍然需要它),请注意 JMeter.convertSubTree(testPlanTree);

   //JMeter Home
String jmeterHome = "c:/apps/jmeter";

// JMeter Engine
StandardJMeterEngine jmeter = new StandardJMeterEngine();

// Initialize Properties, logging, locale, etc.
JMeterUtils.loadJMeterProperties(jmeterHome + "bin/jmeter.properties");
JMeterUtils.setJMeterHome(jmeterHome);
JMeterUtils.initLogging();// you can comment this line out to see extra log messages of i.e. DEBUG level
JMeterUtils.initLocale();

// Initialize JMeter SaveService
SaveService.loadProperties();

// Load existing .jmx Test Plan
HashTree testPlanTree = SaveService.loadTree(new File(jmeterHome + "bin/test.jmx"));

// Remove disabled test elements
JMeter.convertSubTree(testPlanTree);


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


// Store execution results into a .jtl file
String logFile = jmeterHome + "/bin/test.jtl";
ResultCollector logger = new ResultCollector(summer);
logger.setFilename(logFile);
testPlanTree.add(testPlanTree.getArray()[0], logger);

// Run JMeter Test
jmeter.configure(testPlanTree);
jmeter.run();

参见Five Ways To Launch a JMeter Test without Using the JMeter GUI文章了解有关执行 JMeter 测试的不同方法的更多信息。

关于java 运行 jmx 禁用操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40970794/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com