本文整理汇总了Java中org.apache.jmeter.samplers.SampleResult.setResponseCodeOK方法的典型用法代码示例。如果您正苦于以下问题:Java SampleResult.setResponseCodeOK方法的具体用法?Java SampleResult.setResponseCodeOK怎么用?Java SampleResult.setResponseCodeOK使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.jmeter.samplers.SampleResult
的用法示例。
在下文中一共展示了SampleResult.setResponseCodeOK方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sample
import org.apache.jmeter.samplers.SampleResult; //导入方法依赖的package包/类
@Override
public SampleResult sample(Entry entry) {
SampleResult result = new SampleResult();
result.setSampleLabel(getName());
try {
if (!DEFAULT_PROTOCOL.equals(getProtocol())) {
mqtt.setSslContext(Util.getContext(this));
}
mqtt.setHost(getProtocol().toLowerCase() + "://" + getServer() + ":" + getPort());
mqtt.setVersion(getMqttVersion());
mqtt.setKeepAlive((short) Integer.parseInt(getConnKeepAlive()));
String clientId = null;
if(isClientIdSuffix()) {
clientId = Util.generateClientId(getConnPrefix());
} else {
clientId = getConnPrefix();
}
mqtt.setClientId(clientId);
mqtt.setConnectAttemptsMax(Integer.parseInt(getConnAttamptMax()));
mqtt.setReconnectAttemptsMax(Integer.parseInt(getConnReconnAttamptMax()));
if (!"".equals(getUserNameAuth().trim())) {
mqtt.setUserName(getUserNameAuth());
}
if (!"".equals(getPasswordAuth().trim())) {
mqtt.setPassword(getPasswordAuth());
}
result.sampleStart();
connection = mqtt.futureConnection();
Future<Void> f1 = connection.connect();
f1.await(Integer.parseInt(getConnTimeout()), TimeUnit.SECONDS);
Topic[] topics = { new Topic("topic_" + clientId, QoS.AT_LEAST_ONCE) };
connection.subscribe(topics);
result.sampleEnd();
result.setSuccessful(true);
result.setResponseData("Successful.".getBytes());
result.setResponseMessage(MessageFormat.format("Connection {0} connected successfully.", connection));
result.setResponseCodeOK();
} catch (Exception e) {
logger.log(Priority.ERROR, e.getMessage(), e);
result.sampleEnd();
result.setSuccessful(false);
result.setResponseMessage(MessageFormat.format("Connection {0} connected failed.", connection));
result.setResponseData("Failed.".getBytes());
result.setResponseCode("500");
}
return result;
}