@Test public void shouldKeepFailedIndexesAsFailedAfterRestart() throws Exception { // Given IndexPopulator indexPopulator = mock( IndexPopulator.class ); when( mockedIndexProvider.getPopulator( any( StoreIndexDescriptor.class ), any( IndexSamplingConfig.class ) ) ) .thenReturn( indexPopulator ); IndexAccessor indexAccessor = mock( IndexAccessor.class ); when( mockedIndexProvider.getOnlineAccessor( any( StoreIndexDescriptor.class ), any( IndexSamplingConfig.class ) ) ) .thenReturn( indexAccessor ); startDb(); createIndex( myLabel ); rotateLogsAndCheckPoint(); // And Given killDb(); when( mockedIndexProvider.getInitialState( any( StoreIndexDescriptor.class ) ) ) .thenReturn( InternalIndexState.FAILED ); // When startDb(); // Then assertThat( getIndexes( db, myLabel ), inTx( db, hasSize( 1 ) ) ); assertThat( getIndexes( db, myLabel ), inTx( db, haveState( db, Schema.IndexState.FAILED ) ) ); verify( mockedIndexProvider, times( 2 ) ) .getPopulator( any( StoreIndexDescriptor.class ), any( IndexSamplingConfig.class ) ); }
assertThat( getIndexes( db, myLabel ), inTx( db, hasSize( 1 ) ) ); assertThat( getIndexes( db, myLabel ), inTx( db, haveState( db, Schema.IndexState.POPULATING ) ) ); verify( mockedIndexProvider, times( 2 ) )
assertThat( getIndexes( db, myLabel ), inTx( db, hasSize( 1 ) ) ); assertThat( getIndexes( db, myLabel ), inTx( db, haveState( db, Schema.IndexState.POPULATING ) ) ); verify( mockedIndexProvider, times( 2 ) )
assertThat( getIndexes( db, myLabel ), inTx( db, hasSize( 1 ) ) ); assertThat( getIndexes( db, myLabel ), inTx( db, haveState( db, Schema.IndexState.ONLINE ) ) ); verify( mockedIndexProvider, times( 1 ) )
@Test public void shouldBeAbleToDropIndexWhileItIsPopulating() { // GIVEN startDb(); DoubleLatch populationCompletionLatch = provider.installPopulationJobCompletionLatch(); IndexDefinition index = createIndex(); populationCompletionLatch.waitForAllToStart(); // await population job to start // WHEN dropIndex( index, populationCompletionLatch ); // THEN assertThat( getIndexes( db, myLabel ), inTx( db, hasSize( 0 ) ) ); try { getIndexState( db, index ); fail( "This index should have been deleted" ); } catch ( NotFoundException e ) { assertThat( e.getMessage(), CoreMatchers.containsString( myLabel.name() ) ); } }