Search in sources :

Example 1 with CURRENT_FORMAT_LOG_HEADER_SIZE

use of org.neo4j.kernel.impl.transaction.log.entry.LogVersions.CURRENT_FORMAT_LOG_HEADER_SIZE in project neo4j by neo4j.

the class ThresholdBasedPruneStrategyTest method shouldNotDeleteAnythingIfThresholdDoesNotAllow.

@Test
void shouldNotDeleteAnythingIfThresholdDoesNotAllow() throws IOException {
    // Given
    Path fileName0 = Path.of("logical.log.v0");
    Path fileName1 = Path.of("logical.log.v1");
    Path fileName2 = Path.of("logical.log.v2");
    Path fileName3 = Path.of("logical.log.v3");
    Path fileName4 = Path.of("logical.log.v4");
    Path fileName5 = Path.of("logical.log.v5");
    Path fileName6 = Path.of("logical.log.v6");
    when(logFile.getLogFileForVersion(6)).thenReturn(fileName6);
    when(logFile.getLogFileForVersion(5)).thenReturn(fileName5);
    when(logFile.getLogFileForVersion(4)).thenReturn(fileName4);
    when(logFile.getLogFileForVersion(3)).thenReturn(fileName3);
    when(logFile.getLogFileForVersion(2)).thenReturn(fileName2);
    when(logFile.getLogFileForVersion(1)).thenReturn(fileName1);
    when(logFile.getLogFileForVersion(0)).thenReturn(fileName0);
    when(logFile.getLowestLogVersion()).thenReturn(0L);
    when(fileSystem.fileExists(fileName6)).thenReturn(true);
    when(fileSystem.fileExists(fileName5)).thenReturn(true);
    when(fileSystem.fileExists(fileName4)).thenReturn(true);
    when(fileSystem.fileExists(fileName3)).thenReturn(true);
    when(fileSystem.fileExists(fileName2)).thenReturn(true);
    when(fileSystem.fileExists(fileName1)).thenReturn(true);
    when(fileSystem.fileExists(fileName0)).thenReturn(true);
    when(fileSystem.getFileSize(any(Path.class))).thenReturn(CURRENT_FORMAT_LOG_HEADER_SIZE + 1L);
    when(threshold.reached(any(), anyLong(), any())).thenReturn(false);
    ThresholdBasedPruneStrategy strategy = new ThresholdBasedPruneStrategy(logFile, threshold);
    // When
    strategy.findLogVersionsToDelete(7L).forEachOrdered(uncheckedLongConsumer(v -> fileSystem.deleteFile(logFile.getLogFileForVersion(v))));
    // Then
    verify(threshold).init();
    verify(fileSystem, never()).deleteFile(any(Path.class));
}
Also used : Path(java.nio.file.Path) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) IOException(java.io.IOException) TransactionLogFile(org.neo4j.kernel.impl.transaction.log.files.TransactionLogFile) Mockito.when(org.mockito.Mockito.when) LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) Mockito.never(org.mockito.Mockito.never) LogFileInformation(org.neo4j.kernel.impl.transaction.log.LogFileInformation) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) CURRENT_FORMAT_LOG_HEADER_SIZE(org.neo4j.kernel.impl.transaction.log.entry.LogVersions.CURRENT_FORMAT_LOG_HEADER_SIZE) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Path(java.nio.file.Path) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Mockito.mock(org.mockito.Mockito.mock) IOUtils.uncheckedLongConsumer(org.neo4j.io.IOUtils.uncheckedLongConsumer) Test(org.junit.jupiter.api.Test)

Example 2 with CURRENT_FORMAT_LOG_HEADER_SIZE

use of org.neo4j.kernel.impl.transaction.log.entry.LogVersions.CURRENT_FORMAT_LOG_HEADER_SIZE in project neo4j by neo4j.

the class ThresholdBasedPruneStrategyTest method shouldDeleteJustWhatTheThresholdSays.

