You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2019/01/17 11:01:40 UTC
[1/8] james-project git commit: MAILBOX-372
ListeningMessageSearchIndex should not catch exceptions
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 <bt...@linagora.com>
Authored: Wed Jan 16 11:45:29 2019 +0700
Committer: Benoit Tellier <bt...@linagora.com>
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: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[5/8] james-project git commit: MAILBOX-372 Allow MailboxListeners to
throw exception
Posted by bt...@apache.org.
MAILBOX-372 Allow MailboxListeners to throw exception
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/5c301e8e
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/5c301e8e
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/5c301e8e
Branch: refs/heads/master
Commit: 5c301e8e3d37726d16ac765f5a5c2e8ea215d083
Parents: 21cde6d
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Jan 16 11:41:52 2019 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Jan 17 18:01:13 2019 +0700
----------------------------------------------------------------------
.../apache/james/mailbox/MailboxListener.java | 2 +-
.../james/mailbox/events/GroupContract.java | 22 ++++++------
.../james/mailbox/events/KeyContract.java | 38 ++++++++++----------
.../events/delivery/InVmEventDelivery.java | 2 ++
.../events/delivery/InVmEventDeliveryTest.java | 18 +++++-----
.../james/mailbox/events/GroupRegistration.java | 3 +-
.../mailbox/events/KeyRegistrationHandler.java | 3 +-
.../processor/base/SelectedMailboxImplTest.java | 2 +-
8 files changed, 47 insertions(+), 43 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/5c301e8e/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
index d845154..98607f1 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
@@ -67,7 +67,7 @@ public interface MailboxListener {
*
* @param event not null
*/
- void event(Event event);
+ void event(Event event) throws Exception;
interface QuotaEvent extends Event {
QuotaRoot getQuotaRoot();
http://git-wip-us.apache.org/repos/asf/james-project/blob/5c301e8e/mailbox/api/src/test/java/org/apache/james/mailbox/events/GroupContract.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/events/GroupContract.java b/mailbox/api/src/test/java/org/apache/james/mailbox/events/GroupContract.java
index beeeb0b..870f75f 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/events/GroupContract.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/events/GroupContract.java
@@ -55,7 +55,7 @@ public interface GroupContract {
interface SingleEventBusGroupContract extends EventBusContract {
@Test
- default void listenerGroupShouldReceiveEvents() {
+ default void listenerGroupShouldReceiveEvents() throws Exception {
MailboxListener listener = newListener();
eventBus().register(listener, GROUP_A);
@@ -66,7 +66,7 @@ public interface GroupContract {
}
@Test
- default void groupListenersShouldNotReceiveNoopEvents() {
+ default void groupListenersShouldNotReceiveNoopEvents() throws Exception {
MailboxListener listener = newListener();
eventBus().register(listener, GROUP_A);
@@ -79,7 +79,7 @@ public interface GroupContract {
}
@Test
- default void dispatchShouldNotThrowWhenAGroupListenerFails() {
+ default void dispatchShouldNotThrowWhenAGroupListenerFails() throws Exception {
MailboxListener listener = newListener();
doThrow(new RuntimeException()).when(listener).event(any());
@@ -90,7 +90,7 @@ public interface GroupContract {
}
@Test
- default void eachListenerGroupShouldReceiveEvents() {
+ default void eachListenerGroupShouldReceiveEvents() throws Exception {
MailboxListener listener = newListener();
MailboxListener listener2 = newListener();
eventBus().register(listener, GROUP_A);
@@ -103,7 +103,7 @@ public interface GroupContract {
}
@Test
- default void unregisteredGroupListenerShouldNotReceiveEvents() {
+ default void unregisteredGroupListenerShouldNotReceiveEvents() throws Exception {
MailboxListener listener = newListener();
Registration registration = eventBus().register(listener, GROUP_A);
@@ -148,7 +148,7 @@ public interface GroupContract {
}
@Test
- default void registerShouldAcceptAlreadyUnregisteredGroups() {
+ default void registerShouldAcceptAlreadyUnregisteredGroups() throws Exception {
MailboxListener listener = newListener();
eventBus().register(listener, GROUP_A).unregister();
@@ -160,7 +160,7 @@ public interface GroupContract {
}
@Test
- default void dispatchShouldCallSynchronousListener() {
+ default void dispatchShouldCallSynchronousListener() throws Exception {
MailboxListener listener = newListener();
eventBus().register(listener, GROUP_A);
@@ -183,7 +183,7 @@ public interface GroupContract {
}
@Test
- default void allGroupListenersShouldBeExecutedWhenAGroupListenerFails() {
+ default void allGroupListenersShouldBeExecutedWhenAGroupListenerFails() throws Exception {
MailboxListener listener = newListener();
MailboxListener failingListener = mock(MailboxListener.class);
@@ -202,7 +202,7 @@ public interface GroupContract {
interface MultipleEventBusGroupContract extends EventBusContract.MultipleEventBusContract {
@Test
- default void groupsDefinedOnlyOnSomeNodesShouldBeNotified() {
+ default void groupsDefinedOnlyOnSomeNodesShouldBeNotified() throws Exception {
MailboxListener mailboxListener = newListener();
eventBus().register(mailboxListener, GROUP_A);
@@ -213,7 +213,7 @@ public interface GroupContract {
}
@Test
- default void groupListenersShouldBeExecutedOnceInAControlledEnvironment() {
+ default void groupListenersShouldBeExecutedOnceInAControlledEnvironment() throws Exception {
MailboxListener mailboxListener = newListener();
eventBus().register(mailboxListener, GROUP_A);
@@ -225,7 +225,7 @@ public interface GroupContract {
}
@Test
- default void unregisterShouldStopNotificationForDistantGroups() {
+ default void unregisterShouldStopNotificationForDistantGroups() throws Exception {
MailboxListener mailboxListener = newListener();
eventBus().register(mailboxListener, GROUP_A).unregister();
http://git-wip-us.apache.org/repos/asf/james-project/blob/5c301e8e/mailbox/api/src/test/java/org/apache/james/mailbox/events/KeyContract.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/events/KeyContract.java b/mailbox/api/src/test/java/org/apache/james/mailbox/events/KeyContract.java
index 1421174..6e82af0 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/events/KeyContract.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/events/KeyContract.java
@@ -58,7 +58,7 @@ public interface KeyContract extends EventBusContract {
interface SingleEventBusKeyContract extends EventBusContract {
@Test
- default void registeredListenersShouldNotReceiveNoopEvents() {
+ default void registeredListenersShouldNotReceiveNoopEvents() throws Exception {
MailboxListener listener = newListener();
eventBus().register(listener, KEY_1);
@@ -71,7 +71,7 @@ public interface KeyContract extends EventBusContract {
}
@Test
- default void dispatchShouldNotThrowWhenARegisteredListenerFails() {
+ default void dispatchShouldNotThrowWhenARegisteredListenerFails() throws Exception {
MailboxListener listener = newListener();
doThrow(new RuntimeException()).when(listener).event(any());
@@ -82,7 +82,7 @@ public interface KeyContract extends EventBusContract {
}
@Test
- default void dispatchShouldNotNotifyRegisteredListenerWhenEmptyKeySet() {
+ default void dispatchShouldNotNotifyRegisteredListenerWhenEmptyKeySet() throws Exception {
MailboxListener listener = newListener();
eventBus().register(listener, KEY_1);
@@ -93,7 +93,7 @@ public interface KeyContract extends EventBusContract {
}
@Test
- default void dispatchShouldNotNotifyListenerRegisteredOnOtherKeys() {
+ default void dispatchShouldNotNotifyListenerRegisteredOnOtherKeys() throws Exception {
MailboxListener listener = newListener();
eventBus().register(listener, KEY_1);
@@ -104,7 +104,7 @@ public interface KeyContract extends EventBusContract {
}
@Test
- default void dispatchShouldNotifyRegisteredListeners() {
+ default void dispatchShouldNotifyRegisteredListeners() throws Exception {
MailboxListener listener = newListener();
eventBus().register(listener, KEY_1);
@@ -114,7 +114,7 @@ public interface KeyContract extends EventBusContract {
}
@Test
- default void dispatchShouldNotifyOnlyRegisteredListener() {
+ default void dispatchShouldNotifyOnlyRegisteredListener() throws Exception {
MailboxListener listener = newListener();
MailboxListener listener2 = newListener();
eventBus().register(listener, KEY_1);
@@ -128,7 +128,7 @@ public interface KeyContract extends EventBusContract {
}
@Test
- default void dispatchShouldNotifyAllListenersRegisteredOnAKey() {
+ default void dispatchShouldNotifyAllListenersRegisteredOnAKey() throws Exception {
MailboxListener listener = newListener();
MailboxListener listener2 = newListener();
eventBus().register(listener, KEY_1);
@@ -141,7 +141,7 @@ public interface KeyContract extends EventBusContract {
}
@Test
- default void registerShouldAllowDuplicatedRegistration() {
+ default void registerShouldAllowDuplicatedRegistration() throws Exception {
MailboxListener listener = newListener();
eventBus().register(listener, KEY_1);
eventBus().register(listener, KEY_1);
@@ -152,7 +152,7 @@ public interface KeyContract extends EventBusContract {
}
@Test
- default void unregisterShouldRemoveDoubleRegisteredListener() {
+ default void unregisterShouldRemoveDoubleRegisteredListener() throws Exception {
MailboxListener listener = newListener();
eventBus().register(listener, KEY_1);
eventBus().register(listener, KEY_1).unregister();
@@ -164,7 +164,7 @@ public interface KeyContract extends EventBusContract {
}
@Test
- default void callingAllUnregisterMethodShouldUnregisterTheListener() {
+ default void callingAllUnregisterMethodShouldUnregisterTheListener() throws Exception {
MailboxListener listener = newListener();
Registration registration = eventBus().register(listener, KEY_1);
eventBus().register(listener, KEY_1).unregister();
@@ -177,7 +177,7 @@ public interface KeyContract extends EventBusContract {
}
@Test
- default void unregisterShouldHaveNotNotifyWhenCalledOnDifferentKeys() {
+ default void unregisterShouldHaveNotNotifyWhenCalledOnDifferentKeys() throws Exception {
MailboxListener listener = newListener();
eventBus().register(listener, KEY_1);
eventBus().register(listener, KEY_2).unregister();
@@ -199,7 +199,7 @@ public interface KeyContract extends EventBusContract {
}
@Test
- default void dispatchShouldAcceptSeveralKeys() {
+ default void dispatchShouldAcceptSeveralKeys() throws Exception {
MailboxListener listener = newListener();
eventBus().register(listener, KEY_1);
@@ -209,7 +209,7 @@ public interface KeyContract extends EventBusContract {
}
@Test
- default void dispatchShouldCallListenerOnceWhenSeveralKeysMatching() {
+ default void dispatchShouldCallListenerOnceWhenSeveralKeysMatching() throws Exception {
MailboxListener listener = newListener();
eventBus().register(listener, KEY_1);
eventBus().register(listener, KEY_2);
@@ -220,7 +220,7 @@ public interface KeyContract extends EventBusContract {
}
@Test
- default void dispatchShouldNotNotifyUnregisteredListener() {
+ default void dispatchShouldNotNotifyUnregisteredListener() throws Exception {
MailboxListener listener = newListener();
eventBus().register(listener, KEY_1).unregister();
@@ -231,7 +231,7 @@ public interface KeyContract extends EventBusContract {
}
@Test
- default void dispatchShouldNotBlockAsynchronousListener() {
+ default void dispatchShouldNotBlockAsynchronousListener() throws Exception {
MailboxListener listener = newListener();
when(listener.getExecutionMode()).thenReturn(MailboxListener.ExecutionMode.ASYNCHRONOUS);
CountDownLatch latch = new CountDownLatch(1);
@@ -266,7 +266,7 @@ public interface KeyContract extends EventBusContract {
}
@Test
- default void allRegisteredListenersShouldBeExecutedWhenARegisteredListenerFails() {
+ default void allRegisteredListenersShouldBeExecutedWhenARegisteredListenerFails() throws Exception {
MailboxListener listener = newListener();
MailboxListener failingListener = mock(MailboxListener.class);
@@ -285,7 +285,7 @@ public interface KeyContract extends EventBusContract {
interface MultipleEventBusKeyContract extends MultipleEventBusContract {
@Test
- default void crossEventBusRegistrationShouldBeAllowed() {
+ default void crossEventBusRegistrationShouldBeAllowed() throws Exception {
MailboxListener mailboxListener = newListener();
eventBus().register(mailboxListener, KEY_1);
@@ -296,7 +296,7 @@ public interface KeyContract extends EventBusContract {
}
@Test
- default void unregisteredDistantListenersShouldNotBeNotified() {
+ default void unregisteredDistantListenersShouldNotBeNotified() throws Exception {
MailboxListener mailboxListener = newListener();
eventBus().register(mailboxListener, KEY_1).unregister();
@@ -308,7 +308,7 @@ public interface KeyContract extends EventBusContract {
}
@Test
- default void allRegisteredListenersShouldBeDispatched() {
+ default void allRegisteredListenersShouldBeDispatched() throws Exception {
MailboxListener mailboxListener1 = newListener();
MailboxListener mailboxListener2 = newListener();
http://git-wip-us.apache.org/repos/asf/james-project/blob/5c301e8e/mailbox/event/event-memory/src/main/java/org/apache/james/mailbox/events/delivery/InVmEventDelivery.java
----------------------------------------------------------------------
diff --git a/mailbox/event/event-memory/src/main/java/org/apache/james/mailbox/events/delivery/InVmEventDelivery.java b/mailbox/event/event-memory/src/main/java/org/apache/james/mailbox/events/delivery/InVmEventDelivery.java
index c59a8b8..c5446dd 100644
--- a/mailbox/event/event-memory/src/main/java/org/apache/james/mailbox/events/delivery/InVmEventDelivery.java
+++ b/mailbox/event/event-memory/src/main/java/org/apache/james/mailbox/events/delivery/InVmEventDelivery.java
@@ -95,6 +95,8 @@ public class InVmEventDelivery implements EventDelivery {
TimeMetric timer = metricFactory.timer("mailbox-listener-" + mailboxListener.getClass().getSimpleName());
try {
mailboxListener.event(event);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
} finally {
timer.stopAndPublish();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/5c301e8e/mailbox/event/event-memory/src/test/java/org/apache/james/mailbox/events/delivery/InVmEventDeliveryTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/event-memory/src/test/java/org/apache/james/mailbox/events/delivery/InVmEventDeliveryTest.java b/mailbox/event/event-memory/src/test/java/org/apache/james/mailbox/events/delivery/InVmEventDeliveryTest.java
index 9796328..207d319 100644
--- a/mailbox/event/event-memory/src/test/java/org/apache/james/mailbox/events/delivery/InVmEventDeliveryTest.java
+++ b/mailbox/event/event-memory/src/test/java/org/apache/james/mailbox/events/delivery/InVmEventDeliveryTest.java
@@ -175,7 +175,7 @@ class InVmEventDeliveryTest {
}
@Test
- void deliverShouldHaveCalledSynchronousListenersWhenAllListenerExecutedJoined() {
+ void deliverShouldHaveCalledSynchronousListenersWhenAllListenerExecutedJoined() throws Exception {
when(listener.getExecutionMode()).thenReturn(MailboxListener.ExecutionMode.SYNCHRONOUS);
inVmEventDelivery.deliver(ImmutableList.of(listener), event).allListenerFuture().block();
@@ -184,7 +184,7 @@ class InVmEventDeliveryTest {
}
@Test
- void deliverShouldHaveCalledAsynchronousListenersWhenAllListenerExecutedJoined() {
+ void deliverShouldHaveCalledAsynchronousListenersWhenAllListenerExecutedJoined() throws Exception {
when(listener.getExecutionMode()).thenReturn(MailboxListener.ExecutionMode.ASYNCHRONOUS);
inVmEventDelivery.deliver(ImmutableList.of(listener), event).allListenerFuture().block();
@@ -193,7 +193,7 @@ class InVmEventDeliveryTest {
}
@Test
- void deliverShouldHaveCalledSynchronousListenersWhenSynchronousListenerExecutedJoined() {
+ void deliverShouldHaveCalledSynchronousListenersWhenSynchronousListenerExecutedJoined() throws Exception {
when(listener.getExecutionMode()).thenReturn(MailboxListener.ExecutionMode.SYNCHRONOUS);
inVmEventDelivery.deliver(ImmutableList.of(listener), event).synchronousListenerFuture().block();
@@ -202,7 +202,7 @@ class InVmEventDeliveryTest {
}
@Test
- void deliverShouldNotBlockOnAsynchronousListenersWhenSynchronousListenerExecutedJoined() {
+ void deliverShouldNotBlockOnAsynchronousListenersWhenSynchronousListenerExecutedJoined() throws Exception {
when(listener.getExecutionMode()).thenReturn(MailboxListener.ExecutionMode.ASYNCHRONOUS);
CountDownLatch latch = new CountDownLatch(1);
doAnswer(invocation -> {
@@ -218,7 +218,7 @@ class InVmEventDeliveryTest {
}
@Test
- void deliverShouldNotBlockOnSynchronousListenersWhenNoJoin() {
+ void deliverShouldNotBlockOnSynchronousListenersWhenNoJoin() throws Exception {
when(listener.getExecutionMode()).thenReturn(MailboxListener.ExecutionMode.SYNCHRONOUS);
CountDownLatch latch = new CountDownLatch(1);
doAnswer(invocation -> {
@@ -234,7 +234,7 @@ class InVmEventDeliveryTest {
}
@Test
- void deliverShouldNotBlockOnAsynchronousListenersWhenNoJoin() {
+ void deliverShouldNotBlockOnAsynchronousListenersWhenNoJoin() throws Exception {
when(listener.getExecutionMode()).thenReturn(MailboxListener.ExecutionMode.ASYNCHRONOUS);
CountDownLatch latch = new CountDownLatch(1);
doAnswer(invocation -> {
@@ -250,7 +250,7 @@ class InVmEventDeliveryTest {
}
@Test
- void deliverShouldEventuallyDeliverAsynchronousListenersWhenSynchronousListenerExecutedJoined() {
+ void deliverShouldEventuallyDeliverAsynchronousListenersWhenSynchronousListenerExecutedJoined() throws Exception {
when(listener.getExecutionMode()).thenReturn(MailboxListener.ExecutionMode.ASYNCHRONOUS);
inVmEventDelivery.deliver(ImmutableList.of(listener), event).synchronousListenerFuture().block();
@@ -259,7 +259,7 @@ class InVmEventDeliveryTest {
}
@Test
- void deliverShouldEventuallyDeliverSynchronousListenersWhenNoJoin() {
+ void deliverShouldEventuallyDeliverSynchronousListenersWhenNoJoin() throws Exception {
when(listener.getExecutionMode()).thenReturn(MailboxListener.ExecutionMode.SYNCHRONOUS);
inVmEventDelivery.deliver(ImmutableList.of(listener), event);
@@ -268,7 +268,7 @@ class InVmEventDeliveryTest {
}
@Test
- void deliverShouldCallSynchronousListenersWhenAsynchronousListenersAreAlsoRegistered() {
+ void deliverShouldCallSynchronousListenersWhenAsynchronousListenersAreAlsoRegistered() throws Exception {
when(listener.getExecutionMode()).thenReturn(MailboxListener.ExecutionMode.ASYNCHRONOUS);
when(listener2.getExecutionMode()).thenReturn(MailboxListener.ExecutionMode.SYNCHRONOUS);
http://git-wip-us.apache.org/repos/asf/james-project/blob/5c301e8e/mailbox/event/event-rabbitmq/src/main/java/org/apache/james/mailbox/events/GroupRegistration.java
----------------------------------------------------------------------
diff --git a/mailbox/event/event-rabbitmq/src/main/java/org/apache/james/mailbox/events/GroupRegistration.java b/mailbox/event/event-rabbitmq/src/main/java/org/apache/james/mailbox/events/GroupRegistration.java
index b382dee..68f67be 100644
--- a/mailbox/event/event-rabbitmq/src/main/java/org/apache/james/mailbox/events/GroupRegistration.java
+++ b/mailbox/event/event-rabbitmq/src/main/java/org/apache/james/mailbox/events/GroupRegistration.java
@@ -35,6 +35,7 @@ import org.apache.james.event.json.EventSerializer;
import org.apache.james.mailbox.Event;
import org.apache.james.mailbox.MailboxListener;
+import com.github.fge.lambdas.Throwing;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
@@ -149,7 +150,7 @@ class GroupRegistration implements Registration {
int currentRetryCount = getRetryCount(acknowledgableDelivery);
return delayGenerator.delayIfHaveTo(currentRetryCount)
- .flatMap(any -> Mono.fromRunnable(() -> mailboxListener.event(event)))
+ .flatMap(any -> Mono.fromRunnable(Throwing.runnable(() -> mailboxListener.event(event))))
.onErrorResume(throwable -> retryHandler.handleRetry(eventAsBytes, event, currentRetryCount, throwable))
.then(Mono.fromRunnable(acknowledgableDelivery::ack))
.subscribeWith(MonoProcessor.create())
http://git-wip-us.apache.org/repos/asf/james-project/blob/5c301e8e/mailbox/event/event-rabbitmq/src/main/java/org/apache/james/mailbox/events/KeyRegistrationHandler.java
----------------------------------------------------------------------
diff --git a/mailbox/event/event-rabbitmq/src/main/java/org/apache/james/mailbox/events/KeyRegistrationHandler.java b/mailbox/event/event-rabbitmq/src/main/java/org/apache/james/mailbox/events/KeyRegistrationHandler.java
index ff388df..3610b4b 100644
--- a/mailbox/event/event-rabbitmq/src/main/java/org/apache/james/mailbox/events/KeyRegistrationHandler.java
+++ b/mailbox/event/event-rabbitmq/src/main/java/org/apache/james/mailbox/events/KeyRegistrationHandler.java
@@ -33,6 +33,7 @@ import org.apache.james.mailbox.MailboxListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.github.fge.lambdas.Throwing;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Delivery;
@@ -111,7 +112,7 @@ public class KeyRegistrationHandler {
Event event = toEvent(delivery);
return mailboxListenerRegistry.getLocalMailboxListeners(registrationKey)
- .flatMap(listener -> Mono.fromRunnable(() -> listener.event(event))
+ .flatMap(listener -> Mono.fromRunnable(Throwing.runnable(() -> listener.event(event)))
.doOnError(e -> LOGGER.error("Exception happens when handling event of user {}", event.getUser().asString(), e))
.onErrorResume(e -> Mono.empty()))
.subscribeOn(Schedulers.elastic())
http://git-wip-us.apache.org/repos/asf/james-project/blob/5c301e8e/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
index a307c27..d89a36b 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
@@ -169,7 +169,7 @@ public class SelectedMailboxImplTest {
};
}
- private void emitEvent(MailboxListener mailboxListener) {
+ private void emitEvent(MailboxListener mailboxListener) throws Exception {
mailboxListener.event(EventFactory.added()
.randomEventId()
.mailboxSession(MailboxSessionUtil.create("user"))
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[2/8] james-project git commit: MAILBOX-372
QuotaThresholdCrossingListener should not catch exceptions
Posted by bt...@apache.org.
MAILBOX-372 QuotaThresholdCrossingListener 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/45691e92
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/45691e92
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/45691e92
Branch: refs/heads/master
Commit: 45691e92cbfb2d565f066bf9f7724a9682a79a3c
Parents: 369d4db
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Jan 16 11:51:57 2019 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Jan 17 18:01:13 2019 +0700
----------------------------------------------------------------------
.../listeners/QuotaThresholdCrossingListener.java | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/45691e92/mailbox/plugin/quota-mailing/src/main/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdCrossingListener.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-mailing/src/main/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdCrossingListener.java b/mailbox/plugin/quota-mailing/src/main/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdCrossingListener.java
index 73c6b1c..900d0fd 100644
--- a/mailbox/plugin/quota-mailing/src/main/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdCrossingListener.java
+++ b/mailbox/plugin/quota-mailing/src/main/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdCrossingListener.java
@@ -37,15 +37,12 @@ import org.apache.james.mailbox.quota.mailing.commands.DetectThresholdCrossingHa
import org.apache.james.mailbox.quota.mailing.subscribers.QuotaThresholdMailer;
import org.apache.james.user.api.UsersRepository;
import org.apache.mailet.MailetContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import com.google.common.collect.ImmutableSet;
public class QuotaThresholdCrossingListener implements MailboxListener.GroupMailboxListener {
private static class QuotaThresholdCrossingListenerGroup extends Group {}
- private static final Logger LOGGER = LoggerFactory.getLogger(QuotaThresholdCrossingListener.class);
private static final Group GROUP = new QuotaThresholdCrossingListenerGroup();
private final EventSourcingSystem eventSourcingSystem;
@@ -72,12 +69,8 @@ public class QuotaThresholdCrossingListener implements MailboxListener.GroupMail
@Override
public void event(Event event) {
- try {
- if (event instanceof QuotaUsageUpdatedEvent) {
- handleEvent(event.getUser(), (QuotaUsageUpdatedEvent) event);
- }
- } catch (Exception e) {
- LOGGER.error("Can not re-emmit quota threshold events", e);
+ if (event instanceof QuotaUsageUpdatedEvent) {
+ handleEvent(event.getUser(), (QuotaUsageUpdatedEvent) event);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[3/8] james-project git commit: MAILBOX-372
ElasticSearchQuotaMailboxListener should not catch exceptions
Posted by bt...@apache.org.
MAILBOX-372 ElasticSearchQuotaMailboxListener 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/f2b84ce1
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/f2b84ce1
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/f2b84ce1
Branch: refs/heads/master
Commit: f2b84ce16a402598262ae6a893c228803967a7a7
Parents: 5c301e8
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Jan 16 11:43:09 2019 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Jan 17 18:01:13 2019 +0700
----------------------------------------------------------------------
.../events/ElasticSearchQuotaMailboxListener.java | 13 +++----------
1 file changed, 3 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/f2b84ce1/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListener.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListener.java b/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListener.java
index a546492..25c5613 100644
--- a/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListener.java
+++ b/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListener.java
@@ -28,15 +28,12 @@ import org.apache.james.mailbox.MailboxListener;
import org.apache.james.mailbox.events.Group;
import org.apache.james.quota.search.elasticsearch.QuotaRatioElasticSearchConstants;
import org.apache.james.quota.search.elasticsearch.json.QuotaRatioToElasticSearchJson;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.core.JsonProcessingException;
public class ElasticSearchQuotaMailboxListener implements MailboxListener.GroupMailboxListener {
private static class ElasticSearchQuotaMailboxListenerGroup extends Group {}
- private static final Logger LOGGER = LoggerFactory.getLogger(ElasticSearchQuotaMailboxListener.class);
private static final Group GROUP = new ElasticSearchQuotaMailboxListenerGroup();
private final ElasticSearchIndexer indexer;
@@ -56,13 +53,9 @@ public class ElasticSearchQuotaMailboxListener implements MailboxListener.GroupM
}
@Override
- public void event(Event event) {
- try {
- if (event instanceof QuotaUsageUpdatedEvent) {
- handleEvent(event.getUser(), (QuotaUsageUpdatedEvent) event);
- }
- } catch (Exception e) {
- LOGGER.error("Can not index quota ratio", e);
+ public void event(Event event) throws JsonProcessingException {
+ if (event instanceof QuotaUsageUpdatedEvent) {
+ handleEvent(event.getUser(), (QuotaUsageUpdatedEvent) event);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[7/8] james-project git commit: MAILBOX-372 SpamAssassinListener
should not catch exceptions
Posted by bt...@apache.org.
MAILBOX-372 SpamAssassinListener 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/a5870f5e
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/a5870f5e
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/a5870f5e
Branch: refs/heads/master
Commit: a5870f5ecb0c66ae2ab2b73325cd2a13f942b38f
Parents: 45691e9
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Jan 16 11:53:16 2019 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Jan 17 18:01:13 2019 +0700
----------------------------------------------------------------------
.../spamassassin/SpamAssassinListener.java | 18 +++++++-----------
.../spamassassin/SpamAssassinListenerTest.java | 4 ++--
2 files changed, 9 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/a5870f5e/mailbox/plugin/spamassassin/src/main/java/org/apache/james/mailbox/spamassassin/SpamAssassinListener.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/spamassassin/src/main/java/org/apache/james/mailbox/spamassassin/SpamAssassinListener.java b/mailbox/plugin/spamassassin/src/main/java/org/apache/james/mailbox/spamassassin/SpamAssassinListener.java
index 5427320..70ce446 100644
--- a/mailbox/plugin/spamassassin/src/main/java/org/apache/james/mailbox/spamassassin/SpamAssassinListener.java
+++ b/mailbox/plugin/spamassassin/src/main/java/org/apache/james/mailbox/spamassassin/SpamAssassinListener.java
@@ -82,17 +82,13 @@ public class SpamAssassinListener implements SpamEventListener {
}
@Override
- public void event(Event event) {
- try {
- MailboxSession session = mailboxManager.createSystemSession(getClass().getCanonicalName());
- if (event instanceof MessageMoveEvent) {
- handleMessageMove(event, session, (MessageMoveEvent) event);
- }
- if (event instanceof Added) {
- handleAdded(event, session, (Added) event);
- }
- } catch (MailboxException e) {
- LOGGER.warn("Error while processing SPAM listener", e);
+ public void event(Event event) throws MailboxException {
+ MailboxSession session = mailboxManager.createSystemSession(getClass().getCanonicalName());
+ if (event instanceof MessageMoveEvent) {
+ handleMessageMove(event, session, (MessageMoveEvent) event);
+ }
+ if (event instanceof Added) {
+ handleAdded(event, session, (Added) event);
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a5870f5e/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java b/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
index e1647ae..1a66b30 100644
--- a/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
+++ b/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
@@ -141,7 +141,7 @@ public class SpamAssassinListenerTest {
}
@Test
- public void eventShouldCallSpamAssassinSpamLearningWhenTheEventMatches() {
+ public void eventShouldCallSpamAssassinSpamLearningWhenTheEventMatches() throws Exception {
MessageMoveEvent messageMoveEvent = MessageMoveEvent.builder()
.session(MAILBOX_SESSION)
.messageMoves(MessageMoves.builder()
@@ -213,7 +213,7 @@ public class SpamAssassinListenerTest {
}
@Test
- public void eventShouldCallSpamAssassinHamLearningWhenTheEventMatches() {
+ public void eventShouldCallSpamAssassinHamLearningWhenTheEventMatches() throws Exception {
MessageMoveEvent messageMoveEvent = MessageMoveEvent.builder()
.session(MAILBOX_SESSION)
.messageMoves(MessageMoves.builder()
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[6/8] james-project git commit: MAILBOX-372 MailboxAnnotationListener
should not catch exceptions
Posted by bt...@apache.org.
MAILBOX-372 MailboxAnnotationListener 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/ce2036f0
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/ce2036f0
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/ce2036f0
Branch: refs/heads/master
Commit: ce2036f0373a3a0dc93b3374562d59a90bb2b20c
Parents: b7df724
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Jan 16 11:49:04 2019 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Jan 17 18:01:13 2019 +0700
----------------------------------------------------------------------
.../store/event/MailboxAnnotationListener.java | 23 +++++---------------
.../event/MailboxAnnotationListenerTest.java | 8 +++----
2 files changed, 10 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/ce2036f0/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxAnnotationListener.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxAnnotationListener.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxAnnotationListener.java
index b026186..5c293cb 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxAnnotationListener.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxAnnotationListener.java
@@ -32,13 +32,10 @@ import org.apache.james.mailbox.model.MailboxId;
import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
import org.apache.james.mailbox.store.SessionProvider;
import org.apache.james.mailbox.store.mail.AnnotationMapper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
public class MailboxAnnotationListener implements MailboxListener.GroupMailboxListener {
private static final class MailboxAnnotationListenerGroup extends Group {}
- private static final Logger logger = LoggerFactory.getLogger(MailboxAnnotationListener.class);
private static final Group GROUP = new MailboxAnnotationListenerGroup();
private final MailboxSessionMapperFactory mailboxSessionMapperFactory;
@@ -56,28 +53,20 @@ public class MailboxAnnotationListener implements MailboxListener.GroupMailboxLi
}
@Override
- public void event(Event event) {
+ public void event(Event event) throws MailboxException {
if (event instanceof MailboxDeletion) {
- try {
- MailboxSession mailboxSession = sessionProvider.createSystemSession(event.getUser().asString());
- AnnotationMapper annotationMapper = mailboxSessionMapperFactory.getAnnotationMapper(mailboxSession);
- MailboxId mailboxId = ((MailboxDeletion) event).getMailboxId();
+ MailboxSession mailboxSession = sessionProvider.createSystemSession(event.getUser().asString());
+ AnnotationMapper annotationMapper = mailboxSessionMapperFactory.getAnnotationMapper(mailboxSession);
+ MailboxId mailboxId = ((MailboxDeletion) event).getMailboxId();
- deleteRelatedAnnotations(mailboxId, annotationMapper);
- } catch (MailboxException e) {
- logger.error("Unable to look up AnnotationMapper", e);
- }
+ deleteRelatedAnnotations(mailboxId, annotationMapper);
}
}
private void deleteRelatedAnnotations(MailboxId mailboxId, AnnotationMapper annotationMapper) {
List<MailboxAnnotation> annotations = annotationMapper.getAllAnnotations(mailboxId);
for (MailboxAnnotation annotation : annotations) {
- try {
- annotationMapper.deleteAnnotation(mailboxId, annotation.getKey());
- } catch (Exception e) {
- logger.error("Unable to delete annotation {} cause {}", annotation.getKey(), e.getMessage());
- }
+ annotationMapper.deleteAnnotation(mailboxId, annotation.getKey());
}
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/ce2036f0/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
index 394b008..ee68c71 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
@@ -18,6 +18,7 @@
****************************************************************/
package org.apache.james.mailbox.store.event;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doThrow;
@@ -94,7 +95,7 @@ public class MailboxAnnotationListenerTest {
}
@Test
- public void eventShouldDoNothingIfDoNotHaveMailboxDeletionEvent() {
+ public void eventShouldDoNothingIfDoNotHaveMailboxDeletionEvent() throws Exception {
MailboxListener.MailboxEvent event = new MailboxListener.MailboxAdded(null, null, MAILBOX_PATH, MAILBOX_ID, Event.EventId.random());
listener.event(event);
@@ -133,16 +134,15 @@ public class MailboxAnnotationListenerTest {
}
@Test
- public void eventShouldDeteleAllMailboxIfHasAnyOneFailed() throws Exception {
+ public void eventShouldPropagateFailure() throws Exception {
when(annotationMapper.getAllAnnotations((eq(mailboxId)))).thenReturn(ANNOTATIONS);
doThrow(new RuntimeException()).when(annotationMapper).deleteAnnotation(eq(mailboxId), eq(PRIVATE_KEY));
- listener.event(deleteEvent);
+ assertThatThrownBy(() -> listener.event(deleteEvent)).isInstanceOf(RuntimeException.class);
verify(mailboxSessionMapperFactory).getAnnotationMapper(eq(mailboxSession));
verify(annotationMapper).getAllAnnotations(eq(mailboxId));
verify(annotationMapper).deleteAnnotation(eq(mailboxId), eq(PRIVATE_KEY));
- verify(annotationMapper).deleteAnnotation(eq(mailboxId), eq(SHARED_KEY));
verifyNoMoreInteractions(mailboxSessionMapperFactory);
verifyNoMoreInteractions(annotationMapper);
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[8/8] james-project git commit: MAILBOX-372
PropagateLookupRightListener should not catch exceptions
Posted by bt...@apache.org.
MAILBOX-372 PropagateLookupRightListener 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/369d4db6
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/369d4db6
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/369d4db6
Branch: refs/heads/master
Commit: 369d4db65db1d39978955dd5316dbf9a808180f0
Parents: ce2036f
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Jan 16 11:50:28 2019 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Jan 17 18:01:13 2019 +0700
----------------------------------------------------------------------
.../event/PropagateLookupRightListener.java | 30 +++++++-------------
1 file changed, 11 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/369d4db6/server/protocols/jmap/src/main/java/org/apache/james/jmap/event/PropagateLookupRightListener.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/event/PropagateLookupRightListener.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/event/PropagateLookupRightListener.java
index 2ab0273..d56b616 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/event/PropagateLookupRightListener.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/event/PropagateLookupRightListener.java
@@ -59,30 +59,22 @@ public class PropagateLookupRightListener implements MailboxListener.GroupMailbo
}
@Override
- public void event(Event event) {
- try {
- MailboxSession mailboxSession = createMailboxSession(event);
+ public void event(Event event) throws MailboxException {
+ MailboxSession mailboxSession = createMailboxSession(event);
- if (event instanceof MailboxACLUpdated) {
- MailboxACLUpdated aclUpdateEvent = (MailboxACLUpdated) event;
- MailboxPath mailboxPath = mailboxManager.getMailbox(aclUpdateEvent.getMailboxId(), mailboxSession).getMailboxPath();
+ if (event instanceof MailboxACLUpdated) {
+ MailboxACLUpdated aclUpdateEvent = (MailboxACLUpdated) event;
+ MailboxPath mailboxPath = mailboxManager.getMailbox(aclUpdateEvent.getMailboxId(), mailboxSession).getMailboxPath();
- updateLookupRightOnParent(mailboxSession, mailboxPath, aclUpdateEvent.getAclDiff());
- } else if (event instanceof MailboxRenamed) {
- MailboxRenamed renamedEvent = (MailboxRenamed) event;
- updateLookupRightOnParent(mailboxSession, renamedEvent.getNewPath());
- }
- } catch (MailboxException e) {
- throw new RuntimeException(e);
+ updateLookupRightOnParent(mailboxSession, mailboxPath, aclUpdateEvent.getAclDiff());
+ } else if (event instanceof MailboxRenamed) {
+ MailboxRenamed renamedEvent = (MailboxRenamed) event;
+ updateLookupRightOnParent(mailboxSession, renamedEvent.getNewPath());
}
}
- private MailboxSession createMailboxSession(Event event) {
- try {
- return mailboxManager.createSystemSession(event.getUser().asString());
- } catch (MailboxException e) {
- throw new RuntimeException("unable to create system session of user:" + event.getUser().toString(), e);
- }
+ private MailboxSession createMailboxSession(Event event) throws MailboxException {
+ return mailboxManager.createSystemSession(event.getUser().asString());
}
private void updateLookupRightOnParent(MailboxSession session, MailboxPath path) throws MailboxException {
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[4/8] james-project git commit: MAILBOX-372
ListeningCurrentQuotaUpdater should not catch exceptions
Posted by bt...@apache.org.
MAILBOX-372 ListeningCurrentQuotaUpdater 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/b7df724b
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/b7df724b
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/b7df724b
Branch: refs/heads/master
Commit: b7df724bb413381f7212b5e54027fcc3abbaf51e
Parents: f2b84ce
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Jan 16 11:44:36 2019 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Jan 17 18:01:13 2019 +0700
----------------------------------------------------------------------
.../quota/ListeningCurrentQuotaUpdater.java | 31 ++++++++------------
1 file changed, 12 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/b7df724b/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
index 251541b..57cee5a 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
@@ -34,15 +34,12 @@ import org.apache.james.mailbox.model.QuotaRoot;
import org.apache.james.mailbox.quota.QuotaManager;
import org.apache.james.mailbox.quota.QuotaRootResolver;
import org.apache.james.mailbox.store.event.EventFactory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import com.google.common.collect.ImmutableSet;
public class ListeningCurrentQuotaUpdater implements MailboxListener.GroupMailboxListener, QuotaUpdater {
private static class ListeningCurrentQuotaUpdaterGroup extends Group {}
- private static final Logger LOGGER = LoggerFactory.getLogger(ListeningCurrentQuotaUpdater.class);
public static final Group GROUP = new ListeningCurrentQuotaUpdaterGroup();
private static final ImmutableSet<RegistrationKey> NO_REGISTRATION_KEYS = ImmutableSet.of();
@@ -65,22 +62,18 @@ public class ListeningCurrentQuotaUpdater implements MailboxListener.GroupMailbo
}
@Override
- public void event(Event event) {
- try {
- if (event instanceof Added) {
- Added addedEvent = (Added) event;
- QuotaRoot quotaRoot = quotaRootResolver.getQuotaRoot(addedEvent.getMailboxId());
- handleAddedEvent(addedEvent, quotaRoot);
- } else if (event instanceof Expunged) {
- Expunged expungedEvent = (Expunged) event;
- QuotaRoot quotaRoot = quotaRootResolver.getQuotaRoot(expungedEvent.getMailboxId());
- handleExpungedEvent(expungedEvent, quotaRoot);
- } else if (event instanceof MailboxDeletion) {
- MailboxDeletion mailboxDeletionEvent = (MailboxDeletion) event;
- handleMailboxDeletionEvent(mailboxDeletionEvent);
- }
- } catch (MailboxException e) {
- LOGGER.error("Error while updating quotas", e);
+ public void event(Event event) throws MailboxException {
+ if (event instanceof Added) {
+ Added addedEvent = (Added) event;
+ QuotaRoot quotaRoot = quotaRootResolver.getQuotaRoot(addedEvent.getMailboxId());
+ handleAddedEvent(addedEvent, quotaRoot);
+ } else if (event instanceof Expunged) {
+ Expunged expungedEvent = (Expunged) event;
+ QuotaRoot quotaRoot = quotaRootResolver.getQuotaRoot(expungedEvent.getMailboxId());
+ handleExpungedEvent(expungedEvent, quotaRoot);
+ } else if (event instanceof MailboxDeletion) {
+ MailboxDeletion mailboxDeletionEvent = (MailboxDeletion) event;
+ handleMailboxDeletionEvent(mailboxDeletionEvent);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org