use of org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel in project neo4j by neo4j.
the class VersionAwareLogEntryReaderTest method shouldReadAStartLogEntry.
@Test
public void shouldReadAStartLogEntry() throws IOException {
// given
LogEntryVersion version = LogEntryVersion.CURRENT;
final LogEntryStart start = new LogEntryStart(version, 1, 2, 3, 4, new byte[] { 5 }, new LogPosition(0, 31));
final InMemoryClosableChannel channel = new InMemoryClosableChannel();
// version
channel.put(version.byteCode());
// type
channel.put(LogEntryByteCodes.TX_START);
channel.putInt(start.getMasterId());
channel.putInt(start.getLocalId());
channel.putLong(start.getTimeWritten());
channel.putLong(start.getLastCommittedTxWhenTransactionStarted());
channel.putInt(start.getAdditionalHeader().length);
channel.put(start.getAdditionalHeader(), start.getAdditionalHeader().length);
// when
final LogEntry logEntry = logEntryReader.readLogEntry(channel);
// then
assertEquals(start, logEntry);
}
use of org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel in project neo4j by neo4j.
the class VersionAwareLogEntryReaderTest method shouldParseAnOldCommandLogEntry.
@Test
public void shouldParseAnOldCommandLogEntry() throws IOException {
// given
LogEntryVersion version = LogEntryVersion.V2_1;
Command.NodeCommand nodeCommand = new Command.NodeCommand(new NodeRecord(10), new NodeRecord(10));
final LogEntryCommand command = new LogEntryCommand(version, nodeCommand);
final InMemoryClosableChannel channel = new InMemoryClosableChannel();
channel.put(version.byteCode());
channel.put(LogEntryByteCodes.COMMAND);
// ignored data
// identifier ignored
channel.putInt(42);
// actual used data
nodeCommand.serialize(channel);
// when
final LogEntry logEntry = logEntryReader.readLogEntry(channel);
// then
assertTrue(logEntry instanceof IdentifiableLogEntry);
assertEquals(command, ((IdentifiableLogEntry) logEntry).getEntry());
}
use of org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel in project neo4j by neo4j.
the class LogTruncationTest method testInMemoryLogChannel.
@Test
public void testInMemoryLogChannel() throws Exception {
InMemoryClosableChannel channel = new InMemoryClosableChannel();
for (int i = 0; i < 25; i++) {
channel.putInt(i);
}
for (int i = 0; i < 25; i++) {
assertEquals(i, channel.getInt());
}
channel.reset();
for (long i = 0; i < 12; i++) {
channel.putLong(i);
}
for (long i = 0; i < 12; i++) {
assertEquals(i, channel.getLong());
}
channel.reset();
for (long i = 0; i < 8; i++) {
channel.putLong(i);
channel.putInt((int) i);
}
for (long i = 0; i < 8; i++) {
assertEquals(i, channel.getLong());
assertEquals(i, channel.getInt());
}
channel.close();
}
use of org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel in project neo4j by neo4j.
the class ProtocolTest method shouldSerializeAndDeserializeTransactionRepresentation.
@Test
public void shouldSerializeAndDeserializeTransactionRepresentation() throws Exception {
// GIVEN
PhysicalTransactionRepresentation transaction = new PhysicalTransactionRepresentation(justOneNode());
byte[] additionalHeader = "extra".getBytes();
int masterId = 1, authorId = 2;
long timeStarted = 12345, lastTxWhenStarted = 12, timeCommitted = timeStarted + 10;
transaction.setHeader(additionalHeader, masterId, authorId, timeStarted, lastTxWhenStarted, timeCommitted, -1);
Protocol.TransactionSerializer serializer = new Protocol.TransactionSerializer(transaction);
ChannelBuffer buffer = new ChannelBufferWrapper(new InMemoryClosableChannel());
// WHEN serializing the transaction
serializer.write(buffer);
// THEN deserializing the same transaction should yield the same data.
// ... remember that this deserializer doesn't read the data source name string. Read it manually here
assertEquals(NeoStoreDataSource.DEFAULT_DATA_SOURCE_NAME, Protocol.readString(buffer));
VersionAwareLogEntryReader<ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader<>();
TransactionRepresentation readTransaction = new Protocol.TransactionRepresentationDeserializer(reader).read(buffer, ByteBuffer.allocate(1000));
assertArrayEquals(additionalHeader, readTransaction.additionalHeader());
assertEquals(masterId, readTransaction.getMasterId());
assertEquals(authorId, readTransaction.getAuthorId());
assertEquals(timeStarted, readTransaction.getTimeStarted());
assertEquals(lastTxWhenStarted, readTransaction.getLatestCommittedTxWhenStarted());
assertEquals(timeCommitted, readTransaction.getTimeCommitted());
}
use of org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel in project neo4j by neo4j.
the class SegmentHeaderTest method shouldWriteAndReadHeader.
@Test
public void shouldWriteAndReadHeader() throws Exception {
// given
long prevFileLastIndex = 1;
long version = 2;
long prevIndex = 3;
long prevTerm = 4;
SegmentHeader writtenHeader = new SegmentHeader(prevFileLastIndex, version, prevIndex, prevTerm);
InMemoryClosableChannel channel = new InMemoryClosableChannel();
// when
marshal.marshal(writtenHeader, channel);
SegmentHeader readHeader = marshal.unmarshal(channel);
// then
assertEquals(writtenHeader, readHeader);
}
Aggregations