Search in sources :

Example 1 with NodeLabelRange

use of org.neo4j.kernel.api.labelscan.NodeLabelRange in project neo4j by neo4j.

the class NativeAllEntriesLabelScanReaderTest method assertRanges.

private static void assertRanges(AllEntriesLabelScanReader reader, Labels[] data) {
    Iterator<NodeLabelRange> iterator = reader.iterator();
    long highestRangeId = highestRangeId(data);
    for (long rangeId = 0; rangeId <= highestRangeId; rangeId++) {
        SortedMap<Long, List<Long>> /*labelIds*/
        expected = rangeOf(data, rangeId);
        if (expected != null) {
            assertTrue("Was expecting range " + expected, iterator.hasNext());
            NodeLabelRange range = iterator.next();
            assertEquals(rangeId, range.id());
            assertArrayEquals("Unexpected data in range " + rangeId, nodesOf(expected), range.nodes());
            for (Map.Entry<Long, List<Long>> expectedEntry : expected.entrySet()) {
                long[] labels = range.labels(expectedEntry.getKey());
                assertArrayEquals(asArray(expectedEntry.getValue().iterator()), labels);
            }
        }
    // else there was nothing in this range
    }
    assertFalse(iterator.hasNext());
}
Also used : NodeLabelRange(org.neo4j.kernel.api.labelscan.NodeLabelRange) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) TreeMap(java.util.TreeMap) PrimitiveIntObjectMap(org.neo4j.collection.primitive.PrimitiveIntObjectMap) SortedMap(java.util.SortedMap)

Example 2 with NodeLabelRange

use of org.neo4j.kernel.api.labelscan.NodeLabelRange in project neo4j by neo4j.

the class LabelScanStoreTest method shouldScanMultipleRanges.

@Test
public void shouldScanMultipleRanges() throws Exception {
    // GIVEN
    int labelId1 = 1, labelId2 = 2;
    long nodeId1 = 10, nodeId2 = 1280;
    start(asList(labelChanges(nodeId1, NO_LABELS, new long[] { labelId1 }), labelChanges(nodeId2, NO_LABELS, new long[] { labelId1, labelId2 })));
    // WHEN
    BoundedIterable<NodeLabelRange> reader = store.allNodeLabelRanges();
    Iterator<NodeLabelRange> iterator = reader.iterator();
    NodeLabelRange range1 = iterator.next();
    NodeLabelRange range2 = iterator.next();
    assertFalse(iterator.hasNext());
    // THEN
    assertArrayEquals(new long[] { nodeId1 }, sorted(range1.nodes()));
    assertArrayEquals(new long[] { nodeId2 }, sorted(range2.nodes()));
    assertArrayEquals(new long[] { labelId1 }, sorted(range1.labels(nodeId1)));
    assertArrayEquals(new long[] { labelId1, labelId2 }, sorted(range2.labels(nodeId2)));
}
Also used : NodeLabelRange(org.neo4j.kernel.api.labelscan.NodeLabelRange) Test(org.junit.Test)

Example 3 with NodeLabelRange

use of org.neo4j.kernel.api.labelscan.NodeLabelRange in project neo4j by neo4j.

the class LabelScanStoreTest method shouldScanSingleRange.

@Test
public void shouldScanSingleRange() throws Exception {
    // GIVEN
    int labelId1 = 1, labelId2 = 2;
    long nodeId1 = 10, nodeId2 = 11;
    start(asList(labelChanges(nodeId1, NO_LABELS, new long[] { labelId1 }), labelChanges(nodeId2, NO_LABELS, new long[] { labelId1, labelId2 })));
    // WHEN
    BoundedIterable<NodeLabelRange> reader = store.allNodeLabelRanges();
    NodeLabelRange range = single(reader.iterator());
    // THEN
    assertArrayEquals(new long[] { nodeId1, nodeId2 }, sorted(range.nodes()));
    assertArrayEquals(new long[] { labelId1 }, sorted(range.labels(nodeId1)));
    assertArrayEquals(new long[] { labelId1, labelId2 }, sorted(range.labels(nodeId2)));
}
Also used : NodeLabelRange(org.neo4j.kernel.api.labelscan.NodeLabelRange) Test(org.junit.Test)

Aggregations

NodeLabelRange (org.neo4j.kernel.api.labelscan.NodeLabelRange)3 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 PrimitiveIntObjectMap (org.neo4j.collection.primitive.PrimitiveIntObjectMap)1