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);
}
}
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);
}
Aggregations