需要測試的應用程序,但我得到以下錯誤:的JMeter的示例代碼
ERROR - jmeter.samplers.SampleResult: setEndTime must be called after setStartTime java.lang.Throwable: Invalid call sequence
at org.apache.jmeter.samplers.SampleResult.setEndTime(SampleResult.java:1023)
at org.apache.jmeter.samplers.SampleResult.sampleEnd(SampleResult.java:1062)
at infy.dop.rsi.jmeter.EmoDb.runTest(EmoDb.java:94)
at org.apache.jmeter.protocol.java.sampler.JavaSampler.sample(JavaSampler.java:191)
at org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:434)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:261)
at java.lang.Thread.run(Thread.java:745)
他是我的代碼:
public class EmoDb extends AbstractJavaSamplerClient {
private static final Logger LOGGER = LoggerFactory.getLogger(EmoDb.class);
private Properties prop = new Properties();
public Arguments getDefaultParameters() {
Arguments defaultParameters = new Arguments();
return defaultParameters;
}
public void setupTest(JavaSamplerContext context) {
for (Iterator<String> it = context.getParameterNamesIterator(); it.hasNext();) {
String paramName = it.next();
prop.put(paramName, context.getParameter(paramName));
}
}
@Override
public SampleResult runTest(JavaSamplerContext arg0) {
SampleResult result = new SampleResult();
try {
URL url=new URL(" ");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("GET");
connection.connect();
result.sampleStart();
int code = connection.getResponseCode();
if (code==200)
{
System.out.println("OK");
result.sampleEnd();
}
else {
throw new Exception("status is not=200");
}
} catch (Exception e) {
LOGGER.error(ExceptionUtils.getStackTrace(e));
result.sampleEnd();
result.setSuccessful(false);
result.setResponseMessage("Exception: " + e);
result.setSampleLabel(e.getMessage());
return result;
}
result.setSuccessful(true);
result.setResponseMessage("Successfully completed");
result.setResponseOK();
return result;
}
}
什麼是'SampleResult.java:1023' –