Search in sources :

Example 26 with InMemoryClosableChannel

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);
}
Also used : InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.Test)

Example 27 with InMemoryClosableChannel

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());
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) Command(org.neo4j.kernel.impl.transaction.command.Command) InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) Test(org.junit.Test)

Example 28 with InMemoryClosableChannel

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();
}
Also used : InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) Test(org.junit.Test)

Example 29 with InMemoryClosableChannel

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());
}
Also used : InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) Test(org.junit.Test)

Example 30 with InMemoryClosableChannel

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);
}
Also used : InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) Test(org.junit.Test)

Aggregations

InMemoryClosableChannel (org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel)66 Test (org.junit.Test)63 Command (org.neo4j.kernel.impl.transaction.command.Command)8 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)5 RelationshipGroupRecord (org.neo4j.kernel.impl.store.record.RelationshipGroupRecord)4 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)3 RelationshipRecord (org.neo4j.kernel.impl.store.record.RelationshipRecord)3 CommandReader (org.neo4j.storageengine.api.CommandReader)3 Before (org.junit.Before)2 AddRelationshipCommand (org.neo4j.kernel.impl.index.IndexCommand.AddRelationshipCommand)2 CountsKey (org.neo4j.kernel.impl.store.counts.keys.CountsKey)2 SchemaRecord (org.neo4j.kernel.impl.store.record.SchemaRecord)2 SchemaRuleCommand (org.neo4j.kernel.impl.transaction.command.Command.SchemaRuleCommand)2 ReadableClosablePositionAwareChannel (org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)1 EndOfStreamException (org.neo4j.causalclustering.messaging.EndOfStreamException)1