diff options
author | jonmv <venstad@gmail.com> | 2022-11-01 22:11:07 +0100 |
---|---|---|
committer | jonmv <venstad@gmail.com> | 2022-11-01 22:11:07 +0100 |
commit | 116afffc4920705f8d0ce2b016700216a2a0cbb3 (patch) | |
tree | 59219dc968c7c6addbed5375e062d835a34a6f0d /container-core | |
parent | 4984373de8e6b5b4b6d62d13e7efbaf0f025b2c5 (diff) |
No real changes
Diffstat (limited to 'container-core')
4 files changed, 29 insertions, 24 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 942555e391d..2bf33888569 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 @@ -42,11 +42,6 @@ public class ConfigRetrieverTest { dirConfigSource = new DirConfigSource(tmpDir, "ConfigRetrieverTest-"); } - @AfterEach - public void cleanup() { - dirConfigSource.cleanup(); - } - @Test void require_that_bootstrap_configs_come_first() { writeConfigs(); @@ -54,6 +49,7 @@ public class ConfigRetrieverTest { ConfigSnapshot bootstrapConfigs = retriever.getConfigs(Collections.emptySet(), 0, true); assertTrue(bootstrapConfigs instanceof BootstrapConfigs); + retriever.shutdown(); } @Test @@ -71,12 +67,12 @@ public class ConfigRetrieverTest { } else { fail("ComponentsConfigs has unexpected type: " + componentsConfigs); } + retriever.shutdown(); } @Disabled @SuppressWarnings("unused") public void require_exception_upon_modified_components_keys_without_bootstrap() { - writeConfigs(); ConfigRetriever retriever = createConfigRetriever(); ConfigKey<? extends ConfigInstance> testConfigKey = new ConfigKey<>(TestConfig.class, dirConfigSource.configId()); @@ -99,6 +95,7 @@ public class ConfigRetrieverTest { ConfigRetriever retriever = createConfigRetriever(); assertTrue(retriever.getConfigs(Collections.emptySet(), 0, true) instanceof BootstrapConfigs); assertTrue(retriever.getConfigs(Collections.emptySet(), 0, true) instanceof ComponentsConfigs); + retriever.shutdown(); } public void writeConfigs() { 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 c0d691c8a5a..6d95ba9c344 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 @@ -112,10 +112,8 @@ public class ContainerTest extends ContainerTestBase { // bundle-2 is installed, bundle-1 has been uninstalled assertEquals(1, osgi.getBundles().length); assertEquals("bundle-2", osgi.getBundles()[0].getSymbolicName()); - } - //@Test TODO - public void deconstructor_is_given_guice_components() { + container.shutdownConfigRetriever(); } @Test @@ -131,9 +129,11 @@ public class ContainerTest extends ContainerTestBase { container.reloadConfig(2); getNewComponentGraph(container, oldGraph); assertTrue(componentToDestruct.deconstructed); + + container.shutdownConfigRetriever(); } - @Disabled // because logAndDie is impossible(?) to verify programmatically + @Disabled("because logAndDie is impossible(?) to verify programmatically") @Test void manually_verify_what_happens_when_first_graph_contains_component_that_throws_exception_in_ctor() { writeBootstrapConfigs("thrower", ComponentThrowingExceptionInConstructor.class); @@ -144,6 +144,8 @@ public class ContainerTest extends ContainerTestBase { } catch (Throwable t) { fail("Expected to log and die"); } + + container.shutdownConfigRetriever(); } // Failure in component construction phase @@ -172,6 +174,8 @@ public class ContainerTest extends ContainerTestBase { assertEquals(3, currentGraph.generation()); assertSame(simpleComponent, currentGraph.getInstance(SimpleComponent.class)); assertNotNull(currentGraph.getInstance(ComponentTakingConfig.class)); + + container.shutdownConfigRetriever(); } @Test @@ -195,6 +199,8 @@ public class ContainerTest extends ContainerTestBase { // bundle-1 is kept, bundle-2 has been uninstalled assertEquals(1, osgi.getBundles().length); assertEquals("bundle-1", osgi.getBundles()[0].getSymbolicName()); + + container.shutdownConfigRetriever(); } // Failure in graph creation phase @@ -213,6 +219,8 @@ public class ContainerTest extends ContainerTestBase { container.reloadConfig(2); assertNewComponentGraphFails(container, currentGraph, IllegalArgumentException.class); assertEquals(1, currentGraph.generation()); + + container.shutdownConfigRetriever(); } @Test @@ -238,6 +246,8 @@ public class ContainerTest extends ContainerTestBase { // bundle-1 is kept, bundle-2 has been uninstalled assertEquals(1, osgi.getBundles().length); assertEquals("bundle-1", osgi.getBundles()[0].getSymbolicName()); + + container.shutdownConfigRetriever(); } private void assertNewComponentGraphFails(Container container, ComponentGraph currentGraph, Class<? extends RuntimeException> exception) { @@ -261,7 +271,7 @@ public class ContainerTest extends ContainerTestBase { container.reloadConfig(2); assertThrows(IllegalArgumentException.class, - () -> getNewComponentGraph(container, currentGraph)); + () -> getNewComponentGraph(container, currentGraph)); ExecutorService exec = Executors.newFixedThreadPool(1); Future<ComponentGraph> newGraph = exec.submit(() -> getNewComponentGraph(container, currentGraph)); @@ -277,10 +287,12 @@ public class ContainerTest extends ContainerTestBase { container.reloadConfig(3); assertNotNull(newGraph.get(5, TimeUnit.MINUTES)); + + container.shutdownConfigRetriever(); } @Test - void providers_are_destructed() { + void providers_are_destroyed() { writeBootstrapConfigs("id1", DestructableProvider.class); ComponentDeconstructor deconstructor = (generation, components, bundles) -> { @@ -304,6 +316,8 @@ public class ContainerTest extends ContainerTestBase { getNewComponentGraph(container, oldGraph); assertTrue(destructableEntity.deconstructed); + + container.shutdownConfigRetriever(); } @Test 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 7442eb2068d..54e5c54438b 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 @@ -36,12 +36,6 @@ public class ContainerTestBase { osgi = new TestOsgi(BundleTestUtil.testBundles()); } - @AfterEach - public void cleanup() { - dirConfigSource.cleanup(); - } - - protected Container newContainer(DirConfigSource dirConfigSource, ComponentDeconstructor deconstructor) { return new Container(new CloudSubscriberFactory(dirConfigSource.configSource), 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 db7e93f7c6e..39b50c66244 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 @@ -3,13 +3,17 @@ package com.yahoo.container.di; import com.yahoo.config.subscription.ConfigSource; import com.yahoo.config.subscription.ConfigSourceSet; +import org.junit.jupiter.api.Assertions; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.nio.charset.StandardCharsets; import java.util.Random; +import static java.nio.charset.StandardCharsets.UTF_8; + /** * @author Tony Vaagenes * @author gjoranv @@ -18,7 +22,7 @@ import java.util.Random; public class DirConfigSource { private final File tempFolder; - public final ConfigSource configSource; + public final ConfigSource configSource; // TODO jonmv: remove, unused public DirConfigSource(File tmpDir, String testSourcePrefix) { this.tempFolder = tmpDir; @@ -46,13 +50,9 @@ public class DirConfigSource { return configSource; } - public void cleanup() { - tempFolder.delete(); - } - private static void printFile(File f, String content) { try (OutputStream out = new FileOutputStream(f)) { - out.write(content.getBytes("UTF-8")); + out.write(content.getBytes(UTF_8)); } catch (IOException e) { throw new RuntimeException(e); } |