Search in sources :

Example 91 with TransactionManager

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

the class CopyCollectionRecoveryTest method copyToSubCollection.

@Test(expected = PermissionDeniedException.class)
public void copyToSubCollection() throws Exception {
    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 Collection src = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
        broker.saveCollection(transaction, src);
        final Collection dst = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI2);
        broker.saveCollection(transaction, dst);
        broker.copyCollection(transaction, src, dst, src.getURI().lastSegment());
        fail("expect PermissionDeniedException: Cannot copy collection '/db/test' to it child collection '/db/test/test2'");
        transaction.commit();
    }
}
Also used : TransactionManager(org.exist.storage.txn.TransactionManager) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) Test(org.junit.Test)

Example 92 with TransactionManager

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

the class CopyResourceRecoveryTest method storeAborted.

private void storeAborted(final String testCollectionName, final String subCollection) throws EXistException, PermissionDeniedException, IOException, SAXException, LockException, URISyntaxException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    final TransactionManager transact = pool.getTransactionManager();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
        Collection testCollection;
        DocumentImpl doc;
        try (final Txn transaction = transact.beginTransaction()) {
            final Collection root = broker.getOrCreateCollection(transaction, XmldbURI.ROOT_COLLECTION_URI.append("test"));
            assertNotNull(root);
            broker.saveCollection(transaction, root);
            testCollection = broker.getOrCreateCollection(transaction, XmldbURI.ROOT_COLLECTION_URI.append("test").append(testCollectionName));
            assertNotNull(root);
            broker.saveCollection(transaction, root);
            final Collection subTestCollection = broker.getOrCreateCollection(transaction, XmldbURI.ROOT_COLLECTION_URI.append("test").append(testCollectionName).append(subCollection));
            assertNotNull(subTestCollection);
            broker.saveCollection(transaction, subTestCollection);
            final String sample;
            try (final InputStream is = SAMPLES.getRomeoAndJulietSample()) {
                assertNotNull(is);
                sample = InputStreamUtil.readString(is, UTF_8);
            }
            broker.storeDocument(transaction, XmldbURI.create("test2.xml"), new StringInputSource(sample), MimeType.XML_TYPE, subTestCollection);
            doc = subTestCollection.getDocument(broker, XmldbURI.create("test2.xml"));
            transact.commit(transaction);
        }
        final Txn transaction = transact.beginTransaction();
        broker.copyResource(transaction, doc, testCollection, XmldbURI.create("new_test2.xml"));
        broker.saveCollection(transaction, testCollection);
        // DO NOT COMMIT TRANSACTION
        pool.getJournalManager().get().flush(true, false);
    }
}
Also used : StringInputSource(org.exist.util.StringInputSource) TransactionManager(org.exist.storage.txn.TransactionManager) InputStream(java.io.InputStream) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) DocumentImpl(org.exist.dom.persistent.DocumentImpl)

Example 93 with TransactionManager

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

the class BFileOverflowTest method add.

@Test
public void add() throws EXistException, IOException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    final TransactionManager mgr = pool.getTransactionManager();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
        broker.flush();
        broker.sync(Sync.MAJOR);
        final BFile collectionsDb = (BFile) ((NativeBroker) broker).getStorage(NativeBroker.COLLECTIONS_DBX_ID);
        BrokerPool.FORCE_CORRUPTION = true;
        final Value key = new Value("test".getBytes());
        try (final Txn txn = mgr.beginTransaction()) {
            byte[] data = "_HELLO_YOU_".getBytes();
            collectionsDb.put(txn, key, new FixedByteArray(data, 0, data.length), true);
            for (int i = 1; i < 101; i++) {
                String value = "_HELLO_" + i;
                data = value.getBytes(UTF_8);
                collectionsDb.append(txn, key, new FixedByteArray(data, 0, data.length));
            }
            mgr.commit(txn);
        }
        // start a new transaction that will not be committed and thus undone
        final Txn txn = mgr.beginTransaction();
        for (int i = 1001; i < 2001; i++) {
            String value = "_HELLO_" + i;
            final byte[] data = value.getBytes(UTF_8);
            collectionsDb.append(txn, key, new FixedByteArray(data, 0, data.length));
        }
        collectionsDb.remove(txn, key);
        pool.getJournalManager().get().flush(true, false);
    }
}
Also used : TransactionManager(org.exist.storage.txn.TransactionManager) FixedByteArray(org.exist.util.FixedByteArray) Value(org.exist.storage.btree.Value) Txn(org.exist.storage.txn.Txn) BFile(org.exist.storage.index.BFile) Test(org.junit.Test)

