use of org.apache.jena.tdb.base.file.LocationLock in project jena by apache.
the class TestLocationLock method location_lock_dir_01.
@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());
}
use of org.apache.jena.tdb.base.file.LocationLock in project jena by apache.
the class TestLocationLock method location_lock_dir_error_01.
@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();
}
use of org.apache.jena.tdb.base.file.LocationLock in project jena by apache.
the class TestLocationLock method location_lock_dir_error_02.
@Test(expected = TDBException.class)
public void location_lock_dir_error_02() 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 release a lock we don't own should error
Assert.assertFalse(lock.canObtain());
lock.release();
}
Aggregations