use of org.apache.jmeter.report.processor.SampleContext in project jmeter by apache.
the class ReportGenerator method generate.
/**
* Generate dashboard reports using the data from the specified CSV File.
*
* @throws GenerationException
* when the generation failed
*/
public void generate() throws GenerationException {
if (resultCollector != null) {
log.info("Flushing result collector before report Generation");
resultCollector.flushFile();
}
log.debug("Start report generation");
File tmpDir = configuration.getTempDirectory();
boolean tmpDirCreated = createTempDir(tmpDir);
// Build consumers chain
SampleContext sampleContext = new SampleContext();
sampleContext.setWorkingDirectory(tmpDir);
SampleSource source = new CsvFileSampleSource(testFile, CSV_DEFAULT_SEPARATOR);
source.setSampleContext(sampleContext);
NormalizerSampleConsumer normalizer = new NormalizerSampleConsumer();
normalizer.setName(NORMALIZER_CONSUMER_NAME);
FilterConsumer dateRangeConsumer = createFilterByDateRange();
dateRangeConsumer.addSampleConsumer(createBeginDateConsumer());
dateRangeConsumer.addSampleConsumer(createEndDateConsumer());
FilterConsumer nameFilter = createNameFilter();
FilterConsumer excludeControllerFilter = createExcludeControllerFilter();
nameFilter.addSampleConsumer(excludeControllerFilter);
dateRangeConsumer.addSampleConsumer(nameFilter);
normalizer.addSampleConsumer(dateRangeConsumer);
source.addSampleConsumer(normalizer);
// Get graph configurations
Map<String, GraphConfiguration> graphConfigurations = configuration.getGraphConfigurations();
// Process configuration to build graph consumers
for (Map.Entry<String, GraphConfiguration> entryGraphCfg : graphConfigurations.entrySet()) {
addGraphConsumer(nameFilter, excludeControllerFilter, entryGraphCfg);
}
// Generate data
log.debug("Start samples processing");
try {
// NOSONAR
source.run();
} catch (SampleException ex) {
throw new GenerationException("Error while processing samples:" + ex.getMessage(), ex);
}
log.debug("End of samples processing");
log.debug("Start data exporting");
// Process configuration to build data exporters
String key;
ExporterConfiguration value;
for (Map.Entry<String, ExporterConfiguration> entry : configuration.getExportConfigurations().entrySet()) {
key = entry.getKey();
value = entry.getValue();
if (log.isInfoEnabled()) {
log.info("Exporting data using exporter:'{}' of className:'{}'", key, value.getClassName());
}
exportData(sampleContext, key, value);
}
log.debug("End of data exporting");
removeTempDir(tmpDir, tmpDirCreated);
log.debug("End of report generation");
}
Aggregations