use of org.exist.storage.BrokerPool in project exist by eXist-db.
the class RestoreAppsTest method restoreOverwriteOlderWithIncompleteSemver.
/**
* Semver coercion: create an app with an incomplete semver and try to restore it.
* The newer version inside the backup should overwrite the older in the database.
*
* @throws Exception in case of error
*/
@Test
public void restoreOverwriteOlderWithIncompleteSemver() throws Exception {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
createAndInstallApp("2.0.0", REPO_XML_APP);
Path backup = export(pool);
removePackage(pool);
createAndInstallApp("1.0", REPO_XML_APP);
restoreAndCheck(pool, backup, null);
}
use of org.exist.storage.BrokerPool in project exist by eXist-db.
the class RestoreAppsTest method restoreSkipNewer.
/**
* Create an app package and generate a backup. Install a newer version
* of the same package and restore the backup. The newer version inside
* the expath repo should be preserved and not overwritten.
*
* @throws Exception in case of error
*/
@Test
public void restoreSkipNewer() throws Exception {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
createAndInstallApp("1.0.0", REPO_XML_APP);
Path backup = export(pool);
removePackage(pool);
createAndInstallApp("2.0.0", REPO_XML_APP);
restoreAndCheck(pool, backup, "Newer version is already installed.");
}
use of org.exist.storage.BrokerPool in project exist by eXist-db.
the class SystemExportFiltersTest method exportImport.
@Test
public void exportImport() throws Exception {
Path file;
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final Txn transaction = pool.getTransactionManager().beginTransaction()) {
List<String> filters = new ArrayList<>();
filters.add(FilterForBackup.class.getName());
broker.getConfiguration().setProperty(SystemExport.CONFIG_FILTERS, filters);
final Collection test = broker.getCollection(TEST_COLLECTION_URI);
assertNotNull(test);
boolean direct = true;
final SystemExport sysexport = new SystemExport(broker, transaction, null, null, direct);
final Path backupDir = tempFolder.newFolder().toPath();
file = sysexport.export(backupDir.toAbsolutePath().toString(), false, false, null);
transaction.commit();
}
TestUtils.cleanupDB();
final SystemImport restore = new SystemImport(pool);
final RestoreListener listener = new LogRestoreListener();
restore.restore(TestUtils.ADMIN_DB_USER, TestUtils.ADMIN_DB_PWD, null, file, listener);
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final Txn transaction = pool.getTransactionManager().beginTransaction()) {
final Collection test = broker.getCollection(TEST_COLLECTION_URI);
assertNotNull(test);
DocumentImpl doc = getDoc(broker, test, doc01uri.lastSegment());
assertEquals(XML1_BACKUP, serializer(broker, doc));
doc = getDoc(broker, test, doc02uri.lastSegment());
assertEquals(XML2_PROPER, serializer(broker, doc));
doc = getDoc(broker, test, doc03uri.lastSegment());
assertEquals(XML3_PROPER, serializer(broker, doc));
doc = getDoc(broker, test, doc11uri.lastSegment());
assertTrue(doc instanceof BinaryDocument);
try (final InputStream is = broker.getBinaryResource(transaction, ((BinaryDocument) doc))) {
assertEquals(BINARY, InputStreamUtil.readString(is, UTF_8));
}
transaction.commit();
}
}
use of org.exist.storage.BrokerPool in project exist by eXist-db.
the class CollectionRemovalTest method initDB.
@Before
public void initDB() throws EXistException, PermissionDeniedException, IOException, SAXException, LockException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
final TransactionManager transact = pool.getTransactionManager();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final Txn transaction = transact.beginTransaction()) {
final int worldReadable = 0744;
final int worldForbidden = 0700;
/*
* Creates 3 collections: /db/test, /db/test/test2, /db/test/test2/test3 and /db/test/test2/test4,
* and stores one document into each.
* Collection /db/test/test2/test3 is only readable by the owner (i.e. admin user).
*/
final List<Tuple2<XmldbURI, Integer>> collectionUriAndModes = Arrays.asList(Tuple(TestConstants.TEST_COLLECTION_URI2, worldReadable), Tuple(TestConstants.TEST_COLLECTION_URI3, worldForbidden), Tuple(TestConstants.TEST_COLLECTION_URI2.append("test4"), worldReadable));
// creat collections
for (final Tuple2<XmldbURI, Integer> collectionUriAndMode : collectionUriAndModes) {
final XmldbURI collectionUri = collectionUriAndMode._1;
final int mode = collectionUriAndMode._2;
// create collection
final Collection collection = broker.getOrCreateCollection(transaction, collectionUri);
assertNotNull(collection);
final Permission perms = collection.getPermissions();
perms.setMode(mode);
broker.saveCollection(transaction, collection);
// store document
broker.storeDocument(transaction, XmldbURI.create("document.xml"), new StringInputSource(DATA), MimeType.XML_TYPE, collection);
}
transact.commit(transaction);
}
}
use of org.exist.storage.BrokerPool in project exist by eXist-db.
the class CollectionRemovalTest method retrieveDoc.
private void retrieveDoc(final XmldbURI uri) throws EXistException, PermissionDeniedException, SAXException, LockException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final Collection test = broker.openCollection(uri, LockMode.READ_LOCK)) {
assertNotNull(test);
try (final LockedDocument lockedDoc = test.getDocumentWithLock(broker, XmldbURI.createInternal("document.xml"), LockMode.READ_LOCK)) {
assertNotNull(lockedDoc);
final Serializer serializer = broker.borrowSerializer();
try {
String xml = serializer.serialize(lockedDoc.getDocument());
} finally {
broker.returnSerializer(serializer);
}
// NOTE: early release of Collection lock inline with Asymmetrical Locking scheme
test.close();
}
}
}
Aggregations