Search in sources :

Example 26 with Location

use of org.apache.jena.tdb.base.file.Location in project jena by apache.

the class TestLocationLock method location_lock_mem.

@Test
public void location_lock_mem() {
    Location mem = Location.mem();
    LocationLock lock = mem.getLock();
    Assert.assertFalse(lock.canLock());
    Assert.assertFalse(lock.isLocked());
    Assert.assertFalse(lock.isOwned());
    Assert.assertFalse(lock.canObtain());
}
Also used : LocationLock(org.apache.jena.tdb.base.file.LocationLock) Location(org.apache.jena.tdb.base.file.Location) Test(org.junit.Test)

Example 27 with Location

use of org.apache.jena.tdb.base.file.Location 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());
}
Also used : LocationLock(org.apache.jena.tdb.base.file.LocationLock) Location(org.apache.jena.tdb.base.file.Location) Test(org.junit.Test)

Example 28 with Location

use of org.apache.jena.tdb.base.file.Location 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();
}
Also used : FileWriter(java.io.FileWriter) LocationLock(org.apache.jena.tdb.base.file.LocationLock) Location(org.apache.jena.tdb.base.file.Location) BufferedWriter(java.io.BufferedWriter) Test(org.junit.Test)

Example 29 with Location

use of org.apache.jena.tdb.base.file.Location 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();
}
Also used : FileWriter(java.io.FileWriter) LocationLock(org.apache.jena.tdb.base.file.LocationLock) Location(org.apache.jena.tdb.base.file.Location) BufferedWriter(java.io.BufferedWriter) Test(org.junit.Test)

Aggregations

Location (org.apache.jena.tdb.base.file.Location)29 Test (org.junit.Test)16 BaseTest (org.apache.jena.atlas.junit.BaseTest)9 LocationLock (org.apache.jena.tdb.base.file.LocationLock)8 ConfigTest (org.apache.jena.tdb.ConfigTest)6 BufferedWriter (java.io.BufferedWriter)4 FileWriter (java.io.FileWriter)4 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)4 StoreConnection (org.apache.jena.tdb.StoreConnection)4 TupleIndex (org.apache.jena.tdb.store.tupletable.TupleIndex)4 Record (org.apache.jena.tdb.base.record.Record)3 StoreParams (org.apache.jena.tdb.setup.StoreParams)3 AssemblerException (org.apache.jena.assembler.exceptions.AssemblerException)2 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)2 Dataset (org.apache.jena.query.Dataset)2 VocabTDB.pLocation (org.apache.jena.tdb.assembler.VocabTDB.pLocation)2 RecordFactory (org.apache.jena.tdb.base.record.RecordFactory)2 RangeIndex (org.apache.jena.tdb.index.RangeIndex)2 BPlusTree (org.apache.jena.tdb.index.bplustree.BPlusTree)2 ColumnMap (org.apache.jena.tdb.lib.ColumnMap)2