本文整理匯總了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");
}
}
}