Search in sources :

Example 31 with InMemoryClosableChannel

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

the class SegmentHeaderTest method shouldThrowExceptionWhenReadingIncompleteHeader.

@Test
public void shouldThrowExceptionWhenReadingIncompleteHeader() 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();
    channel.putLong(writtenHeader.version());
    channel.putLong(writtenHeader.prevIndex());
    // when
    try {
        marshal.unmarshal(channel);
        fail();
    } catch (EndOfStreamException e) {
    // expected
    }
}
Also used : InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) EndOfStreamException(org.neo4j.causalclustering.messaging.EndOfStreamException) Test(org.junit.Test)

Example 32 with InMemoryClosableChannel

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

the class PhysicalLogNeoCommandReaderV2Test method shouldReadIndexCommandHeaderCorrectly.

@Test
public void shouldReadIndexCommandHeaderCorrectly() throws Exception {
    // This bug manifested in header byte[1] {0,1,2}, which contains:
    // [x   ,    ] start node needs long
    // [ x  ,    ] end node needs long
    // [  xx,xxxx] index name id
    // would have the mask for reading "start node needs long" to 0x8, where it should have been 0x80.
    // So we need an index name id which has the 0x8 bit set to falsely read that value as "true".
    // Number 12 will do just fine.
    // GIVEN
    PhysicalLogCommandReaderV2_2_4 reader = new PhysicalLogCommandReaderV2_2_4();
    InMemoryClosableChannel data = new InMemoryClosableChannel();
    AddRelationshipCommand command = new AddRelationshipCommand();
    byte indexNameId = (byte) 12;
    long entityId = 123;
    byte keyId = (byte) 1;
    Object value = "test value";
    long startNode = 14;
    long endNode = 15;
    // WHEN
    command.init(indexNameId, entityId, keyId, value, startNode, endNode);
    command.serialize(data);
    // THEN
    AddRelationshipCommand readCommand = (AddRelationshipCommand) reader.read(data);
    assertEquals(indexNameId, readCommand.getIndexNameId());
    assertEquals(entityId, readCommand.getEntityId());
    assertEquals(keyId, readCommand.getKeyId());
    assertEquals(value, readCommand.getValue());
    assertEquals(startNode, readCommand.getStartNode());
    assertEquals(endNode, readCommand.getEndNode());
}
Also used : InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) AddRelationshipCommand(org.neo4j.kernel.impl.index.IndexCommand.AddRelationshipCommand) Test(org.junit.Test)

Example 33 with InMemoryClosableChannel

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

the class LogEntryParserDispatcherV6Test method shouldParserStartEntry.

@Test
public void shouldParserStartEntry() 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 34 with InMemoryClosableChannel

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

the class LogEntryParserDispatcherV6Test method shouldParserOnePhaseCommitEntry.

@Test
public void shouldParserOnePhaseCommitEntry() 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 35 with InMemoryClosableChannel

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

the class LogEntryParserDispatcherV6Test method shouldParseEmptyEntry.

@Test
public void shouldParseEmptyEntry() throws IOException {
    // when
    final LogEntryParser parser = version.entryParser(LogEntryByteCodes.EMPTY);
    final LogEntry logEntry = parser.parse(version, new InMemoryClosableChannel(), marker, commandReader);
    // then
    assertNull(logEntry);
    assertFalse(parser.skip());
}
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