Search in sources :

Example 1 with LabelScanReader

use of org.neo4j.storageengine.api.schema.LabelScanReader in project neo4j by neo4j.

the class StoreStatementTest method shouldCloseOpenedLabelScanReader.

@Test
public void shouldCloseOpenedLabelScanReader() throws Exception {
    // given
    Supplier<LabelScanReader> scanStore = mock(Supplier.class);
    LabelScanReader scanReader = mock(LabelScanReader.class);
    when(scanStore.get()).thenReturn(scanReader);
    StoreStatement statement = new StoreStatement(MockedNeoStores.basicMockedNeoStores(), mock(Supplier.class), scanStore, LockService.NO_LOCK_SERVICE);
    statement.acquire();
    // when
    LabelScanReader actualReader = statement.getLabelScanReader();
    // then
    assertEquals(scanReader, actualReader);
    // when
    statement.close();
    // then
    verify(scanStore).get();
    verifyNoMoreInteractions(scanStore);
    verify(scanReader).close();
    verifyNoMoreInteractions(scanReader);
}
Also used : LabelScanReader(org.neo4j.storageengine.api.schema.LabelScanReader) Supplier(java.util.function.Supplier) Test(org.junit.Test)

Example 2 with LabelScanReader

use of org.neo4j.storageengine.api.schema.LabelScanReader in project neo4j by neo4j.

the class LabelScanStoreTest method shouldFindDecentAmountOfNodesForALabel.

@Test
public void shouldFindDecentAmountOfNodesForALabel() throws Exception {
    // GIVEN
    // 16 is the magic number of the page iterator
    // 32 is the number of nodes in each lucene document
    final int labelId = 1, nodeCount = 32 * 16 + 10;
    start();
    write(new PrefetchingIterator<NodeLabelUpdate>() {

        private int i = -1;

        @Override
        protected NodeLabelUpdate fetchNextOrNull() {
            return ++i < nodeCount ? labelChanges(i, NO_LABELS, new long[] { labelId }) : null;
        }
    });
    // WHEN
    Set<Long> nodeSet = new TreeSet<>();
    LabelScanReader reader = store.newReader();
    PrimitiveLongIterator nodes = reader.nodesWithLabel(labelId);
    while (nodes.hasNext()) {
        nodeSet.add(nodes.next());
    }
    reader.close();
    // THEN
    assertEquals("Found gaps in node id range: " + gaps(nodeSet, nodeCount), nodeCount, nodeSet.size());
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) LabelScanReader(org.neo4j.storageengine.api.schema.LabelScanReader) TreeSet(java.util.TreeSet) NodeLabelUpdate(org.neo4j.kernel.api.labelscan.NodeLabelUpdate) Test(org.junit.Test)

Example 3 with LabelScanReader

use of org.neo4j.storageengine.api.schema.LabelScanReader in project neo4j by neo4j.

the class LabelScanStoreTest method shouldFindNodesWithAllGivenLabels.

@Test
public void shouldFindNodesWithAllGivenLabels() throws Exception {
    // GIVEN
    int labelId1 = 3, labelId2 = 5, labelId3 = 13;
    start();
    // WHEN
    write(iterator(labelChanges(5, EMPTY_LONG_ARRAY, new long[] { labelId1, labelId2, labelId3 }), labelChanges(8, EMPTY_LONG_ARRAY, new long[] { labelId3 }), labelChanges(3, EMPTY_LONG_ARRAY, new long[] { labelId1 }), labelChanges(6, EMPTY_LONG_ARRAY, new long[] { labelId2 }), labelChanges(1, EMPTY_LONG_ARRAY, new long[] { labelId1 }), labelChanges(7, EMPTY_LONG_ARRAY, new long[] { labelId2 }), labelChanges(4, EMPTY_LONG_ARRAY, new long[] { labelId1, labelId3 }), labelChanges(2, EMPTY_LONG_ARRAY, new long[] { labelId1, labelId2 }), labelChanges(9, EMPTY_LONG_ARRAY, new long[] { labelId3 })));
    // THEN
    try (LabelScanReader reader = store.newReader()) {
        assertArrayEquals(new long[] { 2, 5 }, PrimitiveLongCollections.asArray(reader.nodesWithAllLabels(labelId1, labelId2)));
        assertArrayEquals(new long[] { 4, 5 }, PrimitiveLongCollections.asArray(reader.nodesWithAllLabels(labelId1, labelId3)));
        assertArrayEquals(new long[] { 5 }, PrimitiveLongCollections.asArray(reader.nodesWithAllLabels(labelId1, labelId2, labelId3)));
    }
}
Also used : LabelScanReader(org.neo4j.storageengine.api.schema.LabelScanReader) Test(org.junit.Test)

