Search in sources :

Example 6 with Scheduler

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);
}
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)

Aggregations

Scheduler (org.exist.scheduler.Scheduler)6 Path (java.nio.file.Path)5 BrokerPool (org.exist.storage.BrokerPool)5 Configuration (org.exist.util.Configuration)5 IOException (java.io.IOException)2 java.util (java.util)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 SecurityManager (org.exist.security.SecurityManager)2 JournalManager (org.exist.storage.journal.JournalManager)2 RecoveryManager (org.exist.storage.recovery.RecoveryManager)2 TransactionManager (org.exist.storage.txn.TransactionManager)2 Txn (org.exist.storage.txn.Txn)2 Test (org.junit.Test)2 Either (com.evolvedbinary.j8fu.Either)1 AtomicFSM (com.evolvedbinary.j8fu.fsm.AtomicFSM)1 FSM (com.evolvedbinary.j8fu.fsm.FSM)1 TransitionTable.transitionTable (com.evolvedbinary.j8fu.fsm.TransitionTable.transitionTable)1 AtomicLazyVal (com.evolvedbinary.j8fu.lazy.AtomicLazyVal)1 InputStream (java.io.InputStream)1