### Question:
OnlineIndexSamplingJob implements IndexSamplingJob { @Override public void run() { try ( DurationLogger durationLogger = new DurationLogger( log, "Sampling index " + indexUserDescription ) ) { try { try ( IndexReader reader = indexProxy.newReader(); IndexSampler sampler = reader.createSampler() ) { IndexSample sample = sampler.sampleIndex(); if ( indexProxy.getState() == ONLINE ) { storeView.replaceIndexCounts( indexId, sample.uniqueValues(), sample.sampleSize(), sample.indexSize() ); durationLogger.markAsFinished(); log.debug( format( "Sampled index %s with %d unique values in sample of avg size %d taken from " + "index containing %d entries", indexUserDescription, sample.uniqueValues(), sample.sampleSize(), sample.indexSize() ) ); } else { durationLogger.markAsAborted( "Index no longer ONLINE" ); } } } catch ( IndexNotFoundKernelException e ) { durationLogger.markAsAborted( "Attempted to sample missing/already deleted index " + indexUserDescription ); } } } OnlineIndexSamplingJob( long indexId, IndexProxy indexProxy, IndexStoreView storeView, String indexUserDescription,
            LogProvider logProvider ); @Override long indexId(); @Override void run();  }### Answer:
@Test public void shouldSampleTheIndexAndStoreTheValueWhenTheIndexIsOnline() { OnlineIndexSamplingJob job = new OnlineIndexSamplingJob( indexId, indexProxy, indexStoreView, "Foo", logProvider ); when( indexProxy.getState() ).thenReturn( ONLINE ); job.run(); verify( indexStoreView ).replaceIndexCounts( indexId, indexUniqueValues, indexSize, indexSize ); verifyNoMoreInteractions( indexStoreView ); }
@Test public void shouldSampleTheIndexButDoNotStoreTheValuesIfTheIndexIsNotOnline() { OnlineIndexSamplingJob job = new OnlineIndexSamplingJob( indexId, indexProxy, indexStoreView, "Foo", logProvider ); when( indexProxy.getState() ).thenReturn( FAILED ); job.run(); verifyNoMoreInteractions( indexStoreView ); }