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());
}
}
}
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);
}
}
}
}
}
}
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);
}
}
}
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);
}
}
}
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));
}
}
}
Aggregations