Search in sources :

Example 1 with AssertionResult

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) }));
    }
}
Also used : AssertionResult(org.apache.jmeter.assertions.AssertionResult) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath) SampleResult(org.apache.jmeter.samplers.SampleResult)

Example 2 with AssertionResult

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();
}
Also used : SampleSaveConfiguration(org.apache.jmeter.samplers.SampleSaveConfiguration) AssertionResult(org.apache.jmeter.assertions.AssertionResult) StatisticalSampleResult(org.apache.jmeter.samplers.StatisticalSampleResult) SampleResult(org.apache.jmeter.samplers.SampleResult) Date(java.util.Date)

Example 3 with AssertionResult

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()));
}
Also used : AssertionResult(org.apache.jmeter.assertions.AssertionResult) Assertion(org.apache.jmeter.assertions.Assertion) AbstractScopedAssertion(org.apache.jmeter.testelement.AbstractScopedAssertion) AbstractScopedAssertion(org.apache.jmeter.testelement.AbstractScopedAssertion) SampleResult(org.apache.jmeter.samplers.SampleResult)

Example 4 with AssertionResult

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);
}
Also used : AssertionResult(org.apache.jmeter.assertions.AssertionResult) JMeterError(org.apache.jorphan.util.JMeterError) JMeterStopTestException(org.apache.jorphan.util.JMeterStopTestException) JMeterStopThreadException(org.apache.jorphan.util.JMeterStopThreadException) JMeterStopTestNowException(org.apache.jorphan.util.JMeterStopTestNowException)

Example 5 with 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);
    }
}
Also used : AssertionResult(org.apache.jmeter.assertions.AssertionResult)

Aggregations

AssertionResult (org.apache.jmeter.assertions.AssertionResult)9 SampleResult (org.apache.jmeter.samplers.SampleResult)6 Date (java.util.Date)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 JMeterError (org.apache.jorphan.util.JMeterError)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Entry (java.util.Map.Entry)1 BadLocationException (javax.swing.text.BadLocationException)1 Style (javax.swing.text.Style)1 StyledDocument (javax.swing.text.StyledDocument)1 TreePath (javax.swing.tree.TreePath)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1 Assertion (org.apache.jmeter.assertions.Assertion)1 SampleSaveConfiguration (org.apache.jmeter.samplers.SampleSaveConfiguration)1 StatisticalSampleResult (org.apache.jmeter.samplers.StatisticalSampleResult)1 AbstractScopedAssertion (org.apache.jmeter.testelement.AbstractScopedAssertion)1 JMeterContext (org.apache.jmeter.threads.JMeterContext)1 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)1