use of org.exist.storage.recovery.RecoveryManager 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);
}
Aggregations