diff options
author | gjoranv <gv@verizonmedia.com> | 2022-09-07 10:40:39 +0200 |
---|---|---|
committer | gjoranv <gv@verizonmedia.com> | 2022-09-07 11:48:05 +0200 |
commit | 21843fba7d909e1dc09c3c999e71982ad9a8b368 (patch) | |
tree | 524a89ac17270ab5339b9e34b508c4f3478e043c | |
parent | 886ea2944ecc6aecb23acd4a880b1c324d510e8f (diff) |
Rename tests, extract common code and rearrange test order.
-rw-r--r-- | container-core/src/test/java/com/yahoo/container/di/ContainerTest.java | 64 |
1 files changed, 28 insertions, 36 deletions
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 5fbb035136f..625e81997f9 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 @@ -146,6 +146,7 @@ public class ContainerTest extends ContainerTestBase { } } + // Failure in component construction phase @Test void previous_graph_is_retained_when_new_graph_contains_component_that_throws_exception_in_ctor() { ComponentEntry simpleComponentEntry = new ComponentEntry("simpleComponent", SimpleComponent.class); @@ -158,14 +159,7 @@ public class ContainerTest extends ContainerTestBase { writeBootstrapConfigs("thrower", ComponentThrowingExceptionInConstructor.class); container.reloadConfig(2); - try { - currentGraph = getNewComponentGraph(container, currentGraph); - fail("Expected exception"); - } catch (ComponentConstructorException ignored) { - // Expected, do nothing - } catch (Throwable t) { - fail("Expected ComponentConstructorException"); - } + assertNewComponentGraphFails(container, currentGraph, ComponentConstructorException.class); assertEquals(1, currentGraph.generation()); // Also verify that next reconfig is successful @@ -181,55 +175,53 @@ public class ContainerTest extends ContainerTestBase { } @Test - void previous_graph_is_retained_when_new_graph_throws_exception_for_missing_config() { + void bundle_from_generation_that_fails_in_component_construction_is_uninstalled() { ComponentEntry simpleComponentEntry = new ComponentEntry("simpleComponent", SimpleComponent.class); + ComponentEntry throwingComponentEntry = new ComponentEntry("throwingComponent", ComponentThrowingExceptionInConstructor.class); - writeBootstrapConfigs(simpleComponentEntry); + writeBootstrapConfigsWithBundles(List.of("bundle-1"), List.of(simpleComponentEntry)); Container container = newContainer(dirConfigSource); ComponentGraph currentGraph = getNewComponentGraph(container); - currentGraph.getInstance(SimpleComponent.class); + // bundle-1 is installed + assertEquals(1, osgi.getBundles().length); + assertEquals("bundle-1", osgi.getBundles()[0].getSymbolicName()); - writeBootstrapConfigs("thrower", ComponentThrowingExceptionForMissingConfig.class); - dirConfigSource.writeConfig("test", "stringVal \"myString\""); + writeBootstrapConfigsWithBundles(List.of("bundle-2"), List.of(throwingComponentEntry)); container.reloadConfig(2); - try { - currentGraph = getNewComponentGraph(container, currentGraph); - fail("Expected exception"); - } catch (IllegalArgumentException ignored) { - // Expected, do nothing - } catch (Throwable t) { - fail("Expected IllegalArgumentException"); - } + assertNewComponentGraphFails(container, currentGraph, ComponentConstructorException.class); assertEquals(1, currentGraph.generation()); + + // bundle-1 is kept, bundle-2 has been uninstalled + assertEquals(1, osgi.getBundles().length); + assertEquals("bundle-1", osgi.getBundles()[0].getSymbolicName()); } + // Failure in graph creation phase @Test - void bundle_from_failing_generation_is_uninstalled() { + void previous_graph_is_retained_when_new_graph_throws_exception_for_missing_config() { ComponentEntry simpleComponentEntry = new ComponentEntry("simpleComponent", SimpleComponent.class); - ComponentEntry throwingComponentEntry = new ComponentEntry("throwingComponent", ComponentThrowingExceptionInConstructor.class); - writeBootstrapConfigsWithBundles(List.of("bundle-1"), List.of(simpleComponentEntry)); + writeBootstrapConfigs(simpleComponentEntry); Container container = newContainer(dirConfigSource); ComponentGraph currentGraph = getNewComponentGraph(container); - // bundle-1 is installed - assertEquals(1, osgi.getBundles().length); - assertEquals("bundle-1", osgi.getBundles()[0].getSymbolicName()); + currentGraph.getInstance(SimpleComponent.class); - writeBootstrapConfigsWithBundles(List.of("bundle-2"), List.of(throwingComponentEntry)); + writeBootstrapConfigs("thrower", ComponentThrowingExceptionForMissingConfig.class); + dirConfigSource.writeConfig("test", "stringVal \"myString\""); container.reloadConfig(2); + assertNewComponentGraphFails(container, currentGraph, IllegalArgumentException.class); + assertEquals(1, currentGraph.generation()); + } + + private void assertNewComponentGraphFails(Container container, ComponentGraph currentGraph, Class<? extends RuntimeException> exception) { try { - currentGraph = getNewComponentGraph(container, currentGraph); + getNewComponentGraph(container, currentGraph); fail("Expected exception"); - } catch (ComponentConstructorException ignored) { - // Expected, do nothing + } catch (Exception e) { + assertEquals(exception, e.getClass()); } - assertEquals(1, currentGraph.generation()); - - // bundle-1 is kept, bundle-2 has been uninstalled - assertEquals(1, osgi.getBundles().length); - assertEquals("bundle-1", osgi.getBundles()[0].getSymbolicName()); } @Test |