Search in sources :

Example 16 with NodeLabels

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

the class NodeLabelsFieldTest method shouldInlineFiveSmallLabels.

@Test
public void shouldInlineFiveSmallLabels() throws Exception {
    // GIVEN
    long labelId1 = 10, labelId2 = 30, labelId3 = 45, labelId4 = 60, labelId5 = 61;
    NodeRecord node = nodeRecordWithInlinedLabels(labelId1, labelId2, labelId3, labelId4);
    NodeLabels nodeLabels = NodeLabelsField.parseLabelsField(node);
    // WHEN
    nodeLabels.add(labelId5, null, null);
    // THEN
    assertEquals(inlinedLabelsLongRepresentation(labelId1, labelId2, labelId3, labelId4, labelId5), node.getLabelField());
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) NodeLabels(org.neo4j.kernel.impl.store.NodeLabels) DynamicNodeLabels(org.neo4j.kernel.impl.store.DynamicNodeLabels) Test(org.junit.Test)

Example 17 with NodeLabels

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

the class NodeLabelsFieldTest method oneDynamicRecordShouldShrinkIntoInlinedWhenRemoving.

@Test
public void oneDynamicRecordShouldShrinkIntoInlinedWhenRemoving() throws Exception {
    // 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));
    // THEN
    assertEquals(initialRecords, changedDynamicRecords);
    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) NodeLabels(org.neo4j.kernel.impl.store.NodeLabels) DynamicNodeLabels(org.neo4j.kernel.impl.store.DynamicNodeLabels) Test(org.junit.Test)

Example 18 with NodeLabels

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

the class NodeLabelsFieldTest method addingAnAlreadyAddedLabelWhenLabelsAreInDynamicRecordsShouldFail.

@Test
public void addingAnAlreadyAddedLabelWhenLabelsAreInDynamicRecordsShouldFail() throws Exception {
    // GIVEN
    long[] labels = oneByteLongs(20);
    NodeRecord node = nodeRecordWithDynamicLabels(nodeStore, labels);
    NodeLabels nodeLabels = NodeLabelsField.parseLabelsField(node);
    // WHEN
    try {
        nodeLabels.add(safeCastLongToInt(labels[0]), nodeStore, nodeStore.getDynamicLabelStore());
        fail("Should have thrown exception");
    } catch (IllegalStateException e) {
    // THEN
    }
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) NodeLabels(org.neo4j.kernel.impl.store.NodeLabels) DynamicNodeLabels(org.neo4j.kernel.impl.store.DynamicNodeLabels) Test(org.junit.Test)

Example 19 with NodeLabels

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

the class NodeLabelsFieldTest method shouldHandleRandomAddsAndRemoves.

/*
     * There was this issue that DynamicNodeLabels#add would consider even unused dynamic records when
     * reading existing label ids before making the change. Previously this would create a duplicate
     * last label id (the one formerly being in the second record).
     *
     * This randomized test found this issue every time when it existed and it will potentially find other
     * unforeseen issues as well.
     */
@Test
public void shouldHandleRandomAddsAndRemoves() throws Exception {
    // GIVEN
    Set<Integer> key = new HashSet<>();
    NodeRecord node = new NodeRecord(0);
    node.setInUse(true);
    // WHEN
    for (int i = 0; i < 100_000; i++) {
        NodeLabels labels = NodeLabelsField.parseLabelsField(node);
        int labelId = random.nextInt(200);
        if (random.nextBoolean()) {
            if (!key.contains(labelId)) {
                labels.add(labelId, nodeStore, nodeStore.getDynamicLabelStore());
                key.add(labelId);
            }
        } else {
            if (key.remove(labelId)) {
                labels.remove(labelId, nodeStore);
            }
        }
    }
    // THEN
    NodeLabels labels = NodeLabelsField.parseLabelsField(node);
    long[] readLabelIds = labels.get(nodeStore);
    for (long labelId : readLabelIds) {
        assertTrue("Found an unexpected label " + labelId, key.remove((int) labelId));
    }
    assertTrue(key.isEmpty());
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) NodeLabels(org.neo4j.kernel.impl.store.NodeLabels) DynamicNodeLabels(org.neo4j.kernel.impl.store.DynamicNodeLabels) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 20 with NodeLabels

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

the class NodeLabelsFieldTest method removingNonExistentInlinedLabelShouldFail.

@Test
public void removingNonExistentInlinedLabelShouldFail() throws Exception {
    // GIVEN
    int labelId1 = 1, labelId2 = 2;
    NodeRecord node = nodeRecordWithInlinedLabels(labelId1);
    NodeLabels nodeLabels = NodeLabelsField.parseLabelsField(node);
    // WHEN
    try {
        nodeLabels.remove(labelId2, nodeStore);
        fail("Should have thrown exception");
    } catch (IllegalStateException e) {
    // THEN
    }
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) NodeLabels(org.neo4j.kernel.impl.store.NodeLabels) DynamicNodeLabels(org.neo4j.kernel.impl.store.DynamicNodeLabels) Test(org.junit.Test)

Aggregations

NodeLabels (org.neo4j.kernel.impl.store.NodeLabels)26 Test (org.junit.Test)23 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)23 DynamicNodeLabels (org.neo4j.kernel.impl.store.DynamicNodeLabels)21 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)10 HashSet (java.util.HashSet)2 NodeStore (org.neo4j.kernel.impl.store.NodeStore)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