@Override public void nodesWithLabel( IndexProgressor.NodeLabelClient client, int labelId ) { RawCursor<Hit<LabelScanKey,LabelScanValue>,IOException> cursor; try { cursor = seekerForLabel( 0, labelId ); openCursors.add( cursor ); } catch ( IOException e ) { throw new UncheckedIOException( e ); } client.scan( new LabelScanValueIndexProgressor( cursor, openCursors, client ), false, labelId ); }
private void exhaust( LabelScanValueIndexProgressor pro ) { while ( pro.next() ) { //do nothing } } }
@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<>(); LabelScanValueIndexProgressor iterator = new LabelScanValueIndexProgressor( cursor, toRemoveFrom, mock( IndexProgressor.NodeLabelClient.class ) ); 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.next(); verify( cursor, times( 1 ) ).close(); // and set should be empty assertTrue( toRemoveFrom.isEmpty() ); }
close(); return false; assert keysInOrder( hit.key() );
close(); return false; assert keysInOrder( hit.key() );
@Override public void nodesWithLabel( IndexProgressor.NodeLabelClient client, int labelId ) { RawCursor<Hit<LabelScanKey,LabelScanValue>,IOException> cursor; try { cursor = seekerForLabel( 0, labelId ); openCursors.add( cursor ); } catch ( IOException e ) { throw new UncheckedIOException( e ); } client.scan( new LabelScanValueIndexProgressor( cursor, openCursors, client ), false, labelId ); }