JSR223中的Jruby语言未能找到Jmeter预定义变量



我正在尝试用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中在JSR示例中找到了带有前缀为 @variableName

的变量

Engine.put("@name","樱花"(;

但是,对于@log,我会有不同的错误(因为nil/null(

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

可以克服它,还是我不能在Jmeter的JSR223中运行Jruby?

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

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

相关内容

  • 没有找到相关文章

最新更新