com.lazerycode.jmeter.results.CSVFileScanner Maven / Gradle / Ivy
package com.lazerycode.jmeter.results;
import com.fasterxml.jackson.databind.MappingIterator;
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
import org.apache.maven.plugin.MojoExecutionException;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
public class CSVFileScanner {
private static final String ROW_NAME_SUCCESS = "success";
private static final String ROW_NAME_FAILURE_MESSAGE = "failureMessage";
private static final CsvMapper CSV_MAPPER = new CsvMapper();
private static final int DEFAULT_BUFFER_SIZE = 8 * 1024;
/**
* Scans a csv file to calculate success/failure counts.
* Will also take a list of failure messages to search for
*
* @param file The file to parse
* @param values Failure messages to search for
* @return A map of failure messages/associated count for failure messages explicitly searched for
* @throws MojoExecutionException When an error occurs while reading the file
*/
protected static CSVScanResult scanCsvForValues(File file, List values) throws MojoExecutionException {
Map specificFailureMessages = values.stream().collect(Collectors.toMap(Function.identity(), (a) -> 0));
int successCount = 0, failureCount = 0;
try {
char separator = computeSeparator(file);
CsvSchema schema = CsvSchema.emptySchema().withHeader().withColumnSeparator(separator);
try (FileReader fr = new FileReader(file); BufferedReader reader = new BufferedReader(fr, DEFAULT_BUFFER_SIZE)) {
MappingIterator
© 2015 - 2025 Weber Informatics LLC | Privacy Policy