Skip to content
Snippets Groups Projects

Multithreaded report generator fix

1 file
+ 50
32
Compare changes
  • Side-by-side
  • Inline
@@ -43,21 +43,6 @@ public class ReportGeneratorNg {
*/
private final ScriptExecutionContextFactory secf;
/**
* The total number of warnings.
*/
private int totalWarnings = 0;
/**
* The total number of failures.
*/
private int totalFailures = 0;
/**
* A field that indicates if one of the lower metrics has failed.
*/
private Verdict subVerdict = Verdict.PASS;
/**
* Creates a new entity report generator.
*
@@ -75,12 +60,18 @@ public class ReportGeneratorNg {
*/
public void report(final Assignment assignment, final EntityContainer results) {
try (var ctx = this.secf.create()) {
final var countContainer = new CountContainer();
final var scripts = this.precompile(ctx, assignment);
this.report(results.getEntity(), scripts, assignment.getMetricSettings());
this.report(
results.getEntity(),
scripts,
assignment.getMetricSettings(),
countContainer
);
final var finalVerdict =
this.getFinalVerdict(assignment.getMaxFailures(), assignment.getMaxWarnings(),
results);
results, countContainer);
results.setVerdict(finalVerdict);
this.dispose(scripts.values());
@@ -98,9 +89,10 @@ public class ReportGeneratorNg {
* @param entity the entity to report on
* @param scripts the set of scripts to apply to the entity
* @param settings the settings for the metrics
* @param countContainer the number of failures and sub verdict.
*/
private void report(final Entity entity, final Map<MetricName, Script> scripts,
final Set<MetricSettings> settings) {
final Set<MetricSettings> settings, final CountContainer countContainer) {
entity.getReports().clear();
for (final var result : entity.getMetrics()) {
@@ -126,7 +118,7 @@ public class ReportGeneratorNg {
}
//final var grade = script.execute(result.getValue(), null, notes);
final var setting = this.getSettings(settings, result.getName());
final var verdict = this.getVerdict(notes, setting);
final var verdict = this.getVerdict(notes, setting, countContainer);
entity.getReports().add(
new MetricReport(result.getName(), notes, (Double) grade.orElse(null), verdict)
@@ -134,7 +126,7 @@ public class ReportGeneratorNg {
}
for (final var child : entity.getChildren()) {
this.report(child, scripts, settings);
this.report(child, scripts, settings, countContainer);
}
}
@@ -199,10 +191,12 @@ public class ReportGeneratorNg {
* Returns the verdict for a metric.
* @param notes The notes collected by the script
* @param settings the settings for the metric
* @param countContainer the number of failures and sub verdict.
* @return the verdict for the metric
*/
private Verdict getVerdict(final NoteCollection notes,
final @Nullable MetricSettings settings) {
final @Nullable MetricSettings settings,
final CountContainer countContainer) {
var maxFailures = 0;
var maxWarnings = 0;
@@ -214,17 +208,17 @@ public class ReportGeneratorNg {
// Count how many warnings and failures this metric has
final var warnings = notes.getNotesBySeverity(Severity.WARNING).size();
final var failures = notes.getNotesBySeverity(Severity.FAILURE).size();
this.totalFailures += failures;
this.totalWarnings += warnings;
countContainer.totalFailures += failures;
countContainer.totalWarnings += warnings;
// Return the verdict for this metric and set the global verdict accordingly
if (failures > maxFailures) {
this.subVerdict = Verdict.FAIL;
countContainer.subVerdict = Verdict.FAIL;
return Verdict.FAIL;
}
if (warnings > maxWarnings) {
if (this.subVerdict != Verdict.FAIL) {
this.subVerdict = Verdict.WARN;
if (countContainer.subVerdict != Verdict.FAIL) {
countContainer.subVerdict = Verdict.WARN;
}
return Verdict.WARN;
}
@@ -236,33 +230,57 @@ public class ReportGeneratorNg {
* @param maxFailures the maximum amount of failures for this submission
* @param maxWarnings the maximum amount of warnings for this submission
* @param container The entity container
* @param countContainer the number of failures and sub verdict.
* @return the verdict for the submission
*/
private Verdict getFinalVerdict(final @Nullable Integer maxFailures,
final @Nullable Integer maxWarnings,
final EntityContainer container) {
final EntityContainer container,
final CountContainer countContainer) {
if (container.hadException()) {
return Verdict.ERROR;
}
if ((maxFailures == null) || ((maxWarnings == null))) {
return this.subVerdict;
return countContainer.subVerdict;
}
if (this.subVerdict == Verdict.FAIL) {
if (countContainer.subVerdict == Verdict.FAIL) {
return Verdict.FAIL;
}
if (this.totalFailures > maxFailures) {
if (countContainer.totalFailures > maxFailures) {
return Verdict.FAIL;
}
if (this.subVerdict == Verdict.WARN) {
if (countContainer.subVerdict == Verdict.WARN) {
return Verdict.WARN;
}
if (this.totalWarnings > maxWarnings) {
if (countContainer.totalWarnings > maxWarnings) {
return Verdict.WARN;
}
return Verdict.PASS;
}
/**
* A container to store the data beloning to the current submission.
*/
private static class CountContainer {
/**
* The total number of failures for this submission.
*/
private Integer totalFailures = 0;
/**
* The total number of warnings for this submission.
*/
private Integer totalWarnings = 0;
/**
* The sub verdict of the submission.
*/
private Verdict subVerdict = Verdict.PASS;
}
}
Loading