本文整理汇总了Java中org.apache.jmeter.samplers.SampleResult.sampleEnd方法的典型用法代码示例。如果您正苦于以下问题:Java SampleResult.sampleEnd方法的具体用法?Java SampleResult.sampleEnd怎么用?Java SampleResult.sampleEnd使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.jmeter.samplers.SampleResult
的用法示例。
在下文中一共展示了SampleResult.sampleEnd方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: send
import org.apache.jmeter.samplers.SampleResult; //导入方法依赖的package包/类
@Override
public void send(JMeterContext context, SampleResult result) {
JMeterVariables variables = context.getVariables();
ConcurrentHashMap<String, MockLwM2mClient> clients = (ConcurrentHashMap<String, MockLwM2mClient>) variables.getObject("lwm2mClients");
MockLwM2mClient client = clients.get(endpoint);
if (client != null) {
SimpleResource resource = (SimpleResource) client.getObject(objectId).getChild(instanceId).getChild(resourceId);
result.sampleStart();
if (resource != null) {
resource.setResourceValue(Float.toString(rng.nextInt(100)));
result.setSuccessful(true);
log.debug("Sent observation for " + objectId + "/" + instanceId + "/" + resourceId);
} else {
result.setSuccessful(false);
log.debug("Could not send observation for " + objectId + "/" + instanceId + "/" + resourceId);
}
result.sampleEnd();
}
}
示例2: testTestEnded
import org.apache.jmeter.samplers.SampleResult; //导入方法依赖的package包/类
@Test
public void testTestEnded() throws IOException {
System.out.println("testEnded");
LoadosophiaUploader instance = new LoadosophiaUploaderEmul();
instance.resetTest();
instance.setStoreDir(TestJMeterUtils.getTempDir());
instance.setTitle("UnitTest");
instance.setColorFlag("gray");
instance.setProject("DEFAULT");
instance.setUploadToken("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
instance.testStarted();
SampleResult res = new SampleResult();
res.sampleStart();
res.sampleEnd();
SampleEvent event = new SampleEvent(res, "test");
instance.sampleOccurred(event);
instance.testEnded();
}
示例3: testTestEndedWithNoStoreDir
import org.apache.jmeter.samplers.SampleResult; //导入方法依赖的package包/类
@Test
public void testTestEndedWithNoStoreDir() throws IOException {
System.out.println("testEnded");
JMeterUtils.setProperty("loadosophia.address", "http://localhost/");
LoadosophiaUploader instance = new LoadosophiaUploaderEmul();
instance.setStoreDir("");
instance.setTitle("UnitTest");
instance.setColorFlag("gray");
instance.setProject("DEFAULT");
instance.setUploadToken("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
instance.testStarted();
SampleResult res = new SampleResult();
res.sampleStart();
res.sampleEnd();
SampleEvent event = new SampleEvent(res, "test");
instance.sampleOccurred(event);
instance.testEnded();
}
示例4: sample
import org.apache.jmeter.samplers.SampleResult; //导入方法依赖的package包/类
public SampleResult sample(Entry arg0) {
SampleResult res = new SampleResult();
res.setSampleLabel("函数助手小工具");
res.sampleStart();
// 输出GUI界面所输入的函数方法返回结果
JMeterProperty properties = this.getProperty(FUNCTION);
System.out.println(properties);
//
if (properties != null) {
res.setResponseData("Function结果是:" + properties.getStringValue(), null);
res.setDataType(SampleResult.TEXT);
}
res.sampleEnd();
res.setSuccessful(true);
return res;
}
示例5: runTest
import org.apache.jmeter.samplers.SampleResult; //导入方法依赖的package包/类
/**
* For each sample request this method is invoked and will return success/failure result
*
* @param context
* @return
*/
@Override
public SampleResult runTest(JavaSamplerContext context) {
SampleResult sampleResult = new SampleResult();
sampleResult.sampleStart();
Object message = JMeterContextService.getContext().getVariables().getObject(placeHolder);
try {
ProducerRecord<String, Object> producerRecord = new ProducerRecord<String, Object>(topic, message);
producer.send(producerRecord);
sampleResult.setResponseData(message.toString(), StandardCharsets.UTF_8.name());
sampleResult.setSuccessful(true);
sampleResult.sampleEnd();
} catch (Exception e) {
log.error("Failed to send message", e);
sampleResult.setResponseData(e.getMessage(), StandardCharsets.UTF_8.name());
sampleResult.setSuccessful(false);
sampleResult.sampleEnd();
}
return sampleResult;
}
示例6: getMasterList
import org.apache.jmeter.samplers.SampleResult; //导入方法依赖的package包/类
private DataRequest getMasterList(SampleResult masterResult, Parser parser) throws IOException {
masterResult.sampleStart();
DataRequest respond = parser.getBaseUrl(new URL(getURLData()), masterResult, true);
masterResult.sampleEnd();
masterResult.setRequestHeaders(respond.getRequestHeaders() + "\n\n" + getCookieHeader(getURLData()) + "\n\n"
+ getRequestHeader(this.getHeaderManager()));
masterResult.setSuccessful(respond.isSuccess());
masterResult.setResponseMessage(respond.getResponseMessage());
masterResult.setSampleLabel(this.getName());
masterResult.setResponseHeaders(respond.getHeadersAsString());
masterResult.setResponseData(respond.getResponse().getBytes());
masterResult.setResponseCode(respond.getResponseCode());
masterResult.setContentType(respond.getContentType());
masterResult.setBytes(masterResult.getBytesAsLong() + (long) masterResult.getRequestHeaders().length());
int headerBytes = masterResult.getResponseHeaders().length() // condensed
// length
// (without
// \r)
+ respond.getHeaders().size() // Add \r for each header
+ 1 // Add \r for initial header
+ 2; // final \r\n before data
masterResult.setHeadersSize((int) headerBytes);
masterResult.setSentBytes(respond.getSentBytes());
masterResult.setDataEncoding(respond.getContentEncoding());
return respond;
}
示例7: getPlayList
import org.apache.jmeter.samplers.SampleResult; //导入方法依赖的package包/类
private DataRequest getPlayList(SampleResult playListResult, Parser parser) throws IOException {
String lastPath = "";
playListResult.sampleStart();
DataRequest subRespond = parser.getBaseUrl(new URL(playlist), playListResult, true);
playListResult.sampleEnd();
String[] urlArray = playlist.split("/");
lastPath = urlArray[urlArray.length - 1];
playListResult.setRequestHeaders(subRespond.getRequestHeaders() + "\n\n" + getCookieHeader(playlist) + "\n\n"
+ getRequestHeader(this.getHeaderManager()));
playListResult.setSuccessful(subRespond.isSuccess());
playListResult.setResponseMessage(subRespond.getResponseMessage());
playListResult.setSampleLabel(lastPath);
playListResult.setResponseHeaders(subRespond.getHeadersAsString());
playListResult.setResponseData(subRespond.getResponse().getBytes());
playListResult.setResponseCode(subRespond.getResponseCode());
playListResult.setContentType(subRespond.getContentType());
playListResult.setBytes(playListResult.getBytesAsLong() + (long) playListResult.getRequestHeaders().length());
int headerBytes = playListResult.getResponseHeaders().length() // condensed
// length
// (without
// \r)
+ subRespond.getHeaders().size() // Add \r for each header
+ 1 // Add \r for initial header
+ 2; // final \r\n before data
playListResult.setHeadersSize((int) headerBytes);
playListResult.setSentBytes(subRespond.getSentBytes());
playListResult.setDataEncoding(subRespond.getContentEncoding());
return subRespond;
}
示例8: runTest
import org.apache.jmeter.samplers.SampleResult; //导入方法依赖的package包/类
/**
* 开始测试,从arg0参数可以获得参数值;
*/
public SampleResult runTest(JavaSamplerContext arg0) {
name = arg0.getParameter("name");
SampleResult sr = new SampleResult();
sr.setSampleLabel("Java请求--sayHelloToPerson");
try {
// jmeter 开始统计响应时间标记
sr.sampleStart();
Hello test = new Hello();
// 通过下面的操作就可以将被测方法的响应输出到Jmeter的察看结果树中的响应数据里面了。
resultData = test.sayHelloToPerson(name);
if (resultData != null && resultData.length() > 0) {
sr.setResponseData("结果是:" + resultData, null);
sr.setDataType(SampleResult.TEXT);
}
sr.setSuccessful(true);
} catch (Throwable e) {
sr.setSuccessful(false);
e.printStackTrace();
} finally {
// jmeter 结束统计响应时间标记
sr.sampleEnd();
}
return sr;
}
示例9: runTest
import org.apache.jmeter.samplers.SampleResult; //导入方法依赖的package包/类
public SampleResult runTest(JavaSamplerContext context) {
String name = context.getParameter("name");
getNewLogger().info("dubbo test - {} start", name);
SampleResult sr = new SampleResult();
// 开始测试
sr.sampleStart();
start = System.currentTimeMillis();
sr.setSampleLabel("Dubbo请求--sayHello");
try {
String result = this.userService.sayHello();
if (null != result && result.length() > 0) {
sr.setResponseData("结果是:" + result, null);
sr.setDataType(SampleResult.TEXT);
}
sr.setSuccessful(true);
} catch (Exception e) {
sr.setSuccessful(false);
e.printStackTrace();
} finally {
sr.sampleEnd();
}
return sr;
}
示例10: fillOKResult
import org.apache.jmeter.samplers.SampleResult; //导入方法依赖的package包/类
private SampleResult fillOKResult(SampleResult result, int size, String message, String contents) {
result.setResponseCode("200");
result.setSuccessful(true);
result.setResponseMessage(message);
result.setBodySize(size);
result.setBytes(size);
result.setResponseData(contents.getBytes());
result.sampleEnd();
return result;
}
示例11: sample
import org.apache.jmeter.samplers.SampleResult; //导入方法依赖的package包/类
@Override
public SampleResult sample(Entry e) {
SampleResult masterResult = new SampleResult();
float currenTimeseconds = 0;
boolean isVod = getHlsVideoType().equals("vod");
boolean out = false;
boolean firstTime = true;
boolean containNewFragments = false;
List<String> list = new ArrayList<>();
try {
DataRequest respond = getMasterList(masterResult, parser);
String auxPath = getPlaylistPath(respond, parser);
int playSeconds = 0;
if (!getPlAYSecondsData().isEmpty())
playSeconds = Integer.parseInt(getPlAYSecondsData());
while ((playSeconds >= currenTimeseconds) && !out) {
SampleResult playListResult = new SampleResult();
DataRequest subRespond = getPlayList(playListResult, parser);
List<DataFragment> videoUri = parser.extractVideoUrl(subRespond.getResponse());
List<DataFragment> fragmentToDownload = new ArrayList<>();
if (firstTime) {
if (!(((getHlsVideoType().equals("live")) && (parser.isLive(subRespond.getResponse())))
|| ((isVod) && (!parser.isLive(subRespond.getResponse())))
|| ((getHlsVideoType().equals("event")) && (parser.isLive(subRespond.getResponse()))))) {
} else {
firstTime = false;
out = isVod;
}
}
while ((!videoUri.isEmpty()) && (playSeconds >= currenTimeseconds)) {
DataFragment frag = videoUri.remove(0);
boolean isPresent = false;
int length = fragmentsDownloaded.size();
if (length != 0) {
isPresent = fragmentsDownloaded.contains(frag.getTsUri().trim());
}
if (!isPresent) {
fragmentToDownload.add(frag);
fragmentsDownloaded.add(frag.getTsUri().trim());
containNewFragments = true;
if(getVideoDuration()) {
currenTimeseconds += Float.parseFloat(frag.getDuration());
}
}
}
List<SampleResult> videoFragment = getFragments(parser, fragmentToDownload, auxPath);
for (SampleResult sam : videoFragment) {
playListResult.addSubResult(sam);
}
if((!list.contains(playListResult.getSampleLabel())) || (list.contains(playListResult.getSampleLabel()) && containNewFragments))
{
masterResult.addSubResult(playListResult);
list.add(playListResult.getSampleLabel());
containNewFragments = false;
}
}
} catch (IOException e1) {
e1.printStackTrace();
masterResult.sampleEnd();
masterResult.setSuccessful(false);
masterResult.setResponseMessage("Exception: " + e1);
}
return masterResult;
}
示例12: getFragments
import org.apache.jmeter.samplers.SampleResult; //导入方法依赖的package包/类
public List<SampleResult> getFragments(Parser parser, List<DataFragment> uris, String url) {
List<SampleResult> res = new ArrayList<>();
if (!uris.isEmpty()) {
SampleResult result = new SampleResult();
String uriString = uris.get(0).getTsUri();
if ((url != null) && (!uriString.startsWith("http"))) {
uriString = url + uriString;
}
result.sampleStart();
try {
DataRequest respond = parser.getBaseUrl(new URL(uriString), result, false);
result.sampleEnd();
String[] urlArray = uriString.split("/");
String lastPath = urlArray[urlArray.length - 1];
result.setRequestHeaders(respond.getRequestHeaders() + "\n\n" + getCookieHeader(uriString) + "\n\n"
+ getRequestHeader(this.getHeaderManager()));
result.setSuccessful(respond.isSuccess());
result.setResponseMessage(respond.getResponseMessage());
result.setSampleLabel(lastPath);
result.setResponseHeaders("URL: " + uriString + "\n" + respond.getHeadersAsString());
result.setResponseCode(respond.getResponseCode());
result.setContentType(respond.getContentType());
result.setBytes(result.getBytesAsLong() + (long) result.getRequestHeaders().length());
int headerBytes = result.getResponseHeaders().length() // condensed
// length
// (without
// \r)
+ respond.getHeaders().size() // Add \r for each header
+ 1 // Add \r for initial header
+ 2; // final \r\n before data
result.setHeadersSize((int) headerBytes);
result.setSentBytes(respond.getSentBytes());
result.setDataEncoding(respond.getContentEncoding());
res.add(result);
} catch (IOException e1) {
e1.printStackTrace();
result.sampleEnd();
result.setSuccessful(false);
result.setResponseMessage("Exception: " + e1);
res.add(result);
}
uris.remove(0);
List<SampleResult> aux = getFragments(parser, uris, url);
for (SampleResult s : aux) {
if(!res.contains(s))
res.add(s);
}
}
return res;
}
示例13: sample
import org.apache.jmeter.samplers.SampleResult; //导入方法依赖的package包/类
@Override
public SampleResult sample(Entry entry) {
SampleResult res = new SampleResult();
res.setSampleLabel(getName());
res.setDataType(SampleResult.TEXT);
res.setSuccessful(true);
res.setResponseCode("200");
res.setResponseMessage("OK");
res.sampleStart();
try {
if (connConfig == null) {
throw new RuntimeException("Cannot sample XMPP without XMPP Connection component");
}
XMPPConnection conn = getXMPPConnection();
if (conn == null) {
throw new RuntimeException("No XMPP Connection available");
}
String headers = "Connection ID: " + conn.getConnectionID() + "\r\n";
String action = getAction();
if (!conn.isConnected() && !action.equals(Connect.class.getCanonicalName())) {
log.error("Please call Connect before calling other actions");
throw new SmackException.NotConnectedException();
}
headers += "User: " + conn.getUser() + "\r\n";
res.setRequestHeaders(headers);
AbstractXMPPAction actObject = connConfig.getActions().get(action);
if (actObject.perform(this, res) == null) {
return null;
}
} catch (Exception e) {
log.error("Error in XMPP Sampler: ", e);
res.setSuccessful(false);
res.setResponseCode("500");
res.setResponseMessage((e.getMessage() == null || e.getMessage().isEmpty()) ? e.toString() : e.getMessage());
res.setResponseData(ExceptionUtils.getStackTrace(e).getBytes());
}
res.sampleEnd();
return res;
}
示例14: 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;
}