Repository: james-project
Updated Branches:
  refs/heads/master 21cde6d28 -> 07bc44463


MAILBOX-372 ListeningMessageSearchIndex should not catch exceptions


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/07bc4446
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/07bc4446
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/07bc4446

Branch: refs/heads/master
Commit: 07bc444631a8053af4a07fc7ec68b0ca30e746bd
Parents: a5870f5
Author: Benoit Tellier <[email protected]>
Authored: Wed Jan 16 11:45:29 2019 +0700
Committer: Benoit Tellier <[email protected]>
Committed: Thu Jan 17 18:01:13 2019 +0700

----------------------------------------------------------------------
 ...lasticSearchListeningMessageSearchIndex.java | 75 ++++++---------
 ...icSearchListeningMessageSearchIndexTest.java | 98 ++++++--------------
 .../lucene/search/LuceneMessageSearchIndex.java | 43 +++------
 .../store/search/LazyMessageSearchIndex.java    | 10 +-
 .../search/ListeningMessageSearchIndex.java     | 74 +++++----------
 .../tools/indexer/ReIndexerPerformer.java       |  2 +-
 .../indexer/SingleMailboxReindexingTask.java    |  3 +-
 7 files changed, 98 insertions(+), 207 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/07bc4446/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
----------------------------------------------------------------------
diff --git 
a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
 
b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
index 398e792..f0df750 100644
--- 
a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
+++ 
b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
@@ -25,7 +25,6 @@ import java.util.EnumSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Optional;
-import java.util.stream.Collectors;
 
 import javax.inject.Inject;
 import javax.inject.Named;
@@ -55,6 +54,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
+import com.github.fge.lambdas.Throwing;
 import com.github.steveash.guavate.Guavate;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
@@ -126,80 +126,61 @@ public class ElasticSearchListeningMessageSearchIndex 
extends ListeningMessageSe
     }
 
     @Override
-    public void add(MailboxSession session, Mailbox mailbox, MailboxMessage 
message) {
+    public void add(MailboxSession session, Mailbox mailbox, MailboxMessage 
message) throws JsonProcessingException {
+        LOGGER.info("Indexing mailbox {}-{} of user {} on message {}",
+            mailbox.getName(),
+            mailbox.getMailboxId(),
+            session.getUser().asString(),
+            message.getUid());
+
+        String jsonContent = generateIndexedJson(mailbox, message, session);
+        elasticSearchIndexer.index(indexIdFor(mailbox, message.getUid()), 
jsonContent);
+    }
+
+    private String generateIndexedJson(Mailbox mailbox, MailboxMessage 
message, MailboxSession session) throws JsonProcessingException {
         try {
-            LOGGER.info("Indexing mailbox {}-{} of user {} on message {}",
-                    mailbox.getName(),
-                    mailbox.getMailboxId(),
-                    session.getUser().asString(),
-                    message.getUid());
-            elasticSearchIndexer.index(indexIdFor(mailbox, message.getUid()), 
messageToElasticSearchJson.convertToJson(message, 
ImmutableList.of(session.getUser())));
+            return messageToElasticSearchJson.convertToJson(message, 
ImmutableList.of(session.getUser()));
         } catch (Exception e) {
-            try {
-                LOGGER.warn("Indexing mailbox {}-{} of user {} on message {} 
without attachments ",
-                        mailbox.getName(),
-                        mailbox.getMailboxId().serialize(),
-                        session.getUser().asString(),
-                        message.getUid(),
-                        e);
-                elasticSearchIndexer.index(indexIdFor(mailbox, 
message.getUid()), 
messageToElasticSearchJson.convertToJsonWithoutAttachment(message, 
ImmutableList.of(session.getUser())));
-            } catch (JsonProcessingException e1) {
-                LOGGER.error("Error when indexing mailbox {}-{} of user {} on 
message {} without its attachment",
-                        mailbox.getName(),
-                        mailbox.getMailboxId().serialize(),
-                        session.getUser().asString(),
-                        message.getUid(),
-                        e1);
-            }
+            LOGGER.warn("Indexing mailbox {}-{} of user {} on message {} 
without attachments ",
+                mailbox.getName(),
+                mailbox.getMailboxId().serialize(),
+                session.getUser().asString(),
+                message.getUid(),
+                e);
+            return 
messageToElasticSearchJson.convertToJsonWithoutAttachment(message, 
ImmutableList.of(session.getUser()));
         }
     }
-    
+
     @Override
     public void delete(MailboxSession session, Mailbox mailbox, 
Collection<MessageUid> expungedUids) {
-        try {
             elasticSearchIndexer.delete(expungedUids.stream()
                 .map(uid ->  indexIdFor(mailbox, uid))
-                .collect(Collectors.toList()));
-        } catch (Exception e) {
-            if (LOGGER.isErrorEnabled()) {
-                LOGGER.error("Error when deleting messages {} in mailbox {} 
from index", mailbox.getMailboxId().serialize(), expungedUids.toArray(), e);
-            }
-        }
+                .collect(Guavate.toImmutableList()));
     }
 
     @Override
     public void deleteAll(MailboxSession session, Mailbox mailbox) {
-        try {
             elasticSearchIndexer.deleteAllMatchingQuery(
                 termQuery(
                     JsonMessageConstants.MAILBOX_ID,
                     mailbox.getMailboxId().serialize()));
-        } catch (Exception e) {
-            LOGGER.error("Error when deleting all messages in mailbox {}", 
mailbox.getMailboxId().serialize(), e);
-        }
     }
 
     @Override
     public void update(MailboxSession session, Mailbox mailbox, 
List<UpdatedFlags> updatedFlagsList) {
-        try {
             elasticSearchIndexer.update(updatedFlagsList.stream()
-                .map(updatedFlags -> 
createUpdatedDocumentPartFromUpdatedFlags(mailbox, updatedFlags))
-                .collect(Collectors.toList()));
-        } catch (Exception e) {
-            LOGGER.error("Error when updating index on mailbox {}", 
mailbox.getMailboxId().serialize(), e);
-        }
+                .map(Throwing.<UpdatedFlags, UpdatedRepresentation>function(
+                    updatedFlags -> 
createUpdatedDocumentPartFromUpdatedFlags(mailbox, updatedFlags))
+                    .sneakyThrow())
+                .collect(Guavate.toImmutableList()));
     }
 
