我有以下Jmeter测试计划
Thread Group
-Java Request
-CSV Data set config(Sharing mode :current thread group)
View Results Tree
Java Request具有一次处理N个值的代码。 CSV文件中的每个值只能使用一次。 例如,如果
no of entries in CSV file: 1000
threads : 10
loop count :10
N=entries to process in each iteration =10[calculated as :(no of entries in CSV)/(threads)/(loop count)]
因此,在每次迭代中,每个线程必须一次获取10个条目并将其传递给Java Request。
我有以下问题:
答案 0 :(得分:0)
按如下方式修改您的测试计划:
在Beanshell Sampler中,您需要放置自定义代码,该代码将从CSV数据集配置中读取值并将其添加到JMeter变量,如:
var1=foo
var2=bar
...
var10=something
因此,您可以将这10个变量作为${var1}
,${var2}
等传递给Java Request Sampler。
有关脚本的信息,请参阅How to use BeanShell: JMeter's favorite built-in component指南。
伪代码看起来像:
String postfix = vars.get("POSTFIX"); // where POSTFIX is Reference name of Counter
String value = vars.get("VALUE"); // where VALUE is the Variable Name defined in CSV Data Set
vars.put("var" + postfix, value); // put current value read form CSV file into varX JMeter Variable
答案 1 :(得分:0)
我修改了上面提到的测试计划,并使用Beanshell Sampler中的以下代码将一个变量发送到Java Sampler -
String postfix = vars.get("POSTFIX"); // where POSTFIX is Reference name of Counter
String value = vars.get("VALUE"); // where VALUE is the Variable Name defined in CSV Data Set
vars.put("var" + postfix, value); // put current value read form CSV file into varX JMeter Variable
// all the 10 values are concatenated to the input variable ,and is the single variable sent to the Java Sampler
if(postfix.equals("1"))
vars.put("input",vars.get("var"+postfix));
else
vars.put("input",vars.get("input")+","+vars.get("var"+postfix));