Search in sources :

Example 1 with PrimitiveLongResourceIterator

use of org.neo4j.collection.primitive.PrimitiveLongResourceIterator in project neo4j by neo4j.

the class LabelScanViewNodeStoreScanTest method iterateOverLabeledNodeIds.

@Test
public void iterateOverLabeledNodeIds() throws Exception {
    PrimitiveLongIterator labeledNodes = PrimitiveLongCollections.iterator(1, 2, 4, 8);
    when(nodeStore.getHighId()).thenReturn(15L);
    when(labelScanReader.nodesWithAnyOfLabels(1, 2)).thenReturn(labeledNodes);
    int[] labelIds = new int[] { 1, 2 };
    LabelScanViewNodeStoreScan<Exception> storeScan = getLabelScanViewStoreScan(labelIds);
    PrimitiveLongResourceIterator idIterator = storeScan.getNodeIdIterator();
    List<Long> visitedNodeIds = PrimitiveLongCollections.asList(idIterator);
    assertThat(visitedNodeIds, Matchers.hasSize(4));
    assertThat(visitedNodeIds, Matchers.hasItems(1L, 2L, 4L, 8L));
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) PrimitiveLongResourceIterator(org.neo4j.collection.primitive.PrimitiveLongResourceIterator) Test(org.junit.Test)

Example 2 with PrimitiveLongResourceIterator

use of org.neo4j.collection.primitive.PrimitiveLongResourceIterator in project neo4j by neo4j.

the class LabelScanViewNodeStoreScanTest method resetNodeIdIteratorDuringConcurrentUpdates.

@Test
public void resetNodeIdIteratorDuringConcurrentUpdates() {
    when(labelScanReader.nodesWithAnyOfLabels(1, 2)).thenReturn(PrimitiveLongCollections.iterator(1, 2, 3, 4));
    LabelScanViewNodeStoreScan<Exception> scanViewStoreScan = getLabelScanViewStoreScan(new int[] { 1, 2 });
    PrimitiveLongResourceIterator nodeIdIterator = scanViewStoreScan.getNodeIdIterator();
    verify(labelScanStore).newReader();
    verify(labelScanReader).nodesWithAnyOfLabels(1, 2);
    assertTrue("Contain 4 nodes id.", nodeIdIterator.hasNext());
    assertEquals("First expected node id is 1.", 1, nodeIdIterator.next());
    assertTrue("Contain 4 nodes id.", nodeIdIterator.hasNext());
    assertEquals("Second expected node id is 2.", 2, nodeIdIterator.next());
    populateWithConcurrentUpdates(scanViewStoreScan);
    assertTrue("Contain 4 nodes id.", nodeIdIterator.hasNext());
    assertEquals("Third expected node id is 3.", 3, nodeIdIterator.next());
    verify(labelScanReader).close();
    verify(labelScanStore, times(2)).newReader();
    verify(labelScanReader, times(2)).nodesWithAnyOfLabels(1, 2);
    assertTrue("Contain 4 nodes id.", nodeIdIterator.hasNext());
    assertEquals("Fourth expected node id is 4.", 4, nodeIdIterator.next());
    assertFalse(nodeIdIterator.hasNext());
    verifyNoMoreInteractions(labelScanReader, labelScanStore);
}
Also used : PrimitiveLongResourceIterator(org.neo4j.collection.primitive.PrimitiveLongResourceIterator) Test(org.junit.Test)

Example 3 with PrimitiveLongResourceIterator

use of org.neo4j.collection.primitive.PrimitiveLongResourceIterator in project neo4j by neo4j.

the class StateHandlingStatementOperations method nodeGetFromUniqueIndexSeek.

@Override
public long nodeGetFromUniqueIndexSeek(KernelStatement state, NewIndexDescriptor index, IndexQuery.ExactPredicate... query) throws IndexNotFoundKernelException, IndexBrokenKernelException, IndexNotApplicableKernelException {
    IndexReader reader = state.getStoreStatement().getFreshIndexReader(index);
    /* Here we have an intricate scenario where we need to return the PrimitiveLongIterator
         * since subsequent filtering will happen outside, but at the same time have the ability to
         * close the IndexReader when done iterating over the lookup result. This is because we get
         * a fresh reader that isn't associated with the current transaction and hence will not be
         * automatically closed. */
    PrimitiveLongResourceIterator committed = resourceIterator(reader.query(query), reader);
    PrimitiveLongIterator exactMatches = LookupFilter.exactIndexMatches(this, state, committed, query);
    PrimitiveLongIterator changesFiltered = filterIndexStateChangesForSeek(state, exactMatches, index, OrderedPropertyValues.of(query));
    return single(resourceIterator(changesFiltered, committed), NO_SUCH_NODE);
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) PrimitiveLongResourceIterator(org.neo4j.collection.primitive.PrimitiveLongResourceIterator)

Aggregations

PrimitiveLongResourceIterator (org.neo4j.collection.primitive.PrimitiveLongResourceIterator)3 Test (org.junit.Test)2 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)2 IndexReader (org.neo4j.storageengine.api.schema.IndexReader)1