use of org.neo4j.kernel.impl.transaction.log.entry.LogEntry in project neo4j by neo4j.
the class LegacyLogEntryWriterTest method shouldWriteAllTheEntryInACommitToTheFile.
@Test
public void shouldWriteAllTheEntryInACommitToTheFile() throws IOException {
// given
final LogVersionedStoreChannel channel = mock(LogVersionedStoreChannel.class);
final LogEntryWriter logEntryWriter = mock(LogEntryWriter.class);
final LegacyLogEntryWriter writer = new LegacyLogEntryWriter(fs, liftToFactory(logEntryWriter));
final LogEntryStart start = new LogEntryStart(0, 1, 2L, 3L, EMPTY_ADDITIONAL_ARRAY, UNSPECIFIED);
final LogEntryCommand command = new LogEntryCommand(new Command.NodeCommand(nodeRecord, nodeRecord));
final LogEntryCommit commit = new OnePhaseCommit(42L, 43L);
// when
final IOCursor<LogEntry> cursor = mockCursor(start, command, commit);
writer.writeAllLogEntries(channel, cursor);
// then
verify(logEntryWriter, times(1)).writeStartEntry(0, 1, 2L, 3L, EMPTY_ADDITIONAL_ARRAY);
final TransactionRepresentation expected = new PhysicalTransactionRepresentation(Arrays.asList(command.getXaCommand()));
verify(logEntryWriter, times(1)).serialize(eq(expected));
verify(logEntryWriter, times(1)).writeCommitEntry(42L, 43L);
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogEntry in project neo4j by neo4j.
the class LegacyLogsTest method shouldRewriteLogFiles.
@Test
public void shouldRewriteLogFiles() throws IOException {
// given
final IOCursor<LogEntry> cursor = mock(IOCursor.class);
final LogVersionedStoreChannel writeChannel = mock(LogVersionedStoreChannel.class);
final LogHeader header = new LogHeader(CURRENT_LOG_VERSION, 1, 42);
when(fs.listFiles(storeDir, versionedLegacyLogFilesFilter)).thenReturn(new File[] { new File(getLegacyLogFilename(1)) });
when(reader.openReadableChannel(new File(getLegacyLogFilename(1)))).thenReturn(Pair.of(header, cursor));
when(writer.openWritableChannel(new File(migrationDir, getLegacyLogFilename(1)))).thenReturn(writeChannel);
// when
new LegacyLogs(fs, reader, writer).migrateLogs(storeDir, migrationDir);
// then
verify(writer, times(1)).writeLogHeader(writeChannel, header);
verify(writer, times(1)).writeAllLogEntries(writeChannel, cursor);
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogEntry in project neo4j by neo4j.
the class LegacyLogsTest method transactionInformationRetrievedFromCommitEntries.
@Test
@SuppressWarnings("unchecked")
public void transactionInformationRetrievedFromCommitEntries() throws IOException {
FileSystemAbstraction fs = mock(FileSystemAbstraction.class);
File logFile = new File(LegacyLogFilenames.getLegacyLogFilename(1));
when(fs.listFiles(any(File.class), any(FilenameFilter.class))).thenReturn(new File[] { logFile });
LegacyLogEntryReader reader = mock(LegacyLogEntryReader.class);
LogEntry[] entries = new LogEntry[] { start(1), createNode(1), createNode(2), commit(1), start(2), createNode(3), createNode(4), commit(2), start(3), createNode(5), commit(3) };
when(reader.openReadableChannel(any(File.class))).thenReturn(readableChannel(entries), readableChannel(entries), readableChannel(entries));
LegacyLogEntryWriter writer = new LegacyLogEntryWriter(fs);
LegacyLogs legacyLogs = new LegacyLogs(fs, reader, writer);
assertEquals(newTransactionId(1), getTransactionInformation(legacyLogs, 1));
assertEquals(newTransactionId(2), getTransactionInformation(legacyLogs, 2));
assertEquals(newTransactionId(3), getTransactionInformation(legacyLogs, 3));
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogEntry in project neo4j by neo4j.
the class LogEntrySortingCursorTest method shouldBeFineIfThereAreEntriesWithoutACommit.
@Test
public void shouldBeFineIfThereAreEntriesWithoutACommit() throws IOException {
// given
final LogEntry start1 = start(3);
final LogEntry command1 = command();
final LogEntry start2 = start(3);
final LogEntry command2 = command();
final LogEntry commit2 = commit(4);
when(reader.readLogEntry(channel)).thenReturn(id(start2, 2), id(start1, 1), id(command1, 1), id(command2, 2), id(commit2, 2), null);
// when
final LogEntrySortingCursor cursor = new LogEntrySortingCursor(reader, channel);
// then
final List<LogEntry> expected = Arrays.asList(start2, command2, commit2);
assertCursorContains(expected, cursor);
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogEntry in project neo4j by neo4j.
the class LogEntrySortingCursorTest method shouldDoNothingIfTheListIsOrdered.
@Test
public void shouldDoNothingIfTheListIsOrdered() throws IOException {
// given
final LogEntry start1 = start(1);
final LogEntry command1 = command();
final LogEntry commit1 = commit(2);
final LogEntry start2 = start(2);
final LogEntry command2 = command();
final LogEntry commit2 = commit(3);
when(reader.readLogEntry(channel)).thenReturn(id(start1, 1), id(command1, 1), id(commit1, 1), id(start2, 2), id(command2, 2), id(commit2, 2), null);
// when
final LogEntrySortingCursor cursor = new LogEntrySortingCursor(reader, channel);
// then
final List<LogEntry> expected = Arrays.asList(start1, command1, commit1, start2, command2, commit2);
assertCursorContains(expected, cursor);
}
Aggregations