Search in sources :

Example 56 with BrokerPool

use of org.exist.storage.BrokerPool in project exist by eXist-db.

the class SystemExportImportTest method setup.

@BeforeClass
public static void setup() throws EXistException, PermissionDeniedException, IOException, SAXException, CollectionConfigurationException, LockException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        final Collection test = broker.getOrCreateCollection(transaction, TEST_COLLECTION_URI);
        assertNotNull(test);
        broker.saveCollection(transaction, test);
        final CollectionConfigurationManager mgr = pool.getConfigurationManager();
        mgr.addConfiguration(transaction, broker, test, COLLECTION_CONFIG);
        broker.storeDocument(transaction, doc01uri.lastSegment(), new StringInputSource(XML1), MimeType.XML_TYPE, test);
        broker.storeDocument(transaction, doc02uri.lastSegment(), new StringInputSource(XML2), MimeType.XML_TYPE, test);
        broker.storeDocument(transaction, doc03uri.lastSegment(), new StringInputSource(XML3), MimeType.XML_TYPE, test);
        broker.storeDocument(transaction, doc11uri.lastSegment(), new StringInputSource(BINARY.getBytes(UTF_8)), MimeType.BINARY_TYPE, test);
        transaction.commit();
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) StringInputSource(org.exist.util.StringInputSource) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) CollectionConfigurationManager(org.exist.collections.CollectionConfigurationManager) BrokerPool(org.exist.storage.BrokerPool)

Example 57 with BrokerPool

use of org.exist.storage.BrokerPool in project exist by eXist-db.

the class CollectionOrderTest method collectionOrderIsOldestInsertedFirst_persistedOverRestart.

/**
 * Ensures that when iterating over Collections the order of iteration is always the same
 * and that this persists across restarts of database
 */
@Test
public void collectionOrderIsOldestInsertedFirst_persistedOverRestart() throws EXistException, PermissionDeniedException, IOException, TriggerException, LockException, DatabaseConfigurationException {
    BrokerPool pool = existEmbeddedServer.getBrokerPool();
    final List<String> subCollectionNames1 = generateRandomNames(SUB_COLLECTION_COUNT);
    createSubCollections(pool, subCollectionNames1);
    // we delete some collections to ensure that collection ids will be reused in the next createSubCollections step
    final List<String> subCollectionNames1_toDelete = selectRandom(subCollectionNames1, SUB_COLLECTION_COUNT / 10);
    deleteSubCollections(pool, subCollectionNames1_toDelete);
    final List<String> subsetSubCollectionNames1 = filterFrom(subCollectionNames1, subCollectionNames1_toDelete);
    // check the order of sub-collections
    assertOrderOfSubCollections(pool, subsetSubCollectionNames1);
    // restart the server to ensure the order is correctly persisted
    existEmbeddedServer.restart();
    pool = existEmbeddedServer.getBrokerPool();
    // check the order of sub-collections
    assertOrderOfSubCollections(pool, subsetSubCollectionNames1);
    // add some more sub-collections
    final List<String> subCollectionNames2 = generateRandomNames(SUB_COLLECTION_COUNT / 2);
    createSubCollections(pool, subCollectionNames2);
    // check the order of all sub-collections
    final List<String> allSubCollectionNames = new ArrayList<>(subsetSubCollectionNames1.size() + subCollectionNames2.size());
    allSubCollectionNames.addAll(subsetSubCollectionNames1);
    allSubCollectionNames.addAll(subCollectionNames2);
    assertOrderOfSubCollections(pool, allSubCollectionNames);
    // restart the server to ensure the order is correctly persisted
    existEmbeddedServer.restart();
    pool = existEmbeddedServer.getBrokerPool();
    // check the order of all sub-collections
    assertOrderOfSubCollections(pool, allSubCollectionNames);
}
Also used : BrokerPool(org.exist.storage.BrokerPool) Test(org.junit.Test)

Example 58 with BrokerPool

use of org.exist.storage.BrokerPool in project exist by eXist-db.

the class CollectionOrderTest method createTestCollection.

@Before
public void createTestCollection() throws EXistException, PermissionDeniedException, IOException, TriggerException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        broker.getOrCreateCollection(transaction, TEST_COLLECTION);
        transaction.commit();
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) Txn(org.exist.storage.txn.Txn) BrokerPool(org.exist.storage.BrokerPool) Before(org.junit.Before)

Example 59 with BrokerPool

use of org.exist.storage.BrokerPool in project exist by eXist-db.

the class CollectionOrderTest method collectionOrderIsOldestInsertedFirst.

/**
 * Ensures that when iterating over Collections the order of iteration is always the same
 */
@Test
public void collectionOrderIsOldestInsertedFirst() throws EXistException, PermissionDeniedException, IOException, TriggerException, LockException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    final List<String> subCollectionNames1 = generateRandomNames(SUB_COLLECTION_COUNT / 2);
    createSubCollections(pool, subCollectionNames1);
    // we delete some collections to ensure that collection ids will be reused in the next createSubCollections step
    final List<String> subCollectionNames1_toDelete = selectRandom(subCollectionNames1, SUB_COLLECTION_COUNT / 10);
    deleteSubCollections(pool, subCollectionNames1_toDelete);
    final List<String> subsetSubCollectionNames1 = filterFrom(subCollectionNames1, subCollectionNames1_toDelete);
    final List<String> subCollectionNames2 = generateRandomNames(SUB_COLLECTION_COUNT / 2);
    createSubCollections(pool, subCollectionNames2);
    final List<String> allSubCollectionNames = new ArrayList<>(subsetSubCollectionNames1.size() + subCollectionNames2.size());
    allSubCollectionNames.addAll(subsetSubCollectionNames1);
    allSubCollectionNames.addAll(subCollectionNames2);
    assertOrderOfSubCollections(pool, allSubCollectionNames);
}
Also used : BrokerPool(org.exist.storage.BrokerPool) Test(org.junit.Test)

Example 60 with BrokerPool

use of org.exist.storage.BrokerPool in project exist by eXist-db.

the class CollectionStoreTest method store.

@Test
public void store() throws EXistException, PermissionDeniedException, IOException, SAXException, LockException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        try (final Collection col = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI)) {
            broker.storeDocument(transaction, TEST_XML_DOC_URI, new StringInputSource(TEST_XML_DOC), MimeType.XML_TYPE, col);
            broker.saveCollection(transaction, col);
        }
        try (final Collection col = broker.openCollection(TestConstants.TEST_COLLECTION_URI, LockMode.READ_LOCK)) {
            try (final LockedDocument lockedDoc = col.getDocumentWithLock(broker, TEST_XML_DOC_URI, LockMode.READ_LOCK)) {
                // NOTE: early release of collection lock inline with async locking
                col.close();
                if (lockedDoc != null) {
                    final Source expected = Input.fromString(TEST_XML_DOC).build();
                    final Source actual = Input.fromDocument(lockedDoc.getDocument()).build();
                    final Diff diff = DiffBuilder.compare(expected).withTest(actual).checkForSimilar().build();
                    assertFalse(diff.toString(), diff.hasDifferences());
                }
            }
        }
        transaction.commit();
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) StringInputSource(org.exist.util.StringInputSource) Diff(org.xmlunit.diff.Diff) LockedDocument(org.exist.dom.persistent.LockedDocument) Txn(org.exist.storage.txn.Txn) BrokerPool(org.exist.storage.BrokerPool) StringInputSource(org.exist.util.StringInputSource) Source(javax.xml.transform.Source) Test(org.junit.Test)

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