Jmeter:在全局变量中捕获 JDBC 值 [英] Jmeter: Capture JDBC value in global variable

查看:42
本文介绍了Jmeter:在全局变量中捕获 JDBC 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Jmeter 很陌生,我想知道是否有某种方法可以将查询结果存储在全局变量中以在不同的线程中使用.

I'm very new to Jmeter and I'd like to know if there is some way to store the result of a query in a global variable to use in a different thread.

换句话说,我需要一个设置线程来从数据库设置开始日期和结束日期(2 个值).然后,在第二个线程(主线程)中,我必须使用开始日期和结束日期作为测试的参数.

In other words, I need a set-up thread that sets a start-date and end-date (2 values) from the DB. Then, in a second thread (the main thread), I have to use the start-date and end-date as parameters for the tests.

这可能吗?

提前致谢!,纳韦尔

推荐答案

使用以下元素:

JDBC 请求

BeanShell 采样器

设置线程组

按以下方式组织它们:

它将如下工作:

  1. JDBC Connection Configuration 将建立到 DB 的连接,命名变量名以便它匹配 JDBC 请求的变量名,在我的例子中我将它命名为 conn

设置线程组将通过 JDBC 请求运行查询并将结果存储在变量中

Setup Thread Group will run query through JDBC Request and store result in variables

Beanshell 采样器使用该值并将其存储为属性,以便所有线程共享.

Beanshell sampler with use the value and store it as a property so it can be shared by all threads.

注意以下几点:

  • JDBC Request 的变量名称必须与您的 SQL 查询返回的列数相匹配,注意在示例中我有 3 列,我放置了 3 个变量,并且将使用 clt_nom_1 名称,因为我确保只返回行通过查询

  • The variable names of JDBC Request must match the number of columns returned by your SQL Query, note in example I have 3 columns, I put 3 variables, and will use clt_nom_1 name as I ensure there is only row returned by query

  • 在 Bean Shell 采样器中,我输入了以下代码:

  • In Bean Shell sampler I put the following code:

props.put("toto",vars.get("clt_nom_1"));

  • clt_nom_1 之所以这样命名是因为它是第一行值

  • clt_nom_1 is named like this because it's the first row value

    最后在线程组中,我可以通过以下方式使用属性 toto:

    Finally in Thread Group I can use property toto through:

    ${__P(toto)}
    

  • 你也可以用一个名为的调试采样器替换 BeanShell 采样器:

    You could also replace BeanShell sampler by a debug sampler named:

    ${__setProperty(toto,${clt_nom_1})};
    

    将变量存储在属性中

    这篇关于Jmeter:在全局变量中捕获 JDBC 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