Search in sources :

Example 16 with InMemoryClosableChannel

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

the class LogEntryParserV2_1Test method shouldParseTwoPhaseCommitEntryAndMapThemIntoOnePhaseCommit.

@Test
public void shouldParseTwoPhaseCommitEntryAndMapThemIntoOnePhaseCommit() throws IOException {
    // given
    final LogEntryCommit commit = new OnePhaseCommit(version, 42, 21);
    final InMemoryClosableChannel channel = new InMemoryClosableChannel();
    // ignored data
    // identifier
    channel.putInt(123);
    // actual read data
    channel.putLong(commit.getTxId());
    channel.putLong(commit.getTimeWritten());
    channel.getCurrentPosition(marker);
    // when
    final LogEntryParser<LogEntry> parser = version.entryParser(LogEntryByteCodes.TX_2P_COMMIT);
    final LogEntry logEntry = parser.parse(version, channel, marker, commandReader);
    // then
    assertEquals(commit, entryOf(logEntry));
    assertFalse(parser.skip());
}
Also used : InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) Test(org.junit.Test)

Example 17 with InMemoryClosableChannel

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

the class LogEntryParserV2_2Test method shouldParseStartEntry.

@Test
public void shouldParseStartEntry() throws IOException {
    // given
    final LogEntryStart start = new LogEntryStart(version, 1, 2, 3, 4, new byte[] { 5 }, position);
    final InMemoryClosableChannel channel = new InMemoryClosableChannel();
    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);
    channel.getCurrentPosition(marker);
    // when
    final LogEntryParser parser = version.entryParser(LogEntryByteCodes.TX_START);
    final LogEntry logEntry = parser.parse(version, channel, marker, commandReader);
    // then
    assertEquals(start, logEntry);
    assertFalse(parser.skip());
}
Also used : InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) Test(org.junit.Test)

Example 18 with InMemoryClosableChannel

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

the class LogEntryParserV2_2Test method shouldParseCommandsUsingAGivenFactory.

@Test
public void shouldParseCommandsUsingAGivenFactory() throws IOException {
    // given
    Command.NodeCommand nodeCommand = new Command.NodeCommand(new NodeRecord(0), new NodeRecord(0));
    final LogEntryCommand command = new LogEntryCommand(version, nodeCommand);
    final InMemoryClosableChannel channel = new InMemoryClosableChannel();
    nodeCommand.serialize(channel);
    channel.getCurrentPosition(marker);
    // when
    final LogEntryParser parser = version.entryParser(LogEntryByteCodes.COMMAND);
    final LogEntry logEntry = parser.parse(version, channel, marker, commandReader);
    // then
    assertEquals(command, logEntry);
    assertFalse(parser.skip());
}
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 19 with InMemoryClosableChannel

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

the class LogEntryParserV2_2Test method shouldParseOnePhaseCommitEntry.

@Test
public void shouldParseOnePhaseCommitEntry() throws IOException {
    // given
    final LogEntryCommit commit = new OnePhaseCommit(version, 42, 21);
    final InMemoryClosableChannel channel = new InMemoryClosableChannel();
    channel.putLong(commit.getTxId());
    channel.putLong(commit.getTimeWritten());
    channel.getCurrentPosition(marker);
    // when
    final LogEntryParser parser = version.entryParser(LogEntryByteCodes.TX_1P_COMMIT);
    final LogEntry logEntry = parser.parse(version, channel, marker, commandReader);
    // then
    assertEquals(commit, logEntry);
    assertFalse(parser.skip());
}
Also used : InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) Test(org.junit.Test)

Example 20 with InMemoryClosableChannel

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

the class VersionAwareLogEntryReaderTest method shouldParseOldOnePhaseCommit.

@Test
public void shouldParseOldOnePhaseCommit() throws IOException {
    // given
    LogEntryVersion version = LogEntryVersion.V2_1;
    final InMemoryClosableChannel channel = new InMemoryClosableChannel();
    final OnePhaseCommit commit = new OnePhaseCommit(42, 456);
    channel.put(version.byteCode());
    channel.put(LogEntryByteCodes.TX_1P_COMMIT);
    // ignored data
    // identifier
    channel.putInt(123);
    // actually used data
    channel.putLong(commit.getTxId());
    channel.putLong(commit.getTimeWritten());
    // when
    final LogEntry logEntry = logEntryReader.readLogEntry(channel);
    // then
    assertTrue(logEntry instanceof IdentifiableLogEntry);
    assertEquals(commit, ((IdentifiableLogEntry) logEntry).getEntry());
}
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