use of org.exist.dom.persistent.LockedDocument in project exist by eXist-db.
the class StoreResourceTest method checkAttributes.
private void checkAttributes(final XmldbURI docName, final String expectedOwner, final String expectedGroup, final int expectedMode, final Matcher<Long> expectedCreated, final Matcher<Long> expectedLastModified) throws EXistException, PermissionDeniedException {
final BrokerPool pool = existWebServer.getBrokerPool();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final LockedDocument lockedDoc = broker.getXMLResource(TEST_COLLECTION_URI.append(docName), Lock.LockMode.READ_LOCK)) {
final DocumentImpl doc = lockedDoc.getDocument();
final Permission permission = doc.getPermissions();
assertEquals("Owner value was not expected", expectedOwner, permission.getOwner().getName());
assertEquals("Group value was not expected", expectedGroup, permission.getGroup().getName());
assertEquals("Mode value was not expected", expectedMode, permission.getMode());
assertThat("Created value is not correct", doc.getCreated(), expectedCreated);
assertThat("LastModified value is not correct", doc.getLastModified(), expectedLastModified);
}
}
use of org.exist.dom.persistent.LockedDocument in project exist by eXist-db.
the class UpdateRecoverTest method read.
private void read(final BrokerPool pool) throws IllegalAccessException, DatabaseConfigurationException, InstantiationException, ClassNotFoundException, XMLDBException, EXistException, PermissionDeniedException, SAXException {
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
final Serializer serializer = broker.borrowSerializer();
try (final LockedDocument lockedDoc = broker.getXMLResource(TestConstants.TEST_COLLECTION_URI2.append(TestConstants.TEST_XML_URI), LockMode.READ_LOCK)) {
assertNotNull("Document '" + XmldbURI.ROOT_COLLECTION + "/test/test2/test.xml' should not be null", lockedDoc);
final String data = serializer.serialize(lockedDoc.getDocument());
assertNotNull(data);
} finally {
broker.returnSerializer(serializer);
}
}
}
use of org.exist.dom.persistent.LockedDocument in project exist by eXist-db.
the class AbstractJournalTest method read.
/**
* Read a document from the database.
*
* @param shouldExist true if the document should exist in the database, false if the document should not exist
* @param file The file that was previously stored
* @param dbFilename The name of the file to read from the database
*/
private void read(final boolean shouldExist, final Path file, final String dbFilename) throws EXistException, PermissionDeniedException, IOException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
final XmldbURI uri = TestConstants.TEST_COLLECTION_URI.append(dbFilename);
try (final LockedDocument lockedDoc = broker.getXMLResource(uri, Lock.LockMode.READ_LOCK)) {
if (!shouldExist) {
assertNull("Document should not exist in the database: " + uri, lockedDoc);
} else {
assertNotNull("Document does not exist in the database: " + uri, lockedDoc);
readAndVerify(broker, lockedDoc.getDocument(), file, dbFilename);
}
}
}
}
use of org.exist.dom.persistent.LockedDocument in project exist by eXist-db.
the class MoveResourceRecoveryTest method readAborted.
private void readAborted() throws EXistException, PermissionDeniedException, SAXException, IOException, LockException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
final Serializer serializer = broker.borrowSerializer();
try (final LockedDocument lockedDoc = broker.getXMLResource(TestConstants.TEST_COLLECTION_URI2.append("new_test2.xml"), LockMode.READ_LOCK)) {
assertNotNull("Document should not be null", lockedDoc);
final String data = serializer.serialize(lockedDoc.getDocument());
assertNotNull(data);
} finally {
broker.returnSerializer(serializer);
}
final TransactionManager transact = pool.getTransactionManager();
try (final Txn transaction = transact.beginTransaction();
final Collection root = broker.openCollection(TestConstants.TEST_COLLECTION_URI, LockMode.WRITE_LOCK)) {
assertNotNull(root);
transaction.acquireCollectionLock(() -> broker.getBrokerPool().getLockManager().acquireCollectionWriteLock(root.getURI()));
broker.removeCollection(transaction, root);
transact.commit(transaction);
}
}
}
use of org.exist.dom.persistent.LockedDocument in project exist by eXist-db.
the class MoveResourceRecoveryTest method read.
private void read() throws EXistException, PermissionDeniedException, SAXException, IOException, LockException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
final Serializer serializer = broker.borrowSerializer();
try (final LockedDocument lockedDoc = broker.getXMLResource(XmldbURI.ROOT_COLLECTION_URI.append("test/new_test.xml"), LockMode.READ_LOCK)) {
assertNotNull("Document should not be null", lockedDoc);
final String data = serializer.serialize(lockedDoc.getDocument());
assertNotNull(data);
} finally {
broker.returnSerializer(serializer);
}
final TransactionManager transact = pool.getTransactionManager();
try (final Txn transaction = transact.beginTransaction();
final Collection root = broker.openCollection(TestConstants.TEST_COLLECTION_URI, LockMode.WRITE_LOCK)) {
assertNotNull(root);
transaction.acquireCollectionLock(() -> broker.getBrokerPool().getLockManager().acquireCollectionWriteLock(root.getURI()));
broker.removeCollection(transaction, root);
transact.commit(transaction);
}
}
}
Aggregations