Search in sources :

Example 1 with IncompleteLogHeaderException

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

the class PhysicalLogFileTest method shouldCloseChannelInFailedAttemptToReadHeaderAfterOpen.

@Test
public void shouldCloseChannelInFailedAttemptToReadHeaderAfterOpen() throws Exception {
    // GIVEN a file which returns 1/2 log header size worth of bytes
    File directory = new File("/dir");
    FileSystemAbstraction fs = mock(FileSystemAbstraction.class);
    PhysicalLogFiles logFiles = new PhysicalLogFiles(directory, fs);
    int logVersion = 0;
    File logFile = logFiles.getLogFileForVersion(logVersion);
    StoreChannel channel = mock(StoreChannel.class);
    when(channel.read(any(ByteBuffer.class))).thenReturn(LogHeader.LOG_HEADER_SIZE / 2);
    when(fs.fileExists(logFile)).thenReturn(true);
    when(fs.open(eq(logFile), anyString())).thenReturn(channel);
    // WHEN
    try {
        PhysicalLogFile.openForVersion(logFiles, fs, logVersion, false);
        fail("Should have failed");
    } catch (IncompleteLogHeaderException e) {
        // THEN good
        verify(channel).close();
    }
}
Also used : FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) StoreChannel(org.neo4j.io.fs.StoreChannel) File(java.io.File) ByteBuffer(java.nio.ByteBuffer) IncompleteLogHeaderException(org.neo4j.kernel.impl.transaction.log.entry.IncompleteLogHeaderException) Test(org.junit.Test)

Example 2 with IncompleteLogHeaderException

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

the class PhysicalLogFileTest method shouldSuppressFailueToCloseChannelInFailedAttemptToReadHeaderAfterOpen.

@Test
public void shouldSuppressFailueToCloseChannelInFailedAttemptToReadHeaderAfterOpen() throws Exception {
    // GIVEN a file which returns 1/2 log header size worth of bytes
    File directory = new File("/dir");
    FileSystemAbstraction fs = mock(FileSystemAbstraction.class);
    PhysicalLogFiles logFiles = new PhysicalLogFiles(directory, fs);
    int logVersion = 0;
    File logFile = logFiles.getLogFileForVersion(logVersion);
    StoreChannel channel = mock(StoreChannel.class);
    when(channel.read(any(ByteBuffer.class))).thenReturn(LogHeader.LOG_HEADER_SIZE / 2);
    when(fs.fileExists(logFile)).thenReturn(true);
    when(fs.open(eq(logFile), anyString())).thenReturn(channel);
    doThrow(IOException.class).when(channel).close();
    // WHEN
    try {
        PhysicalLogFile.openForVersion(logFiles, fs, logVersion, false);
        fail("Should have failed");
    } catch (IncompleteLogHeaderException e) {
        // THEN good
        verify(channel).close();
        assertEquals(1, e.getSuppressed().length);
        assertTrue(e.getSuppressed()[0] instanceof IOException);
    }
}
Also used : FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) StoreChannel(org.neo4j.io.fs.StoreChannel) IOException(java.io.IOException) File(java.io.File) ByteBuffer(java.nio.ByteBuffer) IncompleteLogHeaderException(org.neo4j.kernel.impl.transaction.log.entry.IncompleteLogHeaderException) Test(org.junit.Test)

Aggregations

File (java.io.File)2 ByteBuffer (java.nio.ByteBuffer)2 Test (org.junit.Test)2 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)2 StoreChannel (org.neo4j.io.fs.StoreChannel)2 IncompleteLogHeaderException (org.neo4j.kernel.impl.transaction.log.entry.IncompleteLogHeaderException)2 IOException (java.io.IOException)1