Groovy脚本不在Jmeter下执行

Groovy脚本不在Jmeter下执行,groovy,jmeter,jsr223,Groovy,Jmeter,Jsr223,我在Jmeter下运行groovy脚本时遇到问题。有人能建议我是否需要启用/调整groovy要执行的东西吗 *Jmeter版本=5.2.1 Groovy=2.4.16/Groovy脚本引擎2.0 Jar=/lib/groovy-all-2.4.16.Jar* 我一直在遵循一个在线示例,所以我知道这个脚本应该可以工作 我已将以下脚本置于JSR223采样器下: import groovy.io.FileType String folderPath = "data-management&q

我在Jmeter下运行groovy脚本时遇到问题。有人能建议我是否需要启用/调整groovy要执行的东西吗

*Jmeter版本=5.2.1

Groovy=2.4.16/Groovy脚本引擎2.0

Jar=/lib/groovy-all-2.4.16.Jar*

我一直在遵循一个在线示例,所以我知道这个脚本应该可以工作

我已将以下脚本置于JSR223采样器下:

import groovy.io.FileType

String folderPath = "data-management"
new File(folderPath).eachfile (FileType.FILES) { file ->
    /* Delete file if file name contains .dat */
    if (file.name.contains('.dat')) file.delete()
}
Response code:500
Response message:javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: java.io.File.eachfile() is applicable for argument types: (groovy.io.FileType, Script2$_run_closure1) values: [FILES, Script2$_run_closure1@17b02a]
Possible solutions: eachFile(groovy.io.FileType, groovy.lang.Closure), eachFile(groovy.lang.Closure), eachLine(int, groovy.lang.Closure), eachLine(java.lang.String, groovy.lang.Closure), eachLine(groovy.lang.Closure), isFile()
2020-08-19 17:49:15,917 INFO o.a.j.t.JMeterThread: Thread started: tearDown Thread Group 1-1
2020-08-19 17:49:15,951 ERROR o.a.j.p.j.s.JSR223Sampler: **Problem in JSR223 script JSR223 Sampler**, message: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: java.io.File.eachfile() is applicable for argument types: (groovy.io.FileType, Script2$_run_closure1) values: [FILES, Script2$_run_closure1@17b02a]
Possible solutions: eachFile(groovy.io.FileType, groovy.lang.Closure), eachFile(groovy.lang.Closure), eachLine(int, groovy.lang.Closure), eachLine(java.lang.String, groovy.lang.Closure), eachLine(groovy.lang.Closure), isFile()
javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: java.io.File.eachfile() is applicable for argument types: (groovy.io.FileType, Script2$_run_closure1) values: [FILES, Script2$_run_closure1@17b02a]
Possible solutions: eachFile(groovy.io.FileType, groovy.lang.Closure), eachFile(groovy.lang.Closure), eachLine(int, groovy.lang.Closure), eachLine(java.lang.String, groovy.lang.Closure), eachLine(groovy.lang.Closure), isFile()
              at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:324) ~[groovy-all-2.4.16.jar:2.4.16]
              at org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:72) ~[groovy-all-2.4.16.jar:2.4.16]
              at javax.script.CompiledScript.eval(CompiledScript.java:92) ~[?:1.8.0_241]
              at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:223) ~[ApacheJMeter_core.jar:5.2.1]
              at org.apache.jmeter.protocol.java.sampler.JSR223Sampler.sample(JSR223Sampler.java:71) [ApacheJMeter_java.jar:5.2.1]
              at org.apache.jmeter.threads.JMeterThread.doSampling(JMeterThread.java:627) [ApacheJMeter_core.jar:5.2.1]
              at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:551) [ApacheJMeter_core.jar:5.2.1]
              at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:490) [ApacheJMeter_core.jar:5.2.1]
              at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:257) [ApacheJMeter_core.jar:5.2.1]
              at java.lang.Thread.run(Thread.java:748) [?:1.8.0_241]
Caused by: groovy.lang.MissingMethodException: No signature of method: java.io.File.eachfile() is applicable for argument types: (groovy.io.FileType, Script2$_run_closure1) values: [FILES, Script2$_run_closure1@17b02a]
Possible solutions: eachFile(groovy.io.FileType, groovy.lang.Closure), eachFile(groovy.lang.Closure), eachLine(int, groovy.lang.Closure), eachLine(java.lang.String, groovy.lang.Closure), eachLine(groovy.lang.Closure), isFile()
              at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:71) ~[groovy-all-2.4.16.jar:2.4.16]
              at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:48) ~[groovy-all-2.4.16.jar:2.4.16]
              at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) ~[groovy-all-2.4.16.jar:2.4.16]
              at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) ~[groovy-all-2.4.16.jar:2.4.16]
              at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:136) ~[groovy-all-2.4.16.jar:2.4.16]
              at Script2.run(Script2.groovy:4) ~[?:?]
              at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:321) ~[groovy-all-2.4.16.jar:2.4.16]
              ... 9 more
