Search in sources :

Example 6 with MultiLock

use of uk.ac.ic.doc.slurp.multilock.MultiLock in project exist by eXist-db.

the class GetXMLResourceNoLockTest method testCollectionMaintainsLockWhenResourceIsSelectedNoLock.

@Test
public void testCollectionMaintainsLockWhenResourceIsSelectedNoLock() throws EXistException, LockException, SAXException, PermissionDeniedException, IOException {
    storeTestResource();
    final BrokerPool pool = BrokerPool.getInstance();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Collection testCollection = broker.openCollection(TestConstants.TEST_COLLECTION_URI, LockMode.READ_LOCK)) {
        final XmldbURI docPath = TestConstants.TEST_COLLECTION_URI.append(DOCUMENT_NAME_URI);
        try (final LockedDocument lockedDoc = broker.getXMLResource(docPath, LockMode.NO_LOCK)) {
            // if document is not present, null is returned
            if (lockedDoc == null) {
                fail("Binary document '" + docPath + " does not exist.");
            }
        }
        final LockManager lockManager = broker.getBrokerPool().getLockManager();
        final MultiLock colLock = lockManager.getPathLock(testCollection.getURI().toString());
        assertEquals("Collection does not have lock!", true, colLock.getReadHoldCount() > 0);
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) LockedDocument(org.exist.dom.persistent.LockedDocument) Collection(org.exist.collections.Collection) MultiLock(uk.ac.ic.doc.slurp.multilock.MultiLock) BrokerPool(org.exist.storage.BrokerPool) XmldbURI(org.exist.xmldb.XmldbURI)

Example 7 with MultiLock

use of uk.ac.ic.doc.slurp.multilock.MultiLock in project exist by eXist-db.

the class LockManagerTest method getDocumentLock_isStripedByPath.

@Test
public void getDocumentLock_isStripedByPath() {
    final LockManager lockManager = new LockManager(CONCURRENCY_LEVEL);
    final MultiLock doc1Lock1 = lockManager.getDocumentLock("/db/1.xml");
    assertNotNull(doc1Lock1);
    final MultiLock doc1Lock2 = lockManager.getDocumentLock("/db/1.xml");
    assertNotNull(doc1Lock2);
    assertTrue(doc1Lock1 == doc1Lock2);
    final MultiLock doc2Lock = lockManager.getDocumentLock("/db/a/b/c/2.xml");
    assertNotNull(doc2Lock);
    assertFalse(doc1Lock1 == doc2Lock);
    final MultiLock doc3Lock = lockManager.getDocumentLock("/db/d/e/f/3.xml");
    assertNotNull(doc3Lock);
    assertFalse(doc1Lock1 == doc3Lock);
    assertFalse(doc2Lock == doc3Lock);
}
Also used : MultiLock(uk.ac.ic.doc.slurp.multilock.MultiLock)

Aggregations

MultiLock (uk.ac.ic.doc.slurp.multilock.MultiLock)7 XmldbURI (org.exist.xmldb.XmldbURI)5 Tuple3 (com.evolvedbinary.j8fu.tuple.Tuple3)4 ReentrantLock (java.util.concurrent.locks.ReentrantLock)4 LockException (org.exist.util.LockException)4 Arrays (java.util.Arrays)2 Consumer (java.util.function.Consumer)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 LockType (org.exist.storage.lock.Lock.LockType)2 Configuration (org.exist.util.Configuration)2 WeakLazyStripes (org.exist.util.WeakLazyStripes)2 Collection (org.exist.collections.Collection)1 LockedDocument (org.exist.dom.persistent.LockedDocument)1 BrokerPool (org.exist.storage.BrokerPool)1 DBBroker (org.exist.storage.DBBroker)1