本文整理汇总了Java中org.apache.jmeter.samplers.SampleResult类的典型用法代码示例。如果您正苦于以下问题:Java SampleResult类的具体用法?Java SampleResult怎么用?Java SampleResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SampleResult类属于org.apache.jmeter.samplers包,在下文中一共展示了SampleResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getResponseAsString
import org.apache.jmeter.samplers.SampleResult; //导入依赖的package包/类
public static String getResponseAsString(SampleResult res) {
String response = null;
if (isTextDataType(res)) {
// Showing large strings can be VERY costly, so we will avoid
// doing so if the response
// data is larger than 200K. TODO: instead, we could delay doing
// the result.setText
// call until the user chooses the "Response data" tab. Plus we
// could warn the user
// if this happens and revert the choice if he doesn't confirm
// he's ready to wait.
int len = res.getResponseDataAsString().length();
if (MAX_DISPLAY_SIZE > 0 && len > MAX_DISPLAY_SIZE) {
StringBuilder builder = new StringBuilder(MAX_DISPLAY_SIZE+100);
builder.append(JMeterUtils.getResString("view_results_response_too_large_message")) //$NON-NLS-1$
.append(len).append(" > Max: ").append(MAX_DISPLAY_SIZE)
.append(", ").append(JMeterUtils.getResString("view_results_response_partial_message")) // $NON-NLS-1$
.append("\n").append(res.getResponseDataAsString().substring(0, MAX_DISPLAY_SIZE)).append("\n...");
response = builder.toString();
} else {
response = res.getResponseDataAsString();
}
}
return response;
}
示例2: caclucateMetrics
import org.apache.jmeter.samplers.SampleResult; //导入依赖的package包/类
private static JSONObject caclucateMetrics(List<SampleResult> accumulatedValues, List<SampleResult> intervalValues, String label) {
final JSONObject res = new JSONObject();
res.put("n", accumulatedValues.size()); // total count of samples
res.put("name", label); // label
res.put("interval", 1); // not used
res.put("samplesNotCounted", 0); // not used
res.put("assertionsNotCounted", 0); // not used
res.put("failedEmbeddedResources", "[]"); // not used
res.put("failedEmbeddedResourcesSpilloverCount", 0); // not used
res.put("otherErrorsCount", 0); // not used
res.put("percentileHistogram", "[]"); // not used
res.put("percentileHistogramLatency", "[]"); // not used
res.put("percentileHistogramBytes", "[]"); // not used
res.put("empty", "[]"); // not used
res.put("summary", generateSummary(accumulatedValues)); // summary info
res.put("intervals", calculateIntervals(intervalValues)); // list of intervals
addErrors(res, accumulatedValues);
return res;
}
示例3: testHandleSamples
import org.apache.jmeter.samplers.SampleResult; //导入依赖的package包/类
@Test
public void testHandleSamples() throws Exception {
JMeterUtils.setProperty("sense.delay", "10000");
LoadosophiaClient client = new LoadosophiaClient();
client.setOnlineInitiated(true);
client.setResultCollector(new ResultCollector());
client.setFileName("");
StatusNotifierCallbackTest.StatusNotifierCallbackImpl notifierCallback = new StatusNotifierCallbackTest.StatusNotifierCallbackImpl();
client.setInformer(notifierCallback);
client.setApiClient(new LoadosophiaAPIClientEmul(notifierCallback));
List<SampleResult> list = new LinkedList<>();
list.add(new SampleResult(System.currentTimeMillis(), 1));
list.add(new SampleResult(System.currentTimeMillis() + 1000, 1));
list.add(new SampleResult(System.currentTimeMillis() + 2000, 1));
long start = System.currentTimeMillis();
client.handleSampleResults(list, null);
long end = System.currentTimeMillis();
assertTrue((end - start) > 9999);
}
示例4: 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();
}
}
示例5: flowDefault
import org.apache.jmeter.samplers.SampleResult; //导入依赖的package包/类
@Test
public void flowDefault() throws Exception {
RotatingResultCollector te = new RotatingResultCollector();
te.setMaxSamplesCount("ZXC");
assertEquals(Integer.MAX_VALUE, te.getMaxSamplesCountAsInt());
File f = File.createTempFile("rotating", ".jtl");
f.deleteOnExit();
te.setFilename(f.getAbsolutePath());
te.setMaxSamplesCount("3");
te.testStarted();
for (int n = 0; n < 10; n++) {
SampleResult result = new SampleResult();
result.setSampleLabel("#" + n);
te.sampleOccurred(new SampleEvent(result, ""));
}
te.testEnded();
assertTrue(te.filename.endsWith(".3.jtl"));
}
示例6: testFlowWithoutExtension
import org.apache.jmeter.samplers.SampleResult; //导入依赖的package包/类
@Test
public void testFlowWithoutExtension() throws Exception {
RotatingResultCollector te = new RotatingResultCollector();
te.setMaxSamplesCount("ZXC");
assertEquals(Integer.MAX_VALUE, te.getMaxSamplesCountAsInt());
File f = File.createTempFile("rotating", "");
f.deleteOnExit();
te.setFilename(f.getAbsolutePath());
te.setMaxSamplesCount("3");
te.testStarted();
for (int n = 0; n < 10; n++) {
SampleResult result = new SampleResult();
result.setSampleLabel("#" + n);
te.sampleOccurred(new SampleEvent(result, ""));
}
te.testEnded();
assertTrue(te.filename, te.filename.endsWith(".3"));
}
示例7: testFlowWithNumberExtension
import org.apache.jmeter.samplers.SampleResult; //导入依赖的package包/类
@Test
public void testFlowWithNumberExtension() throws Exception {
RotatingResultCollector te = new RotatingResultCollector();
te.setMaxSamplesCount("ZXC");
assertEquals(Integer.MAX_VALUE, te.getMaxSamplesCountAsInt());
File f = File.createTempFile("rotating", ".9");
f.deleteOnExit();
te.setFilename(f.getAbsolutePath());
te.setMaxSamplesCount("3");
te.testStarted();
for (int n = 0; n < 10; n++) {
SampleResult result = new SampleResult();
result.setSampleLabel("#" + n);
te.sampleOccurred(new SampleEvent(result, ""));
}
te.testEnded();
assertTrue(te.filename, te.filename.endsWith(".3.9"));
}
示例8: updateGui
import org.apache.jmeter.samplers.SampleResult; //导入依赖的package包/类
/**
* Update the visualizer with new data.
*/
private synchronized void updateGui(SampleResult res) {
// Add sample
DefaultMutableTreeNode currNode = new SearchableTreeNode(res, treeModel);
treeModel.insertNodeInto(currNode, root, root.getChildCount());
addSubResults(currNode, res);
// Add any assertion that failed as children of the sample node
AssertionResult[] assertionResults = res.getAssertionResults();
int assertionIndex = currNode.getChildCount();
for (AssertionResult assertionResult : assertionResults) {
if (assertionResult.isFailure() || assertionResult.isError()) {
DefaultMutableTreeNode assertionNode = new SearchableTreeNode(assertionResult, treeModel);
treeModel.insertNodeInto(assertionNode, currNode, assertionIndex++);
}
}
if (root.getChildCount() == 1) {
jTree.expandPath(new TreePath(root));
}
if (autoScrollCB.isSelected() && root.getChildCount() > 1) {
jTree.scrollPathToVisible(new TreePath(new Object[] { root,
treeModel.getChild(root, root.getChildCount() - 1) }));
}
}
示例9: createLeftPanel
import org.apache.jmeter.samplers.SampleResult; //导入依赖的package包/类
private synchronized Component createLeftPanel() {
SampleResult rootSampleResult = new SampleResult();
rootSampleResult.setSampleLabel("Root");
rootSampleResult.setSuccessful(true);
root = new SearchableTreeNode(rootSampleResult, null);
treeModel = new DefaultTreeModel(root);
jTree = new JTree(treeModel);
jTree.setCellRenderer(new ResultsNodeRenderer());
jTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
jTree.addTreeSelectionListener(this);
jTree.setRootVisible(false);
jTree.setShowsRootHandles(true);
JScrollPane treePane = new JScrollPane(jTree);
treePane.setPreferredSize(new Dimension(200, 300));
VerticalPanel leftPane = new VerticalPanel();
leftPane.add(treePane, BorderLayout.CENTER);
leftPane.add(createComboRender(), BorderLayout.NORTH);
autoScrollCB = new JCheckBox(JMeterUtils.getResString("view_results_autoscroll")); // $NON-NLS-1$
autoScrollCB.setSelected(false);
autoScrollCB.addItemListener(this);
leftPane.add(autoScrollCB, BorderLayout.SOUTH);
return leftPane;
}
示例10: setParentSampleSuccess
import org.apache.jmeter.samplers.SampleResult; //导入依赖的package包/类
/**
* Set parent successful attribute based on IGNORE_FAILED_EMBEDDED_RESOURCES
* parameter
*
* @param res
* {@link HTTP2SampleResult}
* @param initialValue
* boolean
*/
private void setParentSampleSuccess(HTTP2SampleResult res, boolean initialValue) {
if (!IGNORE_FAILED_EMBEDDED_RESOURCES) {
res.setSuccessful(initialValue);
if (!initialValue) {
StringBuilder detailedMessage = new StringBuilder(80);
detailedMessage.append("Embedded resource download error:"); //$NON-NLS-1$
for (SampleResult subResult : res.getSubResults()) {
HTTP2SampleResult httpSampleResult = (HTTP2SampleResult) subResult;
if (!httpSampleResult.isSuccessful()) {
detailedMessage.append(httpSampleResult.getURL()).append(" code:") //$NON-NLS-1$
.append(httpSampleResult.getResponseCode()).append(" message:") //$NON-NLS-1$
.append(httpSampleResult.getResponseMessage()).append(", "); //$NON-NLS-1$
}
}
res.setResponseMessage(detailedMessage.toString()); // $NON-NLS-1$
}
}
}
示例11: setUp
import org.apache.jmeter.samplers.SampleResult; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
sampler = HTTPSamplerFactory.newInstance();
sampler.setProtocol("http");
sampler.setDomain("dummy.net");
sampler.setPath("/base/form");
sampler.setMethod("POST");
prev = SampleResult.createTestSample(0);
prev.setURL(new URL("http://dummy.net/base/form"));
prev.setContentType("text/html");
prev.setResponseData(html, "UTF-8");
context = JMeterContextService.getContext();
context.setCurrentSampler(sampler);
context.setPreviousResult(prev);
instance = new HTTPFormManager();
instance.setThreadContext(context);
}
示例12: sample
import org.apache.jmeter.samplers.SampleResult; //导入依赖的package包/类
/**
* Perform a sample, and return the results
*
* @return results of the sampling
*/
public SampleResult sample() {
SampleResult res = null;
try {
URL url= getUrl();
// Create Sample Result
HTTP2SampleResult sampleResult =new HTTP2SampleResult(url, getMethod());
setConnection(url, sampleResult);
res = sample(url, getMethod(), false, 0, getConnection(), sampleResult);
if (res != null) {
res.setSampleLabel(getName());
}
return res;
} catch (Exception e) {
return res;
}
}
示例13: sampleOccurredTest
import org.apache.jmeter.samplers.SampleResult; //导入依赖的package包/类
@Test
public void sampleOccurredTest() throws Exception {
HTTP2SampleResult result = new HTTP2SampleResult();
HTTP2SampleResult child1 = new HTTP2SampleResult();
HTTP2SampleResult child2 = new HTTP2SampleResult();
child1.sampleStart();
child2.sampleStart();
result.sampleStart();
result.addSubResult(child1);
result.addSubResult(child2);
SampleEvent event = new SampleEvent((SampleResult) result, "threadGroup", "");
http2ResultCollector.setFilename("datawriter");
http2ResultCollector.testStarted();
http2ResultCollector.sampleOccurred(event);
http2ResultCollector.testEnded();
}
示例14: getResponseAsStringTest
import org.apache.jmeter.samplers.SampleResult; //导入依赖的package包/类
@Test
public void getResponseAsStringTest() {
HTTP2SampleResult http2SampleRes= new HTTP2SampleResult();
http2SampleRes.setDataType(SampleResult.TEXT);
String textExp = "Convert Java String";
byte[] bytes = textExp.getBytes();
http2SampleRes.setResponseData(bytes);
String textRes = http2ViewResTree.getResponseAsString(http2SampleRes);
assertEquals(textExp, textRes);
HTTP2SampleResult http2SampleRes2= new HTTP2SampleResult();
textExp = "Convert Java String and more text";
bytes = textExp.getBytes();
http2SampleRes2.setResponseData(bytes);
textRes = http2ViewResTree.getResponseAsString(http2SampleRes2);
assertTrue(textRes.contains("Response too large to be displayed."));
}
示例15: handleSampleResults
import org.apache.jmeter.samplers.SampleResult; //导入依赖的package包/类
@Override
public void handleSampleResults(List<SampleResult> list, BackendListenerContext backendListenerContext) {
if (list != null && isOnlineInitiated) {
try {
JSONArray array = getDataToSend(list);
log.info(array.toString());
apiClient.sendOnlineData(array);
} catch (IOException ex) {
log.warn("Failed to send active test data", ex);
}
try {
Thread.sleep(delay);
} catch (InterruptedException e) {
log.warn("Backend listener client thread was interrupted");
}
}
}