我的 localhost:8181 上运行着一个 Spring Boot 服务器,我可以成功地向它发出 GET 请求,并且我会看到打印出来的日志。
现在我为负载测试做了一个概念验证。我正在使用 JMeter Java API 通过 JMeter 的 Java API 向 Spring Boot 服务器发送请求。 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();
}
}
有人可以帮我找出这里缺少/错误的地方,因为此代码没有按预期发出请求吗?
-------------编辑-------------
使用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演示项目,了解如何使用 JMeter API 构建示例测试计划
关于java - JMeter java API - 负载测试运行但服务器上未收到请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44231942/