Skip to content

Commit

Permalink
HSEARCH-3460 Test refresh failure during mass indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
yrodiere committed Feb 17, 2020
1 parent 6055263 commit ebe841c
Showing 1 changed file with 72 additions and 0 deletions.
Expand Up @@ -267,6 +267,30 @@ public void flush() {
assertMassIndexerOperationFailureHandling( exceptionMessage, failingOperationAsString );
}

@Test
public void refresh() {
SessionFactory sessionFactory = setup();

String exceptionMessage = "REFRESH failure";
String failingOperationAsString = "MassIndexer operation";

expectMassIndexerOperationFailureHandling( exceptionMessage, failingOperationAsString );

doMassIndexingWithFailure(
Search.mapping( sessionFactory ).scope( Object.class ).massIndexer(),
ThreadExpectation.CREATED_AND_TERMINATED,
throwable -> assertThat( throwable ).isInstanceOf( SimulatedFailure.class )
.hasMessageContaining( exceptionMessage ),
expectIndexScopeWork( StubIndexScopeWork.Type.PURGE, ExecutionExpectation.SUCCEED ),
expectIndexScopeWork( StubIndexScopeWork.Type.MERGE_SEGMENTS, ExecutionExpectation.SUCCEED ),
expectIndexingWorks( ExecutionExpectation.SUCCEED ),
expectIndexScopeWork( StubIndexScopeWork.Type.FLUSH, ExecutionExpectation.SUCCEED ),
expectIndexScopeWork( StubIndexScopeWork.Type.REFRESH, ExecutionExpectation.FAIL )
);

assertMassIndexerOperationFailureHandling( exceptionMessage, failingOperationAsString );
}

@Test
public void indexingAndFlush() {
SessionFactory sessionFactory = setup();
Expand Down Expand Up @@ -314,6 +338,54 @@ public void indexingAndFlush() {
);
}

@Test
public void indexingAndRefresh() {
SessionFactory sessionFactory = setup();

String entityName = Book.NAME;
String entityReferenceAsString = Book.NAME + "#2";
String failingEntityIndexingExceptionMessage = "Indexing failure";
String failingEntityIndexingOperationAsString = "Indexing instance of entity '" + entityName + "' during mass indexing";
String failingMassIndexerOperationExceptionMessage = "REFRESH failure";
String failingMassIndexerOperationAsString = "MassIndexer operation";

expectEntityIndexingAndMassIndexerOperationFailureHandling(
entityName, entityReferenceAsString,
failingEntityIndexingExceptionMessage, failingEntityIndexingOperationAsString,
failingMassIndexerOperationExceptionMessage, failingMassIndexerOperationAsString
);

doMassIndexingWithFailure(
Search.mapping( sessionFactory ).scope( Object.class ).massIndexer(),
ThreadExpectation.CREATED_AND_TERMINATED,
throwable -> assertThat( throwable ).isInstanceOf( SimulatedFailure.class )
.hasMessageContaining( failingMassIndexerOperationExceptionMessage )
// Indexing failure should also be mentioned as a suppressed exception
.extracting( Throwable::getSuppressed ).asInstanceOf( InstanceOfAssertFactories.ARRAY )
.anySatisfy( suppressed -> assertThat( suppressed ).asInstanceOf( InstanceOfAssertFactories.THROWABLE )
.isInstanceOf( SearchException.class )
.hasMessageContainingAll(
"1 entities could not be indexed",
"See the logs for details.",
"First failure on entity 'Book#2': ",
failingEntityIndexingExceptionMessage
)
.hasCauseInstanceOf( SimulatedFailure.class )
),
expectIndexScopeWork( StubIndexScopeWork.Type.PURGE, ExecutionExpectation.SUCCEED ),
expectIndexScopeWork( StubIndexScopeWork.Type.MERGE_SEGMENTS, ExecutionExpectation.SUCCEED ),
expectIndexingWorks( ExecutionExpectation.FAIL ),
expectIndexScopeWork( StubIndexScopeWork.Type.FLUSH, ExecutionExpectation.SUCCEED ),
expectIndexScopeWork( StubIndexScopeWork.Type.REFRESH, ExecutionExpectation.FAIL )
);

assertEntityIndexingAndMassIndexerOperationFailureHandling(
entityName, entityReferenceAsString,
failingEntityIndexingExceptionMessage, failingEntityIndexingOperationAsString,
failingMassIndexerOperationExceptionMessage, failingMassIndexerOperationAsString
);
}

protected abstract String getBackgroundFailureHandlerReference();

protected abstract MassIndexingFailureHandler getMassIndexingFailureHandler();
Expand Down

0 comments on commit ebe841c

Please sign in to comment.