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/18 11:06:58 UTC

[2/3] james-project git commit: MAILBOX-372 RabbitMQEventBus should receive events didn't fully processed

MAILBOX-372 RabbitMQEventBus should receive events didn't fully processed


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

Branch: refs/heads/master
Commit: b3ec659cf6485be441be81fe515f6cbe4919d5a1
Parents: c216bce
Author: tran tien duc <dt...@linagora.com>
Authored: Thu Jan 17 15:47:02 2019 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Jan 18 18:02:08 2019 +0700

----------------------------------------------------------------------
 .../mailbox/events/RabbitMQEventBusTest.java    | 40 ++++++++++++++++++++
 1 file changed, 40 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/b3ec659c/mailbox/event/event-rabbitmq/src/test/java/org/apache/james/mailbox/events/RabbitMQEventBusTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/event-rabbitmq/src/test/java/org/apache/james/mailbox/events/RabbitMQEventBusTest.java b/mailbox/event/event-rabbitmq/src/test/java/org/apache/james/mailbox/events/RabbitMQEventBusTest.java
index ffcdac8..feaf712 100644
--- a/mailbox/event/event-rabbitmq/src/test/java/org/apache/james/mailbox/events/RabbitMQEventBusTest.java
+++ b/mailbox/event/event-rabbitmq/src/test/java/org/apache/james/mailbox/events/RabbitMQEventBusTest.java
@@ -32,12 +32,16 @@ import static org.apache.james.mailbox.events.EventBusTestFixture.GroupA;
 import static org.apache.james.mailbox.events.EventBusTestFixture.KEY_1;
 import static org.apache.james.mailbox.events.EventBusTestFixture.MailboxListenerCountingSuccessfulExecution;
 import static org.apache.james.mailbox.events.EventBusTestFixture.NO_KEYS;
+import static org.apache.james.mailbox.events.EventBusTestFixture.WAIT_CONDITION;
 import static org.apache.james.mailbox.events.EventBusTestFixture.newListener;
 import static org.apache.james.mailbox.events.RabbitMQEventBus.MAILBOX_EVENT;
 import static org.apache.james.mailbox.events.RabbitMQEventBus.MAILBOX_EVENT_EXCHANGE_NAME;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
 
 import java.nio.charset.StandardCharsets;
 import java.time.Duration;
@@ -63,6 +67,7 @@ import org.junit.jupiter.api.extension.AfterEachCallback;
 import org.junit.jupiter.api.extension.BeforeEachCallback;
 import org.junit.jupiter.api.extension.ExtensionContext;
 import org.junit.jupiter.api.extension.RegisterExtension;
+import org.mockito.stubbing.Answer;
 
 import com.rabbitmq.client.Connection;
 
@@ -200,6 +205,41 @@ class RabbitMQEventBusTest implements GroupContract.SingleEventBusGroupContract,
     }
 
     @Nested
+    class AtLeastOnceTest {
+
+        @Test
+        void inProcessingEventShouldBeReDispatchedToAnotherEventBusWhenOneIsDown() {
+            MailboxListenerCountingSuccessfulExecution eventBusListener = spy(new EventBusTestFixture.MailboxListenerCountingSuccessfulExecution());
+            MailboxListenerCountingSuccessfulExecution eventBus2Listener = spy(new EventBusTestFixture.MailboxListenerCountingSuccessfulExecution());
+            MailboxListenerCountingSuccessfulExecution eventBus3Listener = spy(new EventBusTestFixture.MailboxListenerCountingSuccessfulExecution());
+            Answer callEventAndSleepForever = invocation -> {
+                invocation.callRealMethod();
+                TimeUnit.SECONDS.sleep(Long.MAX_VALUE);
+                return null;
+            };
+
+            doAnswer(callEventAndSleepForever).when(eventBusListener).event(any());
+            doAnswer(callEventAndSleepForever).when(eventBus2Listener).event(any());
+
+            eventBus.register(eventBusListener, GROUP_A);
+            eventBus2.register(eventBus2Listener, GROUP_A);
+            eventBus3.register(eventBus3Listener, GROUP_A);
+
+            eventBus.dispatch(EVENT, NO_KEYS).block();
+            WAIT_CONDITION
+                .until(() -> assertThat(eventBusListener.numberOfEventCalls()).isEqualTo(1));
+            eventBus.stop();
+
+            WAIT_CONDITION
+                .until(() -> assertThat(eventBus2Listener.numberOfEventCalls()).isEqualTo(1));
+            eventBus2.stop();
+
+            WAIT_CONDITION
+                .until(() -> assertThat(eventBus3Listener.numberOfEventCalls()).isEqualTo(1));
+        }
+    }
+
+    @Nested
     class PublishingTest {
         private static final String MAILBOX_WORK_QUEUE_NAME = MAILBOX_EVENT + "-workQueue";
 


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