Author: btellier
Date: Sat Nov 28 13:05:21 2015
New Revision: 1716961

URL: http://svn.apache.org/viewvc?rev=1716961&view=rev
Log:
MAILBOX-211 Event processing should not be stopped by errors thrown

Modified:
    
james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListener.java
    
james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListenerTest.java

Modified: 
james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListener.java
URL: 
http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListener.java?rev=1716961&r1=1716960&r2=1716961&view=diff
==============================================================================
--- 
james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListener.java
 (original)
+++ 
james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListener.java
 Sat Nov 28 13:05:21 2015
@@ -97,7 +97,17 @@ public class DefaultDelegatingMailboxLis
     }
 
     private void deliverEvent(Event event, MailboxListener listener) {
-        listener.event(event);
+        try {
+            listener.event(event);
+        } catch(Throwable throwable) {
+            event.getSession()
+                .getLog()
+                .error("Error while processing listener "
+                    + listener.getClass().getCanonicalName()
+                    + " for "
+                    + event.getClass().getCanonicalName(),
+                    throwable);
+        }
     }
 
 }

Modified: 
james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListenerTest.java
URL: 
http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListenerTest.java?rev=1716961&r1=1716960&r2=1716961&view=diff
==============================================================================
--- 
james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListenerTest.java
 (original)
+++ 
james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListenerTest.java
 Sat Nov 28 13:05:21 2015
@@ -21,15 +21,31 @@ package org.apache.james.mailbox.store.e
 
 import static org.assertj.core.api.Assertions.assertThat;
 
+
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
+
 import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.util.EventCollector;
 import org.junit.Before;
 import org.junit.Test;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class DefaultDelegatingMailboxListenerTest {
 
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(DefaultDelegatingMailboxListenerTest.class);
+
     private static final MailboxPath MAILBOX_PATH = new 
MailboxPath("namespace", "user", "name");
     private static final MailboxPath OTHER_MAILBOX_PATH = new 
MailboxPath("namespace", "other", "name");
 
@@ -179,4 +195,20 @@ public class DefaultDelegatingMailboxLis
         assertThat(onceEventCollector.getEvents()).isEmpty();
     }
 
+    @Test
+    public void listenersErrorsShouldNotBePropageted() throws Exception {
+        MailboxSession session = new MockMailboxSession("benwa");
+        MailboxListener.Event event = new MailboxListener.Event(session, 
MAILBOX_PATH) {};
+        MailboxListener mockedListener = mock(MailboxListener.class);
+        when(mockedListener.getType()).thenAnswer(new 
Answer<MailboxListener.ListenerType>() {
+            @Override
+            public MailboxListener.ListenerType answer(InvocationOnMock 
invocation) throws Throwable {
+                return MailboxListener.ListenerType.ONCE;
+            }
+        });
+        doThrow(new RuntimeException()).when(mockedListener).event(event);
+        defaultDelegatingMailboxListener.addGlobalListener(mockedListener, 
null);
+        defaultDelegatingMailboxListener.event(event);
+    }
+
 }



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

Reply via email to