### Question:
Indexes { public static void awaitResampling( SchemaRead schemaRead, long timeout ) throws TimeoutException { final Iterator<IndexReference> indexes = schemaRead.indexesGetAll(); final Register.DoubleLongRegister register = Registers.newDoubleLongRegister(); final long t0 = System.currentTimeMillis(); final long timeoutMillis = 1000 * timeout; while ( indexes.hasNext() ) { final IndexReference index = indexes.next(); try { long readUpdates = readUpdates( index, schemaRead, register ); long updateCount = readUpdates; boolean hasTimedOut = false; while ( updateCount > 0 && updateCount <= readUpdates && !hasTimedOut ) { Thread.sleep( 10 ); hasTimedOut = System.currentTimeMillis() - t0 >= timeoutMillis; updateCount = Math.max( updateCount, readUpdates ); readUpdates = readUpdates( index, schemaRead, register ); } if ( hasTimedOut ) { throw new TimeoutException( String.format( "Indexes were not resampled within %s %s", timeout, TimeUnit.SECONDS ) ); } } catch ( InterruptedException e ) { Thread.currentThread().interrupt(); throw new RuntimeException( e ); } catch ( IndexNotFoundKernelException e ) { throw new ConcurrentModificationException( "Index was dropped while awaiting resampling", e ); } } }  static void awaitResampling( SchemaRead schemaRead, long timeout );  }### Answer:
@Test public void shouldNotTimeOutIfNoIndexes() throws Throwable { final SchemaRead schemaRead = schemaWithIndexes(); Indexes.awaitResampling( schemaRead, 0 ); }
@Test public void shouldNotTimeOutIfNoUpdates() throws Throwable { IndexReference index = mock( IndexReference.class ); final SchemaRead schemaRead = schemaWithIndexes( index ); setUpdates( schemaRead, 0 ); Indexes.awaitResampling( schemaRead, 0 ); }
@Test public void shouldAwaitIndexResampling() throws Throwable { IndexReference index = mock( IndexReference.class ); final SchemaRead schemaRead = schemaWithIndexes( index ); setUpdates( schemaRead, 1, 2, 3, 0 ); Indexes.awaitResampling( schemaRead, 60 ); }
@Test public void shouldAwaitIndexResamplingForHeavyLoad() throws Throwable { IndexReference index = mock( IndexReference.class ); final SchemaRead schemaRead = schemaWithIndexes( index ); setUpdates( schemaRead, 1, 2, 3, 2 ); Indexes.awaitResampling( schemaRead, 60 ); }
@Test public void shouldTimeout() throws Throwable { IndexReference index = mock( IndexReference.class ); final SchemaRead schemaRead = schemaWithIndexes( index ); setUpdates( schemaRead, 1, 1, 1 ); exception.expect( TimeoutException.class ); Indexes.awaitResampling( schemaRead, 1 ); }