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 <[email protected]> Authored: Wed Jan 16 11:49:04 2019 +0700 Committer: Benoit Tellier <[email protected]> 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: [email protected] For additional commands, e-mail: [email protected]