Example 94 with TransactionManager

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

the class BTreeRecoverTest method add.

private void add(final BrokerPool pool) throws EXistException, IOException, BTreeException, TerminatedException {
    // Add some random data and force db corruption
    final TransactionManager mgr = pool.getTransactionManager();
    final NodeIdFactory idFact = pool.getNodeFactory();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
        broker.flush();
        final DOMFile domDb = ((NativeBroker) broker).getDOMFile();
        domDb.setOwnerObject(this);
        try (final Txn txn = mgr.beginTransaction()) {
            // put 1000 values into the btree
            for (int i = 1; i < 1001; i++) {
                final NodeId id = idFact.createInstance(i);
                domDb.addValue(txn, new NativeBroker.NodeRef(500, id), i);
            }
            final IndexQuery idx = new IndexQuery(IndexQuery.GT, new NativeBroker.NodeRef(500, idFact.createInstance(800)));
            domDb.remove(txn, idx, null);
            mgr.commit(txn);
        }
        // start a dirty, uncommitted transaction. This will be rolled back by the recovery.
        final Txn txn = mgr.beginTransaction();
        for (int i = 801; i < 2001; i++) {
            domDb.addValue(txn, new NativeBroker.NodeRef(500, idFact.createInstance(i)), i);
        }
        for (int i = 101; i < 301; i++) {
            domDb.addValue(txn, new NativeBroker.NodeRef(500, idFact.createInstance(i)), i * 3);
        }
        final IndexQuery idx = new IndexQuery(IndexQuery.GT, new NativeBroker.NodeRef(500, idFact.createInstance(600)));
        domDb.remove(txn, idx, null);
        // DO NOT COMMIT THE TRANSACTION!
        pool.getJournalManager().get().flush(true, false);
    }
}
Also used : NodeIdFactory(org.exist.numbering.NodeIdFactory) IndexQuery(org.exist.storage.btree.IndexQuery) TransactionManager(org.exist.storage.txn.TransactionManager) NodeId(org.exist.numbering.NodeId) DOMFile(org.exist.storage.dom.DOMFile) Txn(org.exist.storage.txn.Txn)

Example 95 with TransactionManager

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

the class AbstractUpdateTest method update.

@Test
public final void update() throws EXistException, DatabaseConfigurationException, LockException, SAXException, PermissionDeniedException, IOException, ParserConfigurationException, XPathException {
    BrokerPool.FORCE_CORRUPTION = true;
    BrokerPool pool = startDb();
    try {
        final TransactionManager transact = pool.getTransactionManager();
        try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
            final DocumentImpl doc = init(broker, transact);
            final MutableDocumentSet docs = new DefaultDocumentSet();
            docs.add(doc);
            doUpdate(broker, transact, docs);
            pool.getJournalManager().get().flush(true, false);
        }
        BrokerPool.FORCE_CORRUPTION = false;
        existEmbeddedServer.restart(false);
        pool = existEmbeddedServer.getBrokerPool();
        read(pool);
    } finally {
        existEmbeddedServer.stopDb(true);
    }
}
Also used : MutableDocumentSet(org.exist.dom.persistent.MutableDocumentSet) DefaultDocumentSet(org.exist.dom.persistent.DefaultDocumentSet) TransactionManager(org.exist.storage.txn.TransactionManager) DocumentImpl(org.exist.dom.persistent.DocumentImpl) Test(org.junit.Test)

Aggregations

TransactionManager (org.exist.storage.txn.TransactionManager)131 Txn (org.exist.storage.txn.Txn)128 Collection (org.exist.collections.Collection)86 DBBroker (org.exist.storage.DBBroker)70 BrokerPool (org.exist.storage.BrokerPool)61 StringInputSource (org.exist.util.StringInputSource)27 EXistException (org.exist.EXistException)21 XmldbURI (org.exist.xmldb.XmldbURI)20 Sequence (org.exist.xquery.value.Sequence)20 XQuery (org.exist.xquery.XQuery)18 InputSource (org.xml.sax.InputSource)18 DocumentImpl (org.exist.dom.persistent.DocumentImpl)17 Test (org.junit.Test)16 DefaultDocumentSet (org.exist.dom.persistent.DefaultDocumentSet)15 InputStream (java.io.InputStream)14 StringReader (java.io.StringReader)13 MutableDocumentSet (org.exist.dom.persistent.MutableDocumentSet)13 PermissionDeniedException (org.exist.security.PermissionDeniedException)13 IOException (java.io.IOException)12 Modification (org.exist.xupdate.Modification)12