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 2015/11/28 16:30:09 UTC
svn commit: r1716987 - in /james/project/trunk/mailbox/store/src:
main/java/org/apache/james/mailbox/store/event/
main/java/org/apache/james/mailbox/store/event/distributed/
test/java/org/apache/james/mailbox/store/event/
Author: btellier
Date: Sat Nov 28 15:30:09 2015
New Revision: 1716987
URL: http://svn.apache.org/viewvc?rev=1716987&view=rev
Log:
MAILBOX-259 Introduce event delivery, and a synchronous and asynchronous delivery
Added:
james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/AsynchronousEventDelivery.java
james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventDelivery.java
james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/SynchronousEventDelivery.java
james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/AsynchronousEventDeliveryTest.java
james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/SynchronousEventDeliveryTest.java
Modified:
james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListener.java
james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/distributed/BroadcastDelegatingMailboxListener.java
james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/distributed/RegisteredDelegatingMailboxListener.java
james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListenerTest.java
Added: james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/AsynchronousEventDelivery.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/AsynchronousEventDelivery.java?rev=1716987&view=auto
==============================================================================
--- james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/AsynchronousEventDelivery.java (added)
+++ james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/AsynchronousEventDelivery.java Sat Nov 28 15:30:09 2015
@@ -0,0 +1,52 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.mailbox.store.event;
+
+import org.apache.james.mailbox.MailboxListener;
+
+import javax.annotation.PreDestroy;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+public class AsynchronousEventDelivery implements EventDelivery {
+
+ private final ExecutorService threadPoolExecutor;
+ private final SynchronousEventDelivery synchronousEventDelivery;
+
+ public AsynchronousEventDelivery(int threadPoolSize) {
+ this.threadPoolExecutor = Executors.newFixedThreadPool(threadPoolSize);
+ this.synchronousEventDelivery = new SynchronousEventDelivery();
+ }
+
+ @Override
+ public void deliver(final MailboxListener mailboxListener, final MailboxListener.Event event) {
+ threadPoolExecutor.submit(new Runnable() {
+ @Override
+ public void run() {
+ synchronousEventDelivery.deliver(mailboxListener, event);
+ }
+ });
+ }
+
+ @PreDestroy
+ public void stop() {
+ threadPoolExecutor.shutdownNow();
+ }
+}
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=1716987&r1=1716986&r2=1716987&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 15:30:09 2015
@@ -34,7 +34,8 @@ import org.apache.james.mailbox.model.Ma
*/
public class DefaultDelegatingMailboxListener implements DelegatingMailboxListener {
- private MailboxListenerRegistry registry;
+ private final MailboxListenerRegistry registry;
+ private final EventDelivery eventDelivery;
@Override
public ListenerType getType() {
@@ -42,7 +43,12 @@ public class DefaultDelegatingMailboxLis
}
public DefaultDelegatingMailboxListener() {
+ this(new SynchronousEventDelivery());
+ }
+
+ public DefaultDelegatingMailboxListener(EventDelivery eventDelivery) {
this.registry = new MailboxListenerRegistry();
+ this.eventDelivery = eventDelivery;
}
@Override
@@ -86,27 +92,13 @@ public class DefaultDelegatingMailboxLis
protected void deliverEventToMailboxListeners(Event event, Collection<MailboxListener> listenerSnapshot) {
for (MailboxListener listener : listenerSnapshot) {
- deliverEvent(event, listener);
+ eventDelivery.deliver(listener, event);
}
}
protected void deliverEventToGlobalListeners(Event event) {
for (MailboxListener mailboxListener : registry.getGlobalListeners()) {
- deliverEvent(event, mailboxListener);
- }
- }
-
- private void deliverEvent(Event event, MailboxListener listener) {
- try {
- listener.event(event);
- } catch(Throwable throwable) {
- event.getSession()
- .getLog()
- .error("Error while processing listener "
- + listener.getClass().getCanonicalName()
- + " for "
- + event.getClass().getCanonicalName(),
- throwable);
+ eventDelivery.deliver(mailboxListener, event);
}
}
Added: james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventDelivery.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventDelivery.java?rev=1716987&view=auto
==============================================================================
--- james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventDelivery.java (added)
+++ james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventDelivery.java Sat Nov 28 15:30:09 2015
@@ -0,0 +1,28 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.mailbox.store.event;
+
+import org.apache.james.mailbox.MailboxListener;
+
+public interface EventDelivery {
+
+ void deliver(MailboxListener mailboxListener, MailboxListener.Event event);
+
+}
Modified: james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java?rev=1716987&r1=1716986&r2=1716987&view=diff
==============================================================================
--- james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java (original)
+++ james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java Sat Nov 28 15:30:09 2015
@@ -1,4 +1,21 @@
-
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
package org.apache.james.mailbox.store.event;
Added: james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/SynchronousEventDelivery.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/SynchronousEventDelivery.java?rev=1716987&view=auto
==============================================================================
--- james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/SynchronousEventDelivery.java (added)
+++ james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/SynchronousEventDelivery.java Sat Nov 28 15:30:09 2015
@@ -0,0 +1,40 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.mailbox.store.event;
+
+import org.apache.james.mailbox.MailboxListener;
+
+public class SynchronousEventDelivery implements EventDelivery {
+
+ @Override
+ public void deliver(MailboxListener mailboxListener, MailboxListener.Event event) {
+ try {
+ mailboxListener.event(event);
+ } catch(Throwable throwable) {
+ event.getSession()
+ .getLog()
+ .error("Error while processing listener "
+ + mailboxListener.getClass().getCanonicalName()
+ + " for "
+ + event.getClass().getCanonicalName(),
+ throwable);
+ }
+ }
+}
Modified: james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/distributed/BroadcastDelegatingMailboxListener.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/distributed/BroadcastDelegatingMailboxListener.java?rev=1716987&r1=1716986&r2=1716987&view=diff
==============================================================================
--- james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/distributed/BroadcastDelegatingMailboxListener.java (original)
+++ james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/distributed/BroadcastDelegatingMailboxListener.java Sat Nov 28 15:30:09 2015
@@ -23,8 +23,10 @@ import org.apache.james.mailbox.MailboxL
import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.store.event.EventDelivery;
import org.apache.james.mailbox.store.event.EventSerializer;
import org.apache.james.mailbox.store.event.MailboxListenerRegistry;
+import org.apache.james.mailbox.store.event.SynchronousEventDelivery;
import org.apache.james.mailbox.store.publisher.MessageConsumer;
import org.apache.james.mailbox.store.publisher.Publisher;
import org.apache.james.mailbox.store.publisher.Topic;
@@ -41,19 +43,29 @@ public class BroadcastDelegatingMailboxL
private final Publisher publisher;
private final EventSerializer eventSerializer;
private final Topic globalTopic;
+ private final EventDelivery eventDelivery;
public BroadcastDelegatingMailboxListener(Publisher publisher,
MessageConsumer messageConsumer,
EventSerializer eventSerializer,
+ EventDelivery eventDelivery,
String globalTopic) throws Exception {
this.mailboxListenerRegistry = new MailboxListenerRegistry();
this.publisher = publisher;
this.eventSerializer = eventSerializer;
this.globalTopic = new Topic(globalTopic);
+ this.eventDelivery = eventDelivery;
messageConsumer.setMessageReceiver(this);
messageConsumer.init(this.globalTopic);
}
+ public BroadcastDelegatingMailboxListener(Publisher publisher,
+ MessageConsumer messageConsumer,
+ EventSerializer eventSerializer,
+ String globalTopic) throws Exception {
+ this(publisher, messageConsumer, eventSerializer, new SynchronousEventDelivery(), globalTopic);
+ }
+
@Override
public ListenerType getType() {
return ListenerType.ONCE;
@@ -108,29 +120,16 @@ public class BroadcastDelegatingMailboxL
mailboxListenerRegistry.handleRename(renamed.getMailboxPath(), renamed.getNewPath());
}
for (MailboxListener listener : listenerSnapshot) {
- deliverEvent(event, listener);
+ eventDelivery.deliver(listener, event);
}
}
private void deliverEventToGlobalListeners(Event event, ListenerType type) {
for (MailboxListener mailboxListener : mailboxListenerRegistry.getGlobalListeners()) {
if (mailboxListener.getType() == type) {
- deliverEvent(event, mailboxListener);
+ eventDelivery.deliver(mailboxListener, event);
}
}
}
- private void deliverEvent(Event event, MailboxListener listener) {
- 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/main/java/org/apache/james/mailbox/store/event/distributed/RegisteredDelegatingMailboxListener.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/distributed/RegisteredDelegatingMailboxListener.java?rev=1716987&r1=1716986&r2=1716987&view=diff
==============================================================================
--- james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/distributed/RegisteredDelegatingMailboxListener.java (original)
+++ james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/distributed/RegisteredDelegatingMailboxListener.java Sat Nov 28 15:30:09 2015
@@ -23,8 +23,10 @@ import org.apache.james.mailbox.MailboxL
import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.store.event.EventDelivery;
import org.apache.james.mailbox.store.event.EventSerializer;
import org.apache.james.mailbox.store.event.MailboxListenerRegistry;
+import org.apache.james.mailbox.store.event.SynchronousEventDelivery;
import org.apache.james.mailbox.store.publisher.MessageConsumer;
import org.apache.james.mailbox.store.publisher.Publisher;
import org.apache.james.mailbox.store.publisher.Topic;
@@ -42,19 +44,29 @@ public class RegisteredDelegatingMailbox
private final MailboxPathRegister mailboxPathRegister;
private final Publisher publisher;
private final EventSerializer eventSerializer;
+ private final EventDelivery eventDelivery;
public RegisteredDelegatingMailboxListener(EventSerializer eventSerializer,
Publisher publisher,
MessageConsumer messageConsumer,
- MailboxPathRegister mailboxPathRegister) throws Exception {
+ MailboxPathRegister mailboxPathRegister,
+ EventDelivery eventDelivery) throws Exception {
this.eventSerializer = eventSerializer;
this.publisher = publisher;
this.mailboxPathRegister = mailboxPathRegister;
this.mailboxListenerRegistry = new MailboxListenerRegistry();
+ this.eventDelivery = eventDelivery;
messageConsumer.setMessageReceiver(this);
messageConsumer.init(mailboxPathRegister.getLocalTopic());
}
+ public RegisteredDelegatingMailboxListener(EventSerializer eventSerializer,
+ Publisher publisher,
+ MessageConsumer messageConsumer,
+ MailboxPathRegister mailboxPathRegister) throws Exception {
+ this(eventSerializer, publisher, messageConsumer, mailboxPathRegister, new SynchronousEventDelivery());
+ }
+
@Override
public ListenerType getType() {
return ListenerType.ONCE;
@@ -118,14 +130,14 @@ public class RegisteredDelegatingMailbox
mailboxPathRegister.doRename(renamed.getMailboxPath(), renamed.getNewPath());
}
for (MailboxListener listener : listenerSnapshot) {
- deliverEvent(event, listener);
+ eventDelivery.deliver(listener, event);
}
}
private void deliverEventToOnceGlobalListeners(Event event) {
for (MailboxListener mailboxListener : mailboxListenerRegistry.getGlobalListeners()) {
if (mailboxListener.getType() == ListenerType.ONCE) {
- deliverEvent(event, mailboxListener);
+ eventDelivery.deliver(mailboxListener, event);
}
}
}
@@ -157,18 +169,4 @@ public class RegisteredDelegatingMailbox
}
}
- private void deliverEvent(Event event, MailboxListener listener) {
- try {
- listener.event(event);
- } catch(Throwable throwable) {
- event.getSession()
- .getLog()
- .error("Error while processing listener "
- + listener.getClass().getCanonicalName()
- + " for "
- + event.getClass().getCanonicalName(),
- throwable);
- }
- }
-
}
Added: james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/AsynchronousEventDeliveryTest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/AsynchronousEventDeliveryTest.java?rev=1716987&view=auto
==============================================================================
--- james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/AsynchronousEventDeliveryTest.java (added)
+++ james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/AsynchronousEventDeliveryTest.java Sat Nov 28 15:30:09 2015
@@ -0,0 +1,113 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.mailbox.store.event;
+
+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.verify;
+
+import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.mailbox.mock.MockMailboxSession;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.atomic.AtomicLong;
+
+public class AsynchronousEventDeliveryTest {
+
+ public class WaitMailboxListener implements MailboxListener {
+
+ private final AtomicLong invocationCount;
+
+ public WaitMailboxListener() {
+ invocationCount = new AtomicLong(0);
+ }
+
+ public AtomicLong getInvocationCount() {
+ return invocationCount;
+ }
+
+ @Override
+ public ListenerType getType() {
+ return ListenerType.MAILBOX;
+ }
+
+ @Override
+ public void event(Event event) {
+ try {
+ Thread.sleep(100);
+ invocationCount.incrementAndGet();
+ } catch (InterruptedException e) {
+ LOGGER.info("interrupted", e);
+ }
+ }
+ }
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(AsynchronousEventDeliveryTest.class);
+
+ private MailboxListener mailboxListener;
+ private AsynchronousEventDelivery asynchronousEventDelivery;
+
+ @Before
+ public void setUp() {
+ mailboxListener = mock(MailboxListener.class);
+ asynchronousEventDelivery = new AsynchronousEventDelivery(2);
+ }
+
+ @After
+ public void tearDown() {
+ asynchronousEventDelivery.stop();
+ }
+
+ @Test
+ public void deliverShouldWork() throws Exception {
+ MailboxListener.Event event = new MailboxListener.Event(null, null) {};
+ asynchronousEventDelivery.deliver(mailboxListener, event);
+ Thread.sleep(100);
+ verify(mailboxListener).event(event);
+ }
+
+ @Test
+ public void deliverShouldNotPropagateException() throws Exception {
+ MailboxListener.Event event = new MailboxListener.Event(new MockMailboxSession("test"), null) {};
+ doThrow(new RuntimeException()).when(mailboxListener).event(event);
+ asynchronousEventDelivery.deliver(mailboxListener, event);
+ Thread.sleep(100);
+ verify(mailboxListener).event(event);
+ }
+
+ @Test
+ public void deliverShouldWorkWhenThePoolIsFull() throws Exception {
+ MailboxListener.Event event = new MailboxListener.Event(new MockMailboxSession("test"), null) {};
+ WaitMailboxListener waitMailboxListener = new WaitMailboxListener();
+ long operationCount = 10;
+ for (int i = 0; i < operationCount; i++) {
+ asynchronousEventDelivery.deliver(waitMailboxListener, event);
+ }
+ Thread.sleep(2000);
+ assertThat(waitMailboxListener.getInvocationCount().get()).isEqualTo(operationCount);
+ }
+
+}
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=1716987&r1=1716986&r2=1716987&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 15:30:09 2015
@@ -21,12 +21,8 @@ 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;
Added: james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/SynchronousEventDeliveryTest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/SynchronousEventDeliveryTest.java?rev=1716987&view=auto
==============================================================================
--- james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/SynchronousEventDeliveryTest.java (added)
+++ james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/SynchronousEventDeliveryTest.java Sat Nov 28 15:30:09 2015
@@ -0,0 +1,57 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.mailbox.store.event;
+
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.mailbox.mock.MockMailboxSession;
+import org.junit.Before;
+import org.junit.Test;
+
+public class SynchronousEventDeliveryTest {
+
+ private MailboxListener mailboxListener;
+ private SynchronousEventDelivery synchronousEventDelivery;
+
+ @Before
+ public void setUp() {
+ mailboxListener = mock(MailboxListener.class);
+ synchronousEventDelivery = new SynchronousEventDelivery();
+ }
+
+ @Test
+ public void deliverShouldWork() {
+ MailboxListener.Event event = new MailboxListener.Event(null, null) {};
+ synchronousEventDelivery.deliver(mailboxListener, event);
+ verify(mailboxListener).event(event);
+ }
+
+ @Test
+ public void deliverShouldNotPropagateException() {
+ MailboxListener.Event event = new MailboxListener.Event(new MockMailboxSession("test"), null) {};
+ doThrow(new RuntimeException()).when(mailboxListener).event(event);
+ synchronousEventDelivery.deliver(mailboxListener, event);
+ verify(mailboxListener).event(event);
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org