diff options
author | gjoranv <gv@verizonmedia.com> | 2022-09-01 08:43:56 +0200 |
---|---|---|
committer | gjoranv <gv@verizonmedia.com> | 2022-09-01 08:43:56 +0200 |
commit | cf928294be0c0d3a5be9137f4882fe02db6986ac (patch) | |
tree | 9ccccc9ae351e5fcee87f69d4c18c969de7ef65d /container-core/src/test | |
parent | 35e134e209ac8cec8d4643e1eee691a6e3f32bdf (diff) |
Reapply "Clean up bundles and allowed duplicates after a failed reconfig."
This reverts commit f869fa7fc3fbce76bc19745201bb62484dfc8efe.
Diffstat (limited to 'container-core/src/test')
3 files changed, 28 insertions, 1 deletions
diff --git a/container-core/src/test/java/com/yahoo/container/core/config/ApplicationBundleLoaderTest.java b/container-core/src/test/java/com/yahoo/container/core/config/ApplicationBundleLoaderTest.java index cf8cc6053cd..04ed52db53b 100644 --- a/container-core/src/test/java/com/yahoo/container/core/config/ApplicationBundleLoaderTest.java +++ b/container-core/src/test/java/com/yahoo/container/core/config/ApplicationBundleLoaderTest.java @@ -9,6 +9,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.osgi.framework.Bundle; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Set; @@ -70,7 +71,6 @@ public class ApplicationBundleLoaderTest { assertEquals(BUNDLE_1.getSymbolicName(), osgi.getCurrentBundles().get(0).getSymbolicName()); assertEquals(BUNDLE_2.getSymbolicName(), osgi.getCurrentBundles().get(1).getSymbolicName()); - // Both file references are active assertEquals(2, bundleLoader.getActiveFileReferences().size()); assertEquals(BUNDLE_1_REF, bundleLoader.getActiveFileReferences().get(0)); @@ -101,6 +101,27 @@ public class ApplicationBundleLoaderTest { } + @Test + void previous_generation_can_be_restored_after_a_failed_reconfig() { + bundleLoader.useBundles(List.of(BUNDLE_1_REF)); + Set<Bundle> obsoleteBundles = bundleLoader.useBundles(List.of(BUNDLE_2_REF)); + assertEquals(BUNDLE_1.getSymbolicName(), obsoleteBundles.iterator().next().getSymbolicName()); + + // Revert to the previous generation, as will be done upon a failed reconfig. + Collection<Bundle> bundlesToUninstall = bundleLoader.revertToPreviousGeneration(); + + assertEquals(1, bundlesToUninstall.size()); + assertEquals(BUNDLE_2.getSymbolicName(), bundlesToUninstall.iterator().next().getSymbolicName()); + + // Both bundles are still current, until the bundle from the failed gen will be uninstalled. + // Uninstalling is handled by the Deconstructor, not included in this test setup. + assertEquals(2, osgi.getCurrentBundles().size()); + + // Only the bundle-1 file reference is active, bundle-2 is removed. + assertEquals(1, bundleLoader.getActiveFileReferences().size()); + assertEquals(BUNDLE_1_REF, bundleLoader.getActiveFileReferences().get(0)); + } + private static Map<String, Bundle> testBundles() { return Map.of(BUNDLE_1_REF.value(), BUNDLE_1, BUNDLE_2_REF.value(), BUNDLE_2); diff --git a/container-core/src/test/java/com/yahoo/container/core/config/TestOsgi.java b/container-core/src/test/java/com/yahoo/container/core/config/TestOsgi.java index 2e22af889ed..cf3d1cef5f8 100644 --- a/container-core/src/test/java/com/yahoo/container/core/config/TestOsgi.java +++ b/container-core/src/test/java/com/yahoo/container/core/config/TestOsgi.java @@ -51,6 +51,7 @@ class TestOsgi extends MockOsgi { @Override public void allowDuplicateBundles(Collection<Bundle> bundles) { + allowedDuplicates.clear(); allowedDuplicates.addAll(bundles); } 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 4383bd08f71..7aa5d7b1ce7 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 @@ -66,6 +66,11 @@ public class ContainerTestBase { } @Override + public Collection<Bundle> revertApplicationBundles() { + return emptySet(); + } + + @Override public Bundle getBundle(ComponentSpecification spec) { throw new UnsupportedOperationException("getBundle not supported."); } |