summaryrefslogtreecommitdiffstats
path: root/vespa-osgi-testrunner/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'vespa-osgi-testrunner/src/main/java')
-rw-r--r--vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/AggregateTestRunner.java119
-rw-r--r--vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/JunitRunner.java60
-rw-r--r--vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/TestReport.java66
-rw-r--r--vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/TestRunner.java26
-rw-r--r--vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/TestRunnerHandler.java165
-rw-r--r--vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/legacy/LegacyTestRunner.java22
-rw-r--r--vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/legacy/TestProfile.java30
-rw-r--r--vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/legacy/package-info.java9
8 files changed, 249 insertions, 248 deletions
diff --git a/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/AggregateTestRunner.java b/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/AggregateTestRunner.java
new file mode 100644
index 00000000000..82c1f7194d0
--- /dev/null
+++ b/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/AggregateTestRunner.java
@@ -0,0 +1,119 @@
+// 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.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+
+import static java.util.stream.Collectors.toUnmodifiableList;
+
+/**
+ * @author jonmv
+ */
+public class AggregateTestRunner implements TestRunner {
+
+ static final TestRunner noRunner = new TestRunner() {
+ final LogRecord record = new LogRecord(Level.WARNING, "No tests were found");
+ @Override public Collection<LogRecord> getLog(long after) { return List.of(record); }
+ @Override public Status getStatus() { return Status.FAILURE; }
+ @Override public CompletableFuture<?> test(Suite suite, byte[] config) { return CompletableFuture.completedFuture(null); }
+ @Override public boolean isSupported() { return true; }
+ };
+
+ private final List<TestRunner> wrapped;
+ private final AtomicInteger current = new AtomicInteger(-1);
+
+ private AggregateTestRunner(List<TestRunner> testRunners) {
+ this.wrapped = testRunners;
+ }
+
+ public static TestRunner of(Collection<TestRunner> testRunners) {
+ List<TestRunner> supported = testRunners.stream().filter(TestRunner::isSupported).collect(toUnmodifiableList());
+ return supported.isEmpty() ? noRunner : new AggregateTestRunner(supported);
+ }
+
+ @Override
+ public Collection<LogRecord> getLog(long after) {
+ ArrayList<LogRecord> records = new ArrayList<>();
+ for (int i = 0; i <= current.get() && i < wrapped.size(); i++)
+ records.addAll(wrapped.get(i).getLog(after));
+
+ return records;
+ }
+
+ @Override
+ public Status getStatus() {
+ if (current.get() == -1)
+ return Status.NOT_STARTED;
+
+ boolean failed = false;
+ for (int i = 0; i <= current.get(); i++) {
+ if (i == wrapped.size())
+ return failed ? Status.FAILURE : Status.SUCCESS;
+
+ switch (wrapped.get(i).getStatus()) {
+ case ERROR: return Status.ERROR;
+ case FAILURE: failed = true;
+ }
+ }
+ return Status.RUNNING;
+ }
+
+ @Override
+ public CompletableFuture<?> test(Suite suite, byte[] config) {
+ if (0 <= current.get() && current.get() < wrapped.size())
+ throw new IllegalStateException("Tests already running, should not attempt to start now");
+
+ current.set(-1);
+ CompletableFuture<?> aggregate = new CompletableFuture<>();
+ CompletableFuture<?> vessel = CompletableFuture.completedFuture(null);
+ runNext(suite, config, vessel, aggregate);
+ return aggregate;
+ }
+
+ private void runNext(Suite suite, byte[] config, CompletableFuture<?> vessel, CompletableFuture<?> aggregate) {
+ vessel.whenComplete((__, ___) -> {
+ int next = current.incrementAndGet();
+ if (next == wrapped.size())
+ aggregate.complete(null);
+ else
+ runNext(suite, config, wrapped.get(next).test(suite, config), aggregate);
+ });
+ }
+
+ @Override
+ public boolean isSupported() {
+ return wrapped.stream().anyMatch(TestRunner::isSupported);
+ }
+
+ @Override
+ public TestReport getReport() {
+ return wrapped.stream().map(TestRunner::getReport).filter(Objects::nonNull)
+ .reduce(AggregateTestRunner::merge).orElse(null);
+ }
+
+ static TestReport merge(TestReport first, TestReport second) {
+ return TestReport.builder()
+ .withAbortedCount(first.abortedCount + second.abortedCount)
+ .withFailedCount(first.failedCount + second.failedCount)
+ .withIgnoredCount(first.ignoredCount + second.ignoredCount)
+ .withSuccessCount(first.successCount + second.successCount)
+ .withTotalCount(first.totalCount + second.totalCount)
+ .withFailures(merged(first.failures, second.failures))
+ .withLogs(merged(first.logLines, second.logLines))
+ .build();
+ }
+
+ static <T> List<T> merged(List<T> first, List<T> second) {
+ ArrayList<T> merged = new ArrayList<>();
+ merged.addAll(first);
+ merged.addAll(second);
+ return merged;
+ }
+
+}
diff --git a/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/JunitRunner.java b/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/JunitRunner.java
index 87b98c8efc1..6aa36c62416 100644
--- a/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/JunitRunner.java
+++ b/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/JunitRunner.java
@@ -11,7 +11,6 @@ import com.yahoo.component.AbstractComponent;
import com.yahoo.io.IOUtils;
import com.yahoo.jdisc.application.OsgiFramework;
import com.yahoo.vespa.defaults.Defaults;
-import com.yahoo.vespa.testrunner.legacy.LegacyTestRunner;
import org.junit.jupiter.engine.JupiterTestEngine;
import org.junit.platform.engine.discovery.DiscoverySelectors;
import org.junit.platform.launcher.Launcher;
@@ -26,12 +25,13 @@ import org.osgi.framework.BundleContext;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.Charset;
-import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import java.util.Optional;
+import java.util.SortedMap;
import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
@@ -44,9 +44,10 @@ import java.util.stream.Stream;
public class JunitRunner extends AbstractComponent implements TestRunner {
private static final Logger logger = Logger.getLogger(JunitRunner.class.getName());
+ private final SortedMap<Long, LogRecord> logRecords = new ConcurrentSkipListMap<>();
private final BundleContext bundleContext;
private final TestRuntimeProvider testRuntimeProvider;
- private volatile Future<TestReport> execution;
+ private volatile CompletableFuture<TestReport> execution;
@Inject
public JunitRunner(OsgiFramework osgiFramework,
@@ -84,12 +85,23 @@ public class JunitRunner extends AbstractComponent implements TestRunner {
credentialsRoot.ifPresent(root -> System.setProperty("vespa.test.credentials.root", root));
}
+ private static TestDescriptor.TestCategory toCategory(TestRunner.Suite testProfile) {
+ switch(testProfile) {
+ case SYSTEM_TEST: return TestDescriptor.TestCategory.systemtest;
+ case STAGING_SETUP_TEST: return TestDescriptor.TestCategory.stagingsetuptest;
+ case STAGING_TEST: return TestDescriptor.TestCategory.stagingtest;
+ case PRODUCTION_TEST: return TestDescriptor.TestCategory.productiontest;
+ default: throw new RuntimeException("Unknown test profile: " + testProfile.name());
+ }
+ }
+
@Override
- public void executeTests(TestDescriptor.TestCategory category, byte[] testConfig) {
- if (execution != null && !execution.isDone()) {
+ public CompletableFuture<?> test(Suite suite, byte[] testConfig) {
+ if (execution != null && ! execution.isDone()) {
throw new IllegalStateException("Test execution already in progress");
}
try {
+ logRecords.clear();
testRuntimeProvider.initialize(testConfig);
Optional<Bundle> testBundle = findTestBundle();
if (testBundle.isEmpty()) {
@@ -100,10 +112,16 @@ public class JunitRunner extends AbstractComponent implements TestRunner {
if (testDescriptor.isEmpty()) {
throw new RuntimeException("Could not find test descriptor");
}
- execution = CompletableFuture.supplyAsync(() -> launchJunit(loadClasses(testBundle.get(), testDescriptor.get(), category)));
+ execution = CompletableFuture.supplyAsync(() -> launchJunit(loadClasses(testBundle.get(), testDescriptor.get(), toCategory(suite))));
} catch (Exception e) {
execution = CompletableFuture.completedFuture(createReportWithFailedInitialization(e));
}
+ return execution;
+ }
+
+ @Override
+ public Collection<LogRecord> getLog(long after) {
+ return logRecords.tailMap(after + 1).values();
}
private static TestReport createReportWithFailedInitialization(Exception exception) {
@@ -175,8 +193,7 @@ public class JunitRunner extends AbstractComponent implements TestRunner {
Launcher launcher = LauncherFactory.create(launcherConfig);
// Create log listener:
- var logLines = new ArrayList<LogRecord>();
- var logListener = VespaJunitLogListener.forBiConsumer((t, m) -> log(logLines, m.get(), t));
+ var logListener = VespaJunitLogListener.forBiConsumer((t, m) -> log(logRecords, m.get(), t));
// Create a summary listener:
var summaryListener = new SummaryGeneratingListener();
launcher.registerTestExecutionListeners(logListener, summaryListener);
@@ -193,14 +210,14 @@ public class JunitRunner extends AbstractComponent implements TestRunner {
.withIgnoredCount(report.getTestsSkippedCount())
.withFailedCount(report.getTestsFailedCount())
.withFailures(failures)
- .withLogs(logLines)
+ .withLogs(logRecords.values())
.build();
}
- private void log(List<LogRecord> logs, String message, Throwable t) {
+ private void log(SortedMap<Long, LogRecord> logs, String message, Throwable t) {
LogRecord logRecord = new LogRecord(Level.INFO, message);
Optional.ofNullable(t).ifPresent(logRecord::setThrown);
- logs.add(logRecord);
+ logs.put(logRecord.getSequenceNumber(), logRecord);
}
@Override
@@ -209,20 +226,19 @@ public class JunitRunner extends AbstractComponent implements TestRunner {
}
@Override
- public LegacyTestRunner.Status getStatus() {
- if (execution == null) return LegacyTestRunner.Status.NOT_STARTED;
- if (!execution.isDone()) return LegacyTestRunner.Status.RUNNING;
+ public TestRunner.Status getStatus() {
+ if (execution == null) return TestRunner.Status.NOT_STARTED;
+ if (!execution.isDone()) return TestRunner.Status.RUNNING;
try {
TestReport report = execution.get();
if (report.isSuccess()) {
- return LegacyTestRunner.Status.SUCCESS;
+ return TestRunner.Status.SUCCESS;
} else {
- return LegacyTestRunner.Status.FAILURE;
+ return TestRunner.Status.FAILURE;
}
} catch (InterruptedException|ExecutionException e) {
logger.log(Level.WARNING, "Error while getting test report", e);
- // Return FAILURE to enforce getting the test report from the caller.
- return LegacyTestRunner.Status.FAILURE;
+ return TestRunner.Status.ERROR;
}
}
@@ -242,10 +258,4 @@ public class JunitRunner extends AbstractComponent implements TestRunner {
}
}
- @Override
- public String getReportAsJson() {
- return Optional.ofNullable(getReport())
- .map(TestReport::toJson)
- .orElse("");
- }
}
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 9a1200d0bf3..b3ca47e2480 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,13 +1,7 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.testrunner;
-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.Collection;
import java.util.Collections;
import java.util.List;
import java.util.logging.LogRecord;
@@ -16,15 +10,16 @@ import java.util.logging.LogRecord;
* @author mortent
*/
public class TestReport {
- 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) {
+
+ 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) {
this.totalCount = totalCount;
this.successCount = successCount;
this.failedCount = failedCount;
@@ -34,31 +29,6 @@ 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;
}
@@ -71,7 +41,9 @@ public class TestReport {
return new Builder();
}
+
public static class Builder {
+
private long totalCount;
private long successCount;
private long failedCount;
@@ -88,18 +60,22 @@ 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;
@@ -110,12 +86,14 @@ public class TestReport {
return this;
}
- public Builder withLogs(List<LogRecord> logRecords) {
- this.logLines = logRecords;
+ public Builder withLogs(Collection<LogRecord> logRecords) {
+ this.logLines = List.copyOf(logRecords);
return this;
}
+
}
+
public static class Failure {
private final String testId;
private final Throwable exception;
@@ -132,5 +110,7 @@ public class TestReport {
public Throwable exception() {
return exception;
}
+
}
+
}
diff --git a/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/TestRunner.java b/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/TestRunner.java
index 31474d6c348..d70a3f60c7d 100644
--- a/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/TestRunner.java
+++ b/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/TestRunner.java
@@ -1,20 +1,32 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.testrunner;
-import ai.vespa.hosted.api.TestDescriptor;
-import com.yahoo.vespa.testrunner.legacy.LegacyTestRunner;
+import java.util.Collection;
+import java.util.concurrent.CompletableFuture;
+import java.util.logging.LogRecord;
/**
+ * @author jonmv
* @author mortent
*/
public interface TestRunner {
- void executeTests(TestDescriptor.TestCategory category, byte[] testConfig);
+
+ Collection<LogRecord> getLog(long after);
+
+ Status getStatus();
+
+ CompletableFuture<?> test(Suite suite, byte[] config);
boolean isSupported();
- LegacyTestRunner.Status getStatus();
+ default TestReport getReport() { return null; }
+
+ enum Status {
+ NOT_STARTED, RUNNING, FAILURE, ERROR, SUCCESS
+ }
- TestReport getReport();
+ enum Suite {
+ SYSTEM_TEST, STAGING_SETUP_TEST, STAGING_TEST, PRODUCTION_TEST
+ }
- String getReportAsJson();
-}
+} \ No newline at end of file
diff --git a/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/TestRunnerHandler.java b/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/TestRunnerHandler.java
index 4c359071fc9..62601e4dfa0 100644
--- a/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/TestRunnerHandler.java
+++ b/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/TestRunnerHandler.java
@@ -1,34 +1,27 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.testrunner;
-import ai.vespa.hosted.api.TestDescriptor;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.inject.Inject;
+import com.yahoo.component.provider.ComponentRegistry;
import com.yahoo.container.jdisc.EmptyResponse;
import com.yahoo.container.jdisc.HttpRequest;
import com.yahoo.container.jdisc.HttpResponse;
import com.yahoo.container.jdisc.LoggingRequestHandler;
+import com.yahoo.exception.ExceptionUtils;
+import com.yahoo.restapi.MessageResponse;
+import com.yahoo.restapi.SlimeJsonResponse;
import com.yahoo.slime.Cursor;
-import com.yahoo.slime.JsonFormat;
import com.yahoo.slime.Slime;
-import com.yahoo.slime.SlimeUtils;
-import com.yahoo.vespa.testrunner.legacy.LegacyTestRunner;
-import com.yahoo.vespa.testrunner.legacy.TestProfile;
import com.yahoo.yolean.Exceptions;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
import java.util.Optional;
import java.util.concurrent.Executor;
import java.util.logging.Level;
import java.util.logging.LogRecord;
-import java.util.stream.Collectors;
import static com.yahoo.jdisc.Response.Status;
@@ -39,18 +32,16 @@ import static com.yahoo.jdisc.Response.Status;
*/
public class TestRunnerHandler extends LoggingRequestHandler {
- private static final String CONTENT_TYPE_APPLICATION_JSON = "application/json";
-
- private final TestRunner junitRunner;
- private final LegacyTestRunner testRunner;
- private final boolean useOsgiMode;
+ private final TestRunner testRunner;
@Inject
- public TestRunnerHandler(Executor executor, TestRunner junitRunner, LegacyTestRunner testRunner) {
+ public TestRunnerHandler(Executor executor, ComponentRegistry<TestRunner> testRunners) {
+ this(executor, AggregateTestRunner.of(testRunners.allComponents()));
+ }
+
+ TestRunnerHandler(Executor executor, TestRunner testRunner) {
super(executor);
- this.junitRunner = junitRunner;
this.testRunner = testRunner;
- this.useOsgiMode = junitRunner.isSupported();
}
@Override
@@ -60,81 +51,48 @@ public class TestRunnerHandler extends LoggingRequestHandler {
case GET: return handleGET(request);
case POST: return handlePOST(request);
- default: return new Response(Status.METHOD_NOT_ALLOWED, "Method '" + request.getMethod() + "' is not supported");
+ default: return new MessageResponse(Status.METHOD_NOT_ALLOWED, "Method '" + request.getMethod() + "' is not supported");
}
} catch (IllegalArgumentException e) {
- return new Response(Status.BAD_REQUEST, Exceptions.toMessageString(e));
+ return new MessageResponse(Status.BAD_REQUEST, Exceptions.toMessageString(e));
} catch (Exception e) {
log.log(Level.WARNING, "Unexpected error handling '" + request.getUri() + "'", e);
- return new Response(Status.INTERNAL_SERVER_ERROR, Exceptions.toMessageString(e));
+ return new MessageResponse(Status.INTERNAL_SERVER_ERROR, Exceptions.toMessageString(e));
}
}
private HttpResponse handleGET(HttpRequest request) {
String path = request.getUri().getPath();
- if (path.equals("/tester/v1/log")) {
- if (useOsgiMode) {
+ switch (path) {
+ case "/tester/v1/log":
long fetchRecordsAfter = Optional.ofNullable(request.getProperty("after"))
- .map(Long::parseLong)
- .orElse(-1L);
-
- List<LogRecord> logRecords = Optional.ofNullable(junitRunner.getReport())
- .map(TestReport::logLines)
- .orElse(Collections.emptyList()).stream()
- .filter(record -> record.getSequenceNumber()>fetchRecordsAfter)
- .collect(Collectors.toList());
- return new SlimeJsonResponse(logToSlime(logRecords));
- } else {
- return new SlimeJsonResponse(logToSlime(testRunner.getLog(request.hasProperty("after")
- ? Long.parseLong(request.getProperty("after"))
- : -1)));
- }
- } else if (path.equals("/tester/v1/status")) {
- if (useOsgiMode) {
- log.info("Responding with status " + junitRunner.getStatus());
- return new Response(junitRunner.getStatus().name());
- } else {
+ .map(Long::parseLong)
+ .orElse(-1L);
+ return new SlimeJsonResponse(logToSlime(testRunner.getLog(fetchRecordsAfter)));
+ case "/tester/v1/status":
log.info("Responding with status " + testRunner.getStatus());
- return new Response(testRunner.getStatus().name());
- }
- } else if (path.equals("/tester/v1/report")) {
- if (useOsgiMode) {
- String report = junitRunner.getReportAsJson();
- return new SlimeJsonResponse(SlimeUtils.jsonToSlime(report));
- } else {
- return new EmptyResponse(200);
- }
+ return new MessageResponse(testRunner.getStatus().name());
+ case "/tester/v1/report":
+ TestReport report = testRunner.getReport();
+ if (report == null)
+ return new EmptyResponse(200);
+
+ return new SlimeJsonResponse(toSlime(report));
}
- return new Response(Status.NOT_FOUND, "Not found: " + request.getUri().getPath());
+ return new MessageResponse(Status.NOT_FOUND, "Not found: " + request.getUri().getPath());
}
private HttpResponse handlePOST(HttpRequest request) throws IOException {
final String path = request.getUri().getPath();
if (path.startsWith("/tester/v1/run/")) {
String type = lastElement(path);
- TestProfile testProfile = TestProfile.valueOf(type.toUpperCase() + "_TEST");
+ TestRunner.Suite testSuite = TestRunner.Suite.valueOf(type.toUpperCase() + "_TEST");
byte[] config = request.getData().readAllBytes();
- if (useOsgiMode) {
- junitRunner.executeTests(categoryFromProfile(testProfile), config);
- log.info("Started tests of type " + type + " and status is " + junitRunner.getStatus());
- return new Response("Successfully started " + type + " tests");
- } else {
- testRunner.test(testProfile, config);
- log.info("Started tests of type " + type + " and status is " + testRunner.getStatus());
- return new Response("Successfully started " + type + " tests");
- }
- }
- return new Response(Status.NOT_FOUND, "Not found: " + request.getUri().getPath());
- }
-
- TestDescriptor.TestCategory categoryFromProfile(TestProfile testProfile) {
- switch(testProfile) {
- case SYSTEM_TEST: return TestDescriptor.TestCategory.systemtest;
- case STAGING_SETUP_TEST: return TestDescriptor.TestCategory.stagingsetuptest;
- case STAGING_TEST: return TestDescriptor.TestCategory.stagingtest;
- case PRODUCTION_TEST: return TestDescriptor.TestCategory.productiontest;
- default: throw new RuntimeException("Unknown test profile: " + testProfile.name());
+ testRunner.test(testSuite, config);
+ log.info("Started tests of type " + type + " and status is " + testRunner.getStatus());
+ return new MessageResponse("Successfully started " + type + " tests");
}
+ return new MessageResponse(Status.NOT_FOUND, "Not found: " + request.getUri().getPath());
}
private static String lastElement(String path) {
@@ -177,48 +135,31 @@ public class TestRunnerHandler extends LoggingRequestHandler {
: "error";
}
- private static class SlimeJsonResponse extends HttpResponse {
- private final Slime slime;
+ private static Slime toSlime(TestReport testReport) {
+ var slime = new Slime();
+ var root = slime.setObject();
+ if (testReport == null)
+ return slime;
- private SlimeJsonResponse(Slime slime) {
- super(200);
- this.slime = slime;
- }
+ var summary = root.setObject("summary");
+ summary.setLong("total", testReport.totalCount);
+ summary.setLong("success", testReport.successCount);
+ summary.setLong("failed", testReport.failedCount);
+ summary.setLong("ignored", testReport.ignoredCount);
+ summary.setLong("aborted", testReport.abortedCount);
+ var failureRoot = summary.setArray("failures");
+ testReport.failures.forEach(failure -> serializeFailure(failure, failureRoot.addObject()));
- @Override
- public void render(OutputStream outputStream) throws IOException {
- new JsonFormat(true).encode(outputStream, slime);
- }
+ var output = root.setArray("output");
+ testReport.logLines.forEach(lr -> output.addString(lr.getMessage()));
- @Override
- public String getContentType() {
- return CONTENT_TYPE_APPLICATION_JSON;
- }
+ return slime;
}
- private static class Response extends HttpResponse {
- private static final ObjectMapper objectMapper = new ObjectMapper();
- private final String message;
-
- private Response(String response) {
- this(200, response);
- }
-
- private Response(int statusCode, String message) {
- super(statusCode);
- this.message = message;
- }
-
- @Override
- public void render(OutputStream outputStream) throws IOException {
- ObjectNode objectNode = objectMapper.createObjectNode();
- objectNode.put("message", message);
- objectMapper.writeValue(outputStream, objectNode);
- }
-
- @Override
- public String getContentType() {
- return CONTENT_TYPE_APPLICATION_JSON;
- }
+ private static void serializeFailure(TestReport.Failure failure, Cursor slime) {
+ slime.setString("testName", failure.testId());
+ slime.setString("testError",failure.exception().getMessage());
+ slime.setString("exception", ExceptionUtils.getStackTraceAsString(failure.exception()));
}
+
}
diff --git a/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/legacy/LegacyTestRunner.java b/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/legacy/LegacyTestRunner.java
deleted file mode 100644
index 418ab7fe5d0..00000000000
--- a/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/legacy/LegacyTestRunner.java
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.vespa.testrunner.legacy;
-
-import java.util.Collection;
-import java.util.logging.LogRecord;
-
-/**
- * @author mortent
- */
-public interface LegacyTestRunner {
-
- Collection<LogRecord> getLog(long after);
-
- Status getStatus();
-
- void test(TestProfile testProfile, byte[] config);
-
- // TODO (mortent) : This seems to be duplicated in TesterCloud.Status and expects to have the same values
- enum Status {
- NOT_STARTED, RUNNING, FAILURE, ERROR, SUCCESS
- }
-}
diff --git a/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/legacy/TestProfile.java b/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/legacy/TestProfile.java
deleted file mode 100644
index ad65d150874..00000000000
--- a/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/legacy/TestProfile.java
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.vespa.testrunner.legacy;
-
-/**
- * @author valerijf
- * @author jvenstad
- */
-public enum TestProfile {
-
- SYSTEM_TEST("system, com.yahoo.vespa.tenant.systemtest.base.SystemTest", true),
- STAGING_SETUP_TEST("staging-setup", false),
- STAGING_TEST("staging, com.yahoo.vespa.tenant.systemtest.base.StagingTest", true),
- PRODUCTION_TEST("production, com.yahoo.vespa.tenant.systemtest.base.ProductionTest", false);
-
- private final String group;
- private final boolean failIfNoTests;
-
- TestProfile(String group, boolean failIfNoTests) {
- this.group = group;
- this.failIfNoTests = failIfNoTests;
- }
-
- public String group() {
- return group;
- }
-
- public boolean failIfNoTests() {
- return failIfNoTests;
- }
-}
diff --git a/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/legacy/package-info.java b/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/legacy/package-info.java
deleted file mode 100644
index 6f6a8c819a6..00000000000
--- a/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/legacy/package-info.java
+++ /dev/null
@@ -1,9 +0,0 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-/**
- * @author mortent
- */
-@ExportPackage
-package com.yahoo.vespa.testrunner.legacy;
-
-import com.yahoo.osgi.annotation.ExportPackage; \ No newline at end of file