Search in sources :

Example 81 with SampleResult

use of org.apache.jmeter.samplers.SampleResult in project jmeter by apache.

the class HtmlExtractor method process.

/**
 * Parses the response data using CSS/JQuery expressions and saving the results
 * into variables for use later in the test.
 *
 * @see org.apache.jmeter.processor.PostProcessor#process()
 */
@Override
public void process() {
    JMeterContext context = getThreadContext();
    SampleResult previousResult = context.getPreviousResult();
    if (previousResult == null) {
        return;
    }
    if (log.isDebugEnabled()) {
        log.debug("HtmlExtractor {}: processing result", getName());
    }
    // Fetch some variables
    JMeterVariables vars = context.getVariables();
    String refName = getRefName();
    String expression = getExpression();
    String attribute = getAttribute();
    int matchNumber = getMatchNumber();
    final String defaultValue = getDefaultValue();
    if (defaultValue.length() > 0 || isEmptyDefaultValue()) {
        // Only replace default if it is provided or empty default value is explicitly requested
        vars.put(refName, defaultValue);
    }
    try {
        List<String> matches = extractMatchingStrings(vars, expression, attribute, matchNumber, previousResult);
        int prevCount = 0;
        String prevString = vars.get(refName + REF_MATCH_NR);
        if (prevString != null) {
            // ensure old value is not left defined
            vars.remove(refName + REF_MATCH_NR);
            try {
                prevCount = Integer.parseInt(prevString);
            } catch (NumberFormatException nfe) {
                if (log.isWarnEnabled()) {
                    log.warn("{}: Could not parse number: '{}'.", getName(), prevString);
                }
            }
        }
        // Number of refName_n variable sets to keep
        int matchCount = 0;
        String match;
        if (matchNumber >= 0) {
            // Original match behaviour
            match = getCorrectMatch(matches, matchNumber);
            if (match != null) {
                vars.put(refName, match);
            }
        } else // < 0 means we save all the matches
        {
            matchCount = matches.size();
            // Save the count
            vars.put(refName + REF_MATCH_NR, Integer.toString(matchCount));
            for (int i = 1; i <= matchCount; i++) {
                match = getCorrectMatch(matches, i);
                if (match != null) {
                    final String refNameN = refName + UNDERSCORE + i;
                    vars.put(refNameN, match);
                }
            }
        }
        // Remove any left-over variables
        for (int i = matchCount + 1; i <= prevCount; i++) {
            final String refNameN = refName + UNDERSCORE + i;
            vars.remove(refNameN);
        }
    } catch (RuntimeException e) {
        if (log.isWarnEnabled()) {
            log.warn("{}: Error while generating result. {}", getName(), e.toString());
        }
    }
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) JMeterContext(org.apache.jmeter.threads.JMeterContext) SampleResult(org.apache.jmeter.samplers.SampleResult)

Example 82 with SampleResult

use of org.apache.jmeter.samplers.SampleResult in project jmeter by apache.

the class RespTimeGraphVisualizer method actionPerformed.

@Override
public void actionPerformed(ActionEvent event) {
    boolean forceReloadData = false;
    final Object eventSource = event.getSource();
    if (eventSource == displayButton) {
        actionMakeGraph();
    } else if (eventSource == saveGraph) {
        saveGraphToFile = true;
        try {
            ActionRouter.getInstance().getAction(ActionNames.SAVE_GRAPHICS, SaveGraphics.class.getName()).doAction(new ActionEvent(this, event.getID(), ActionNames.SAVE_GRAPHICS));
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    } else if (eventSource == syncWithName) {
        graphTitle.setText(getName());
    } else if (eventSource == dynamicGraphSize) {
        enableDynamicGraph(dynamicGraphSize.isSelected());
    } else if (eventSource == samplerSelection) {
        enableSamplerSelection(samplerSelection.isSelected());
        if (!samplerSelection.isSelected()) {
            // Force reload data
            forceReloadData = true;
        }
    }
    // Not 'else if' because forceReloadData
    if (eventSource == applyFilterBtn || eventSource == intervalButton || forceReloadData) {
        if (eventSource == intervalButton) {
            intervalValue = Integer.parseInt(intervalField.getText());
        }
        if (eventSource == applyFilterBtn && samplerSelection.isSelected() && samplerMatchLabel.getText() != null && samplerMatchLabel.getText().length() > 0) {
            pattern = createPattern(samplerMatchLabel.getText());
        } else if (forceReloadData) {
            pattern = null;
        }
        if (getFile() != null && getFile().length() > 0) {
            // Reload data from file
            clearData();
            FilePanel filePanel = (FilePanel) getFilePanel();
            filePanel.actionPerformed(event);
        } else {
            // Reload data form internal list of results
            synchronized (lockInterval) {
                if (internalList.size() >= 2) {
                    List<RespTimeGraphDataBean> tempList = new ArrayList<>();
                    tempList.addAll(internalList);
                    this.clearData();
                    for (RespTimeGraphDataBean data : tempList) {
                        SampleResult sr = new SampleResult(data.getStartTime(), data.getTime());
                        sr.setSampleLabel(data.getSamplerLabel());
                        this.add(sr);
                    }
                }
            }
        }
    }
}
Also used : ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) FilePanel(org.apache.jmeter.gui.util.FilePanel) SampleResult(org.apache.jmeter.samplers.SampleResult) SaveGraphics(org.apache.jmeter.gui.action.SaveGraphics) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 83 with SampleResult

