diff options
author | jonmv <venstad@gmail.com> | 2022-11-01 23:39:22 +0100 |
---|---|---|
committer | jonmv <venstad@gmail.com> | 2022-11-01 23:39:22 +0100 |
commit | 2619a4060c8b0e5cbb653942762313394ec6c59e (patch) | |
tree | 90ed40b9e7f1d8f6b62fab13b7bd414b3da9ed42 /container-core/src/test/java/com | |
parent | 116afffc4920705f8d0ce2b016700216a2a0cbb3 (diff) |
Cleanup, no effective changes
Diffstat (limited to 'container-core/src/test/java/com')
4 files changed, 27 insertions, 31 deletions
diff --git a/container-core/src/test/java/com/yahoo/container/di/ConfigRetrieverTest.java b/container-core/src/test/java/com/yahoo/container/di/ConfigRetrieverTest.java index 2bf33888569..df92160550c 100644 --- a/container-core/src/test/java/com/yahoo/container/di/ConfigRetrieverTest.java +++ b/container-core/src/test/java/com/yahoo/container/di/ConfigRetrieverTest.java @@ -9,7 +9,6 @@ import com.yahoo.container.di.ConfigRetriever.BootstrapConfigs; import com.yahoo.container.di.ConfigRetriever.ComponentsConfigs; import com.yahoo.container.di.ConfigRetriever.ConfigSnapshot; import com.yahoo.vespa.config.ConfigKey; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -39,7 +38,7 @@ public class ConfigRetrieverTest { @BeforeEach public void setup() { - dirConfigSource = new DirConfigSource(tmpDir, "ConfigRetrieverTest-"); + dirConfigSource = new DirConfigSource(tmpDir); } @Test diff --git a/container-core/src/test/java/com/yahoo/container/di/ContainerTest.java b/container-core/src/test/java/com/yahoo/container/di/ContainerTest.java index 6d95ba9c344..6bb1af8258f 100644 --- a/container-core/src/test/java/com/yahoo/container/di/ContainerTest.java +++ b/container-core/src/test/java/com/yahoo/container/di/ContainerTest.java @@ -66,6 +66,7 @@ public class ContainerTest extends ContainerTestBase { assertEquals("reconfigured", component2.config.stringVal()); container.shutdownConfigRetriever(); + container.shutdown(newComponentGraph); } @Test @@ -90,6 +91,7 @@ public class ContainerTest extends ContainerTestBase { assertNotNull(ComponentGraph.getNode(newGraph, "id2")); container.shutdownConfigRetriever(); + container.shutdown(newGraph); } @Test @@ -107,13 +109,14 @@ public class ContainerTest extends ContainerTestBase { writeBootstrapConfigsWithBundles(List.of("bundle-2"), List.of(component2)); container.reloadConfig(2); - getNewComponentGraph(container, graph); + ComponentGraph newGraph = getNewComponentGraph(container, graph); // bundle-2 is installed, bundle-1 has been uninstalled assertEquals(1, osgi.getBundles().length); assertEquals("bundle-2", osgi.getBundles()[0].getSymbolicName()); container.shutdownConfigRetriever(); + container.shutdown(newGraph); } @Test @@ -127,10 +130,11 @@ public class ContainerTest extends ContainerTestBase { writeBootstrapConfigs("id2", DestructableComponent.class); container.reloadConfig(2); - getNewComponentGraph(container, oldGraph); + ComponentGraph newGraph = getNewComponentGraph(container, oldGraph); assertTrue(componentToDestruct.deconstructed); container.shutdownConfigRetriever(); + container.shutdown(newGraph); } @Disabled("because logAndDie is impossible(?) to verify programmatically") @@ -176,6 +180,7 @@ public class ContainerTest extends ContainerTestBase { assertNotNull(currentGraph.getInstance(ComponentTakingConfig.class)); container.shutdownConfigRetriever(); + container.shutdown(currentGraph); } @Test @@ -201,6 +206,7 @@ public class ContainerTest extends ContainerTestBase { assertEquals("bundle-1", osgi.getBundles()[0].getSymbolicName()); container.shutdownConfigRetriever(); + container.shutdown(currentGraph); } // Failure in graph creation phase @@ -221,6 +227,7 @@ public class ContainerTest extends ContainerTestBase { assertEquals(1, currentGraph.generation()); container.shutdownConfigRetriever(); + container.shutdown(currentGraph); } @Test @@ -248,6 +255,7 @@ public class ContainerTest extends ContainerTestBase { assertEquals("bundle-1", osgi.getBundles()[0].getSymbolicName()); container.shutdownConfigRetriever(); + container.shutdown(currentGraph); } private void assertNewComponentGraphFails(Container container, ComponentGraph currentGraph, Class<? extends RuntimeException> exception) { @@ -286,9 +294,10 @@ public class ContainerTest extends ContainerTestBase { writeBootstrapConfigs("myId2", ComponentTakingConfig.class); container.reloadConfig(3); - assertNotNull(newGraph.get(5, TimeUnit.MINUTES)); + assertNotNull(newGraph.get(10, TimeUnit.SECONDS)); container.shutdownConfigRetriever(); + container.shutdown(newGraph.get()); } @Test @@ -313,11 +322,12 @@ public class ContainerTest extends ContainerTestBase { writeBootstrapConfigs("id2", DestructableProvider.class); container.reloadConfig(2); - getNewComponentGraph(container, oldGraph); + ComponentGraph graph = getNewComponentGraph(container, oldGraph); assertTrue(destructableEntity.deconstructed); container.shutdownConfigRetriever(); + container.shutdown(graph); } @Test @@ -327,6 +337,7 @@ public class ContainerTest extends ContainerTestBase { Container container = newContainer(dirConfigSource); ComponentGraph oldGraph = getNewComponentGraph(container); + container.shutdown(oldGraph); } static class DestructableEntity { 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 54e5c54438b..0ad376a13d8 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 @@ -6,7 +6,6 @@ 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; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.io.TempDir; import org.osgi.framework.Bundle; @@ -31,14 +30,14 @@ public class ContainerTestBase { @BeforeEach public void setup() { - dirConfigSource = new DirConfigSource(tmpDir, "ContainerTest-"); + dirConfigSource = new DirConfigSource(tmpDir); componentGraph = new ComponentGraph(0); osgi = new TestOsgi(BundleTestUtil.testBundles()); } protected Container newContainer(DirConfigSource dirConfigSource, ComponentDeconstructor deconstructor) { - return new Container(new CloudSubscriberFactory(dirConfigSource.configSource), + return new Container(new CloudSubscriberFactory(dirConfigSource.configSource()), dirConfigSource.configId(), deconstructor, osgi); diff --git a/container-core/src/test/java/com/yahoo/container/di/DirConfigSource.java b/container-core/src/test/java/com/yahoo/container/di/DirConfigSource.java index 39b50c66244..7704827311c 100644 --- a/container-core/src/test/java/com/yahoo/container/di/DirConfigSource.java +++ b/container-core/src/test/java/com/yahoo/container/di/DirConfigSource.java @@ -19,30 +19,24 @@ import static java.nio.charset.StandardCharsets.UTF_8; * @author gjoranv * @author ollivir */ -public class DirConfigSource { +class DirConfigSource { private final File tempFolder; - public final ConfigSource configSource; // TODO jonmv: remove, unused - public DirConfigSource(File tmpDir, String testSourcePrefix) { + DirConfigSource(File tmpDir) { this.tempFolder = tmpDir; - this.configSource = new ConfigSourceSet(testSourcePrefix + new Random().nextLong()); } - public void writeConfig(String name, String contents) { - File file = new File(tempFolder, name + ".cfg"); - if (!file.exists()) { - try { - file.createNewFile(); - } catch (IOException e) { - throw new RuntimeException(e); - } + void writeConfig(String name, String contents) { + try { + Files.writeString(tempFolder.toPath().resolve(name + ".cfg"), contents); + } + catch (IOException e) { + throw new UncheckedIOException(e); } - - printFile(file, contents + "\n"); } - public String configId() { + String configId() { return "dir:" + tempFolder.getPath(); } @@ -50,12 +44,5 @@ public class DirConfigSource { return configSource; } - private static void printFile(File f, String content) { - try (OutputStream out = new FileOutputStream(f)) { - out.write(content.getBytes(UTF_8)); - } catch (IOException e) { - throw new RuntimeException(e); - } - } } |