ElasticsearchExceptionHandler { public <T extends Throwable> void handleDeleteDocumentException(T t) throws T { if (isIndexNotFound(t)) { if (_log.isInfoEnabled()) { _log.info(t, t); } } else { logOrThrow(t); } } ElasticsearchExceptionHandler(Log log, boolean logExceptionsOnly); void handleDeleteDocumentException(T t); void logOrThrow(T t);  }
@Test public void testDeleteIndexNotFoundLogExceptionsOnlyFalse() throws Throwable { expectedLogTestRule.configure( ElasticsearchExceptionHandlerTest.class, Level.INFO); expectedLogTestRule.expectMessage( ElasticsearchExceptionHandler.INDEX_NOT_FOUND_EXCEPTION_MESSAGE); ElasticsearchExceptionHandler elasticsearchExceptionHandler = new ElasticsearchExceptionHandler(_log, false); elasticsearchExceptionHandler.handleDeleteDocumentException( new SearchException( ElasticsearchExceptionHandler. INDEX_NOT_FOUND_EXCEPTION_MESSAGE)); }
@Test public void testDeleteIndexNotFoundLogExceptionsOnlyTrue() throws Throwable { expectedLogTestRule.configure( ElasticsearchExceptionHandlerTest.class, Level.INFO); expectedLogTestRule.expectMessage( ElasticsearchExceptionHandler.INDEX_NOT_FOUND_EXCEPTION_MESSAGE); ElasticsearchExceptionHandler elasticsearchExceptionHandler = new ElasticsearchExceptionHandler(_log, true); elasticsearchExceptionHandler.handleDeleteDocumentException( new SearchException( ElasticsearchExceptionHandler. INDEX_NOT_FOUND_EXCEPTION_MESSAGE)); }
@Test public void testDeleteLogExceptionsOnlyFalse() throws Throwable { expectedException.expect(SearchException.class); expectedException.expectMessage( "deletion failed and results in exception"); ElasticsearchExceptionHandler elasticsearchExceptionHandler = new ElasticsearchExceptionHandler(_log, false); elasticsearchExceptionHandler.handleDeleteDocumentException( new SearchException("deletion failed and results in exception")); }
@Test public void testDeleteLogExceptionsOnlyTrue() throws Throwable { expectedLogTestRule.expectMessage("deletion failed is only logged"); ElasticsearchExceptionHandler elasticsearchExceptionHandler = new ElasticsearchExceptionHandler(_log, true); elasticsearchExceptionHandler.handleDeleteDocumentException( new SearchException("deletion failed is only logged")); }