Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Performance RandomUtils.nextLong(10L,1000L)失败,并带有;意外标记:10L“;在JMeterHTTP请求主体中_Performance_Groovy_Jmeter_Apache Commons - Fatal编程技术网

Performance RandomUtils.nextLong(10L,1000L)失败,并带有;意外标记:10L“;在JMeterHTTP请求主体中

Performance RandomUtils.nextLong(10L,1000L)失败,并带有;意外标记:10L“;在JMeterHTTP请求主体中,performance,groovy,jmeter,apache-commons,Performance,Groovy,Jmeter,Apache Commons,我必须在一个HTTP请求正文数据中传递一个随机长值 我使用的代码是“${groovy(import org.apache.commons.lang3.RandomUtils;RandomUtils.nextLong(10L,1000L);)}” 我在用于groovy的JSR223预处理器中尝试了相关的groovy代码,它正确地打印出了数字 long rand = org.apache.commons.lang3.RandomUtils.nextLong(2000, 10000); log.inf

我必须在一个HTTP请求正文数据中传递一个随机长值

我使用的代码是“${groovy(import org.apache.commons.lang3.RandomUtils;RandomUtils.nextLong(10L,1000L);)}”

我在用于groovy的JSR223预处理器中尝试了相关的groovy代码,它正确地打印出了数字

long rand = org.apache.commons.lang3.RandomUtils.nextLong(2000, 10000);
log.info("random   [" + rand + "]");
但是,当我在HTTP请求体中的_groovy()中使用相同的代码时,它会失败

2020-03-06 09:50:57,821 INFO o.a.j.m.J.JSR223 PreProcessor: random   [4023]
2020-03-06 09:50:57,827 WARN o.a.j.f.Groovy: Error running groovy script
javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script358.groovy: 1: unexpected token: 10L @ line 1, column 66.
   domUtils;RandomUtils.nextLong(10L
                                 ^

1 error

    at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:162) ~[groovy-all-2.4.16.jar:2.4.16]
    at javax.script.AbstractScriptEngine.eval(Unknown Source) ~[?:1.8.0_221]
    at org.apache.jmeter.functions.Groovy.execute(Groovy.java:121) [ApacheJMeter_functions.jar:5.1.1 r1855137]
    at org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:136) [ApacheJMeter_core.jar:5.1.1 r1855137]
    at org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:111) [ApacheJMeter_core.jar:5.1.1 r1855137]
    at org.apache.jmeter.testelement.property.FunctionProperty.getStringValue(FunctionProperty.java:101) [ApacheJMeter_core.jar:5.1.1 r1855137]
    at org.apache.jmeter.testelement.AbstractTestElement.getPropertyAsString(AbstractTestElement.java:281) [ApacheJMeter_core.jar:5.1.1 r1855137]
    at org.apache.jmeter.config.Argument.getValue(Argument.java:146) [ApacheJMeter_core.jar:5.1.1 r1855137]
    at org.apache.jmeter.protocol.http.util.HTTPArgument.getEncodedValue(HTTPArgument.java:248) [ApacheJMeter_http.jar:5.1.1 r1855137]
    at org.apache.jmeter.protocol.http.util.HTTPArgument.getEncodedValue(HTTPArgument.java:229) [ApacheJMeter_http.jar:5.1.1 r1855137]
    at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.setupHttpEntityEnclosingRequestData(HTTPHC4Impl.java:1529) [ApacheJMeter_http.jar:5.1.1 r1855137]
    at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.handleMethod(HTTPHC4Impl.java:794) [ApacheJMeter_http.jar:5.1.1 r1855137]
    at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sample(HTTPHC4Impl.java:569) [ApacheJMeter_http.jar:5.1.1 r1855137]
    at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:67) [ApacheJMeter_http.jar:5.1.1 r1855137]
    at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1231) [ApacheJMeter_http.jar:5.1.1 r1855137]
    at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1220) [ApacheJMeter_http.jar:5.1.1 r1855137]
    at org.apache.jmeter.threads.JMeterThread.doSampling(JMeterThread.java:622) [ApacheJMeter_core.jar:5.1.1 r1855137]
    at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:546) [ApacheJMeter_core.jar:5.1.1 r1855137]
    at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:486) [ApacheJMeter_core.jar:5.1.1 r1855137]
    at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:253) [ApacheJMeter_core.jar:5.1.1 r1855137]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_221]
我可以看到,我可以让其他groovy脚本,比如“${uuu groovy(new Date().format(“yyy-MM-dd'HH:MM:ss.SSS'Z”)}”在HTTP请求体数据中正常工作

我错过了什么

更新:我还尝试了不带“L”的代码,甚至
RandomUtils.nextLong(101000)相同的异常。

本身包含逗号的参数值应根据需要进行转义。如果需要在参数值中包含逗号,请按如下方式对其进行转义:
\,

所以,应该是这样的:


groovy(org.apache.commons.lang3.RandomUtils.nextLong(10\,1000))

您需要像以下那样转义逗号:

${__groovy(return org.apache.commons.lang3.RandomUtils.nextLong(10\, 1000),)}

下次考虑使用以获得JMIT函数的正确语法。 一般来说,建议使用JMIT的内置测试元素和/或函数,避免在可能的情况下编写脚本,因此考虑使用,相关语法将是:

${__Random(10,1000,)}
如果提供第三个参数,JMeter将在变量中存储生成的值


更多信息:

也尝试过<代码>2020-03-06 11:03:29855信息o.a.j.m.j.JSR223预处理器:随机[3387]2020-03-06 11:03:29861警告o.a.j.f.Groovy:运行Groovy脚本javax.script.ScriptException时出错:org.codehaus.Groovy.control.multipleCompationerrorsException:启动失败:Script362.Groovy:1:意外标记:10@line 1,第66列。多穆蒂尔斯;RandomUtils.nextLong(10^
。与我在HTTP请求正文中使用的groovy代码相同,${\uu groovy(import org.apache.commons.lang3.RandomUtils;RandomUtils.nextLong(101000);)}“