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/02 10:34:14 UTC

[04/11] james-project git commit: MAILBOX-370 EventBus should not dispatch noop events

MAILBOX-370 EventBus should not dispatch noop events


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

Branch: refs/heads/master
Commit: 59996dc07cd350a5f542b09ac7b983755c2dca80
Parents: df5d4c1
Author: Benoit Tellier <bt...@linagora.com>
Authored: Fri Dec 28 11:39:19 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Jan 2 17:28:02 2019 +0700

----------------------------------------------------------------------
 .../james/mailbox/events/EventBusContract.java  | 29 ++++++++++++++++++++
 .../james/mailbox/events/InVMEventBus.java      |  5 +++-
 2 files changed, 33 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/59996dc0/mailbox/api/src/test/java/org/apache/james/mailbox/events/EventBusContract.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/events/EventBusContract.java b/mailbox/api/src/test/java/org/apache/james/mailbox/events/EventBusContract.java
index d884076..236ee75 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/events/EventBusContract.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/events/EventBusContract.java
@@ -28,18 +28,23 @@ 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.verifyZeroInteractions;
 import static org.mockito.Mockito.when;
 
 import java.time.Duration;
 import java.util.concurrent.CountDownLatch;
 
+import org.apache.james.core.User;
 import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.TestId;
 import org.junit.jupiter.api.Test;
 
 import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableSortedMap;
 
 public interface EventBusContract {
     MailboxListener.MailboxEvent event = mock(MailboxListener.MailboxEvent.class);
@@ -74,6 +79,30 @@ public interface EventBusContract {
     }
 
     @Test
+    default void groupListenersShouldNotReceiveNoopEvents() {
+        MailboxListener listener = newListener();
+
+        eventBus().register(listener, new GroupA());
+
+        MailboxListener.Added noopEvent = new MailboxListener.Added(MailboxSession.SessionId.of(18), User.fromUsername("bob"), MailboxPath.forUser("bob", "mailbox"), TestId.of(58), ImmutableSortedMap.of());
+        eventBus().dispatch(noopEvent, NO_KEYS).block();
+
+        verifyNoMoreInteractions(listener);
+    }
+
+    @Test
+    default void registeredListenersShouldNotReceiveNoopEvents() {
+        MailboxListener listener = newListener();
+
+        eventBus().register(listener, KEY_1);
+
+        MailboxListener.Added noopEvent = new MailboxListener.Added(MailboxSession.SessionId.of(18), User.fromUsername("bob"), MailboxPath.forUser("bob", "mailbox"), TestId.of(58), ImmutableSortedMap.of());
+        eventBus().dispatch(noopEvent, KEY_1).block();
+
+        verifyNoMoreInteractions(listener);
+    }
+
+    @Test
     default void dispatchShouldNotThrowWhenAGroupListenerFails() {
         MailboxListener listener = newListener();
         doThrow(new RuntimeException()).when(listener).event(any());

http://git-wip-us.apache.org/repos/asf/james-project/blob/59996dc0/mailbox/event/event-memory/src/main/java/org/apache/james/mailbox/events/InVMEventBus.java
----------------------------------------------------------------------
diff --git a/mailbox/event/event-memory/src/main/java/org/apache/james/mailbox/events/InVMEventBus.java b/mailbox/event/event-memory/src/main/java/org/apache/james/mailbox/events/InVMEventBus.java
index fb4aee3..0f452bf 100644
--- a/mailbox/event/event-memory/src/main/java/org/apache/james/mailbox/events/InVMEventBus.java
+++ b/mailbox/event/event-memory/src/main/java/org/apache/james/mailbox/events/InVMEventBus.java
@@ -62,7 +62,10 @@ public class InVMEventBus implements EventBus {
 
     @Override
     public Mono<Void> dispatch(Event event, Set<RegistrationKey> keys) {
-        return eventDelivery.deliver(registeredListeners(keys), event).synchronousListenerFuture();
+        if (!event.isNoop()) {
+            return eventDelivery.deliver(registeredListeners(keys), event).synchronousListenerFuture();
+        }
+        return Mono.empty();
     }
 
     private Set<MailboxListener> registeredListeners(Set<RegistrationKey> keys) {


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org