Search in sources :

Example 46 with InMemoryClosableChannel

use of org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel in project neo4j by neo4j.

the class VersionAwareLogEntryReaderTest method shouldReadACommandLogEntry.

@Test
public void shouldReadACommandLogEntry() throws IOException {
    // given
    LogEntryVersion version = LogEntryVersion.CURRENT;
    Command.NodeCommand nodeCommand = new Command.NodeCommand(new NodeRecord(11), new NodeRecord(11));
    final LogEntryCommand command = new LogEntryCommand(version, nodeCommand);
    final InMemoryClosableChannel channel = new InMemoryClosableChannel();
    channel.put(version.byteCode());
    channel.put(LogEntryByteCodes.COMMAND);
    nodeCommand.serialize(channel);
    // when
    final LogEntry logEntry = logEntryReader.readLogEntry(channel);
    // then
    assertEquals(command, logEntry);
}
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 47 with InMemoryClosableChannel

use of org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel in project neo4j by neo4j.

the class VersionAwareLogEntryReaderTest method shouldReturnNullWhenThereIsNoCommand.

@Test
public void shouldReturnNullWhenThereIsNoCommand() throws IOException {
    // given
    LogEntryVersion version = LogEntryVersion.CURRENT;
    final InMemoryClosableChannel channel = new InMemoryClosableChannel();
    channel.put(version.byteCode());
    channel.put(LogEntryByteCodes.COMMAND);
    channel.put(NeoCommandType.NONE);
    // when
    final LogEntry logEntry = logEntryReader.readLogEntry(channel);
    // then
    assertNull(logEntry);
}
Also used : InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) Test(org.junit.Test)

Example 48 with InMemoryClosableChannel

use of org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel in project neo4j by neo4j.

the class VersionAwareLogEntryReaderTest method shouldParseStreamOfZerosAsEmptyLogEntries.

@Test
public void shouldParseStreamOfZerosAsEmptyLogEntries() throws Exception {
    // GIVEN
    LogEntryReader<ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader<>();
    InMemoryClosableChannel channel = new InMemoryClosableChannel();
    int count = 100;
    channel.put(new byte[count], count);
    // WHEN/THEN
    for (int i = 0; i < count; i++) {
        LogEntry entry = reader.readLogEntry(channel);
        assertNull(entry);
        assertEquals(i + 1, channel.readerPosition());
    }
}
Also used : InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) Test(org.junit.Test)

Example 49 with InMemoryClosableChannel

use of org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel in project neo4j by neo4j.

the class VersionAwareLogEntryReaderTest method shouldParseOldStartEntry.

@Test
public void shouldParseOldStartEntry() throws IOException {
    // given
    LogEntryVersion version = LogEntryVersion.V2_1;
    final InMemoryClosableChannel channel = new InMemoryClosableChannel();
    final LogEntryStart start = new LogEntryStart(1, 2, 3, 4, new byte[] {}, new LogPosition(0, 37));
    channel.put(version.byteCode());
    channel.put(LogEntryByteCodes.TX_START);
    // ignored data
    // globalId length
    channel.put((byte) 1);
    // branchId length
    channel.put((byte) 0);
    // globalId
    channel.put(new byte[] { 7 }, 1);
    // branchId
    channel.put(new byte[] {}, 0);
    // identifier
    channel.putInt(123);
    // formatId
    channel.putInt(456);
    // actually used data
    channel.putInt(start.getMasterId());
    channel.putInt(start.getLocalId());
    channel.putLong(start.getTimeWritten());
    channel.putLong(start.getLastCommittedTxWhenTransactionStarted());
    // when
    final LogEntry logEntry = logEntryReader.readLogEntry(channel);
    // then
    assertTrue(logEntry instanceof IdentifiableLogEntry);
    assertEquals(start, ((IdentifiableLogEntry) logEntry).getEntry());
}
Also used : InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.Test)

Example 50 with InMemoryClosableChannel

use of org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel in project neo4j by neo4j.

the class VersionAwareLogEntryReaderTest method shouldReturnNullWhenThereIsNoCommandOldVersion.

@Test
public void shouldReturnNullWhenThereIsNoCommandOldVersion() throws IOException {
    // given
    LogEntryVersion version = LogEntryVersion.V2_1;
    final InMemoryClosableChannel channel = new InMemoryClosableChannel();
    channel.put(version.byteCode());
    channel.put(LogEntryByteCodes.COMMAND);
    channel.put(NeoCommandType.NONE);
    // when
    final LogEntry logEntry = logEntryReader.readLogEntry(channel);
    // then
    assertNull(logEntry);
}
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