Search in sources :

Example 1 with SampleContext

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");
}
Also used : NormalizerSampleConsumer(org.apache.jmeter.report.processor.NormalizerSampleConsumer) SampleException(org.apache.jmeter.report.core.SampleException) GraphConfiguration(org.apache.jmeter.report.config.GraphConfiguration) FilterConsumer(org.apache.jmeter.report.processor.FilterConsumer) ExporterConfiguration(org.apache.jmeter.report.config.ExporterConfiguration) SampleContext(org.apache.jmeter.report.processor.SampleContext) CsvFileSampleSource(org.apache.jmeter.report.processor.CsvFileSampleSource) CsvFileSampleSource(org.apache.jmeter.report.processor.CsvFileSampleSource) SampleSource(org.apache.jmeter.report.processor.SampleSource) File(java.io.File) Map(java.util.Map)

Aggregations

File (java.io.File)1 Map (java.util.Map)1 ExporterConfiguration (org.apache.jmeter.report.config.ExporterConfiguration)1 GraphConfiguration (org.apache.jmeter.report.config.GraphConfiguration)1 SampleException (org.apache.jmeter.report.core.SampleException)1 CsvFileSampleSource (org.apache.jmeter.report.processor.CsvFileSampleSource)1 FilterConsumer (org.apache.jmeter.report.processor.FilterConsumer)1 NormalizerSampleConsumer (org.apache.jmeter.report.processor.NormalizerSampleConsumer)1 SampleContext (org.apache.jmeter.report.processor.SampleContext)1 SampleSource (org.apache.jmeter.report.processor.SampleSource)1