JMeter java API - 负载测试运行但服务器上未收到任何请求
JMeter java API - load test runs but no requests are received on the server
我的 localhost:8181 上有一个 Spring 引导服务器 运行,我可以成功地向它发出 GET 请求,并且我看到打印出来的日志。
现在我做了一个负载测试的概念验证。我正在使用 JMeter Java API 使用来自 JMeter 的 Java API 向 Spring 引导服务器发送请求。 JMeter 运行测试套件并且没有错误报告但是在我的服务器上我没有传入请求。
这是我使用的负载测试代码:
public class Main {
public static void main(String... args) {
// Engine
StandardJMeterEngine jm = new StandardJMeterEngine();
JMeterUtils.setJMeterHome("C:\Users\daz\Desktop\apache-jmeter-3.2");
// jmeter.properties
String jmeterProperties = Main.class.getClassLoader().getResource("jmeter.properties").toString().replace("file:", "");
JMeterUtils.loadJMeterProperties(jmeterProperties);
HashTree hashTree = new HashTree();
// HTTP Sampler
HTTPSampler httpSampler = new HTTPSampler();
httpSampler.setDomain("localhost");
httpSampler.setPort(8181);
httpSampler.setPath("/job/test");
httpSampler.setMethod("GET");
// Loop Controller
LoopController loopController = new LoopController();
loopController.setLoops(1);
loopController.addTestElement(httpSampler);
loopController.setFirst(true);
loopController.initialize();
// Thread Group
SetupThreadGroup threadGroup = new SetupThreadGroup();
threadGroup.setNumThreads(2);
threadGroup.setRampUp(1);
threadGroup.setSamplerController(loopController);
// Test plan
TestPlan testPlan = new TestPlan("MY TEST SUITE");
// Construct Test Plan from previously initialized elements
hashTree.add("testPlan", testPlan);
hashTree.add("loopController", loopController);
hashTree.add("threadGroup", threadGroup);
hashTree.add("httpSampler", httpSampler);
jm.configure(hashTree);
jm.run();
}
}
谁能帮我找出这里的 missing/wrong 是什么,因为这段代码没有按预期发出请求?
------------编辑------------
使用 Summariser
我得到以下输出:
summary = 0 in 00:00:00 = ******/s Avg: 0 Min:
9223372036854775807 Max: -9223372036854775808 Err: 0 (0,00%)
我认为这意味着没有像我怀疑的那样提出请求。
您构建的测试计划有点错误,您需要使用以下代码:
hashTree.add(testPlan);
HashTree threadGroupHashTree = hashTree.add(testPlan, threadGroup);
threadGroupHashTree.add(httpSampler);
除此之外,一切看起来都差不多。
参考文献:
你也可以看看jmeter-from-code demo project to see how to build an example Test Plan using JMeter API
我的 localhost:8181 上有一个 Spring 引导服务器 运行,我可以成功地向它发出 GET 请求,并且我看到打印出来的日志。
现在我做了一个负载测试的概念验证。我正在使用 JMeter Java API 使用来自 JMeter 的 Java API 向 Spring 引导服务器发送请求。 JMeter 运行测试套件并且没有错误报告但是在我的服务器上我没有传入请求。
这是我使用的负载测试代码:
public class Main {
public static void main(String... args) {
// Engine
StandardJMeterEngine jm = new StandardJMeterEngine();
JMeterUtils.setJMeterHome("C:\Users\daz\Desktop\apache-jmeter-3.2");
// jmeter.properties
String jmeterProperties = Main.class.getClassLoader().getResource("jmeter.properties").toString().replace("file:", "");
JMeterUtils.loadJMeterProperties(jmeterProperties);
HashTree hashTree = new HashTree();
// HTTP Sampler
HTTPSampler httpSampler = new HTTPSampler();
httpSampler.setDomain("localhost");
httpSampler.setPort(8181);
httpSampler.setPath("/job/test");
httpSampler.setMethod("GET");
// Loop Controller
LoopController loopController = new LoopController();
loopController.setLoops(1);
loopController.addTestElement(httpSampler);
loopController.setFirst(true);
loopController.initialize();
// Thread Group
SetupThreadGroup threadGroup = new SetupThreadGroup();
threadGroup.setNumThreads(2);
threadGroup.setRampUp(1);
threadGroup.setSamplerController(loopController);
// Test plan
TestPlan testPlan = new TestPlan("MY TEST SUITE");
// Construct Test Plan from previously initialized elements
hashTree.add("testPlan", testPlan);
hashTree.add("loopController", loopController);
hashTree.add("threadGroup", threadGroup);
hashTree.add("httpSampler", httpSampler);
jm.configure(hashTree);
jm.run();
}
}
谁能帮我找出这里的 missing/wrong 是什么,因为这段代码没有按预期发出请求?
------------编辑------------
使用 Summariser
我得到以下输出:
summary = 0 in 00:00:00 = ******/s Avg: 0 Min: 9223372036854775807 Max: -9223372036854775808 Err: 0 (0,00%)
我认为这意味着没有像我怀疑的那样提出请求。
您构建的测试计划有点错误,您需要使用以下代码:
hashTree.add(testPlan);
HashTree threadGroupHashTree = hashTree.add(testPlan, threadGroup);
threadGroupHashTree.add(httpSampler);
除此之外,一切看起来都差不多。
参考文献:
你也可以看看jmeter-from-code demo project to see how to build an example Test Plan using JMeter API