use of org.exist.util.Configuration in project exist by eXist-db.
the class JournalTest method switchFilesBacksUpOldFileFirst.
@Test
public void switchFilesBacksUpOldFileFirst() throws EXistException, IOException, ReadOnlyException {
final BrokerPool mockBrokerPool = mock(BrokerPool.class);
final Configuration mockConfiguration = mock(Configuration.class);
final Scheduler mockScheduler = createNiceMock(Scheduler.class);
expect(mockBrokerPool.getConfiguration()).andReturn(mockConfiguration);
expect(mockConfiguration.getProperty(Journal.PROPERTY_RECOVERY_SYNC_ON_COMMIT, Journal.DEFAULT_SYNC_ON_COMMIT)).andReturn(Journal.DEFAULT_SYNC_ON_COMMIT);
expect(mockConfiguration.getProperty(Journal.PROPERTY_RECOVERY_JOURNAL_DIR)).andReturn(null);
expect(mockConfiguration.getProperty(Journal.PROPERTY_RECOVERY_SIZE_MIN, Journal.DEFAULT_MIN_SIZE)).andReturn(Journal.DEFAULT_MIN_SIZE);
expect(mockConfiguration.getProperty(Journal.PROPERTY_RECOVERY_SIZE_LIMIT, Journal.DEFAULT_MAX_SIZE)).andReturn(Journal.DEFAULT_MAX_SIZE);
expect(mockBrokerPool.getScheduler()).andReturn(mockScheduler);
replay(mockBrokerPool, mockConfiguration);
final Path tempJournalDir = TEMPORARY_FOLDER.newFolder().toPath();
Files.createDirectories(tempJournalDir);
assertTrue(Files.exists(tempJournalDir));
final Journal journal = new Journal(mockBrokerPool, tempJournalDir);
journal.initialize();
// journal is not yet operating!
assertEquals(-1, journal.getCurrentJournalFileNumber());
// create an existing (old) journal file first
final Path existingJournalFile = Files.createFile(tempJournalDir.resolve(Journal.getFileName((short) 0)));
assertTrue(Files.exists(existingJournalFile));
// start the journal by calling switch files
journal.switchFiles();
short currentJournalFileNumber = journal.getCurrentJournalFileNumber();
assertEquals(0, currentJournalFileNumber);
final Path journalFile0 = journal.getFile(currentJournalFileNumber);
assertNotNull(journalFile0);
assertTrue(Files.exists(journalFile0));
// check that the existingJournalFile was moved to a backup
assertTrue(Files.exists(existingJournalFile.resolveSibling(FileUtils.fileName(existingJournalFile) + Journal.BAK_FILE_SUFFIX)));
verify(mockBrokerPool, mockConfiguration);
}
use of org.exist.util.Configuration 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.util.Configuration in project exist by eXist-db.
the class IndexManager method prepare.
/**
* Registers the indexes specified in
* the global configuration object, i.e. in the :
* <pre>
* <modules>
* <module id="foo" class="bar" foo1="bar1" ... />
* </modules>
* </pre>
* section of the configuration file.
*/
@Override
public void prepare(final BrokerPool brokerPool) throws BrokerPoolServiceException {
try {
if (modConfigs != null) {
for (final Configuration.IndexModuleConfig modConfig : modConfigs) {
final String className = modConfig.getClassName();
initIndex(pool, modConfig.getId(), modConfig.getConfig(), dataDir, className);
}
}
// check if a structural index was configured. If not, create one based on default settings.
AbstractIndex structural = (AbstractIndex) indexers.get(StructuralIndex.STRUCTURAL_INDEX_ID);
if (structural == null) {
structural = initIndex(pool, StructuralIndex.STRUCTURAL_INDEX_ID, null, dataDir, StructuralIndex.DEFAULT_CLASS);
if (structural != null) {
structural.setName(StructuralIndex.STRUCTURAL_INDEX_ID);
}
}
} catch (final DatabaseConfigurationException e) {
throw new BrokerPoolServiceException(e);
} finally {
configurationChanged();
}
}
use of org.exist.util.Configuration in project exist by eXist-db.
the class TransformerFactoryAllocatorTest method getTransformerFactory.
@Test
public void getTransformerFactory() {
final Hashtable<String, Object> testAttributes = new Hashtable<String, Object>();
BrokerPool mockBrokerPool = EasyMock.createMock(BrokerPool.class);
Configuration mockConfiguration = EasyMock.createMock(Configuration.class);
expect(mockBrokerPool.getConfiguration()).andReturn(mockConfiguration);
expect(mockConfiguration.getProperty(TransformerFactoryAllocator.PROPERTY_TRANSFORMER_CLASS)).andReturn(transformerFactoryClass);
expect(mockBrokerPool.getConfiguration()).andReturn(mockConfiguration);
expect(mockConfiguration.getProperty(TransformerFactoryAllocator.PROPERTY_TRANSFORMER_ATTRIBUTES)).andReturn(testAttributes);
replay(mockBrokerPool, mockConfiguration);
SAXTransformerFactory transformerFactory = TransformerFactoryAllocator.getTransformerFactory(mockBrokerPool);
assertEquals(transformerFactoryClass, transformerFactory.getClass().getName());
verify(mockBrokerPool, mockConfiguration);
}
use of org.exist.util.Configuration in project exist by eXist-db.
the class XMLStatistics method genBufferStatus.
private void genBufferStatus(BrokerPool instance) throws SAXException {
final AttributesImpl atts = new AttributesImpl();
this.contentHandler.startElement(NAMESPACE, "buffers", PREFIX + ":buffers", atts);
final Configuration conf = instance.getConfiguration();
BFile db;
db = (BFile) conf.getProperty(CollectionStore.FILE_KEY_IN_CONFIG);
genBufferDetails(db.getIndexBufferStats(), db.getDataBufferStats(), "Collections storage (" + FileUtils.fileName(db.getFile()) + ")");
final DOMFile dom = (DOMFile) conf.getProperty(DOMFile.CONFIG_KEY_FOR_FILE);
genBufferDetails(dom.getIndexBufferStats(), dom.getDataBufferStats(), "Resource storage (" + FileUtils.fileName(dom.getFile()) + ")");
db = (BFile) conf.getProperty(NativeValueIndex.FILE_KEY_IN_CONFIG);
if (db != null) {
genBufferDetails(db.getIndexBufferStats(), db.getDataBufferStats(), "Values index (" + FileUtils.fileName(db.getFile()) + ")");
}
this.contentHandler.endElement(NAMESPACE, "buffers", PREFIX + ":buffers");
}
Aggregations