Skip to content

Commit

Permalink
New version 0.2.6 for csv report function
Browse files Browse the repository at this point in the history
ENB-4946
  • Loading branch information
Matthias Clasen committed Dec 7, 2020
1 parent 4256296 commit b533d9f
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>net.seibertmedia.jmeter</groupId>
<artifactId>jmeter-statistical-assertions</artifactId>
<version>0.2.5</version>
<version>0.2.6</version>

<name>jmeter-statistical-assertions</name>
<!-- FIXME change it to the project's website -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

public enum AppCommand {
report("Create a report", new ReportCommandFunction(), createParameter("filename")),
csvReport("Create a csv report", new ReportCSVCommandFunction(), createParameter("filename")),
check("Check", new CheckCommandFunction(), createParameter("filename"), createParameter("assertions-filename"));

private final String description;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package net.seibertmedia.jmeter.commands;

import static net.seibertmedia.jmeter.util.JMeterStatistic.Getter.median;
import static net.seibertmedia.jmeter.util.StatisticsParser.createStatisticsFromFilename;

import java.util.Map;

import net.seibertmedia.jmeter.util.JMeterStatistics;
import net.seibertmedia.jmeter.util.JMeterStatisticsCSVReport;

public class ReportCSVCommandFunction implements AppCommandFunction {
@Override
public void apply(Map<String, String> args) throws Exception {
JMeterStatistics elapsedStatistics = createStatisticsFromFilename(args.get("filename"), "elapsed");
JMeterStatisticsCSVReport jMeterStatisticsCSVReport = new JMeterStatisticsCSVReport(elapsedStatistics);

jMeterStatisticsCSVReport.addValueColumn(median);

jMeterStatisticsCSVReport.printReport();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package net.seibertmedia.jmeter.util;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class JMeterStatisticsCSVReport {

private final JMeterStatistics jMeterStatistics;
private final List<JMeterStatistic.Getter> columns = new ArrayList<>();

public JMeterStatisticsCSVReport(JMeterStatistics jMeterStatistics) {
this.jMeterStatistics = jMeterStatistics;
}

public void addValueColumn(JMeterStatistic.Getter columnGetter) {
columns.add(columnGetter);
}

public void printReport() {
printReport(System.out);
}

protected void printReport(PrintStream printStream) {

for (String label : jMeterStatistics.getLabels()) {
JMeterStatistic statisticsForLabel = jMeterStatistics.getStatisticForLabel(label);

final Double[] values = columns.stream()
.map(column -> column.getGetter().apply(statisticsForLabel))
.collect(Collectors.toList()).toArray(new Double[columns.size()]);

printStream.print(label);
printStream.printf(";%.0f\n", (Object[]) values);
}
}

}

0 comments on commit b533d9f

Please sign in to comment.