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