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();
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations