use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand 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.LogEntryCommand in project neo4j by neo4j.
the class LegacyLogsTest method createNode.
private static LogEntry createNode(int id) {
NodeRecord before = new NodeRecord(id).initialize(false, NO_NEXT_REL, false, NO_NEXT_REL, NO_LABELS);
NodeRecord after = new NodeRecord(id).initialize(true, NO_NEXT_REL, false, NO_NEXT_REL, NO_LABELS);
Command.NodeCommand command = new Command.NodeCommand(before, after);
return new LogEntryCommand(command);
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand in project neo4j by neo4j.
the class LogEntrySortingCursorTest method command.
private LogEntry command() {
NodeRecord before = new NodeRecord(random.nextInt());
NodeRecord after = new NodeRecord(random.nextInt());
return new LogEntryCommand(new Command.NodeCommand(before, after));
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand in project neo4j by neo4j.
the class ReplicatedTransactionFactory method read.
public static TransactionRepresentation read(NetworkReadableClosableChannelNetty4 channel, byte[] extraHeader) throws IOException {
LogEntryReader<ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader<>(new RecordStorageCommandReaderFactory());
int authorId = channel.getInt();
int masterId = channel.getInt();
long latestCommittedTxWhenStarted = channel.getLong();
long timeStarted = channel.getLong();
long timeCommitted = channel.getLong();
int lockSessionId = channel.getInt();
int headerLength = channel.getInt();
byte[] header;
if (headerLength == 0) {
header = extraHeader;
} else {
header = new byte[headerLength];
}
channel.get(header, headerLength);
LogEntryCommand entryRead;
List<StorageCommand> commands = new LinkedList<>();
while ((entryRead = (LogEntryCommand) reader.readLogEntry(channel)) != null) {
commands.add(entryRead.getXaCommand());
}
PhysicalTransactionRepresentation tx = new PhysicalTransactionRepresentation(commands);
tx.setHeader(header, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted, lockSessionId);
return tx;
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand in project neo4j by neo4j.
the class ReplicatedTokenRequestSerializer method extractCommands.
static Collection<StorageCommand> extractCommands(byte[] commandBytes) {
ByteBuf txBuffer = Unpooled.wrappedBuffer(commandBytes);
NetworkReadableClosableChannelNetty4 channel = new NetworkReadableClosableChannelNetty4(txBuffer);
LogEntryReader<ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader<>(new RecordStorageCommandReaderFactory());
LogEntryCommand entryRead;
List<StorageCommand> commands = new LinkedList<>();
try {
while ((entryRead = (LogEntryCommand) reader.readLogEntry(channel)) != null) {
commands.add(entryRead.getXaCommand());
}
} catch (IOException e) {
// TODO: Handle or throw.
e.printStackTrace();
}
return commands;
}
Aggregations