我在整型JMeter Beanshell取樣器/前/後處理器中遇到問題。我有一些值的數組,我想使用這個數組的每個值來設置JMeterProperty以備下次使用。JMeter Beanshell整數錯誤
GOAL>查詢中有N行。例如UPSTREAM列有差異值,我需要它保存下一次使用。因爲我將使用它們通過「OS進程採樣器」將CMD.exe作爲參數調用。
So, if UPSTREAM_1=XXX, UPSTREAM_2=AAA,
CMD.EXE will looks like: CMD.EXE -upstream_1 -upstream_2, etc.
從SQL我有值的數組
COUNT=31
UPSTREAM_#=31
UPSTREAM_1=XXX
UPSTREAM_2=AAA
....
在PostProcessor中我設置:
${__setProperty(COUNT, ${COUNT_1})};
我想這scrpit:
import java.util.*;
import java.text.*;
import java.io.*;
int max = Integer.parseInt(vars.get(${COUNT_1})); //--COUNT=31, Integer doesnt work
int n = vars.get(${COUNT_1}); //--COUNT=31, this also doesnt work
for (int i=1;i<=n;i++)
{
${__setProperty(UPSTREAM_i, ${UPSTREAM_i})};
}
但是JMeter的日誌說,它不知道「INT」
2016/10/03 14:52:13 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: `` import java.util.*; import java.text.*; import java.io.*; int max = Integer.p . . . '' : Typed variable declaration : Error in method invocation: Method get(int) not found in class'org.apache.jmeter.threads.JMeterVariables'
2016/10/03 14:52:13 WARN - jmeter.protocol.java.sampler.BeanShellSampler: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: `` import java.util.*; import java.text.*; import java.io.*; int max = Integer.p . . . '' : Typed variable declaration : Error in method invocation: Method get(int) not found in class'org.apache.jmeter.threads.JMeterVariables'
有人可以幫我嗎?也許我想念一些庫或什麼。我有JRE/JDK。
UPDATE_1
用戶變量所有:
COUNT ${__property(COUNT)} Count of Rows from SQL Query
Test_Plan:
PostProcessor中登錄:
SamplerProperties:
variableNames=DATE,DOWNSTREAM,UPSTREAM,COUNT,etc.
JMeterVariables:
COUNT=31
COUNT_#=31
COUNT_1=31
COUNT_2=31
.....
DATE_#=31
DATE_1=04.10.2016
DATE_2=04.10.2016
.....
DOWNSTREAM_#=31
DOWNSTREAM_1=DDD11
DOWNSTREAM_2=DDD11
.....
UPSTREAM_#=31
UPSTREAM_1=XXX
UPSTREAM_2=AAA
....
JMeterProperties:
COUNT= 31
DATE= 04.10.2016
DOWNSTREAM= DDD11
TEST= 1
調試循環日誌:
SamplerProperties:
BeanShellSampler.query=import java.util.*;
import java.text.*;
import java.io.*;
int n = Integer.parseInt(vars.get("COUNT"));
for (int i=1;i<=n;i++)
{
props.setProperty("UPSTREAM_"+i, vars.get("UPSTREAM_i"));
}
JMeterVariables:
COUNT=31
COUNT_#=31
COUNT_1=31
COUNT_2=31
.....
DATE_#=31
DATE_1=04.10.2016
DATE_2=04.10.2016
.....
DOWNSTREAM_#=31
DOWNSTREAM_1=DDD11
DOWNSTREAM_2=DDD11
.....
UPSTREAM_#=31
UPSTREAM_1=XXX
UPSTREAM_2=AAA
....
JMeterProperties:
COUNT= 31
DATE= 04.10.2016
DOWNSTREAM= DDD11
TEST= 1
這是現在的JMeter日誌:
UPDATE_2
UBIK負載組的解決方案工程:),目標更新。
貝殼樣品仍然有一些問題..
Response code: 500 Response message: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval \t Sourced file: inline evaluation of: ''import java.util.*; import java.text.*; import java.io.*; int n = Integer.pa . . . '' : Typed variable declaration : Method Invocation Integer.parseInt
–你確定COUNT是真的被定義爲一個變量嗎?你可以展示你的測試計劃嗎?在Beanshell PostProcessor之前添加一個DebugPostProcessor並顯示輸出?thx –
沒有COUNT也來自SQL。但是當我在用戶定義變量COUNT = $ {__ property(COUNT)}中設置GLOBAL VAR時,它返回另一個錯誤int n = Integer.pa。 。 。 '':方法調用props.setProperty' –