diff options
author | gjoranv <gv@verizonmedia.com> | 2019-10-05 00:06:55 +0200 |
---|---|---|
committer | gjoranv <gv@verizonmedia.com> | 2019-10-16 11:41:33 +0200 |
commit | af771506b97cf996dd7c25053c07e1cc8f9eba99 (patch) | |
tree | e77bdc57d861ee747f4211e638a163f394472238 /jdisc_core_test | |
parent | 685704ab391abc6efdb9577c24bdf7ed48333f8e (diff) |
Allow duplicate bsn+version for a given set of bundles.
- Set 'org.osgi.framework.bsnversion' to 'managed'
- Add bundle collision/event hook to handle duplicates and their
lifecycle.
- Add unit tests for duplicate bundles.
o Add bundle 'l1-dup' which is a duplicate of the existing 'l1',
but returns a different value from its implemented class.
o Add bundle 'ml-dup' that is exactly the same as 'ml'
Diffstat (limited to 'jdisc_core_test')
10 files changed, 218 insertions, 1 deletions
diff --git a/jdisc_core_test/integration_test/pom.xml b/jdisc_core_test/integration_test/pom.xml index 670d812c9e9..0b0a1ce81ef 100644 --- a/jdisc_core_test/integration_test/pom.xml +++ b/jdisc_core_test/integration_test/pom.xml @@ -153,6 +153,12 @@ </dependency> <dependency> <groupId>com.yahoo.vespa.jdisc_core</groupId> + <artifactId>cert-l1-dup</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.yahoo.vespa.jdisc_core</groupId> <artifactId>cert-l2</artifactId> <version>${project.version}</version> <scope>test</scope> @@ -165,6 +171,12 @@ </dependency> <dependency> <groupId>com.yahoo.vespa.jdisc_core</groupId> + <artifactId>cert-ml-dup</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.yahoo.vespa.jdisc_core</groupId> <artifactId>cert-nac</artifactId> <version>${project.version}</version> <scope>test</scope> diff --git a/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/core/BundleCollisionHookIntegrationTest.java b/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/core/BundleCollisionHookIntegrationTest.java new file mode 100644 index 00000000000..58c6c1ba8d6 --- /dev/null +++ b/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/core/BundleCollisionHookIntegrationTest.java @@ -0,0 +1,88 @@ +package com.yahoo.jdisc.core; + +import com.yahoo.jdisc.test.TestDriver; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleException; + +import java.util.Collections; + +import static com.yahoo.jdisc.core.FelixFrameworkIntegrationTest.startBundle; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * Note that the '-dup' bundles are necessary, because felix ignores duplicate bundles with the same location. + * + * @author gjoranv + */ +public class BundleCollisionHookIntegrationTest { + + private FelixFramework felix; + + @Before + public void startFelix() throws Exception { + felix = TestDriver.newOsgiFramework(); + felix.start(); + } + + @After + public void stopFelix() throws Exception { + felix.stop(); + } + + @Test + public void duplicate_bundles_cannot_be_installed_in_general() throws Exception { + startBundle(felix, "cert-l1.jar"); + try { + startBundle(felix, "cert-l1-dup.jar"); + fail("Expected exception due to duplicate bundles"); + } catch (BundleException e) { + assertTrue(e.getMessage().contains("Bundle symbolic name and version are not unique")); + } + } + + @Test + public void duplicate_bundles_can_be_installed_if_bsn_version_is_whitelisted() throws Exception { + Bundle bundleL = startBundle(felix, "cert-l1.jar"); + felix.allowDuplicateBundles(Collections.singleton(bundleL)); + + Bundle bundleLdup = startBundle(felix, "cert-l1-dup.jar"); + assertNotEquals(bundleL.getBundleId(), bundleLdup.getBundleId()); + } + + @Test + public void duplicates_whitelist_is_updated_when_bundles_are_uninstalled() throws Exception { + Bundle bundleL = startBundle(felix, "cert-l1.jar"); + felix.allowDuplicateBundles(Collections.singleton(bundleL)); + + startBundle(felix, "cert-l1-dup.jar"); + + // Remove the original bundle -> will also remove the allowed duplicate + bundleL.uninstall(); + + // Trigger error by trying to re-install the bundle while the duplicate remains + try { + startBundle(felix, "cert-l1.jar"); + fail("Expected exception due to duplicate bundles"); + } catch (BundleException e) { + assertTrue(e.getMessage().contains("Bundle symbolic name and version are not unique")); + } + + } + + @Test + public void duplicates_whitelist_can_be_updated_with_additional_bundles() throws Exception { + Bundle bundleL = startBundle(felix, "cert-l1.jar"); + Bundle bundleMl = startBundle(felix, "cert-ml.jar"); + felix.allowDuplicateBundles(Collections.singleton(bundleL)); + felix.allowDuplicateBundles(Collections.singleton(bundleMl)); + + startBundle(felix, "cert-l1-dup.jar"); + startBundle(felix, "cert-ml-dup.jar"); + } + +} diff --git a/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/core/FelixFrameworkIntegrationTest.java b/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/core/FelixFrameworkIntegrationTest.java index e8551b44a3c..9b7453d2d6b 100644 --- a/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/core/FelixFrameworkIntegrationTest.java +++ b/jdisc_core_test/integration_test/src/test/java/com/yahoo/jdisc/core/FelixFrameworkIntegrationTest.java @@ -111,8 +111,11 @@ public class FelixFrameworkIntegrationTest { Bundle bundleL = startBundle(felix, "cert-l1.jar"); Bundle bundleM = startBundle(felix, "cert-ml.jar"); assertEquals(1, callClass(bundleM, "com.yahoo.jdisc.bundle.m.CertificateM")); + + // Switch from l1 to l2 (identical bundles, except for bsn) bundleL.uninstall(); startBundle(felix, "cert-l2.jar"); + felix.refreshPackages(); assertEquals(2, callClass(bundleM, "com.yahoo.jdisc.bundle.m.CertificateM")); felix.stop(); @@ -185,7 +188,7 @@ public class FelixFrameworkIntegrationTest { "com.yahoo.vespa.jdisc_core.cert-q-frag"); } - private static Bundle startBundle(FelixFramework felix, String bundleLocation) throws BundleException { + static Bundle startBundle(FelixFramework felix, String bundleLocation) throws BundleException { List<Bundle> lst = felix.installBundle(bundleLocation); assertEquals(1, lst.size()); felix.startBundles(lst, false); diff --git a/jdisc_core_test/test_bundles/cert-l1-dup/.gitignore b/jdisc_core_test/test_bundles/cert-l1-dup/.gitignore new file mode 100644 index 00000000000..3cc25b51fc4 --- /dev/null +++ b/jdisc_core_test/test_bundles/cert-l1-dup/.gitignore @@ -0,0 +1,2 @@ +/pom.xml.build +/target diff --git a/jdisc_core_test/test_bundles/cert-l1-dup/pom.xml b/jdisc_core_test/test_bundles/cert-l1-dup/pom.xml new file mode 100644 index 00000000000..b1a61bc4145 --- /dev/null +++ b/jdisc_core_test/test_bundles/cert-l1-dup/pom.xml @@ -0,0 +1,36 @@ +<?xml version="1.0"?> +<!-- Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 + http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>com.yahoo.vespa.jdisc_core</groupId> + <artifactId>test_bundles</artifactId> + <version>7-SNAPSHOT</version> + </parent> + <artifactId>cert-l1-dup</artifactId> + <version>7-SNAPSHOT</version> + <packaging>bundle</packaging> + <name>${project.artifactId}</name> + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <configuration> + <instructions> + <Bundle-SymbolicName> + ${project.groupId}.cert-l1 + </Bundle-SymbolicName> + <Export-Package> + com.yahoo.jdisc.bundle.l + </Export-Package> + </instructions> + </configuration> + </plugin> + </plugins> + </build> +</project> diff --git a/jdisc_core_test/test_bundles/cert-l1-dup/src/main/java/com/yahoo/jdisc/bundle/l/CertificateL.java b/jdisc_core_test/test_bundles/cert-l1-dup/src/main/java/com/yahoo/jdisc/bundle/l/CertificateL.java new file mode 100644 index 00000000000..2060686ee4f --- /dev/null +++ b/jdisc_core_test/test_bundles/cert-l1-dup/src/main/java/com/yahoo/jdisc/bundle/l/CertificateL.java @@ -0,0 +1,15 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.jdisc.bundle.l; + +import java.util.concurrent.Callable; + +/** + * @author Simon Thoresen Hult + */ +public class CertificateL implements Callable<Integer> { + + @Override + public Integer call() throws Exception { + return 11; + } +} diff --git a/jdisc_core_test/test_bundles/cert-ml-dup/.gitignore b/jdisc_core_test/test_bundles/cert-ml-dup/.gitignore new file mode 100644 index 00000000000..3cc25b51fc4 --- /dev/null +++ b/jdisc_core_test/test_bundles/cert-ml-dup/.gitignore @@ -0,0 +1,2 @@ +/pom.xml.build +/target diff --git a/jdisc_core_test/test_bundles/cert-ml-dup/pom.xml b/jdisc_core_test/test_bundles/cert-ml-dup/pom.xml new file mode 100644 index 00000000000..4382664c923 --- /dev/null +++ b/jdisc_core_test/test_bundles/cert-ml-dup/pom.xml @@ -0,0 +1,39 @@ +<?xml version="1.0"?> +<!-- Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 + http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>com.yahoo.vespa.jdisc_core</groupId> + <artifactId>test_bundles</artifactId> + <version>7-SNAPSHOT</version> + </parent> + <artifactId>cert-ml-dup</artifactId> + <version>7-SNAPSHOT</version> + <packaging>bundle</packaging> + <name>${project.artifactId}</name> + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <configuration> + <instructions> + <Bundle-SymbolicName> + ${project.groupId}.cert-ml + </Bundle-SymbolicName> + <Import-Package> + com.yahoo.jdisc.bundle.l + </Import-Package> + <Export-Package> + com.yahoo.jdisc.bundle.m + </Export-Package> + </instructions> + </configuration> + </plugin> + </plugins> + </build> +</project> diff --git a/jdisc_core_test/test_bundles/cert-ml-dup/src/main/java/com/yahoo/jdisc/bundle/m/CertificateM.java b/jdisc_core_test/test_bundles/cert-ml-dup/src/main/java/com/yahoo/jdisc/bundle/m/CertificateM.java new file mode 100644 index 00000000000..131c9e41a1e --- /dev/null +++ b/jdisc_core_test/test_bundles/cert-ml-dup/src/main/java/com/yahoo/jdisc/bundle/m/CertificateM.java @@ -0,0 +1,18 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.jdisc.bundle.m; + +import java.util.concurrent.Callable; + +/** + * @author Simon Thoresen Hult + */ +public class CertificateM implements Callable<Integer> { + + @Override + @SuppressWarnings({ "unchecked" }) + public Integer call() throws Exception { + Class<?> certClass = Class.forName("com.yahoo.jdisc.bundle.l.CertificateL"); + Callable<Integer> cert = (Callable<Integer>)certClass.getDeclaredConstructor().newInstance(); + return cert.call(); + } +} diff --git a/jdisc_core_test/test_bundles/pom.xml b/jdisc_core_test/test_bundles/pom.xml index c11a94eacc5..d62d22c67f9 100644 --- a/jdisc_core_test/test_bundles/pom.xml +++ b/jdisc_core_test/test_bundles/pom.xml @@ -65,8 +65,10 @@ <module>cert-j-priv</module> <module>cert-k-pkgs</module> <module>cert-l1</module> + <module>cert-l1-dup</module> <module>cert-l2</module> <module>cert-ml</module> + <module>cert-ml-dup</module> <module>cert-nac</module> <module>cert-oa-path</module> <module>cert-p-jar</module> |