2020-08-19 17:49:15,955 INFO o.a.j.t.JMeterThread: Thread is done: tearDown Thread Group 1-1
2020-08-19 17:49:15,955 INFO o.a.j.t.JMeterThread: Thread finished: tearDown Thread Group 1-1
采样器结果给出:

import groovy.io.FileType

String folderPath = "data-management"
new File(folderPath).eachfile (FileType.FILES) { file ->
    /* Delete file if file name contains .dat */
    if (file.name.contains('.dat')) file.delete()
}
Response code:500
Response message:javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: java.io.File.eachfile() is applicable for argument types: (groovy.io.FileType, Script2$_run_closure1) values: [FILES, Script2$_run_closure1@17b02a]
Possible solutions: eachFile(groovy.io.FileType, groovy.lang.Closure), eachFile(groovy.lang.Closure), eachLine(int, groovy.lang.Closure), eachLine(java.lang.String, groovy.lang.Closure), eachLine(groovy.lang.Closure), isFile()
2020-08-19 17:49:15,917 INFO o.a.j.t.JMeterThread: Thread started: tearDown Thread Group 1-1
2020-08-19 17:49:15,951 ERROR o.a.j.p.j.s.JSR223Sampler: **Problem in JSR223 script JSR223 Sampler**, message: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: java.io.File.eachfile() is applicable for argument types: (groovy.io.FileType, Script2$_run_closure1) values: [FILES, Script2$_run_closure1@17b02a]
Possible solutions: eachFile(groovy.io.FileType, groovy.lang.Closure), eachFile(groovy.lang.Closure), eachLine(int, groovy.lang.Closure), eachLine(java.lang.String, groovy.lang.Closure), eachLine(groovy.lang.Closure), isFile()
javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: java.io.File.eachfile() is applicable for argument types: (groovy.io.FileType, Script2$_run_closure1) values: [FILES, Script2$_run_closure1@17b02a]
Possible solutions: eachFile(groovy.io.FileType, groovy.lang.Closure), eachFile(groovy.lang.Closure), eachLine(int, groovy.lang.Closure), eachLine(java.lang.String, groovy.lang.Closure), eachLine(groovy.lang.Closure), isFile()
              at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:324) ~[groovy-all-2.4.16.jar:2.4.16]
              at org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:72) ~[groovy-all-2.4.16.jar:2.4.16]
              at javax.script.CompiledScript.eval(CompiledScript.java:92) ~[?:1.8.0_241]
              at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:223) ~[ApacheJMeter_core.jar:5.2.1]
              at org.apache.jmeter.protocol.java.sampler.JSR223Sampler.sample(JSR223Sampler.java:71) [ApacheJMeter_java.jar:5.2.1]
              at org.apache.jmeter.threads.JMeterThread.doSampling(JMeterThread.java:627) [ApacheJMeter_core.jar:5.2.1]
              at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:551) [ApacheJMeter_core.jar:5.2.1]
              at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:490) [ApacheJMeter_core.jar:5.2.1]
              at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:257) [ApacheJMeter_core.jar:5.2.1]
              at java.lang.Thread.run(Thread.java:748) [?:1.8.0_241]
Caused by: groovy.lang.MissingMethodException: No signature of method: java.io.File.eachfile() is applicable for argument types: (groovy.io.FileType, Script2$_run_closure1) values: [FILES, Script2$_run_closure1@17b02a]
Possible solutions: eachFile(groovy.io.FileType, groovy.lang.Closure), eachFile(groovy.lang.Closure), eachLine(int, groovy.lang.Closure), eachLine(java.lang.String, groovy.lang.Closure), eachLine(groovy.lang.Closure), isFile()
              at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:71) ~[groovy-all-2.4.16.jar:2.4.16]
              at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:48) ~[groovy-all-2.4.16.jar:2.4.16]
              at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) ~[groovy-all-2.4.16.jar:2.4.16]
              at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) ~[groovy-all-2.4.16.jar:2.4.16]
              at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:136) ~[groovy-all-2.4.16.jar:2.4.16]
              at Script2.run(Script2.groovy:4) ~[?:?]
              at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:321) ~[groovy-all-2.4.16.jar:2.4.16]
              ... 9 more
