summaryrefslogtreecommitdiffstats
path: root/container-core/src/test/java/com/yahoo/container/di/ContainerTestBase.java
diff options
context:
space:
mode:
Diffstat (limited to 'container-core/src/test/java/com/yahoo/container/di/ContainerTestBase.java')
-rw-r--r--container-core/src/test/java/com/yahoo/container/di/ContainerTestBase.java99
1 files changed, 55 insertions, 44 deletions
diff --git a/container-core/src/test/java/com/yahoo/container/di/ContainerTestBase.java b/container-core/src/test/java/com/yahoo/container/di/ContainerTestBase.java
index f2faed650a8..7442eb2068d 100644
--- a/container-core/src/test/java/com/yahoo/container/di/ContainerTestBase.java
+++ b/container-core/src/test/java/com/yahoo/container/di/ContainerTestBase.java
@@ -2,9 +2,8 @@
package com.yahoo.container.di;
import com.google.inject.Guice;
-import com.yahoo.component.ComponentSpecification;
-import com.yahoo.config.FileReference;
-import com.yahoo.container.bundle.BundleInstantiationSpecification;
+import com.yahoo.container.core.config.BundleTestUtil;
+import com.yahoo.container.core.config.TestOsgi;
import com.yahoo.container.di.ContainerTest.ComponentTakingConfig;
import com.yahoo.container.di.componentgraph.core.ComponentGraph;
import org.junit.jupiter.api.AfterEach;
@@ -14,9 +13,7 @@ import org.osgi.framework.Bundle;
import java.io.File;
import java.util.Collection;
-import java.util.Set;
-
-import static java.util.Collections.emptySet;
+import java.util.List;
/**
* @author Tony Vaagenes
@@ -27,6 +24,7 @@ public class ContainerTestBase {
private ComponentGraph componentGraph;
protected DirConfigSource dirConfigSource = null;
+ protected TestOsgi osgi;
@TempDir
File tmpDir;
@@ -34,6 +32,8 @@ public class ContainerTestBase {
@BeforeEach
public void setup() {
dirConfigSource = new DirConfigSource(tmpDir, "ContainerTest-");
+ componentGraph = new ComponentGraph(0);
+ osgi = new TestOsgi(BundleTestUtil.testBundles());
}
@AfterEach
@@ -41,52 +41,43 @@ public class ContainerTestBase {
dirConfigSource.cleanup();
}
- @BeforeEach
- public void createGraph() {
- componentGraph = new ComponentGraph(0);
+
+ protected Container newContainer(DirConfigSource dirConfigSource,
+ ComponentDeconstructor deconstructor) {
+ return new Container(new CloudSubscriberFactory(dirConfigSource.configSource),
+ dirConfigSource.configId(),
+ deconstructor,
+ osgi);
}
- public void complete() {
- try {
- Container container = new Container(new CloudSubscriberFactory(dirConfigSource.configSource()), dirConfigSource.configId(),
- new ContainerTest.TestDeconstructor(), new Osgi() {
- @SuppressWarnings("unchecked")
- @Override
- public Class<Object> resolveClass(BundleInstantiationSpecification spec) {
- try {
- return (Class<Object>) Class.forName(spec.classId.getName());
- } catch (ClassNotFoundException e) {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- public Set<Bundle> useApplicationBundles(Collection<FileReference> bundles) {
- return emptySet();
- }
-
- @Override
- public Collection<Bundle> revertApplicationBundles() {
- return emptySet();
- }
-
- @Override
- public Bundle getBundle(ComponentSpecification spec) {
- throw new UnsupportedOperationException("getBundle not supported.");
- }
- });
- Container.ComponentGraphResult result = container.waitForNextGraphGeneration(this.componentGraph, Guice.createInjector(), true);
- result.oldComponentsCleanupTask().run();
- this.componentGraph = result.newGraph();
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
+ protected Container newContainer(DirConfigSource dirConfigSource) {
+ return newContainer(dirConfigSource, new TestDeconstructor(osgi));
}
+ ComponentGraph getNewComponentGraph(Container container, ComponentGraph oldGraph) {
+ Container.ComponentGraphResult result = container.waitForNextGraphGeneration(oldGraph, Guice.createInjector(), true);
+ result.oldComponentsCleanupTask().run();
+ return result.newGraph();
+ }
+
+ ComponentGraph getNewComponentGraph(Container container) {
+ return container.waitForNextGraphGeneration(new ComponentGraph(), Guice.createInjector(), true).newGraph();
+ }
+
+
public <T> T getInstance(Class<T> componentClass) {
return componentGraph.getInstance(componentClass);
}
+ protected void writeBootstrapConfigsWithBundles(List<String> applicationBundles, List<ComponentEntry> components) {
+ writeBootstrapConfigs(components.toArray(new ComponentEntry[0]));
+ StringBuilder bundles = new StringBuilder();
+ for (int i = 0; i < applicationBundles.size(); i++) {
+ bundles.append("bundles[" + i + "] \"" + applicationBundles.get(i) + "\"\n");
+ }
+ dirConfigSource.writeConfig("application-bundles", String.format("bundles[%s]\n%s", applicationBundles.size(), bundles));
+ }
+
protected void writeBootstrapConfigs(ComponentEntry... componentEntries) {
dirConfigSource.writeConfig("platform-bundles", "");
dirConfigSource.writeConfig("application-bundles", "");
@@ -126,4 +117,24 @@ public class ContainerTestBase {
}
}
+
+ public static class TestDeconstructor implements ComponentDeconstructor {
+
+ final TestOsgi osgi;
+
+ public TestDeconstructor(TestOsgi osgi) {
+ this.osgi = osgi;
+ }
+
+ @Override
+ public void deconstruct(long generation, List<Object> components, Collection<Bundle> bundles) {
+ components.forEach(component -> {
+ if (component instanceof ContainerTest.DestructableComponent vespaComponent) {
+ vespaComponent.deconstruct();
+ }
+ });
+ bundles.forEach(osgi::removeBundle);
+ }
+ }
+
}