Jmeter - 无法将 属性 传递给 JDBC 连接器

Jmeter - can't pass property to JDBC connector

我有一个 setUp 线程组和一个 normal 线程组。 Jmeter 连续运行线程组。

在设置组中,我 select 来自数据库的用户名,然后我将其放入 属性 中,并使用 JSR223 采样器,如下所示:

import org.apache.jmeter.util.JMeterUtils;
JMeterUtils.setProperty("schemaProp", vars.get("schemaVar_1"));

在第二个线程中,我有一个 JDBC 连接器,它可以像这样访问 属性:

${__property(sshUserProp,)}

但是没用。

日志:

2021-12-16 08:54:58,802 DEBUG o.a.j.p.j.c.DataSourceElement: Driver: org.postgresql.Driver DbUrl: jdbc:postgresql://127.0.0.1:50539/JB7 User: sshUserProp

JDBC 连接器并没有真正看到 属性,尽管它实际上已设置,因为我可以使用另一个 JSR223 采样器访问它:

import org.apache.jmeter.util.JMeterUtils;
log.info ("------------------------- MESSAGE: " + JMeterUtils.getProperty("sshUserProp"))

日志:

2021-12-16 08:54:58,961 INFO o.a.j.p.j.s.J.JSR223 Sampler: ------------------------- MESSAGE: 160116

恐怕这是不可能的,至少在 JMeter 5.4.1 中不可能,调查 JDBC Connection Configuration source code the element is being set up in the testStarted() function and according to the JavaDoc

Called just before the start of the test from the main engine thread. This is before the test elements are cloned. Note that not all the test variables will have been set up at this point.

所以你需要先确定用户名某处,即通过运行另一个JMeter测试并通过[=将用户名保存到文件中13=] 会起作用。