我想问一下是否有办法通过代码而不是通过 GUI 创建 JMeter 的 JDBC 连接配置实例。
我有以下线程组:
SetupThreadGroup threadGroup = new SetupThreadGroup();
threadGroup.setNumThreads(jMeterParam.getNumOfConnections());
threadGroup.setRampUp(0);
threadGroup.setDuration(7200);
JDBCSampler sampler = new JDBCSampler();
sampler.setQuery("select top 1 * from Production.ProductPhoto;");
sampler.setVariableNames("firstPrfile");
sampler.setQueryType("Select Statement");
ConstantTimer timer = new ConstantTimer();
timer.setDelay("300");
我需要创建 JDBCConnectionConfiguration 实例,以便在 JDBC Connection Configuration JMeter GUI 中设置 JMeter 变量名称、最大连接数、池超时和所有可用参数。
我需要编写 java 代码以配置测试计划并通过 JMeter 运行它的问题。我已经尝试过您的建议来创建 JDBC 连接,如下所示:
SetupThreadGroup threadGroup = new SetupThreadGroup();
threadGroup.setNumThreads(jMeterParam.getNumOfConnections());
threadGroup.setRampUp(0);
threadGroup.setDuration(7200);
DefaultPoolController defaultPoolController = new DefaultPoolController();
JdbcConnectionFactory jdbcFactory = new JdbcConnectionFactory("jdbc:sqlserver://10.10.10.171:1401;databaseName=AdventureWorks","sa","1q@W3e4r",true,"True","com.microsoft.sqlserver.jdbc.SQLServerDriver");
JdbcConnectionPool jdbcConnPool= new JdbcConnectionPool(jdbcFactory,defaultPoolController,0,10,true);
JDBCSampler sampler = new JDBCSampler();
sampler.setQuery("select top 1 * from Production.ProductPhoto;");
sampler.setVariableNames("firstPrfile");
sampler.setQueryType("Select Statement");
ConstantTimer timer = new ConstantTimer();
timer.setDelay("300");
sampler.addTestElement(timer);
// Test plan
TestPlan testPlan = new TestPlan("MY TEST PLAN");
hashTree.add("testPlan", testPlan);
hashTree.add("threadGroup", threadGroup);
hashTree.add("JDBC Connection Configuration", jdbcConnPool);
hashTree.add("sampler", sampler);
jm.configure(hashTree);
jm.run();
运行 WARN MSG 时显示:1)“加载 bean 类 org.apache.jmeter.protocol.jdbc.sampler.JDBCSampler 的 bean 信息时发生了一些错误”2)没有找到“.....ApacheJMeter.jar/commons- io-2.2.jar/等....
你知道如何解决吗?
非常感谢, 希洛