Search in sources :

Example 1 with SystemTaskManager

use of org.exist.storage.SystemTaskManager 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 2 with SystemTaskManager

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

the class TransactionManagerTestHelper method createTestableTransactionManager.

protected TransactionManager createTestableTransactionManager(final boolean expectTxnClose) throws NoSuchFieldException, IllegalAccessException, EXistException {
    mockBrokerPool = createMock(BrokerPool.class);
    mockBroker = createMock(NativeBroker.class);
    expect(mockBrokerPool.getBroker()).andReturn(mockBroker).atLeastOnce();
    mockBroker.addCurrentTransaction(anyObject());
    expectLastCall().atLeastOnce();
    if (expectTxnClose) {
        mockBroker.removeCurrentTransaction(anyObject());
        expectLastCall().atLeastOnce();
    }
    mockBroker.close();
    expectLastCall().atLeastOnce();
    final SecurityManager mockSecurityManager = createMock(SecurityManager.class);
    final Subject mockSystemSubject = createMock(Subject.class);
    expect(mockBrokerPool.get(Optional.of(mockSystemSubject))).andReturn(mockBroker).anyTimes();
    expect(mockBrokerPool.getSecurityManager()).andReturn(mockSecurityManager).anyTimes();
    expect(mockSecurityManager.getSystemSubject()).andReturn(mockSystemSubject).anyTimes();
    final JournalManager mockJournalManager = createMock(JournalManager.class);
    final SystemTaskManager mockTaskManager = createMock(SystemTaskManager.class);
    replay(mockBrokerPool, mockBroker, mockSecurityManager);
    return new TransactionManager(mockBrokerPool, Optional.of(mockJournalManager), mockTaskManager);
}
Also used : SecurityManager(org.exist.security.SecurityManager) JournalManager(org.exist.storage.journal.JournalManager) NativeBroker(org.exist.storage.NativeBroker) SystemTaskManager(org.exist.storage.SystemTaskManager) BrokerPool(org.exist.storage.BrokerPool) Subject(org.exist.security.Subject)

Aggregations

SecurityManager (org.exist.security.SecurityManager)2 Subject (org.exist.security.Subject)2 BrokerPool (org.exist.storage.BrokerPool)2 SystemTaskManager (org.exist.storage.SystemTaskManager)2 JournalManager (org.exist.storage.journal.JournalManager)2 Properties (java.util.Properties)1 Scheduler (org.exist.scheduler.Scheduler)1 DBBroker (org.exist.storage.DBBroker)1 NativeBroker (org.exist.storage.NativeBroker)1 FileLockHeartBeat (org.exist.storage.lock.FileLockHeartBeat)1 RecoveryManager (org.exist.storage.recovery.RecoveryManager)1 TransactionManager (org.exist.storage.txn.TransactionManager)1 Txn (org.exist.storage.txn.Txn)1 Configuration (org.exist.util.Configuration)1