I'm trying to execute JSR223 with jruby language
If I put normal String it works, but I can't use JMeter predefined variables as log
log.info("Hello from JRuby");
Will failed to find log
:
2019-07-11 17:27:30,078 ERROR o.a.j.p.j.s.JSR223Sampler: Problem in JSR223 script JSR223 Sampler, message: javax.script.ScriptException: org.jruby.embed.EvalFailedException: (NameError) undefined local variable or method `log' for main:Object
javax.script.ScriptException: org.jruby.embed.EvalFailedException: (NameError) undefined local variable or method `log' for main:Object
at org.jruby.embed.jsr223.JRubyEngine.wrapException(JRubyEngine.java:104) ~[jruby-core-1.7.27.jar:?]
at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java:93) ~[jruby-core-1.7.27.jar:?]
at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java:133) ~[jruby-core-1.7.27.jar:?]
at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:225) ~[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]
Caused by: org.jruby.embed.EvalFailedException: (NameError) undefined local variable or method `log' for main:Object
at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java:132) ~[jruby-core-1.7.27.jar:?]
at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java:90) ~[jruby-core-1.7.27.jar:?]
... 8 more
Caused by: org.jruby.exceptions.RaiseException: (NameError) undefined local variable or method `log' for main:Object
at RUBY.(root)(<script>:1) ~[?:?]
I find in jruby wiki on JSR examples with variables with prefix as @variableName
engine.put("@name", "cherry blossom");
But for @log
I get different error (as it Nil/Null)
javax.script.ScriptException: org.jruby.embed.EvalFailedException: (NoMethodError) undefined method
info' for nil:NilClass`
Can it be overcome or I can't run jruby inside JMeter's JSR223?
JRuby actually can find the predefined variable using $
prefix:
$log.info("Hello from JRuby");