我有JSR233侦听器,它在JMeter非GUI模式下似乎被忽略了 [英] I have JSR233 listener which seems to be ignored in JMeter non-gui mode
问题描述
我在HTTP请求下有JSR233侦听器,它存储所有响应时间值,创建数组,然后对数组进行排序以找到90%的行,然后如果最后90%的行阈值为,则标记最后一个事务/请求通过或失败到达. 一切在GUI中都可以完美运行,但是我正在使用Docker Image在Gitlab CI中运行此测试,看起来这个JSR233脚本在10次中被忽略了8次,但在这里也可以正常工作2次. 真的很困惑 它在Windows控制台JMeter non-gui中的行为也很奇怪,可能被忽略了
I have JSR233 listener under HTTP Request, it stores all the response time values, creates array and then sort the array to find 90% line and then marks the last transaction/Request Pass or Fail if the final 90% Line threshold is reached. Everything works perfect in GUI but I am running this test in Gitlab CI using Docker Image and it looks like this JSR233 script get ignored 8 out of 10 times but 2 times it works fine there as well. Really confused It behaves weird in windows console JMeter non-gui too, it gets ignored may be
String requests = props.get("requests");
long requestsSum = 0;
if (requests != null) {
requestsSum = Long.parseLong(props.get("requests"));
}
long thisRequest = sampleResult.getTime();
requestsSum++;
props.put("requests", String.valueOf(requestsSum));
props.put("rt"+String.valueOf(requestsSum), String.valueOf(thisRequest));
if ( requestsSum > 4 ) {
ArrayList strList = new ArrayList();
for (int i=1;i<6; i++){
strList.add(Integer.parseInt(props.get("rt"+String.valueOf(i))));
}
vars.putObject("ArrayListBeforeSorting",strList);
Collections.sort(strList);
vars.putObject("ArrayListAfterSorting",strList);
String HID = vars.get("ArrayListAfterSorting"); String[] words = HID.split(",");
log.info("ninetypercent line is: " + words[3]);
vars.put("NPL" , words[3]);
int ninetypercentline = Integer.parseInt(words[3].trim());
if ( ninetypercentline > 100 ) {
sampleResult.setSuccessful(false);
sampleResult.setResponseMessage("ninety percent line is reached");
}
}
推荐答案
JMeter不会忽略"任何内容,您可以通过以下方式自行检查:
JMeter doesn't "ignore" anything, you can double check it youself by:
-
将 __counter()函数放入参数"您的JSR223侦听器的字段,例如:
Putting __counter() function into the "Parameters" field of your JSR223 Listener like:
${__counter(FALSE,)}
将此行添加为脚本的第一行:
Adding this line as the first line of your script:
println('Executing listener #' + ((Parameters as int) -1))
您应该在 stdout 中看到以下输出:>
You should see the following output in the stdout:
Executing listener #1
Executing listener #2
Executing listener #3
Executing listener #4
Executing listener #5
Executing listener #6
Executing listener #7
Executing listener #8
Executing listener #9
Executing listener #10
这意味着侦听器已执行了10次(实际顺序可能会有所不同,具体取决于您的
which means that the listener has been executed 10 times (the actual order may be different depending on your ramp-up settings)
关于代码本身,请注意,如果您有> 1个虚拟用户,则由于 全局
With regards to your code itself, be aware that if you have > 1 virtual user your so called "code" will either fail or produce invalid results due to the race condition as these requests
, and rt*
values are global
属性与变量不同.变量是线程本地的;属性是所有线程共有的
Properties are not the same as variables. Variables are local to a thread; properties are common to all threads
这篇关于我有JSR233侦听器,它在JMeter非GUI模式下似乎被忽略了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!