Search in sources :

Example 31 with StorageCommand

use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.

the class LogCommandSerializationV4_0Test method shouldReadRelationshipGroupCommand.

@Test
void shouldReadRelationshipGroupCommand() throws Throwable {
    // Given
    InMemoryClosableChannel channel = new InMemoryClosableChannel();
    RelationshipGroupRecord before = new RelationshipGroupRecord(42).initialize(false, 3, NULL_REF, NULL_REF, NULL_REF, NULL_REF, NULL_REF);
    RelationshipGroupRecord after = new RelationshipGroupRecord(42).initialize(true, 3, 4, 5, 6, 7, 8);
    after.setCreated();
    new Command.RelationshipGroupCommand(writer(), before, after).serialize(channel);
    // When
    CommandReader reader = createReader();
    StorageCommand command = reader.read(channel);
    assertTrue(command instanceof Command.RelationshipGroupCommand);
    Command.RelationshipGroupCommand relationshipGroupCommand = (Command.RelationshipGroupCommand) command;
    // Then
    assertBeforeAndAfterEquals(relationshipGroupCommand, before, after);
}
Also used : CommandReader(org.neo4j.storageengine.api.CommandReader) RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) StorageCommand(org.neo4j.storageengine.api.StorageCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 32 with StorageCommand

use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.

the class LogCommandSerializationV4_0Test method readRelationshipGroupCommandWithFixedReferenceFormat.

@Test
void readRelationshipGroupCommandWithFixedReferenceFormat() throws IOException {
    // Given
    InMemoryClosableChannel channel = new InMemoryClosableChannel();
    RelationshipGroupRecord before = new RelationshipGroupRecord(42).initialize(false, 3, NULL_REF, NULL_REF, NULL_REF, NULL_REF, NULL_REF);
    before.setUseFixedReferences(true);
    RelationshipGroupRecord after = new RelationshipGroupRecord(42).initialize(true, 3, 4, 5, 6, 7, 8);
    after.setUseFixedReferences(true);
    after.setCreated();
    new Command.RelationshipGroupCommand(writer(), before, after).serialize(channel);
    // When
    CommandReader reader = createReader();
    StorageCommand command = reader.read(channel);
    assertTrue(command instanceof Command.RelationshipGroupCommand);
    Command.RelationshipGroupCommand relationshipGroupCommand = (Command.RelationshipGroupCommand) command;
    // Then
    assertBeforeAndAfterEquals(relationshipGroupCommand, before, after);
    assertTrue(relationshipGroupCommand.getBefore().isUseFixedReferences());
    assertTrue(relationshipGroupCommand.getAfter().isUseFixedReferences());
}
Also used : CommandReader(org.neo4j.storageengine.api.CommandReader) RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) StorageCommand(org.neo4j.storageengine.api.StorageCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 33 with StorageCommand

use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.

the class LogCommandSerializationV4_0Test method shouldReadInternalPropertyKeyCommand.

@Test
void shouldReadInternalPropertyKeyCommand() throws Exception {
    // Given
    InMemoryClosableChannel channel = new InMemoryClosableChannel();
    PropertyKeyTokenRecord before = new PropertyKeyTokenRecord(42);
    PropertyKeyTokenRecord after = before.copy();
    after.initialize(true, 13);
    after.setCreated();
    after.setInternal(true);
    new Command.PropertyKeyTokenCommand(writer(), before, after).serialize(channel);
    // When
    CommandReader reader = createReader();
    StorageCommand command = reader.read(channel);
    assertTrue(command instanceof Command.PropertyKeyTokenCommand);
    Command.PropertyKeyTokenCommand propertyKeyTokenCommand = (Command.PropertyKeyTokenCommand) command;
    // Then
    assertBeforeAndAfterEquals(propertyKeyTokenCommand, before, after);
}
Also used : CommandReader(org.neo4j.storageengine.api.CommandReader) InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) StorageCommand(org.neo4j.storageengine.api.StorageCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) PropertyKeyTokenRecord(org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 34 with StorageCommand

use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.

the class LogCommandSerializationV4_0Test method shouldReadRelationshipCommand.

@Test
void shouldReadRelationshipCommand() throws Throwable {
    // Given
    InMemoryClosableChannel channel = new InMemoryClosableChannel();
    RelationshipRecord before = new RelationshipRecord(42);
    before.setLinks(-1, -1, -1);
    RelationshipRecord after = new RelationshipRecord(42);
    after.initialize(true, 0, 1, 2, 3, 4, 5, 6, 7, true, true);
    after.setCreated();
    new Command.RelationshipCommand(writer(), before, after).serialize(channel);
    // When
    CommandReader reader = createReader();
    StorageCommand command = reader.read(channel);
    assertTrue(command instanceof Command.RelationshipCommand);
    Command.RelationshipCommand relationshipCommand = (Command.RelationshipCommand) command;
    // Then
    assertBeforeAndAfterEquals(relationshipCommand, before, after);
}
Also used : CommandReader(org.neo4j.storageengine.api.CommandReader) InMemoryClosableChannel(org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel) StorageCommand(org.neo4j.storageengine.api.StorageCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 35 with StorageCommand

use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.

the class LogTruncationTest method assertHandlesLogTruncation.

private void assertHandlesLogTruncation(Command cmd) throws IOException {
    inMemoryChannel.reset();
    cmd.serialize(inMemoryChannel);
    int bytesSuccessfullyWritten = inMemoryChannel.writerPosition();
    try {
        StorageCommand command = serialization.read(inMemoryChannel);
        assertEquals(cmd, command);
    } catch (Exception e) {
        throw new AssertionError("Failed to deserialize " + cmd + ", because: ", e);
    }
    bytesSuccessfullyWritten--;
    while (bytesSuccessfullyWritten-- > 0) {
        inMemoryChannel.reset();
        cmd.serialize(inMemoryChannel);
        inMemoryChannel.truncateTo(bytesSuccessfullyWritten);
        Command command = null;
        try {
            command = serialization.read(inMemoryChannel);
        } catch (ReadPastEndException e) {
            assertNull(command, "Deserialization did not detect log truncation!" + "Record: " + cmd + ", deserialized: " + command);
        }
    }
}
Also used : RelationshipCountsCommand(org.neo4j.internal.recordstorage.Command.RelationshipCountsCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) NodeCountsCommand(org.neo4j.internal.recordstorage.Command.NodeCountsCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) IOException(java.io.IOException) ReadPastEndException(org.neo4j.io.fs.ReadPastEndException) ReadPastEndException(org.neo4j.io.fs.ReadPastEndException)

Aggregations

StorageCommand (org.neo4j.storageengine.api.StorageCommand)77 ArrayList (java.util.ArrayList)39 Test (org.junit.jupiter.api.Test)34 CommandReader (org.neo4j.storageengine.api.CommandReader)23 InMemoryClosableChannel (org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel)22 RepeatedTest (org.junit.jupiter.api.RepeatedTest)19 PhysicalTransactionRepresentation (org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)14 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)10 Test (org.junit.Test)10 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)9 RelationshipGroupRecord (org.neo4j.kernel.impl.store.record.RelationshipGroupRecord)9 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)8 Command (org.neo4j.kernel.impl.transaction.command.Command)7 NodeCommand (org.neo4j.kernel.impl.transaction.command.Command.NodeCommand)7 LogEntryCommand (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand)7 SchemaRuleCommand (org.neo4j.internal.recordstorage.Command.SchemaRuleCommand)6 NeoStores (org.neo4j.kernel.impl.store.NeoStores)6 IOException (java.io.IOException)5 PropertyCommand (org.neo4j.internal.recordstorage.Command.PropertyCommand)5 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)5