Search in sources :

Example 41 with NodeLabels

use of org.neo4j.kernel.impl.store.NodeLabels in project neo4j by neo4j.

the class NodeLabelsFieldTest method addingAnAlreadyAddedLabelWhenLabelsAreInlinedShouldFail.

@Test
void addingAnAlreadyAddedLabelWhenLabelsAreInlinedShouldFail() {
    // GIVEN
    int labelId = 1;
    NodeRecord node = nodeRecordWithInlinedLabels(labelId);
    NodeLabels nodeLabels = NodeLabelsField.parseLabelsField(node);
    // WHEN
    try {
        nodeLabels.add(labelId, nodeStore, nodeStore.getDynamicLabelStore(), NULL, INSTANCE);
        fail("Should have thrown exception");
    } catch (IllegalStateException e) {
    // THEN
    }
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) DynamicNodeLabels(org.neo4j.kernel.impl.store.DynamicNodeLabels) NodeLabels(org.neo4j.kernel.impl.store.NodeLabels) Test(org.junit.jupiter.api.Test)

Example 42 with NodeLabels

use of org.neo4j.kernel.impl.store.NodeLabels in project neo4j by neo4j.

the class NodeLabelsFieldTest method shouldReallocateSomeOfPreviousDynamicRecords.

@Test
void shouldReallocateSomeOfPreviousDynamicRecords() {
    // GIVEN
    NodeRecord node = nodeRecordWithDynamicLabels(nodeStore, oneByteLongs(5));
    Set<DynamicRecord> initialRecords = Iterables.asUniqueSet(node.getDynamicLabelRecords());
    NodeLabels nodeLabels = NodeLabelsField.parseLabelsField(node);
    // WHEN
    Set<DynamicRecord> reallocatedRecords = Iterables.asUniqueSet(nodeLabels.put(fourByteLongs(100), nodeStore, nodeStore.getDynamicLabelStore(), NULL, INSTANCE));
    // THEN
    assertTrue(reallocatedRecords.containsAll(initialRecords));
    assertTrue(reallocatedRecords.size() > initialRecords.size());
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) DynamicNodeLabels(org.neo4j.kernel.impl.store.DynamicNodeLabels) NodeLabels(org.neo4j.kernel.impl.store.NodeLabels) Test(org.junit.jupiter.api.Test)

Example 43 with NodeLabels

use of org.neo4j.kernel.impl.store.NodeLabels in project neo4j by neo4j.

the class NodeLabelsFieldTest method oneDynamicRecordShouldShrinkIntoInlinedWhenRemoving.

@Test
void oneDynamicRecordShouldShrinkIntoInlinedWhenRemoving() {
    // GIVEN
    NodeRecord node = nodeRecordWithDynamicLabels(nodeStore, oneByteLongs(5));
    Collection<DynamicRecord> initialRecords = node.getDynamicLabelRecords();
    NodeLabels nodeLabels = NodeLabelsField.parseLabelsField(node);
    // WHEN
    Collection<DynamicRecord> changedDynamicRecords = Iterables.asCollection(nodeLabels.remove(255, nodeStore, NULL, INSTANCE));
    // THEN
    assertEquals(initialRecords, changedDynamicRecords);
    Assertions.assertFalse(Iterables.single(changedDynamicRecords).inUse());
    assertEquals(inlinedLabelsLongRepresentation(251, 252, 253, 254), node.getLabelField());
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) DynamicNodeLabels(org.neo4j.kernel.impl.store.DynamicNodeLabels) NodeLabels(org.neo4j.kernel.impl.store.NodeLabels) Test(org.junit.jupiter.api.Test)

Example 44 with NodeLabels

use of org.neo4j.kernel.impl.store.NodeLabels in project neo4j by neo4j.

the class NodeLabelsFieldTest method shouldInlineOneLabelWithHighId.

@Test
void shouldInlineOneLabelWithHighId() {
    // GIVEN
    long labelId = 10000;
    NodeRecord node = nodeRecordWithInlinedLabels();
    NodeLabels nodeLabels = NodeLabelsField.parseLabelsField(node);
    // WHEN
    nodeLabels.add(labelId, null, null, NULL, INSTANCE);
    // THEN
    assertEquals(inlinedLabelsLongRepresentation(labelId), node.getLabelField());
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) DynamicNodeLabels(org.neo4j.kernel.impl.store.DynamicNodeLabels) NodeLabels(org.neo4j.kernel.impl.store.NodeLabels) Test(org.junit.jupiter.api.Test)

Example 45 with NodeLabels

use of org.neo4j.kernel.impl.store.NodeLabels in project neo4j by neo4j.

the class NodeLabelsFieldTest method shouldReallocateAllOfPreviousDynamicRecordsAndThenSome.

@Test
void shouldReallocateAllOfPreviousDynamicRecordsAndThenSome() {
    // GIVEN
    NodeRecord node = nodeRecordWithDynamicLabels(nodeStore, fourByteLongs(100));
    Set<DynamicRecord> initialRecords = Iterables.asSet(cloned(node.getDynamicLabelRecords(), DynamicRecord.class));
    NodeLabels nodeLabels = NodeLabelsField.parseLabelsField(node);
    // WHEN
    Set<DynamicRecord> reallocatedRecords = Iterables.asUniqueSet(nodeLabels.put(fourByteLongs(5), nodeStore, nodeStore.getDynamicLabelStore(), NULL, INSTANCE));
    // THEN
    assertTrue(idsOf(initialRecords).containsAll(idsOf(used(reallocatedRecords))), "initial:" + initialRecords + ", reallocated:" + reallocatedRecords);
    assertTrue(used(reallocatedRecords).size() < initialRecords.size());
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) DynamicNodeLabels(org.neo4j.kernel.impl.store.DynamicNodeLabels) NodeLabels(org.neo4j.kernel.impl.store.NodeLabels) Test(org.junit.jupiter.api.Test)

Aggregations

NodeLabels (org.neo4j.kernel.impl.store.NodeLabels)49 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)46 DynamicNodeLabels (org.neo4j.kernel.impl.store.DynamicNodeLabels)40 Test (org.junit.Test)23 Test (org.junit.jupiter.api.Test)21 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)18 NodeStore (org.neo4j.kernel.impl.store.NodeStore)4 HashSet (java.util.HashSet)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 Command (org.neo4j.kernel.impl.transaction.command.Command)2 BatchInserter (org.neo4j.unsafe.batchinsert.BatchInserter)2 CheckerEngine (org.neo4j.consistency.checking.CheckerEngine)1 LabelChainWalker (org.neo4j.consistency.checking.LabelChainWalker)1 RecordAccess (org.neo4j.consistency.store.RecordAccess)1 InlineNodeLabels (org.neo4j.kernel.impl.store.InlineNodeLabels)1