use of org.apache.jmeter.report.core.CsvSampleReader in project jmeter by apache.
the class CsvFileSampleSource method produce.
/**
* Read all input CSV files and produce their samples on registered sample
* consumers
*/
private void produce() {
SampleContext context = getSampleContext();
Validate.validState(context != null, "Set a sample context before producing samples.");
for (int i = 0; i < csvReaders.length; i++) {
long sampleCount = 0;
long start = now();
CsvSampleReader csvReader = csvReaders[i];
producer.setSampleContext(context);
producer.setProducedMetadata(csvReader.getMetadata(), i);
producer.setChannelAttribute(i, SOURCE_FILE_ATTRIBUTE, inputFiles[i]);
producer.startProducing();
try {
Sample s = null;
while ((s = csvReader.readSample()) != null) {
producer.produce(s, i);
sampleCount++;
}
} finally {
producer.stopProducing();
csvReader.close();
}
if (LOG.isInfoEnabled()) {
LOG.info("produce(): " + sampleCount + " samples produced in " + time(now() - start) + " on channel " + i);
}
}
}
use of org.apache.jmeter.report.core.CsvSampleReader 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.CsvSampleReader in project jmeter by apache.
the class ExternalSampleSorter method mergeFiles.
private void mergeFiles(SampleMetadata metadata, File left, File right, SampleProducer out) {
try (CsvSampleReader l = new CsvSampleReader(left, metadata);
CsvSampleReader r = new CsvSampleReader(right, metadata)) {
while (l.hasNext() || r.hasNext()) {
if (l.hasNext() && r.hasNext()) {
Sample firstLeft = l.peek();
Sample firstRight = r.peek();
if (leftBeforeRight(firstLeft, firstRight)) {
out.produce(firstLeft, 0);
l.readSample();
} else {
out.produce(firstRight, 0);
r.readSample();
}
} else if (l.hasNext()) {
out.produce(l.readSample(), 0);
} else if (r.hasNext()) {
out.produce(r.readSample(), 0);
}
}
}
}
use of org.apache.jmeter.report.core.CsvSampleReader in project jmeter by apache.
the class ExternalSampleSorter method mergeFiles.
private void mergeFiles(SampleMetadata metadata, File left, File right, File out, boolean writeHeader) {
if (out == null) {
out = getChunkFile();
}
try (CsvSampleWriter csvWriter = new CsvSampleWriter(out, metadata);
CsvSampleReader l = new CsvSampleReader(left, metadata);
CsvSampleReader r = new CsvSampleReader(right, metadata)) {
if (writeHeader) {
csvWriter.writeHeader();
}
while (l.hasNext() || r.hasNext()) {
if (l.hasNext() && r.hasNext()) {
Sample firstLeft = l.peek();
Sample firstRight = r.peek();
if (leftBeforeRight(firstLeft, firstRight)) {
csvWriter.write(firstLeft);
l.readSample();
} else {
csvWriter.write(firstRight);
r.readSample();
}
} else if (l.hasNext()) {
csvWriter.write(l.readSample());
} else if (r.hasNext()) {
csvWriter.write(r.readSample());
}
}
}
}
Aggregations