diff options
author | Simon Kaegi | 2009-01-09 21:10:49 +0000 |
---|---|---|
committer | Simon Kaegi | 2009-01-09 21:10:49 +0000 |
commit | e0bd9591c4adc9f8e274a5fd286dfa4f5e6be25a (patch) | |
tree | 72b38006be0f753e2bfcc3f83df691a94a1d0507 /bundles | |
parent | 8b50461df911d899768b2e9447bc830c077bf238 (diff) | |
download | rt.equinox.p2-e0bd9591c4adc9f8e274a5fd286dfa4f5e6be25a.tar.gz rt.equinox.p2-e0bd9591c4adc9f8e274a5fd286dfa4f5e6be25a.tar.xz rt.equinox.p2-e0bd9591c4adc9f8e274a5fd286dfa4f5e6be25a.zip |
Bug 257654 [engine] Cross process locking of profiles
Improving messages
Fixing up bogus mac and linux tests
Diffstat (limited to 'bundles')
2 files changed, 27 insertions, 13 deletions
diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfileLock.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfileLock.java index c6d92df66..649e028df 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfileLock.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfileLock.java @@ -20,14 +20,14 @@ import org.eclipse.osgi.util.NLS; * The purpose of this class is to enable cross process locking. * See 257654 for more details. */ -final class ProfileLock { +public class ProfileLock { private static final String LOCK_FILENAME = ".lock"; //$NON-NLS-1$ private final Location location; private Thread lockHolder; private int lockedCount; - protected ProfileLock(File profileDirectory) { + public ProfileLock(File profileDirectory) { location = createLockLocation(profileDirectory); } @@ -47,7 +47,7 @@ final class ProfileLock { } } - protected synchronized void checkLocked() { + public synchronized void checkLocked() { if (lockHolder == null) throw new IllegalStateException(Messages.SimpleProfileRegistry_Profile_not_locked); @@ -62,7 +62,7 @@ final class ProfileLock { } } - protected boolean lock() { + public synchronized boolean lock() { Thread current = Thread.currentThread(); try { if (lockHolder == null && location.lock()) @@ -77,7 +77,7 @@ final class ProfileLock { return true; } - protected void unlock() { + public synchronized void unlock() { if (lockHolder == null) throw new IllegalStateException(Messages.SimpleProfileRegistry_Profile_not_locked); diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/ProfileRegistryTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/ProfileRegistryTest.java index 1166ea79b..1e0d7b822 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/ProfileRegistryTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/ProfileRegistryTest.java @@ -15,8 +15,7 @@ import java.io.IOException; import java.util.Properties; import org.eclipse.core.runtime.FileLocator; import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; -import org.eclipse.equinox.internal.p2.engine.Profile; -import org.eclipse.equinox.internal.p2.engine.SimpleProfileRegistry; +import org.eclipse.equinox.internal.p2.engine.*; import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus; @@ -220,7 +219,7 @@ public class ProfileRegistryTest extends AbstractProvisioningTest { assertEquals(0, timestamps.length); } - public void testProfileLockingNested() { + public void testProfileLockingNested() throws IOException { final String SIMPLE_PROFILE = "Simple"; SimpleProfileRegistry simpleRgy = createAndValidateProfileRegistry("testData/engineTest/SimpleRegistry/", SIMPLE_PROFILE); Profile simpleProfile = (Profile) simpleRgy.getProfile(SIMPLE_PROFILE); @@ -247,15 +246,30 @@ public class ProfileRegistryTest extends AbstractProvisioningTest { simpleRgy.lockProfile(simpleProfile); simpleRgy.unlockProfile(simpleProfile); // Create a lock file to confirm locking - MockFileLock mockLock = new MockFileLock("testData/engineTest/SimpleRegistry/", SIMPLE_PROFILE); - assertTrue("Lock file does not exist", mockLock.getLockFile().exists()); - assertFalse("Lock file was not locked", mockLock.getLockFile().delete()); + + File lockDirectory = new File(getResourceAsBundleRelFile("testData/engineTest/SimpleRegistry/"), SIMPLE_PROFILE + ".profile"); + File lockFile = new File(lockDirectory, ".lock"); + assertTrue("Lock file does not exist", lockFile.exists()); + + ProfileLock profileLock = new ProfileLock(lockDirectory); + boolean locked = profileLock.lock(); + try { + assertFalse("Lock file was not locked", locked); + } finally { + if (locked) + profileLock.unlock(); + } simpleRgy.unlockProfile(simpleProfile); simpleRgy.lockProfile(simpleProfile); simpleRgy.unlockProfile(simpleProfile); - if (mockLock.getLockFile().exists()) { - assertTrue("Lock file could not removed", mockLock.getLockFile().delete()); + locked = profileLock.lock(); + try { + assertTrue("Lock file could not be locked", locked); + } finally { + if (locked) + profileLock.unlock(); } + assertTrue("Lock file could not removed", lockFile.delete()); } public void testProfileLockingMultiProcess() { |