use of org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel in project neo4j by neo4j.
the class LogTestUtils method filterNeostoreLogicalLog.
public static File filterNeostoreLogicalLog(FileSystemAbstraction fileSystem, File file, final LogHook<LogEntry> filter) throws IOException {
filter.file(file);
File tempFile = new File(file.getAbsolutePath() + ".tmp");
fileSystem.deleteFile(tempFile);
try (StoreChannel in = fileSystem.open(file, "r");
StoreChannel out = fileSystem.open(tempFile, "rw")) {
LogHeader logHeader = transferLogicalLogHeader(in, out, ByteBuffer.allocate(LOG_HEADER_SIZE));
PhysicalLogVersionedStoreChannel outChannel = new PhysicalLogVersionedStoreChannel(out, logHeader.logVersion, logHeader.logFormatVersion);
PhysicalLogVersionedStoreChannel inChannel = new PhysicalLogVersionedStoreChannel(in, logHeader.logVersion, logHeader.logFormatVersion);
ReadableLogChannel inBuffer = new ReadAheadLogChannel(inChannel, LogVersionBridge.NO_MORE_CHANNELS);
LogEntryReader<ReadableLogChannel> entryReader = new VersionAwareLogEntryReader<>();
LogEntry entry;
while ((entry = entryReader.readLogEntry(inBuffer)) != null) {
if (filter.test(entry)) {
// TODO allright, write to outBuffer
}
}
}
return tempFile;
}
use of org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel in project neo4j by neo4j.
the class ReaderLogVersionBridgeTest method shouldOpenTheNextChannelWhenItExists.
@Test
public void shouldOpenTheNextChannelWhenItExists() throws IOException {
// given
final StoreChannel newStoreChannel = mock(StoreChannel.class);
final ReaderLogVersionBridge bridge = new ReaderLogVersionBridge(fs, logFiles);
when(channel.getVersion()).thenReturn(version);
when(channel.getLogFormatVersion()).thenReturn(CURRENT_LOG_VERSION);
when(logFiles.getLogFileForVersion(version + 1)).thenReturn(file);
when(fs.fileExists(file)).thenReturn(true);
when(fs.open(file, "r")).thenReturn(newStoreChannel);
when(newStoreChannel.read(Matchers.<ByteBuffer>any())).then(new Answer<Integer>() {
@Override
public Integer answer(InvocationOnMock invocationOnMock) throws Throwable {
ByteBuffer buffer = (ByteBuffer) invocationOnMock.getArguments()[0];
buffer.putLong(encodeLogVersion(version + 1));
buffer.putLong(42);
return LOG_HEADER_SIZE;
}
});
// when
final LogVersionedStoreChannel result = bridge.next(channel);
// then
PhysicalLogVersionedStoreChannel expected = new PhysicalLogVersionedStoreChannel(newStoreChannel, version + 1, CURRENT_LOG_VERSION);
assertEquals(expected, result);
verify(channel, times(1)).close();
}
Aggregations