aboutsummaryrefslogtreecommitdiffstats
path: root/tenant-cd-api
diff options
context:
space:
mode:
authorMorten Tokle <mortent@verizonmedia.com>2020-06-22 08:55:36 +0200
committerMorten Tokle <mortent@verizonmedia.com>2020-06-22 08:55:36 +0200
commite2dace4bc4f72e86a671664cb1b32eea48361cfb (patch)
tree2aadf30b9343cdba51646248ad5588f4f22d8bbc /tenant-cd-api
parent3a66636ae7790b334467898ab31badf522f70a1e (diff)
Execute Junit tests in container
Diffstat (limited to 'tenant-cd-api')
-rw-r--r--tenant-cd-api/pom.xml7
-rw-r--r--tenant-cd-api/src/main/java/ai/vespa/hosted/cd/TestRuntime.java19
-rw-r--r--tenant-cd-api/src/main/java/ai/vespa/hosted/cd/internal/TestRuntimeProvider.java29
3 files changed, 53 insertions, 2 deletions
diff --git a/tenant-cd-api/pom.xml b/tenant-cd-api/pom.xml
index b19d42d094f..233788a12a9 100644
--- a/tenant-cd-api/pom.xml
+++ b/tenant-cd-api/pom.xml
@@ -40,6 +40,13 @@
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <!-- required to inject component from test implementation -->
+ <groupId>com.yahoo.vespa</groupId>
+ <artifactId>component</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
<!-- compile -->
<dependency> <!-- TODO(bjorncs): share junit version number with test-runner implementation -->
diff --git a/tenant-cd-api/src/main/java/ai/vespa/hosted/cd/TestRuntime.java b/tenant-cd-api/src/main/java/ai/vespa/hosted/cd/TestRuntime.java
index 08cc0467b71..7aebbc7b7e7 100644
--- a/tenant-cd-api/src/main/java/ai/vespa/hosted/cd/TestRuntime.java
+++ b/tenant-cd-api/src/main/java/ai/vespa/hosted/cd/TestRuntime.java
@@ -2,7 +2,10 @@
package ai.vespa.hosted.cd;
import ai.vespa.cloud.Zone;
+import ai.vespa.hosted.cd.internal.TestRuntimeProvider;
+import org.osgi.framework.BundleReference;
+import java.util.Optional;
import java.util.ServiceLoader;
/**
@@ -13,8 +16,20 @@ import java.util.ServiceLoader;
*/
public interface TestRuntime {
static TestRuntime get() {
- ServiceLoader<TestRuntime> serviceLoader = ServiceLoader.load(TestRuntime.class);
- return serviceLoader.findFirst().orElseThrow(() -> new RuntimeException("No TestRuntime implementation found"));
+ var classloader = TestRuntime.class.getClassLoader();
+
+ System.out.println("classloader.toString() = " + classloader.toString());
+ System.out.println("classloader.getClass().toString() = " + classloader.getClass().toString());
+
+ if (classloader instanceof BundleReference) {
+ System.out.println("Loading Test runtime from osgi component");
+ return Optional.ofNullable(TestRuntimeProvider.getTestRuntime())
+ .orElseThrow(() -> new RuntimeException("Component graph not ready, retrying"));
+ } else {
+ System.out.println("Loading Test runtime from service loader");
+ ServiceLoader<TestRuntime> serviceLoader = ServiceLoader.load(TestRuntime.class, TestRuntime.class.getClassLoader());
+ return serviceLoader.findFirst().orElseThrow(() -> new RuntimeException("No TestRuntime implementation found"));
+ }
}
Deployment deploymentToTest();
diff --git a/tenant-cd-api/src/main/java/ai/vespa/hosted/cd/internal/TestRuntimeProvider.java b/tenant-cd-api/src/main/java/ai/vespa/hosted/cd/internal/TestRuntimeProvider.java
new file mode 100644
index 00000000000..e97fa5faf85
--- /dev/null
+++ b/tenant-cd-api/src/main/java/ai/vespa/hosted/cd/internal/TestRuntimeProvider.java
@@ -0,0 +1,29 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package ai.vespa.hosted.cd.internal;
+
+import ai.vespa.hosted.cd.TestRuntime;
+import com.yahoo.component.AbstractComponent;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * @author mortent
+ */
+public class TestRuntimeProvider extends AbstractComponent {
+
+ private static final AtomicReference<TestRuntime> testRuntime = new AtomicReference<>();
+
+ public TestRuntimeProvider(TestRuntime testRuntime) {
+ TestRuntimeProvider.testRuntime.set(testRuntime);
+ }
+
+ public static TestRuntime getTestRuntime() {
+ return testRuntime.get();
+ }
+
+ @Override
+ public void deconstruct() {
+ super.deconstruct();
+ testRuntime.set(null);
+ }
+}