我试图从一个groovy脚本中获取12:00 am GMT的时间戳,并使用下面的代码将其转换为Epoc计时器:
use(groovy.time.TimeCategory) {
daytime = new Date()
daytime.set(hourOfDay: 0, minute: 0, second: 0)
time=daytime.getTime()
log.info(time)
}
当我在groovy Editor online上运行这段代码时,我得到了预期的响应-1554249600472
当我在Jmeter中使用JSR 223采样器运行相同的脚本时,我得到以下错误响应
2019-04-03 10:54:06,597 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.use() is applicable for argument types: (java.lang.Class, Script20$_run_closure1) values: [class groovy.time.TimeCategory, Script20$_run_closure1@6aaee2b9]
Possible solutions: use(java.lang.Class, groovy.lang.Closure), use(java.util.List, groovy.lang.Closure), use([Ljava.lang.Object;), grep(), any(), dump()
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:324) ~[groovy-all-2.4.15.jar:2.4.15]
at org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:72) ~[groovy-all-2.4.15.jar:2.4.15]
at javax.script.CompiledScript.eval(Unknown Source) ~[?:1.8.0_201]
at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:221) ~[ApacheJMeter_core.jar:5.0 r1840935]
at org.apache.jmeter.modifiers.JSR223PreProcessor.process(JSR223PreProcessor.java:44) [ApacheJMeter_components.jar:5.0 r1840935]
at org.apache.jmeter.threads.JMeterThread.runPreProcessors(JMeterThread.java:935) [ApacheJMeter_core.jar:5.0 r1840935]
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:537) [ApacheJMeter_core.jar:5.0 r1840935]
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:486) [ApacheJMeter_core.jar:5.0 r1840935]
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:253) [ApacheJMeter_core.jar:5.0 r1840935]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_201]
Caused by: groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.use() is applicable for argument types: (java.lang.Class, Script20$_run_closure1) values: [class groovy.time.TimeCategory, Script20$_run_closure1@6aaee2b9]
Possible solutions: use(java.lang.Class, groovy.lang.Closure), use(java.util.List, groovy.lang.Closure), use([Ljava.lang.Object;), grep(), any(), dump()
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.callGlobal(GroovyScriptEngineImpl.java:403) ~[groovy-all-2.4.15.jar:2.4.15]
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.access$100(GroovyScriptEngineImpl.java:94) ~[groovy-all-2.4.15.jar:2.4.15]
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl$3.invokeMethod(GroovyScriptEngineImpl.java:307) ~[groovy-all-2.4.15.jar:2.4.15]
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:68) ~[groovy-all-2.4.15.jar:2.4.15]
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:51) ~[groovy-all-2.4.15.jar:2.4.15]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:157) ~[groovy-all-2.4.15.jar:2.4.15]
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:177) ~[groovy-all-2.4.15.jar:2.4.15]
at Script20.run(Script20.groovy:1) ~[?:?]
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:321) ~[groovy-all-2.4.15.jar:2.4.15]
... 9 more
2条答案
按热度按时间nhjlsmyf1#
我不知道为什么
use
不适合你(可能是groovy版本或其他版本)但是您不需要它来清除时间:
8xiog9wr2#
谢谢你,人们,为您的善良和快速的React,排版的输出工作。下面是给我成功响应的代码片段