Search in sources :

Example 16 with Configuration

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);
}
Also used : Path(java.nio.file.Path) Configuration(org.exist.util.Configuration) Scheduler(org.exist.scheduler.Scheduler) BrokerPool(org.exist.storage.BrokerPool) Test(org.junit.Test)

Example 17 with Configuration

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);
}
Also used : Configuration(org.exist.util.Configuration) SecurityManager(org.exist.security.SecurityManager) Scheduler(org.exist.scheduler.Scheduler) JournalManager(org.exist.storage.journal.JournalManager) Txn(org.exist.storage.txn.Txn) Properties(java.util.Properties) Subject(org.exist.security.Subject) FileLockHeartBeat(org.exist.storage.lock.FileLockHeartBeat) RecoveryManager(org.exist.storage.recovery.RecoveryManager) DBBroker(org.exist.storage.DBBroker) TransactionManager(org.exist.storage.txn.TransactionManager) SystemTaskManager(org.exist.storage.SystemTaskManager) BrokerPool(org.exist.storage.BrokerPool)

Example 18 with Configuration

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>
 * &lt;modules&gt;
 *   &lt;module id="foo" class="bar" foo1="bar1" ... /&gt;
 * &lt;/modules&gt;
 * </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();
    }
}
Also used : BrokerPoolServiceException(org.exist.storage.BrokerPoolServiceException) Configuration(org.exist.util.Configuration) DatabaseConfigurationException(org.exist.util.DatabaseConfigurationException)

Example 19 with Configuration

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);
}
Also used : Configuration(org.exist.util.Configuration) Hashtable(java.util.Hashtable) SAXTransformerFactory(javax.xml.transform.sax.SAXTransformerFactory) BrokerPool(org.exist.storage.BrokerPool) Test(org.junit.Test)

Example 20 with Configuration

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");
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) Configuration(org.exist.util.Configuration) DOMFile(org.exist.storage.dom.DOMFile) BFile(org.exist.storage.index.BFile)

Aggregations

Configuration (org.exist.util.Configuration)30 Test (org.junit.Test)10 Path (java.nio.file.Path)9 EXistException (org.exist.EXistException)8 IOException (java.io.IOException)7 BrokerPool (org.exist.storage.BrokerPool)6 DatabaseConfigurationException (org.exist.util.DatabaseConfigurationException)6 InputStream (java.io.InputStream)4 Scheduler (org.exist.scheduler.Scheduler)4 DBBroker (org.exist.storage.DBBroker)4 Paths (java.nio.file.Paths)3 PermissionDeniedException (org.exist.security.PermissionDeniedException)3 Subject (org.exist.security.Subject)3 MalformedURLException (java.net.MalformedURLException)2 Map (java.util.Map)2 ServletException (javax.servlet.ServletException)2 Database (org.exist.Database)2 AuthenticationException (org.exist.security.AuthenticationException)2 SecurityManager (org.exist.security.SecurityManager)2 Ignore (org.junit.Ignore)2