-    private UpdatedRepresentation 
createUpdatedDocumentPartFromUpdatedFlags(Mailbox mailbox, UpdatedFlags 
updatedFlags) {
-        try {
+    private UpdatedRepresentation 
createUpdatedDocumentPartFromUpdatedFlags(Mailbox mailbox, UpdatedFlags 
updatedFlags) throws JsonProcessingException {
             return new UpdatedRepresentation(
                 indexIdFor(mailbox, updatedFlags.getUid()),
                     messageToElasticSearchJson.getUpdatedJsonMessagePart(
                         updatedFlags.getNewFlags(),
                         updatedFlags.getModSeq()));
-        } catch (JsonProcessingException e) {
-            throw new RuntimeException("Error while creating 
updatedDocumentParts", e);
-        }
     }
 
     private String indexIdFor(Mailbox mailbox, MessageUid uid) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/07bc4446/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
 
b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
index de5f599..0dc602f 100644
--- 
a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
+++ 
b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
@@ -18,7 +18,9 @@
  ****************************************************************/
 package org.apache.james.mailbox.elasticsearch.events;
 
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.ArgumentMatchers.refEq;
 import static org.mockito.Mockito.doThrow;
@@ -71,7 +73,8 @@ public class ElasticSearchListeningMessageSearchIndexTest {
     private ElasticSearchListeningMessageSearchIndex testee;
     private MailboxSession session;
     private List<User> users;
-    
+    private Mailbox mailbox;
+
     @Before
     public void setup() {
         MailboxSessionMapperFactory mapperFactory = 
mock(MailboxSessionMapperFactory.class);
@@ -85,14 +88,14 @@ public class ElasticSearchListeningMessageSearchIndexTest {
             messageToElasticSearchJson, mockSessionProvider);
         session = MailboxSessionUtil.create(USERNAME);
         users = ImmutableList.of(User.fromUsername(USERNAME));
+
+        mailbox = mock(Mailbox.class);
+        when(mailbox.getMailboxId()).thenReturn(MAILBOX_ID);
     }
     
     @Test
     public void addShouldIndex() throws Exception {
         //Given
-        Mailbox mailbox = mock(Mailbox.class);
-        when(mailbox.getMailboxId())
-            .thenReturn(MAILBOX_ID);
         MailboxMessage message = mockedMessage(MESSAGE_UID);
         
         when(messageToElasticSearchJson.convertToJson(eq(message), eq(users)))
@@ -108,10 +111,6 @@ public class ElasticSearchListeningMessageSearchIndexTest {
     @Test
     public void addShouldIndexEmailBodyWhenNotIndexableAttachment() throws 
Exception {
         //Given
-        Mailbox mailbox = mock(Mailbox.class);
-        when(mailbox.getMailboxId())
-            .thenReturn(MAILBOX_ID);
-        
         MailboxMessage message = mockedMessage(MESSAGE_UID);
         
         when(messageToElasticSearchJson.convertToJson(eq(message), eq(users)))
@@ -127,43 +126,33 @@ public class ElasticSearchListeningMessageSearchIndexTest 
{
         verify(elasticSearchIndexer).index(eq(ELASTIC_SEARCH_ID), 
eq(EXPECTED_JSON_CONTENT));
     }
 
-    private MailboxMessage mockedMessage(MessageUid messageId) {
+    private MailboxMessage mockedMessage(MessageUid uid) {
         MailboxMessage message = mock(MailboxMessage.class);
-        when(message.getUid())
-            .thenReturn(messageId);
+        when(message.getUid()).thenReturn(uid);
         return message;
     }
 
     @Test
-    public void addShouldNotPropagateExceptionWhenExceptionOccurs() throws 
Exception {
+    public void addShouldPropagateExceptionWhenExceptionOccurs() throws 
Exception {
         //Given
-        Mailbox mailbox = mock(Mailbox.class);
-        when(mailbox.getMailboxId())
-            .thenReturn(MAILBOX_ID);
         MailboxMessage message = mockedMessage(MESSAGE_UID);
         
         when(messageToElasticSearchJson.convertToJson(eq(message), eq(users)))
             .thenThrow(JsonProcessingException.class);
 
+        // When
         JsonGenerator jsonGenerator = null;
         
when(messageToElasticSearchJson.convertToJsonWithoutAttachment(eq(message), 
eq(users)))
             .thenThrow(new JsonGenerationException("expected error", 
jsonGenerator));
         
-        //When
-        testee.add(session, mailbox, message);
-        
         //Then
-        //No exception
+        assertThatThrownBy(() -> testee.add(session, mailbox, 
message)).isInstanceOf(JsonGenerationException.class);
     }
 
     @Test
     @SuppressWarnings("unchecked")
-    public void deleteShouldWork() throws Exception {
+    public void deleteShouldWork() {
         //Given
-        Mailbox mailbox = mock(Mailbox.class);
-        when(mailbox.getMailboxId())
-            .thenReturn(MAILBOX_ID);
-
         BulkResponse expectedBulkResponse = mock(BulkResponse.class);
         when(elasticSearchIndexer.delete(any(List.class)))
             .thenReturn(Optional.of(expectedBulkResponse));
@@ -177,15 +166,12 @@ public class ElasticSearchListeningMessageSearchIndexTest 
{
 
     @Test
     @SuppressWarnings("unchecked")
-    public void deleteShouldWorkWhenMultipleMessageIds() throws Exception {
+    public void deleteShouldWorkWhenMultipleMessageIds() {
         //Given
-        Mailbox mailbox = mock(Mailbox.class);
         MessageUid messageId2 = MessageUid.of(2);
         MessageUid messageId3 = MessageUid.of(3);
         MessageUid messageId4 = MessageUid.of(4);
         MessageUid messageId5 = MessageUid.of(5);
-        when(mailbox.getMailboxId())
-            .thenReturn(MAILBOX_ID);
 
         BulkResponse expectedBulkResponse = mock(BulkResponse.class);
         when(elasticSearchIndexer.delete(any(List.class)))
@@ -200,26 +186,19 @@ public class ElasticSearchListeningMessageSearchIndexTest 
{
 
     @Test
     @SuppressWarnings("unchecked")
-    public void deleteShouldNotPropagateExceptionWhenExceptionOccurs() throws 
Exception {
+    public void deleteShouldPropagateExceptionWhenExceptionOccurs() {
         //Given
-        Mailbox mailbox = mock(Mailbox.class);
-        when(mailbox.getMailboxId())
-            .thenReturn(MAILBOX_ID);
-        
         when(elasticSearchIndexer.delete(any(List.class)))
             .thenThrow(new ElasticsearchException(""));
-        
-        //When
-        testee.delete(session, mailbox, Lists.newArrayList(MESSAGE_UID));
-        
-        //Then
-        //No exception
+
+        // Then
+        assertThatThrownBy(() -> testee.delete(session, mailbox, 
Lists.newArrayList(MESSAGE_UID)))
+            .isInstanceOf(ElasticsearchException.class);
     }
 
     @Test
     public void updateShouldWork() throws Exception {
         //Given
-        Mailbox mailbox = mock(Mailbox.class);
         Flags flags = new Flags();
 
         UpdatedFlags updatedFlags = UpdatedFlags.builder()
@@ -229,9 +208,6 @@ public class ElasticSearchListeningMessageSearchIndexTest {
             .newFlags(flags)
             .build();
 
-        when(mailbox.getMailboxId())
-            .thenReturn(MAILBOX_ID);
-
         
when(messageToElasticSearchJson.getUpdatedJsonMessagePart(any(Flags.class), 
any(Long.class)))
             .thenReturn("json updated content");
         
@@ -244,9 +220,8 @@ public class ElasticSearchListeningMessageSearchIndexTest {
     }
 
     @Test
-    public void updateShouldNotPropagateExceptionWhenExceptionOccurs() throws 
Exception {
+    public void updateShouldPropagateExceptionWhenExceptionOccurs() throws 
Exception {
         //Given
-        Mailbox mailbox = mock(Mailbox.class);
         Flags flags = new Flags();
         UpdatedFlags updatedFlags = UpdatedFlags.builder()
             .uid(MESSAGE_UID)
@@ -254,28 +229,18 @@ public class ElasticSearchListeningMessageSearchIndexTest 
{
             .oldFlags(flags)
             .newFlags(flags)
             .build();
-        when(mailbox.getMailboxId())
-            .thenReturn(MAILBOX_ID);
+        when(messageToElasticSearchJson.getUpdatedJsonMessagePart(any(), 
anyLong())).thenReturn("update doc");
 
-        ImmutableList<UpdatedRepresentation> expectedUpdatedRepresentations = 
ImmutableList.of(new UpdatedRepresentation(ELASTIC_SEARCH_ID, "json updated 
content"));
-        when(elasticSearchIndexer.update(expectedUpdatedRepresentations))
-            .thenThrow(new ElasticsearchException(""));
-        
         //When
-        testee.update(session, mailbox, Lists.newArrayList(updatedFlags));
+        when(elasticSearchIndexer.update(any())).thenThrow(new 
ElasticsearchException(""));
         
         //Then
-        //No exception
+        assertThatThrownBy(() -> testee.update(session, mailbox, 
Lists.newArrayList(updatedFlags))).isInstanceOf(ElasticsearchException.class);
     }
 
     @Test
-    public void deleteAllShouldWork() throws Exception {
+    public void deleteAllShouldWork() {
         //Given
-        Mailbox mailbox = mock(Mailbox.class);
-        when(mailbox.getMailboxId())
-            .thenReturn(MAILBOX_ID);
-
-        //When
         testee.deleteAll(session, mailbox);
         
         //Then
@@ -284,20 +249,13 @@ public class ElasticSearchListeningMessageSearchIndexTest 
{
     }
 
     @Test
-    public void deleteAllShouldNotPropagateExceptionWhenExceptionOccurs() 
throws Exception {
+    public void deleteAllShouldNotPropagateExceptionWhenExceptionOccurs() {
         //Given
-        Mailbox mailbox = mock(Mailbox.class);
-        when(mailbox.getMailboxId())
-            .thenReturn(MAILBOX_ID);
-   
         doThrow(RuntimeException.class)
-            
.when(elasticSearchIndexer).deleteAllMatchingQuery(QueryBuilders.termQuery("mailboxId",
 "12"));
+            .when(elasticSearchIndexer).deleteAllMatchingQuery(any());
 
-        //When
-        testee.deleteAll(session, mailbox);
-        
         //Then
-        //No Exception
+        assertThatThrownBy(() -> testee.deleteAll(session, 
mailbox)).isInstanceOf(RuntimeException.class);
     }
 
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/07bc4446/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
----------------------------------------------------------------------
diff --git 
a/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
 
b/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
index 6ede59f..4652e95 100644
--- 
a/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
+++ 
b/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
@@ -544,7 +544,7 @@ public class LuceneMessageSearchIndex extends 
ListeningMessageSearchIndex {
      * @param membership
      * @return document
      */
-    private Document createMessageDocument(final MailboxSession session, final 
MailboxMessage membership) throws MailboxException {
+    private Document createMessageDocument(final MailboxSession session, final 
MailboxMessage membership) throws IOException, MimeException {
         final Document doc = new Document();
         // TODO: Better handling
         doc.add(new Field(USERS, 
session.getUser().asString().toUpperCase(Locale.US), Store.YES, 
Index.NOT_ANALYZED));
@@ -738,14 +738,9 @@ public class LuceneMessageSearchIndex extends 
ListeningMessageSearchIndex {
         MimeStreamParser parser = new MimeStreamParser(MimeConfig.PERMISSIVE);
         parser.setContentDecoding(true);
         parser.setContentHandler(handler);
-       
-        try {
-            // parse the message to index headers and body
-            parser.parse(membership.getFullContent());
-        } catch (MimeException | IOException e) {
-            // This should never happen as it was parsed before too without 
problems.            
-            throw new MailboxException("Unable to index content of message", 
e);
-        }
+
+        // parse the message to index headers and body
+        parser.parse(membership.getFullContent());
 
 
         return doc;
@@ -1239,26 +1234,22 @@ public class LuceneMessageSearchIndex extends 
ListeningMessageSearchIndex {
     }
 
     @Override
-    public void add(MailboxSession session, Mailbox mailbox, MailboxMessage 
membership) throws MailboxException {
+    public void add(MailboxSession session, Mailbox mailbox, MailboxMessage 
membership) throws IOException, MimeException {
         Document doc = createMessageDocument(session, membership);
         Document flagsDoc = createFlagsDocument(membership);
 
-        try {
-            writer.addDocument(doc);
-            writer.addDocument(flagsDoc);
-        } catch (IOException e) {
-            throw new MailboxException("Unable to add message to index", e);
-        }
+        writer.addDocument(doc);
+        writer.addDocument(flagsDoc);
     }
 
     @Override
-    public void update(MailboxSession session, Mailbox mailbox, 
List<UpdatedFlags> updatedFlagsList) throws MailboxException {
+    public void update(MailboxSession session, Mailbox mailbox, 
List<UpdatedFlags> updatedFlagsList) throws IOException {
         for (UpdatedFlags updatedFlags : updatedFlagsList) {
             update(mailbox, updatedFlags.getUid(), updatedFlags.getNewFlags());
         }
     }
 
-    private void update(Mailbox mailbox, MessageUid uid, Flags f) throws 
MailboxException {
+    private void update(Mailbox mailbox, MessageUid uid, Flags f) throws 
IOException {
         try (IndexSearcher searcher = new 
IndexSearcher(IndexReader.open(writer, true))) {
             BooleanQuery query = new BooleanQuery();
             query.add(new TermQuery(new Term(MAILBOX_ID_FIELD, 
mailbox.getMailboxId().serialize())), BooleanClause.Occur.MUST);
@@ -1278,8 +1269,6 @@ public class LuceneMessageSearchIndex extends 
ListeningMessageSearchIndex {
 
                 }
             }
-        } catch (IOException e) {
-            throw new MailboxException("Unable to add messages in index", e);
         }
     }
 
@@ -1338,7 +1327,7 @@ public class LuceneMessageSearchIndex extends 
ListeningMessageSearchIndex {
     }
 
     @Override
-    public void delete(MailboxSession session, Mailbox mailbox, 
Collection<MessageUid> expungedUids) throws MailboxException {
+    public void delete(MailboxSession session, Mailbox mailbox, 
Collection<MessageUid> expungedUids) throws IOException {
         Collection<MessageRange> messageRanges = 
MessageRange.toRanges(expungedUids);
         for (MessageRange messageRange : messageRanges) {
             delete(mailbox, messageRange);
@@ -1346,20 +1335,16 @@ public class LuceneMessageSearchIndex extends 
ListeningMessageSearchIndex {
     }
 
     @Override
-    public void deleteAll(MailboxSession session, Mailbox mailbox) throws 
MailboxException {
+    public void deleteAll(MailboxSession session, Mailbox mailbox) throws 
IOException {
         delete(mailbox, MessageRange.all());
     }
 
-    public void delete(Mailbox mailbox, MessageRange range) throws 
MailboxException {
+    public void delete(Mailbox mailbox, MessageRange range) throws IOException 
{
         BooleanQuery query = new BooleanQuery();
         query.add(new TermQuery(new Term(MAILBOX_ID_FIELD, 
mailbox.getMailboxId().serialize())), BooleanClause.Occur.MUST);
         query.add(createQuery(range), BooleanClause.Occur.MUST);
-        
-        try {
-            writer.deleteDocuments(query);
-        } catch (IOException e) {
-            throw new MailboxException("Unable to delete message from index", 
e);
-        }
+
+        writer.deleteDocuments(query);
     }
 
     public void commit() throws IOException {

http://git-wip-us.apache.org/repos/asf/james-project/blob/07bc4446/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java
----------------------------------------------------------------------
diff --git 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java
 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java
index 6a44864..0a05fd3 100644
--- 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java
+++ 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java
@@ -83,17 +83,17 @@ public class LazyMessageSearchIndex extends 
ListeningMessageSearchIndex {
     }
 
     @Override
-    public void add(MailboxSession session, Mailbox mailbox, MailboxMessage 
message) throws MailboxException {
+    public void add(MailboxSession session, Mailbox mailbox, MailboxMessage 
message) throws Exception {
         index.add(session, mailbox, message);
     }
 
     @Override
-    public void delete(MailboxSession session, Mailbox mailbox, 
Collection<MessageUid> expungedUids) throws MailboxException {
+    public void delete(MailboxSession session, Mailbox mailbox, 
Collection<MessageUid> expungedUids) throws Exception {
         index.delete(session, mailbox, expungedUids);
     }
 
     @Override
-    public void deleteAll(MailboxSession session, Mailbox mailbox) throws 
MailboxException {
+    public void deleteAll(MailboxSession session, Mailbox mailbox) throws 
Exception {
         index.deleteAll(session, mailbox);
     }
 
@@ -121,7 +121,7 @@ public class LazyMessageSearchIndex extends 
ListeningMessageSearchIndex {
                     final MailboxMessage message = messages.next();
                     try {
                         add(session, mailbox, message);
-                    } catch (MailboxException e) {
+                    } catch (Exception e) {
                         LOGGER.error("Unable to index message {} in mailbox 
{}", message.getUid(), mailbox.getName(), e);
                     }
                 }
@@ -132,7 +132,7 @@ public class LazyMessageSearchIndex extends 
ListeningMessageSearchIndex {
     }
 
     @Override
-    public void update(MailboxSession session, Mailbox mailbox, 
List<UpdatedFlags> updatedFlagsList) throws MailboxException {
+    public void update(MailboxSession session, Mailbox mailbox, 
List<UpdatedFlags> updatedFlagsList) throws Exception {
         index.update(session, mailbox, updatedFlagsList);
     }
     

http://git-wip-us.apache.org/repos/asf/james-project/blob/07bc4446/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java
----------------------------------------------------------------------
diff --git 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java
 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java
index c6301c2..a1ffc3d 100644
--- 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java
+++ 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java
@@ -26,7 +26,6 @@ import org.apache.james.mailbox.Event;
 import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageUid;
-import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.MessageRange;
 import org.apache.james.mailbox.model.UpdatedFlags;
 import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
@@ -37,6 +36,7 @@ import 
org.apache.james.mailbox.store.mail.model.MailboxMessage;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.github.fge.lambdas.Throwing;
 import com.google.common.collect.ImmutableList;
 
 /**
@@ -63,47 +63,27 @@ public abstract class ListeningMessageSearchIndex 
implements MessageSearchIndex,
      * something relevant is received
      */
     @Override
-    public void event(Event event) {
-        try {
-            if (event instanceof MailboxEvent) {
-                handleMailboxEvent(event,
-                    
sessionProvider.createSystemSession(event.getUser().asString()),
-                    (MailboxEvent) event);
-            }
-        } catch (MailboxException e) {
-            LOGGER.error("Unable to update index for event {}", event, e);
-        }
-    }
-
-    private void handleMailboxEvent(Event event, MailboxSession session, 
MailboxEvent mailboxEvent) throws MailboxException {
+    public void event(Event event) throws Exception {
         if (INTERESTING_EVENTS.contains(event.getClass())) {
-            Mailbox mailbox = 
factory.getMailboxMapper(session).findMailboxById(mailboxEvent.getMailboxId());
-
-            if (event instanceof Added) {
-                handleAdded(session, mailbox, (Added) event);
-            } else if (event instanceof Expunged) {
-                handleExpunged(session, mailbox, (Expunged) event);
-            } else if (event instanceof FlagsUpdated) {
-                handleFlagsUpdated(session, mailbox, (FlagsUpdated) event);
-            } else if (event instanceof MailboxDeletion) {
-                deleteAll(session, mailbox);
-            }
+            handleMailboxEvent(event,
+                
sessionProvider.createSystemSession(event.getUser().asString()),
+                (MailboxEvent) event);
         }
     }
 
-    private void handleFlagsUpdated(MailboxSession session, Mailbox mailbox, 
FlagsUpdated flagsUpdated) {
-        try {
-            update(session, mailbox, flagsUpdated.getUpdatedFlags());
-        } catch (MailboxException e) {
-            LOGGER.error("Unable to update flags in index for mailbox {}", 
mailbox, e);
-        }
-    }
+    private void handleMailboxEvent(Event event, MailboxSession session, 
MailboxEvent mailboxEvent) throws Exception {
+        Mailbox mailbox = 
factory.getMailboxMapper(session).findMailboxById(mailboxEvent.getMailboxId());
 
-    private void handleExpunged(MailboxSession session, Mailbox mailbox, 
Expunged expunged) {
-        try {
+        if (event instanceof Added) {
+            handleAdded(session, mailbox, (Added) event);
+        } else if (event instanceof Expunged) {
+            Expunged expunged = (Expunged) event;
             delete(session, mailbox, expunged.getUids());
-        } catch (MailboxException e) {
-            LOGGER.error("Unable to deleted messages {} from index for mailbox 
{}", expunged.getUids(), mailbox, e);
+        } else if (event instanceof FlagsUpdated) {
+            FlagsUpdated flagsUpdated = (FlagsUpdated) event;
+            update(session, mailbox, flagsUpdated.getUpdatedFlags());
+        } else if (event instanceof MailboxDeletion) {
+            deleteAll(session, mailbox);
         }
     }
 
@@ -111,7 +91,7 @@ public abstract class ListeningMessageSearchIndex implements 
MessageSearchIndex,
         MessageRange.toRanges(added.getUids())
             .stream()
             .flatMap(range -> retrieveMailboxMessages(session, mailbox, range))
-            .forEach(mailboxMessage -> addMessage(session, mailbox, 
mailboxMessage));
+            .forEach(Throwing.<MailboxMessage>consumer(mailboxMessage -> 
add(session, mailbox, mailboxMessage)).sneakyThrow());
     }
 
     private Stream<MailboxMessage> retrieveMailboxMessages(MailboxSession 
session, Mailbox mailbox, MessageRange range) {
@@ -125,23 +105,14 @@ public abstract class ListeningMessageSearchIndex 
implements MessageSearchIndex,
         }
     }
 
-    private void addMessage(MailboxSession session, Mailbox mailbox, 
MailboxMessage message) {
-        try {
-            add(session, mailbox, message);
-        } catch (MailboxException e) {
-            LOGGER.error("Unable to index message {} for mailbox {}", 
message.getUid(), mailbox, e);
-        }
-    }
-
     /**
      * Add the {@link MailboxMessage} for the given {@link Mailbox} to the 
index
      *
      * @param session The mailbox session performing the message addition
      * @param mailbox mailbox on which the message addition was performed
      * @param message The added message
-     * @throws MailboxException
      */
-    public abstract void add(MailboxSession session, Mailbox mailbox, 
MailboxMessage message) throws MailboxException;
+    public abstract void add(MailboxSession session, Mailbox mailbox, 
MailboxMessage message) throws Exception;
 
     /**
      * Delete the concerned UIDs for the given {@link Mailbox} from the index
@@ -149,18 +120,16 @@ public abstract class ListeningMessageSearchIndex 
implements MessageSearchIndex,
      * @param session The mailbox session performing the expunge
      * @param mailbox mailbox on which the expunge was performed
      * @param expungedUids UIDS to be deleted
-     * @throws MailboxException
      */
-    public abstract void delete(MailboxSession session, Mailbox mailbox, 
Collection<MessageUid> expungedUids) throws MailboxException;
+    public abstract void delete(MailboxSession session, Mailbox mailbox, 
Collection<MessageUid> expungedUids) throws Exception;
 
     /**
      * Delete the messages contained in the given {@link Mailbox} from the 
index
      *
      * @param session The mailbox session performing the expunge
      * @param mailbox mailbox on which the expunge was performed
-     * @throws MailboxException
      */
-    public abstract void deleteAll(MailboxSession session, Mailbox mailbox) 
throws MailboxException;
+    public abstract void deleteAll(MailboxSession session, Mailbox mailbox) 
throws Exception;
     
     /**
      * Update the messages concerned by the updated flags list for the given 
{@link Mailbox}
@@ -168,7 +137,6 @@ public abstract class ListeningMessageSearchIndex 
implements MessageSearchIndex,
      * @param session session that performed the update
      * @param mailbox mailbox containing the updated messages
      * @param updatedFlagsList list of flags that were updated
-     * @throws MailboxException
      */
-    public abstract void update(MailboxSession session, Mailbox mailbox, 
List<UpdatedFlags> updatedFlagsList) throws MailboxException;
+    public abstract void update(MailboxSession session, Mailbox mailbox, 
List<UpdatedFlags> updatedFlagsList) throws Exception;
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/07bc4446/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerPerformer.java
----------------------------------------------------------------------
diff --git 
a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerPerformer.java
 
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerPerformer.java
index ffa623d..461bc71 100644
--- 
a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerPerformer.java
+++ 
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerPerformer.java
@@ -65,7 +65,7 @@ public class ReIndexerPerformer {
         this.mailboxSessionMapperFactory = mailboxSessionMapperFactory;
     }
 
-    Task.Result reIndex(MailboxId mailboxId, ReprocessingContext 
reprocessingContext) throws MailboxException {
+    Task.Result reIndex(MailboxId mailboxId, ReprocessingContext 
reprocessingContext) throws Exception {
         LOGGER.info("Intend to reindex mailbox with mailboxId {}", 
mailboxId.serialize());
         MailboxSession mailboxSession = 
mailboxManager.createSystemSession(RE_INDEXING);
         Mailbox mailbox = 
mailboxSessionMapperFactory.getMailboxMapper(mailboxSession).findMailboxById(mailboxId);

http://git-wip-us.apache.org/repos/asf/james-project/blob/07bc4446/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SingleMailboxReindexingTask.java
----------------------------------------------------------------------
diff --git 
a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SingleMailboxReindexingTask.java
 
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SingleMailboxReindexingTask.java
index 00f771b..5aade16 100644
--- 
a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SingleMailboxReindexingTask.java
+++ 
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SingleMailboxReindexingTask.java
@@ -23,7 +23,6 @@ import java.util.Optional;
 
 import javax.inject.Inject;
 
-import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.task.Task;
 import org.apache.james.task.TaskExecutionDetails;
@@ -72,7 +71,7 @@ public class SingleMailboxReindexingTask implements Task {
     public Result run() {
         try {
             return reIndexerPerformer.reIndex(mailboxId, reprocessingContext);
-        } catch (MailboxException e) {
+        } catch (Exception e) {
             return Result.PARTIAL;
         }
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to