Search in sources :

Example 1 with SampleException

use of org.apache.jmeter.report.core.SampleException in project jmeter by apache.

the class ExternalSampleSorter method sortAndDump.

private File sortAndDump(final List<Sample> samples, final SampleMetadata sampleMetadata) {
    long start = 0;
    if (LOG.isDebugEnabled()) {
        LOG.debug("sortAndDump(): Sorting " + samples.size() + " samples...");
        start = System.currentTimeMillis();
    }
    final List<Sample> sortedSamples = sortSamplesParallel(samples);
    if (sortedSamples.size() != samples.size()) {
        throw new SampleException("sort failed ! " + sortedSamples.size() + " != " + samples.size());
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("sortAndDump(): in " + (System.currentTimeMillis() - start) / 1000f + " s. Sorted  " + samples.size() + " samples.");
    }
    File out = getChunkFile();
    if (LOG.isDebugEnabled()) {
        LOG.debug("sortAndDump(): Dumping chunk " + out);
        start = System.currentTimeMillis();
    }
    try (CsvSampleWriter csvWriter = new CsvSampleWriter(out, sampleMetadata)) {
        for (Sample sample : sortedSamples) {
            csvWriter.write(sample);
            chunkedSampleCount.incrementAndGet();
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("sortAndDump(): in " + (System.currentTimeMillis() - start) / 1000f + " s : Dumped chunk " + out.getAbsolutePath());
    }
    return out;
}
Also used : SampleException(org.apache.jmeter.report.core.SampleException) Sample(org.apache.jmeter.report.core.Sample) CsvSampleWriter(org.apache.jmeter.report.core.CsvSampleWriter) File(java.io.File) CsvFile(org.apache.jmeter.report.core.CsvFile)

Example 2 with SampleException

use of org.apache.jmeter.report.core.SampleException 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)

Example 3 with SampleException

use of org.apache.jmeter.report.core.SampleException in project jmeter by apache.

the class ExternalSampleSorter method sortSamplesParallel.

private List<Sample> sortSamplesParallel(final List<Sample> samples) {
    int sz = samples.size();
    if (sz <= 1) {
        return samples;
    }
    int middle = sz / 2;
    final List<Sample> left = samples.subList(0, middle);
    final List<Sample> right = samples.subList(middle, sz);
    List<Sample> newLeft;
    List<Sample> newRight;
    Job<List<Sample>> jobLeft = createSortJob(left);
    Job<List<Sample>> jobRight = createSortJob(right);
    if (parallelize) {
        workQueue.add(jobLeft);
        workQueue.add(jobRight);
        try {
            newLeft = jobLeft.getResult();
            newRight = jobRight.getResult();
        } catch (InterruptedException ie) {
            // NOSONAR we throw another exception
            throw new SampleException("Unexpected interruption !", ie);
        }
    } else {
        newLeft = jobLeft.exec();
        newRight = jobRight.exec();
    }
    return merge(newLeft, newRight);
}
Also used : SampleException(org.apache.jmeter.report.core.SampleException) Sample(org.apache.jmeter.report.core.Sample) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList)

Example 4 with SampleException

use of org.apache.jmeter.report.core.SampleException in project jmeter by apache.

the class ExternalSampleSorter method sortFilesParallel.

private void sortFilesParallel(List<File> chunks, final SampleMetadata metadata, SampleProducer out) {
    int sz = chunks.size();
    if (sz > 1) {
        int middle = sz / 2;
        final List<File> left = chunks.subList(0, middle);
        final List<File> right = chunks.subList(middle, sz);
        File leftFile;
        File rightFile;
        Job<File> leftJob = createMergeJob(left, metadata);
        Job<File> rightJob = createMergeJob(right, metadata);
        if (parallelize) {
            workQueue.add(leftJob);
            workQueue.add(rightJob);
            try {
                leftFile = leftJob.getResult();
                rightFile = rightJob.getResult();
            } catch (InterruptedException ie) {
                // NOSONAR We throw an exception
                throw new SampleException("Unexpected interruption !", ie);
            }
        } else {
            leftFile = leftJob.exec();
            rightFile = rightJob.exec();
        }
        mergeFiles(metadata, leftFile, rightFile, out);
    } else {
        File f = chunks.get(0);
        try (CsvSampleReader reader = new CsvSampleReader(f, metadata)) {
            Sample sample;
            while ((sample = reader.readSample()) != null) {
                out.produce(sample, 0);
            }
        }
    }
}
Also used : SampleException(org.apache.jmeter.report.core.SampleException) Sample(org.apache.jmeter.report.core.Sample) CsvSampleReader(org.apache.jmeter.report.core.CsvSampleReader) File(java.io.File) CsvFile(org.apache.jmeter.report.core.CsvFile)

Example 5 with SampleException

use of org.apache.jmeter.report.core.SampleException in project jmeter by apache.

the class NormalizerSampleConsumer method consume.

@Override
public void consume(Sample s, int channel) {
    Date date = null;
    try {
        String tStr = s.getData(timestamp);
        if (isMillisFormat) {
            date = new Date(Long.parseLong(tStr));
        } else {
            date = dateFormat.parse(tStr);
        }
    } catch (Exception e) {
        throw new SampleException(String.format(PARSE_TIMESTAMP_EXCEPTION_MESSAGE, s.getData(timestamp), TIMESTAMP_FORMAT, s.toString()), e);
    }
    long time = date.getTime();
    int cc = sampleMetadata.getColumnCount();
    String[] data = new String[cc];
    for (int i = 0; i < cc; i++) {
        if (i == timestamp) {
            data[i] = Long.toString(time);
        } else {
            data[i] = s.getData(i);
        }
    }
    Sample rewritten = new Sample(s.getSampleRow(), sampleMetadata, data);
    super.produce(rewritten, 0);
}
Also used : SampleException(org.apache.jmeter.report.core.SampleException) Sample(org.apache.jmeter.report.core.Sample) Date(java.util.Date) SampleException(org.apache.jmeter.report.core.SampleException)

Aggregations

SampleException (org.apache.jmeter.report.core.SampleException)7 Sample (org.apache.jmeter.report.core.Sample)4 File (java.io.File)3 CsvFile (org.apache.jmeter.report.core.CsvFile)2 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 ExporterConfiguration (org.apache.jmeter.report.config.ExporterConfiguration)1 GraphConfiguration (org.apache.jmeter.report.config.GraphConfiguration)1 CsvSampleReader (org.apache.jmeter.report.core.CsvSampleReader)1 CsvSampleWriter (org.apache.jmeter.report.core.CsvSampleWriter)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