Skip to content

Commit

Permalink
Include index information when throwing index population failure
Browse files Browse the repository at this point in the history
  • Loading branch information
burqen committed Mar 11, 2019
1 parent 53f28b2 commit 6f703c8
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
Expand Up @@ -48,13 +48,15 @@ void includeCauseOfFailure() throws IndexNotFoundKernelException
{ {
// given // given
IndexDefinitionImpl indexDefinition = mockIndexDefinition(); IndexDefinitionImpl indexDefinition = mockIndexDefinition();
when( indexDefinition.toString() ).thenReturn( "IndexDefinition( of-some-sort )" );
KernelTransaction kernelTransaction = mockKernelTransaction(); KernelTransaction kernelTransaction = mockKernelTransaction();
SchemaImpl schema = new SchemaImpl( () -> kernelTransaction ); SchemaImpl schema = new SchemaImpl( () -> kernelTransaction );


// when // when
IllegalStateException e = assertThrows( IllegalStateException.class, () -> schema.awaitIndexOnline( indexDefinition, 1, TimeUnit.MINUTES ) ); IllegalStateException e = assertThrows( IllegalStateException.class, () -> schema.awaitIndexOnline( indexDefinition, 1, TimeUnit.MINUTES ) );


// then // then
assertThat( e.getMessage(), Matchers.containsString( indexDefinition.toString() ) );
assertThat( e.getMessage(), Matchers.containsString( Exceptions.stringify( cause ) ) ); assertThat( e.getMessage(), Matchers.containsString( Exceptions.stringify( cause ) ) );
} }


Expand Down
Expand Up @@ -422,7 +422,8 @@ private void awaitOnline( IndexProxy proxy )
return; return;
case FAILED: case FAILED:
IndexPopulationFailure populationFailure = proxy.getPopulationFailure(); IndexPopulationFailure populationFailure = proxy.getPopulationFailure();
String message = String.format( "Index entered %s state while recovery waited for it to be fully populated.", FAILED ); String message =
String.format( "Index entered %s state while recovery waited for it to be fully populated. Index: %s.", FAILED, proxy.getDescriptor() );
String causeOfFailure = populationFailure.asString(); String causeOfFailure = populationFailure.asString();
throw new IllegalStateException( IndexPopulationFailure.appendCauseOfFailure( message, causeOfFailure ) ); throw new IllegalStateException( IndexPopulationFailure.appendCauseOfFailure( message, causeOfFailure ) );
case POPULATING: case POPULATING:
Expand Down
Expand Up @@ -203,7 +203,8 @@ public void awaitIndexOnline( IndexDefinition index, long duration, TimeUnit uni
return; return;
case FAILED: case FAILED:
String cause = getIndexFailure( index ); String cause = getIndexFailure( index );
String message = IndexPopulationFailure.appendCauseOfFailure( "Index entered a FAILED state. Please see database logs.", cause ); String message = IndexPopulationFailure
.appendCauseOfFailure( String.format( "Index entered a %s state. Please see database logs. Index: %s", state, index ), cause );
throw new IllegalStateException( message ); throw new IllegalStateException( message );
default: default:
try try
Expand Down
Expand Up @@ -157,6 +157,7 @@ public void shouldThrowAnExceptionIfTheIndexHasFailed() throws IndexNotFoundKern
catch ( ProcedureException e ) catch ( ProcedureException e )
{ {
assertThat( e.status(), is( Status.Schema.IndexCreationFailed ) ); assertThat( e.status(), is( Status.Schema.IndexCreationFailed ) );
assertThat( e.getMessage(), containsString( ":Person(name)" ) );
assertThat( e.getMessage(), containsString( "Kilroy was here" ) ); assertThat( e.getMessage(), containsString( "Kilroy was here" ) );
} }
} }
Expand Down
Expand Up @@ -1080,7 +1080,7 @@ public void shouldReportCauseOfPopulationFailureIfPopulationFailsDuringRecovery(
{ {
// given // given
long indexId = 1; long indexId = 1;
StoreIndexDescriptor indexRule = uniqueIndex.withId( indexId ); CapableIndexDescriptor indexRule = uniqueIndex.withId( indexId ).withoutCapabilities();
Barrier.Control barrier = new Barrier.Control(); Barrier.Control barrier = new Barrier.Control();
CountDownLatch exceptionBarrier = new CountDownLatch( 1 ); CountDownLatch exceptionBarrier = new CountDownLatch( 1 );
IndexingService indexing = newIndexingServiceWithMockedDependencies( populator, accessor, withData(), new IndexingService.MonitorAdapter() IndexingService indexing = newIndexingServiceWithMockedDependencies( populator, accessor, withData(), new IndexingService.MonitorAdapter()
Expand Down Expand Up @@ -1123,12 +1123,13 @@ public void awaitingPopulationOfRecoveredIndex( StoreIndexDescriptor descriptor
FlippableIndexProxy flippableIndexProxy = (FlippableIndexProxy) delegate; FlippableIndexProxy flippableIndexProxy = (FlippableIndexProxy) delegate;
Exception expectedCause = new Exception( "index was failed on purpose" ); Exception expectedCause = new Exception( "index was failed on purpose" );
IndexPopulationFailure indexFailure = IndexPopulationFailure.failure( expectedCause ); IndexPopulationFailure indexFailure = IndexPopulationFailure.failure( expectedCause );
flippableIndexProxy.flipTo( new FailedIndexProxy( mock( CapableIndexDescriptor.class ), "string", mock( IndexPopulator.class ), flippableIndexProxy.flipTo( new FailedIndexProxy( indexRule, "string", mock( IndexPopulator.class ),
indexFailure, mock( IndexCountsRemover.class ), internalLogProvider ) ); indexFailure, mock( IndexCountsRemover.class ), internalLogProvider ) );
barrier.release(); barrier.release();
exceptionBarrier.await(); exceptionBarrier.await();
Throwable actual = startException.get(); Throwable actual = startException.get();


assertThat( actual.getMessage(), Matchers.containsString( indexRule.toString() ) );
assertThat( actual.getCause(), instanceOf( IllegalStateException.class ) ); assertThat( actual.getCause(), instanceOf( IllegalStateException.class ) );
assertThat( Exceptions.stringify( actual.getCause() ), Matchers.containsString( Exceptions.stringify( expectedCause ) ) ); assertThat( Exceptions.stringify( actual.getCause() ), Matchers.containsString( Exceptions.stringify( expectedCause ) ) );
} }
Expand Down

0 comments on commit 6f703c8

Please sign in to comment.