Search in sources :

Example 41 with LogFile

use of org.neo4j.kernel.impl.transaction.log.files.LogFile in project neo4j by neo4j.

the class PhysicalLogicalTransactionStoreTest method shouldThrowNoSuchTransactionExceptionIfLogFileIsMissing.

@Test
void shouldThrowNoSuchTransactionExceptionIfLogFileIsMissing() throws Exception {
    // GIVEN
    LogFile logFile = mock(LogFile.class);
    LogFiles logFiles = mock(LogFiles.class);
    // a missing file
    when(logFiles.getLogFile()).thenReturn(logFile);
    when(logFile.getReader(any(LogPosition.class))).thenThrow(new NoSuchFileException("mock"));
    // Which is nevertheless in the metadata cache
    TransactionMetadataCache cache = new TransactionMetadataCache();
    cache.cacheTransactionMetadata(10, new LogPosition(2, 130));
    LifeSupport life = new LifeSupport();
    final LogicalTransactionStore txStore = new PhysicalLogicalTransactionStore(logFiles, cache, logEntryReader(), monitors, true);
    try {
        life.start();
        // WHEN
        // we ask for that transaction and forward
        assertThrows(NoSuchTransactionException.class, () -> txStore.getTransactions(10));
    } finally {
        life.shutdown();
    }
}
Also used : LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) NoSuchFileException(java.nio.file.NoSuchFileException) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) Test(org.junit.jupiter.api.Test)

Example 42 with LogFile

use of org.neo4j.kernel.impl.transaction.log.files.LogFile in project neo4j by neo4j.

the class PhysicalLogicalTransactionStoreTest method extractTransactionFromLogFilesSkippingLastLogFileWithoutHeader.

@Test
void extractTransactionFromLogFilesSkippingLastLogFileWithoutHeader() throws IOException {
    TransactionIdStore transactionIdStore = new SimpleTransactionIdStore();
    TransactionMetadataCache positionCache = new TransactionMetadataCache();
    final byte[] additionalHeader = new byte[] { 1, 2, 5 };
    final long timeStarted = 12345;
    long latestCommittedTxWhenStarted = 4545;
    long timeCommitted = timeStarted + 10;
    LifeSupport life = new LifeSupport();
    final LogFiles logFiles = buildLogFiles(transactionIdStore);
    life.add(logFiles);
    life.start();
    try {
        addATransactionAndRewind(life, logFiles, positionCache, transactionIdStore, additionalHeader, timeStarted, latestCommittedTxWhenStarted, timeCommitted);
    } finally {
        life.shutdown();
    }
    // create empty transaction log file and clear transaction cache to force re-read
    LogFile logFile = logFiles.getLogFile();
    fileSystem.write(logFile.getLogFileForVersion(logFile.getHighestLogVersion() + 1)).close();
    positionCache.clear();
    final LogicalTransactionStore store = new PhysicalLogicalTransactionStore(logFiles, positionCache, logEntryReader(), monitors, true);
    verifyTransaction(positionCache, additionalHeader, timeStarted, latestCommittedTxWhenStarted, timeCommitted, store);
}
Also used : LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) TransactionIdStore(org.neo4j.storageengine.api.TransactionIdStore) SimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore) SimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) Test(org.junit.jupiter.api.Test)

Aggregations

LogFile (org.neo4j.kernel.impl.transaction.log.files.LogFile)42 Test (org.junit.jupiter.api.Test)25 LogFiles (org.neo4j.kernel.impl.transaction.log.files.LogFiles)21 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)15 Path (java.nio.file.Path)12 CheckpointFile (org.neo4j.kernel.impl.transaction.log.files.checkpoint.CheckpointFile)9 SimpleTransactionIdStore (org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore)7 Lifespan (org.neo4j.kernel.lifecycle.Lifespan)7 File (java.io.File)5 ZipFile (java.util.zip.ZipFile)5 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)5 SimpleLogVersionRepository (org.neo4j.kernel.impl.transaction.SimpleLogVersionRepository)5 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)5 IOException (java.io.IOException)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)4 FlushablePositionAwareChecksumChannel (org.neo4j.kernel.impl.transaction.log.FlushablePositionAwareChecksumChannel)4 LogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader)4 Assertions.assertArrayEquals (org.junit.jupiter.api.Assertions.assertArrayEquals)3 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)3