2020-08-19 17:49:15,955 INFO o.a.j.t.JMeterThread: Thread is done: tearDown Thread Group 1-1
2020-08-19 17:49:15,955 INFO o.a.j.t.JMeterThread: Thread finished: tearDown Thread Group 1-1
从日志中提取:

import groovy.io.FileType

String folderPath = "data-management"
new File(folderPath).eachfile (FileType.FILES) { file ->
    /* Delete file if file name contains .dat */
    if (file.name.contains('.dat')) file.delete()
}
Response code:500
Response message:javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: java.io.File.eachfile() is applicable for argument types: (groovy.io.FileType, Script2$_run_closure1) values: [FILES, Script2$_run_closure1@17b02a]
Possible solutions: eachFile(groovy.io.FileType, groovy.lang.Closure), eachFile(groovy.lang.Closure), eachLine(int, groovy.lang.Closure), eachLine(java.lang.String, groovy.lang.Closure), eachLine(groovy.lang.Closure), isFile()
2020-08-19 17:49:15,917 INFO o.a.j.t.JMeterThread: Thread started: tearDown Thread Group 1-1
2020-08-19 17:49:15,951 ERROR o.a.j.p.j.s.JSR223Sampler: **Problem in JSR223 script JSR223 Sampler**, message: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: java.io.File.eachfile() is applicable for argument types: (groovy.io.FileType, Script2$_run_closure1) values: [FILES, Script2$_run_closure1@17b02a]
Possible solutions: eachFile(groovy.io.FileType, groovy.lang.Closure), eachFile(groovy.lang.Closure), eachLine(int, groovy.lang.Closure), eachLine(java.lang.String, groovy.lang.Closure), eachLine(groovy.lang.Closure), isFile()
javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: java.io.File.eachfile() is applicable for argument types: (groovy.io.FileType, Script2$_run_closure1) values: [FILES, Script2$_run_closure1@17b02a]
Possible solutions: eachFile(groovy.io.FileType, groovy.lang.Closure), eachFile(groovy.lang.Closure), eachLine(int, groovy.lang.Closure), eachLine(java.lang.String, groovy.lang.Closure), eachLine(groovy.lang.Closure), isFile()
              at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:324) ~[groovy-all-2.4.16.jar:2.4.16]
              at org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:72) ~[groovy-all-2.4.16.jar:2.4.16]
              at javax.script.CompiledScript.eval(CompiledScript.java:92) ~[?:1.8.0_241]
              at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:223) ~[ApacheJMeter_core.jar:5.2.1]
              at org.apache.jmeter.protocol.java.sampler.JSR223Sampler.sample(JSR223Sampler.java:71) [ApacheJMeter_java.jar:5.2.1]
              at org.apache.jmeter.threads.JMeterThread.doSampling(JMeterThread.java:627) [ApacheJMeter_core.jar:5.2.1]
              at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:551) [ApacheJMeter_core.jar:5.2.1]
              at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:490) [ApacheJMeter_core.jar:5.2.1]
              at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:257) [ApacheJMeter_core.jar:5.2.1]
              at java.lang.Thread.run(Thread.java:748) [?:1.8.0_241]
Caused by: groovy.lang.MissingMethodException: No signature of method: java.io.File.eachfile() is applicable for argument types: (groovy.io.FileType, Script2$_run_closure1) values: [FILES, Script2$_run_closure1@17b02a]
Possible solutions: eachFile(groovy.io.FileType, groovy.lang.Closure), eachFile(groovy.lang.Closure), eachLine(int, groovy.lang.Closure), eachLine(java.lang.String, groovy.lang.Closure), eachLine(groovy.lang.Closure), isFile()
              at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:71) ~[groovy-all-2.4.16.jar:2.4.16]
              at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:48) ~[groovy-all-2.4.16.jar:2.4.16]
              at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) ~[groovy-all-2.4.16.jar:2.4.16]
              at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) ~[groovy-all-2.4.16.jar:2.4.16]
              at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:136) ~[groovy-all-2.4.16.jar:2.4.16]
              at Script2.run(Script2.groovy:4) ~[?:?]
              at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:321) ~[groovy-all-2.4.16.jar:2.4.16]
              ... 9 more
2020-08-19 17:49:15,955 INFO o.a.j.t.JMeterThread: Thread is done: tearDown Thread Group 1-1
2020-08-19 17:49:15,955 INFO o.a.j.t.JMeterThread: Thread finished: tearDown Thread Group 1-1
问候


Raja是一种区分大小写的语言

所以

每个文件

必须是:

每个文件

见: