@Override public IndexSampler createSampler() { return delegate.createSampler(); }
@Override public IndexSampler createSampler() { return actual.createSampler(); }
@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 ) ); } }
IndexSampler sampler = reader.createSampler(); 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() ); } }
assertEquals( affectedNodes, nodes.length ); IndexSampler indexSampler = indexReader.createSampler(); IndexSample sample = indexSampler.sampleIndex(); assertEquals( affectedNodes, sample.indexSize() );
IndexSampler sampler = reader.createSampler(); IndexSample sample = sampler.sampleIndex();