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