private IndexSample sampleIndex( IndexSampler sampler ) { try { return sampler.sampleIndex(); } catch ( IndexNotFoundKernelException e ) { throw new RuntimeException( e ); } }
@Override public IndexSample sampleIndex() throws IndexNotFoundKernelException { List<IndexSample> samples = new ArrayList<>(); Exception exception = null; for ( IndexSampler sampler : samplers ) { try { samples.add( sampler.sampleIndex() ); } catch ( IndexNotFoundKernelException | RuntimeException e ) { exception = Exceptions.chain( exception, e ); } } if ( exception != null ) { Exceptions.throwIfUnchecked( exception ); throw (IndexNotFoundKernelException)exception; } return combineSamples( samples ); }
@Before public void setup() throws IndexNotFoundKernelException { when( indexProxy.getDescriptor() ).thenReturn( indexDescriptor ); when( indexProxy.newReader() ).thenReturn( indexReader ); when( indexReader.createSampler() ).thenReturn( indexSampler ); when( indexSampler.sampleIndex() ).thenReturn( new IndexSample( indexSize, indexUniqueValues, indexSize ) ); } }
@Test public void samplingOverPartitions() throws IndexNotFoundKernelException { PartitionedIndexReader indexReader = createPartitionedReaderFromReaders(); when( indexReader1.createSampler() ).thenReturn( new SimpleSampler( 1 ) ); when( indexReader2.createSampler() ).thenReturn( new SimpleSampler( 2 ) ); when( indexReader3.createSampler() ).thenReturn( new SimpleSampler( 3 ) ); IndexSampler sampler = indexReader.createSampler(); assertEquals( new IndexSample( 6, 6, 6 ), sampler.sampleIndex() ); }
IndexSample sample = sampler.sampleIndex();
@Test public void shouldStopSamplingWhenIndexIsDropped() throws Exception { // given updateAndCommit( asList( add( nodeId, value ), add( nodeId2, value2 ) ) ); // when IndexReader indexReader = accessor.newReader(); // needs to be acquired before drop() is called IndexSampler indexSampler = indexReader.createSampler(); Future<Void> drop = threading.executeAndAwait( (IOFunction<Void,Void>) nothing -> { accessor.drop(); return nothing; }, null, waitingWhileIn( TaskCoordinator.class, "awaitCompletion" ), 3, SECONDS ); try ( IndexReader reader = indexReader /* do not inline! */ ) { indexSampler.sampleIndex(); fail( "expected exception" ); } catch ( IndexNotFoundKernelException e ) { assertEquals( "Index dropped while sampling.", e.getMessage() ); } finally { drop.get(); } }
@Test public void shouldStopSamplingWhenIndexIsDropped() throws Exception { // given updateAndCommit( asList( add( nodeId, values ), add( nodeId2, values2 ) ) ); // when IndexReader indexReader = accessor.newReader(); // needs to be acquired before drop() is called IndexSampler indexSampler = indexReader.createSampler(); Future<Void> drop = threading.executeAndAwait( (IOFunction<Void,Void>) nothing -> { accessor.drop(); return nothing; }, null, waitingWhileIn( TaskCoordinator.class, "awaitCompletion" ), 3, SECONDS ); try ( IndexReader reader = indexReader /* do not inline! */ ) { indexSampler.sampleIndex(); fail( "expected exception" ); } catch ( IndexNotFoundKernelException e ) { assertEquals( "Index dropped while sampling.", e.getMessage() ); } finally { drop.get(); } }
@Test public void shouldSampleIndex() throws Exception { // given IndexEntryUpdate<IndexDescriptor>[] updates = someUpdatesSingleType(); processAll( updates ); try ( IndexReader reader = accessor.newReader() ) { IndexSampler sampler = reader.createSampler(); // when IndexSample sample = sampler.sampleIndex(); // then assertEquals( updates.length, sample.indexSize() ); assertEquals( updates.length, sample.sampleSize() ); assertEquals( countUniqueValues( updates ), sample.uniqueValues() ); } }
IndexSample sample = indexSampler.sampleIndex(); assertEquals( affectedNodes, sample.indexSize() ); assertEquals( affectedNodes, sample.uniqueValues() );
@Override public IndexSample sampleIndex() throws IndexNotFoundKernelException { List<IndexSample> samples = new ArrayList<>(); Exception exception = null; for ( IndexSampler sampler : samplers ) { try { samples.add( sampler.sampleIndex() ); } catch ( IndexNotFoundKernelException | RuntimeException e ) { exception = Exceptions.chain( exception, e ); } } if ( exception != null ) { Exceptions.throwIfUnchecked( exception ); throw (IndexNotFoundKernelException)exception; } return combineSamples( samples ); }
IndexSample sample = sampler.sampleIndex();