Jmeter:捕获全局变量中的JDBC值 [英] Jmeter: Capture JDBC value in global variable
问题描述
我对Jmeter非常陌生,我想知道是否有方法将查询的结果存储在全局变量中,以便在不同的线程中使用。
换句话说,我需要一个设置线程来设置数据库的开始日期和结束日期(2个值)。
然后,在第二个线程(主线程)中,我必须使用开始日期和结束日期作为测试的参数。
是这可能吗?
在此先感谢!,
Nahuel
使用以下元素:
将它们组织为foll由于:
它的工作方式如下:
-
JDBC连接配置将设置连接到数据库,名称变量名称,以便它与变量JDBC Request的名称,在我的例子中,我将它命名为 conn
-
Setup Thread Group将通过JDBC Request运行查询并将结果存储在变量
-
Beanshell采样器使用该值并将其存储为属性,以便它可以被所有线程共享。
请注意以下几点: 变量名称JDBC请求必须匹配你的SQL查询返回的列数,注意在例子中,我有3列,我把3个变量,并将使用clt_nom_1名称,因为我确保只有查询返回行 在Bean Shell采样器中,我输入以下代码: clt_nom_1被命名为这是因为它是第一行值 最后在线程组中,我可以使用属性toto: 您还可以通过调试采样器替换BeanShell采样器: 可以将变量存储在属性中 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. 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. Is this possible? Thanks in advance!,
Nahuel Use the following elements: Organize them as following:
It will work as following: JDBC Connection Configuration will setup the connection to DB, name Variable name so that it matches Variable name of JDBC Request, in my case I name it conn Setup Thread Group will run query through JDBC Request and store result in variables Beanshell sampler with use the value and store it as a property so it can be shared by all threads. Note the following: 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 In Bean Shell sampler I put the following code: clt_nom_1 is named like this because it's the first row value Finally in Thread Group I can use property toto through: You could also replace BeanShell sampler by a debug sampler named: which would store variable in property 这篇关于Jmeter:捕获全局变量中的JDBC值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
props.pu吨( TOTO,vars.get( clt_nom_1));
$ {__ P
$ {__ setProperty(toto,$ {clt_nom_1})};
props.put("toto",vars.get("clt_nom_1"));
${__P(toto)}
${__setProperty(toto,${clt_nom_1})};