use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.
the class GetXMLResourceNoLockTest method storeTestResource.
private void storeTestResource() throws EXistException, PermissionDeniedException, IOException, SAXException, LockException {
final BrokerPool pool = BrokerPool.getInstance();
final TransactionManager transact = pool.getTransactionManager();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final Txn transaction = transact.beginTransaction()) {
final Collection collection = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
broker.saveCollection(transaction, collection);
broker.storeDocument(transaction, DOCUMENT_NAME_URI, new StringInputSource(EMPTY_BINARY_FILE.getBytes(UTF_8)), MimeType.TEXT_TYPE, collection);
transact.commit(transaction);
}
}
use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.
the class BlobStoreRecoveryTest method newBlobDb.
private BlobDb newBlobDb(final Path journalDir, final Path blobDbx, final Path blobDir) throws BrokerPoolServiceException, EXistException {
final Configuration mockConfiguration = createNiceMock(Configuration.class);
expect(mockConfiguration.getProperty(Journal.PROPERTY_RECOVERY_JOURNAL_DIR)).andReturn(journalDir);
expect(mockConfiguration.getProperty(BrokerPool.PROPERTY_RECOVERY_GROUP_COMMIT, false)).andReturn(false);
expect(mockConfiguration.getProperty(PROPERTY_RECOVERY_SYNC_ON_COMMIT, true)).andReturn(true);
expect(mockConfiguration.getProperty(PROPERTY_RECOVERY_SIZE_MIN, 1)).andReturn(1);
expect(mockConfiguration.getProperty(PROPERTY_RECOVERY_SIZE_LIMIT, 100)).andReturn(100);
replay(mockConfiguration);
final BrokerPool mockBrokerPool = createNiceMock(BrokerPool.class);
if (!cleanShutdown) {
// NOTE: needed so we don't checkpoint at clean shutdown and can simulate a crash!
mockBrokerPool.FORCE_CORRUPTION = true;
}
final SecurityManager mockSecurityManager = createNiceMock(SecurityManager.class);
final Subject mockSystemSubject = createNiceMock(Subject.class);
expect(mockBrokerPool.getSecurityManager()).andReturn(mockSecurityManager).anyTimes();
expect(mockSecurityManager.getSystemSubject()).andReturn(mockSystemSubject).anyTimes();
replay(mockSecurityManager);
final JournalManager journalManager = new JournalManager();
journalManager.configure(mockConfiguration);
final DBBroker mockSystemBroker = createNiceMock(DBBroker.class);
final Txn mockSystemTransaction = createNiceMock(Txn.class);
final SystemTaskManager mockSystemTaskManager = createNiceMock(SystemTaskManager.class);
mockSystemTaskManager.processTasks(mockSystemBroker, mockSystemTransaction);
expectLastCall().anyTimes();
replay(mockSystemTaskManager);
final DBBroker mockBroker = createNiceMock(DBBroker.class);
expect(mockBroker.getBrokerPool()).andReturn(mockBrokerPool).anyTimes();
expect(mockBrokerPool.getBroker()).andReturn(mockBroker).anyTimes();
replay(mockBroker);
final TransactionManager transactionManager = new TransactionManager(mockBrokerPool, Optional.of(journalManager), mockSystemTaskManager);
final Scheduler mockScheduler = createNiceMock(Scheduler.class);
final BlobStore blobStore = new BlobStoreImpl(mockBrokerPool, blobDbx, blobDir, DIGEST_TYPE);
expect(mockBrokerPool.getConfiguration()).andReturn(mockConfiguration).anyTimes();
expect(mockBrokerPool.getScheduler()).andReturn(mockScheduler);
expect(mockScheduler.createPeriodicJob(anyLong(), anyObject(FileLockHeartBeat.class), anyLong(), anyObject(Properties.class))).andReturn(true);
expect(mockBrokerPool.getTransactionManager()).andReturn(transactionManager).anyTimes();
expect(mockBrokerPool.getThreadGroup()).andReturn(Thread.currentThread().getThreadGroup());
expect(mockBrokerPool.getId()).andReturn("BlobStoreRecoveryTest").times(2);
expect(mockBrokerPool.getJournalManager()).andReturn(Optional.of(journalManager)).anyTimes();
expect(mockBrokerPool.getBlobStore()).andReturn(blobStore).anyTimes();
replay(mockBrokerPool);
journalManager.prepare(mockBrokerPool);
final RecoveryManager recoveryManager = new RecoveryManager(mockBroker, journalManager, false);
recoveryManager.recover();
return new BlobDb(transactionManager, blobStore);
}
use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.
the class MoveCollectionTest method moveDeep.
/**
* Test move collection /db/a/b/c/d/e/f/g/h/i/j/k to /db/z/y/x/w/v/u/k
*/
@Test
public void moveDeep() throws EXistException, IOException, PermissionDeniedException, TriggerException, 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 XmldbURI srcUri = XmldbURI.create("/db/a/b/c/d/e/f/g/h/i/j/k");
final XmldbURI destUri = XmldbURI.create("/db/z/y/x/w/v/u");
try (final Collection src = broker.getOrCreateCollection(transaction, srcUri)) {
assertNotNull(src);
broker.saveCollection(transaction, src);
}
try (final Collection dst = broker.getOrCreateCollection(transaction, destUri)) {
assertNotNull(dst);
broker.saveCollection(transaction, dst);
}
try (final Collection src = broker.openCollection(srcUri, Lock.LockMode.WRITE_LOCK);
final Collection dst = broker.openCollection(destUri, Lock.LockMode.WRITE_LOCK)) {
broker.moveCollection(transaction, src, dst, src.getURI().lastSegment());
}
transact.commit(transaction);
}
}
use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.
the class CustomIndexTest method xupdateRemove.
/**
* Remove nodes from different levels of the tree and check if the index is
* correctly updated.
*/
@Test
public void xupdateRemove() throws EXistException, PermissionDeniedException, XPathException, ParserConfigurationException, 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()) {
checkIndex(broker, docs, "cha", 1);
checkIndex(broker, docs, "le8", 1);
XQuery xquery = pool.getXQueryService();
assertNotNull(xquery);
Sequence seq = xquery.execute(broker, "//item[ngram:contains(., 'cha')]", null);
assertNotNull(seq);
assertEquals(1, seq.getItemCount());
XUpdateProcessor proc = new XUpdateProcessor(broker, docs);
assertNotNull(proc);
proc.setBroker(broker);
proc.setDocumentSet(docs);
String xupdate = XUPDATE_START + " <xu:remove select=\"//item[@id='2']/price\"/>" + XUPDATE_END;
Modification[] modifications = proc.parse(new InputSource(new StringReader(xupdate)));
assertNotNull(modifications);
modifications[0].process(transaction);
proc.reset();
checkIndex(broker, docs, "892", 0);
checkIndex(broker, docs, "tab", 1);
checkIndex(broker, docs, "le8", 0);
checkIndex(broker, docs, "cab", 1);
proc.setBroker(broker);
proc.setDocumentSet(docs);
xupdate = XUPDATE_START + " <xu:remove select=\"//item[@id='3']/description/text()\"/>" + XUPDATE_END;
modifications = proc.parse(new InputSource(new StringReader(xupdate)));
assertNotNull(modifications);
modifications[0].process(transaction);
proc.reset();
checkIndex(broker, docs, "cab", 0);
checkIndex(broker, docs, "att", 1);
proc.setBroker(broker);
proc.setDocumentSet(docs);
xupdate = XUPDATE_START + " <xu:remove select=\"//item[@id='1']/@attr\"/>" + XUPDATE_END;
modifications = proc.parse(new InputSource(new StringReader(xupdate)));
assertNotNull(modifications);
modifications[0].process(transaction);
proc.reset();
checkIndex(broker, docs, "att", 0);
checkIndex(broker, docs, "cha", 1);
proc.setBroker(broker);
proc.setDocumentSet(docs);
xupdate = XUPDATE_START + " <xu:remove select=\"//item[@id='1']\"/>" + XUPDATE_END;
modifications = proc.parse(new InputSource(new StringReader(xupdate)));
assertNotNull(modifications);
modifications[0].process(transaction);
proc.reset();
checkIndex(broker, docs, "cha", 0);
transact.commit(transaction);
}
}
use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.
the class CustomIndexTest method reindex.
@Test
public void reindex() throws PermissionDeniedException, XPathException, URISyntaxException, EXistException, IOException, 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()) {
// Doh ! This reindexes *all* the collections for *every* index
broker.reindexCollection(transaction, XmldbURI.xmldbUriFor("/db"));
checkIndex(broker, docs, "cha", 1);
checkIndex(broker, docs, "le8", 1);
XQuery xquery = pool.getXQueryService();
assertNotNull(xquery);
Sequence seq = xquery.execute(broker, "//item[ngram:contains(., 'cha')]", null);
assertNotNull(seq);
assertEquals(1, seq.getItemCount());
seq = xquery.execute(broker, "//section[ngram:contains(para, '123')]", null);
assertNotNull(seq);
assertEquals(1, seq.getItemCount());
seq = xquery.execute(broker, "//section[ngram:contains(para, '123')]", null);
assertNotNull(seq);
assertEquals(1, seq.getItemCount());
transact.commit(transaction);
}
}
Aggregations