lock.obtain();
@Test(expected = TDBException.class) public void location_lock_dir_error_01() throws IOException { Assume.assumeTrue(negativePidsTreatedAsAlive); Location dir = Location.create(tempDir.getRoot().getAbsolutePath()); LocationLock lock = dir.getLock(); Assert.assertTrue(lock.canLock()); Assert.assertFalse(lock.isLocked()); Assert.assertFalse(lock.isOwned()); Assert.assertTrue(lock.canObtain()); // Write a fake PID to the lock file try (BufferedWriter writer = new BufferedWriter(new FileWriter(dir.getPath("tdb.lock")))) { // Fake PID that would never be valid writer.write(Integer.toString(-1234)); } Assert.assertTrue(lock.isLocked()); Assert.assertFalse(lock.isOwned()); // Attempting to obtain the lock should now error Assert.assertFalse(lock.canObtain()); lock.obtain(); }
@Test(expected = TDBException.class) public void location_lock_dir_error_01() throws IOException { Assume.assumeTrue(negativePidsTreatedAsAlive); Location dir = Location.create(tempDir.getRoot().getAbsolutePath()); LocationLock lock = dir.getLock(); Assert.assertTrue(lock.canLock()); Assert.assertFalse(lock.isLocked()); Assert.assertFalse(lock.isOwned()); Assert.assertTrue(lock.canObtain()); // Write a fake PID to the lock file try(BufferedWriter writer = new BufferedWriter(new FileWriter(dir.getPath("tdb.lock")))) { // Fake PID that would never be valid writer.write(Integer.toString(-1234)); } Assert.assertTrue(lock.isLocked()); Assert.assertFalse(lock.isOwned()); // Attempting to obtain the lock should now error Assert.assertFalse(lock.canObtain()); lock.obtain(); }
@Test public void location_lock_dir_01() { Location dir = Location.create(tempDir.getRoot().getAbsolutePath()); LocationLock lock = dir.getLock(); Assert.assertTrue(lock.canLock()); Assert.assertFalse(lock.isLocked()); Assert.assertFalse(lock.isOwned()); Assert.assertTrue(lock.canObtain()); // Try to obtain the lock lock.obtain(); Assert.assertTrue(lock.isLocked()); Assert.assertTrue(lock.isOwned()); // Release the lock lock.release(); Assert.assertFalse(lock.isLocked()); Assert.assertFalse(lock.isOwned()); }
@Test public void location_lock_dir_01() { Location dir = Location.create(tempDir.getRoot().getAbsolutePath()); LocationLock lock = dir.getLock(); Assert.assertTrue(lock.canLock()); Assert.assertFalse(lock.isLocked()); Assert.assertFalse(lock.isOwned()); Assert.assertTrue(lock.canObtain()); // Try to obtain the lock lock.obtain(); Assert.assertTrue(lock.isLocked()); Assert.assertTrue(lock.isOwned()); // Release the lock lock.release(); Assert.assertFalse(lock.isLocked()); Assert.assertFalse(lock.isOwned()); }