Search in sources :

Example 1 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 2 with InMemoryClosableChannel

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

the class PhysicalLogCommandReaderV3_0Test method readRelationshipGroupCommandWithNonRequiredSecondaryUnit.

@Test
public void readRelationshipGroupCommandWithNonRequiredSecondaryUnit() throws IOException {
    // Given
    InMemoryClosableChannel channel = new InMemoryClosableChannel();
    RelationshipGroupRecord before = new RelationshipGroupRecord(42, 3);
    RelationshipGroupRecord after = new RelationshipGroupRecord(42, 3, 4, 5, 6, 7, 8, true);
    after.setRequiresSecondaryUnit(false);
    after.setSecondaryUnitId(17);
    after.setCreated();
    new Command.RelationshipGroupCommand(before, after).serialize(channel);
    // When
    PhysicalLogCommandReaderV3_0 reader = new PhysicalLogCommandReaderV3_0();
    Command command = reader.read(channel);
    assertTrue(command instanceof Command.RelationshipGroupCommand);
    Command.RelationshipGroupCommand relationshipGroupCommand = (Command.RelationshipGroupCommand) command;
    // Then
    assertEquals(before, relationshipGroupCommand.getBefore());
    assertEquals(after, relationshipGroupCommand.getAfter());
    verifySecondaryUnit(after, relationshipGroupCommand.getAfter());
}
Also used : RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) Test(org.junit.Test)

Example 3 with InMemoryClosableChannel

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

the class PhysicalLogNeoCommandReaderV2Test method shouldProperlyMaskIndexIdFieldInIndexHeader.

@Test
public void shouldProperlyMaskIndexIdFieldInIndexHeader() throws Exception {
    /* This is how the index command header is laid out
         * [x   ,    ] start node needs long
         * [ x  ,    ] end node needs long
         * [  xx,xxxx] index name id
         * This means that the index name id can be in the range of 0 to 63. This test verifies that
         * this constraint is actually respected
         */
    // GIVEN
    PhysicalLogCommandReaderV2_2_4 reader = new PhysicalLogCommandReaderV2_2_4();
    InMemoryClosableChannel data = new InMemoryClosableChannel();
    // Here we take advantage of the fact that all index commands have the same header written out
    AddRelationshipCommand command = new AddRelationshipCommand();
    long entityId = 123;
    byte keyId = (byte) 1;
    Object value = "test value";
    long startNode = 14;
    long endNode = 15;
    for (byte indexByteId = 0; indexByteId < 63; indexByteId++) {
        // WHEN
        command.init(indexByteId, entityId, keyId, value, startNode, endNode);
        command.serialize(data);
        // THEN
        AddRelationshipCommand readCommand = (AddRelationshipCommand) reader.read(data);
        assertEquals(indexByteId, readCommand.getIndexNameId());
        assertEquals(entityId, readCommand.getEntityId());
        assertEquals(keyId, readCommand.getKeyId());
        assertEquals(value, readCommand.getValue());
        assertEquals(startNode, readCommand.getStartNode());
        assertEquals(endNode, readCommand.getEndNode());
        data.reset();
    }
}
Also used : InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) AddRelationshipCommand(org.neo4j.kernel.impl.index.IndexCommand.AddRelationshipCommand) Test(org.junit.Test)

Example 4 with InMemoryClosableChannel

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

the class PhysicalLogCommandReaderV2_1Test method shouldReadPropertyCommandWithDeletedDynamicRecords.

@Test
public void shouldReadPropertyCommandWithDeletedDynamicRecords() throws Exception {
    // GIVEN
    PhysicalLogCommandReaderV2_1 reader = new PhysicalLogCommandReaderV2_1();
    InMemoryClosableChannel data = new InMemoryClosableChannel();
    long id = 5;
    int keyId = 6;
    byte[] data1 = new byte[] { 1, 2, 3, 4, 5 };
    byte[] data2 = new byte[] { 6, 7, 8, 9, 10 };
    long value = 1234;
    PropertyRecord property = new PropertyRecord(id);
    property.setInUse(true);
    property.addPropertyBlock(propertyBlockWithSomeDynamicRecords(keyId, STRING, value, data1, data2));
    property.addDeletedRecord(dynamicRecord(false, null, STRING.intValue()));
    property.addDeletedRecord(dynamicRecord(false, null, STRING.intValue()));
    // WHEN
    new PropertyCommand(new PropertyRecord(id), property).serialize(data);
    // THEN
    PropertyCommand readCommand = (PropertyCommand) reader.read(data);
    PropertyRecord readRecord = readCommand.getAfter();
    assertEquals(id, readRecord.getId());
    PropertyBlock readBlock = Iterables.single((Iterable<PropertyBlock>) readRecord);
    assertArrayEquals(data1, readBlock.getValueRecords().get(0).getData());
    assertArrayEquals(data2, readBlock.getValueRecords().get(1).getData());
    assertEquals(2, readRecord.getDeletedRecords().size());
}
Also used : PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) PropertyCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyCommand) Test(org.junit.Test)

Example 5 with InMemoryClosableChannel

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

the class PhysicalLogCommandReaderV2_2_4Test method shouldReadNoKeyIdAsMinusOne.

@Test
public void shouldReadNoKeyIdAsMinusOne() throws Exception {
    // GIVEN
    InMemoryClosableChannel channel = new InMemoryClosableChannel();
    IndexDefineCommand definitions = new IndexDefineCommand();
    int indexNameId = 10;
    definitions.init(MapUtil.<String, Integer>genericMap("myindex", indexNameId), MapUtil.<String, Integer>genericMap());
    definitions.serialize(channel);
    RemoveCommand removeCommand = new IndexCommand.RemoveCommand();
    removeCommand.init(indexNameId, IndexEntityType.Node.id(), 1234, -1, null);
    removeCommand.serialize(channel);
    // WHEN
    PhysicalLogCommandReaderV2_2_4 reader = new PhysicalLogCommandReaderV2_2_4();
    assertTrue(reader.read(channel) instanceof IndexDefineCommand);
    RemoveCommand readRemoveCommand = (RemoveCommand) reader.read(channel);
    // THEN
    assertEquals(removeCommand.getIndexNameId(), readRemoveCommand.getIndexNameId());
    assertEquals(removeCommand.getEntityType(), readRemoveCommand.getEntityType());
    assertEquals(removeCommand.getEntityId(), readRemoveCommand.getEntityId());
    assertEquals(removeCommand.getKeyId(), readRemoveCommand.getKeyId());
    assertNull(removeCommand.getValue());
}
Also used : RemoveCommand(org.neo4j.kernel.impl.index.IndexCommand.RemoveCommand) InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) IndexDefineCommand(org.neo4j.kernel.impl.index.IndexDefineCommand) 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