@Override public PrimitiveLongResourceIterator nodesWithLabel( int labelId ) { RawCursor<Hit<LabelScanKey,LabelScanValue>,IOException> cursor; try { cursor = seekerForLabel( 0, labelId ); openCursors.add( cursor ); } catch ( IOException e ) { throw new UncheckedIOException( e ); } return new LabelScanValueIterator( cursor, openCursors, NO_ID ); }
private List<PrimitiveLongResourceIterator> iteratorsForLabels( long fromId, int[] labelIds ) { List<PrimitiveLongResourceIterator> iterators = new ArrayList<>(); try { for ( int labelId : labelIds ) { RawCursor<Hit<LabelScanKey,LabelScanValue>,IOException> cursor = seekerForLabel( fromId, labelId ); openCursors.add( cursor ); iterators.add( new LabelScanValueIterator( cursor, openCursors, fromId ) ); } } catch ( IOException e ) { throw new UncheckedIOException( e ); } return iterators; }
@Test public void shouldCloseExhaustedCursors() throws Exception { // GIVEN RawCursor<Hit<LabelScanKey,LabelScanValue>,IOException> cursor = mock( RawCursor.class ); when( cursor.next() ).thenReturn( false ); Collection<RawCursor<Hit<LabelScanKey,LabelScanValue>,IOException>> toRemoveFrom = new HashSet<>(); LabelScanValueIterator iterator = new LabelScanValueIterator( cursor, toRemoveFrom, NO_ID ); verify( cursor, never() ).close(); // WHEN exhaust( iterator ); verify( cursor, times( 1 ) ).close(); // retrying to get more items from the first one should not close it again iterator.hasNext(); verify( cursor, times( 1 ) ).close(); // and set should be empty assertTrue( toRemoveFrom.isEmpty() ); }
@Test public void shouldAddLabels() throws Exception { // GIVEN ControlledInserter inserter = new ControlledInserter(); long[] expected = new long[NODE_COUNT]; try ( NativeLabelScanWriter writer = new NativeLabelScanWriter( max( 5, NODE_COUNT / 100 ), NativeLabelScanWriter.EMPTY ) ) { writer.initialize( inserter ); // WHEN for ( int i = 0; i < NODE_COUNT * 3; i++ ) { NodeLabelUpdate update = randomUpdate( expected ); writer.write( update ); } } // THEN for ( int i = 0; i < LABEL_COUNT; i++ ) { long[] expectedNodeIds = nodesWithLabel( expected, i ); long[] actualNodeIds = asArray( new LabelScanValueIterator( inserter.nodesFor( i ), new ArrayList<>(), NO_ID ) ); assertArrayEquals( "For label " + i, expectedNodeIds, actualNodeIds ); } }
@Override public PrimitiveLongResourceIterator nodesWithLabel( int labelId ) { RawCursor<Hit<LabelScanKey,LabelScanValue>,IOException> cursor; try { cursor = seekerForLabel( 0, labelId ); openCursors.add( cursor ); } catch ( IOException e ) { throw new UncheckedIOException( e ); } return new LabelScanValueIterator( cursor, openCursors, NO_ID ); }
private List<PrimitiveLongResourceIterator> iteratorsForLabels( long fromId, int[] labelIds ) { List<PrimitiveLongResourceIterator> iterators = new ArrayList<>(); try { for ( int labelId : labelIds ) { RawCursor<Hit<LabelScanKey,LabelScanValue>,IOException> cursor = seekerForLabel( fromId, labelId ); openCursors.add( cursor ); iterators.add( new LabelScanValueIterator( cursor, openCursors, fromId ) ); } } catch ( IOException e ) { throw new UncheckedIOException( e ); } return iterators; }