【问题标题】:Jmeter Create JDBC Connection Configuration instance in java codeJmeter在java代码中创建JDBC连接配置实例
【发布时间】:2013-10-29 16:50:48
【问题描述】:

我想问一下是否有办法通过代码而不是通过 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/etc ....

你知道怎么解决吗?

非常感谢, 希洛

【问题讨论】:

    标签: java jdbc jmeter


    【解决方案1】:

    我个人通过 JMeter GUI 创建测试,不直接使用 JMeter API。但考虑到您的问题,我认为您可以创建 JDBC 连接并执行所需的查询,而无需实例化 JDBC 采样器。或者您可以创建 BSF 采样器并在其主体中设置连接和查询。我做了第二种方法(虽然我使用了 GUI):创建 BSF Sampler,连接到 DB 并执行查询,然后使用 Groovy 操作数据。

    【讨论】:

      猜你喜欢
      • 2014-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-25
      • 1970-01-01
      • 2016-01-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多