diff options
2 files changed, 44 insertions, 3 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 bcfb46950..69df07323 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 @@ -1070,6 +1070,38 @@ public class TestModuleContainer extends AbstractTest { } @Test + public void testTimestampSeeding() throws BundleException, IOException, InterruptedException { + Assert.assertNotEquals("The timestamps are the same!", createTestContainerAndGetTimestamp(), createTestContainerAndGetTimestamp()); + } + + private long createTestContainerAndGetTimestamp() throws BundleException, IOException, InterruptedException { + // wait here to ensure current time really has increased + Thread.sleep(100); + DummyContainerAdaptor adaptor = createDummyAdaptor(); + ModuleContainer container = adaptor.getContainer(); + DummyModuleDatabase database = adaptor.getDatabase(); + + Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, container); + + container.resolve(Arrays.asList(systemBundle), true); + + // actually launch the container + systemBundle.start(); + + // install some bundles and set some settings + container.getFrameworkStartLevel().setInitialBundleStartLevel(2); + Module c4 = installDummyModule("c4_v1.MF", "c4_v1", container); + Module lazy1 = installDummyModule("lazy1_v1.MF", "lazy1", container); + + container.resolve(Arrays.asList(c4, lazy1), true); + + // set some settings + Assert.assertEquals("Wrong startlevel.", 2, c4.getStartLevel()); + Assert.assertEquals("Wrong startlevel.", 2, lazy1.getStartLevel()); + return database.getTimestamp(); + } + + @Test public void testEventsStartLevelBeginningAt100() throws BundleException, IOException { doTestEventsStartLevel(100); } diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleDatabase.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleDatabase.java index 57ed77d82..6d3a5bd4b 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleDatabase.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleDatabase.java @@ -97,6 +97,13 @@ public class ModuleDatabase { */ final AtomicLong allTimeStamp; + /** + * Holds the construction time which is used to check for empty database on + * load. This is necessary to ensure the loaded database is consistent with + * what was persisted. + */ + final long constructionTime; + private final Capabilities capabilities; /** @@ -140,8 +147,10 @@ public class ModuleDatabase { this.wirings = new HashMap<ModuleRevision, ModuleWiring>(); // Start at id 1 because 0 is reserved for the system bundle this.nextId = new AtomicLong(1); - this.revisionsTimeStamp = new AtomicLong(0); - this.allTimeStamp = new AtomicLong(0); + // seed with current time to avoid duplicate timestamps after using -clean + this.constructionTime = System.currentTimeMillis(); + this.revisionsTimeStamp = new AtomicLong(constructionTime); + this.allTimeStamp = new AtomicLong(constructionTime); this.moduleSettings = new HashMap<Long, EnumSet<Settings>>(); this.capabilities = new Capabilities(); } @@ -865,7 +874,7 @@ public class ModuleDatabase { public final void load(DataInputStream in) throws IOException { writeLock(); try { - if (allTimeStamp.get() != 0) + if (allTimeStamp.get() != constructionTime) throw new IllegalStateException("Can only load into a empty database."); //$NON-NLS-1$ Persistence.load(this, in); } finally { |