Example 4 with LabelScanReader

use of org.neo4j.storageengine.api.schema.LabelScanReader in project neo4j by neo4j.

the class LabelScanStoreTest method shouldWorkWithAFullRange.

@Test
public void shouldWorkWithAFullRange() throws Exception {
    // given
    long labelId = 0;
    List<NodeLabelUpdate> updates = new ArrayList<>();
    Set<Long> nodes = new HashSet<>();
    for (int i = 0; i < 34; i++) {
        updates.add(NodeLabelUpdate.labelChanges(i, new long[] {}, new long[] { labelId }));
        nodes.add((long) i);
    }
    start(updates);
    // when
    LabelScanReader reader = store.newReader();
    Set<Long> nodesWithLabel = PrimitiveLongCollections.toSet(reader.nodesWithLabel((int) labelId));
    // then
    assertEquals(nodes, nodesWithLabel);
}
Also used : LabelScanReader(org.neo4j.storageengine.api.schema.LabelScanReader) ArrayList(java.util.ArrayList) NodeLabelUpdate(org.neo4j.kernel.api.labelscan.NodeLabelUpdate) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with LabelScanReader

use of org.neo4j.storageengine.api.schema.LabelScanReader in project neo4j by neo4j.

the class LabelScanStoreTest method shouldFindNodesWithAnyOfGivenLabels.

@Test
public void shouldFindNodesWithAnyOfGivenLabels() throws Exception {
    // GIVEN
    int labelId1 = 3, labelId2 = 5, labelId3 = 13;
    start();
    // WHEN
    write(iterator(labelChanges(2, EMPTY_LONG_ARRAY, new long[] { labelId1, labelId2 }), labelChanges(1, EMPTY_LONG_ARRAY, new long[] { labelId1 }), labelChanges(4, EMPTY_LONG_ARRAY, new long[] { labelId1, labelId3 }), labelChanges(5, EMPTY_LONG_ARRAY, new long[] { labelId1, labelId2, labelId3 }), labelChanges(3, EMPTY_LONG_ARRAY, new long[] { labelId1 }), labelChanges(7, EMPTY_LONG_ARRAY, new long[] { labelId2 }), labelChanges(8, EMPTY_LONG_ARRAY, new long[] { labelId3 }), labelChanges(6, EMPTY_LONG_ARRAY, new long[] { labelId2 }), labelChanges(9, EMPTY_LONG_ARRAY, new long[] { labelId3 })));
    // THEN
    try (LabelScanReader reader = store.newReader()) {
        assertArrayEquals(new long[] { 1, 2, 3, 4, 5, 6, 7 }, PrimitiveLongCollections.asArray(reader.nodesWithAnyOfLabels(labelId1, labelId2)));
        assertArrayEquals(new long[] { 1, 2, 3, 4, 5, 8, 9 }, PrimitiveLongCollections.asArray(reader.nodesWithAnyOfLabels(labelId1, labelId3)));
        assertArrayEquals(new long[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, PrimitiveLongCollections.asArray(reader.nodesWithAnyOfLabels(labelId1, labelId2, labelId3)));
    }
}
Also used : LabelScanReader(org.neo4j.storageengine.api.schema.LabelScanReader) Test(org.junit.Test)

Aggregations

LabelScanReader (org.neo4j.storageengine.api.schema.LabelScanReader)9 Test (org.junit.Test)8 NodeLabelUpdate (org.neo4j.kernel.api.labelscan.NodeLabelUpdate)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)2 TreeSet (java.util.TreeSet)1 Supplier (java.util.function.Supplier)1 AllEntriesLabelScanReader (org.neo4j.kernel.api.labelscan.AllEntriesLabelScanReader)1 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)1 RecordLoad (org.neo4j.kernel.impl.store.record.RecordLoad)1