当前位置: 首页>>代码示例>>Java>>正文


Java SampleResult.setResponseCodeOK方法代码示例

本文整理汇总了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;
}
 
开发者ID:emqtt,项目名称:mqtt-jmeter,代码行数:55,代码来源:ConnectionSampler.java


注:本文中的org.apache.jmeter.samplers.SampleResult.setResponseCodeOK方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。