private List<LuceneWork> extractFailedWorks(ErrorContext errorContext) { List<LuceneWork> failingOperations = errorContext.getFailingOperations(); LuceneWork operationAtFault = errorContext.getOperationAtFault(); List<LuceneWork> failed = new ArrayList<>(failingOperations); failed.add(operationAtFault); return failed; }
private List<LuceneWork> extractFailedWorks(ErrorContext errorContext) { List<LuceneWork> failingOperations = errorContext.getFailingOperations(); LuceneWork operationAtFault = errorContext.getOperationAtFault(); List<LuceneWork> failed = new ArrayList<>(failingOperations); failed.add(operationAtFault); return failed; }
@Override public void handle(ErrorContext context) { final List<LuceneWork> failingOperations = context.getFailingOperations(); final LuceneWork primaryFailure = context.getOperationAtFault(); final Throwable exceptionThatOccurred = context.getThrowable(); final StringBuilder errorMsg = new StringBuilder(); if ( exceptionThatOccurred != null ) { errorMsg.append( "Exception occurred " ) .append( exceptionThatOccurred ) .append( "\n" ); } if ( primaryFailure != null ) { errorMsg.append( "Primary Failure:\n" ); appendFailureMessage( errorMsg, primaryFailure ); } if ( ! failingOperations.isEmpty() ) { errorMsg.append( "Subsequent failures:\n" ); for ( LuceneWork workThatFailed : failingOperations ) { appendFailureMessage( errorMsg, workThatFailed ); } } handleException( errorMsg.toString(), exceptionThatOccurred ); }
@Override public void handle(ErrorContext context) { final List<LuceneWork> failingOperations = context.getFailingOperations(); final LuceneWork primaryFailure = context.getOperationAtFault(); final Throwable exceptionThatOccurred = context.getThrowable(); final StringBuilder errorMsg = new StringBuilder(); if ( exceptionThatOccurred != null ) { errorMsg.append( "Exception occurred " ) .append( exceptionThatOccurred ) .append( "\n" ); } if ( primaryFailure != null ) { errorMsg.append( "Primary Failure:\n" ); appendFailureMessage( errorMsg, primaryFailure ); } if ( ! failingOperations.isEmpty() ) { errorMsg.append( "Subsequent failures:\n" ); for ( LuceneWork workThatFailed : failingOperations ) { appendFailureMessage( errorMsg, workThatFailed ); } } handleException( errorMsg.toString(), exceptionThatOccurred ); }
@Test public void multipleErrors_works() { Capture<ErrorContext> capture = newCapture(); replay(); DefaultContextualErrorHandler handler = new DefaultContextualErrorHandler( errorHandlerMock ); verify(); Throwable throwable1 = new Throwable(); Throwable throwable2 = new Throwable(); reset(); expect( work1.getLuceneWork() ).andReturn( luceneWork1 ); expect( work2.getLuceneWork() ).andReturn( luceneWork2 ); expect( work3.getLuceneWork() ).andReturn( luceneWork3 ); replay(); handler.markAsFailed( work1, throwable1 ); handler.markAsFailed( work2, throwable2 ); handler.markAsSkipped( work3 ); verify(); reset(); errorHandlerMock.handle( capture( capture ) ); replay(); handler.handle(); verify(); ErrorContext errorContext = capture.getValue(); assertThat( errorContext.getThrowable() ).isSameAs( throwable1 ); assertThat( throwable1.getSuppressed() ).containsExactlyInAnyOrder( throwable2 ); assertThat( errorContext.getOperationAtFault() ).isIn( luceneWork1, luceneWork2 ); assertThat( errorContext.getFailingOperations() ).containsExactlyInAnyOrder( luceneWork1, luceneWork2, luceneWork3 ); }
@Test public void singleError() { Capture<ErrorContext> capture = newCapture(); replay(); DefaultContextualErrorHandler handler = new DefaultContextualErrorHandler( errorHandlerMock ); verify(); Throwable throwable = new Throwable(); reset(); expect( work1.getLuceneWork() ).andReturn( luceneWork1 ); expect( work2.getLuceneWork() ).andReturn( luceneWork2 ); expect( work3.getLuceneWork() ).andReturn( luceneWork3 ); replay(); handler.markAsFailed( work1, throwable ); handler.markAsSkipped( work2 ); handler.markAsSkipped( work3 ); verify(); reset(); errorHandlerMock.handle( capture( capture ) ); replay(); handler.handle(); verify(); ErrorContext errorContext = capture.getValue(); assertThat( errorContext.getThrowable() ).isSameAs( throwable ); assertThat( errorContext.getOperationAtFault() ).isSameAs( luceneWork1 ); assertThat( errorContext.getFailingOperations() ).containsExactlyInAnyOrder( luceneWork1, luceneWork2, luceneWork3 ); }
assertThat( errorContext.getThrowable() ).isSameAs( throwable ); assertThat( errorContext.getOperationAtFault() ).isNull(); assertThat( errorContext.getFailingOperations() ).containsExactlyInAnyOrder( luceneWork1, luceneWork2, luceneWork3 );
assertThat( throwable1.getSuppressed() ).containsExactlyInAnyOrder( throwable2 ); assertThat( errorContext.getOperationAtFault() ).isSameAs( luceneWork1 ); assertThat( errorContext.getFailingOperations() ).containsExactlyInAnyOrder( luceneWork1, luceneWork2, luceneWork3 );