use of org.apache.jmeter.assertions.AssertionResult in project jmeter by apache.
the class ViewResultsFullVisualizer method updateGui.
/**
* Update the visualizer with new data.
*/
private void updateGui() {
synchronized (buffer) {
if (!dataChanged) {
return;
}
root.removeAllChildren();
for (Object sampler : buffer) {
SampleResult res = (SampleResult) sampler;
// 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++);
}
}
}
treeModel.nodeStructureChanged(root);
dataChanged = false;
}
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) }));
}
}
use of org.apache.jmeter.assertions.AssertionResult in project jmeter by apache.
the class CSVSaveService method resultToDelimitedString.
/**
* Convert a result into a string, where the fields of the result are
* separated by a specified String.
*
* @param event
* the sample event to be converted
* @param delimiter
* the separation string
* @return the separated value representation of the result
*/
public static String resultToDelimitedString(SampleEvent event, final String delimiter) {
StringQuoter text = new StringQuoter(delimiter.charAt(0));
SampleResult sample = event.getResult();
SampleSaveConfiguration saveConfig = sample.getSaveConfig();
if (saveConfig.saveTimestamp()) {
if (saveConfig.printMilliseconds()) {
text.append(sample.getTimeStamp());
} else if (saveConfig.threadSafeLenientFormatter() != null) {
String stamp = saveConfig.threadSafeLenientFormatter().format(new Date(sample.getTimeStamp()));
text.append(stamp);
}
}
if (saveConfig.saveTime()) {
text.append(sample.getTime());
}
if (saveConfig.saveLabel()) {
text.append(sample.getSampleLabel());
}
if (saveConfig.saveCode()) {
text.append(sample.getResponseCode());
}
if (saveConfig.saveMessage()) {
text.append(sample.getResponseMessage());
}
if (saveConfig.saveThreadName()) {
text.append(sample.getThreadName());
}
if (saveConfig.saveDataType()) {
text.append(sample.getDataType());
}
if (saveConfig.saveSuccess()) {
text.append(sample.isSuccessful());
}
if (saveConfig.saveAssertionResultsFailureMessage()) {
String message = null;
AssertionResult[] results = sample.getAssertionResults();
if (results != null) {
// Find the first non-null message
for (AssertionResult result : results) {
message = result.getFailureMessage();
if (message != null) {
break;
}
}
}
if (message != null) {
text.append(message);
} else {
// Need to append something so delimiter is
text.append("");
// added
}
}
if (saveConfig.saveBytes()) {
text.append(sample.getBytesAsLong());
}
if (saveConfig.saveSentBytes()) {
text.append(sample.getSentBytes());
}
if (saveConfig.saveThreadCounts()) {
text.append(sample.getGroupThreads());
text.append(sample.getAllThreads());
}
if (saveConfig.saveUrl()) {
text.append(sample.getURL());
}
if (saveConfig.saveFileName()) {
text.append(sample.getResultFileName());
}
if (saveConfig.saveLatency()) {
text.append(sample.getLatency());
}
if (saveConfig.saveEncoding()) {
text.append(sample.getDataEncodingWithDefault());
}
if (saveConfig.saveSampleCount()) {
// Need both sample and error count to be any use
text.append(sample.getSampleCount());
text.append(sample.getErrorCount());
}
if (saveConfig.saveHostname()) {
text.append(event.getHostname());
}
if (saveConfig.saveIdleTime()) {
text.append(event.getResult().getIdleTime());
}
if (saveConfig.saveConnectTime()) {
text.append(sample.getConnectTime());
}
for (int i = 0; i < SampleEvent.getVarCount(); i++) {
text.append(event.getVarValue(i));
}
return text.toString();
}
use of org.apache.jmeter.assertions.AssertionResult in project jmeter by apache.
the class JMeterThread method checkAssertions.
private void checkAssertions(List<Assertion> assertions, SampleResult parent, JMeterContext threadContext) {
for (Assertion assertion : assertions) {
TestBeanHelper.prepare((TestElement) assertion);
if (assertion instanceof AbstractScopedAssertion) {
AbstractScopedAssertion scopedAssertion = (AbstractScopedAssertion) assertion;
String scope = scopedAssertion.fetchScope();
if (scopedAssertion.isScopeParent(scope) || scopedAssertion.isScopeAll(scope) || scopedAssertion.isScopeVariable(scope)) {
processAssertion(parent, assertion);
}
if (scopedAssertion.isScopeChildren(scope) || scopedAssertion.isScopeAll(scope)) {
SampleResult[] children = parent.getSubResults();
boolean childError = false;
for (SampleResult childSampleResult : children) {
processAssertion(childSampleResult, assertion);
if (!childSampleResult.isSuccessful()) {
childError = true;
}
}
// If parent is OK, but child failed, add a message and flag the parent as failed
if (childError && parent.isSuccessful()) {
AssertionResult assertionResult = new AssertionResult(((AbstractTestElement) assertion).getName());
assertionResult.setResultForFailure("One or more sub-samples failed");
parent.addAssertionResult(assertionResult);
parent.setSuccessful(false);
}
}
} else {
processAssertion(parent, assertion);
}
}
threadContext.getVariables().put(LAST_SAMPLE_OK, Boolean.toString(parent.isSuccessful()));
}
use of org.apache.jmeter.assertions.AssertionResult in project jmeter by apache.
the class JMeterThread method processAssertion.
private void processAssertion(SampleResult result, Assertion assertion) {
AssertionResult assertionResult;
try {
assertionResult = assertion.getResult(result);
} catch (ThreadDeath e) {
throw e;
} catch (JMeterError e) {
log.error("Error processing Assertion.", e);
assertionResult = new AssertionResult("Assertion failed! See log file.");
assertionResult.setError(true);
assertionResult.setFailureMessage(e.toString());
} catch (Exception e) {
log.error("Exception processing Assertion.", e);
assertionResult = new AssertionResult("Assertion failed! See log file.");
assertionResult.setError(true);
assertionResult.setFailureMessage(e.toString());
}
result.setSuccessful(result.isSuccessful() && !(assertionResult.isError() || assertionResult.isFailure()));
result.addAssertionResult(assertionResult);
}
use of org.apache.jmeter.assertions.AssertionResult in project jmeter by apache.
the class XPathExtractor method addAssertionFailure.
private void addAssertionFailure(final SampleResult previousResult, final Throwable thrown, final boolean setFailed) {
// $NON-NLS-1$
AssertionResult ass = new AssertionResult(getName());
ass.setFailure(true);
ass.setFailureMessage(thrown.getLocalizedMessage() + "\nSee log file for further details.");
previousResult.addAssertionResult(ass);
if (setFailed) {
previousResult.setSuccessful(false);
}
}
Aggregations