Search in sources :

Example 6 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 7 with LabelScanReader

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

the class DynamicIndexStoreViewTest method visitOnlyLabeledNodesWhenThresholdNotReached.

@Test
public void visitOnlyLabeledNodesWhenThresholdNotReached() throws Exception {
    LabelScanReader labelScanReader = mock(LabelScanReader.class);
    when(labelScanStore.newReader()).thenReturn(labelScanReader);
    when(nodeLabelRanges.maxCount()).thenReturn(1L);
    PrimitiveLongIterator labeledNodesIterator = PrimitiveLongCollections.iterator(1, 2, 3, 4, 5, 6, 7, 8);
    when(nodeStore.getHighestPossibleIdInUse()).thenReturn(200L);
    when(nodeStore.getHighId()).thenReturn(20L);
    when(labelScanReader.nodesWithAnyOfLabels(2, 6)).thenReturn(labeledNodesIterator);
    mockLabelNodeCount(countStore, 2);
    mockLabelNodeCount(countStore, 6);
    DynamicIndexStoreView storeView = new DynamicIndexStoreView(labelScanStore, LockService.NO_LOCK_SERVICE, neoStores, NullLogProvider.getInstance());
    StoreScan<Exception> storeScan = storeView.visitNodes(new int[] { 2, 6 }, propertyKeyIdFilter, propertyUpdateVisitor, labelUpdateVisitor, false);
    storeScan.run();
    Mockito.verify(nodeStore, times(8)).getRecord(anyLong(), any(NodeRecord.class), any(RecordLoad.class));
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) AllEntriesLabelScanReader(org.neo4j.kernel.api.labelscan.AllEntriesLabelScanReader) LabelScanReader(org.neo4j.storageengine.api.schema.LabelScanReader) RecordLoad(org.neo4j.kernel.impl.store.record.RecordLoad) Test(org.junit.Test)

Example 8 with LabelScanReader

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

the class LabelScanStoreTest method shouldUpdateAFullRange.

@Test
public void shouldUpdateAFullRange() throws Exception {
    // given
    long label0Id = 0;
    List<NodeLabelUpdate> label0Updates = new ArrayList<>();
    Set<Long> nodes = new HashSet<>();
    for (int i = 0; i < 34; i++) {
        label0Updates.add(NodeLabelUpdate.labelChanges(i, new long[] {}, new long[] { label0Id }));
        nodes.add((long) i);
    }
    start(label0Updates);
    // when
    write(Collections.emptyIterator());
    // then
    LabelScanReader reader = store.newReader();
    Set<Long> nodesWithLabel0 = PrimitiveLongCollections.toSet(reader.nodesWithLabel((int) label0Id));
    assertEquals(nodes, nodesWithLabel0);
}
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 9 with LabelScanReader

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

the class NativeLabelScanStoreIT method verifyReads.

private void verifyReads(long[] expected) {
    try (LabelScanReader reader = store.newReader()) {
        for (int i = 0; i < LABEL_COUNT; i++) {
            long[] actualNodes = asArray(reader.nodesWithLabel(i));
            long[] expectedNodes = nodesWithLabel(expected, i);
            assertArrayEquals(expectedNodes, actualNodes);
        }
    }
}
Also used : LabelScanReader(org.neo4j.storageengine.api.schema.LabelScanReader)

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