JSR223中的JRuby语言找不到JMeter预定义变量

JRuby language in JSR223 failed to find JMeter predefined variables

我正在尝试用 jruby 语言执行 JSR223

如果我输入普通字符串,它可以工作,但我不能将 JMeter 预定义变量用作 log

log.info("Hello from JRuby");

将无法找到 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) ~[?:?]

我在 jruby wiki on JSR 示例中找到前缀为 @variableName

的变量

engine.put("@name", "cherry blossom");

但是对于 @log 我得到了不同的错误(因为它 Nil/Null)

javax.script.ScriptException: org.jruby.embed.EvalFailedException: (NoMethodError) undefined method信息' nil:NilClass`

JMeter 的 JSR223 里面的 jruby 能不能克服还是我不能运行?

JRuby 实际上可以使用 $ 前缀找到预定义变量:

$log.info("Hello from JRuby");