Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2017-09-13 20:57:02 +0000
committerThomas Watson2017-09-18 17:06:06 +0000
commit6f59ecfcd9585d5a5712883a05efef2a8d057296 (patch)
tree9eaef7c423db90baebb42c6de21bbf7256e6d389 /bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java
parentef125a15e04c6e4258dff8c57e0b5c2983643940 (diff)
downloadrt.equinox.framework-6f59ecfcd9585d5a5712883a05efef2a8d057296.tar.gz
rt.equinox.framework-6f59ecfcd9585d5a5712883a05efef2a8d057296.tar.xz
rt.equinox.framework-6f59ecfcd9585d5a5712883a05efef2a8d057296.zip
Bug 522313 - Remove loop used to acquire the bundle id lock on bundle
installation When installing a new module there is a loop in the Storage class which repeatedly attempts to acquire the next module ID lock before installing the module into the module container. This has always been a sort of hack because it is attempting to lock the next module ID outside of the module container so that we can stage the bundle content correctly into the bundle id folder before installing the module into the container. To do that we needed to know what the next module id is going to be and lock it so that no other thread attempts to install over with the module ID we are trying to stage. Instead of doing this strange locking loop this fix adds a new method to the module container to get and increment the next module ID and then passes that module ID in as part of the ModuleRevisionBuilder. This way if multiple threads are installing modules they each will get thier own unique module ID without requiring any outside the container locking. Change-Id: I215a991bb4ef2a71eea542259b32e0c9509d9c8f Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
Diffstat (limited to 'bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java')
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java39
1 files changed, 39 insertions, 0 deletions
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java
index 884901693..553819d87 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java
@@ -3274,6 +3274,45 @@ public class TestModuleContainer extends AbstractTest {
Assert.assertNull("Failed to resolve test.", report.getResolutionException());
}
+ @Test
+ public void testModuleIDSetting() throws BundleException, IOException {
+ DummyContainerAdaptor adaptor = createDummyAdaptor();
+ ModuleContainer container = adaptor.getContainer();
+
+ // install the system.bundle
+ Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, Constants.SYSTEM_BUNDLE_SYMBOLICNAME, null, null, container);
+ ResolutionReport report = container.resolve(Arrays.asList(systemBundle), true);
+ Assert.assertNull("Failed to resolve system.bundle.", report.getResolutionException());
+
+ Map<String, String> manifest = new HashMap<String, String>();
+
+ // test by installing bundles with decreasing IDs
+ List<Module> modules = new ArrayList<Module>();
+ for (int i = 5; i > 0; i--) {
+ manifest.clear();
+ manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
+ manifest.put(Constants.BUNDLE_SYMBOLICNAME, String.valueOf(i));
+ modules.add(installDummyModule(manifest, i, manifest.get(Constants.BUNDLE_SYMBOLICNAME), container));
+ }
+
+ // test that the modules have decreasing ID starting at 5
+ long id = 5;
+ for (Module module : modules) {
+ Assert.assertEquals("Wrong ID found.", id--, module.getId().longValue());
+ }
+
+ // test that error occurs when trying to use an existing ID
+ manifest.clear();
+ manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
+ manifest.put(Constants.BUNDLE_SYMBOLICNAME, String.valueOf("test.dup.id"));
+ try {
+ installDummyModule(manifest, 5, manifest.get(Constants.BUNDLE_SYMBOLICNAME), container);
+ fail("Expected to fail installation with duplicate ID.");
+ } catch (IllegalStateException e) {
+ // expected
+ }
+ }
+
private static void assertWires(List<ModuleWire> required, List<ModuleWire>... provided) {
for (ModuleWire requiredWire : required) {
for (List<ModuleWire> providedList : provided) {

Back to the top