@Test
void shouldDeleteJustWhatTheThresholdSays() throws IOException {
    // Given
    when(threshold.reached(any(), eq(6L), any())).thenReturn(false);
    when(threshold.reached(any(), eq(5L), any())).thenReturn(false);
    when(threshold.reached(any(), eq(4L), any())).thenReturn(false);
    when(threshold.reached(any(), eq(3L), any())).thenReturn(true);
    Path fileName1 = Path.of("logical.log.v1");
    Path fileName2 = Path.of("logical.log.v2");
    Path fileName3 = Path.of("logical.log.v3");
    Path fileName4 = Path.of("logical.log.v4");
    Path fileName5 = Path.of("logical.log.v5");
    Path fileName6 = Path.of("logical.log.v6");
    when(logFile.getLogFileForVersion(6)).thenReturn(fileName6);
    when(logFile.getLogFileForVersion(5)).thenReturn(fileName5);
    when(logFile.getLogFileForVersion(4)).thenReturn(fileName4);
    when(logFile.getLogFileForVersion(3)).thenReturn(fileName3);
    when(logFile.getLogFileForVersion(2)).thenReturn(fileName2);
    when(logFile.getLogFileForVersion(1)).thenReturn(fileName1);
    when(logFile.getLowestLogVersion()).thenReturn(1L);
    when(fileSystem.getFileSize(any(Path.class))).thenReturn(CURRENT_FORMAT_LOG_HEADER_SIZE + 1L);
    ThresholdBasedPruneStrategy strategy = new ThresholdBasedPruneStrategy(logFile, threshold);
    // When
    strategy.findLogVersionsToDelete(7L).forEachOrdered(uncheckedLongConsumer(v -> fileSystem.deleteFile(logFile.getLogFileForVersion(v))));
    // Then
    verify(threshold).init();
    verify(fileSystem).deleteFile(fileName1);
    verify(fileSystem).deleteFile(fileName2);
    verify(fileSystem).deleteFile(fileName3);
    verify(fileSystem, never()).deleteFile(fileName4);
    verify(fileSystem, never()).deleteFile(fileName5);
    verify(fileSystem, never()).deleteFile(fileName6);
}
Also used : Path(java.nio.file.Path) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) IOException(java.io.IOException) TransactionLogFile(org.neo4j.kernel.impl.transaction.log.files.TransactionLogFile) Mockito.when(org.mockito.Mockito.when) LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) Mockito.never(org.mockito.Mockito.never) LogFileInformation(org.neo4j.kernel.impl.transaction.log.LogFileInformation) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) CURRENT_FORMAT_LOG_HEADER_SIZE(org.neo4j.kernel.impl.transaction.log.entry.LogVersions.CURRENT_FORMAT_LOG_HEADER_SIZE) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Path(java.nio.file.Path) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Mockito.mock(org.mockito.Mockito.mock) IOUtils.uncheckedLongConsumer(org.neo4j.io.IOUtils.uncheckedLongConsumer) Test(org.junit.jupiter.api.Test)

Aggregations

IOException (java.io.IOException)2 Path (java.nio.file.Path)2 Assertions.assertArrayEquals (org.junit.jupiter.api.Assertions.assertArrayEquals)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)2 Test (org.junit.jupiter.api.Test)2 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)2 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)2 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)2 Mockito.mock (org.mockito.Mockito.mock)2 Mockito.never (org.mockito.Mockito.never)2 Mockito.verify (org.mockito.Mockito.verify)2 Mockito.when (org.mockito.Mockito.when)2 IOUtils.uncheckedLongConsumer (org.neo4j.io.IOUtils.uncheckedLongConsumer)2 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)2 LogFileInformation (org.neo4j.kernel.impl.transaction.log.LogFileInformation)2 CURRENT_FORMAT_LOG_HEADER_SIZE (org.neo4j.kernel.impl.transaction.log.entry.LogVersions.CURRENT_FORMAT_LOG_HEADER_SIZE)2 LogFile (org.neo4j.kernel.impl.transaction.log.files.LogFile)2 TransactionLogFile (org.neo4j.kernel.impl.transaction.log.files.TransactionLogFile)2