Added Kotlin JSR223 support to JMeter and execute script using Kotlin language
It ignores JMeter bindings parameters, as String type Parameters
, Tried:
println(Parameters)
Receive unresolved error:
javax.script.ScriptException: Error: Unresolved reference: Parameters
at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.compile(KotlinJsr223JvmScriptEngineBase.kt:74) ~[kotlin-compiler.jar:1.3.50-release-112]
at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.compile(KotlinJsr223JvmScriptEngineBase.kt:35) ~[kotlin-compiler.jar:1.3.50-release-112]
at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:217) ~[ApacheJMeter_core.jar:5.1.1 r1855137]
at org.apache.jmeter.protocol.java.sampler.JSR223Sampler.sample(JSR223Sampler.java:71) [ApacheJMeter_java.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_191]
I tried using $
:
println($Parameters)
Ambiguity error
2019-11-11 08:56:21,803 ERROR o.a.j.p.j.s.JSR223Sampler: Problem in JSR223 script JSR223 Sampler, message: javax.script.ScriptException: Error: Overload resolution ambiguity:
@InlineOnly public inline fun println(message: Any?): Unit defined in kotlin.io
@InlineOnly public inline fun println(message: Boolean): Unit defined in kotlin.io
@InlineOnly public inline fun println(message: Byte): Unit defined in kotlin.io
@InlineOnly public inline fun println(message: Char): Unit defined in kotlin.io
@InlineOnly public inline fun println(message: CharArray): Unit defined in kotlin.io
@InlineOnly public inline fun println(message: Double): Unit defined in kotlin.io
@InlineOnly public inline fun println(message: Float): Unit defined in kotlin.io
@InlineOnly public inline fun println(message: Int): Unit defined in kotlin.io
@InlineOnly public inline fun println(message: Long): Unit defined in kotlin.io
@InlineOnly public inline fun println(message: Short): Unit defined in kotlin.io
javax.script.ScriptException: Error: Overload resolution ambiguity:
@InlineOnly public inline fun println(message: Any?): Unit defined in kotlin.io
@InlineOnly public inline fun println(message: Boolean): Unit defined in kotlin.io
@InlineOnly public inline fun println(message: Byte): Unit defined in kotlin.io
@InlineOnly public inline fun println(message: Char): Unit defined in kotlin.io
@InlineOnly public inline fun println(message: CharArray): Unit defined in kotlin.io
@InlineOnly public inline fun println(message: Double): Unit defined in kotlin.io
@InlineOnly public inline fun println(message: Float): Unit defined in kotlin.io
@InlineOnly public inline fun println(message: Int): Unit defined in kotlin.io
@InlineOnly public inline fun println(message: Long): Unit defined in kotlin.io
@InlineOnly public inline fun println(message: Short): Unit defined in kotlin.io
at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.compile(KotlinJsr223JvmScriptEngineBase.kt:74) ~[kotlin-compiler.jar:1.3.50-release-112]
at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.compile(KotlinJsr223JvmScriptEngineBase.kt:35) ~[kotlin-compiler.jar:1.3.50-release-112]
at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:217) ~[ApacheJMeter_core.jar:5.1.1 r1855137]
at org.apache.jmeter.protocol.java.sampler.JSR223Sampler.sample(JSR223Sampler.java:71) [ApacheJMeter_java.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_191]
It failed also using [bindings][1] as
println(bindings["ctx"])
Similar error:
javax.script.ScriptException: Error: Unresolved reference: bindings
I tried also adding importAllBindings, but with same results
importAllBindings(true)
JMeter's bindings code:
Bindings bindings = engine.createBindings(); bindings.put("Parameters", scriptParameters); ... CompiledScript compiledScript = compiledScriptsCache.get(newCacheKey); ... compiledScript.eval(bindings)
If not using compiled script, error is similar
javax.script.ScriptException: Unresolved reference: Parameters
at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.asJsr223EvalResult(KotlinJsr223JvmScriptEngineBase.kt:104) ~[kotlin-compiler-embeddable-1.3.50.jar:1.3.50-release-112 (1.3.50)]
at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.compileAndEval(KotlinJsr223JvmScriptEngineBase.kt:63) ~[kotlin-compiler-embeddable-1.3.50.jar:1.3.50-release-112 (1.3.50)]
at kotlin.script.experimental.jvmhost.jsr223.KotlinJsr223ScriptEngineImpl.compileAndEval(KotlinJsr223ScriptEngineImpl.kt:82) ~[kotlin-main-kts.jar:1.3.50-release-112]
at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.eval(KotlinJsr223JvmScriptEngineBase.kt:31) ~[kotlin-compiler-embeddable-1.3.50.jar:1.3.50-release-112 (1.3.50)]
at javax.script.AbstractScriptEngine.eval(Unknown Source) ~[?:1.8.0_191]
at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:225) ~[ApacheJMeter_core.jar:5.1.1 r1855137]
There's similar issue when using Scala with JSR223
bindings parameters can't be used when using Scala engine (in other engines as beanshell,groovy,velocity,... it works)
Open an issue KT-35113 Failed bind parameters using JSR223 with Kotlin