Search in sources :

Example 46 with NodeLabels

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

the class NodeLabelsFieldTest method addingAnAlreadyAddedLabelWhenLabelsAreInDynamicRecordsShouldFail.

@Test
void addingAnAlreadyAddedLabelWhenLabelsAreInDynamicRecordsShouldFail() {
    // 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(), 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 47 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
void shouldHandleRandomAddsAndRemoves() {
    // 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(), NULL, INSTANCE);
                key.add(labelId);
            }
        } else {
            if (key.remove(labelId)) {
                labels.remove(labelId, nodeStore, NULL, INSTANCE);
            }
        }
    }
    // THEN
    NodeLabels labels = NodeLabelsField.parseLabelsField(node);
    long[] readLabelIds = labels.get(nodeStore, NULL);
    for (long labelId : readLabelIds) {
        assertTrue(key.remove((int) labelId), "Found an unexpected label " + labelId);
    }
    assertTrue(key.isEmpty());
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) DynamicNodeLabels(org.neo4j.kernel.impl.store.DynamicNodeLabels) NodeLabels(org.neo4j.kernel.impl.store.NodeLabels) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 48 with NodeLabels

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

the class NodeLabelsFieldTest method maximumOfSevenInlinedLabels.

@Test
void maximumOfSevenInlinedLabels() {
    // GIVEN
    long[] labels = new long[] { 0, 1, 2, 3, 4, 5, 6 };
    NodeRecord node = nodeRecordWithInlinedLabels(labels);
    NodeLabels nodeLabels = NodeLabelsField.parseLabelsField(node);
    // WHEN
    Iterable<DynamicRecord> changedDynamicRecords = nodeLabels.add(23, nodeStore, nodeStore.getDynamicLabelStore(), NULL, INSTANCE);
    // THEN
    assertEquals(dynamicLabelsLongRepresentation(changedDynamicRecords), node.getLabelField());
    assertEquals(1, Iterables.count(changedDynamicRecords));
}
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 49 with NodeLabels

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

the class BatchInsertTest method shouldSortLabelIdsWhenGetOrCreate.

@ParameterizedTest
@MethodSource("params")
void shouldSortLabelIdsWhenGetOrCreate(int denseNodeThreshold) throws Exception {
    // GIVEN
    var inserter = newBatchInserter(denseNodeThreshold);
    // WHEN
    long nodeId = inserter.createNode(map("Item", 123456789123L), label("AA"), label("BB"), label("CC"), label("DD"));
    inserter.setNodeLabels(nodeId, label("CC"), label("AA"), label("DD"), label("EE"), label("FF"));
    // THEN
    NodeStore nodeStore = getFlushedNeoStores(inserter).getNodeStore();
    NodeRecord node = nodeStore.getRecord(nodeId, nodeStore.newRecord(), NORMAL, NULL);
    NodeLabels labels = NodeLabelsField.parseLabelsField(node);
    long[] labelIds = labels.get(nodeStore, NULL);
    long[] sortedLabelIds = Arrays.copyOf(labelIds, labelIds.length);
    Arrays.sort(sortedLabelIds);
    assertArrayEquals(sortedLabelIds, labelIds);
    inserter.shutdown();
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) NodeStore(org.neo4j.kernel.impl.store.NodeStore) NodeLabels(org.neo4j.kernel.impl.store.NodeLabels) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

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