Jmeter beanscript获取currentTime不起作用

时间:2016-10-16 19:50:03

标签: jmeter beanshell

我是Jmeter的新手。创建一个Jsr223后处理器并选择语言为Bsh。

import java.util.Date; 
import java.text.SimpleDateFormat;

long mill = System.currentTimeMillis();
log.info(mill);

输出:

 ERROR - jmeter.extractor.JSR223PostProcessor: Problem in JSR223 script JSR223 PostProcessor javax.script.ScriptException: Sourced file: inline evaluation of: ``import java.util.Date;  import java.text.SimpleDateFormat;  long mill = System.c . . . '' : Error in method invocation: Method info( long ) not found in class'org.apache.log.Logger' : at Line: 5 : in file: inline evaluation of: ``import java.util.Date;  import java.text.SimpleDateFormat;  long mill = System.c . . . '' : log .info ( mill ) 
 in inline evaluation of: ``import java.util.Date;  import java.text.SimpleDateFormat;  long mill = System.c . . . '' at line number 5
    at bsh.engine.BshScriptEngine.evalSource(BshScriptEngine.java:92)
    at bsh.engine.BshScriptEngine.eval(BshScriptEngine.java:46)
    at javax.script.AbstractScriptEngine.eval(Unknown Source)
    at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:206)
    at org.apache.jmeter.extractor.JSR223PostProcessor.process(JSR223PostProcessor.java:42)
    at org.apache.jmeter.threads.JMeterThread.runPostProcessors(JMeterThread.java:776)
    at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:489)
    at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:410)
    at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:241)
    at java.lang.Thread.run(Unknown Source)

请告知修复。谢谢!

1 个答案:

答案 0 :(得分:1)

首先,你知道__time() JMeter function能以不同的格式输出当前时间吗?

如果您仍想在Beanshell中执行此操作,请注意您无法将Long值直接打印到 jmeter.log 文件,您需要首先使用其中一个将其强制转换为String以下方法

  • log.info(String.valueOf(mill));
  • log.info(Long.toString(mill));
  • log.info("Current time is: " + mill);

你可以得到一个好的"将代码置于try block之内,如:

,则会出现Beanshell错误

JMeter beanshell try catch