Reputation: 3427
I am using JMeter to run query load tests against an Elasticsearch cluster. I have a csv file of 100 names that I am iterating through to populate the ES query with a different search term on each call.
The column in the csv file is called name
, so in the JMeter HTTP request, the query in the Body Data looks like this:
{
"query": {
"match": {
"search_name": "${name}"
}
}
}
And to iterate through the csv file to get the names, I have a JSR223 PreProcessor as a child of the HTTP request as such:
upto(1, {
if (vars.get('param' + "$it") != null) {
sampler.addArgument(vars.get('param' + "$it"),'name')
}
})
then a JSR223 PostProcessor as such:
upto(1, {
vars.remove("param" + "$it")
})
I came up with this approach by reading the accepted answer at this thread: How to make the search parameters in http request as dynamic in jmeter and adjusting as I saw fit.
The processing code is doing what it's supposed to be doing as far as correctly populating the queries, and all HTTP Requests are successful. However, every call is also throwing an error in the Jmeter log at both the PreProcessor and PostProcessor step:
ERROR o.a.j.m.JSR223PreProcessor: Problem in JSR223 script, JSR223 PreProcessor
javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.upto() is applicable for argument types: (Integer, Script1$_run_closure1) values: [1, Script1$_run_closure1@7c7ff704]
Possible solutions: put(java.lang.String, java.lang.Object), wait(), grep(), any(), dump(), find()
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:320) ~[groovy-jsr223-3.0.11.jar:3.0.11]
at org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:71) ~[groovy-jsr223-3.0.11.jar:3.0.11]
at javax.script.CompiledScript.eval(CompiledScript.java:93) ~[java.scripting:?]
at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:217) ~[ApacheJMeter_core.jar:5.5]
at org.apache.jmeter.modifiers.JSR223PreProcessor.process(JSR223PreProcessor.java:45) ~[ApacheJMeter_components.jar:5.5]
at org.apache.jmeter.threads.JMeterThread.runPreProcessors(JMeterThread.java:978) ~[ApacheJMeter_core.jar:5.5]
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:561) ~[ApacheJMeter_core.jar:5.5]
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:501) ~[ApacheJMeter_core.jar:5.5]
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:268) ~[ApacheJMeter_core.jar:5.5]
at java.lang.Thread.run(Thread.java:833) ~[?:?]
Caused by: groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.upto() is applicable for argument types: (Integer, Script1$_run_closure1) values: [1, Script1$_run_closure1@7c7ff704]
Possible solutions: put(java.lang.String, java.lang.Object), wait(), grep(), any(), dump(), find()
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.callGlobal(GroovyScriptEngineImpl.java:404) ~[groovy-jsr223-3.0.11.jar:3.0.11]
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.access$100(GroovyScriptEngineImpl.java:90) ~[groovy-jsr223-3.0.11.jar:3.0.11]
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl$3.invokeMethod(GroovyScriptEngineImpl.java:303) ~[groovy-jsr223-3.0.11.jar:3.0.11]
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:73) ~[groovy-3.0.11.jar:3.0.11]
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:51) ~[groovy-3.0.11.jar:3.0.11]
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:83) ~[groovy-3.0.11.jar:3.0.11]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:194) ~[groovy-3.0.11.jar:3.0.11]
at Script1.run(Script1.groovy:1) ~[?:?]
at org.codehaus.groovy.jsr223.GroovyScrip
tEngineImpl.eval(GroovyScriptEngineImpl.java:317) ~[groovy-jsr223-3.0.11.jar:3.0.11]
In the interest of saving space, I won't paste the PostProcessor code, which is virtually identical.
I am not well-versed in groovy at all, and again, I did my best to adapt the pre and post processor code from the other thread. Even though everything appears to be working, I'd like to resolve this error b/c I can't imagine I have a clean test going with all these errors thrown.
Upvotes: 0
Views: 199
Reputation: 168002
The error you're getting means syntax error, you cannot call upto() function per se, according to its JavaDoc:
Iterates from this number up to the given number, inclusive, incrementing by one each time.
So I think you need to amend it to look like:
0.upto(1, {
if (vars.get('param' + "$it") != null) {
sampler.addArgument(vars.get('param' + "$it"),'name')
}
})
the Post-Processor can be just removed.
More information on Groovy scripting in JMeter: Apache Groovy: What Is Groovy Used For?
Groovy has its own very comprehensive documentation: https://groovy-lang.org/documentation.html#gettingstarted
Upvotes: 1