use of org.exist.scheduler.Scheduler in project exist by eXist-db.
the class JournalTest method switchFilesWrapsCurrentJournalFileNumberAround.
@Test
public void switchFilesWrapsCurrentJournalFileNumberAround() 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());
// set the current journal file number to one less than the maximum
journal.setCurrentJournalFileNumber((short) (Short.MAX_VALUE - 1));
short currentJournalFileNumber = journal.getCurrentJournalFileNumber();
// journal is not yet operating!
assertEquals(Short.MAX_VALUE - 1, currentJournalFileNumber);
// start the journal by calling switch files
journal.switchFiles();
currentJournalFileNumber = journal.getCurrentJournalFileNumber();
// we should now be at the maximum
assertEquals(Short.MAX_VALUE, currentJournalFileNumber);
final Path journalFileMax = journal.getFile(currentJournalFileNumber);
assertNotNull(journalFileMax);
assertTrue(Files.exists(journalFileMax));
// advance to a new journal by calling switch files, this should cause the journal file number to wrap around
journal.switchFiles();
currentJournalFileNumber = journal.getCurrentJournalFileNumber();
// should be back at the start of the range for journal file numbers
assertEquals(0, currentJournalFileNumber);
final Path journalFile0 = journal.getFile(currentJournalFileNumber);
assertNotNull(journalFile0);
assertNotEquals(journalFileMax.toAbsolutePath().toString(), journalFile0.toAbsolutePath().toString());
assertTrue(Files.exists(journalFile0));
verify(mockBrokerPool, mockConfiguration);
}
Aggregations