diff options
Diffstat (limited to 'vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/TestReport.java')
-rw-r--r-- | vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/TestReport.java | 66 |
1 files changed, 43 insertions, 23 deletions
diff --git a/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/TestReport.java b/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/TestReport.java index b3ca47e2480..9a1200d0bf3 100644 --- a/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/TestReport.java +++ b/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/TestReport.java @@ -1,7 +1,13 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.testrunner; -import java.util.Collection; +import com.yahoo.exception.ExceptionUtils; +import com.yahoo.slime.Cursor; +import com.yahoo.slime.Slime; +import com.yahoo.slime.SlimeUtils; +import com.yahoo.yolean.Exceptions; + +import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.List; import java.util.logging.LogRecord; @@ -10,16 +16,15 @@ import java.util.logging.LogRecord; * @author mortent */ public class TestReport { - - final long totalCount; - final long successCount; - final long failedCount; - final long ignoredCount; - final long abortedCount; - final List<Failure> failures; - final List<LogRecord> logLines; - - private TestReport(long totalCount, long successCount, long failedCount, long ignoredCount, long abortedCount, List<Failure> failures, List<LogRecord> logLines) { + private final long totalCount; + private final long successCount; + private final long failedCount; + private final long ignoredCount; + private final long abortedCount; + private final List<Failure> failures; + private final List<LogRecord> logLines; + + public TestReport(long totalCount, long successCount, long failedCount, long ignoredCount, long abortedCount, List<Failure> failures, List<LogRecord> logLines) { this.totalCount = totalCount; this.successCount = successCount; this.failedCount = failedCount; @@ -29,6 +34,31 @@ public class TestReport { this.logLines = logLines; } + private void serializeFailure(Failure failure, Cursor slime) { + var testIdentifier = failure.testId(); + slime.setString("testName", failure.testId()); + slime.setString("testError",failure.exception().getMessage()); + slime.setString("exception", ExceptionUtils.getStackTraceAsString(failure.exception())); + } + + public String toJson() { + var slime = new Slime(); + var root = slime.setObject(); + var summary = root.setObject("summary"); + summary.setLong("total", totalCount); + summary.setLong("success", successCount); + summary.setLong("failed", failedCount); + summary.setLong("ignored", ignoredCount); + summary.setLong("aborted", abortedCount); + var failureRoot = summary.setArray("failures"); + this.failures.forEach(failure -> serializeFailure(failure, failureRoot.addObject())); + + var output = root.setArray("output"); + logLines.forEach(lr -> output.addString(lr.getMessage())); + + return Exceptions.uncheck(() -> new String(SlimeUtils.toJsonBytes(slime), StandardCharsets.UTF_8)); + } + public List<LogRecord> logLines() { return logLines; } @@ -41,9 +71,7 @@ public class TestReport { return new Builder(); } - public static class Builder { - private long totalCount; private long successCount; private long failedCount; @@ -60,22 +88,18 @@ public class TestReport { this.totalCount = totalCount; return this; } - public Builder withSuccessCount(long successCount) { this.successCount = successCount; return this; } - public Builder withFailedCount(long failedCount) { this.failedCount = failedCount; return this; } - public Builder withIgnoredCount(long ignoredCount) { this.ignoredCount = ignoredCount; return this; } - public Builder withAbortedCount(long abortedCount) { this.abortedCount = abortedCount; return this; @@ -86,14 +110,12 @@ public class TestReport { return this; } - public Builder withLogs(Collection<LogRecord> logRecords) { - this.logLines = List.copyOf(logRecords); + public Builder withLogs(List<LogRecord> logRecords) { + this.logLines = logRecords; return this; } - } - public static class Failure { private final String testId; private final Throwable exception; @@ -110,7 +132,5 @@ public class TestReport { public Throwable exception() { return exception; } - } - } |