Search in sources :

Example 66 with BrokerPool

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);
}
Also used : Path(java.nio.file.Path) BrokerPool(org.exist.storage.BrokerPool) Test(org.junit.Test)

Example 67 with BrokerPool

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.");
}
Also used : Path(java.nio.file.Path) BrokerPool(org.exist.storage.BrokerPool) Test(org.junit.Test)

Example 68 with BrokerPool

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();
    }
}
Also used : Path(java.nio.file.Path) LogRestoreListener(org.exist.backup.restore.listener.LogRestoreListener) InputStream(java.io.InputStream) Txn(org.exist.storage.txn.Txn) DocumentImpl(org.exist.dom.persistent.DocumentImpl) BinaryDocument(org.exist.dom.persistent.BinaryDocument) DBBroker(org.exist.storage.DBBroker) Collection(org.exist.collections.Collection) LogRestoreListener(org.exist.backup.restore.listener.LogRestoreListener) RestoreListener(org.exist.backup.restore.listener.RestoreListener) BrokerPool(org.exist.storage.BrokerPool)

Example 69 with BrokerPool

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);
    }
}
Also used : Txn(org.exist.storage.txn.Txn) DBBroker(org.exist.storage.DBBroker) StringInputSource(org.exist.util.StringInputSource) TransactionManager(org.exist.storage.txn.TransactionManager) Tuple2(com.evolvedbinary.j8fu.tuple.Tuple2) Permission(org.exist.security.Permission) BrokerPool(org.exist.storage.BrokerPool) XmldbURI(org.exist.xmldb.XmldbURI)

Example 70 with BrokerPool

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();
        }
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) LockedDocument(org.exist.dom.persistent.LockedDocument) BrokerPool(org.exist.storage.BrokerPool) Serializer(org.exist.storage.serializers.Serializer)

Aggregations

BrokerPool (org.exist.storage.BrokerPool)381 DBBroker (org.exist.storage.DBBroker)300 Txn (org.exist.storage.txn.Txn)180 Sequence (org.exist.xquery.value.Sequence)157 Test (org.junit.Test)115 XQuery (org.exist.xquery.XQuery)105 Collection (org.exist.collections.Collection)71 StringInputSource (org.exist.util.StringInputSource)66 TransactionManager (org.exist.storage.txn.TransactionManager)61 Source (org.exist.source.Source)43 StringSource (org.exist.source.StringSource)40 CompiledXQuery (org.exist.xquery.CompiledXQuery)38 Path (java.nio.file.Path)22 XmldbURI (org.exist.xmldb.XmldbURI)21 XPathException (org.exist.xquery.XPathException)21 Properties (java.util.Properties)20 LockedDocument (org.exist.dom.persistent.LockedDocument)20 InputSource (org.xml.sax.InputSource)20 IOException (java.io.IOException)19 XQueryContext (org.exist.xquery.XQueryContext)19