use of org.apache.jmeter.samplers.SampleResult in project jmeter by apache.

the class GraphiteBackendListenerClient method handleSampleResults.

@Override
public void handleSampleResults(List<SampleResult> sampleResults, BackendListenerContext context) {
    boolean samplersToFilterMatch;
    synchronized (LOCK) {
        UserMetric userMetrics = getUserMetrics();
        for (SampleResult sampleResult : sampleResults) {
            userMetrics.add(sampleResult);
            if (!summaryOnly) {
                if (useRegexpForSamplersList) {
                    Matcher matcher = pattern.matcher(sampleResult.getSampleLabel());
                    samplersToFilterMatch = matcher.matches();
                } else {
                    samplersToFilterMatch = samplersToFilter.contains(sampleResult.getSampleLabel());
                }
                if (samplersToFilterMatch) {
                    SamplerMetric samplerMetric = getSamplerMetric(sampleResult.getSampleLabel());
                    samplerMetric.add(sampleResult);
                }
            }
            getSamplerMetric(CUMULATED_METRICS).addCumulated(sampleResult);
        }
    }
}
Also used : UserMetric(org.apache.jmeter.visualizers.backend.UserMetric) Matcher(java.util.regex.Matcher) SampleResult(org.apache.jmeter.samplers.SampleResult) SamplerMetric(org.apache.jmeter.visualizers.backend.SamplerMetric)

Example 84 with SampleResult

use of org.apache.jmeter.samplers.SampleResult in project jmeter by apache.

the class InfluxdbBackendListenerClient method handleSampleResults.

@Override
public void handleSampleResults(List<SampleResult> sampleResults, BackendListenerContext context) {
    synchronized (LOCK) {
        UserMetric userMetrics = getUserMetrics();
        for (SampleResult sampleResult : sampleResults) {
            userMetrics.add(sampleResult);
            Matcher matcher = samplersToFilter.matcher(sampleResult.getSampleLabel());
            if (!summaryOnly && matcher.find()) {
                SamplerMetric samplerMetric = getSamplerMetricInfluxdb(sampleResult.getSampleLabel());
                samplerMetric.add(sampleResult);
            }
            SamplerMetric cumulatedMetrics = getSamplerMetricInfluxdb(CUMULATED_METRICS);
            cumulatedMetrics.addCumulated(sampleResult);
        }
    }
}
Also used : UserMetric(org.apache.jmeter.visualizers.backend.UserMetric) Matcher(java.util.regex.Matcher) SampleResult(org.apache.jmeter.samplers.SampleResult) SamplerMetric(org.apache.jmeter.visualizers.backend.SamplerMetric)

Example 85 with SampleResult

use of org.apache.jmeter.samplers.SampleResult in project jmeter by apache.

the class TableVisualizer method collectNewSamples.

private void collectNewSamples() {
    synchronized (calc) {
        SampleResult res = null;
        while (!newRows.isEmpty()) {
            res = newRows.pop();
            calc.addSample(res);
            int count = calc.getCount();
            TableSample newS = new TableSample(count, res.getSampleCount(), res.getStartTime(), res.getThreadName(), res.getSampleLabel(), res.getTime(), res.isSuccessful(), res.getBytesAsLong(), res.getSentBytes(), res.getLatency(), res.getConnectTime());
            model.addRow(newS);
        }
        if (res == null) {
            return;
        }
        updateTextFields(res);
        if (autoscroll.isSelected()) {
            table.scrollRectToVisible(table.getCellRect(table.getRowCount() - 1, 0, true));
        }
    }
}
Also used : SampleResult(org.apache.jmeter.samplers.SampleResult)

Aggregations

SampleResult (org.apache.jmeter.samplers.SampleResult)379 Test (org.junit.Test)83 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)71 Test (org.junit.jupiter.api.Test)59 JMeterContext (org.apache.jmeter.threads.JMeterContext)47 BeforeEach (org.junit.jupiter.api.BeforeEach)36 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)34 SampleEvent (org.apache.jmeter.samplers.SampleEvent)30 Sampler (org.apache.jmeter.samplers.Sampler)30 AssertionResult (org.apache.jmeter.assertions.AssertionResult)27 ArrayList (java.util.ArrayList)26 CompoundVariable (org.apache.jmeter.engine.util.CompoundVariable)20 HTTPSamplerBase (org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)20 IOException (java.io.IOException)17 Arguments (org.apache.jmeter.config.Arguments)16 MethodSource (org.junit.jupiter.params.provider.MethodSource)13 CorrectedResultCollector (kg.apc.jmeter.vizualizers.CorrectedResultCollector)12 URL (java.net.URL)9 File (java.io.File)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7