/** * @return {@link LabelScanReader} capable of finding node ids with given label ids. * Readers will immediately see updates made by {@link LabelScanWriter}, although {@link LabelScanWriter} * may internally batch updates so functionality isn't reliable. The only given is that readers will * see at least updates from closed {@link LabelScanWriter writers}. */ @Override public LabelScanReader newReader() { return new NativeLabelScanReader( index ); }
@Test public void shouldCloseUnexhaustedCursorsOnReaderClose() throws Exception { // GIVEN GBPTree<LabelScanKey,LabelScanValue> index = mock( GBPTree.class ); RawCursor<Hit<LabelScanKey,LabelScanValue>,IOException> cursor1 = mock( RawCursor.class ); when( cursor1.next() ).thenReturn( false ); RawCursor<Hit<LabelScanKey,LabelScanValue>,IOException> cursor2 = mock( RawCursor.class ); when( cursor2.next() ).thenReturn( false ); when( index.seek( any( LabelScanKey.class ), any( LabelScanKey.class ) ) ).thenReturn( cursor1, cursor2 ); // WHEN try ( NativeLabelScanReader reader = new NativeLabelScanReader( index ) ) { // first check test invariants reader.nodesWithLabel( LABEL_ID ); reader.nodesWithLabel( LABEL_ID ); verify( cursor1, never() ).close(); verify( cursor2, never() ).close(); } // THEN verify( cursor1, times( 1 ) ).close(); verify( cursor2, times( 1 ) ).close(); }
try ( NativeLabelScanReader reader = new NativeLabelScanReader( index ) )
/** * @return {@link LabelScanReader} capable of finding node ids with given label ids. * Readers will immediately see updates made by {@link LabelScanWriter}, although {@link LabelScanWriter} * may internally batch updates so functionality isn't reliable. The only given is that readers will * see at least updates from closed {@link LabelScanWriter writers}. */ @Override public LabelScanReader newReader() { return new NativeLabelScanReader( index ); }