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 2020/06/21 09:16:23 UTC

[james-project] branch master updated (7f08147 -> 3567a93)

This is an automated email from the ASF dual-hosted git repository.

btellier pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git.


    from 7f08147  JAMES-3208 Add SizeGreaterThan integration test
     new 91617ef  JAMES-3253 RemoteDelivery maxRetries configuration examples should be valid
     new 506d881  JAMES-3252 DomainList autoDection should be turned off by default
     new fae3ece  JAMES-3202 Add get document action to ElasticSearchIndexer
     new 6835041  JAMES-3202 Add `retrieveIndexedFlags` in MessageSearchIndex API
     new cc8848f  JAMES-3202 implement `retrieveIndexedFlags` in ElasticSearchListeningMessageSearchIndex
     new 1b5a9c7  JAMES-3202 implement `retrieveIndexedFlags` in LuceneMailboxMessageSearchIndexTest
     new 9173eea  JAMES-3202 test name fixes in ReIndexerImplTest
     new 013d7a5  JAMES-3167 Add MailboxReactorUtils
     new 5ccf47c  JAMES-3167 Reactify MailboxMapper
     new 2aefb06  JAMES-3167 Improve MailboxManagerTest coverage to avoid bug detection upon MPT IMAP tests run
     new e7015c2  JAMES-3167 Rework mailbox right merging
     new 3567a93  JAMES-3167 Reactify right management in StoreMessageIdManager

The 12 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 CHANGELOG.md                                       |   1 +
 .../james/backends/es/ElasticSearchIndexer.java    |  14 +
 .../backends/es/ReactorElasticSearchClient.java    |   6 +
 .../backends/es/ElasticSearchIndexerTest.java      |  26 ++
 .../cassandra-ldap/destination/conf/domainlist.xml |   7 +-
 .../destination/conf/mailetcontainer.xml           |   2 +-
 .../destination/conf/domainlist.xml                |   7 +-
 .../destination/conf/mailetcontainer.xml           |   2 +-
 .../destination/conf/domainlist.xml                |   7 +-
 .../destination/conf/mailetcontainer.xml           |   2 +-
 .../cassandra/destination/conf/domainlist.xml      |   7 +-
 .../cassandra/destination/conf/mailetcontainer.xml |   2 +-
 .../guice/jpa-smtp/destination/conf/domainlist.xml |   5 +-
 .../jpa-smtp/destination/conf/mailetcontainer.xml  |   2 +-
 .../run/guice/jpa/destination/conf/domainlist.xml  |   7 +-
 .../guice/jpa/destination/conf/mailetcontainer.xml |   2 +-
 .../guice/memory/destination/conf/domainlist.xml   |   7 +-
 .../memory/destination/conf/mailetcontainer.xml    |   2 +-
 .../run/spring/destination/conf/domainlist.xml     |   7 +-
 .../spring/destination/conf/mailetcontainer.xml    |   2 +-
 .../org/apache/james/mailbox/FlagsBuilder.java     |  42 +++
 .../org/apache/james/mailbox/MailboxManager.java   |   4 +-
 .../org/apache/james/mailbox/RightManager.java     |   4 +-
 .../apache/james/mailbox/MailboxManagerTest.java   |  61 +++-
 .../james/mailbox/backup/DefaultMailboxBackup.java |   2 +-
 .../mailbox/cassandra/mail/CassandraACLMapper.java |  14 +-
 .../cassandra/mail/CassandraMailboxMapper.java     |  62 ++---
 .../cassandra/mail/CassandraMessageIdMapper.java   |  27 +-
 .../mail/task/MailboxMergingTaskRunner.java        |  30 +-
 .../CassandraMailboxManagerConsistencyTest.java    |  50 ++--
 .../cassandra/mail/CassandraACLMapperTest.java     |  27 +-
 .../CassandraMailboxMapperConcurrencyTest.java     |   6 +-
 .../cassandra/mail/CassandraMailboxMapperTest.java | 180 ++++++------
 .../mail/migration/MailboxPathV2MigrationTest.java |  11 +-
 .../ElasticSearchListeningMessageSearchIndex.java  |  51 +++-
 ...asticSearchListeningMessageSearchIndexTest.java |  31 ++-
 .../james/mailbox/jpa/mail/JPAMailboxMapper.java   | 159 +++++------
 .../jpa/mail/TransactionalMailboxMapper.java       |  27 +-
 .../lucene/search/LuceneMessageSearchIndex.java    |  61 +++-
 .../LuceneMailboxMessageSearchIndexTest.java       |  76 +++++
 .../mailbox/maildir/mail/MaildirMailboxMapper.java | 306 +++++++++++----------
 .../DomainUserMaildirMailboxManagerTest.java       |   5 +
 .../InMemoryMailboxSessionMapperFactory.java       |   2 +-
 .../inmemory/mail/InMemoryMailboxMapper.java       | 100 +++----
 .../inmemory/mail/InMemoryMessageIdMapper.java     |   9 +-
 .../james/vault/DeletedMessageVaultHook.java       |  27 +-
 .../mailbox/spamassassin/SpamAssassinListener.java |   4 +-
 .../spamassassin/SpamAssassinListenerTest.java     |  12 +-
 ...ctionalMapper.java => MailboxReactorUtils.java} |  54 ++--
 .../store/StoreMailboxAnnotationManager.java       |   5 +-
 .../james/mailbox/store/StoreMailboxManager.java   | 251 +++++++----------
 .../james/mailbox/store/StoreMessageIdManager.java | 125 ++++-----
 .../james/mailbox/store/StoreRightManager.java     |  75 +++--
 .../mailbox/store/SystemMailboxesProviderImpl.java |   2 +-
 .../james/mailbox/store/mail/MailboxMapper.java    |  52 +---
 .../store/quota/DefaultUserQuotaRootResolver.java  |   2 +-
 .../store/search/LazyMessageSearchIndex.java       | 306 +++++++++++----------
 .../store/search/ListeningMessageSearchIndex.java  |  13 +-
 .../store/search/SimpleMessageSearchIndex.java     |   3 +-
 .../james/mailbox/store/transaction/Mapper.java    |   2 +-
 .../store/transaction/TransactionalMapper.java     |  20 +-
 .../mailbox/store/MailboxReactorUtilsTest.java}    |  39 +--
 .../mailbox/store/MessageIdManagerTestSystem.java  |   6 +-
 .../store/StoreMailboxManagerAnnotationTest.java   |  28 +-
 .../mailbox/store/StoreMailboxManagerTest.java     |  12 +-
 .../james/mailbox/store/StoreRightManagerTest.java |  12 +-
 .../store/SystemMailboxesProviderImplTest.java     |   4 +
 .../store/mail/model/MailboxMapperACLTest.java     | 137 ++++-----
 .../store/mail/model/MailboxMapperTest.java        |  79 +++---
 .../store/mail/model/MessageIdMapperTest.java      |   2 +-
 .../store/mail/model/MessageMapperTest.java        |   2 +-
 .../mailbox/store/mail/model/MessageMoveTest.java  |   4 +-
 .../quota/DefaultUserQuotaRootResolverTest.java    |   4 +-
 .../ListeningMessageSearchIndexContract.java       | 149 ++++++++++
 .../mailbox/tools/indexer/ReIndexerImpl.java       |   3 +-
 .../mailbox/tools/indexer/ReIndexerPerformer.java  |  10 +-
 .../mailbox/tools/indexer/ReIndexerImplTest.java   |   4 +-
 .../apache/james/imap/processor/ListProcessor.java |  12 +-
 server/app/src/main/resources/domainlist.xml       |   4 +-
 server/app/src/main/resources/mailetcontainer.xml  |   2 +-
 .../src/test/resources/mailetcontainer.xml         |   2 +-
 .../src/test/resources/mailetcontainer.xml         |   2 +-
 .../src/test/resources/mailetcontainer.xml         |   2 +-
 .../src/test/resources/mailetcontainer.xml         |   2 +-
 .../src/test/resources/mailetcontainer.xml         |   2 +-
 .../src/test/resources/mailetcontainer.xml         |   2 +-
 .../sample-configuration/domainlist.xml            |   7 +-
 .../jpa-smtp/sample-configuration/domainlist.xml   |   7 +-
 .../sample-configuration/mailetcontainer.xml       |   2 +-
 .../org/apache/james/modules/MailboxProbeImpl.java |  12 +-
 .../sample-configuration/domainlist.xml            |   7 +-
 .../sample-configuration/mailetcontainer.xml       |   2 +-
 .../org/apache/james/FakeMessageSearchIndex.java   |   7 +
 .../src/test/resources/mailetcontainer.xml         |   2 +-
 .../adapter/mailbox/MailboxManagerManagement.java  |   4 +-
 .../adapter/mailbox/MailboxManagementTest.java     |  46 ++--
 .../domainlist/lib/DomainListConfiguration.java    |   6 +-
 .../lib/DomainListConfigurationTest.java           |  25 +-
 .../rrt/lib/AliasReverseResolverImplTest.java      |   4 +-
 .../apache/james/rrt/lib/CanSendFromImplTest.java  |   4 +-
 .../mailets/configuration/CommonProcessors.java    |   2 +-
 .../impl/JamesMailetContextTest.java               |  14 -
 .../james/transport/mailets/RandomStoring.java     |   2 +-
 .../src/test/resources/mailetcontainer.xml         |   2 +-
 .../src/test/resources/mailetcontainer.xml         |   2 +-
 .../src/test/resources/mailetcontainer.xml         |   2 +-
 .../jmap/draft/methods/GetMailboxesMethod.java     |   2 +-
 .../jmap/draft/methods/GetMailboxesMethodTest.java |   2 +-
 .../methods/SetMessagesCreationProcessorTest.java  |   4 +-
 .../methods/SetMessagesUpdateProcessorTest.java    |   9 +-
 .../james/jmap/draft/model/MailboxFactoryTest.java |   2 +-
 .../event/PropagateLookupRightListenerTest.java    |  28 +-
 .../src/test/resources/mailetcontainer.xml         |   2 +-
 .../src/test/resources/mailetcontainer.xml         |   2 +-
 .../james/jmap/method/MailboxGetMethod.scala       |   2 +-
 .../src/test/resources/mailetcontainer.xml         |   2 +-
 .../src/test/resources/mailetcontainer.xml         |   2 +-
 .../james/webadmin/routes/AliasRoutesTest.java     |   4 +-
 .../james/webadmin/routes/ForwardRoutesTest.java   |   4 +-
 .../jmap/MessageFastViewProjectionCorrector.java   |  23 +-
 .../routes/DeletedMessagesVaultRoutesTest.java     |   4 +-
 .../webadmin/service/UserMailboxesService.java     |   2 +-
 .../routes/ScanningQuotaSearchExtension.java       |   4 +-
 .../webadmin/routes/UserMailboxesRoutesTest.java   |  29 +-
 src/site/xdoc/server/config-domainlist.xml         |   4 +-
 125 files changed, 1778 insertions(+), 1454 deletions(-)
 copy mailbox/store/src/main/java/org/apache/james/mailbox/store/{transaction/TransactionalMapper.java => MailboxReactorUtils.java} (59%)
 copy mailbox/{api/src/test/java/org/apache/james/mailbox/ModSeqTest.java => store/src/test/java/org/apache/james/mailbox/store/MailboxReactorUtilsTest.java} (60%)
 create mode 100644 mailbox/store/src/test/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndexContract.java
 copy core/src/test/java/org/apache/james/core/quota/QuotaLimitValueTest.java => server/data/data-library/src/test/java/org/apache/james/domainlist/lib/DomainListConfigurationTest.java (66%)


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


[james-project] 07/12: JAMES-3202 test name fixes in ReIndexerImplTest

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 9173eea87f6f3cd10d89cdeba0871094e136247a
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Fri Jun 12 15:04:32 2020 +0700

    JAMES-3202 test name fixes in ReIndexerImplTest
---
 .../ElasticSearchListeningMessageSearchIndex.java  |   2 +-
 ...asticSearchListeningMessageSearchIndexTest.java | 117 +++-------------
 .../LuceneMailboxMessageSearchIndexTest.java       |  95 +++----------
 .../store/search/LazyMessageSearchIndex.java       |   3 +-
 .../ListeningMessageSearchIndexContract.java       | 149 +++++++++++++++++++++
 .../mailbox/tools/indexer/ReIndexerImplTest.java   |   4 +-
 6 files changed, 192 insertions(+), 178 deletions(-)

diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
index e23882c..ddb016e 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
@@ -233,7 +233,7 @@ public class ElasticSearchListeningMessageSearchIndex extends ListeningMessageSe
             .filter(GetResponse::isExists)
             .map(GetResponse::getSourceAsMap)
             .map(this::extractFlags)
-            .switchIfEmpty(Mono.error(new IndexNotFoundException(
+            .switchIfEmpty(Mono.error(() -> new IndexNotFoundException(
                 String.format("Index for message %s in mailbox %s not found", uid.toString(), mailbox.getMailboxId().serialize()))));
     }
 
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
index 4f80bb0..b934ec3 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
@@ -37,7 +37,6 @@ import org.apache.james.backends.es.ReactorElasticSearchClient;
 import org.apache.james.core.Username;
 import org.apache.james.mailbox.Authorizator;
 import org.apache.james.mailbox.DefaultMailboxes;
-import org.apache.james.mailbox.FlagsBuilder;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.ModSeq;
@@ -76,9 +75,12 @@ import org.apache.james.mailbox.store.SessionProviderImpl;
 import org.apache.james.mailbox.store.extractor.DefaultTextExtractor;
 import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
+import org.apache.james.mailbox.store.search.ListeningMessageSearchIndex;
+import org.apache.james.mailbox.store.search.ListeningMessageSearchIndexContract;
 import org.awaitility.Duration;
 import org.elasticsearch.index.IndexNotFoundException;
 import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Nested;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.RegisterExtension;
 import org.testcontainers.shaded.com.google.common.collect.ImmutableList;
@@ -446,102 +448,27 @@ class ElasticSearchListeningMessageSearchIndexTest {
             .doesNotThrowAnyException();
     }
 
-    @Test
-    void retrieveIndexedFlagsShouldRetrieveSystemFlags() {
-        Flags flags = FlagsBuilder.builder()
-            .add(Flags.Flag.RECENT)
-            .add(Flags.Flag.DRAFT)
-            .build();
-
-        SimpleMailboxMessage message = MESSAGE_BUILDER.messageId(MESSAGE_ID_4)
-            .uid(MESSAGE_UID_4)
-            .flags(flags)
-            .build();
-
-        testee.add(session, mailbox, message).block();
-
-        assertThat(testee.retrieveIndexedFlags(mailbox, MESSAGE_UID_4).block())
-            .isEqualTo(flags);
-    }
-
-    @Test
-    void retrieveIndexedFlagsShouldReturnEmptyFlagsWhenNoFlags() {
-        Flags flags = new Flags();
-
-        SimpleMailboxMessage message = MESSAGE_BUILDER.messageId(MESSAGE_ID_4)
-            .uid(MESSAGE_UID_4)
-            .flags(flags)
-            .build();
-
-        testee.add(session, mailbox, message).block();
-
-        assertThat(testee.retrieveIndexedFlags(mailbox, MESSAGE_UID_4).block())
-            .isEqualTo(flags);
-    }
-
-    @Test
-    void retrieveIndexedFlagsShouldReturnAllSystemFlagsWhenAllFlagsSet() {
-        Flags flags = FlagsBuilder.builder()
-            .add(Flags.Flag.ANSWERED)
-            .add(Flags.Flag.DELETED)
-            .add(Flags.Flag.RECENT)
-            .add(Flags.Flag.DRAFT)
-            .add(Flags.Flag.FLAGGED)
-            .add(Flags.Flag.SEEN)
-            .build();
-
-        SimpleMailboxMessage message = MESSAGE_BUILDER.messageId(MESSAGE_ID_4)
-            .uid(MESSAGE_UID_4)
-            .flags(flags)
-            .build();
-
-        testee.add(session, mailbox, message).block();
-
-        assertThat(testee.retrieveIndexedFlags(mailbox, MESSAGE_UID_4).block())
-            .isEqualTo(flags);
-    }
-
-    @Test
-    void retrieveIndexedFlagsShouldReturnUserFlags() {
-        Flags flags = FlagsBuilder.builder()
-            .add("flag1")
-            .add("flag2")
-            .build();
-
-        SimpleMailboxMessage message = MESSAGE_BUILDER.messageId(MESSAGE_ID_4)
-            .uid(MESSAGE_UID_4)
-            .flags(flags)
-            .build();
-
-        testee.add(session, mailbox, message).block();
-
-        assertThat(testee.retrieveIndexedFlags(mailbox, MESSAGE_UID_4).block())
-            .isEqualTo(flags);
-    }
-
-    @Test
-    void retrieveIndexedFlagsShouldReturnUserAndSystemFlags() {
-        Flags flags = FlagsBuilder.builder()
-            .add(Flags.Flag.ANSWERED)
-            .add(Flags.Flag.DELETED)
-            .add("flag1")
-            .add("flag2")
-            .build();
-
-        SimpleMailboxMessage message = MESSAGE_BUILDER.messageId(MESSAGE_ID_4)
-            .uid(MESSAGE_UID_4)
-            .flags(flags)
-            .build();
+    @Nested
+    class RetrieveIndexedFlags implements ListeningMessageSearchIndexContract {
+        @Override
+        public ListeningMessageSearchIndex testee() {
+            return testee;
+        }
 
-        testee.add(session, mailbox, message).block();
+        @Override
+        public MailboxSession session() {
+            return session;
+        }
 
-        assertThat(testee.retrieveIndexedFlags(mailbox, MESSAGE_UID_4).block())
-            .isEqualTo(flags);
-    }
+        @Override
+        public Mailbox mailbox() {
+            return mailbox;
+        }
 
-    @Test
-    void retrieveIndexedFlagsShouldPropagateExceptionWhenNotFound() {
-        assertThatThrownBy(() -> testee.retrieveIndexedFlags(mailbox, MESSAGE_UID_4).block())
-            .isInstanceOf(IndexNotFoundException.class);
+        @Test
+        void retrieveIndexedFlagsShouldPropagateExceptionWhenNotFound() {
+            assertThatThrownBy(() -> testee.retrieveIndexedFlags(mailbox, MESSAGE_UID_4).block())
+                .isInstanceOf(IndexNotFoundException.class);
+        }
     }
 }
\ No newline at end of file
diff --git a/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMailboxMessageSearchIndexTest.java b/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMailboxMessageSearchIndexTest.java
index 15ac2a3..a0ec57c 100644
--- a/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMailboxMessageSearchIndexTest.java
+++ b/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMailboxMessageSearchIndexTest.java
@@ -35,7 +35,6 @@ import javax.mail.Flags;
 import javax.mail.Flags.Flag;
 
 import org.apache.james.core.Username;
-import org.apache.james.mailbox.FlagsBuilder;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MailboxSessionUtil;
 import org.apache.james.mailbox.MessageUid;
@@ -53,8 +52,11 @@ import org.apache.james.mailbox.model.TestMessageId;
 import org.apache.james.mailbox.model.UidValidity;
 import org.apache.james.mailbox.model.UpdatedFlags;
 import org.apache.james.mailbox.store.MessageBuilder;
+import org.apache.james.mailbox.store.search.ListeningMessageSearchIndex;
+import org.apache.james.mailbox.store.search.ListeningMessageSearchIndexContract;
 import org.apache.lucene.store.RAMDirectory;
 import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Nested;
 import org.junit.jupiter.api.Test;
 
 import com.google.common.collect.ImmutableList;
@@ -671,84 +673,21 @@ class LuceneMailboxMessageSearchIndexTest {
             .containsExactly(uid2);
     }
 
-    @Test
-    void retrieveIndexedFlagsShouldRetrieveSystemFlags() {
-        Flags expectedFlags = new Flags(Flag.ANSWERED);
-
-        assertThat(index.retrieveIndexedFlags(mailbox, uid1).block())
-            .isEqualTo(expectedFlags);
-    }
-
-    @Test
-    void retrieveIndexedFlagsShouldReturnEmptyFlagsWhenNoFlags() {
-        Flags expectedFlags = new Flags();
-
-        assertThat(index.retrieveIndexedFlags(mailbox, uid5).block())
-            .isEqualTo(expectedFlags);
-    }
-
-    @Test
-    void retrieveIndexedFlagsShouldReturnAllSystemFlagsWhenAllFlagsSet() {
-        Flags newFlags = FlagsBuilder.builder()
-            .add(Flags.Flag.ANSWERED)
-            .add(Flags.Flag.DELETED)
-            .add(Flags.Flag.RECENT)
-            .add(Flags.Flag.DRAFT)
-            .add(Flags.Flag.FLAGGED)
-            .add(Flags.Flag.SEEN)
-            .build();
-
-        UpdatedFlags updatedFlags = UpdatedFlags.builder()
-            .uid(uid2)
-            .modSeq(MOD_SEQ)
-            .oldFlags(new Flags(Flag.ANSWERED))
-            .newFlags(newFlags)
-            .build();
-
-        index.update(session, mailbox, Lists.newArrayList(updatedFlags)).block();
-
-        assertThat(index.retrieveIndexedFlags(mailbox, uid2).block())
-            .isEqualTo(newFlags);
-    }
-
-    @Test
-    void retrieveIndexedFlagsShouldReturnUserFlags() {
-        Flags newFlags = FlagsBuilder.builder()
-            .add("flag1")
-            .add("flag2")
-            .build();
-
-        UpdatedFlags updatedFlags = UpdatedFlags.builder()
-            .uid(uid2)
-            .modSeq(MOD_SEQ)
-            .oldFlags(new Flags(Flag.ANSWERED))
-            .newFlags(newFlags)
-            .build();
-
-        index.update(session, mailbox, Lists.newArrayList(updatedFlags)).block();
-
-        assertThat(index.retrieveIndexedFlags(mailbox, uid2).block())
-            .isEqualTo(newFlags);
-    }
+    @Nested
+    class RetrieveIndexedFlags implements ListeningMessageSearchIndexContract {
+        @Override
+        public ListeningMessageSearchIndex testee() {
+            return index;
+        }
 
-    @Test
-    void retrieveIndexedFlagsShouldReturnUserAndSystemFlags() {
-        Flags newFlags = FlagsBuilder.builder()
-            .add("flag1")
-            .add("flag2")
-            .add(Flag.DRAFT)
-            .build();
-
-        UpdatedFlags updatedFlags = UpdatedFlags.builder()
-            .uid(uid2)
-            .modSeq(MOD_SEQ)
-            .oldFlags(new Flags(Flag.ANSWERED))
-            .newFlags(newFlags)
-            .build();
-
-        index.update(session, mailbox, Lists.newArrayList(updatedFlags)).block();
+        @Override
+        public MailboxSession session() {
+            return session;
+        }
 
-        assertThat(index.retrieveIndexedFlags(mailbox, uid2).block())
-            .isEqualTo(newFlags);
+        @Override
+        public Mailbox mailbox() {
+            return mailbox;
+        }
     }
 }
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java
index 459cc22..e889b2b 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java
@@ -72,8 +72,7 @@ public class LazyMessageSearchIndex extends ListeningMessageSearchIndex {
     private final ListeningMessageSearchIndex index;
     private final ConcurrentHashMap<MailboxId, Object> indexed = new ConcurrentHashMap<>();
     private final MailboxSessionMapperFactory factory;
-    
-    
+
     public LazyMessageSearchIndex(ListeningMessageSearchIndex index, MailboxSessionMapperFactory factory, SessionProvider sessionProvider) {
         super(factory, sessionProvider);
         this.index = index;
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndexContract.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndexContract.java
new file mode 100644
index 0000000..98b0b19
--- /dev/null
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndexContract.java
@@ -0,0 +1,149 @@
+/****************************************************************
+ * 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.search;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Date;
+
+import javax.mail.Flags;
+import javax.mail.util.SharedByteArrayInputStream;
+
+import org.apache.james.mailbox.FlagsBuilder;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MessageUid;
+import org.apache.james.mailbox.ModSeq;
+import org.apache.james.mailbox.model.Mailbox;
+import org.apache.james.mailbox.model.MessageId;
+import org.apache.james.mailbox.model.TestMessageId;
+import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
+import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
+import org.junit.jupiter.api.Test;
+
+public interface ListeningMessageSearchIndexContract {
+    ModSeq MOD_SEQ = ModSeq.of(42L);
+    int SIZE = 25;
+    int BODY_START_OCTET = 100;
+    MessageId MESSAGE_ID = TestMessageId.of(21L);
+    MessageUid MESSAGE_UID = MessageUid.of(28);
+    
+    SimpleMailboxMessage.Builder MESSAGE_BUILDER = SimpleMailboxMessage.builder()
+        .messageId(MESSAGE_ID)
+        .uid(MESSAGE_UID)
+        .bodyStartOctet(BODY_START_OCTET)
+        .internalDate(new Date(1433628000000L))
+        .size(SIZE)
+        .content(new SharedByteArrayInputStream("message".getBytes(StandardCharsets.UTF_8)))
+        .propertyBuilder(new PropertyBuilder())
+        .modseq(MOD_SEQ);
+    
+    ListeningMessageSearchIndex testee();
+    MailboxSession session();
+    Mailbox mailbox();
+    
+    @Test
+    default void retrieveIndexedFlagsShouldRetrieveSystemFlags() {
+        Flags flags = FlagsBuilder.builder()
+            .add(Flags.Flag.RECENT)
+            .add(Flags.Flag.DRAFT)
+            .build();
+
+        SimpleMailboxMessage message = MESSAGE_BUILDER.mailboxId(mailbox().getMailboxId())
+            .flags(flags)
+            .build();
+
+        testee().add(session(), mailbox(), message).block();
+
+        assertThat(testee().retrieveIndexedFlags(mailbox(), MESSAGE_UID).block())
+            .isEqualTo(flags);
+    }
+
+    @Test
+    default void retrieveIndexedFlagsShouldReturnEmptyFlagsWhenNoFlags() {
+        Flags flags = new Flags();
+
+        SimpleMailboxMessage message = MESSAGE_BUILDER.mailboxId(mailbox().getMailboxId())
+            .flags(flags)
+            .build();
+
+        testee().add(session(), mailbox(), message).block();
+
+        assertThat(testee().retrieveIndexedFlags(mailbox(), MESSAGE_UID).block())
+            .isEqualTo(flags);
+    }
+
+    @Test
+    default void retrieveIndexedFlagsShouldReturnAllSystemFlagsWhenAllFlagsSet() {
+        Flags flags = FlagsBuilder.builder()
+            .add(Flags.Flag.ANSWERED)
+            .add(Flags.Flag.DELETED)
+            .add(Flags.Flag.RECENT)
+            .add(Flags.Flag.DRAFT)
+            .add(Flags.Flag.FLAGGED)
+            .add(Flags.Flag.SEEN)
+            .build();
+
+        SimpleMailboxMessage message = MESSAGE_BUILDER.mailboxId(mailbox().getMailboxId())
+            .flags(flags)
+            .build();
+
+        testee().add(session(), mailbox(), message).block();
+
+        assertThat(testee().retrieveIndexedFlags(mailbox(), MESSAGE_UID).block())
+            .isEqualTo(flags);
+    }
+
+    @Test
+    default void retrieveIndexedFlagsShouldReturnUserFlags() {
+        Flags flags = FlagsBuilder.builder()
+            .add("flag1")
+            .add("flag2")
+            .build();
+
+        SimpleMailboxMessage message = MESSAGE_BUILDER.mailboxId(mailbox().getMailboxId())
+            .flags(flags)
+            .build();
+
+        testee().add(session(), mailbox(), message).block();
+
+        assertThat(testee().retrieveIndexedFlags(mailbox(), MESSAGE_UID).block())
+            .isEqualTo(flags);
+    }
+
+    @Test
+    default void retrieveIndexedFlagsShouldReturnUserAndSystemFlags() {
+        Flags flags = FlagsBuilder.builder()
+            .add(Flags.Flag.ANSWERED)
+            .add(Flags.Flag.DELETED)
+            .add("flag1")
+            .add("flag2")
+            .build();
+
+        SimpleMailboxMessage message = MESSAGE_BUILDER.mailboxId(mailbox().getMailboxId())
+            .flags(flags)
+            .build();
+
+        testee().add(session(), mailbox(), message).block();
+
+        assertThat(testee().retrieveIndexedFlags(mailbox(), MESSAGE_UID).block())
+            .isEqualTo(flags);
+    }
+}
diff --git a/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/ReIndexerImplTest.java b/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/ReIndexerImplTest.java
index 237dbb5..32135ad 100644
--- a/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/ReIndexerImplTest.java
+++ b/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/ReIndexerImplTest.java
@@ -71,7 +71,7 @@ public class ReIndexerImplTest {
     }
 
     @Test
-    void reIndexAllShouldCallMessageSearchIndex() throws Exception {
+    void reIndexMailboxPathShouldCallMessageSearchIndex() throws Exception {
         MailboxSession systemSession = mailboxManager.createSystemSession(USERNAME);
         MailboxId mailboxId = mailboxManager.createMailbox(INBOX, systemSession).get();
         ComposedMessageId createdMessage = mailboxManager.getMailbox(INBOX, systemSession)
@@ -98,7 +98,7 @@ public class ReIndexerImplTest {
     }
 
     @Test
-    void reIndexMailboxPathShouldCallMessageSearchIndex() throws Exception {
+    void reIndexAllShouldCallMessageSearchIndex() throws Exception {
         MailboxSession systemSession = mailboxManager.createSystemSession(USERNAME);
         MailboxId mailboxId = mailboxManager.createMailbox(INBOX, systemSession).get();
         ComposedMessageId createdMessage = mailboxManager.getMailbox(INBOX, systemSession)


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


[james-project] 09/12: JAMES-3167 Reactify MailboxMapper

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 5ccf47c38a651653a79283f9f83b491d72b852e9
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed Jun 3 14:08:55 2020 +0700

    JAMES-3167 Reactify MailboxMapper
---
 .../org/apache/james/mailbox/MailboxManager.java   |   4 +-
 .../org/apache/james/mailbox/RightManager.java     |   4 +-
 .../apache/james/mailbox/MailboxManagerTest.java   |  40 ++-
 .../james/mailbox/backup/DefaultMailboxBackup.java |   2 +-
 .../mailbox/cassandra/mail/CassandraACLMapper.java |  14 +-
 .../cassandra/mail/CassandraMailboxMapper.java     |  62 ++---
 .../cassandra/mail/CassandraMessageIdMapper.java   |  27 +-
 .../mail/task/MailboxMergingTaskRunner.java        |  27 +-
 .../CassandraMailboxManagerConsistencyTest.java    |  50 ++--
 .../cassandra/mail/CassandraACLMapperTest.java     |  27 +-
 .../CassandraMailboxMapperConcurrencyTest.java     |   6 +-
 .../cassandra/mail/CassandraMailboxMapperTest.java | 180 ++++++------
 .../mail/migration/MailboxPathV2MigrationTest.java |  11 +-
 ...asticSearchListeningMessageSearchIndexTest.java |   2 +-
 .../james/mailbox/jpa/mail/JPAMailboxMapper.java   | 159 +++++------
 .../jpa/mail/TransactionalMailboxMapper.java       |  27 +-
 .../mailbox/maildir/mail/MaildirMailboxMapper.java | 306 +++++++++++----------
 .../DomainUserMaildirMailboxManagerTest.java       |   5 +
 .../InMemoryMailboxSessionMapperFactory.java       |   2 +-
 .../inmemory/mail/InMemoryMailboxMapper.java       | 100 +++----
 .../inmemory/mail/InMemoryMessageIdMapper.java     |   9 +-
 .../james/vault/DeletedMessageVaultHook.java       |  27 +-
 .../mailbox/spamassassin/SpamAssassinListener.java |   4 +-
 .../spamassassin/SpamAssassinListenerTest.java     |  12 +-
 .../store/StoreMailboxAnnotationManager.java       |   5 +-
 .../james/mailbox/store/StoreMailboxManager.java   | 251 +++++++----------
 .../james/mailbox/store/StoreMessageIdManager.java |  68 ++---
 .../james/mailbox/store/StoreRightManager.java     |  75 +++--
 .../mailbox/store/SystemMailboxesProviderImpl.java |   2 +-
 .../james/mailbox/store/mail/MailboxMapper.java    |  52 +---
 .../store/quota/DefaultUserQuotaRootResolver.java  |   2 +-
 .../store/search/ListeningMessageSearchIndex.java  |   6 +-
 .../store/search/SimpleMessageSearchIndex.java     |   3 +-
 .../james/mailbox/store/transaction/Mapper.java    |   2 +-
 .../store/transaction/TransactionalMapper.java     |  20 +-
 .../mailbox/store/MessageIdManagerTestSystem.java  |   6 +-
 .../store/StoreMailboxManagerAnnotationTest.java   |  28 +-
 .../mailbox/store/StoreMailboxManagerTest.java     |  12 +-
 .../james/mailbox/store/StoreRightManagerTest.java |  12 +-
 .../store/SystemMailboxesProviderImplTest.java     |   4 +
 .../store/mail/model/MailboxMapperACLTest.java     | 137 ++++-----
 .../store/mail/model/MailboxMapperTest.java        |  79 +++---
 .../store/mail/model/MessageIdMapperTest.java      |   2 +-
 .../store/mail/model/MessageMapperTest.java        |   2 +-
 .../mailbox/store/mail/model/MessageMoveTest.java  |   4 +-
 .../quota/DefaultUserQuotaRootResolverTest.java    |   4 +-
 .../mailbox/tools/indexer/ReIndexerImpl.java       |   3 +-
 .../mailbox/tools/indexer/ReIndexerPerformer.java  |  10 +-
 .../apache/james/imap/processor/ListProcessor.java |  12 +-
 .../org/apache/james/modules/MailboxProbeImpl.java |  12 +-
 .../adapter/mailbox/MailboxManagerManagement.java  |   4 +-
 .../adapter/mailbox/MailboxManagementTest.java     |  46 ++--
 .../james/transport/mailets/RandomStoring.java     |   2 +-
 .../jmap/draft/methods/GetMailboxesMethod.java     |   2 +-
 .../jmap/draft/methods/GetMailboxesMethodTest.java |   2 +-
 .../james/jmap/draft/model/MailboxFactoryTest.java |   2 +-
 .../event/PropagateLookupRightListenerTest.java    |  28 +-
 .../james/jmap/method/MailboxGetMethod.scala       |   2 +-
 .../jmap/MessageFastViewProjectionCorrector.java   |  23 +-
 .../webadmin/service/UserMailboxesService.java     |   2 +-
 .../webadmin/routes/UserMailboxesRoutesTest.java   |  29 +-
 61 files changed, 992 insertions(+), 1070 deletions(-)

diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxManager.java b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxManager.java
index d5ac9d7..ee859af 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxManager.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxManager.java
@@ -243,9 +243,7 @@ public interface MailboxManager extends RequestAware, RightManager, MailboxAnnot
      * @param session
      *            the context for this call, not null
      */
-    List<MailboxMetaData> search(MailboxQuery expression, MailboxSession session) throws MailboxException;
-
-    Flux<MailboxMetaData> searchReactive(MailboxQuery expression, MailboxSession session);
+    Flux<MailboxMetaData> search(MailboxQuery expression, MailboxSession session);
 
     /**
      * Searches for messages matching the given query.
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/RightManager.java b/mailbox/api/src/main/java/org/apache/james/mailbox/RightManager.java
index 3fd6d8a..e66934a 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/RightManager.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/RightManager.java
@@ -109,9 +109,7 @@ public interface RightManager {
      *         {@code session.getUser()} is null.
      * @throws MailboxException in case of unknown mailbox or unsupported right
      */
-    Rfc4314Rights myRights(MailboxId mailboxId, MailboxSession session) throws MailboxException;
-
-    Publisher<Rfc4314Rights> myRightsReactive(MailboxId mailboxId, MailboxSession session);
+    Publisher<Rfc4314Rights> myRights(MailboxId mailboxId, MailboxSession session);
 
     /**
      * Update the Mailbox ACL of the designated mailbox. We can either ADD REPLACE or REMOVE entries.
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
index 2eaa904..603483b 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
@@ -1003,7 +1003,9 @@ public abstract class MailboxManagerTest<T extends MailboxManager> {
                 MailboxQuery.privateMailboxesBuilder(session)
                     .matchesAllMailboxNames()
                     .build(),
-                session);
+                session)
+                .collectList()
+                .block();
             assertThat(metaDatas).hasSize(1);
             assertThat(metaDatas.get(0).getPath()).isEqualTo(MailboxPath.inbox(session));
         }
@@ -1025,7 +1027,9 @@ public abstract class MailboxManagerTest<T extends MailboxManager> {
                 MailboxQuery.privateMailboxesBuilder(session)
                     .matchesAllMailboxNames()
                     .build(),
-                session);
+                session)
+                .collectList()
+                .block();
             assertThat(metaDatas)
                 .hasSize(1)
                 .first()
@@ -1046,7 +1050,9 @@ public abstract class MailboxManagerTest<T extends MailboxManager> {
                 MailboxQuery.privateMailboxesBuilder(session)
                     .matchesAllMailboxNames()
                     .build(),
-                session);
+                session)
+                .collectList()
+                .block();
             assertThat(metaDatas).hasSize(1);
             assertThat(metaDatas.get(0).getPath()).isEqualTo(MailboxPath.inbox(session));
         }
@@ -1068,7 +1074,7 @@ public abstract class MailboxManagerTest<T extends MailboxManager> {
                 .matchesAllMailboxNames()
                 .build();
 
-            assertThat(mailboxManager.search(mailboxQuery, session1))
+            assertThat(mailboxManager.search(mailboxQuery, session1).toStream())
                 .extracting(MailboxMetaData::getPath)
                 .hasSize(1)
                 .containsOnly(inbox1);
@@ -1092,7 +1098,7 @@ public abstract class MailboxManagerTest<T extends MailboxManager> {
                 .matchesAllMailboxNames()
                 .build();
 
-            assertThat(mailboxManager.search(mailboxQuery, session2))
+            assertThat(mailboxManager.search(mailboxQuery, session2).toStream())
                 .extracting(MailboxMetaData::getPath)
                 .containsOnly(inbox1);
         }
@@ -1117,7 +1123,7 @@ public abstract class MailboxManagerTest<T extends MailboxManager> {
                 .matchesAllMailboxNames()
                 .build();
 
-            assertThat(mailboxManager.search(mailboxQuery, session2))
+            assertThat(mailboxManager.search(mailboxQuery, session2).toStream())
                 .extracting(MailboxMetaData::getPath)
                 .containsOnly(inbox1, inbox2);
         }
@@ -1143,7 +1149,7 @@ public abstract class MailboxManagerTest<T extends MailboxManager> {
                 .matchesAllMailboxNames()
                 .build();
 
-            assertThat(mailboxManager.search(mailboxQuery, session2))
+            assertThat(mailboxManager.search(mailboxQuery, session2).toStream())
                 .extracting(MailboxMetaData::getPath)
                 .containsOnly(inbox1);
         }
@@ -1176,7 +1182,7 @@ public abstract class MailboxManagerTest<T extends MailboxManager> {
                 .matchesAllMailboxNames()
                 .build();
 
-            assertThat(mailboxManager.search(mailboxQuery, session2))
+            assertThat(mailboxManager.search(mailboxQuery, session2).toStream())
                 .extracting(MailboxMetaData::getPath)
                 .containsOnly(mailboxPath1);
         }
@@ -1413,7 +1419,7 @@ public abstract class MailboxManagerTest<T extends MailboxManager> {
                 .matchesAllMailboxNames()
                 .build();
 
-            assertThat(mailboxManager.search(mailboxQuery, session2))
+            assertThat(mailboxManager.search(mailboxQuery, session2).toStream())
                 .isEmpty();
         }
     }
@@ -1562,6 +1568,22 @@ public abstract class MailboxManagerTest<T extends MailboxManager> {
         }
 
         @Test
+        protected void renameMailboxShouldChangeTheMailboxPathOfTheChildMailbox() throws Exception {
+            MailboxSession session = mailboxManager.createSystemSession(USER_1);
+
+            MailboxPath mailboxPath1 = MailboxPath.forUser(USER_1, "mbx1");
+            MailboxPath mailboxPath2 = MailboxPath.forUser(USER_1, "mbx2");
+            mailboxManager.createMailbox(mailboxPath1, session);
+            MailboxPath mailboxPath1Child = MailboxPath.forUser(USER_1, "mbx1.child");
+            Optional<MailboxId> mailboxChildId = mailboxManager.createMailbox(mailboxPath1Child, session);
+
+            mailboxManager.renameMailbox(mailboxPath1, mailboxPath2, session);
+
+            assertThat(mailboxManager.getMailbox(mailboxChildId.get(), session).getMailboxPath())
+                    .isEqualTo(MailboxPath.forUser(USER_1, "mbx2.child"));
+        }
+
+        @Test
         protected void renameMailboxByIdShouldChangeTheMailboxPathOfAMailbox() throws Exception {
             MailboxSession session = mailboxManager.createSystemSession(USER_1);
 
diff --git a/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/DefaultMailboxBackup.java b/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/DefaultMailboxBackup.java
index 62dc067..9f19a89 100644
--- a/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/DefaultMailboxBackup.java
+++ b/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/DefaultMailboxBackup.java
@@ -146,7 +146,7 @@ public class DefaultMailboxBackup implements MailboxBackup {
             .user(session.getUser())
             .build();
         Stream<MailboxPath> paths = mailboxManager.search(queryUser, session)
-            .stream()
+            .toStream()
             .map(MailboxMetaData::getPath);
         List<MailAccountContent> mailboxes = paths
             .flatMap(path -> getMailboxWithAnnotationsFromPath(session, path))
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraACLMapper.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraACLMapper.java
index b04814c..0ff9efa 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraACLMapper.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraACLMapper.java
@@ -120,21 +120,19 @@ public class CassandraACLMapper {
         return deserializeACL(cassandraId, serializedACL);
     }
 
-    public ACLDiff updateACL(CassandraId cassandraId, MailboxACL.ACLCommand command) throws MailboxException {
-        MailboxACL replacement = MailboxACL.EMPTY.apply(command);
-        return updateAcl(cassandraId, aclWithVersion -> aclWithVersion.apply(command), replacement)
+    public Mono<ACLDiff> updateACL(CassandraId cassandraId, MailboxACL.ACLCommand command) {
+        return Mono.fromCallable(() -> MailboxACL.EMPTY.apply(command))
+        .flatMap(replacement -> updateAcl(cassandraId, aclWithVersion -> aclWithVersion.apply(command), replacement))
             .flatMap(aclDiff -> userMailboxRightsDAO.update(cassandraId, aclDiff)
             .thenReturn(aclDiff))
-            .blockOptional()
-            .orElseThrow(() -> new MailboxException("Unable to update ACL"));
+            .switchIfEmpty(Mono.error(new MailboxException("Unable to update ACL")));
     }
 
-    public ACLDiff setACL(CassandraId cassandraId, MailboxACL mailboxACL) throws MailboxException {
+    public Mono<ACLDiff> setACL(CassandraId cassandraId, MailboxACL mailboxACL) {
         return updateAcl(cassandraId, acl -> new ACLWithVersion(acl.version, mailboxACL), mailboxACL)
             .flatMap(aclDiff -> userMailboxRightsDAO.update(cassandraId, aclDiff)
             .thenReturn(aclDiff))
-            .blockOptional()
-            .orElseThrow(() -> new MailboxException("Unable to update ACL"));
+            .switchIfEmpty(Mono.defer(() -> Mono.error(new MailboxException("Unable to update ACL"))));
     }
 
     private Mono<ACLDiff> updateAcl(CassandraId cassandraId, Function<ACLWithVersion, ACLWithVersion> aclTransformation, MailboxACL replacement) {
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapper.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapper.java
index e84978f..0e13275 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapper.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapper.java
@@ -40,6 +40,7 @@ import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.UidValidity;
 import org.apache.james.mailbox.model.search.MailboxQuery;
 import org.apache.james.mailbox.store.mail.MailboxMapper;
+import org.apache.james.util.FunctionalUtils;
 import org.apache.james.util.ReactorUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -85,12 +86,11 @@ public class CassandraMailboxMapper implements MailboxMapper {
     }
 
     @Override
-    public void delete(Mailbox mailbox) {
+    public Mono<Void> delete(Mailbox mailbox) {
         CassandraId mailboxId = (CassandraId) mailbox.getMailboxId();
-        deletePath(mailbox)
+        return deletePath(mailbox)
             .thenEmpty(mailboxDAO.delete(mailboxId)
-                .retryWhen(Retry.backoff(MAX_RETRY, MIN_RETRY_BACKOFF).maxBackoff(MAX_RETRY_BACKOFF)))
-            .block();
+                .retryWhen(Retry.backoff(MAX_RETRY, MIN_RETRY_BACKOFF).maxBackoff(MAX_RETRY_BACKOFF)));
     }
 
     private Flux<Void> deletePath(Mailbox mailbox) {
@@ -144,17 +144,10 @@ public class CassandraMailboxMapper implements MailboxMapper {
     }
 
     @Override
-    public Mailbox findMailboxById(MailboxId id) throws MailboxException {
+    public Mono<Mailbox> findMailboxById(MailboxId id) {
         CassandraId mailboxId = (CassandraId) id;
         return retrieveMailbox(mailboxId)
-            .blockOptional()
-            .orElseThrow(() -> new MailboxNotFoundException(id));
-    }
-
-    @Override
-    public Mono<Mailbox> findMailboxByIdReactive(MailboxId id) {
-        CassandraId mailboxId = (CassandraId) id;
-        return retrieveMailbox(mailboxId);
+            .switchIfEmpty(Mono.error(() -> new MailboxNotFoundException(id)));
     }
 
     private Mono<Mailbox> retrieveMailbox(CassandraId mailboxId) {
@@ -203,40 +196,26 @@ public class CassandraMailboxMapper implements MailboxMapper {
     }
 
     @Override
-    public Mailbox create(MailboxPath mailboxPath, UidValidity uidValidity) throws MailboxException {
+    public Mono<Mailbox> create(MailboxPath mailboxPath, UidValidity uidValidity) {
         CassandraId cassandraId = CassandraId.timeBased();
         Mailbox mailbox = new Mailbox(mailboxPath, uidValidity, cassandraId);
 
-        if (!tryCreate(mailbox, cassandraId).block()) {
-            throw new MailboxExistsException(mailbox.generateAssociatedPath().asString());
-        }
-        return mailbox;
-    }
-
-    private Mono<Boolean> tryCreate(Mailbox cassandraMailbox, CassandraId cassandraId) {
-        return mailboxPathV2DAO.save(cassandraMailbox.generateAssociatedPath(), cassandraId)
+        return mailboxPathV2DAO.save(mailbox.generateAssociatedPath(), cassandraId)
             .filter(isCreated -> isCreated)
-            .flatMap(mailboxHasCreated -> persistMailboxEntity(cassandraMailbox)
-                .thenReturn(true))
-            .defaultIfEmpty(false);
+            .flatMap(mailboxHasCreated -> persistMailboxEntity(mailbox)
+                .thenReturn(mailbox))
+            .switchIfEmpty(Mono.error(() -> new MailboxExistsException(mailbox.generateAssociatedPath().asString())));
     }
 
     @Override
-    public MailboxId rename(Mailbox mailbox) throws MailboxException {
+    public Mono<MailboxId> rename(Mailbox mailbox) {
         Preconditions.checkNotNull(mailbox.getMailboxId(), "A mailbox we want to rename should have a defined mailboxId");
 
         CassandraId cassandraId = (CassandraId) mailbox.getMailboxId();
-        try {
-            if (!tryRename(mailbox, cassandraId).block()) {
-                throw new MailboxExistsException(mailbox.generateAssociatedPath().asString());
-            }
-        } catch (RuntimeException e) {
-            if (e.getCause() instanceof MailboxNotFoundException) {
-                throw (MailboxNotFoundException)e.getCause();
-            }
-            throw e;
-        }
-        return cassandraId;
+        return tryRename(mailbox, cassandraId)
+            .filter(FunctionalUtils.identityPredicate())
+            .switchIfEmpty(Mono.error(() -> new MailboxExistsException(mailbox.generateAssociatedPath().asString())))
+            .thenReturn(cassandraId);
     }
 
     private Mono<Boolean> tryRename(Mailbox cassandraMailbox, CassandraId cassandraId) {
@@ -261,13 +240,12 @@ public class CassandraMailboxMapper implements MailboxMapper {
     }
 
     @Override
-    public boolean hasChildren(Mailbox mailbox, char delimiter) {
+    public Mono<Boolean> hasChildren(Mailbox mailbox, char delimiter) {
         return Flux.merge(
                 mailboxPathDAO.listUserMailboxes(mailbox.getNamespace(), mailbox.getUser()),
                 mailboxPathV2DAO.listUserMailboxes(mailbox.getNamespace(), mailbox.getUser()))
             .filter(idAndPath -> isPathChildOfMailbox(idAndPath, mailbox, delimiter))
-            .hasElements()
-            .block();
+            .hasElements();
     }
 
     private boolean isPathChildOfMailbox(CassandraIdAndPath idAndPath, Mailbox mailbox, char delimiter) {
@@ -286,13 +264,13 @@ public class CassandraMailboxMapper implements MailboxMapper {
     }
 
     @Override
-    public ACLDiff updateACL(Mailbox mailbox, MailboxACL.ACLCommand mailboxACLCommand) throws MailboxException {
+    public Mono<ACLDiff> updateACL(Mailbox mailbox, MailboxACL.ACLCommand mailboxACLCommand) {
         CassandraId cassandraId = (CassandraId) mailbox.getMailboxId();
         return cassandraACLMapper.updateACL(cassandraId, mailboxACLCommand);
     }
 
     @Override
-    public ACLDiff setACL(Mailbox mailbox, MailboxACL mailboxACL) throws MailboxException {
+    public Mono<ACLDiff> setACL(Mailbox mailbox, MailboxACL mailboxACL) {
         CassandraId cassandraId = (CassandraId) mailbox.getMailboxId();
         return cassandraACLMapper.setACL(cassandraId, mailboxACL);
     }
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageIdMapper.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageIdMapper.java
index f98090a..2777ec4 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageIdMapper.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageIdMapper.java
@@ -39,6 +39,7 @@ import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.model.UpdatedFlags;
 import org.apache.james.mailbox.store.FlagsUpdateCalculator;
+import org.apache.james.mailbox.store.MailboxReactorUtils;
 import org.apache.james.mailbox.store.mail.MailboxMapper;
 import org.apache.james.mailbox.store.mail.MessageIdMapper;
 import org.apache.james.mailbox.store.mail.MessageMapper.FetchType;
@@ -48,7 +49,6 @@ import org.apache.james.util.FunctionalUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.github.fge.lambdas.runnable.ThrowingRunnable;
 import com.github.steveash.guavate.Guavate;
 import com.google.common.collect.Multimap;
 
@@ -133,31 +133,18 @@ public class CassandraMessageIdMapper implements MessageIdMapper {
     @Override
     public void save(MailboxMessage mailboxMessage) throws MailboxException {
         CassandraId mailboxId = (CassandraId) mailboxMessage.getMailboxId();
-        unbox(() -> mailboxMapper.findMailboxByIdReactive(mailboxId)
-            .switchIfEmpty(Mono.error(new MailboxNotFoundException(mailboxId)))
+        MailboxReactorUtils.block(mailboxMapper.findMailboxById(mailboxId)
+            .switchIfEmpty(Mono.error(() -> new MailboxNotFoundException(mailboxId)))
             .then(messageDAO.save(mailboxMessage))
-            .thenEmpty(saveMessageMetadata(mailboxMessage, mailboxId))
-            .block());
+            .thenEmpty(saveMessageMetadata(mailboxMessage, mailboxId)));
     }
 
     @Override
     public void copyInMailbox(MailboxMessage mailboxMessage) throws MailboxException {
         CassandraId mailboxId = (CassandraId) mailboxMessage.getMailboxId();
-        unbox(() -> mailboxMapper.findMailboxByIdReactive(mailboxId)
-            .switchIfEmpty(Mono.error(new MailboxNotFoundException(mailboxId)))
-            .then(saveMessageMetadata(mailboxMessage, mailboxId))
-            .block());
-    }
-
-    private void unbox(ThrowingRunnable runnable) throws MailboxNotFoundException {
-        try {
-            runnable.run();
-        } catch (RuntimeException e) {
-            if (e.getCause() instanceof MailboxNotFoundException) {
-                throw (MailboxNotFoundException) e.getCause();
-            }
-            throw e;
-        }
+        MailboxReactorUtils.block(mailboxMapper.findMailboxById(mailboxId)
+            .switchIfEmpty(Mono.error(() -> new MailboxNotFoundException(mailboxId)))
+            .then(saveMessageMetadata(mailboxMessage, mailboxId)));
     }
 
     private Mono<Void> saveMessageMetadata(MailboxMessage mailboxMessage, CassandraId mailboxId) {
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/task/MailboxMergingTaskRunner.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/task/MailboxMergingTaskRunner.java
index 2de3caf..bf9888d 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/task/MailboxMergingTaskRunner.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/task/MailboxMergingTaskRunner.java
@@ -41,6 +41,8 @@ import org.apache.james.util.streams.Limit;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import reactor.core.publisher.Mono;
+
 public class MailboxMergingTaskRunner {
     private static final Logger LOGGER = LoggerFactory.getLogger(MailboxMergingTaskRunner.class);
 
@@ -64,7 +66,7 @@ public class MailboxMergingTaskRunner {
     public Task.Result run(CassandraId oldMailboxId, CassandraId newMailboxId, MailboxMergingTask.Context context) {
         return moveMessages(oldMailboxId, newMailboxId, mailboxSession, context)
             .onComplete(
-                () -> mergeRights(oldMailboxId, newMailboxId),
+                () -> mergeRights(oldMailboxId, newMailboxId).block(),
                 () -> mailboxDAO.delete(oldMailboxId).block());
     }
 
@@ -88,20 +90,13 @@ public class MailboxMergingTaskRunner {
         }
     }
 
-    private void mergeRights(CassandraId oldMailboxId, CassandraId newMailboxId) {
-        try {
-            MailboxACL oldAcl = cassandraACLMapper.getACL(oldMailboxId)
-                .defaultIfEmpty(MailboxACL.EMPTY)
-                .block();
-            MailboxACL newAcl = cassandraACLMapper.getACL(newMailboxId)
-                .defaultIfEmpty(MailboxACL.EMPTY)
-                .block();
-            MailboxACL finalAcl = newAcl.union(oldAcl);
-
-            cassandraACLMapper.setACL(newMailboxId, finalAcl);
-            rightsDAO.update(oldMailboxId, ACLDiff.computeDiff(oldAcl, MailboxACL.EMPTY)).block();
-        } catch (MailboxException e) {
-            throw new RuntimeException(e);
-        }
+    private Mono<Void> mergeRights(CassandraId oldMailboxId, CassandraId newMailboxId) {
+            Mono<MailboxACL> oldAclMono = cassandraACLMapper.getACL(oldMailboxId)
+                    .defaultIfEmpty(MailboxACL.EMPTY);
+            Mono<MailboxACL> newAclMono = cassandraACLMapper.getACL(newMailboxId)
+                    .defaultIfEmpty(MailboxACL.EMPTY);
+        return Mono.zip(oldAclMono, newAclMono)
+            .flatMap(acls -> cassandraACLMapper.setACL(newMailboxId, acls.getT1())
+                .then(rightsDAO.update(oldMailboxId, ACLDiff.computeDiff(acls.getT2(), MailboxACL.EMPTY))));
     }
 }
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerConsistencyTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerConsistencyTest.java
index ccd5249..345a5e7 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerConsistencyTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerConsistencyTest.java
@@ -90,7 +90,7 @@ class CassandraMailboxManagerConsistencyTest {
             cassandra.getConf().registerScenario(NOTHING);
 
             SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-                softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+                softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession).toStream())
                     .isEmpty();
                 softly.assertThat(testee.list(mailboxSession))
                     .isEmpty();
@@ -108,7 +108,7 @@ class CassandraMailboxManagerConsistencyTest {
             cassandra.getConf().registerScenario(NOTHING);
 
             SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-                softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+                softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession).toStream())
                     .isEmpty();
                 softly.assertThat(testee.list(mailboxSession))
                     .isEmpty();
@@ -142,7 +142,7 @@ class CassandraMailboxManagerConsistencyTest {
                 .get();
 
             SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-                softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+                softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession).toStream())
                     .hasOnlyOneElementSatisfying(mailboxMetaData -> {
                         softly.assertThat(mailboxMetaData.getId()).isEqualTo(inboxId);
                         softly.assertThat(mailboxMetaData.getPath()).isEqualTo(inboxPath);
@@ -185,7 +185,7 @@ class CassandraMailboxManagerConsistencyTest {
                 .get();
 
             SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-                softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+                softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession).toStream())
                     .hasOnlyOneElementSatisfying(mailboxMetaData -> {
                         softly.assertThat(mailboxMetaData.getId()).isEqualTo(inboxId);
                         softly.assertThat(mailboxMetaData.getPath()).isEqualTo(inboxPath);
@@ -213,7 +213,7 @@ class CassandraMailboxManagerConsistencyTest {
             cassandra.getConf().registerScenario(NOTHING);
 
             SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-                softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+                softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession).toStream())
                     .hasOnlyOneElementSatisfying(mailboxMetaData -> {
                         softly.assertThat(mailboxMetaData.getId()).isEqualTo(inboxId);
                         softly.assertThat(mailboxMetaData.getPath()).isEqualTo(inboxPath);
@@ -237,7 +237,7 @@ class CassandraMailboxManagerConsistencyTest {
             cassandra.getConf().registerScenario(NOTHING);
 
             SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-                softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+                softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession).toStream())
                     .hasOnlyOneElementSatisfying(mailboxMetaData -> {
                         softly.assertThat(mailboxMetaData.getId()).isEqualTo(inboxId);
                         softly.assertThat(mailboxMetaData.getPath()).isEqualTo(inboxPath);
@@ -265,7 +265,7 @@ class CassandraMailboxManagerConsistencyTest {
                 .get();
 
             SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-                softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+                softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession).toStream())
                     .hasSize(2)
                     .anySatisfy(mailboxMetaData -> {
                         softly.assertThat(mailboxMetaData.getId()).isEqualTo(inboxId);
@@ -297,7 +297,7 @@ class CassandraMailboxManagerConsistencyTest {
                 .get();
 
             SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-                softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+                softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession).toStream())
                     .hasSize(2)
                     .anySatisfy(mailboxMetaData -> {
                         softly.assertThat(mailboxMetaData.getId()).isEqualTo(inboxId);
@@ -349,7 +349,7 @@ class CassandraMailboxManagerConsistencyTest {
                 .get();
 
             SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-                softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+                softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession).toStream())
                     .hasOnlyOneElementSatisfying(mailboxMetaData -> {
                         softly.assertThat(mailboxMetaData.getId()).isEqualTo(newMailboxId);
                         softly.assertThat(mailboxMetaData.getPath()).isEqualTo(inboxPathRenamed);
@@ -380,7 +380,7 @@ class CassandraMailboxManagerConsistencyTest {
                 cassandra.getConf().registerScenario(NOTHING);
 
                 SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-                    softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+                    softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession).toStream())
                         .hasOnlyOneElementSatisfying(mailboxMetaData -> {
                             softly.assertThat(mailboxMetaData.getId()).isEqualTo(inboxId);
                             softly.assertThat(mailboxMetaData.getPath()).isEqualTo(inboxPath);
@@ -405,7 +405,7 @@ class CassandraMailboxManagerConsistencyTest {
                 cassandra.getConf().registerScenario(NOTHING);
 
                 SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-                    softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+                    softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession).toStream())
                         .hasOnlyOneElementSatisfying(mailboxMetaData -> {
                             softly.assertThat(mailboxMetaData.getId()).isEqualTo(inboxId);
                             softly.assertThat(mailboxMetaData.getPath()).isEqualTo(inboxPath);
@@ -429,7 +429,7 @@ class CassandraMailboxManagerConsistencyTest {
                 cassandra.getConf().registerScenario(NOTHING);
 
                 SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-                    softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+                    softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession).toStream())
                         .hasOnlyOneElementSatisfying(mailboxMetaData -> {
                             softly.assertThat(mailboxMetaData.getId()).isEqualTo(inboxId);
                             softly.assertThat(mailboxMetaData.getPath()).isEqualTo(inboxPath);
@@ -453,7 +453,7 @@ class CassandraMailboxManagerConsistencyTest {
                 cassandra.getConf().registerScenario(NOTHING);
 
                 SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-                    softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+                    softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession).toStream())
                         .hasOnlyOneElementSatisfying(mailboxMetaData -> {
                             softly.assertThat(mailboxMetaData.getId()).isEqualTo(inboxId);
                             softly.assertThat(mailboxMetaData.getPath()).isEqualTo(inboxPath);
@@ -483,7 +483,7 @@ class CassandraMailboxManagerConsistencyTest {
                     .get();
 
                 SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-                    softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+                    softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession).toStream())
                         .hasOnlyOneElementSatisfying(mailboxMetaData -> {
                             softly.assertThat(mailboxMetaData.getId()).isEqualTo(inboxId);
                             softly.assertThat(mailboxMetaData.getPath()).isEqualTo(inboxPath);
@@ -510,7 +510,7 @@ class CassandraMailboxManagerConsistencyTest {
                     .get();
 
                 SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-                    softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+                    softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession).toStream())
                         .hasOnlyOneElementSatisfying(mailboxMetaData -> {
                             softly.assertThat(mailboxMetaData.getId()).isEqualTo(inboxNewId);
                             softly.assertThat(mailboxMetaData.getPath()).isEqualTo(inboxPath);
@@ -537,7 +537,7 @@ class CassandraMailboxManagerConsistencyTest {
                     .get();
 
                 SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-                    softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+                    softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession).toStream())
                         .hasOnlyOneElementSatisfying(mailboxMetaData -> {
                             softly.assertThat(mailboxMetaData.getId()).isEqualTo(inboxNewId);
                             softly.assertThat(mailboxMetaData.getPath()).isEqualTo(inboxPath);
@@ -565,7 +565,7 @@ class CassandraMailboxManagerConsistencyTest {
                     .get();
 
                 SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-                    softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+                    softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession).toStream())
                         .hasOnlyOneElementSatisfying(mailboxMetaData -> {
                             softly.assertThat(mailboxMetaData.getId()).isEqualTo(inboxNewId);
                             softly.assertThat(mailboxMetaData.getPath()).isEqualTo(inboxPath);
@@ -595,7 +595,7 @@ class CassandraMailboxManagerConsistencyTest {
                 doQuietly(() -> testee.deleteMailbox(inboxPath, mailboxSession));
 
                 SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-                    softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+                    softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession).toStream())
                         .isEmpty();
                     softly.assertThat(testee.list(mailboxSession))
                         .isEmpty();
@@ -618,7 +618,7 @@ class CassandraMailboxManagerConsistencyTest {
                 doQuietly(() -> testee.deleteMailbox(inboxId, mailboxSession));
 
                 SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-                    softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+                    softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession).toStream())
                         .isEmpty();
                     softly.assertThat(testee.list(mailboxSession))
                         .isEmpty();
@@ -640,7 +640,7 @@ class CassandraMailboxManagerConsistencyTest {
                 doQuietly(() -> testee.deleteMailbox(inboxPath, mailboxSession));
 
                 SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-                    softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+                    softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession).toStream())
                         .isEmpty();
                     softly.assertThat(testee.list(mailboxSession))
                         .isEmpty();
@@ -663,7 +663,7 @@ class CassandraMailboxManagerConsistencyTest {
                 doQuietly(() -> testee.deleteMailbox(inboxId, mailboxSession));
 
                 SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-                    softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+                    softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession).toStream())
                         .isEmpty();
                     softly.assertThat(testee.list(mailboxSession))
                         .isEmpty();
@@ -691,7 +691,7 @@ class CassandraMailboxManagerConsistencyTest {
                     .get();
 
                 SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-                    softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+                    softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession).toStream())
                         .hasOnlyOneElementSatisfying(mailboxMetaData -> {
                             softly.assertThat(mailboxMetaData.getId()).isEqualTo(inboxId);
                             softly.assertThat(mailboxMetaData.getPath()).isEqualTo(inboxPath);
@@ -719,7 +719,7 @@ class CassandraMailboxManagerConsistencyTest {
                     .get();
 
                 SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-                    softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+                    softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession).toStream())
                         .hasOnlyOneElementSatisfying(mailboxMetaData -> {
                             softly.assertThat(mailboxMetaData.getId()).isEqualTo(inboxNewId);
                             softly.assertThat(mailboxMetaData.getPath()).isEqualTo(inboxPath);
@@ -746,7 +746,7 @@ class CassandraMailboxManagerConsistencyTest {
                     .get();
 
                 SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-                    softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+                    softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession).toStream())
                         .hasOnlyOneElementSatisfying(mailboxMetaData -> {
                             softly.assertThat(mailboxMetaData.getId()).isEqualTo(inboxNewId);
                             softly.assertThat(mailboxMetaData.getPath()).isEqualTo(inboxPath);
@@ -774,7 +774,7 @@ class CassandraMailboxManagerConsistencyTest {
                     .get();
 
                 SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-                    softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+                    softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession).toStream())
                         .hasOnlyOneElementSatisfying(mailboxMetaData -> {
                             softly.assertThat(mailboxMetaData.getId()).isEqualTo(inboxNewId);
                             softly.assertThat(mailboxMetaData.getPath()).isEqualTo(inboxPath);
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraACLMapperTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraACLMapperTest.java
index f3f8b81..f5b3eb7 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraACLMapperTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraACLMapperTest.java
@@ -113,7 +113,7 @@ class CassandraACLMapperTest {
         MailboxACL.Rfc4314Rights rights = new MailboxACL.Rfc4314Rights(MailboxACL.Right.Read);
 
         cassandraACLMapper.updateACL(MAILBOX_ID,
-            MailboxACL.command().key(key).rights(rights).asAddition());
+            MailboxACL.command().key(key).rights(rights).asAddition()).block();
 
         assertThat(cassandraACLMapper.getACL(MAILBOX_ID).block())
             .isEqualTo(new MailboxACL().union(key, rights));
@@ -124,9 +124,9 @@ class CassandraACLMapperTest {
         MailboxACL.EntryKey keyBob = new MailboxACL.EntryKey("bob", MailboxACL.NameType.user, false);
         MailboxACL.Rfc4314Rights rights = new MailboxACL.Rfc4314Rights(MailboxACL.Right.Read);
 
-        cassandraACLMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(keyBob).rights(rights).asAddition());
+        cassandraACLMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(keyBob).rights(rights).asAddition()).block();
         MailboxACL.EntryKey keyAlice = new MailboxACL.EntryKey("alice", MailboxACL.NameType.user, false);
-        cassandraACLMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(keyAlice).rights(rights).asAddition());
+        cassandraACLMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(keyAlice).rights(rights).asAddition()).block();
 
         assertThat(cassandraACLMapper.getACL(MAILBOX_ID).block())
             .isEqualTo(new MailboxACL().union(keyBob, rights).union(keyAlice, rights));
@@ -137,8 +137,8 @@ class CassandraACLMapperTest {
         MailboxACL.EntryKey key = new MailboxACL.EntryKey("bob", MailboxACL.NameType.user, false);
         MailboxACL.Rfc4314Rights rights = new MailboxACL.Rfc4314Rights(MailboxACL.Right.Read);
 
-        cassandraACLMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(key).rights(rights).asAddition());
-        cassandraACLMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(key).rights(rights).asRemoval());
+        cassandraACLMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(key).rights(rights).asAddition()).block();
+        cassandraACLMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(key).rights(rights).asRemoval()).block();
 
         assertThat(cassandraACLMapper.getACL(MAILBOX_ID).block()).isEqualTo(MailboxACL.EMPTY);
     }
@@ -148,8 +148,8 @@ class CassandraACLMapperTest {
         MailboxACL.EntryKey key = new MailboxACL.EntryKey("bob", MailboxACL.NameType.user, false);
         MailboxACL.Rfc4314Rights rights = new MailboxACL.Rfc4314Rights(MailboxACL.Right.Read);
 
-        cassandraACLMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(key).rights(rights).asAddition());
-        cassandraACLMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(key).noRights().asReplacement());
+        cassandraACLMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(key).rights(rights).asAddition()).block();
+        cassandraACLMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(key).noRights().asReplacement()).block();
 
         assertThat(cassandraACLMapper.getACL(MAILBOX_ID).block()).isEqualTo(MailboxACL.EMPTY);
     }
@@ -159,7 +159,7 @@ class CassandraACLMapperTest {
         MailboxACL.EntryKey key = new MailboxACL.EntryKey("bob", MailboxACL.NameType.user, false);
         MailboxACL.Rfc4314Rights rights = new MailboxACL.Rfc4314Rights(MailboxACL.Right.Read);
 
-        cassandraACLMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(key).rights(rights).asReplacement());
+        cassandraACLMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(key).rights(rights).asReplacement()).block();
 
         assertThat(cassandraACLMapper.getACL(MAILBOX_ID).block()).isEqualTo(new MailboxACL().union(key, rights));
     }
@@ -174,7 +174,7 @@ class CassandraACLMapperTest {
         MailboxACL.EntryKey key = new MailboxACL.EntryKey("bob", MailboxACL.NameType.user, false);
         MailboxACL.Rfc4314Rights rights = new MailboxACL.Rfc4314Rights(MailboxACL.Right.Read);
 
-        cassandraACLMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(key).rights(rights).asAddition());
+        cassandraACLMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(key).rights(rights).asAddition()).block();
 
         assertThat(cassandraACLMapper.getACL(MAILBOX_ID).block()).isEqualTo(new MailboxACL().union(key, rights));
     }
@@ -207,7 +207,7 @@ class CassandraACLMapperTest {
     void twoConcurrentUpdatesWhenStoredShouldReturnACLWithTwoEntries(CassandraCluster cassandra) throws Exception {
         MailboxACL.EntryKey keyBenwa = new MailboxACL.EntryKey("benwa", MailboxACL.NameType.user, false);
         MailboxACL.Rfc4314Rights rights = new MailboxACL.Rfc4314Rights(MailboxACL.Right.Read);
-        cassandraACLMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(keyBenwa).rights(rights).asAddition());
+        cassandraACLMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(keyBenwa).rights(rights).asAddition()).block();
 
         Barrier barrier = new Barrier(2);
         cassandra.getConf()
@@ -243,11 +243,8 @@ class CassandraACLMapperTest {
                 cassandra.getConf(),
                 new CassandraUserMailboxRightsDAO(cassandra.getConf(), CassandraUtils.WITH_DEFAULT_CONFIGURATION),
                 CassandraConfiguration.DEFAULT_CONFIGURATION);
-            try {
-                aclMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(key).rights(rights).asAddition());
-            } catch (MailboxException exception) {
-                throw new RuntimeException(exception);
-            }
+
+            aclMapper.updateACL(MAILBOX_ID, MailboxACL.command().key(key).rights(rights).asAddition()).block();
             return true;
         });
     }
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapperConcurrencyTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapperConcurrencyTest.java
index 35400d8..313fdc2 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapperConcurrencyTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapperConcurrencyTest.java
@@ -65,7 +65,7 @@ class CassandraMailboxMapperConcurrencyTest {
     @Test
     void createShouldBeThreadSafe() throws Exception {
         ConcurrentTestRunner.builder()
-            .operation((a, b) -> testee.create(MAILBOX_PATH, UID_VALIDITY))
+            .operation((a, b) -> testee.create(MAILBOX_PATH, UID_VALIDITY).block())
             .threadCount(THREAD_COUNT)
             .operationCount(OPERATION_COUNT)
             .runAcceptingErrorsWithin(Duration.ofMinutes(1));
@@ -75,12 +75,12 @@ class CassandraMailboxMapperConcurrencyTest {
 
     @Test
     void renameWithUpdateShouldBeThreadSafe() throws Exception {
-        Mailbox mailbox = testee.create(MAILBOX_PATH, UID_VALIDITY);
+        Mailbox mailbox = testee.create(MAILBOX_PATH, UID_VALIDITY).block();
 
         mailbox.setName("newName");
 
         ConcurrentTestRunner.builder()
-            .operation((a, b) -> testee.rename(mailbox))
+            .operation((a, b) -> testee.rename(mailbox).block())
             .threadCount(THREAD_COUNT)
             .operationCount(OPERATION_COUNT)
             .runAcceptingErrorsWithin(Duration.ofMinutes(1));
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapperTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapperTest.java
index f8e6839..29f4158 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapperTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapperTest.java
@@ -40,7 +40,6 @@ import org.apache.james.core.Username;
 import org.apache.james.mailbox.cassandra.ids.CassandraId;
 import org.apache.james.mailbox.cassandra.modules.CassandraAclModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraMailboxModule;
-import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.exception.MailboxNotFoundException;
 import org.apache.james.mailbox.exception.TooLongMailboxNameException;
 import org.apache.james.mailbox.model.Mailbox;
@@ -140,8 +139,8 @@ class CassandraMailboxMapperTest {
         @Nested
         class Retries {
             @Test
-            void renameShouldRetryFailedDeleteMailboxPath(CassandraCluster cassandra) throws Exception {
-                Mailbox inbox = testee.create(inboxPath, UID_VALIDITY);
+            void renameShouldRetryFailedDeleteMailboxPath(CassandraCluster cassandra) {
+                Mailbox inbox = testee.create(inboxPath, UID_VALIDITY).block();
                 MailboxId inboxId = inbox.getMailboxId();
                 Mailbox inboxRenamed = createInboxRenamedMailbox(inboxId);
 
@@ -150,11 +149,11 @@ class CassandraMailboxMapperTest {
                         .times(1)
                         .whenQueryStartsWith("DELETE FROM mailboxPathV2 WHERE namespace=:namespace AND user=:user AND mailboxName=:mailboxName IF EXISTS;"));
 
-                testee.rename(inboxRenamed);
+                testee.rename(inboxRenamed).block();
 
                 SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
                     softly(softly)
-                        .assertThat(testee.findMailboxById(inboxId))
+                        .assertThat(testee.findMailboxById(inboxId).block())
                         .isEqualTo(inboxRenamed);
                     softly(softly)
                         .assertThat(testee.findMailboxByPath(inboxPathRenamed).block())
@@ -168,8 +167,8 @@ class CassandraMailboxMapperTest {
             }
 
             @Test
-            void renameShouldRetryFailedMailboxSaving(CassandraCluster cassandra) throws Exception {
-                Mailbox inbox = testee.create(inboxPath, UID_VALIDITY);
+            void renameShouldRetryFailedMailboxSaving(CassandraCluster cassandra) {
+                Mailbox inbox = testee.create(inboxPath, UID_VALIDITY).block();
                 MailboxId inboxId = inbox.getMailboxId();
                 Mailbox inboxRenamed = createInboxRenamedMailbox(inboxId);
 
@@ -178,11 +177,11 @@ class CassandraMailboxMapperTest {
                     .times(1)
                     .whenQueryStartsWith("INSERT INTO mailbox (id,name,uidvalidity,mailboxbase) VALUES (:id,:name,:uidvalidity,:mailboxbase);"));
 
-                testee.rename(inboxRenamed);
+                testee.rename(inboxRenamed).block();
 
                 SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
                     softly(softly)
-                        .assertThat(testee.findMailboxById(inboxId))
+                        .assertThat(testee.findMailboxById(inboxId).block())
                         .isEqualTo(inboxRenamed);
                     softly(softly)
                         .assertThat(testee.findMailboxByPath(inboxPathRenamed).block())
@@ -196,17 +195,17 @@ class CassandraMailboxMapperTest {
             }
 
             @Test
-            void createShouldRetryFailedMailboxSaving(CassandraCluster cassandra) throws Exception {
+            void createShouldRetryFailedMailboxSaving(CassandraCluster cassandra) {
                 cassandra.getConf()
                     .registerScenario(fail()
                         .times(1)
                         .whenQueryStartsWith("INSERT INTO mailbox (id,name,uidvalidity,mailboxbase) VALUES (:id,:name,:uidvalidity,:mailboxbase);"));
 
-                Mailbox inbox = testee.create(inboxPath, UID_VALIDITY);
+                Mailbox inbox = testee.create(inboxPath, UID_VALIDITY).block();
 
                 SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
                     softly(softly)
-                        .assertThat(testee.findMailboxById(inbox.getMailboxId()))
+                        .assertThat(testee.findMailboxById(inbox.getMailboxId()).block())
                         .isEqualTo(inbox);
                     softly(softly)
                         .assertThat(testee.findMailboxByPath(inboxPath).block())
@@ -220,19 +219,19 @@ class CassandraMailboxMapperTest {
             }
 
             @Test
-            void deleteShouldRetryFailedMailboxDeletion(CassandraCluster cassandra) throws Exception {
-                Mailbox inbox = testee.create(inboxPath, UID_VALIDITY);
+            void deleteShouldRetryFailedMailboxDeletion(CassandraCluster cassandra) {
+                Mailbox inbox = testee.create(inboxPath, UID_VALIDITY).block();
 
                 cassandra.getConf()
                     .registerScenario(fail()
                     .times(1)
                     .whenQueryStartsWith("DELETE FROM mailbox WHERE id=:id;"));
 
-                testee.delete(inbox);
+                testee.delete(inbox).block();
 
                 SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-                    softly.assertThatThrownBy(() -> testee.findMailboxById(inbox.getMailboxId()))
-                        .isInstanceOf(MailboxNotFoundException.class);
+                    softly.assertThatThrownBy(() -> testee.findMailboxById(inbox.getMailboxId()).block())
+                        .hasCauseInstanceOf(MailboxNotFoundException.class);
                     softly.assertThat(testee.findMailboxByPath(inboxPath).blockOptional())
                         .isEmpty();
                     softly.assertThat(testee.findMailboxWithPathLike(allMailboxesSearchQuery)
@@ -249,7 +248,7 @@ class CassandraMailboxMapperTest {
                     .times(10)
                     .whenQueryStartsWith("INSERT INTO mailbox (id,name,uidvalidity,mailboxbase) VALUES (:id,:name,:uidvalidity,:mailboxbase);"));
 
-            doQuietly(() -> testee.create(inboxPath, UID_VALIDITY));
+            doQuietly(() -> testee.create(inboxPath, UID_VALIDITY).block());
 
             SoftAssertions.assertSoftly(softly -> {
                 softly.assertThat(testee.findMailboxByPath(inboxPath).blockOptional())
@@ -264,8 +263,8 @@ class CassandraMailboxMapperTest {
         }
 
         @Test
-        void renameThenFailToRetrieveMailboxShouldBeConsistentWhenFindByInbox(CassandraCluster cassandra) throws Exception {
-            Mailbox inbox = testee.create(inboxPath, UID_VALIDITY);
+        void renameThenFailToRetrieveMailboxShouldBeConsistentWhenFindByInbox(CassandraCluster cassandra) {
+            Mailbox inbox = testee.create(inboxPath, UID_VALIDITY).block();
             CassandraId inboxId = (CassandraId) inbox.getMailboxId();
             Mailbox inboxRenamed = createInboxRenamedMailbox(inboxId);
 
@@ -280,7 +279,7 @@ class CassandraMailboxMapperTest {
 
             SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
                 softly(softly)
-                    .assertThat(testee.findMailboxById(inboxId))
+                    .assertThat(testee.findMailboxById(inboxId).block())
                     .isEqualTo(inbox);
                 softly(softly)
                     .assertThat(testee.findMailboxByPath(inboxPath).block())
@@ -295,8 +294,8 @@ class CassandraMailboxMapperTest {
 
         @Disabled("JAMES-3056 returning two mailboxes with same name and id")
         @Test
-        void renameThenFailToRetrieveMailboxShouldBeConsistentWhenFindAll(CassandraCluster cassandra) throws Exception {
-            Mailbox inbox = testee.create(inboxPath, UID_VALIDITY);
+        void renameThenFailToRetrieveMailboxShouldBeConsistentWhenFindAll(CassandraCluster cassandra) {
+            Mailbox inbox = testee.create(inboxPath, UID_VALIDITY).block();
             CassandraId inboxId = (CassandraId) inbox.getMailboxId();
             Mailbox inboxRenamed = createInboxRenamedMailbox(inboxId);
 
@@ -305,21 +304,21 @@ class CassandraMailboxMapperTest {
                     .times(TRY_COUNT_BEFORE_FAILURE)
                     .whenQueryStartsWith("SELECT id,mailboxbase,uidvalidity,name FROM mailbox WHERE id=:id;"));
 
-            doQuietly(() -> testee.rename(inboxRenamed));
+            doQuietly(() -> testee.rename(inboxRenamed).block());
 
-            SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
+            SoftAssertions.assertSoftly(Throwing.consumer(softly ->
                 softly.assertThat(testee.findMailboxWithPathLike(allMailboxesSearchQuery)
                     .collectList().block())
                     .hasOnlyOneElementSatisfying(searchMailbox -> softly(softly)
                         .assertThat(searchMailbox)
-                        .isEqualTo(inbox));
-            }));
+                        .isEqualTo(inbox))
+            ));
         }
 
         @Disabled("JAMES-3056 find by renamed name returns unexpected results")
         @Test
-        void renameThenFailToRetrieveMailboxShouldBeConsistentWhenFindByRenamedInbox(CassandraCluster cassandra) throws Exception {
-            Mailbox inbox = testee.create(inboxPath, UID_VALIDITY);
+        void renameThenFailToRetrieveMailboxShouldBeConsistentWhenFindByRenamedInbox(CassandraCluster cassandra) {
+            Mailbox inbox = testee.create(inboxPath, UID_VALIDITY).block();
             CassandraId inboxId = (CassandraId) inbox.getMailboxId();
             Mailbox inboxRenamed = createInboxRenamedMailbox(inboxId);
 
@@ -328,10 +327,10 @@ class CassandraMailboxMapperTest {
                     .times(TRY_COUNT_BEFORE_FAILURE)
                     .whenQueryStartsWith("SELECT id,mailboxbase,uidvalidity,name FROM mailbox WHERE id=:id;"));
 
-            doQuietly(() -> testee.rename(inboxRenamed));
+            doQuietly(() -> testee.rename(inboxRenamed).block());
 
             SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-                softly.assertThatThrownBy(() -> testee.findMailboxByPath(inboxPathRenamed))
+                softly.assertThatThrownBy(() -> testee.findMailboxByPath(inboxPathRenamed).block())
                     .isInstanceOf(MailboxNotFoundException.class);
                 softly.assertThat(testee.findMailboxWithPathLike(inboxRenamedSearchQuery)
                     .collectList().block())
@@ -340,8 +339,8 @@ class CassandraMailboxMapperTest {
         }
 
         @Test
-        void renameThenFailToDeleteMailboxPathShouldBeConsistentWhenFindByInbox(CassandraCluster cassandra) throws Exception {
-            Mailbox inbox = testee.create(inboxPath, UID_VALIDITY);
+        void renameThenFailToDeleteMailboxPathShouldBeConsistentWhenFindByInbox(CassandraCluster cassandra) {
+            Mailbox inbox = testee.create(inboxPath, UID_VALIDITY).block();
             CassandraId inboxId = (CassandraId) inbox.getMailboxId();
             Mailbox inboxRenamed = createInboxRenamedMailbox(inboxId);
 
@@ -350,11 +349,11 @@ class CassandraMailboxMapperTest {
                     .times(TRY_COUNT_BEFORE_FAILURE)
                     .whenQueryStartsWith("DELETE FROM mailboxPathV2 WHERE namespace=:namespace AND user=:user AND mailboxName=:mailboxName IF EXISTS;"));
 
-            doQuietly(() -> testee.rename(inboxRenamed));
+            doQuietly(() -> testee.rename(inboxRenamed).block());
 
             SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
                 softly(softly)
-                    .assertThat(testee.findMailboxById(inboxId))
+                    .assertThat(testee.findMailboxById(inboxId).block())
                     .isEqualTo(inbox);
                 softly(softly)
                     .assertThat(testee.findMailboxByPath(inboxPath).block())
@@ -369,8 +368,8 @@ class CassandraMailboxMapperTest {
 
         @Disabled("JAMES-3056 returning two mailboxes with same name and id")
         @Test
-        void renameThenFailToDeleteMailboxPathShouldBeConsistentWhenFindAll(CassandraCluster cassandra) throws Exception {
-            Mailbox inbox = testee.create(inboxPath, UID_VALIDITY);
+        void renameThenFailToDeleteMailboxPathShouldBeConsistentWhenFindAll(CassandraCluster cassandra) {
+            Mailbox inbox = testee.create(inboxPath, UID_VALIDITY).block();
             CassandraId inboxId = (CassandraId) inbox.getMailboxId();
             Mailbox inboxRenamed = createInboxRenamedMailbox(inboxId);
 
@@ -379,21 +378,20 @@ class CassandraMailboxMapperTest {
                     .times(TRY_COUNT_BEFORE_FAILURE)
                     .whenQueryStartsWith("DELETE FROM mailboxPathV2 WHERE namespace=:namespace AND user=:user AND mailboxName=:mailboxName IF EXISTS;"));
 
-            doQuietly(() -> testee.rename(inboxRenamed));
+            doQuietly(() -> testee.rename(inboxRenamed).block());
 
-            SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
+            SoftAssertions.assertSoftly(Throwing.consumer(softly ->
                 softly.assertThat(testee.findMailboxWithPathLike(allMailboxesSearchQuery)
                     .collectList().block())
                     .hasOnlyOneElementSatisfying(searchMailbox -> softly(softly)
                         .assertThat(searchMailbox)
-                        .isEqualTo(inbox));
-            }));
+                        .isEqualTo(inbox))));
         }
 
         @Disabled("JAMES-3056 find by renamed name returns unexpected results")
         @Test
-        void renameThenFailToDeleteMailboxPathShouldBeConsistentWhenFindByRenamedInbox(CassandraCluster cassandra) throws Exception {
-            Mailbox inbox = testee.create(inboxPath, UID_VALIDITY);
+        void renameThenFailToDeleteMailboxPathShouldBeConsistentWhenFindByRenamedInbox(CassandraCluster cassandra) {
+            Mailbox inbox = testee.create(inboxPath, UID_VALIDITY).block();
             CassandraId inboxId = (CassandraId) inbox.getMailboxId();
             Mailbox inboxRenamed = createInboxRenamedMailbox(inboxId);
 
@@ -402,10 +400,10 @@ class CassandraMailboxMapperTest {
                     .times(TRY_COUNT_BEFORE_FAILURE)
                     .whenQueryStartsWith("DELETE FROM mailboxPathV2 WHERE namespace=:namespace AND user=:user AND mailboxName=:mailboxName IF EXISTS;"));
 
-            doQuietly(() -> testee.rename(inboxRenamed));
+            doQuietly(() -> testee.rename(inboxRenamed).block());
 
             SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-                softly.assertThatThrownBy(() -> testee.findMailboxByPath(inboxPathRenamed))
+                softly.assertThatThrownBy(() -> testee.findMailboxByPath(inboxPathRenamed).block())
                     .isInstanceOf(MailboxNotFoundException.class);
                 softly.assertThat(testee.findMailboxWithPathLike(inboxRenamedSearchQuery)
                     .collectList().block())
@@ -415,8 +413,8 @@ class CassandraMailboxMapperTest {
 
         @Disabled("JAMES-3056 find by mailbox name returns unexpected results")
         @Test
-        void deleteShouldBeConsistentWhenFailToDeleteMailbox(CassandraCluster cassandra) throws Exception {
-            Mailbox inbox = testee.create(inboxPath, UID_VALIDITY);
+        void deleteShouldBeConsistentWhenFailToDeleteMailbox(CassandraCluster cassandra) {
+            Mailbox inbox = testee.create(inboxPath, UID_VALIDITY).block();
             CassandraId inboxId = (CassandraId) inbox.getMailboxId();
 
             cassandra.getConf()
@@ -424,12 +422,12 @@ class CassandraMailboxMapperTest {
                     .times(TRY_COUNT_BEFORE_FAILURE)
                     .whenQueryStartsWith("DELETE FROM mailbox WHERE id=:id;"));
 
-            doQuietly(() -> testee.delete(inbox));
+            doQuietly(() -> testee.delete(inbox).block());
 
             SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-                softly.assertThatCode(() -> testee.findMailboxById(inboxId))
+                softly.assertThatCode(() -> testee.findMailboxById(inboxId).block())
                     .doesNotThrowAnyException();
-                softly.assertThatCode(() -> testee.findMailboxByPath(inboxPath))
+                softly.assertThatCode(() -> testee.findMailboxByPath(inboxPath).block())
                     .doesNotThrowAnyException();
                 softly.assertThat(testee.findMailboxWithPathLike(inboxSearchQuery)
                     .collectList().block())
@@ -446,8 +444,8 @@ class CassandraMailboxMapperTest {
 
         @Disabled("JAMES-3056 both mailboxes of the same user have 'INBOX' name")
         @Test
-        void missedMigrationShouldNotLeadToGhostMailbox() throws Exception {
-            Mailbox inbox = testee.create(inboxPath, UID_VALIDITY);
+        void missedMigrationShouldNotLeadToGhostMailbox() {
+            Mailbox inbox = testee.create(inboxPath, UID_VALIDITY).block();
             CassandraId inboxId = (CassandraId) inbox.getMailboxId();
             // simulate mailbox old data has not been migrated to v2
             mailboxPathDAO.save(inboxPath, inboxId).block();
@@ -457,23 +455,23 @@ class CassandraMailboxMapperTest {
             // => two mailboxes with same name but different ids
             CassandraId newId = CassandraId.timeBased();
             Mailbox mailboxHasSameNameWithInbox = new Mailbox(inboxPath, UID_VALIDITY, newId);
-            testee.rename(mailboxHasSameNameWithInbox);
+            testee.rename(mailboxHasSameNameWithInbox).block();
 
-            assertThat(testee.findMailboxById(newId).getName())
-                .isNotEqualTo(testee.findMailboxById(inboxId).getName());
+            assertThat(testee.findMailboxById(newId).block().getName())
+                .isNotEqualTo(testee.findMailboxById(inboxId).block().getName());
         }
 
         @Disabled("JAMES-3056 org.apache.james.mailbox.exception.MailboxNotFoundException: 'mailboxId' can not be found")
         @Test
-        void createAfterPreviousFailedCreateShouldCreateAMailbox(CassandraCluster cassandra) throws MailboxException {
+        void createAfterPreviousFailedCreateShouldCreateAMailbox(CassandraCluster cassandra) {
             cassandra.getConf()
                 .registerScenario(fail()
                     .times(TRY_COUNT_BEFORE_FAILURE)
                     .whenQueryStartsWith("INSERT INTO mailbox (id,name,uidvalidity,mailboxbase) VALUES (:id,:name,:uidvalidity,:mailboxbase);"));
 
-            doQuietly(() -> testee.create(inboxPath, UID_VALIDITY));
+            doQuietly(() -> testee.create(inboxPath, UID_VALIDITY).block());
 
-            Mailbox inbox = testee.create(inboxPath, UID_VALIDITY);
+            Mailbox inbox = testee.create(inboxPath, UID_VALIDITY).block();
 
             SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
                 softly(softly)
@@ -493,16 +491,16 @@ class CassandraMailboxMapperTest {
         }
 
         @Test
-        void createAfterPreviousDeleteOnFailedCreateShouldCreateAMailbox(CassandraCluster cassandra) throws MailboxException {
+        void createAfterPreviousDeleteOnFailedCreateShouldCreateAMailbox(CassandraCluster cassandra) {
             cassandra.getConf()
                 .registerScenario(fail()
                     .times(TRY_COUNT_BEFORE_FAILURE)
                     .whenQueryStartsWith("INSERT INTO mailbox (id,name,uidvalidity,mailboxbase) VALUES (:id,:name,:uidvalidity,:mailboxbase);"));
 
-            doQuietly(() -> testee.create(inboxPath, UID_VALIDITY));
-            doQuietly(() -> testee.delete(new Mailbox(inboxPath, UID_VALIDITY, CassandraId.timeBased())));
+            doQuietly(() -> testee.create(inboxPath, UID_VALIDITY).block());
+            doQuietly(() -> testee.delete(new Mailbox(inboxPath, UID_VALIDITY, CassandraId.timeBased())).block());
 
-            Mailbox inbox = testee.create(inboxPath, UID_VALIDITY);
+            Mailbox inbox = testee.create(inboxPath, UID_VALIDITY).block();
 
             SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
                 softly(softly)
@@ -522,8 +520,8 @@ class CassandraMailboxMapperTest {
         }
 
         @Test
-        void deleteAfterAFailedDeleteShouldDeleteTheMailbox(CassandraCluster cassandra) throws Exception {
-            Mailbox inbox = testee.create(inboxPath, UID_VALIDITY);
+        void deleteAfterAFailedDeleteShouldDeleteTheMailbox(CassandraCluster cassandra) {
+            Mailbox inbox = testee.create(inboxPath, UID_VALIDITY).block();
             CassandraId inboxId = (CassandraId) inbox.getMailboxId();
 
             cassandra.getConf()
@@ -531,13 +529,13 @@ class CassandraMailboxMapperTest {
                     .times(TRY_COUNT_BEFORE_FAILURE)
                     .whenQueryStartsWith("DELETE FROM mailbox WHERE id=:id;"));
 
-            doQuietly(() -> testee.delete(inbox));
+            doQuietly(() -> testee.delete(inbox).block());
 
-            doQuietly(() -> testee.delete(inbox));
+            doQuietly(() -> testee.delete(inbox).block());
 
             SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-                softly.assertThatThrownBy(() -> testee.findMailboxById(inboxId))
-                    .isInstanceOf(MailboxNotFoundException.class);
+                softly.assertThatThrownBy(() -> testee.findMailboxById(inboxId).block())
+                    .hasCauseInstanceOf(MailboxNotFoundException.class);
                     softly.assertThat(testee.findMailboxByPath(inboxPath).blockOptional())
                         .isEmpty();
                 softly.assertThat(testee.findMailboxWithPathLike(inboxSearchQuery)
@@ -552,8 +550,8 @@ class CassandraMailboxMapperTest {
         @Disabled("JAMES-3056 mailbox name is not updated to INBOX_RENAMED).isEqualTo(" +
             "findMailboxWithPathLike() returns a list with two same mailboxes")
         @Test
-        void renameAfterRenameFailOnRetrieveMailboxShouldRenameTheMailbox(CassandraCluster cassandra) throws Exception {
-            Mailbox inbox = testee.create(inboxPath, UID_VALIDITY);
+        void renameAfterRenameFailOnRetrieveMailboxShouldRenameTheMailbox(CassandraCluster cassandra) {
+            Mailbox inbox = testee.create(inboxPath, UID_VALIDITY).block();
             CassandraId inboxId = (CassandraId) inbox.getMailboxId();
             Mailbox inboxRenamed = createInboxRenamedMailbox(inboxId);
 
@@ -562,13 +560,13 @@ class CassandraMailboxMapperTest {
                     .times(TRY_COUNT_BEFORE_FAILURE)
                     .whenQueryStartsWith("SELECT id,mailboxbase,uidvalidity,name FROM mailbox WHERE id=:id;"));
 
-            doQuietly(() -> testee.rename(inboxRenamed));
+            doQuietly(() -> testee.rename(inboxRenamed).block());
 
-            doQuietly(() -> testee.rename(inboxRenamed));
+            doQuietly(() -> testee.rename(inboxRenamed).block());
 
             SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
                 softly(softly)
-                    .assertThat(testee.findMailboxById(inboxId))
+                    .assertThat(testee.findMailboxById(inboxId).block())
                     .isEqualTo(inboxRenamed);
                 softly(softly)
                     .assertThat(testee.findMailboxByPath(inboxPathRenamed).block())
@@ -591,8 +589,8 @@ class CassandraMailboxMapperTest {
 
         @Disabled("JAMES-3056 mailbox name is not updated to INBOX_RENAMED")
         @Test
-        void renameAfterRenameFailOnDeletePathShouldRenameTheMailbox(CassandraCluster cassandra) throws Exception {
-            Mailbox inbox = testee.create(inboxPath, UID_VALIDITY);
+        void renameAfterRenameFailOnDeletePathShouldRenameTheMailbox(CassandraCluster cassandra) {
+            Mailbox inbox = testee.create(inboxPath, UID_VALIDITY).block();
             CassandraId inboxId = (CassandraId) inbox.getMailboxId();
             Mailbox inboxRenamed = createInboxRenamedMailbox(inboxId);
 
@@ -601,13 +599,13 @@ class CassandraMailboxMapperTest {
                     .times(TRY_COUNT_BEFORE_FAILURE)
                     .whenQueryStartsWith("DELETE FROM mailboxPathV2 WHERE namespace=:namespace AND user=:user AND mailboxName=:mailboxName IF EXISTS;"));
 
-            doQuietly(() -> testee.rename(inboxRenamed));
+            doQuietly(() -> testee.rename(inboxRenamed).block());
 
-            doQuietly(() -> testee.rename(inboxRenamed));
+            doQuietly(() -> testee.rename(inboxRenamed).block());
 
             SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
                 softly(softly)
-                    .assertThat(testee.findMailboxById(inboxId))
+                    .assertThat(testee.findMailboxById(inboxId).block())
                     .isEqualTo(inboxRenamed);
                 softly(softly)
                     .assertThat(testee.findMailboxByPath(inboxPathRenamed).block())
@@ -644,12 +642,12 @@ class CassandraMailboxMapperTest {
 
     @Disabled("JAMES-2514 Cassandra 3 supports long mailbox names. Hence we can not rely on this for failing")
     @Test
-    void renameShouldNotRemoveOldMailboxPathWhenCreatingTheNewMailboxPathFails() throws Exception {
-        testee.create(MAILBOX_PATH, UID_VALIDITY);
+    void renameShouldNotRemoveOldMailboxPathWhenCreatingTheNewMailboxPathFails() {
+        testee.create(MAILBOX_PATH, UID_VALIDITY).block();
         Mailbox mailbox = testee.findMailboxByPath(MAILBOX_PATH).block();
 
         Mailbox newMailbox = new Mailbox(tooLongMailboxPath(mailbox.generateAssociatedPath()), UID_VALIDITY, mailbox.getMailboxId());
-        assertThatThrownBy(() -> testee.rename(newMailbox))
+        assertThatThrownBy(() -> testee.rename(newMailbox).block())
             .isInstanceOf(TooLongMailboxNameException.class);
 
         assertThat(mailboxPathV2DAO.retrieveId(MAILBOX_PATH).blockOptional())
@@ -667,7 +665,7 @@ class CassandraMailboxMapperTest {
         mailboxPathDAO.save(MAILBOX_PATH, MAILBOX_ID)
             .block();
 
-        testee.delete(MAILBOX);
+        testee.delete(MAILBOX).block();
 
         assertThat(testee.findMailboxByPath(MAILBOX_PATH).blockOptional())
             .isEmpty();
@@ -680,7 +678,7 @@ class CassandraMailboxMapperTest {
         mailboxPathV2DAO.save(MAILBOX_PATH, MAILBOX_ID)
             .block();
 
-        testee.delete(MAILBOX);
+        testee.delete(MAILBOX).block();
 
         assertThat(testee.findMailboxByPath(MAILBOX_PATH).blockOptional())
             .isEmpty();
@@ -733,7 +731,7 @@ class CassandraMailboxMapperTest {
         mailboxPathV2DAO.save(MAILBOX_PATH, MAILBOX_ID)
             .block();
 
-        testee.delete(MAILBOX);
+        testee.delete(MAILBOX).block();
 
         assertThat(testee.findMailboxByPath(MAILBOX_PATH).blockOptional())
             .isEmpty();
@@ -746,7 +744,7 @@ class CassandraMailboxMapperTest {
         mailboxPathDAO.save(MAILBOX_PATH, MAILBOX_ID)
             .block();
 
-        testee.delete(MAILBOX);
+        testee.delete(MAILBOX).block();
 
         assertThat(testee.findMailboxByPath(MAILBOX_PATH).blockOptional())
             .isEmpty();
@@ -759,7 +757,7 @@ class CassandraMailboxMapperTest {
         mailboxPathV2DAO.save(MAILBOX_PATH, MAILBOX_ID)
             .block();
 
-        testee.delete(MAILBOX);
+        testee.delete(MAILBOX).block();
 
         assertThat(testee.findMailboxByPath(MAILBOX_PATH).blockOptional())
             .isEmpty();
@@ -780,7 +778,7 @@ class CassandraMailboxMapperTest {
             .block();
         mailboxPathDAO.save(MAILBOX_PATH, MAILBOX_ID)
             .block();
-    
+
         List<Mailbox> mailboxes = testee.findMailboxWithPathLike(MailboxQuery.builder()
             .privateNamespace()
             .username(USER)
@@ -818,7 +816,7 @@ class CassandraMailboxMapperTest {
             .block();
         mailboxPathV2DAO.save(MAILBOX_PATH, MAILBOX_ID)
             .block();
-    
+
         List<Mailbox> mailboxes = testee.findMailboxWithPathLike(MailboxQuery.builder()
             .privateNamespace()
             .username(USER)
@@ -844,7 +842,7 @@ class CassandraMailboxMapperTest {
         mailboxPathDAO.save(childMailboxPath, childMailboxId)
             .block();
     
-        boolean hasChildren = testee.hasChildren(MAILBOX, '.');
+        boolean hasChildren = testee.hasChildren(MAILBOX, '.').block();
 
         assertThat(hasChildren).isTrue();
     }
@@ -865,7 +863,7 @@ class CassandraMailboxMapperTest {
         mailboxPathDAO.save(childMailboxPath, childMailboxId)
             .block();
 
-        boolean hasChildren = testee.hasChildren(MAILBOX, '.');
+        boolean hasChildren = testee.hasChildren(MAILBOX, '.').block();
 
         assertThat(hasChildren).isTrue();
     }
@@ -884,7 +882,7 @@ class CassandraMailboxMapperTest {
         mailboxPathV2DAO.save(childMailboxPath, childMailboxId)
             .block();
     
-        boolean hasChildren = testee.hasChildren(MAILBOX, '.');
+        boolean hasChildren = testee.hasChildren(MAILBOX, '.').block();
     
         assertThat(hasChildren).isTrue();
     }
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/migration/MailboxPathV2MigrationTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/migration/MailboxPathV2MigrationTest.java
index e018eb1..ee4be70 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/migration/MailboxPathV2MigrationTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/migration/MailboxPathV2MigrationTest.java
@@ -40,7 +40,6 @@ import org.apache.james.mailbox.cassandra.mail.CassandraMailboxPathV2DAO;
 import org.apache.james.mailbox.cassandra.mail.CassandraUserMailboxRightsDAO;
 import org.apache.james.mailbox.cassandra.modules.CassandraAclModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraMailboxModule;
-import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.Mailbox;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.UidValidity;
@@ -90,7 +89,7 @@ class MailboxPathV2MigrationTest {
     }
 
     @Test
-    void newValuesShouldBeSavedInMostRecentDAO() throws Exception {
+    void newValuesShouldBeSavedInMostRecentDAO() {
         Mailbox mailbox = createMailbox();
         CassandraId mailboxId = (CassandraId) mailbox.getMailboxId();
 
@@ -99,7 +98,7 @@ class MailboxPathV2MigrationTest {
     }
 
     @Test
-    void newValuesShouldNotBeSavedInOldDAO() throws Exception {
+    void newValuesShouldNotBeSavedInOldDAO() {
         createMailbox();
 
         assertThat(daoV1.retrieveId(MAILBOX_PATH_1).blockOptional())
@@ -107,7 +106,7 @@ class MailboxPathV2MigrationTest {
     }
 
     @Test
-    void readingOldValuesShouldMigrateThem() throws Exception {
+    void readingOldValuesShouldMigrateThem() {
         Mailbox mailbox = new Mailbox(MAILBOX_PATH_1, UID_VALIDITY_1, MAILBOX_ID_1);
 
         daoV1.save(MAILBOX_PATH_1, MAILBOX_ID_1).block();
@@ -135,7 +134,7 @@ class MailboxPathV2MigrationTest {
         softly.assertAll();
     }
 
-    private Mailbox createMailbox() throws MailboxException {
-        return mailboxMapper.create(MAILBOX_PATH_1, UID_VALIDITY_1);
+    private Mailbox createMailbox() {
+        return mailboxMapper.create(MAILBOX_PATH_1, UID_VALIDITY_1).block();
     }
 }
\ No newline at end of file
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
index b934ec3..c9ea4e6 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
@@ -187,7 +187,7 @@ class ElasticSearchListeningMessageSearchIndexTest {
             messageToElasticSearchJson, sessionProvider, new MailboxIdRoutingKeyFactory());
         session = sessionProvider.createSystemSession(USERNAME);
 
-        mailbox = mapperFactory.getMailboxMapper(session).create(MailboxPath.forUser(USERNAME, DefaultMailboxes.INBOX), UidValidity.generate());
+        mailbox = mapperFactory.getMailboxMapper(session).create(MailboxPath.forUser(USERNAME, DefaultMailboxes.INBOX), UidValidity.generate()).block();
     }
 
     @Test
diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMailboxMapper.java b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMailboxMapper.java
index d5bfe96..f9c9f44 100644
--- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMailboxMapper.java
+++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMailboxMapper.java
@@ -84,39 +84,31 @@ public class JPAMailboxMapper extends JPATransactionalMapper implements MailboxM
     }
     
     @Override
-    public Mailbox create(MailboxPath mailboxPath, UidValidity uidValidity) throws MailboxException {
-        try {
-            if (isPathAlreadyUsedByAnotherMailbox(mailboxPath)) {
-                throw new MailboxExistsException(mailboxPath.getName());
-            }
-
-            this.lastMailboxName = mailboxPath.getName();
-            JPAMailbox persistedMailbox = new JPAMailbox(mailboxPath, uidValidity);
-            getEntityManager().persist(persistedMailbox);
+    public Mono<Mailbox> create(MailboxPath mailboxPath, UidValidity uidValidity) {
+        return assertPathIsNotAlreadyUsedByAnotherMailbox(mailboxPath)
+            .then(Mono.fromCallable(() -> {
+                this.lastMailboxName = mailboxPath.getName();
+                JPAMailbox persistedMailbox = new JPAMailbox(mailboxPath, uidValidity);
+                getEntityManager().persist(persistedMailbox);
 
-            return new Mailbox(mailboxPath, uidValidity, persistedMailbox.getMailboxId());
-        } catch (PersistenceException e) {
-            throw new MailboxException("Save of mailbox " + mailboxPath.getName() + " failed", e);
-        }
+                return new Mailbox(mailboxPath, uidValidity, persistedMailbox.getMailboxId());
+            }))
+            .onErrorMap(PersistenceException.class, e -> new MailboxException("Save of mailbox " + mailboxPath.getName() + " failed", e));
     }
 
     @Override
-    public MailboxId rename(Mailbox mailbox) throws MailboxException {
+    public Mono<MailboxId> rename(Mailbox mailbox) {
         Preconditions.checkNotNull(mailbox.getMailboxId(), "A mailbox we want to rename should have a defined mailboxId");
 
-        try {
-            if (isPathAlreadyUsedByAnotherMailbox(mailbox.generateAssociatedPath())) {
-                throw new MailboxExistsException(mailbox.getName());
-            }
-
-            this.lastMailboxName = mailbox.getName();
-            JPAMailbox persistedMailbox = jpaMailbox(mailbox);
+        return assertPathIsNotAlreadyUsedByAnotherMailbox(mailbox.generateAssociatedPath())
+            .then(Mono.fromCallable(() -> {
+                this.lastMailboxName = mailbox.getName();
+                JPAMailbox persistedMailbox = jpaMailbox(mailbox);
 
-            getEntityManager().persist(persistedMailbox);
-            return persistedMailbox.getMailboxId();
-        } catch (PersistenceException e) {
-            throw new MailboxException("Save of mailbox " + mailbox.getName() + " failed", e);
-        } 
+                getEntityManager().persist(persistedMailbox);
+                return (MailboxId) persistedMailbox.getMailboxId();
+            }))
+            .onErrorMap(PersistenceException.class, e -> new MailboxException("Save of mailbox " + mailbox.getName() + " failed", e));
     }
 
     private JPAMailbox jpaMailbox(Mailbox mailbox) throws MailboxException {
@@ -127,36 +119,27 @@ public class JPAMailboxMapper extends JPATransactionalMapper implements MailboxM
         return result;
     }
 
-    private boolean isPathAlreadyUsedByAnotherMailbox(MailboxPath mailboxPath) throws MailboxException {
+    private Mono<Void> assertPathIsNotAlreadyUsedByAnotherMailbox(MailboxPath mailboxPath) {
         return findMailboxByPath(mailboxPath)
-            .blockOptional()
-            .isPresent();
+            .flatMap(ignored -> Mono.error(new MailboxExistsException(mailboxPath.getName())));
     }
 
     @Override
     public Mono<Mailbox> findMailboxByPath(MailboxPath mailboxPath)  {
-        try {
-            return Mono.just(getEntityManager().createNamedQuery("findMailboxByNameWithUser", JPAMailbox.class)
-                .setParameter("nameParam", mailboxPath.getName())
-                .setParameter("namespaceParam", mailboxPath.getNamespace())
-                .setParameter("userParam", mailboxPath.getUser().asString())
-                .getSingleResult()
-                .toMailbox());
-        } catch (NoResultException e) {
-            return Mono.empty();
-        } catch (PersistenceException e) {
-            return Mono.error(new MailboxException("Exception upon JPA execution", e));
-        }
+        return Mono.fromCallable(() -> getEntityManager().createNamedQuery("findMailboxByNameWithUser", JPAMailbox.class)
+            .setParameter("nameParam", mailboxPath.getName())
+            .setParameter("namespaceParam", mailboxPath.getNamespace())
+            .setParameter("userParam", mailboxPath.getUser().asString())
+            .getSingleResult()
+            .toMailbox())
+            .onErrorResume(NoResultException.class, e -> Mono.empty())
+            .onErrorResume(PersistenceException.class, e -> Mono.error(new MailboxException("Exception upon JPA execution", e)));
     }
 
     @Override
-    public Mailbox findMailboxById(MailboxId id) throws MailboxException, MailboxNotFoundException {
-
-        try {
-            return loadJpaMailbox(id).toMailbox();
-        } catch (PersistenceException e) {
-            throw new MailboxException("Search of mailbox " + id.serialize() + " failed", e);
-        } 
+    public Mono<Mailbox> findMailboxById(MailboxId id) {
+        return Mono.fromCallable(() -> loadJpaMailbox(id).toMailbox())
+            .onErrorMap(PersistenceException.class, e -> new MailboxException("Search of mailbox " + id.serialize() + " failed", e));
     }
 
     private JPAMailbox loadJpaMailbox(MailboxId id) throws MailboxNotFoundException {
@@ -171,28 +154,25 @@ public class JPAMailboxMapper extends JPATransactionalMapper implements MailboxM
     }
 
     @Override
-    public void delete(Mailbox mailbox) throws MailboxException {
-        try {  
+    public Mono<Void> delete(Mailbox mailbox) {
+        return Mono.fromRunnable(() -> {
             JPAId mailboxId = (JPAId) mailbox.getMailboxId();
             getEntityManager().createNamedQuery("deleteMessages").setParameter("idParam", mailboxId.getRawId()).executeUpdate();
             JPAMailbox jpaMailbox = getEntityManager().find(JPAMailbox.class, mailboxId.getRawId());
             getEntityManager().remove(jpaMailbox);
-        } catch (PersistenceException e) {
-            throw new MailboxException("Delete of mailbox " + mailbox + " failed", e);
-        } 
+        })
+        .onErrorMap(PersistenceException.class, e -> new MailboxException("Delete of mailbox " + mailbox + " failed", e))
+        .then();
     }
 
     @Override
-    public Flux<Mailbox> findMailboxWithPathLike(MailboxQuery.UserBound query) throws MailboxException {
-        try {
-            String pathLike = MailboxExpressionBackwardCompatibility.getPathLike(query);
-            return Flux.fromIterable(findMailboxWithPathLikeTypedQuery(query.getFixedNamespace(), query.getFixedUser(), pathLike)
-                .getResultList())
-                .map(JPAMailbox::toMailbox)
-                .filter(query::matches);
-        } catch (PersistenceException e) {
-            throw new MailboxException("Search of mailbox " + query + " failed", e);
-        }
+    public Flux<Mailbox> findMailboxWithPathLike(MailboxQuery.UserBound query) {
+        String pathLike = MailboxExpressionBackwardCompatibility.getPathLike(query);
+        return Mono.fromCallable(() -> findMailboxWithPathLikeTypedQuery(query.getFixedNamespace(), query.getFixedUser(), pathLike))
+            .flatMapIterable(TypedQuery::getResultList)
+            .map(JPAMailbox::toMailbox)
+            .filter(query::matches)
+            .onErrorMap(PersistenceException.class, e -> new MailboxException("Search of mailbox " + query + " failed", e));
     }
 
     private TypedQuery<JPAMailbox> findMailboxWithPathLikeTypedQuery(String namespace, Username username, String pathLike) {
@@ -203,45 +183,44 @@ public class JPAMailboxMapper extends JPATransactionalMapper implements MailboxM
     }
     
     @Override
-    public boolean hasChildren(Mailbox mailbox, char delimiter) throws MailboxException, MailboxNotFoundException {
+    public Mono<Boolean> hasChildren(Mailbox mailbox, char delimiter) {
         final String name = mailbox.getName() + delimiter + SQL_WILDCARD_CHAR; 
-        final Long numberOfChildMailboxes;
-
-        numberOfChildMailboxes = (Long) getEntityManager()
-            .createNamedQuery("countMailboxesWithNameLikeWithUser")
-            .setParameter("nameParam", name)
-            .setParameter("namespaceParam", mailbox.getNamespace())
-            .setParameter("userParam", mailbox.getUser().asString())
-            .getSingleResult();
 
-        return numberOfChildMailboxes != null && numberOfChildMailboxes > 0;
+        return Mono.defer(() -> Mono.justOrEmpty((Long) getEntityManager()
+                .createNamedQuery("countMailboxesWithNameLikeWithUser")
+                .setParameter("nameParam", name)
+                .setParameter("namespaceParam", mailbox.getNamespace())
+                .setParameter("userParam", mailbox.getUser().asString())
+                .getSingleResult()))
+            .filter(numberOfChildMailboxes -> numberOfChildMailboxes > 0)
+            .hasElement();
     }
 
     @Override
     public Flux<Mailbox> list() {
-        try {
-            return Flux.fromIterable(getEntityManager()
-                    .createNamedQuery("listMailboxes", JPAMailbox.class)
-                    .getResultList())
-                .map(JPAMailbox::toMailbox);
-        } catch (PersistenceException e) {
-            return Flux.error(new MailboxException("Delete of mailboxes failed", e));
-        } 
+        return Mono.fromCallable(() -> getEntityManager().createNamedQuery("listMailboxes", JPAMailbox.class))
+            .flatMapIterable(TypedQuery::getResultList)
+            .onErrorMap(PersistenceException.class, e -> new MailboxException("Delete of mailboxes failed", e))
+            .map(JPAMailbox::toMailbox);
     }
 
     @Override
-    public ACLDiff updateACL(Mailbox mailbox, MailboxACL.ACLCommand mailboxACLCommand) throws MailboxException {
-        MailboxACL oldACL = mailbox.getACL();
-        MailboxACL newACL = mailbox.getACL().apply(mailboxACLCommand);
-        mailbox.setACL(newACL);
-        return ACLDiff.computeDiff(oldACL, newACL);
+    public Mono<ACLDiff> updateACL(Mailbox mailbox, MailboxACL.ACLCommand mailboxACLCommand) {
+        return Mono.fromCallable(() -> {
+            MailboxACL oldACL = mailbox.getACL();
+            MailboxACL newACL = mailbox.getACL().apply(mailboxACLCommand);
+            mailbox.setACL(newACL);
+            return ACLDiff.computeDiff(oldACL, newACL);
+        });
     }
 
     @Override
-    public ACLDiff setACL(Mailbox mailbox, MailboxACL mailboxACL) throws MailboxException {
-        MailboxACL oldMailboxAcl = mailbox.getACL();
-        mailbox.setACL(mailboxACL);
-        return ACLDiff.computeDiff(oldMailboxAcl, mailboxACL);
+    public Mono<ACLDiff> setACL(Mailbox mailbox, MailboxACL mailboxACL) {
+        return Mono.fromCallable(() -> {
+            MailboxACL oldMailboxAcl = mailbox.getACL();
+            mailbox.setACL(mailboxACL);
+            return ACLDiff.computeDiff(oldMailboxAcl, mailboxACL);
+        });
     }
 
     @Override
diff --git a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/TransactionalMailboxMapper.java b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/TransactionalMailboxMapper.java
index f876158..5b6f9b8 100644
--- a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/TransactionalMailboxMapper.java
+++ b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/TransactionalMailboxMapper.java
@@ -22,8 +22,6 @@ package org.apache.james.mailbox.jpa.mail;
 import org.apache.commons.lang3.NotImplementedException;
 import org.apache.james.core.Username;
 import org.apache.james.mailbox.acl.ACLDiff;
-import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.exception.MailboxNotFoundException;
 import org.apache.james.mailbox.model.Mailbox;
 import org.apache.james.mailbox.model.MailboxACL;
 import org.apache.james.mailbox.model.MailboxACL.Right;
@@ -32,7 +30,6 @@ import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.UidValidity;
 import org.apache.james.mailbox.model.search.MailboxQuery;
 import org.apache.james.mailbox.store.mail.MailboxMapper;
-import org.apache.james.mailbox.store.transaction.Mapper;
 
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
@@ -50,23 +47,23 @@ public class TransactionalMailboxMapper implements MailboxMapper {
     }
 
     @Override
-    public <T> T execute(Transaction<T> transaction) throws MailboxException {
+    public <T> T execute(Transaction<T> transaction) {
         throw new NotImplementedException("not implemented");
     }
 
     @Override
-    public Mailbox create(MailboxPath mailboxPath, UidValidity uidValidity) throws MailboxException {
-        return wrapped.execute(() -> wrapped.create(mailboxPath, uidValidity));
+    public Mono<Mailbox> create(MailboxPath mailboxPath, UidValidity uidValidity) {
+        return wrapped.executeReactive(wrapped.create(mailboxPath, uidValidity));
     }
 
     @Override
-    public MailboxId rename(Mailbox mailbox) throws MailboxException {
-        return wrapped.execute(() -> wrapped.rename(mailbox));
+    public Mono<MailboxId> rename(Mailbox mailbox) {
+        return wrapped.executeReactive(wrapped.rename(mailbox));
     }
 
     @Override
-    public void delete(Mailbox mailbox) throws MailboxException {
-        wrapped.execute(Mapper.toTransaction(() -> wrapped.delete(mailbox)));
+    public Mono<Void> delete(Mailbox mailbox) {
+        return wrapped.executeReactiveVoid(wrapped.delete(mailbox));
     }
 
     @Override
@@ -75,27 +72,27 @@ public class TransactionalMailboxMapper implements MailboxMapper {
     }
 
     @Override
-    public Mailbox findMailboxById(MailboxId mailboxId) throws MailboxException, MailboxNotFoundException {
+    public Mono<Mailbox> findMailboxById(MailboxId mailboxId) {
         return wrapped.findMailboxById(mailboxId);
     }
 
     @Override
-    public Flux<Mailbox> findMailboxWithPathLike(MailboxQuery.UserBound query) throws MailboxException {
+    public Flux<Mailbox> findMailboxWithPathLike(MailboxQuery.UserBound query) {
         return wrapped.findMailboxWithPathLike(query);
     }
 
     @Override
-    public boolean hasChildren(Mailbox mailbox, char delimiter) throws MailboxException, MailboxNotFoundException {
+    public Mono<Boolean> hasChildren(Mailbox mailbox, char delimiter) {
         return wrapped.hasChildren(mailbox, delimiter);
     }
 
     @Override
-    public ACLDiff updateACL(Mailbox mailbox, MailboxACL.ACLCommand mailboxACLCommand) throws MailboxException {
+    public Mono<ACLDiff> updateACL(Mailbox mailbox, MailboxACL.ACLCommand mailboxACLCommand) {
         return wrapped.updateACL(mailbox, mailboxACLCommand);
     }
 
     @Override
-    public ACLDiff setACL(Mailbox mailbox, MailboxACL mailboxACL) throws MailboxException {
+    public Mono<ACLDiff> setACL(Mailbox mailbox, MailboxACL mailboxACL) {
         return wrapped.setACL(mailbox, mailboxACL);
     }
 
diff --git a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java
index b0f2238..9e02cf0 100644
--- a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java
+++ b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java
@@ -24,6 +24,7 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.function.Function;
 import java.util.regex.Pattern;
 import java.util.stream.Stream;
 
@@ -76,25 +77,26 @@ public class MaildirMailboxMapper extends NonTransactionalMapper implements Mail
     }
 
     @Override
-    public void delete(Mailbox mailbox) throws MailboxException {
-        String folderName = maildirStore.getFolderName(mailbox);
-        File folder = new File(folderName);
-        if (folder.isDirectory()) {
-            // Shouldn't fail on file deletion, else the mailbox will never be deleted
-            if (mailbox.getName().equals(MailboxConstants.INBOX)) {
-                // We must only delete cur, new, tmp and metadata for top INBOX mailbox.
-                delete(new File(folder, MaildirFolder.CUR), 
-                        new File(folder, MaildirFolder.NEW),
-                        new File(folder, MaildirFolder.TMP),
-                        new File(folder, MaildirFolder.UIDLIST_FILE),
-                        new File(folder, MaildirFolder.VALIDITY_FILE));
-            } else {
-                // We simply delete all the folder for non INBOX mailboxes.
-                delete(folder);
-            }
-        } else {
-            throw new MailboxNotFoundException(mailbox.generateAssociatedPath());
-        }
+    public Mono<Void> delete(Mailbox mailbox) {
+        return Mono.fromCallable(() -> new File(maildirStore.getFolderName(mailbox)))
+            .filter(File::isDirectory)
+            .map(folder -> {
+                // Shouldn't fail on file deletion, else the mailbox will never be deleted
+                if (mailbox.getName().equals(MailboxConstants.INBOX)) {
+                    // We must only delete cur, new, tmp and metadata for top INBOX mailbox.
+                    delete(new File(folder, MaildirFolder.CUR),
+                            new File(folder, MaildirFolder.NEW),
+                            new File(folder, MaildirFolder.TMP),
+                            new File(folder, MaildirFolder.UIDLIST_FILE),
+                            new File(folder, MaildirFolder.VALIDITY_FILE));
+                } else {
+                    // We simply delete all the folder for non INBOX mailboxes.
+                    delete(folder);
+                }
+                return true;
+            })
+            .switchIfEmpty(Mono.error(new MailboxNotFoundException(mailbox.generateAssociatedPath())))
+            .then();
     }
 
     private void delete(File...files) {
@@ -121,156 +123,161 @@ public class MaildirMailboxMapper extends NonTransactionalMapper implements Mail
     }
     
     @Override
-    public Mailbox findMailboxById(MailboxId id) throws MailboxException, MailboxNotFoundException {
+    public Mono<Mailbox> findMailboxById(MailboxId id) {
         if (id == null) {
-            throw new MailboxNotFoundException("null");
+            return Mono.error(new MailboxNotFoundException("null"));
         }
         return list()
             .filter(mailbox -> mailbox.getMailboxId().equals(id))
             .next()
-            .blockOptional()
-            .orElseThrow(() -> new MailboxNotFoundException(id));
+            .switchIfEmpty(Mono.error(new MailboxNotFoundException(id)));
     }
     
     @Override
-    public Flux<Mailbox> findMailboxWithPathLike(MailboxQuery.UserBound query) throws MailboxException {
-        String pathLike = MailboxExpressionBackwardCompatibility.getPathLike(query);
-        final Pattern searchPattern = Pattern.compile("[" + MaildirStore.maildirDelimiter + "]"
-                + pathLike.replace(".", "\\.").replace(MaildirStore.WILDCARD, ".*"));
-        FilenameFilter filter = MaildirMessageName.createRegexFilter(searchPattern);
-        File root = maildirStore.getMailboxRootForUser(query.getFixedUser());
-        File[] folders = root.listFiles(filter);
-        ArrayList<Mailbox> mailboxList = new ArrayList<>();
-        for (File folder : folders) {
-            if (folder.isDirectory()) {
-                Mailbox mailbox = maildirStore.loadMailbox(session, root, query.getFixedNamespace(), query.getFixedUser(), folder.getName());
-                mailboxList.add(mailbox);
+    public Flux<Mailbox> findMailboxWithPathLike(MailboxQuery.UserBound query) {
+        return Mono.fromCallable(() -> {
+            String pathLike = MailboxExpressionBackwardCompatibility.getPathLike(query);
+            final Pattern searchPattern = Pattern.compile("[" + MaildirStore.maildirDelimiter + "]"
+                    + pathLike.replace(".", "\\.").replace(MaildirStore.WILDCARD, ".*"));
+            FilenameFilter filter = MaildirMessageName.createRegexFilter(searchPattern);
+            File root = maildirStore.getMailboxRootForUser(query.getFixedUser());
+            File[] folders = root.listFiles(filter);
+            ArrayList<Mailbox> mailboxList = new ArrayList<>();
+            for (File folder : folders) {
+                if (folder.isDirectory()) {
+                    Mailbox mailbox = maildirStore.loadMailbox(session, root, query.getFixedNamespace(), query.getFixedUser(), folder.getName());
+                    mailboxList.add(mailbox);
+                }
             }
-        }
-        // INBOX is in the root of the folder
-        if (Pattern.matches(pathLike.replace(MaildirStore.WILDCARD, ".*"), MailboxConstants.INBOX)) {
-            Mailbox mailbox = maildirStore.loadMailbox(session, root, query.getFixedNamespace(), query.getFixedUser(), "");
-            mailboxList.add(0, mailbox);
-        }
-        return Flux.fromIterable(mailboxList)
-            .filter(query::matches);
+            // INBOX is in the root of the folder
+            if (Pattern.matches(pathLike.replace(MaildirStore.WILDCARD, ".*"), MailboxConstants.INBOX)) {
+                Mailbox mailbox = maildirStore.loadMailbox(session, root, query.getFixedNamespace(), query.getFixedUser(), "");
+                mailboxList.add(0, mailbox);
+            }
+            return mailboxList;
+        })
+        .flatMapIterable(Function.identity());
     }
 
     @Override
-    public boolean hasChildren(Mailbox mailbox, char delimiter) throws MailboxException, MailboxNotFoundException {
-        List<Mailbox> mailboxes = findMailboxWithPathLike(
+    public Mono<Boolean> hasChildren(Mailbox mailbox, char delimiter) {
+        return findMailboxWithPathLike(
             MailboxQuery.builder()
             .userAndNamespaceFrom(mailbox.generateAssociatedPath())
             .expression(new PrefixedWildcard(mailbox.getName() + delimiter))
             .build()
             .asUserBound())
-            .collectList().block();
-        return mailboxes.size() > 0;
+            .hasElements();
     }
 
     @Override
-    public Mailbox create(MailboxPath mailboxPath, UidValidity uidValidity) throws MailboxException {
-        MaildirId maildirId = MaildirId.random();
-        Mailbox mailbox = new Mailbox(mailboxPath, uidValidity, maildirId);
-        MaildirFolder folder = maildirStore.createMaildirFolder(mailbox);
-
-        if (!folder.exists()) {
-            boolean folderExist = folder.getRootFile().exists();
-            if (!folderExist && !folder.getRootFile().mkdirs()) {
-                throw new MailboxException("Failed to save Mailbox " + mailbox);
-            }
+    public Mono<Mailbox> create(MailboxPath mailboxPath, UidValidity uidValidity) {
+        return Mono.fromCallable(() -> {
+            MaildirId maildirId = MaildirId.random();
+            Mailbox mailbox = new Mailbox(mailboxPath, uidValidity, maildirId);
+            MaildirFolder folder = maildirStore.createMaildirFolder(mailbox);
+
+            if (!folder.exists()) {
+                boolean folderExist = folder.getRootFile().exists();
+                if (!folderExist && !folder.getRootFile().mkdirs()) {
+                    throw new MailboxException("Failed to save Mailbox " + mailbox);
+                }
 
-            boolean isCreated = folder.getCurFolder().mkdir()
-                && folder.getNewFolder().mkdir()
-                && folder.getTmpFolder().mkdir();
-            if (!isCreated) {
-                throw new MailboxException("Failed to save Mailbox " + mailbox, new IOException("Needed folder structure can not be created"));
+                boolean isCreated = folder.getCurFolder().mkdir()
+                        && folder.getNewFolder().mkdir()
+                        && folder.getTmpFolder().mkdir();
+                if (!isCreated) {
+                    throw new MailboxException("Failed to save Mailbox " + mailbox, new IOException("Needed folder structure can not be created"));
+                }
             }
-        }
 
-        try {
-            folder.setUidValidity(mailbox.getUidValidity());
-            folder.setMailboxId(maildirId);
-        } catch (IOException ioe) {
-            throw new MailboxException("Failed to save Mailbox " + mailbox, ioe);
+            try {
+                folder.setUidValidity(mailbox.getUidValidity());
+                folder.setMailboxId(maildirId);
+            } catch (IOException ioe) {
+                throw new MailboxException("Failed to save Mailbox " + mailbox, ioe);
 
-        }
-        folder.setACL(mailbox.getACL());
+            }
+            folder.setACL(mailbox.getACL());
 
-        return mailbox;
+            return mailbox;
+        });
     }
 
     @Override
-    public MailboxId rename(Mailbox mailbox) throws MailboxException {
+    public Mono<MailboxId> rename(Mailbox mailbox) {
         MaildirId maildirId = (MaildirId) mailbox.getMailboxId();
 
-        Mailbox originalMailbox = findMailboxById(mailbox.getMailboxId());
-        MaildirFolder folder = maildirStore.createMaildirFolder(mailbox);
-        // equals with null check
-        if (originalMailbox.getName() == null ? mailbox.getName() != null : !originalMailbox.getName().equals(mailbox.getName())) {
-            if (folder.exists()) {
-                throw new MailboxExistsException(mailbox.getName());
-            }
-
-            MaildirFolder originalFolder = maildirStore.createMaildirFolder(originalMailbox);
-            // renaming the INBOX means to move its contents to the new folder
-            if (originalMailbox.getName().equals(MailboxConstants.INBOX)) {
-                try {
-                    File inboxFolder = originalFolder.getRootFile();
-                    File newFolder = folder.getRootFile();
-                    FileUtils.forceMkdir(newFolder);
-                    if (!originalFolder.getCurFolder().renameTo(folder.getCurFolder())) {
-                        throw new IOException("Could not rename folder " + originalFolder.getCurFolder() + " to " + folder.getCurFolder());
-                    }
-                    if (!originalFolder.getMailboxIdFile().renameTo(folder.getMailboxIdFile())) {
-                        throw new IOException("Could not rename folder " + originalFolder.getCurFolder() + " to " + folder.getCurFolder());
+        return findMailboxById(mailbox.getMailboxId())
+            .flatMap(originalMailbox -> Mono.fromCallable(() -> {
+                MaildirFolder folder = maildirStore.createMaildirFolder(mailbox);
+                // equals with null check
+                if (originalMailbox.getName() == null ? mailbox.getName() != null : !originalMailbox.getName().equals(mailbox.getName())) {
+                    if (folder.exists()) {
+                        throw new MailboxExistsException(mailbox.getName());
                     }
-                    if (!originalFolder.getNewFolder().renameTo(folder.getNewFolder())) {
-                        throw new IOException("Could not rename folder " + originalFolder.getNewFolder() + " to " + folder.getNewFolder());
-                    }
-                    if (!originalFolder.getTmpFolder().renameTo(folder.getTmpFolder())) {
-                        throw new IOException("Could not rename folder " + originalFolder.getTmpFolder() + " to " + folder.getTmpFolder());
-                    }
-                    File oldUidListFile = new File(inboxFolder, MaildirFolder.UIDLIST_FILE);
-                    File newUidListFile = new File(newFolder, MaildirFolder.UIDLIST_FILE);
-                    if (!oldUidListFile.renameTo(newUidListFile)) {
-                        throw new IOException("Could not rename file " + oldUidListFile + " to " + newUidListFile);
-                    }
-                    File oldValidityFile = new File(inboxFolder, MaildirFolder.VALIDITY_FILE);
-                    File newValidityFile = new File(newFolder, MaildirFolder.VALIDITY_FILE);
-                    if (!oldValidityFile.renameTo(newValidityFile)) {
-                        throw new IOException("Could not rename file " + oldValidityFile + " to " + newValidityFile);
+
+                    MaildirFolder originalFolder = maildirStore.createMaildirFolder(originalMailbox);
+                    // renaming the INBOX means to move its contents to the new folder
+                    if (originalMailbox.getName().equals(MailboxConstants.INBOX)) {
+                        try {
+                            File inboxFolder = originalFolder.getRootFile();
+                            File newFolder = folder.getRootFile();
+                            FileUtils.forceMkdir(newFolder);
+                            if (!originalFolder.getCurFolder().renameTo(folder.getCurFolder())) {
+                                throw new IOException("Could not rename folder " + originalFolder.getCurFolder() + " to " + folder.getCurFolder());
+                            }
+                            if (!originalFolder.getMailboxIdFile().renameTo(folder.getMailboxIdFile())) {
+                                throw new IOException("Could not rename folder " + originalFolder.getCurFolder() + " to " + folder.getCurFolder());
+                            }
+                            if (!originalFolder.getNewFolder().renameTo(folder.getNewFolder())) {
+                                throw new IOException("Could not rename folder " + originalFolder.getNewFolder() + " to " + folder.getNewFolder());
+                            }
+                            if (!originalFolder.getTmpFolder().renameTo(folder.getTmpFolder())) {
+                                throw new IOException("Could not rename folder " + originalFolder.getTmpFolder() + " to " + folder.getTmpFolder());
+                            }
+                            File oldUidListFile = new File(inboxFolder, MaildirFolder.UIDLIST_FILE);
+                            File newUidListFile = new File(newFolder, MaildirFolder.UIDLIST_FILE);
+                            if (!oldUidListFile.renameTo(newUidListFile)) {
+                                throw new IOException("Could not rename file " + oldUidListFile + " to " + newUidListFile);
+                            }
+                            File oldValidityFile = new File(inboxFolder, MaildirFolder.VALIDITY_FILE);
+                            File newValidityFile = new File(newFolder, MaildirFolder.VALIDITY_FILE);
+                            if (!oldValidityFile.renameTo(newValidityFile)) {
+                                throw new IOException("Could not rename file " + oldValidityFile + " to " + newValidityFile);
+                            }
+                            // recreate the INBOX folders, uidvalidity and uidlist will
+                            // automatically be recreated later
+                            FileUtils.forceMkdir(originalFolder.getCurFolder());
+                            FileUtils.forceMkdir(originalFolder.getNewFolder());
+                            FileUtils.forceMkdir(originalFolder.getTmpFolder());
+                            originalFolder.setMailboxId(MaildirId.random());
+                        } catch (IOException e) {
+                            throw new MailboxException("Failed to save Mailbox " + mailbox, e);
+                        }
+                    } else {
+                        if (!originalFolder.getRootFile().renameTo(folder.getRootFile())) {
+                            throw new MailboxException("Failed to save Mailbox " + mailbox,
+                                    new IOException("Could not rename folder " + originalFolder));
+                        }
                     }
-                    // recreate the INBOX folders, uidvalidity and uidlist will
-                    // automatically be recreated later
-                    FileUtils.forceMkdir(originalFolder.getCurFolder());
-                    FileUtils.forceMkdir(originalFolder.getNewFolder());
-                    FileUtils.forceMkdir(originalFolder.getTmpFolder());
-                    originalFolder.setMailboxId(MaildirId.random());
-                } catch (IOException e) {
-                    throw new MailboxException("Failed to save Mailbox " + mailbox, e);
                 }
-            } else {
-                if (!originalFolder.getRootFile().renameTo(folder.getRootFile())) {
-                    throw new MailboxException("Failed to save Mailbox " + mailbox,
-                        new IOException("Could not rename folder " + originalFolder));
-                }
-            }
-        }
-        folder.setACL(mailbox.getACL());
+                folder.setACL(mailbox.getACL());
 
-        return maildirId;
+                return maildirId;
+            }));
     }
 
     @Override
     public Flux<Mailbox> list() {
-        File maildirRoot = maildirStore.getMaildirRoot();
-        return Mono.fromCallable(maildirStore::getMaildirLocation)
-            .filter(dir -> dir.endsWith("/" + MaildirStore.PATH_DOMAIN + "/" + MaildirStore.PATH_USER))
-            .map(ignored -> Arrays.stream(maildirRoot.listFiles())
-                .flatMap(Throwing.<File, Stream<Mailbox>>function(domain -> visitUsersForMailboxList(domain, domain.listFiles()).stream()).sneakyThrow()))
-            .switchIfEmpty(Mono.fromCallable(() -> visitUsersForMailboxList(null, maildirRoot.listFiles()).stream()))
-            .flatMapIterable(mailboxes -> mailboxes.collect(Guavate.toImmutableList()));
+       File maildirRoot = maildirStore.getMaildirRoot();
+
+       return Mono.fromCallable(maildirStore::getMaildirLocation)
+           .filter(dir -> dir.endsWith("/" + MaildirStore.PATH_DOMAIN + "/" + MaildirStore.PATH_USER))
+               .map(ignored -> Arrays.stream(maildirRoot.listFiles())
+                       .flatMap(Throwing.<File, Stream<Mailbox>>function(domain -> visitUsersForMailboxList(domain, domain.listFiles()).stream()).sneakyThrow()))
+               .switchIfEmpty(Mono.fromCallable(() -> visitUsersForMailboxList(null, maildirRoot.listFiles()).stream()))
+               .flatMapIterable(mailboxes -> mailboxes.collect(Guavate.toImmutableList()));
     }
 
     @Override
@@ -280,7 +287,7 @@ public class MaildirMailboxMapper extends NonTransactionalMapper implements Mail
 
     private List<Mailbox> visitUsersForMailboxList(File domain, File[] users) throws MailboxException {
         ImmutableList.Builder<Mailbox> mailboxList = ImmutableList.builder();
-        
+
         for (File user: users) {
             String userName = retrieveUsername(domain, user);
 
@@ -292,16 +299,17 @@ public class MaildirMailboxMapper extends NonTransactionalMapper implements Mail
             } catch (MailboxException e) {
                 //do nothing, we should still be able to list the mailboxes even if INBOX does not exist
             }
-            
+
             // List all INBOX sub folders.
             File[] mailboxes = user.listFiles(pathname -> pathname.getName().startsWith("."));
-            
+
             for (File mailbox: mailboxes) {
                 MailboxPath mailboxPath = MailboxPath.forUser(Username.of(userName),
                     mailbox.getName().substring(1));
                 mailboxList.add(maildirStore.loadMailbox(session, mailboxPath));
             }
         }
+
         return mailboxList.build();
     }
 
@@ -314,22 +322,26 @@ public class MaildirMailboxMapper extends NonTransactionalMapper implements Mail
     }
 
     @Override
-    public ACLDiff updateACL(Mailbox mailbox, MailboxACL.ACLCommand mailboxACLCommand) throws MailboxException {
-        MaildirFolder folder = maildirStore.createMaildirFolder(mailbox);
-        MailboxACL oldACL = mailbox.getACL();
-        MailboxACL newACL = mailbox.getACL().apply(mailboxACLCommand);
-        folder.setACL(newACL);
-        mailbox.setACL(newACL);
-        return ACLDiff.computeDiff(oldACL, newACL);
+    public Mono<ACLDiff> updateACL(Mailbox mailbox, MailboxACL.ACLCommand mailboxACLCommand) {
+        return Mono.fromCallable(() -> {
+            MaildirFolder folder = maildirStore.createMaildirFolder(mailbox);
+            MailboxACL oldACL = mailbox.getACL();
+            MailboxACL newACL = mailbox.getACL().apply(mailboxACLCommand);
+            folder.setACL(newACL);
+            mailbox.setACL(newACL);
+            return ACLDiff.computeDiff(oldACL, newACL);
+        });
     }
 
     @Override
-    public ACLDiff setACL(Mailbox mailbox, MailboxACL mailboxACL) throws MailboxException {
-        MailboxACL oldAcl = mailbox.getACL();
-        MaildirFolder folder = maildirStore.createMaildirFolder(mailbox);
-        folder.setACL(mailboxACL);
-        mailbox.setACL(mailboxACL);
-        return ACLDiff.computeDiff(oldAcl, mailboxACL);
+    public Mono<ACLDiff> setACL(Mailbox mailbox, MailboxACL mailboxACL) {
+        return Mono.fromCallable(() -> {
+            MailboxACL oldAcl = mailbox.getACL();
+            MaildirFolder folder = maildirStore.createMaildirFolder(mailbox);
+            folder.setACL(mailboxACL);
+            mailbox.setACL(mailboxACL);
+            return ACLDiff.computeDiff(oldAcl, mailboxACL);
+        });
     }
 
     @Override
diff --git a/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/DomainUserMaildirMailboxManagerTest.java b/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/DomainUserMaildirMailboxManagerTest.java
index e7f5a42..c54dd2c 100644
--- a/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/DomainUserMaildirMailboxManagerTest.java
+++ b/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/DomainUserMaildirMailboxManagerTest.java
@@ -47,6 +47,11 @@ class DomainUserMaildirMailboxManagerTest extends MailboxManagerTest<StoreMailbo
         protected void renameMailboxByIdShouldChangeTheMailboxPathOfAMailbox() {
         }
 
+        @Disabled("MAILBOX-389 Mailbox rename fails with Maildir")
+        @Test
+        protected void renameMailboxShouldChangeTheMailboxPathOfTheChildMailbox() {
+        }
+
         @Disabled("MAILBOX-393 mailboxId support for mailDir is partial")
         @Test
         protected void user1ShouldBeAbleToDeleteSubmailboxByid() {
diff --git a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxSessionMapperFactory.java b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxSessionMapperFactory.java
index 3513c66..42967ee 100644
--- a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxSessionMapperFactory.java
+++ b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxSessionMapperFactory.java
@@ -87,7 +87,7 @@ public class InMemoryMailboxSessionMapperFactory extends MailboxSessionMapperFac
     }
 
     public void deleteAll() throws MailboxException {
-        ((InMemoryMailboxMapper) mailboxMapper).deleteAll();
+        ((InMemoryMailboxMapper) mailboxMapper).deleteAll().block();
         ((InMemoryMessageMapper) messageMapper).deleteAll();
         ((InMemorySubscriptionMapper) subscriptionMapper).deleteAll();
     }
diff --git a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java
index 1606798..0f76a8f 100644
--- a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java
+++ b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java
@@ -21,6 +21,7 @@ package org.apache.james.mailbox.inmemory.mail;
 import java.util.Optional;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.Function;
 
 import org.apache.james.core.Username;
 import org.apache.james.mailbox.acl.ACLDiff;
@@ -55,67 +56,61 @@ public class InMemoryMailboxMapper implements MailboxMapper {
     }
 
     @Override
-    public void delete(Mailbox mailbox) throws MailboxException {
-        mailboxesByPath.remove(mailbox.generateAssociatedPath());
+    public Mono<Void> delete(Mailbox mailbox) {
+        return Mono.fromRunnable(() -> mailboxesByPath.remove(mailbox.generateAssociatedPath()));
     }
 
-    public void deleteAll() throws MailboxException {
-        mailboxesByPath.clear();
+    public Mono<Void> deleteAll() {
+        return Mono.fromRunnable(mailboxesByPath::clear);
     }
 
     @Override
-    public synchronized Mono<Mailbox> findMailboxByPath(MailboxPath path) {
-        Mailbox result = mailboxesByPath.get(path);
-        return Mono.justOrEmpty(result)
+    public Mono<Mailbox> findMailboxByPath(MailboxPath path) {
+        return Mono.defer(() -> Mono.justOrEmpty(mailboxesByPath.get(path)))
             .map(Mailbox::new);
     }
 
     @Override
-    public synchronized Mailbox findMailboxById(MailboxId id) throws MailboxException {
-        InMemoryId mailboxId = (InMemoryId) id;
-        for (Mailbox mailbox: mailboxesByPath.values()) {
-            if (mailbox.getMailboxId().equals(mailboxId)) {
-                return new Mailbox(mailbox);
-            }
-        }
-        throw new MailboxNotFoundException(mailboxId);
+    public Mono<Mailbox> findMailboxById(MailboxId id) {
+        return Mono.fromCallable(mailboxesByPath::values)
+            .flatMapIterable(Function.identity())
+            .filter(mailbox -> mailbox.getMailboxId().equals(id))
+            .next()
+            .map(Mailbox::new)
+            .switchIfEmpty(Mono.error(() -> new MailboxNotFoundException(id)));
     }
 
     @Override
     public Flux<Mailbox> findMailboxWithPathLike(MailboxQuery.UserBound query) {
-        return Flux.fromIterable(mailboxesByPath.values())
-            .filter(query::matches)
-            .map(Mailbox::new);
+        return Mono.fromCallable(mailboxesByPath::values)
+                .flatMapIterable(Function.identity())
+                .filter(query::matches)
+                .map(Mailbox::new);
     }
 
     @Override
-    public Mailbox create(MailboxPath mailboxPath, UidValidity uidValidity) throws MailboxException {
+    public Mono<Mailbox> create(MailboxPath mailboxPath, UidValidity uidValidity) {
         InMemoryId id = InMemoryId.of(mailboxIdGenerator.incrementAndGet());
         Mailbox mailbox = new Mailbox(mailboxPath, uidValidity, id);
 
-        saveMailbox(mailbox);
-
-        return mailbox;
+        return saveMailbox(mailbox)
+            .thenReturn(mailbox);
     }
 
     @Override
-    public MailboxId rename(Mailbox mailbox) throws MailboxException {
+    public Mono<MailboxId> rename(Mailbox mailbox) {
         Preconditions.checkNotNull(mailbox.getMailboxId(), "A mailbox we want to rename should have a defined mailboxId");
 
         InMemoryId id = (InMemoryId) mailbox.getMailboxId();
-        Mailbox mailboxWithPreviousName = findMailboxById(id);
-
-        saveMailbox(mailbox);
-        mailboxesByPath.remove(mailboxWithPreviousName.generateAssociatedPath());
-
-        return mailbox.getMailboxId();
+        return findMailboxById(id)
+            .flatMap(mailboxWithPreviousName -> saveMailbox(mailbox)
+                .then(Mono.fromCallable(() -> mailboxesByPath.remove(mailboxWithPreviousName.generateAssociatedPath()))))
+            .thenReturn(mailbox.getMailboxId());
     }
 
-    private void saveMailbox(Mailbox mailbox) throws MailboxException {
-        Mailbox previousMailbox = mailboxesByPath.putIfAbsent(mailbox.generateAssociatedPath(), mailbox);
-        if (previousMailbox != null) {
-            throw new MailboxExistsException(mailbox.getName());
-        }
+    private Mono<Void> saveMailbox(Mailbox mailbox) {
+        return Mono.defer(() -> Mono.justOrEmpty(mailboxesByPath.putIfAbsent(mailbox.generateAssociatedPath(), mailbox)))
+            .flatMap(ignored -> Mono.error(new MailboxExistsException(mailbox.getName())));
     }
 
     @Override
@@ -124,11 +119,12 @@ public class InMemoryMailboxMapper implements MailboxMapper {
     }
 
     @Override
-    public boolean hasChildren(Mailbox mailbox, char delimiter) throws MailboxException {
+    public Mono<Boolean> hasChildren(Mailbox mailbox, char delimiter) {
         String mailboxName = mailbox.getName() + delimiter;
-        return mailboxesByPath.values()
-            .stream()
-            .anyMatch(box -> belongsToSameUser(mailbox, box) && box.getName().startsWith(mailboxName));
+        return Mono.fromCallable(mailboxesByPath::values)
+            .flatMapIterable(Function.identity())
+            .filter(box -> belongsToSameUser(mailbox, box) && box.getName().startsWith(mailboxName))
+            .hasElements();
     }
 
     private boolean belongsToSameUser(Mailbox mailbox, Mailbox otherMailbox) {
@@ -138,7 +134,8 @@ public class InMemoryMailboxMapper implements MailboxMapper {
 
     @Override
     public Flux<Mailbox> list() {
-        return Flux.fromIterable(mailboxesByPath.values());
+        return Mono.fromCallable(mailboxesByPath::values)
+            .flatMapIterable(Function.identity());
     }
 
     @Override
@@ -147,23 +144,28 @@ public class InMemoryMailboxMapper implements MailboxMapper {
     }
 
     @Override
-    public ACLDiff updateACL(Mailbox mailbox, MailboxACL.ACLCommand mailboxACLCommand) throws MailboxException {
-        MailboxACL oldACL = mailbox.getACL();
-        MailboxACL newACL = mailbox.getACL().apply(mailboxACLCommand);
-        mailboxesByPath.get(mailbox.generateAssociatedPath()).setACL(newACL);
-        return ACLDiff.computeDiff(oldACL, newACL);
+    public Mono<ACLDiff> updateACL(Mailbox mailbox, MailboxACL.ACLCommand mailboxACLCommand) {
+        return Mono.fromCallable(() -> {
+            MailboxACL oldACL = mailbox.getACL();
+            MailboxACL newACL = mailbox.getACL().apply(mailboxACLCommand);
+            mailboxesByPath.get(mailbox.generateAssociatedPath()).setACL(newACL);
+            return ACLDiff.computeDiff(oldACL, newACL);
+        });
     }
 
     @Override
-    public ACLDiff setACL(Mailbox mailbox, MailboxACL mailboxACL) throws MailboxException {
-        MailboxACL oldMailboxAcl = mailbox.getACL();
-        mailboxesByPath.get(mailbox.generateAssociatedPath()).setACL(mailboxACL);
-        return ACLDiff.computeDiff(oldMailboxAcl, mailboxACL);
+    public Mono<ACLDiff> setACL(Mailbox mailbox, MailboxACL mailboxACL) {
+        return Mono.fromCallable(() -> {
+            MailboxACL oldMailboxAcl = mailbox.getACL();
+            mailboxesByPath.get(mailbox.generateAssociatedPath()).setACL(mailboxACL);
+            return ACLDiff.computeDiff(oldMailboxAcl, mailboxACL);
+        });
     }
 
     @Override
     public Flux<Mailbox> findNonPersonalMailboxes(Username userName, Right right) {
-        return Flux.fromIterable(mailboxesByPath.values())
+        return Mono.fromCallable(mailboxesByPath::values)
+            .flatMapIterable(Function.identity())
             .filter(mailbox -> hasRightOn(mailbox, userName, right));
     }
 
diff --git a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageIdMapper.java b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageIdMapper.java
index 4c8e0af..2fe2bee 100644
--- a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageIdMapper.java
+++ b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageIdMapper.java
@@ -36,6 +36,7 @@ import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.model.MessageRange;
 import org.apache.james.mailbox.model.UpdatedFlags;
 import org.apache.james.mailbox.store.FlagsUpdateCalculator;
+import org.apache.james.mailbox.store.MailboxReactorUtils;
 import org.apache.james.mailbox.store.mail.MailboxMapper;
 import org.apache.james.mailbox.store.mail.MessageIdMapper;
 import org.apache.james.mailbox.store.mail.MessageMapper;
@@ -81,7 +82,7 @@ public class InMemoryMessageIdMapper implements MessageIdMapper {
 
     @Override
     public void save(MailboxMessage mailboxMessage) throws MailboxException {
-        Mailbox mailbox = mailboxMapper.findMailboxById(mailboxMessage.getMailboxId());
+        Mailbox mailbox = MailboxReactorUtils.block(mailboxMapper.findMailboxById(mailboxMessage.getMailboxId()));
         messageMapper.save(mailbox, mailboxMessage);
     }
 
@@ -98,7 +99,7 @@ public class InMemoryMessageIdMapper implements MessageIdMapper {
         find(ImmutableList.of(messageId), MessageMapper.FetchType.Metadata)
             .forEach(Throwing.consumer(
                 message -> messageMapper.delete(
-                    mailboxMapper.findMailboxById(message.getMailboxId()),
+                    MailboxReactorUtils.block(mailboxMapper.findMailboxById(message.getMailboxId())),
                     message)));
     }
 
@@ -109,7 +110,7 @@ public class InMemoryMessageIdMapper implements MessageIdMapper {
             .filter(message -> mailboxIds.contains(message.getMailboxId()))
             .forEach(Throwing.consumer(
                 message -> messageMapper.delete(
-                    mailboxMapper.findMailboxById(message.getMailboxId()),
+                    MailboxReactorUtils.block(mailboxMapper.findMailboxById(message.getMailboxId())),
                     message)));
     }
 
@@ -140,7 +141,7 @@ public class InMemoryMessageIdMapper implements MessageIdMapper {
             }
             return Pair.of(message.getMailboxId(),
                 messageMapper.updateFlags(
-                    mailboxMapper.findMailboxById(message.getMailboxId()),
+                    MailboxReactorUtils.block(mailboxMapper.findMailboxById(message.getMailboxId())),
                     flagsUpdateCalculator,
                     message.getUid().toRange())
                     .next());
diff --git a/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/DeletedMessageVaultHook.java b/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/DeletedMessageVaultHook.java
index ff536a8..99858f1 100644
--- a/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/DeletedMessageVaultHook.java
+++ b/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/DeletedMessageVaultHook.java
@@ -24,7 +24,6 @@ import java.time.ZoneOffset;
 import java.time.ZonedDateTime;
 import java.util.List;
 import java.util.Objects;
-import java.util.Optional;
 
 import javax.inject.Inject;
 
@@ -33,14 +32,12 @@ import org.apache.james.core.Username;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MetadataWithMailboxId;
 import org.apache.james.mailbox.SessionProvider;
-import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.extension.PreDeletionHook;
 import org.apache.james.mailbox.model.Mailbox;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
 import org.apache.james.mailbox.store.mail.MessageMapper;
-import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 import org.reactivestreams.Publisher;
 
 import com.github.fge.lambdas.Throwing;
@@ -130,32 +127,30 @@ public class DeletedMessageVaultHook implements PreDeletionHook {
         Preconditions.checkNotNull(deleteOperation);
 
         return groupMetadataByOwnerAndMessageId(deleteOperation)
-            .flatMap(Throwing.function(this::appendToTheVault).sneakyThrow())
+            .flatMap(this::appendToTheVault)
             .then();
     }
 
     private Mono<Void> appendToTheVault(DeletedMessageMailboxContext deletedMessageMailboxContext) {
-        Optional<MailboxMessage> maybeMailboxMessage = mapperFactory.getMessageIdMapper(session)
-            .find(ImmutableList.of(deletedMessageMailboxContext.getMessageId()), MessageMapper.FetchType.Full).stream()
-            .findFirst();
-
-        return maybeMailboxMessage.map(Throwing.function(mailboxMessage -> Pair.of(mailboxMessage,
+        return mapperFactory.getMessageIdMapper(session)
+            .findReactive(ImmutableList.of(deletedMessageMailboxContext.getMessageId()), MessageMapper.FetchType.Full)
+            .next()
+            .map(Throwing.function(mailboxMessage -> Pair.of(mailboxMessage,
                 deletedMessageConverter.convert(deletedMessageMailboxContext, mailboxMessage,
                     ZonedDateTime.ofInstant(clock.instant(), ZoneOffset.UTC)))))
-            .map(Throwing.function(pairs -> Mono.from(deletedMessageVault
-                .append(pairs.getRight(), pairs.getLeft().getFullContent()))))
-            .orElse(Mono.empty());
+            .flatMap(Throwing.function(pairs -> Mono.from(deletedMessageVault
+                .append(pairs.getRight(), pairs.getLeft().getFullContent()))));
     }
 
     private Flux<DeletedMessageMailboxContext> groupMetadataByOwnerAndMessageId(DeleteOperation deleteOperation) {
         return Flux.fromIterable(deleteOperation.getDeletionMetadataList())
             .groupBy(MetadataWithMailboxId::getMailboxId)
-            .flatMap(Throwing.function(this::addOwnerToMetadata).sneakyThrow())
+            .flatMap(this::addOwnerToMetadata)
             .groupBy(this::toMessageIdUserPair)
             .flatMap(groupFlux -> groupFlux.reduce(DeletedMessageMailboxContext::combine));
     }
 
-    private Flux<DeletedMessageMailboxContext> addOwnerToMetadata(GroupedFlux<MailboxId, MetadataWithMailboxId> groupedFlux) throws MailboxException {
+    private Flux<DeletedMessageMailboxContext> addOwnerToMetadata(GroupedFlux<MailboxId, MetadataWithMailboxId> groupedFlux) {
         return retrieveMailboxUser(groupedFlux.key())
             .flatMapMany(owner -> groupedFlux.map(metadata ->
                 new DeletedMessageMailboxContext(metadata.getMessageMetaData().getMessageId(), owner, ImmutableList.of(metadata.getMailboxId()))));
@@ -167,7 +162,7 @@ public class DeletedMessageVaultHook implements PreDeletionHook {
 
     private Mono<Username> retrieveMailboxUser(MailboxId mailboxId) {
         return mapperFactory.getMailboxMapper(session)
-            .findMailboxByIdReactive(mailboxId)
+            .findMailboxById(mailboxId)
             .map(Mailbox::getUser);
     }
-}
\ No newline at end of file
+}
diff --git a/mailbox/plugin/spamassassin/src/main/java/org/apache/james/mailbox/spamassassin/SpamAssassinListener.java b/mailbox/plugin/spamassassin/src/main/java/org/apache/james/mailbox/spamassassin/SpamAssassinListener.java
index 4ccb808..a842a30 100644
--- a/mailbox/plugin/spamassassin/src/main/java/org/apache/james/mailbox/spamassassin/SpamAssassinListener.java
+++ b/mailbox/plugin/spamassassin/src/main/java/org/apache/james/mailbox/spamassassin/SpamAssassinListener.java
@@ -102,9 +102,9 @@ public class SpamAssassinListener implements SpamEventListener {
         }
     }
 
-    private void handleAdded(Event event, MailboxSession session, Added addedEvent) throws MailboxException {
+    private void handleAdded(Event event, MailboxSession session, Added addedEvent) {
         if (isAppendedToInbox(addedEvent)) {
-            Mailbox mailbox = mapperFactory.getMailboxMapper(session).findMailboxById(addedEvent.getMailboxId());
+            Mailbox mailbox = mapperFactory.getMailboxMapper(session).findMailboxById(addedEvent.getMailboxId()).block();
             MessageMapper messageMapper = mapperFactory.getMessageMapper(session);
 
             List<InputStream> contents = MessageRange.toRanges(addedEvent.getUids())
diff --git a/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java b/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
index 4227d3b..e159800 100644
--- a/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
+++ b/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java
@@ -86,14 +86,14 @@ class SpamAssassinListenerTest {
         spamAssassin = mock(SpamAssassin.class);
         mapperFactory = mailboxManager.getMapperFactory();
         MailboxMapper mailboxMapper = mapperFactory.createMailboxMapper(MAILBOX_SESSION);
-        inbox = mailboxMapper.create(MailboxPath.forUser(USER, DefaultMailboxes.INBOX), UID_VALIDITY);
-        mailbox1 = mailboxMapper.create(MailboxPath.forUser(USER, "mailbox1"), UID_VALIDITY);
-        mailbox2 = mailboxMapper.create(MailboxPath.forUser(USER, "mailbox2"), UID_VALIDITY);
+        inbox = mailboxMapper.create(MailboxPath.forUser(USER, DefaultMailboxes.INBOX), UID_VALIDITY).block();
+        mailbox1 = mailboxMapper.create(MailboxPath.forUser(USER, "mailbox1"), UID_VALIDITY).block();
+        mailbox2 = mailboxMapper.create(MailboxPath.forUser(USER, "mailbox2"), UID_VALIDITY).block();
         mailboxId1 = mailbox1.getMailboxId();
         mailboxId2 = mailbox2.getMailboxId();
-        spamMailboxId = mailboxMapper.create(MailboxPath.forUser(USER, "Spam"), UID_VALIDITY).getMailboxId();
-        spamCapitalMailboxId = mailboxMapper.create(MailboxPath.forUser(USER, "SPAM"), UID_VALIDITY).getMailboxId();
-        trashMailboxId = mailboxMapper.create(MailboxPath.forUser(USER, "Trash"), UID_VALIDITY).getMailboxId();
+        spamMailboxId = mailboxMapper.create(MailboxPath.forUser(USER, "Spam"), UID_VALIDITY).block().getMailboxId();
+        spamCapitalMailboxId = mailboxMapper.create(MailboxPath.forUser(USER, "SPAM"), UID_VALIDITY).block().getMailboxId();
+        trashMailboxId = mailboxMapper.create(MailboxPath.forUser(USER, "Trash"), UID_VALIDITY).block().getMailboxId();
 
         listener = new SpamAssassinListener(spamAssassin, systemMailboxesProvider, mailboxManager, mapperFactory, MailboxListener.ExecutionMode.SYNCHRONOUS);
     }
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxAnnotationManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxAnnotationManager.java
index 2b1a52f..b189778 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxAnnotationManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxAnnotationManager.java
@@ -29,6 +29,7 @@ import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.exception.AnnotationException;
 import org.apache.james.mailbox.exception.InsufficientRightsException;
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.exception.MailboxNotFoundException;
 import org.apache.james.mailbox.model.Mailbox;
 import org.apache.james.mailbox.model.MailboxACL.Right;
 import org.apache.james.mailbox.model.MailboxAnnotation;
@@ -69,7 +70,9 @@ public class StoreMailboxAnnotationManager implements MailboxAnnotationManager {
 
     public MailboxId checkThenGetMailboxId(MailboxPath path, MailboxSession session) throws MailboxException {
         MailboxMapper mailboxMapper = mailboxSessionMapperFactory.getMailboxMapper(session);
-        Mailbox mailbox = mailboxMapper.findMailboxByPathBlocking(path);
+        Mailbox mailbox = mailboxMapper.findMailboxByPath(path)
+            .blockOptional()
+            .orElseThrow(() -> new MailboxNotFoundException(path));
         if (!rightManager.hasRight(mailbox, Right.Read, session)) {
             throw new InsufficientRightsException("Not enough rights on " + path);
         }
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
index 09ea5eb..ced75f7 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
@@ -19,6 +19,8 @@
 
 package org.apache.james.mailbox.store;
 
+import static org.apache.james.mailbox.store.MailboxReactorUtils.block;
+import static org.apache.james.mailbox.store.MailboxReactorUtils.blockOptional;
 import static org.apache.james.mailbox.store.mail.AbstractMessageMapper.UNLIMITED;
 
 import java.util.ArrayList;
@@ -80,20 +82,18 @@ import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.apache.james.mailbox.store.quota.QuotaComponents;
 import org.apache.james.mailbox.store.search.MessageSearchIndex;
 import org.apache.james.mailbox.store.transaction.Mapper;
-import org.apache.james.util.streams.Iterators;
+import org.apache.james.util.FunctionalUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.github.fge.lambdas.Throwing;
 import com.github.steveash.guavate.Guavate;
 import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
-import reactor.core.scheduler.Schedulers;
 
 /**
  * This base class of an {@link MailboxManager} implementation provides a high-level api for writing your own
@@ -278,12 +278,7 @@ public class StoreMailboxManager implements MailboxManager {
     public MessageManager getMailbox(MailboxId mailboxId, MailboxSession session)
             throws MailboxException {
         MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session);
-        Mailbox mailboxRow = mapper.findMailboxById(mailboxId);
-
-        if (mailboxRow == null) {
-            LOGGER.info("Mailbox '{}' not found.", mailboxId.serialize());
-            throw new MailboxNotFoundException(mailboxId);
-        }
+        Mailbox mailboxRow = block(mapper.findMailboxById(mailboxId));
 
         if (!assertUserHasAccessTo(mailboxRow, session)) {
             LOGGER.info("Mailbox '{}' does not belong to user '{}' but to '{}'", mailboxId.serialize(), session.getUser(), mailboxRow.getUser());
@@ -320,7 +315,7 @@ public class StoreMailboxManager implements MailboxManager {
             MailboxPath sanitizedMailboxPath = mailboxPath.sanitize(mailboxSession.getPathDelimiter());
             sanitizedMailboxPath.assertAcceptable(mailboxSession.getPathDelimiter());
 
-            if (mailboxExists(sanitizedMailboxPath, mailboxSession).block()) {
+            if (block(mailboxExists(sanitizedMailboxPath, mailboxSession))) {
                 throw new MailboxExistsException(sanitizedMailboxPath.asString());
             }
 
@@ -348,7 +343,7 @@ public class StoreMailboxManager implements MailboxManager {
 
     private Stream<MailboxId> manageMailboxCreation(MailboxSession mailboxSession, boolean isRootPath, MailboxPath mailboxPath) throws MailboxException {
         if (mailboxPath.isInbox()) {
-            if (Mono.from(hasInbox(mailboxSession)).block()) {
+            if (block(Mono.from(hasInbox(mailboxSession)))) {
                 return duplicatedINBOXCreation(isRootPath, mailboxPath);
             }
 
@@ -369,30 +364,34 @@ public class StoreMailboxManager implements MailboxManager {
 
     private List<MailboxId> performConcurrentMailboxCreation(MailboxSession mailboxSession, MailboxPath mailboxPath) throws MailboxException {
         List<MailboxId> mailboxIds = new ArrayList<>();
-        locker.executeWithLock(mailboxPath, (LockAwareExecution<Void>) () -> {
-            if (!mailboxExists(mailboxPath, mailboxSession).block()) {
-                MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession);
-                try {
-                    mapper.execute(Mapper.toTransaction(() -> {
-                        Mailbox mailbox = mapper.create(mailboxPath, UidValidity.generate());
-                        mailboxIds.add(mailbox.getMailboxId());
-                        // notify listeners
-                        eventBus.dispatch(EventFactory.mailboxAdded()
-                                .randomEventId()
-                                .mailboxSession(mailboxSession)
-                                .mailbox(mailbox)
-                                .build(),
-                                new MailboxIdRegistrationKey(mailbox.getMailboxId()))
-                            .subscribeOn(Schedulers.elastic())
-                            .block();
-                    }));
-                } catch (MailboxExistsException e) {
-                    LOGGER.info("{} mailbox was created concurrently", mailboxPath.asString());
-                }
-            }
-            return null;
-
-        }, MailboxPathLocker.LockType.Write);
+        locker.executeWithLock(mailboxPath, () ->
+            block(mailboxExists(mailboxPath, mailboxSession)
+                .filter(FunctionalUtils.identityPredicate().negate())
+                .map(Throwing.<Boolean, MailboxMapper>function(ignored -> mailboxSessionMapperFactory.getMailboxMapper(mailboxSession)).sneakyThrow())
+                .flatMap(mapper -> {
+                    try {
+                        mapper.execute(Mapper.toTransaction(() ->
+                            block(mapper.create(mailboxPath, UidValidity.generate())
+                                .doOnNext(mailbox -> mailboxIds.add(mailbox.getMailboxId()))
+                                .flatMap(mailbox ->
+                                    // notify listeners
+                                    eventBus.dispatch(EventFactory.mailboxAdded()
+                                                    .randomEventId()
+                                                    .mailboxSession(mailboxSession)
+                                                    .mailbox(mailbox)
+                                                    .build(),
+                                            new MailboxIdRegistrationKey(mailbox.getMailboxId()))))));
+                    } catch (Exception e) {
+                        if (e instanceof MailboxExistsException) {
+                            LOGGER.info("{} mailbox was created concurrently", mailboxPath.asString());
+                        } else if (e instanceof MailboxException) {
+                            return Mono.error(e);
+                        }
+                    }
+
+                    return Mono.empty();
+                })
+                .then()), MailboxPathLocker.LockType.Write);
 
         return mailboxIds;
     }
@@ -410,10 +409,10 @@ public class StoreMailboxManager implements MailboxManager {
         assertIsOwner(session, mailboxPath);
         MailboxMapper mailboxMapper = mailboxSessionMapperFactory.getMailboxMapper(session);
 
-        mailboxMapper.execute(() -> {
-            Mailbox mailbox = mailboxMapper.findMailboxByPathBlocking(mailboxPath);
-            return doDeleteMailbox(mailboxMapper, mailbox, session);
-        });
+        mailboxMapper.execute(() -> block(mailboxMapper.findMailboxByPath(mailboxPath)
+            .flatMap(Throwing.<Mailbox, Mono<Mailbox>>function(mailbox ->
+                doDeleteMailbox(mailboxMapper, mailbox, session)).sneakyThrow())
+            .switchIfEmpty(Mono.error(new MailboxNotFoundException(mailboxPath)))));
     }
 
     @Override
@@ -421,49 +420,45 @@ public class StoreMailboxManager implements MailboxManager {
         LOGGER.info("deleteMailbox {}", mailboxId);
         MailboxMapper mailboxMapper = mailboxSessionMapperFactory.getMailboxMapper(session);
 
-        return mailboxMapper.execute(() -> {
-            Mailbox mailbox = mailboxMapper.findMailboxById(mailboxId);
-            if (mailbox == null) {
-                throw new MailboxNotFoundException(mailboxId);
-            }
-            assertIsOwner(session, mailbox.generateAssociatedPath());
-            return doDeleteMailbox(mailboxMapper, mailbox, session);
-        });
+        return mailboxMapper.execute(() -> block(mailboxMapper.findMailboxById(mailboxId)
+                .map(Throwing.<Mailbox, Mailbox>function(mailbox -> {
+                    assertIsOwner(session, mailbox.generateAssociatedPath());
+                    return mailbox;
+                }).sneakyThrow())
+                .flatMap(Throwing.<Mailbox, Mono<Mailbox>>function(mailbox ->
+                    doDeleteMailbox(mailboxMapper, mailbox, session)).sneakyThrow())));
     }
 
-    private Mailbox doDeleteMailbox(MailboxMapper mailboxMapper, Mailbox mailbox, MailboxSession session) throws MailboxException {
+    private Mono<Mailbox> doDeleteMailbox(MailboxMapper mailboxMapper, Mailbox mailbox, MailboxSession session) throws MailboxException {
         MessageMapper messageMapper = mailboxSessionMapperFactory.getMessageMapper(session);
 
         QuotaRoot quotaRoot = quotaRootResolver.getQuotaRoot(mailbox.generateAssociatedPath());
         long messageCount = messageMapper.countMessagesInMailbox(mailbox);
 
-        List<MetadataWithMailboxId> metadata = Iterators.toStream(messageMapper.findInMailbox(mailbox, MessageRange.all(), MessageMapper.FetchType.Metadata, UNLIMITED))
+        return messageMapper.findInMailboxReactive(mailbox, MessageRange.all(), MessageMapper.FetchType.Metadata, UNLIMITED)
             .map(message -> MetadataWithMailboxId.from(message.metaData(), message.getMailboxId()))
-            .collect(Guavate.toImmutableList());
-
-        long totalSize = metadata.stream()
-            .map(MetadataWithMailboxId::getMessageMetaData)
-            .mapToLong(MessageMetaData::getSize)
-            .sum();
-
-        preDeletionHooks.runHooks(PreDeletionHook.DeleteOperation.from(metadata)).block();
-
-        // We need to create a copy of the mailbox as maybe we can not refer to the real
-        // mailbox once we remove it
-        Mailbox m = new Mailbox(mailbox);
-        mailboxMapper.delete(mailbox);
-        eventBus.dispatch(EventFactory.mailboxDeleted()
-                .randomEventId()
-                .mailboxSession(session)
-                .mailbox(mailbox)
-                .quotaRoot(quotaRoot)
-                .quotaCount(QuotaCountUsage.count(messageCount))
-                .quotaSize(QuotaSizeUsage.size(totalSize))
-                .build(),
-                new MailboxIdRegistrationKey(mailbox.getMailboxId()))
-            .subscribeOn(Schedulers.elastic())
-            .block();
-        return m;
+            .collect(Guavate.toImmutableList())
+            .flatMap(metadata -> {
+                long totalSize = metadata.stream()
+                    .map(MetadataWithMailboxId::getMessageMetaData)
+                    .mapToLong(MessageMetaData::getSize)
+                    .sum();
+
+                return preDeletionHooks.runHooks(PreDeletionHook.DeleteOperation.from(metadata))
+                    .then(mailboxMapper.delete(mailbox))
+                    .then(eventBus.dispatch(EventFactory.mailboxDeleted()
+                        .randomEventId()
+                        .mailboxSession(session)
+                        .mailbox(mailbox)
+                        .quotaRoot(quotaRoot)
+                        .quotaCount(QuotaCountUsage.count(messageCount))
+                        .quotaSize(QuotaSizeUsage.size(totalSize))
+                        .build(),
+                            new MailboxIdRegistrationKey(mailbox.getMailboxId())));
+            })
+            // We need to create a copy of the mailbox as maybe we can not refer to the real
+            // mailbox once we remove it
+            .thenReturn(new Mailbox(mailbox));
     }
 
     @Override
@@ -476,7 +471,8 @@ public class StoreMailboxManager implements MailboxManager {
         MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session);
 
         mapper.execute(Mapper.toTransaction(() -> {
-            Mailbox mailbox = mapper.findMailboxByPathBlocking(from);
+            Mailbox mailbox = blockOptional(mapper.findMailboxByPath(from))
+                .orElseThrow(() -> new MailboxNotFoundException(from));
             doRenameMailbox(mailbox, sanitizedMailboxPath, session, mapper);
         }));
     }
@@ -490,15 +486,14 @@ public class StoreMailboxManager implements MailboxManager {
         MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session);
 
         mapper.execute(Mapper.toTransaction(() -> {
-            Mailbox mailbox = Optional.ofNullable(mapper.findMailboxById(mailboxId))
-                .orElseThrow(() -> new MailboxNotFoundException(mailboxId));
+            Mailbox mailbox = block(mapper.findMailboxById(mailboxId));
             assertIsOwner(session, mailbox.generateAssociatedPath());
             doRenameMailbox(mailbox, sanitizedMailboxPath, session, mapper);
         }));
     }
 
     private void validateDestinationPath(MailboxPath newMailboxPath, MailboxSession session) throws MailboxException {
-        if (mailboxExists(newMailboxPath, session).block()) {
+        if (block(mailboxExists(newMailboxPath, session))) {
             throw new MailboxExistsException(newMailboxPath.toString());
         }
         assertIsOwner(session, newMailboxPath);
@@ -519,18 +514,15 @@ public class StoreMailboxManager implements MailboxManager {
         mailbox.setNamespace(newMailboxPath.getNamespace());
         mailbox.setUser(newMailboxPath.getUser());
         mailbox.setName(newMailboxPath.getName());
-        mapper.rename(mailbox);
-
-        eventBus.dispatch(EventFactory.mailboxRenamed()
+        block(mapper.rename(mailbox)
+            .then(eventBus.dispatch(EventFactory.mailboxRenamed()
                 .randomEventId()
                 .mailboxSession(session)
                 .mailboxId(mailbox.getMailboxId())
                 .oldPath(from)
                 .newPath(newMailboxPath)
                 .build(),
-                new MailboxIdRegistrationKey(mailbox.getMailboxId()))
-            .subscribeOn(Schedulers.elastic())
-            .block();
+                new MailboxIdRegistrationKey(mailbox.getMailboxId()))));
 
         // rename submailboxes
         MailboxQuery.UserBound query = MailboxQuery.builder()
@@ -539,26 +531,25 @@ public class StoreMailboxManager implements MailboxManager {
             .build()
             .asUserBound();
         locker.executeWithLock(from, (LockAwareExecution<Void>) () -> {
-            List<Mailbox> subMailboxes = mapper.findMailboxWithPathLike(query).collectList().block();
-            for (Mailbox sub : subMailboxes) {
-                String subOriginalName = sub.getName();
-                String subNewName = newMailboxPath.getName() + subOriginalName.substring(from.getName().length());
-                MailboxPath fromPath = new MailboxPath(from, subOriginalName);
-                sub.setName(subNewName);
-                mapper.rename(sub);
-                eventBus.dispatch(EventFactory.mailboxRenamed()
-                        .randomEventId()
-                        .mailboxSession(session)
-                        .mailboxId(sub.getMailboxId())
-                        .oldPath(fromPath)
-                        .newPath(sub.generateAssociatedPath())
-                        .build(),
-                        new MailboxIdRegistrationKey(sub.getMailboxId()))
-                    .subscribeOn(Schedulers.elastic())
-                    .block();
+            block(mapper.findMailboxWithPathLike(query)
+                .flatMap(sub -> {
+                    String subOriginalName = sub.getName();
+                    String subNewName = newMailboxPath.getName() + subOriginalName.substring(from.getName().length());
+                    MailboxPath fromPath = new MailboxPath(from, subOriginalName);
+                    sub.setName(subNewName);
+                    return mapper.rename(sub)
+                        .then(eventBus.dispatch(EventFactory.mailboxRenamed()
+                            .randomEventId()
+                            .mailboxSession(session)
+                            .mailboxId(sub.getMailboxId())
+                            .oldPath(fromPath)
+                            .newPath(sub.generateAssociatedPath())
+                            .build(),
+                            new MailboxIdRegistrationKey(sub.getMailboxId())))
+                        .then(Mono.fromRunnable(() -> LOGGER.debug("Rename mailbox sub-mailbox {} to {}", subOriginalName, subNewName)));
+                })
+                .then());
 
-                LOGGER.debug("Rename mailbox sub-mailbox {} to {}", subOriginalName, subNewName);
-            }
             return null;
 
         }, MailboxPathLocker.LockType.Write);
@@ -595,28 +586,13 @@ public class StoreMailboxManager implements MailboxManager {
     }
 
     @Override
-    public List<MailboxMetaData> search(MailboxQuery mailboxExpression, MailboxSession session) throws MailboxException {
-        return searchMailboxesMetadata(mailboxExpression, session, Right.Lookup)
-            .collect(Guavate.toImmutableList())
-            .block();
-    }
-
-    @Override
-    public Flux<MailboxMetaData> searchReactive(MailboxQuery expression, MailboxSession session) {
-        try {
-            return searchMailboxesMetadata(expression, session, Right.Lookup);
-        } catch (MailboxException e) {
-            return Flux.error(e);
-        }
-    }
-
-    private Flux<MailboxMetaData> searchMailboxesMetadata(MailboxQuery mailboxQuery, MailboxSession session, Right right) throws MailboxException {
-        Mono<List<Mailbox>> mailboxesMono = searchMailboxes(mailboxQuery, session, right).collectList();
+    public Flux<MailboxMetaData> search(MailboxQuery expression, MailboxSession session) {
+        Mono<List<Mailbox>> mailboxesMono = searchMailboxes(expression, session, Right.Lookup).collectList();
         MessageMapper messageMapper = mailboxSessionMapperFactory.getMessageMapper(session);
 
         return mailboxesMono
             .flatMapMany(mailboxes -> Flux.fromIterable(mailboxes)
-                .filter(mailboxQuery::matches)
+                .filter(expression::matches)
                 .flatMap(mailbox -> retrieveCounters(messageMapper, mailbox, session)
                     .map(Throwing.<MailboxCounters, MailboxMetaData>function(
                         counters -> toMailboxMetadata(session, mailboxes, mailbox, counters))
@@ -635,11 +611,12 @@ public class StoreMailboxManager implements MailboxManager {
                 .build()));
     }
 
-    private Flux<Mailbox> searchMailboxes(MailboxQuery mailboxQuery, MailboxSession session, Right right) throws MailboxException {
+    private Flux<Mailbox> searchMailboxes(MailboxQuery mailboxQuery, MailboxSession session, Right right) {
         MailboxMapper mailboxMapper = mailboxSessionMapperFactory.getMailboxMapper(session);
-        Flux<Mailbox> baseMailboxes = mailboxMapper.findMailboxWithPathLike(toSingleUserQuery(mailboxQuery, session));
+        Flux<Mailbox> baseMailboxes = mailboxMapper
+            .findMailboxWithPathLike(toSingleUserQuery(mailboxQuery, session));
         Flux<Mailbox> delegatedMailboxes = getDelegatedMailboxes(mailboxMapper, mailboxQuery, right, session);
-        return Flux.merge(baseMailboxes, delegatedMailboxes)
+        return Flux.concat(baseMailboxes, delegatedMailboxes)
             .distinct()
             .filter(Throwing.predicate(mailbox -> storeRightManager.hasRight(mailbox, right, session)));
     }
@@ -654,14 +631,6 @@ public class StoreMailboxManager implements MailboxManager {
             .asUserBound();
     }
 
-    private MailboxCounters retrieveCounters(ImmutableMap<MailboxId, MailboxCounters> counters, Mailbox mailbox) {
-        return counters.getOrDefault(mailbox.getMailboxId(), MailboxCounters.builder()
-            .mailboxId(mailbox.getMailboxId())
-            .count(0)
-            .unseen(0)
-            .build());
-    }
-
     private Flux<Mailbox> getDelegatedMailboxes(MailboxMapper mailboxMapper, MailboxQuery mailboxQuery,
                                                 Right right, MailboxSession session) {
         if (mailboxQuery.isPrivateMailboxes(session)) {
@@ -719,7 +688,7 @@ public class StoreMailboxManager implements MailboxManager {
     private Flux<MailboxId> filterReadable(ImmutableSet<MailboxId> inMailboxes, MailboxSession session) throws MailboxException {
         MailboxMapper mailboxMapper = mailboxSessionMapperFactory.getMailboxMapper(session);
         return Flux.fromIterable(inMailboxes)
-            .concatMap(mailboxMapper::findMailboxByIdReactive)
+            .concatMap(mailboxMapper::findMailboxById)
             .filter(Throwing.<Mailbox>predicate(mailbox -> storeRightManager.hasRight(mailbox, Right.Read, session)).sneakyThrow())
             .map(Mailbox::getMailboxId);
     }
@@ -749,12 +718,11 @@ public class StoreMailboxManager implements MailboxManager {
 
     @Override
     public List<MailboxPath> list(MailboxSession session) throws MailboxException {
-        return mailboxSessionMapperFactory.getMailboxMapper(session)
+        return block(mailboxSessionMapperFactory.getMailboxMapper(session)
             .list()
             .map(Mailbox::generateAssociatedPath)
             .distinct()
-            .collect(Guavate.toImmutableList())
-            .block();
+            .collect(Guavate.toImmutableList()));
     }
 
     @Override
@@ -773,16 +741,11 @@ public class StoreMailboxManager implements MailboxManager {
     }
 
     @Override
-    public Rfc4314Rights myRights(MailboxId mailboxId, MailboxSession session) throws MailboxException {
+    public Mono<Rfc4314Rights> myRights(MailboxId mailboxId, MailboxSession session) {
         return storeRightManager.myRights(mailboxId, session);
     }
 
     @Override
-    public Mono<Rfc4314Rights> myRightsReactive(MailboxId mailboxId, MailboxSession session) {
-        return storeRightManager.myRightsReactive(mailboxId, session);
-    }
-
-    @Override
     public List<Rfc4314Rights> listRights(MailboxPath mailboxPath, MailboxACL.EntryKey key, MailboxSession session) throws MailboxException {
         return storeRightManager.listRights(mailboxPath, key, session);
     }
@@ -845,7 +808,7 @@ public class StoreMailboxManager implements MailboxManager {
     @Override
     public boolean hasChildren(MailboxPath mailboxPath, MailboxSession session) throws MailboxException {
         MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session);
-        Mailbox mailbox = mapper.findMailboxByPathBlocking(mailboxPath);
-        return mapper.hasChildren(mailbox, session.getPathDelimiter());
+        return block(mapper.findMailboxByPath(mailboxPath)
+            .flatMap(mailbox -> mapper.hasChildren(mailbox, session.getPathDelimiter())));
     }
 }
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
index 17c0477..4ed6fb9 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
@@ -19,6 +19,8 @@
 
 package org.apache.james.mailbox.store;
 
+import static org.apache.james.mailbox.store.MailboxReactorUtils.block;
+
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
@@ -45,7 +47,7 @@ import org.apache.james.mailbox.exception.MailboxNotFoundException;
 import org.apache.james.mailbox.extension.PreDeletionHook;
 import org.apache.james.mailbox.model.DeleteResult;
 import org.apache.james.mailbox.model.FetchGroup;
-import org.apache.james.mailbox.model.Mailbox;
+import org.apache.james.mailbox.model.MailboxACL;
 import org.apache.james.mailbox.model.MailboxACL.Right;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MessageId;
@@ -226,15 +228,14 @@ public class StoreMessageIdManager implements MessageIdManager {
 
         MailboxMapper mailboxMapper = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession);
         Flux.fromIterable(metadataWithMailbox)
-            .flatMap(Throwing.<MetadataWithMailboxId, Mono<Void>>function(
-                metadataWithMailboxId -> eventBus.dispatch(EventFactory.expunged()
-                    .randomEventId()
-                    .mailboxSession(mailboxSession)
-                    .mailbox(mailboxMapper.findMailboxById(metadataWithMailboxId.getMailboxId()))
-                    .addMetaData(metadataWithMailboxId.getMessageMetaData())
-                    .build(),
-                new MailboxIdRegistrationKey(metadataWithMailboxId.getMailboxId())))
-                .sneakyThrow())
+            .flatMap(metadataWithMailboxId -> mailboxMapper.findMailboxById(metadataWithMailboxId.getMailboxId())
+                .flatMap(mailbox -> eventBus.dispatch(EventFactory.expunged()
+                        .randomEventId()
+                        .mailboxSession(mailboxSession)
+                        .mailbox(mailbox)
+                        .addMetaData(metadataWithMailboxId.getMessageMetaData())
+                        .build(),
+                    new MailboxIdRegistrationKey(metadataWithMailboxId.getMailboxId()))))
             .then()
             .subscribeOn(Schedulers.elastic())
             .block();
@@ -318,13 +319,14 @@ public class StoreMessageIdManager implements MessageIdManager {
 
         for (MailboxId mailboxId: mailboxesToRemove) {
             messageIdMapper.delete(message.getMessageId(), mailboxesToRemove);
-            eventBus.dispatch(EventFactory.expunged()
-                .randomEventId()
-                .mailboxSession(mailboxSession)
-                .mailbox(mailboxMapper.findMailboxById(mailboxId))
-                .addMetaData(eventPayload)
-                .build(),
-                new MailboxIdRegistrationKey(mailboxId))
+            mailboxMapper.findMailboxById(mailboxId)
+                .flatMap(mailbox -> eventBus.dispatch(EventFactory.expunged()
+                        .randomEventId()
+                        .mailboxSession(mailboxSession)
+                        .mailbox(mailbox)
+                        .addMetaData(eventPayload)
+                        .build(),
+                    new MailboxIdRegistrationKey(mailboxId)))
             .subscribeOn(Schedulers.elastic())
             .block();
         }
@@ -332,15 +334,14 @@ public class StoreMessageIdManager implements MessageIdManager {
     
     private void dispatchFlagsChange(MailboxSession mailboxSession, MailboxId mailboxId, ImmutableList<UpdatedFlags> updatedFlags) throws MailboxException {
         if (updatedFlags.stream().anyMatch(UpdatedFlags::flagsChanged)) {
-            Mailbox mailbox = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession).findMailboxById(mailboxId);
-
-            eventBus.dispatch(EventFactory.flagsUpdated()
-                    .randomEventId()
-                    .mailboxSession(mailboxSession)
-                    .mailbox(mailbox)
-                    .updatedFlags(updatedFlags)
-                    .build(),
-                new MailboxIdRegistrationKey(mailboxId))
+            mailboxSessionMapperFactory.getMailboxMapper(mailboxSession).findMailboxById(mailboxId)
+                .flatMap(mailbox -> eventBus.dispatch(EventFactory.flagsUpdated()
+                        .randomEventId()
+                        .mailboxSession(mailboxSession)
+                        .mailbox(mailbox)
+                        .updatedFlags(updatedFlags)
+                        .build(),
+                    new MailboxIdRegistrationKey(mailboxId)))
                 .subscribeOn(Schedulers.elastic())
                 .block();
         }
@@ -380,7 +381,8 @@ public class StoreMessageIdManager implements MessageIdManager {
         MailboxMapper mailboxMapper = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession);
 
         for (MailboxId mailboxId : mailboxIds) {
-            boolean shouldPreserveFlags = rightManager.myRights(mailboxId, mailboxSession).contains(Right.Write);
+            MailboxACL.Rfc4314Rights myRights = block(Mono.from(rightManager.myRights(mailboxId, mailboxSession)));
+            boolean shouldPreserveFlags = myRights.contains(Right.Write);
             SimpleMailboxMessage copy =
                 SimpleMailboxMessage.from(mailboxMessage)
                     .mailboxId(mailboxId)
@@ -397,14 +399,14 @@ public class StoreMessageIdManager implements MessageIdManager {
                     .build();
             save(messageIdMapper, copy);
 
-            eventBus.dispatch(EventFactory.added()
+            mailboxMapper.findMailboxById(mailboxId)
+                .flatMap(mailbox -> eventBus.dispatch(EventFactory.added()
                     .randomEventId()
                     .mailboxSession(mailboxSession)
-                    .mailbox(mailboxMapper.findMailboxById(mailboxId))
+                    .mailbox(mailbox)
                     .addMetaData(copy.metaData())
                     .build(),
-                    new MailboxIdRegistrationKey(mailboxId))
-                .subscribeOn(Schedulers.elastic())
+                    new MailboxIdRegistrationKey(mailboxId)))
                 .block();
         }
     }
@@ -431,12 +433,12 @@ public class StoreMessageIdManager implements MessageIdManager {
 
 
     private Predicate<MailboxId> hasRightsOnMailbox(MailboxSession session, Right... rights) {
-        return Throwing.predicate((MailboxId mailboxId) -> rightManager.myRights(mailboxId, session).contains(rights))
+        return Throwing.predicate((MailboxId mailboxId) -> block(Mono.from(rightManager.myRights(mailboxId, session))).contains(rights))
             .fallbackTo(any -> false);
     }
 
     private Function<MailboxId, Mono<Boolean>> hasRightsOnMailboxReactive(MailboxSession session, Right... rights) {
-        return mailboxId -> Mono.from(rightManager.myRightsReactive(mailboxId, session))
+        return mailboxId -> Mono.from(rightManager.myRights(mailboxId, session))
             .map(myRights -> myRights.contains(rights))
             .onErrorResume(any -> Mono.just(false));
     }
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java
index 0d68316..8dd303e 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java
@@ -19,6 +19,8 @@
 
 package org.apache.james.mailbox.store;
 
+import static org.apache.james.mailbox.store.MailboxReactorUtils.block;
+
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
@@ -30,7 +32,6 @@ import org.apache.james.core.Domain;
 import org.apache.james.core.Username;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.RightManager;
-import org.apache.james.mailbox.acl.ACLDiff;
 import org.apache.james.mailbox.acl.GroupMembershipResolver;
 import org.apache.james.mailbox.acl.MailboxACLResolver;
 import org.apache.james.mailbox.events.EventBus;
@@ -55,7 +56,6 @@ import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ImmutableMap;
 
 import reactor.core.publisher.Mono;
-import reactor.core.scheduler.Schedulers;
 
 public class StoreRightManager implements RightManager {
     public static final boolean GROUP_FOLDER = true;
@@ -83,35 +83,28 @@ public class StoreRightManager implements RightManager {
 
     @Override
     public boolean hasRight(MailboxId mailboxId, Right right, MailboxSession session) throws MailboxException {
-        return myRights(mailboxId, session).contains(right);
+        return block(Mono.from(myRights(mailboxId, session))).contains(right);
     }
 
-    public boolean hasRight(Mailbox mailbox, Right right, MailboxSession session) throws MailboxException {
+    public boolean hasRight(Mailbox mailbox, Right right, MailboxSession session) {
         return myRights(mailbox, session).contains(right);
     }
 
     @Override
     public Rfc4314Rights myRights(MailboxPath mailboxPath, MailboxSession session) throws MailboxException {
         MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session);
-        Mailbox mailbox = mapper.findMailboxByPathBlocking(mailboxPath);
-        return myRights(mailbox, session);
-    }
-
-    @Override
-    public Rfc4314Rights myRights(MailboxId mailboxId, MailboxSession session) throws MailboxException {
-        MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session);
-        Mailbox mailbox = mapper.findMailboxById(mailboxId);
+        Mailbox mailbox = block(mapper.findMailboxByPath(mailboxPath));
         return myRights(mailbox, session);
     }
 
     @Override
-    public Mono<Rfc4314Rights> myRightsReactive(MailboxId mailboxId, MailboxSession session) {
+    public Mono<Rfc4314Rights> myRights(MailboxId mailboxId, MailboxSession session) {
         MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session);
-        return mapper.findMailboxByIdReactive(mailboxId)
+        return mapper.findMailboxById(mailboxId)
             .map(Throwing.function(mailbox -> myRights(mailbox, session)));
     }
 
-    public Rfc4314Rights myRights(Mailbox mailbox, MailboxSession session) throws UnsupportedRightException {
+    public Rfc4314Rights myRights(Mailbox mailbox, MailboxSession session) {
         Username username = session.getUser();
 
         return Optional.ofNullable(username)
@@ -129,7 +122,7 @@ public class StoreRightManager implements RightManager {
     @Override
     public List<Rfc4314Rights> listRights(MailboxPath mailboxPath, EntryKey key, MailboxSession session) throws MailboxException {
         MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session);
-        Mailbox mailbox = mapper.findMailboxByPathBlocking(mailboxPath);
+        Mailbox mailbox = block(mapper.findMailboxByPath(mailboxPath));
 
         return aclResolver.listRights(key,
             groupMembershipResolver,
@@ -140,7 +133,7 @@ public class StoreRightManager implements RightManager {
     @Override
     public MailboxACL listRights(MailboxPath mailboxPath, MailboxSession session) throws MailboxException {
         MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session);
-        Mailbox mailbox = mapper.findMailboxByPathBlocking(mailboxPath);
+        Mailbox mailbox = block(mapper.findMailboxByPath(mailboxPath));
         return mailbox.getACL();
     }
 
@@ -148,18 +141,15 @@ public class StoreRightManager implements RightManager {
     public void applyRightsCommand(MailboxPath mailboxPath, ACLCommand mailboxACLCommand, MailboxSession session) throws MailboxException {
         assertSharesBelongsToUserDomain(mailboxPath.getUser(), mailboxACLCommand);
         MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session);
-        Mailbox mailbox = mapper.findMailboxByPathBlocking(mailboxPath);
-        ACLDiff aclDiff = mapper.updateACL(mailbox, mailboxACLCommand);
-
-        eventBus.dispatch(EventFactory.aclUpdated()
-            .randomEventId()
-            .mailboxSession(session)
-            .mailbox(mailbox)
-            .aclDiff(aclDiff)
-            .build(),
-            new MailboxIdRegistrationKey(mailbox.getMailboxId()))
-            .subscribeOn(Schedulers.elastic())
-            .block();
+        block(mapper.findMailboxByPath(mailboxPath)
+            .flatMap(mailbox -> mapper.updateACL(mailbox, mailboxACLCommand)
+                .flatMap(aclDiff -> eventBus.dispatch(EventFactory.aclUpdated()
+                        .randomEventId()
+                        .mailboxSession(session)
+                        .mailbox(mailbox)
+                        .aclDiff(aclDiff)
+                        .build(),
+                    new MailboxIdRegistrationKey(mailbox.getMailboxId())))));
     }
 
     private void assertSharesBelongsToUserDomain(Username user, ACLCommand mailboxACLCommand) throws DifferentDomainException {
@@ -203,7 +193,7 @@ public class StoreRightManager implements RightManager {
     @Override
     public void setRights(MailboxId mailboxId, MailboxACL mailboxACL, MailboxSession session) throws MailboxException {
         MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session);
-        Mailbox mailbox = mapper.findMailboxById(mailboxId);
+        Mailbox mailbox = block(mapper.findMailboxById(mailboxId));
 
         setRights(mailbox.generateAssociatedPath(), mailboxACL, session);
     }
@@ -212,9 +202,9 @@ public class StoreRightManager implements RightManager {
     public void setRights(MailboxPath mailboxPath, MailboxACL mailboxACL, MailboxSession session) throws MailboxException {
         assertSharesBelongsToUserDomain(mailboxPath.getUser(), mailboxACL.getEntries());
         MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session);
-        Mailbox mailbox = mapper.findMailboxByPathBlocking(mailboxPath);
 
-        setRights(mailboxACL, mapper, mailbox, session);
+        block(mapper.findMailboxByPath(mailboxPath)
+            .flatMap(mailbox -> setRights(mailboxACL, mapper, mailbox, session)));
     }
 
     @VisibleForTesting
@@ -234,18 +224,15 @@ public class StoreRightManager implements RightManager {
         return !domain.equals(otherDomain);
     }
 
-    private void setRights(MailboxACL mailboxACL, MailboxMapper mapper, Mailbox mailbox, MailboxSession session) throws MailboxException {
-        ACLDiff aclDiff = mapper.setACL(mailbox, mailboxACL);
-
-        eventBus.dispatch(EventFactory.aclUpdated()
-            .randomEventId()
-            .mailboxSession(session)
-            .mailbox(mailbox)
-            .aclDiff(aclDiff)
-            .build(),
-            new MailboxIdRegistrationKey(mailbox.getMailboxId()))
-            .subscribeOn(Schedulers.elastic())
-            .block();
+    private Mono<Void> setRights(MailboxACL mailboxACL, MailboxMapper mapper, Mailbox mailbox, MailboxSession session) {
+        return mapper.setACL(mailbox, mailboxACL)
+            .flatMap(aclDiff -> eventBus.dispatch(EventFactory.aclUpdated()
+                    .randomEventId()
+                    .mailboxSession(session)
+                    .mailbox(mailbox)
+                    .aclDiff(aclDiff)
+                    .build(),
+                new MailboxIdRegistrationKey(mailbox.getMailboxId())));
     }
 
     /**
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/SystemMailboxesProviderImpl.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/SystemMailboxesProviderImpl.java
index 235c04c..01eb2dc 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/SystemMailboxesProviderImpl.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/SystemMailboxesProviderImpl.java
@@ -74,7 +74,7 @@ public class SystemMailboxesProviderImpl implements SystemMailboxesProvider {
             .expression(new PrefixedWildcard(aRole.getDefaultMailbox()))
             .build();
         return mailboxManager.search(mailboxQuery, session)
-            .stream()
+            .toStream()
             .map(MailboxMetaData::getPath)
             .filter(path -> hasRole(aRole, path))
             .map(Throwing.function(loadMailbox).sneakyThrow());
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MailboxMapper.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MailboxMapper.java
index 059356e..8743be6 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MailboxMapper.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MailboxMapper.java
@@ -22,8 +22,6 @@ import java.util.List;
 
 import org.apache.james.core.Username;
 import org.apache.james.mailbox.acl.ACLDiff;
-import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.exception.MailboxNotFoundException;
 import org.apache.james.mailbox.model.Mailbox;
 import org.apache.james.mailbox.model.MailboxACL;
 import org.apache.james.mailbox.model.MailboxACL.Right;
@@ -46,17 +44,17 @@ public interface MailboxMapper extends Mapper {
     /**
      * Create a {@link Mailbox} with the given {@link MailboxPath} and uid to the underlying storage
      */
-    Mailbox create(MailboxPath mailboxPath, UidValidity uidValidity) throws MailboxException;
+    Mono<Mailbox> create(MailboxPath mailboxPath, UidValidity uidValidity);
 
     /**
      * Rename the given {@link Mailbox} to the underlying storage
      */
-    MailboxId rename(Mailbox mailbox) throws MailboxException;
+    Mono<MailboxId> rename(Mailbox mailbox);
     
     /**
      * Delete the given {@link Mailbox} from the underlying storage
      */
-    void delete(Mailbox mailbox) throws MailboxException;
+    Mono<Void> delete(Mailbox mailbox);
 
   
     /**
@@ -68,35 +66,10 @@ public interface MailboxMapper extends Mapper {
         return findMailboxByPath(mailboxName).hasElement();
     }
 
-    default Mailbox findMailboxByPathBlocking(MailboxPath mailboxPath) throws MailboxException, MailboxNotFoundException {
-        try {
-            return findMailboxByPath(mailboxPath)
-                .blockOptional()
-                .orElseThrow(() -> new MailboxNotFoundException(mailboxPath));
-        } catch (Exception e) {
-            Throwable cause = e.getCause();
-            if (cause instanceof MailboxException) {
-                throw (MailboxException) cause;
-            }
-            throw e;
-        }
-    }
-
     /**
      * Return the {@link Mailbox} for the given name
      */
-    Mailbox findMailboxById(MailboxId mailboxId)
-            throws MailboxException, MailboxNotFoundException;
-
-    default Mono<Mailbox> findMailboxByIdReactive(MailboxId id) {
-        try {
-            return Mono.justOrEmpty(findMailboxById(id));
-        } catch (MailboxNotFoundException e) {
-            return Mono.empty();
-        } catch (MailboxException e) {
-            return Mono.error(e);
-        }
-    }
+    Mono<Mailbox> findMailboxById(MailboxId mailboxId);
 
     /**
      * Return a List of {@link Mailbox} for the given userName and matching the right
@@ -106,8 +79,7 @@ public interface MailboxMapper extends Mapper {
     /**
      * Return a List of {@link Mailbox} which name is like the given name
      */
-    Flux<Mailbox> findMailboxWithPathLike(MailboxQuery.UserBound query)
-            throws MailboxException;
+    Flux<Mailbox> findMailboxWithPathLike(MailboxQuery.UserBound query);
 
     /**
      * Return if the given {@link Mailbox} has children
@@ -116,27 +88,25 @@ public interface MailboxMapper extends Mapper {
      * @param delimiter path delimiter
      * @return true when the mailbox has children, false otherwise
      */
-    boolean hasChildren(Mailbox mailbox, char delimiter)
-            throws MailboxException, MailboxNotFoundException;
+    Mono<Boolean> hasChildren(Mailbox mailbox, char delimiter);
 
     /**
      * Update the ACL of the stored mailbox.
-     *
      * @param mailbox Mailbox for whom we want to update ACL
      * @param mailboxACLCommand Update to perform
      */
-    ACLDiff updateACL(Mailbox mailbox, MailboxACL.ACLCommand mailboxACLCommand) throws MailboxException;
+    Mono<ACLDiff> updateACL(Mailbox mailbox, MailboxACL.ACLCommand mailboxACLCommand);
 
     /**
      * Reset the ACL of the stored mailbox.
-     *
-     * @param mailbox Mailbox for whom we want to update ACL
+     *  @param mailbox Mailbox for whom we want to update ACL
      * @param mailboxACL New value of the ACL for this mailbox
+     * @return
      */
-    ACLDiff setACL(Mailbox mailbox, MailboxACL mailboxACL) throws MailboxException;
+    Mono<ACLDiff> setACL(Mailbox mailbox, MailboxACL mailboxACL);
 
     /**
      * Return a unmodifable {@link List} of all {@link Mailbox}
      */
     Flux<Mailbox> list();
-}
\ No newline at end of file
+}
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolver.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolver.java
index 773a8b0..9587c87 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolver.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolver.java
@@ -104,7 +104,7 @@ public class DefaultUserQuotaRootResolver implements UserQuotaRootResolver {
         MailboxSession session = sessionProvider.createSystemSession(Username.of("DefaultUserQuotaRootResolver"));
 
         return factory.getMailboxMapper(session)
-            .findMailboxByIdReactive(mailboxId)
+            .findMailboxById(mailboxId)
             .map(Mailbox::generateAssociatedPath)
             .map(MailboxPath::getUser)
             .map(this::forUser);
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java
index 59f4260..7f9db4c 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java
@@ -77,19 +77,19 @@ public abstract class ListeningMessageSearchIndex implements MessageSearchIndex,
 
         if (event instanceof Added) {
             return factory.getMailboxMapper(session)
-                .findMailboxByIdReactive(mailboxId)
+                .findMailboxById(mailboxId)
                 .flatMap(mailbox -> handleAdded(session, mailbox, (Added) event));
         } else if (event instanceof Expunged) {
             Expunged expunged = (Expunged) event;
 
             return factory.getMailboxMapper(session)
-                .findMailboxByIdReactive(mailboxId)
+                .findMailboxById(mailboxId)
                 .flatMap(mailbox -> delete(session, mailbox, expunged.getUids()));
         } else if (event instanceof FlagsUpdated) {
             FlagsUpdated flagsUpdated = (FlagsUpdated) event;
 
             return factory.getMailboxMapper(session)
-                .findMailboxByIdReactive(mailboxId)
+                .findMailboxById(mailboxId)
                 .flatMap(mailbox -> update(session, mailbox, flagsUpdated.getUpdatedFlags()));
         } else if (event instanceof MailboxDeletion) {
             return deleteAll(session, mailboxId);
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndex.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndex.java
index f3d52bb..e4719f9 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndex.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndex.java
@@ -53,7 +53,6 @@ import org.apache.james.mailbox.store.mail.MessageMapper.FetchType;
 import org.apache.james.mailbox.store.mail.MessageMapperFactory;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 
-import com.github.fge.lambdas.Throwing;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 
@@ -151,7 +150,7 @@ public class SimpleMessageSearchIndex implements MessageSearchIndex {
         MailboxMapper mailboxMapper = mailboxMapperFactory.getMailboxMapper(session);
 
         Flux<Mailbox> filteredMailboxes = Flux.fromIterable(mailboxIds)
-            .concatMap(Throwing.function(mailboxMapper::findMailboxByIdReactive).sneakyThrow());
+            .concatMap(mailboxMapper::findMailboxById);
 
         return getAsMessageIds(searchResults(session, filteredMailboxes, searchQuery), limit);
     }
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/transaction/Mapper.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/transaction/Mapper.java
index d5733bf..1560e83 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/transaction/Mapper.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/transaction/Mapper.java
@@ -35,7 +35,7 @@ public interface Mapper {
      * Execute the given Transaction
      */
     <T> T execute(Transaction<T> transaction) throws MailboxException;
-        
+
     /**
      * Unit of work executed in a Transaction
      *
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/transaction/TransactionalMapper.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/transaction/TransactionalMapper.java
index c9e53c6..139d8e7 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/transaction/TransactionalMapper.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/transaction/TransactionalMapper.java
@@ -21,6 +21,10 @@ package org.apache.james.mailbox.store.transaction;
 
 import org.apache.james.mailbox.exception.MailboxException;
 
+import com.github.fge.lambdas.Throwing;
+
+import reactor.core.publisher.Mono;
+
 /**
  *
  * Run Transaction and handle begin, commit and rollback in the right order
@@ -39,7 +43,21 @@ public abstract class TransactionalMapper implements Mapper {
             throw e;
         }
     }
-    
+
+    public final <T> Mono<T> executeReactive(Mono<T> transaction) {
+        return Mono.fromRunnable(Throwing.runnable(this::begin).sneakyThrow())
+            .then(transaction)
+            .doOnNext(Throwing.consumer(ignored -> commit()).sneakyThrow())
+            .doOnError(MailboxException.class, Throwing.consumer(e -> rollback()).sneakyThrow());
+    }
+
+    public final Mono<Void> executeReactiveVoid(Mono<Void> transaction) {
+        return Mono.fromRunnable(Throwing.runnable(this::begin).sneakyThrow())
+                .then(transaction)
+                .thenEmpty(Mono.fromRunnable(Throwing.runnable(this::commit).sneakyThrow()))
+                .doOnError(MailboxException.class, Throwing.consumer(e -> rollback()).sneakyThrow());
+    }
+
     /**
      * Begin transaction
      */
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageIdManagerTestSystem.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageIdManagerTestSystem.java
index 420e94a..24ccc3c 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageIdManagerTestSystem.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageIdManagerTestSystem.java
@@ -56,8 +56,6 @@ public class MessageIdManagerTestSystem {
      * Should persist flags 
      * Should keep track of flag state for setFlags
      * 
-     * @param mailboxId
-     * @param flags
      * @return the id of persisted message
      */
 
@@ -84,7 +82,7 @@ public class MessageIdManagerTestSystem {
     public MessageId persist(MailboxId mailboxId, MessageUid uid, Flags flags, MailboxSession mailboxSession) {
         try {
             MessageId messageId = messageIdFactory.generate();
-            Mailbox mailbox = mapperFactory.getMailboxMapper(mailboxSession).findMailboxById(mailboxId);
+            Mailbox mailbox = mapperFactory.getMailboxMapper(mailboxSession).findMailboxById(mailboxId).block();
             MailboxMessage message = createMessage(mailboxId, flags, messageId, uid);
             mapperFactory.getMessageMapper(mailboxSession).add(mailbox, message);
             mailboxManager.getEventBus().dispatch(EventFactory.added()
@@ -107,7 +105,7 @@ public class MessageIdManagerTestSystem {
 
     public void deleteMailbox(MailboxId mailboxId, MailboxSession mailboxSession) {
         try {
-            Mailbox mailbox = mapperFactory.getMailboxMapper(mailboxSession).findMailboxById(mailboxId);
+            Mailbox mailbox = mapperFactory.getMailboxMapper(mailboxSession).findMailboxById(mailboxId).block();
             mailboxManager.deleteMailbox(new MailboxPath(mailbox.getNamespace(), mailbox.getUser(), mailbox.getName()), mailboxSession);
         } catch (Exception e) {
             throw new RuntimeException(e);
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxManagerAnnotationTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxManagerAnnotationTest.java
index ee73f44..0424b4c 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxManagerAnnotationTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxManagerAnnotationTest.java
@@ -23,8 +23,6 @@ import static org.assertj.core.api.Assertions.assertThat;
 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.doReturn;
-import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
@@ -103,16 +101,16 @@ class StoreMailboxManagerAnnotationTest {
     }
 
     @Test
-    void updateAnnotationsShouldThrowExceptionWhenDoesNotLookupMailbox() throws Exception {
-        doThrow(MailboxException.class).when(mailboxMapper).findMailboxByPathBlocking(eq(mailboxPath));
+    void updateAnnotationsShouldThrowExceptionWhenDoesNotLookupMailbox() {
+        when(mailboxMapper.findMailboxByPath(eq(mailboxPath))).thenReturn(Mono.error(new MailboxException()));
 
         assertThatThrownBy(() -> annotationManager.updateAnnotations(mailboxPath, session, ImmutableList.of(PRIVATE_ANNOTATION)))
-            .isInstanceOf(MailboxException.class);
+            .hasCauseInstanceOf(MailboxException.class);
     }
 
     @Test
     void updateAnnotationsShouldCallAnnotationMapperToInsertAnnotation() throws Exception {
-        when(mailboxMapper.findMailboxByPathBlocking(eq(mailboxPath))).thenReturn(mailbox);
+        when(mailboxMapper.findMailboxByPath(eq(mailboxPath))).thenReturn(Mono.just(mailbox));
         annotationManager.updateAnnotations(mailboxPath, session, ANNOTATIONS);
 
         verify(annotationMapper, times(2)).insertAnnotation(eq(mailboxId), any(MailboxAnnotation.class));
@@ -120,7 +118,7 @@ class StoreMailboxManagerAnnotationTest {
 
     @Test
     void updateAnnotationsShouldCallAnnotationMapperToDeleteAnnotation() throws Exception {
-        when(mailboxMapper.findMailboxByPathBlocking(eq(mailboxPath))).thenReturn(mailbox);
+        when(mailboxMapper.findMailboxByPath(eq(mailboxPath))).thenReturn(Mono.just(mailbox));
         annotationManager.updateAnnotations(mailboxPath, session, ANNOTATIONS_WITH_NIL_ENTRY);
 
         verify(annotationMapper, times(1)).insertAnnotation(eq(mailboxId), eq(PRIVATE_ANNOTATION));
@@ -129,15 +127,15 @@ class StoreMailboxManagerAnnotationTest {
 
     @Test
     void getAllAnnotationsShouldThrowExceptionWhenDoesNotLookupMailbox() throws Exception {
-        doThrow(MailboxException.class).when(mailboxMapper).findMailboxByPathBlocking(eq(mailboxPath));
+        when(mailboxMapper.findMailboxByPath(eq(mailboxPath))).thenReturn(Mono.error(new MailboxException()));
 
         assertThatThrownBy(() -> annotationManager.getAllAnnotations(mailboxPath, session))
-            .isInstanceOf(MailboxException.class);
+            .hasCauseInstanceOf(MailboxException.class);
     }
 
     @Test
     void getAllAnnotationsShouldReturnEmptyForNonStoredAnnotation() throws Exception {
-        when(mailboxMapper.findMailboxByPathBlocking(eq(mailboxPath))).thenReturn(mailbox);
+        when(mailboxMapper.findMailboxByPath(eq(mailboxPath))).thenReturn(Mono.just(mailbox));
         when(annotationMapper.getAllAnnotations(eq(mailboxId))).thenReturn(Collections.<MailboxAnnotation>emptyList());
 
         assertThat(annotationManager.getAllAnnotations(mailboxPath, session)).isEmpty();
@@ -145,23 +143,23 @@ class StoreMailboxManagerAnnotationTest {
 
     @Test
     void getAllAnnotationsShouldReturnStoredAnnotation() throws Exception {
-        when(mailboxMapper.findMailboxByPathBlocking(eq(mailboxPath))).thenReturn(mailbox);
+        when(mailboxMapper.findMailboxByPath(eq(mailboxPath))).thenReturn(Mono.just(mailbox));
         when(annotationMapper.getAllAnnotations(eq(mailboxId))).thenReturn(ANNOTATIONS);
 
         assertThat(annotationManager.getAllAnnotations(mailboxPath, session)).isEqualTo(ANNOTATIONS);
     }
 
     @Test
-    void getAnnotationsByKeysShouldThrowExceptionWhenDoesNotLookupMailbox() throws Exception {
-        doThrow(MailboxException.class).when(mailboxMapper).findMailboxByPathBlocking(eq(mailboxPath));
+    void getAnnotationsByKeysShouldThrowExceptionWhenDoesNotLookupMailbox() {
+        when(mailboxMapper.findMailboxByPath(eq(mailboxPath))).thenReturn(Mono.error(new MailboxException()));
 
         assertThatThrownBy(() -> annotationManager.getAnnotationsByKeys(mailboxPath, session, KEYS))
-            .isInstanceOf(MailboxException.class);
+            .hasCauseInstanceOf(MailboxException.class);
     }
 
     @Test
     void getAnnotationsByKeysShouldRetrieveStoreAnnotationsByKey() throws Exception {
-        when(mailboxMapper.findMailboxByPathBlocking(eq(mailboxPath))).thenReturn(mailbox);
+        when(mailboxMapper.findMailboxByPath(eq(mailboxPath))).thenReturn(Mono.just(mailbox));
         when(annotationMapper.getAnnotationsByKeys(eq(mailboxId), eq(KEYS))).thenReturn(ANNOTATIONS);
 
         assertThat(annotationManager.getAnnotationsByKeys(mailboxPath, session, KEYS)).isEqualTo(ANNOTATIONS);
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxManagerTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxManagerTest.java
index 7feaceb..0143de2 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxManagerTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxManagerTest.java
@@ -107,8 +107,8 @@ class StoreMailboxManagerTest {
     }
 
     @Test
-    void getMailboxShouldThrowWhenUnknownId() throws Exception {
-        when(mockedMailboxMapper.findMailboxById(MAILBOX_ID)).thenReturn(null);
+    void getMailboxShouldThrowWhenUnknownId() {
+        when(mockedMailboxMapper.findMailboxById(MAILBOX_ID)).thenReturn(Mono.error(new MailboxNotFoundException(MAILBOX_ID)));
 
         assertThatThrownBy(() -> storeMailboxManager.getMailbox(MAILBOX_ID, mockedMailboxSession))
             .isInstanceOf(MailboxNotFoundException.class);
@@ -120,7 +120,7 @@ class StoreMailboxManagerTest {
         when(mockedMailbox.generateAssociatedPath())
             .thenReturn(MailboxPath.forUser(CURRENT_USER, "mailboxName"));
         when(mockedMailbox.getMailboxId()).thenReturn(MAILBOX_ID);
-        when(mockedMailboxMapper.findMailboxById(MAILBOX_ID)).thenReturn(mockedMailbox);
+        when(mockedMailboxMapper.findMailboxById(MAILBOX_ID)).thenReturn(Mono.just(mockedMailbox));
 
         MessageManager expected = storeMailboxManager.getMailbox(MAILBOX_ID, mockedMailboxSession);
 
@@ -133,7 +133,7 @@ class StoreMailboxManagerTest {
         when(mockedMailbox.generateAssociatedPath())
             .thenReturn(MailboxPath.forUser(Username.of("uSEr"), "mailboxName"));
         when(mockedMailbox.getMailboxId()).thenReturn(MAILBOX_ID);
-        when(mockedMailboxMapper.findMailboxById(MAILBOX_ID)).thenReturn(mockedMailbox);
+        when(mockedMailboxMapper.findMailboxById(MAILBOX_ID)).thenReturn(Mono.just(mockedMailbox));
 
         MessageManager expected = storeMailboxManager.getMailbox(MAILBOX_ID, mockedMailboxSession);
 
@@ -141,7 +141,7 @@ class StoreMailboxManagerTest {
     }
 
     @Test
-    void getMailboxShouldThrowWhenMailboxDoesNotMatchUserWithoutRight() throws Exception {
+    void getMailboxShouldThrowWhenMailboxDoesNotMatchUserWithoutRight() {
         Username otherUser = Username.of("other.user");
         Mailbox mockedMailbox = mock(Mailbox.class);
         when(mockedMailbox.getACL()).thenReturn(new MailboxACL());
@@ -149,7 +149,7 @@ class StoreMailboxManagerTest {
             .thenReturn(MailboxPath.forUser(otherUser, "mailboxName"));
         when(mockedMailbox.getMailboxId()).thenReturn(MAILBOX_ID);
         when(mockedMailbox.getUser()).thenReturn(otherUser);
-        when(mockedMailboxMapper.findMailboxById(MAILBOX_ID)).thenReturn(mockedMailbox);
+        when(mockedMailboxMapper.findMailboxById(MAILBOX_ID)).thenReturn(Mono.just(mockedMailbox));
         when(mockedMailboxMapper.findMailboxByPath(any())).thenReturn(Mono.just(mockedMailbox));
 
         assertThatThrownBy(() -> storeMailboxManager.getMailbox(MAILBOX_ID, mockedMailboxSession))
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreRightManagerTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreRightManagerTest.java
index a880c3a..465da65 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreRightManagerTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreRightManagerTest.java
@@ -70,7 +70,7 @@ class StoreRightManagerTest {
     MailboxMapper mockedMailboxMapper;
 
     @BeforeEach
-    void setup() throws MailboxException {
+    void setup() {
         aliceSession = MailboxSessionUtil.create(MailboxFixture.ALICE);
         MailboxSessionMapperFactory mockedMapperFactory = mock(MailboxSessionMapperFactory.class);
         mockedMailboxMapper = mock(MailboxMapper.class);
@@ -84,10 +84,10 @@ class StoreRightManagerTest {
     }
 
     @Test
-    void hasRightShouldThrowMailboxNotFoundExceptionWhenMailboxDoesNotExist() throws MailboxException {
+    void hasRightShouldThrowMailboxNotFoundExceptionWhenMailboxDoesNotExist() {
         MailboxPath mailboxPath = MailboxPath.forUser(MailboxFixture.ALICE, "unexisting mailbox");
-        when(mockedMailboxMapper.findMailboxByPathBlocking(mailboxPath))
-            .thenThrow(new MailboxNotFoundException(""));
+        when(mockedMailboxMapper.findMailboxByPath(mailboxPath))
+            .thenReturn(Mono.error(new MailboxNotFoundException("")));
 
         assertThatThrownBy(() ->
             storeRightManager.hasRight(mailboxPath, Right.Read, aliceSession))
@@ -95,7 +95,7 @@ class StoreRightManagerTest {
     }
 
     @Test
-    void hasRightShouldReturnTrueWhenTheUserOwnTheMailbox() throws MailboxException {
+    void hasRightShouldReturnTrueWhenTheUserOwnTheMailbox() {
         Mailbox mailbox = new Mailbox(MailboxPath.forUser(ALICE, MailboxConstants.INBOX), UID_VALIDITY, MAILBOX_ID);
 
         assertThat(storeRightManager.hasRight(mailbox, Right.Write, aliceSession))
@@ -121,7 +121,7 @@ class StoreRightManagerTest {
     }
 
     @Test
-    void hasRightShouldReturnFalseWhenTheUserDoesNotOwnTheMailboxAndHasNoRightOnIt() throws MailboxException {
+    void hasRightShouldReturnFalseWhenTheUserDoesNotOwnTheMailboxAndHasNoRightOnIt() {
         Mailbox mailbox = new Mailbox(MailboxPath.forUser(BOB, MailboxConstants.INBOX), UID_VALIDITY, MAILBOX_ID);
 
         assertThat(storeRightManager.hasRight(mailbox, Right.Write, aliceSession))
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/SystemMailboxesProviderImplTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/SystemMailboxesProviderImplTest.java
index 48b16f6..fc0ca0d 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/SystemMailboxesProviderImplTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/SystemMailboxesProviderImplTest.java
@@ -20,6 +20,7 @@
 package org.apache.james.mailbox.store;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -34,6 +35,8 @@ import org.apache.james.mailbox.fixture.MailboxFixture;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
+import reactor.core.publisher.Flux;
+
 class SystemMailboxesProviderImplTest {
 
     MailboxSession mailboxSession = MailboxSessionUtil.create(MailboxFixture.ALICE);
@@ -55,6 +58,7 @@ class SystemMailboxesProviderImplTest {
     void getMailboxByRoleShouldReturnEmptyWhenNoMailbox() throws Exception {
         when(mailboxManager.createSystemSession(MailboxFixture.ALICE)).thenReturn(mailboxSession);
         when(mailboxManager.getMailbox(eq(MailboxFixture.INBOX_ALICE), eq(mailboxSession))).thenThrow(MailboxNotFoundException.class);
+        when(mailboxManager.search(any(), any())).thenReturn(Flux.empty());
 
         assertThat(systemMailboxProvider.getMailboxByRole(Role.INBOX, mailboxSession.getUser())).isEmpty();
     }
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxMapperACLTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxMapperACLTest.java
index c8aef54..2725022 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxMapperACLTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxMapperACLTest.java
@@ -52,29 +52,31 @@ public abstract class MailboxMapperACLTest {
     protected abstract MailboxMapper createMailboxMapper();
 
     @BeforeEach
-    void setUp() throws Exception {
+    void setUp() {
         mailboxMapper = createMailboxMapper();
         MailboxPath benwaInboxPath = MailboxPath.forUser(Username.of("benwa"), "INBOX");
-        benwaInboxMailbox = mailboxMapper.create(benwaInboxPath, UID_VALIDITY);
+        benwaInboxMailbox = mailboxMapper.create(benwaInboxPath, UID_VALIDITY).block();
     }
 
     @Test
-    void storedAclShouldBeEmptyByDefault() throws MailboxException {
+    void storedAclShouldBeEmptyByDefault() {
         assertThat(
             mailboxMapper.findMailboxById(benwaInboxMailbox.getMailboxId())
+                .block()
                 .getACL()
                 .getEntries())
             .isEmpty();
     }
 
     @Test
-    void updateAclShouldSaveAclWhenReplace() throws MailboxException {
+    void updateAclShouldSaveAclWhenReplace() {
         EntryKey key = EntryKey.createUserEntryKey(USER);
         Rfc4314Rights rights = new Rfc4314Rights(Right.Administer, Right.PerformExpunge, Right.Write, Right.WriteSeenFlag);
-        mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key).rights(rights).asReplacement());
+        mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key).rights(rights).asReplacement()).block();
 
         assertThat(
             mailboxMapper.findMailboxById(benwaInboxMailbox.getMailboxId())
+                .block()
                 .getACL()
                 .getEntries())
             .hasSize(1)
@@ -82,16 +84,17 @@ public abstract class MailboxMapperACLTest {
     }
 
     @Test
-    void updateAclShouldOverwriteStoredAclWhenReplace() throws MailboxException {
+    void updateAclShouldOverwriteStoredAclWhenReplace() {
         EntryKey key = EntryKey.createUserEntryKey(USER);
         Rfc4314Rights rights = new Rfc4314Rights(Right.Administer, Right.PerformExpunge, Right.Write, Right.WriteSeenFlag);
         Rfc4314Rights newRights = new Rfc4314Rights(Right.WriteSeenFlag, Right.CreateMailbox, Right.Administer, Right.PerformExpunge, Right.DeleteMessages);
 
-        mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key).rights(rights).asReplacement());
-        mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key).rights(newRights).asReplacement());
+        mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key).rights(rights).asReplacement()).block();
+        mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key).rights(newRights).asReplacement()).block();
 
         assertThat(
             mailboxMapper.findMailboxById(benwaInboxMailbox.getMailboxId())
+                .block()
                 .getACL()
                 .getEntries())
             .hasSize(1)
@@ -99,16 +102,17 @@ public abstract class MailboxMapperACLTest {
     }
 
     @Test
-    void updateAclShouldTreatNegativeAndPositiveRightSeparately() throws MailboxException {
+    void updateAclShouldTreatNegativeAndPositiveRightSeparately() {
         EntryKey key1 = EntryKey.createUserEntryKey(USER, NEGATIVE);
         EntryKey key2 = EntryKey.createUserEntryKey(USER, POSITIVE);
         Rfc4314Rights rights = new Rfc4314Rights(Right.Administer, Right.PerformExpunge, Right.Write, Right.WriteSeenFlag);
         Rfc4314Rights newRights = new Rfc4314Rights(Right.WriteSeenFlag, Right.CreateMailbox, Right.Administer, Right.PerformExpunge, Right.DeleteMessages);
-        mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key1).rights(rights).asReplacement());
-        mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key2).rights(newRights).asReplacement());
+        mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key1).rights(rights).asReplacement()).block();
+        mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key2).rights(newRights).asReplacement()).block();
 
         assertThat(
             mailboxMapper.findMailboxById(benwaInboxMailbox.getMailboxId())
+                .block()
                 .getACL()
                 .getEntries())
             .hasSize(2)
@@ -117,16 +121,17 @@ public abstract class MailboxMapperACLTest {
     }
 
     @Test
-    void updateAclShouldTreatNameTypesRightSeparately() throws MailboxException {
+    void updateAclShouldTreatNameTypesRightSeparately() {
         EntryKey key1 = EntryKey.createUserEntryKey(USER);
         EntryKey key2 = EntryKey.createGroupEntryKey(USER.asString());
         Rfc4314Rights rights = new Rfc4314Rights(Right.Administer, Right.PerformExpunge, Right.Write, Right.WriteSeenFlag);
         Rfc4314Rights newRights = new Rfc4314Rights(Right.WriteSeenFlag, Right.CreateMailbox, Right.Administer, Right.PerformExpunge, Right.DeleteMessages);
-        mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key1).rights(rights).asReplacement());
-        mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key2).rights(newRights).asReplacement());
+        mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key1).rights(rights).asReplacement()).block();
+        mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key2).rights(newRights).asReplacement()).block();
 
         assertThat(
             mailboxMapper.findMailboxById(benwaInboxMailbox.getMailboxId())
+                .block()
                 .getACL()
                 .getEntries())
             .hasSize(2)
@@ -135,31 +140,33 @@ public abstract class MailboxMapperACLTest {
     }
 
     @Test
-    void updateAclShouldCleanAclEntryWhenEmptyReplace() throws MailboxException {
+    void updateAclShouldCleanAclEntryWhenEmptyReplace() {
         EntryKey key = EntryKey.createUserEntryKey(USER);
         Rfc4314Rights rights = new Rfc4314Rights(Right.Administer, Right.PerformExpunge, Right.Write, Right.WriteSeenFlag);
         Rfc4314Rights newRights = new Rfc4314Rights();
-        mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key).rights(rights).asReplacement());
-        mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key).rights(newRights).asReplacement());
+        mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key).rights(rights).asReplacement()).block();
+        mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key).rights(newRights).asReplacement()).block();
 
         assertThat(
             mailboxMapper.findMailboxById(benwaInboxMailbox.getMailboxId())
+                .block()
                 .getACL()
                 .getEntries())
             .isEmpty();
     }
 
     @Test
-    void updateAclShouldCombineStoredAclWhenAdd() throws MailboxException {
+    void updateAclShouldCombineStoredAclWhenAdd() {
         EntryKey key = EntryKey.createUserEntryKey(USER);
         Rfc4314Rights rights = new Rfc4314Rights(Right.Administer, Right.PerformExpunge, Right.Write, Right.WriteSeenFlag);
         Rfc4314Rights newRights = new Rfc4314Rights(Right.WriteSeenFlag, Right.CreateMailbox, Right.Administer, Right.PerformExpunge, Right.DeleteMessages);
         Rfc4314Rights bothRights = new Rfc4314Rights(Right.Administer, Right.WriteSeenFlag, Right.PerformExpunge, Right.Write, Right.CreateMailbox, Right.DeleteMessages);
-        mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key).rights(rights).asReplacement());
-        mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key).rights(newRights).asAddition());
+        mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key).rights(rights).asReplacement()).block();
+        mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key).rights(newRights).asAddition()).block();
 
         assertThat(
             mailboxMapper.findMailboxById(benwaInboxMailbox.getMailboxId())
+                .block()
                 .getACL()
                 .getEntries())
             .hasSize(1)
@@ -167,16 +174,17 @@ public abstract class MailboxMapperACLTest {
     }
 
     @Test
-    void removeAclShouldRemoveSomeStoredAclWhenAdd() throws MailboxException {
+    void removeAclShouldRemoveSomeStoredAclWhenAdd() {
         EntryKey key = EntryKey.createUserEntryKey(USER);
         Rfc4314Rights rights = new Rfc4314Rights(Right.Administer, Right.PerformExpunge, Right.Write, Right.WriteSeenFlag);
         Rfc4314Rights removedRights = new Rfc4314Rights(Right.WriteSeenFlag, Right.PerformExpunge);
         Rfc4314Rights finalRights = new Rfc4314Rights(Right.Administer, Right.Write);
-        mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key).rights(rights).asReplacement());
-        mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key).rights(removedRights).asRemoval());
+        mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key).rights(rights).asReplacement()).block();
+        mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key).rights(removedRights).asRemoval()).block();
 
         assertThat(
             mailboxMapper.findMailboxById(benwaInboxMailbox.getMailboxId())
+                .block()
                 .getACL()
                 .getEntries())
             .hasSize(1)
@@ -184,16 +192,17 @@ public abstract class MailboxMapperACLTest {
     }
 
     @Test
-    void removeAclShouldNotFailWhenRemovingNonExistingRight() throws MailboxException {
+    void removeAclShouldNotFailWhenRemovingNonExistingRight() {
         EntryKey key = EntryKey.createUserEntryKey(USER);
         Rfc4314Rights rights = new Rfc4314Rights(Right.Administer, Right.PerformExpunge, Right.Write, Right.WriteSeenFlag);
         Rfc4314Rights removedRights = new Rfc4314Rights(Right.WriteSeenFlag, Right.PerformExpunge, Right.Lookup);
         Rfc4314Rights finalRights = new Rfc4314Rights(Right.Administer, Right.Write);
-        mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key).rights(rights).asReplacement());
-        mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key).rights(removedRights).asRemoval());
+        mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key).rights(rights).asReplacement()).block();
+        mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key).rights(removedRights).asRemoval()).block();
 
         assertThat(
             mailboxMapper.findMailboxById(benwaInboxMailbox.getMailboxId())
+                .block()
                 .getACL()
                 .getEntries())
             .hasSize(1)
@@ -201,15 +210,16 @@ public abstract class MailboxMapperACLTest {
     }
 
     @Test
-    void resetAclShouldReplaceStoredAcl() throws MailboxException {
+    void resetAclShouldReplaceStoredAcl() {
         EntryKey key = EntryKey.createUserEntryKey(USER);
         Rfc4314Rights rights = new Rfc4314Rights(Right.Administer, Right.PerformExpunge, Right.Write, Right.WriteSeenFlag);
         Rfc4314Rights newRights = new Rfc4314Rights(Right.WriteSeenFlag, Right.CreateMailbox, Right.Administer, Right.PerformExpunge, Right.DeleteMessages);
-        mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key).rights(rights).asReplacement());
-        mailboxMapper.setACL(benwaInboxMailbox, new MailboxACL(ImmutableMap.of(key, newRights)));
+        mailboxMapper.updateACL(benwaInboxMailbox, MailboxACL.command().key(key).rights(rights).asReplacement()).block();
+        mailboxMapper.setACL(benwaInboxMailbox, new MailboxACL(ImmutableMap.of(key, newRights))).block();
 
         assertThat(
             mailboxMapper.findMailboxById(benwaInboxMailbox.getMailboxId())
+                .block()
                 .getACL()
                 .getEntries())
             .hasSize(1)
@@ -217,14 +227,15 @@ public abstract class MailboxMapperACLTest {
     }
     
     @Test
-    void resetAclShouldInitializeStoredAcl() throws MailboxException {
+    void resetAclShouldInitializeStoredAcl() {
         EntryKey key = EntryKey.createUserEntryKey(USER);
         Rfc4314Rights rights = new Rfc4314Rights(Right.WriteSeenFlag, Right.CreateMailbox, Right.Administer, Right.PerformExpunge, Right.DeleteMessages);
         mailboxMapper.setACL(benwaInboxMailbox,
-            new MailboxACL(ImmutableMap.of(key, rights)));
+            new MailboxACL(ImmutableMap.of(key, rights))).block();
 
         assertThat(
             mailboxMapper.findMailboxById(benwaInboxMailbox.getMailboxId())
+                .block()
                 .getACL()
                 .getEntries())
             .hasSize(1)
@@ -232,51 +243,53 @@ public abstract class MailboxMapperACLTest {
     }
 
     @Test
-    void findMailboxesShouldReturnEmptyWhenNone() throws MailboxException {
-        assertThat(mailboxMapper.findNonPersonalMailboxes(USER, Right.Administer).collectList().block()).isEmpty();
+    void findMailboxesShouldReturnEmptyWhenNone() {
+        assertThat(mailboxMapper.findNonPersonalMailboxes(USER, Right.Administer).collectList().block())
+            .isEmpty();
     }
 
     @Test
-    void findMailboxesShouldReturnEmptyWhenRightDoesntMatch() throws MailboxException {
+    void findMailboxesShouldReturnEmptyWhenRightDoesntMatch() {
         EntryKey key = EntryKey.createUserEntryKey(USER);
         Rfc4314Rights rights = new Rfc4314Rights(Right.Administer);
         mailboxMapper.updateACL(benwaInboxMailbox,
             MailboxACL.command()
                 .key(key)
                 .rights(rights)
-                .asReplacement());
+                .asReplacement()).block();
 
-        assertThat(mailboxMapper.findNonPersonalMailboxes(USER, Right.Read).collectList().block()).isEmpty();
+        assertThat(mailboxMapper.findNonPersonalMailboxes(USER, Right.Read).collectList().block())
+            .isEmpty();
     }
 
     @Test
-    void updateACLShouldInsertUsersRights() throws MailboxException {
+    void updateACLShouldInsertUsersRights() {
         Rfc4314Rights rights = new Rfc4314Rights(Right.Administer, Right.PerformExpunge);
         mailboxMapper.updateACL(benwaInboxMailbox,
             MailboxACL.command()
                 .key(EntryKey.createUserEntryKey(USER))
                 .rights(rights)
-                .asAddition());
+                .asAddition()).block();
 
         assertThat(mailboxMapper.findNonPersonalMailboxes(USER, Right.Administer).collectList().block())
             .containsOnly(benwaInboxMailbox);
     }
 
     @Test
-    void updateACLShouldOverwriteUsersRights() throws MailboxException {
+    void updateACLShouldOverwriteUsersRights() {
         EntryKey key = EntryKey.createUserEntryKey(USER);
         Rfc4314Rights initialRights = new Rfc4314Rights(Right.Administer);
         mailboxMapper.updateACL(benwaInboxMailbox,
             MailboxACL.command()
                 .key(key)
                 .rights(initialRights)
-                .asReplacement());
+                .asReplacement()).block();
         Rfc4314Rights newRights = new Rfc4314Rights(Right.Read);
         mailboxMapper.updateACL(benwaInboxMailbox,
             MailboxACL.command()
                 .key(key)
                 .rights(newRights)
-                .asReplacement());
+                .asReplacement()).block();
 
         assertThat(mailboxMapper.findNonPersonalMailboxes(USER, Right.Read).collectList().block())
             .containsOnly(benwaInboxMailbox);
@@ -286,7 +299,7 @@ public abstract class MailboxMapperACLTest {
     }
 
     @Test
-    void findMailboxesShouldNotReportDeletedACLViaReplace() throws MailboxException {
+    void findMailboxesShouldNotReportDeletedACLViaReplace() {
         EntryKey key = EntryKey.createUserEntryKey(USER);
         Rfc4314Rights initialRights = new Rfc4314Rights(Right.Administer);
         mailboxMapper.updateACL(benwaInboxMailbox,
@@ -294,60 +307,60 @@ public abstract class MailboxMapperACLTest {
                 .key(key)
                 .mode(MailboxACL.EditMode.REPLACE)
                 .rights(initialRights)
-                .build());
+                .build()).block();
         mailboxMapper.updateACL(benwaInboxMailbox,
             MailboxACL.command()
                 .key(key)
                 .mode(MailboxACL.EditMode.REPLACE)
                 .rights(new Rfc4314Rights())
-                .build());
+                .build()).block();
 
         assertThat(mailboxMapper.findNonPersonalMailboxes(USER, Right.Administer).collectList().block())
             .isEmpty();
     }
 
     @Test
-    void findMailboxesShouldNotReportDeletedACLViaRemove() throws MailboxException {
+    void findMailboxesShouldNotReportDeletedACLViaRemove() {
         EntryKey key = EntryKey.createUserEntryKey(USER);
         Rfc4314Rights initialRights = new Rfc4314Rights(Right.Administer);
         mailboxMapper.updateACL(benwaInboxMailbox,
             MailboxACL.command()
                 .key(key)
                 .rights(initialRights)
-                .asReplacement());
+                .asReplacement()).block();
         mailboxMapper.updateACL(benwaInboxMailbox,
             MailboxACL.command()
                 .key(key)
                 .rights(initialRights)
-                .asRemoval());
+                .asRemoval()).block();
 
         assertThat(mailboxMapper.findNonPersonalMailboxes(USER, Right.Administer).collectList().block())
             .isEmpty();
     }
 
     @Test
-    void findMailboxesShouldNotReportDeletedMailboxes() throws MailboxException {
+    void findMailboxesShouldNotReportDeletedMailboxes() {
         EntryKey key = EntryKey.createUserEntryKey(USER);
         Rfc4314Rights initialRights = new Rfc4314Rights(Right.Administer);
         mailboxMapper.updateACL(benwaInboxMailbox,
             MailboxACL.command()
                 .key(key)
                 .rights(initialRights)
-                .asReplacement());
-        mailboxMapper.delete(benwaInboxMailbox);
+                .asReplacement()).block();
+        mailboxMapper.delete(benwaInboxMailbox).block();
 
         assertThat(mailboxMapper.findNonPersonalMailboxes(USER, Right.Administer).collectList().block())
             .isEmpty();
     }
 
     @Test
-    void setACLShouldStoreMultipleUsersRights() throws MailboxException {
+    void setACLShouldStoreMultipleUsersRights() {
         EntryKey user1 = EntryKey.createUserEntryKey(USER_1);
         EntryKey user2 = EntryKey.createUserEntryKey(USER_2);
 
         mailboxMapper.setACL(benwaInboxMailbox, new MailboxACL(
             new MailboxACL.Entry(user1, new Rfc4314Rights(Right.Administer)),
-            new MailboxACL.Entry(user2, new Rfc4314Rights(Right.Read))));
+            new MailboxACL.Entry(user2, new Rfc4314Rights(Right.Read)))).block();
 
         assertThat(mailboxMapper.findNonPersonalMailboxes(USER_1, Right.Administer).collectList().block())
             .containsOnly(benwaInboxMailbox);
@@ -356,43 +369,43 @@ public abstract class MailboxMapperACLTest {
     }
 
     @Test
-    void findMailboxesShouldNotReportRightsRemovedViaSetAcl() throws MailboxException {
+    void findMailboxesShouldNotReportRightsRemovedViaSetAcl() {
         EntryKey user1 = EntryKey.createUserEntryKey(USER_1);
         EntryKey user2 = EntryKey.createUserEntryKey(USER_2);
 
         mailboxMapper.setACL(benwaInboxMailbox, new MailboxACL(
             new MailboxACL.Entry(user1, new Rfc4314Rights(Right.Administer)),
-            new MailboxACL.Entry(user2, new Rfc4314Rights(Right.Read))));
+            new MailboxACL.Entry(user2, new Rfc4314Rights(Right.Read)))).block();
 
         mailboxMapper.setACL(benwaInboxMailbox, new MailboxACL(
-            new MailboxACL.Entry(user2, new Rfc4314Rights(Right.Read))));
+            new MailboxACL.Entry(user2, new Rfc4314Rights(Right.Read)))).block();
 
         assertThat(mailboxMapper.findNonPersonalMailboxes(USER_1, Right.Administer).collectList().block())
             .isEmpty();
     }
 
     @Test
-    void findMailboxesShouldReportRightsUpdatedViaSetAcl() throws MailboxException {
+    void findMailboxesShouldReportRightsUpdatedViaSetAcl() {
         EntryKey user1 = EntryKey.createUserEntryKey(USER_1);
         EntryKey user2 = EntryKey.createUserEntryKey(USER_2);
 
         mailboxMapper.setACL(benwaInboxMailbox, new MailboxACL(
             new MailboxACL.Entry(user1, new Rfc4314Rights(Right.Administer)),
-            new MailboxACL.Entry(user2, new Rfc4314Rights(Right.Read))));
+            new MailboxACL.Entry(user2, new Rfc4314Rights(Right.Read)))).block();
 
         mailboxMapper.setACL(benwaInboxMailbox, new MailboxACL(
-            new MailboxACL.Entry(user2, new Rfc4314Rights(Right.Write))));
+            new MailboxACL.Entry(user2, new Rfc4314Rights(Right.Write)))).block();
 
         assertThat(mailboxMapper.findNonPersonalMailboxes(USER_2, Right.Write).collectList().block())
             .containsOnly(benwaInboxMailbox);
     }
 
     @Test
-    void findMailboxByPathShouldReturnMailboxWithACL() throws MailboxException {
+    void findMailboxByPathShouldReturnMailboxWithACL() {
         EntryKey key = EntryKey.createUserEntryKey(USER);
         Rfc4314Rights rights = new Rfc4314Rights(Right.WriteSeenFlag, Right.CreateMailbox, Right.Administer, Right.PerformExpunge, Right.DeleteMessages);
         mailboxMapper.setACL(benwaInboxMailbox,
-            new MailboxACL(ImmutableMap.of(key, rights)));
+            new MailboxACL(ImmutableMap.of(key, rights))).block();
 
         assertThat(
             mailboxMapper.findMailboxByPath(benwaInboxMailbox.generateAssociatedPath())
@@ -415,7 +428,7 @@ public abstract class MailboxMapperACLTest {
                 .asAddition()));
 
         assertThat(mailboxMapper.setACL(benwaInboxMailbox,
-            new MailboxACL(ImmutableMap.of(key, rights)))).isEqualTo(expectAclDiff);
+            new MailboxACL(ImmutableMap.of(key, rights))).block()).isEqualTo(expectAclDiff);
     }
 
     @Test
@@ -430,6 +443,6 @@ public abstract class MailboxMapperACLTest {
 
         ACLDiff expectAclDiff = ACLDiff.computeDiff(MailboxACL.EMPTY, MailboxACL.EMPTY.apply(aclCommand));
 
-        assertThat(mailboxMapper.updateACL(benwaInboxMailbox, aclCommand)).isEqualTo(expectAclDiff);
+        assertThat(mailboxMapper.updateACL(benwaInboxMailbox, aclCommand).block()).isEqualTo(expectAclDiff);
     }
 }
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxMapperTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxMapperTest.java
index 749dbf3..a5a13d1 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxMapperTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxMapperTest.java
@@ -27,7 +27,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import java.util.List;
 
 import org.apache.james.core.Username;
-import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.exception.MailboxExistsException;
 import org.apache.james.mailbox.exception.MailboxNotFoundException;
 import org.apache.james.mailbox.model.Mailbox;
@@ -87,23 +86,23 @@ public abstract class MailboxMapperTest {
     }
 
     @Test
-    void createShouldPersistTheMailbox() throws MailboxException {
+    void createShouldPersistTheMailbox() {
         benwaInboxMailbox = createMailbox(benwaInboxPath);
 
         assertThat(mailboxMapper.findMailboxByPath(benwaInboxPath).blockOptional()).contains(benwaInboxMailbox);
-        assertThat(mailboxMapper.findMailboxById(benwaInboxMailbox.getMailboxId())).isEqualTo(benwaInboxMailbox);
+        assertThat(mailboxMapper.findMailboxById(benwaInboxMailbox.getMailboxId()).block()).isEqualTo(benwaInboxMailbox);
     }
 
     @Test
-    void createShouldThrowWhenMailboxAlreadyExists() throws MailboxException {
+    void createShouldThrowWhenMailboxAlreadyExists() {
         benwaInboxMailbox = createMailbox(benwaInboxPath);
 
         assertThatThrownBy(() -> createMailbox(benwaInboxPath))
-            .isInstanceOf(MailboxExistsException.class);
+            .hasCauseInstanceOf(MailboxExistsException.class);
     }
 
     @Test
-    void createShouldSetAMailboxIdForMailbox() throws MailboxException {
+    void createShouldSetAMailboxIdForMailbox() {
         benwaInboxMailbox = createMailbox(benwaInboxPath);
 
         assertThat(benwaInboxMailbox.getMailboxId()).isNotNull();
@@ -111,50 +110,50 @@ public abstract class MailboxMapperTest {
 
     @Test
     void renameShouldThrowWhenMailboxIdIsNull() {
-        assertThatThrownBy(() -> mailboxMapper.rename(benwaInboxMailbox))
+        assertThatThrownBy(() -> mailboxMapper.rename(benwaInboxMailbox).block())
             .isInstanceOf(NullPointerException.class);
     }
 
     @Test
-    void renameShouldRenameTheMailbox() throws MailboxException {
+    void renameShouldRenameTheMailbox() {
         benwaInboxMailbox = createMailbox(benwaInboxPath);
         MailboxId mailboxId = benwaInboxMailbox.getMailboxId();
 
         benwaWorkMailbox = new Mailbox(benwaWorkPath, UID_VALIDITY, mailboxId);
-        mailboxMapper.rename(benwaWorkMailbox);
+        mailboxMapper.rename(benwaWorkMailbox).block();
 
-        assertThat(mailboxMapper.findMailboxById(mailboxId)).isEqualTo(benwaWorkMailbox);
+        assertThat(mailboxMapper.findMailboxById(mailboxId).block()).isEqualTo(benwaWorkMailbox);
     }
 
     @Test
-    void renameShouldThrowWhenMailboxAlreadyExist() throws MailboxException {
+    void renameShouldThrowWhenMailboxAlreadyExist() {
         benwaInboxMailbox = createMailbox(benwaInboxPath);
 
-        assertThatThrownBy(() -> mailboxMapper.rename(benwaInboxMailbox))
-            .isInstanceOf(MailboxExistsException.class);
+        assertThatThrownBy(() -> mailboxMapper.rename(benwaInboxMailbox).block())
+            .hasCauseInstanceOf(MailboxExistsException.class);
     }
 
     @Test
     void renameShouldThrowWhenMailboxDoesNotExist() {
         benwaInboxMailbox = new Mailbox(benwaInboxPath, UID_VALIDITY, generateId());
 
-        assertThatThrownBy(() -> mailboxMapper.rename(benwaInboxMailbox))
-            .isInstanceOf(MailboxNotFoundException.class);
+        assertThatThrownBy(() -> mailboxMapper.rename(benwaInboxMailbox).block())
+            .hasCauseInstanceOf(MailboxNotFoundException.class);
     }
 
     @Test
-    void renameShouldRemoveOldMailboxPath() throws MailboxException {
+    void renameShouldRemoveOldMailboxPath() {
         MailboxId mailboxId = createMailbox(benwaInboxPath).getMailboxId();
 
         benwaWorkMailbox = new Mailbox(benwaWorkPath, UID_VALIDITY, mailboxId);
-        mailboxMapper.rename(benwaWorkMailbox);
+        mailboxMapper.rename(benwaWorkMailbox).block();
 
         assertThat(mailboxMapper.findMailboxByPath(benwaInboxPath).blockOptional())
             .isEmpty();
     }
 
     @Test
-    void listShouldRetrieveAllMailbox() throws MailboxException {
+    void listShouldRetrieveAllMailbox() {
         createAll();
         List<Mailbox> mailboxes = mailboxMapper.list().collectList().block();
 
@@ -164,25 +163,25 @@ public abstract class MailboxMapperTest {
     }
     
     @Test
-    void hasChildrenShouldReturnFalseWhenNoChildrenExists() throws MailboxException {
+    void hasChildrenShouldReturnFalseWhenNoChildrenExists() {
         createAll();
-        assertThat(mailboxMapper.hasChildren(benwaWorkTodoMailbox, DELIMITER)).isFalse();
+        assertThat(mailboxMapper.hasChildren(benwaWorkTodoMailbox, DELIMITER).block()).isFalse();
     }
 
     @Test
-    void hasChildrenShouldReturnTrueWhenChildrenExists() throws MailboxException {
+    void hasChildrenShouldReturnTrueWhenChildrenExists() {
         createAll();
-        assertThat(mailboxMapper.hasChildren(benwaInboxMailbox, DELIMITER)).isTrue();
+        assertThat(mailboxMapper.hasChildren(benwaInboxMailbox, DELIMITER).block()).isTrue();
     }
 
     @Test
-    void hasChildrenShouldNotBeAcrossUsersAndNamespace() throws MailboxException {
+    void hasChildrenShouldNotBeAcrossUsersAndNamespace() {
         createAll();
-        assertThat(mailboxMapper.hasChildren(bobInboxMailbox, '.')).isFalse();
+        assertThat(mailboxMapper.hasChildren(bobInboxMailbox, '.').block()).isFalse();
     }
 
     @Test
-    void findMailboxWithPathLikeShouldBeLimitedToUserAndNamespace() throws MailboxException {
+    void findMailboxWithPathLikeShouldBeLimitedToUserAndNamespace() {
         createAll();
         MailboxQuery.UserBound mailboxQuery = MailboxQuery.builder()
             .userAndNamespaceFrom(bobInboxPath)
@@ -195,18 +194,18 @@ public abstract class MailboxMapperTest {
 
         assertMailboxes(mailboxes).containOnly(bobInboxMailbox);
     }
-    
+
     @Test
-    void deleteShouldEraseTheGivenMailbox() throws MailboxException {
+    void deleteShouldEraseTheGivenMailbox() {
         createAll();
-        mailboxMapper.delete(benwaInboxMailbox);
+        mailboxMapper.delete(benwaInboxMailbox).block();
 
         assertThat(mailboxMapper.findMailboxByPath(benwaInboxPath).blockOptional())
             .isEmpty();
     }
 
     @Test
-    void findMailboxWithPathLikeWithChildRegexShouldRetrieveChildren() throws MailboxException {
+    void findMailboxWithPathLikeWithChildRegexShouldRetrieveChildren() {
         createAll();
         MailboxQuery.UserBound mailboxQuery = MailboxQuery.builder()
             .userAndNamespaceFrom(benwaWorkPath)
@@ -221,7 +220,7 @@ public abstract class MailboxMapperTest {
     }
 
     @Test
-    void findMailboxWithPathLikeWithRegexShouldRetrieveCorrespondingMailbox() throws MailboxException {
+    void findMailboxWithPathLikeWithRegexShouldRetrieveCorrespondingMailbox() {
         createAll();
         MailboxQuery.UserBound mailboxQuery = MailboxQuery.builder()
             .userAndNamespaceFrom(benwaWorkPath)
@@ -236,7 +235,7 @@ public abstract class MailboxMapperTest {
     }
 
     @Test
-    void findMailboxWithPathLikeShouldEscapeMailboxName() throws MailboxException {
+    void findMailboxWithPathLikeShouldEscapeMailboxName() {
         createAll();
         MailboxQuery.UserBound mailboxQuery = MailboxQuery.builder()
             .userAndNamespaceFrom(benwaInboxPath)
@@ -249,22 +248,22 @@ public abstract class MailboxMapperTest {
     }
 
     @Test
-    void findMailboxByIdShouldReturnExistingMailbox() throws MailboxException {
+    void findMailboxByIdShouldReturnExistingMailbox() {
         createAll();
-        Mailbox actual = mailboxMapper.findMailboxById(benwaInboxMailbox.getMailboxId());
+        Mailbox actual = mailboxMapper.findMailboxById(benwaInboxMailbox.getMailboxId()).block();
         assertThat(actual).isEqualTo(benwaInboxMailbox);
     }
     
     @Test
-    void findMailboxByIdShouldFailWhenAbsent() throws MailboxException {
+    void findMailboxByIdShouldFailWhenAbsent() {
         createAll();
         MailboxId removed = benwaInboxMailbox.getMailboxId();
-        mailboxMapper.delete(benwaInboxMailbox);
-        assertThatThrownBy(() -> mailboxMapper.findMailboxById(removed))
-            .isInstanceOf(MailboxNotFoundException.class);
+        mailboxMapper.delete(benwaInboxMailbox).block();
+        assertThatThrownBy(() -> mailboxMapper.findMailboxById(removed).block())
+            .hasCauseInstanceOf(MailboxNotFoundException.class);
     }
 
-    private void createAll() throws MailboxException {
+    private void createAll() {
         benwaInboxMailbox = createMailbox(benwaInboxPath);
         benwaWorkMailbox = createMailbox(benwaWorkPath);
         benwaWorkTodoMailbox = createMailbox(benwaWorkTodoPath);
@@ -275,8 +274,8 @@ public abstract class MailboxMapperTest {
         bobDifferentNamespaceMailbox = createMailbox(bobDifferentNamespacePath);
     }
 
-    private Mailbox createMailbox(MailboxPath mailboxPath) throws MailboxException {
-        return mailboxMapper.create(mailboxPath, UID_VALIDITY);
+    private Mailbox createMailbox(MailboxPath mailboxPath) {
+        return mailboxMapper.create(mailboxPath, UID_VALIDITY).block();
     }
 
 }
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageIdMapperTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageIdMapperTest.java
index 57b90f9..944301b 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageIdMapperTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageIdMapperTest.java
@@ -986,7 +986,7 @@ public abstract class MessageIdMapperTest {
     }
 
     private Mailbox createMailbox(MailboxPath mailboxPath) throws MailboxException {
-        return mailboxMapper.create(mailboxPath, UID_VALIDITY);
+        return mailboxMapper.create(mailboxPath, UID_VALIDITY).block();
     }
     
     protected void saveMessages() throws MailboxException {
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java
index 99c7186..7f0d1ed 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java
@@ -1180,7 +1180,7 @@ public abstract class MessageMapperTest {
     }
 
     private Mailbox createMailbox(MailboxPath mailboxPath) throws MailboxException {
-        return mailboxMapper.create(mailboxPath, UID_VALIDITY);
+        return mailboxMapper.create(mailboxPath, UID_VALIDITY).block();
     }
 
     protected void saveMessages() throws MailboxException {
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMoveTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMoveTest.java
index d640246..a9b2182 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMoveTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMoveTest.java
@@ -134,8 +134,8 @@ public abstract class MessageMoveTest {
         assertThat(messageMapper.getMailboxCounters(benwaWorkMailbox).getUnseen()).isEqualTo(0);
     }
 
-    private Mailbox createMailbox(MailboxPath mailboxPath) throws MailboxException {
-        return mailboxMapper.create(mailboxPath, UID_VALIDITY);
+    private Mailbox createMailbox(MailboxPath mailboxPath) {
+        return mailboxMapper.create(mailboxPath, UID_VALIDITY).block();
     }
 
     private MailboxMessage retrieveMessageFromStorage(Mailbox mailbox, MailboxMessage message) throws MailboxException {
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolverTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolverTest.java
index 3a2cfbc..596a86f 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolverTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/DefaultUserQuotaRootResolverTest.java
@@ -99,7 +99,7 @@ class DefaultUserQuotaRootResolverTest {
     }
 
     @Test
-    void retrieveAssociatedMailboxesShouldThrowWhenQuotaRootContainsSeparator2Times() throws Exception {
+    void retrieveAssociatedMailboxesShouldThrowWhenQuotaRootContainsSeparator2Times() {
         assertThatThrownBy(() -> testee.retrieveAssociatedMailboxes(
                     QuotaRoot.quotaRoot("#private&be&nwa", Optional.empty()), MAILBOX_SESSION)
                 .collectList().block())
@@ -110,7 +110,7 @@ class DefaultUserQuotaRootResolverTest {
     void getQuotaRootShouldReturnUserValueWhenCalledWithMailboxId() throws Exception {
         MailboxMapper mockedMapper = mock(MailboxMapper.class);
         when(mockedFactory.getMailboxMapper(any())).thenReturn(mockedMapper);
-        when(mockedMapper.findMailboxByIdReactive(MAILBOX_ID)).thenReturn(Mono.just(MAILBOX));
+        when(mockedMapper.findMailboxById(MAILBOX_ID)).thenReturn(Mono.just(MAILBOX));
 
         assertThat(testee.getQuotaRoot(MAILBOX_ID)).isEqualTo(QUOTA_ROOT);
     }
diff --git a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerImpl.java b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerImpl.java
index f09050a..f557602 100644
--- a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerImpl.java
+++ b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerImpl.java
@@ -30,6 +30,7 @@ import org.apache.james.mailbox.indexer.ReIndexer;
 import org.apache.james.mailbox.indexer.ReIndexingExecutionFailures;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.store.MailboxReactorUtils;
 import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
 import org.apache.james.task.Task;
 
@@ -104,6 +105,6 @@ public class ReIndexerImpl implements ReIndexer {
 
     private void validateIdExists(MailboxId mailboxId) throws MailboxException {
         MailboxSession mailboxSession = mailboxManager.createSystemSession(Username.of("ReIndexingImap"));
-        mapperFactory.getMailboxMapper(mailboxSession).findMailboxById(mailboxId);
+        MailboxReactorUtils.block(mapperFactory.getMailboxMapper(mailboxSession).findMailboxById(mailboxId));
     }
 }
diff --git a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerPerformer.java b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerPerformer.java
index d50b2ee..124238c 100644
--- a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerPerformer.java
+++ b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerPerformer.java
@@ -159,7 +159,7 @@ public class ReIndexerPerformer {
         MailboxSession mailboxSession = mailboxManager.createSystemSession(RE_INDEXER_PERFORMER_USER);
 
         Flux<Either<Failure, ReIndexingEntry>> entriesToIndex = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession)
-            .findMailboxByIdReactive(mailboxId)
+            .findMailboxById(mailboxId)
             .flatMapMany(mailbox -> reIndexingEntriesForMailbox(mailbox, mailboxSession));
 
         return reIndexMessages(entriesToIndex, runningOptions, reprocessingContext);
@@ -188,7 +188,7 @@ public class ReIndexerPerformer {
         MailboxSession mailboxSession = mailboxManager.createSystemSession(RE_INDEXER_PERFORMER_USER);
 
         return mailboxSessionMapperFactory.getMailboxMapper(mailboxSession)
-            .findMailboxByIdReactive(mailboxId)
+            .findMailboxById(mailboxId)
             .flatMap(mailbox -> fullyReadMessage(mailboxSession, mailbox, uid)
                 .map(message -> Either.<Failure, ReIndexingEntry>right(new ReIndexingEntry(mailbox, mailboxSession, message)))
                 .flatMap(entryOrFailure -> reIndex(entryOrFailure, reprocessingContext)))
@@ -217,7 +217,7 @@ public class ReIndexerPerformer {
             Flux.fromIterable(previousReIndexingFailures.messageFailures())
                 .flatMap(this::createReindexingEntryFromFailure),
             Flux.fromIterable(previousReIndexingFailures.mailboxFailures())
-                .flatMap(mailboxId -> mapper.findMailboxByIdReactive(mailboxId)
+                .flatMap(mailboxId -> mapper.findMailboxById(mailboxId)
                     .flatMapMany(mailbox -> reIndexingEntriesForMailbox(mailbox, mailboxSession))
                     .onErrorResume(e -> {
                         LOGGER.warn("Failed to re-index {}", mailboxId, e);
@@ -229,7 +229,7 @@ public class ReIndexerPerformer {
 
     private Mono<Result> reIndex(MailboxMessage mailboxMessage, MailboxSession session) {
         return mailboxSessionMapperFactory.getMailboxMapper(session)
-            .findMailboxByIdReactive(mailboxMessage.getMailboxId())
+            .findMailboxById(mailboxMessage.getMailboxId())
             .flatMap(mailbox -> messageSearchIndex.add(session, mailbox, mailboxMessage))
             .thenReturn(Result.COMPLETED)
             .onErrorResume(e -> {
@@ -248,7 +248,7 @@ public class ReIndexerPerformer {
         MailboxSession mailboxSession = mailboxManager.createSystemSession(RE_INDEXER_PERFORMER_USER);
 
         return mailboxSessionMapperFactory.getMailboxMapper(mailboxSession)
-            .findMailboxByIdReactive(previousFailure.getMailboxId())
+            .findMailboxById(previousFailure.getMailboxId())
             .flatMap(mailbox -> fullyReadMessage(mailboxSession, mailbox, previousFailure.getUid())
                 .map(message -> Either.<Failure, ReIndexingEntry>right(new ReIndexingEntry(mailbox, mailboxSession, message))))
             .onErrorResume(e -> {
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java
index bf96dc9..b489a68 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java
@@ -20,7 +20,6 @@
 package org.apache.james.imap.processor;
 
 import java.io.Closeable;
-import java.util.List;
 
 import org.apache.james.imap.api.ImapMessage;
 import org.apache.james.imap.api.display.HumanReadableText;
@@ -131,18 +130,17 @@ public class ListProcessor extends AbstractMailboxProcessor<ListRequest> {
 
         MailboxPath basePath = computeBasePath(session, finalReferencename, isRelative);
 
-        List<MailboxMetaData> results = getMailboxManager().search(
+        getMailboxManager().search(
                 MailboxQuery.builder()
                     .userAndNamespaceFrom(basePath)
                     .expression(new PrefixedRegex(
                         basePath.getName(),
                         ModifiedUtf7.decodeModifiedUTF7(mailboxName),
                         mailboxSession.getPathDelimiter()))
-                    .build(), mailboxSession);
-
-        for (MailboxMetaData metaData : results) {
-            processResult(responder, isRelative, metaData, getMailboxType(session, metaData.getPath()));
-        }
+                    .build(), mailboxSession)
+            .doOnNext(metaData -> processResult(responder, isRelative, metaData, getMailboxType(session, metaData.getPath())))
+            .then()
+            .block();
     }
 
     private MailboxPath computeBasePath(ImapSession session, String finalReferencename, boolean isRelative) {
diff --git a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxProbeImpl.java b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxProbeImpl.java
index b267c0c..1f5a540 100644
--- a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxProbeImpl.java
+++ b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxProbeImpl.java
@@ -19,10 +19,11 @@
 
 package org.apache.james.modules;
 
+import static org.apache.james.mailbox.store.MailboxReactorUtils.block;
+
 import java.io.InputStream;
 import java.util.Collection;
 import java.util.Date;
-import java.util.List;
 import java.util.stream.Collectors;
 
 import javax.inject.Inject;
@@ -43,6 +44,8 @@ import org.apache.james.mailbox.model.search.Wildcard;
 import org.apache.james.mailbox.probe.MailboxProbe;
 import org.apache.james.utils.GuiceProbe;
 
+import reactor.core.publisher.Flux;
+
 public class MailboxProbeImpl implements GuiceProbe, MailboxProbe {
     private final MailboxManager mailboxManager;
     private final SubscriptionManager subscriptionManager;
@@ -102,11 +105,10 @@ public class MailboxProbeImpl implements GuiceProbe, MailboxProbe {
         try {
             mailboxSession = mailboxManager.createSystemSession(Username.of(user));
             mailboxManager.startProcessingRequest(mailboxSession);
-            return searchUserMailboxes(mailboxSession)
-                    .stream()
+            return block(searchUserMailboxes(mailboxSession)
                     .map(MailboxMetaData::getPath)
                     .map(MailboxPath::getName)
-                    .collect(Collectors.toList());
+                    .collect(Collectors.toList()));
         } catch (MailboxException e) {
             throw new RuntimeException(e);
         } finally {
@@ -114,7 +116,7 @@ public class MailboxProbeImpl implements GuiceProbe, MailboxProbe {
         }
     }
 
-    private List<MailboxMetaData> searchUserMailboxes(MailboxSession session) throws MailboxException {
+    private Flux<MailboxMetaData> searchUserMailboxes(MailboxSession session) {
         return mailboxManager.search(
             MailboxQuery.privateMailboxesBuilder(session)
                 .expression(Wildcard.INSTANCE)
diff --git a/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java b/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java
index 435397d..a482d5f 100644
--- a/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java
+++ b/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java
@@ -205,7 +205,9 @@ public class MailboxManagerManagement extends StandardMBean implements MailboxMa
             MailboxQuery.privateMailboxesBuilder(session)
                 .matchesAllMailboxNames()
                 .build(),
-            session);
+            session)
+            .collect(Guavate.toImmutableList())
+            .block();
     }
 
     private void checkMailboxArguments(String namespace, String user, String name) {
diff --git a/server/container/mailbox-jmx/src/test/java/org/apache/james/adapter/mailbox/MailboxManagementTest.java b/server/container/mailbox-jmx/src/test/java/org/apache/james/adapter/mailbox/MailboxManagementTest.java
index d38bbc7..39b00f5 100644
--- a/server/container/mailbox-jmx/src/test/java/org/apache/james/adapter/mailbox/MailboxManagementTest.java
+++ b/server/container/mailbox-jmx/src/test/java/org/apache/james/adapter/mailbox/MailboxManagementTest.java
@@ -67,42 +67,42 @@ public class MailboxManagementTest {
 
     @Test
     void deleteMailboxesShouldDeleteMailboxes() throws Exception {
-        mapperFactory.createMailboxMapper(session).create(MailboxPath.forUser(USER, "name"), UID_VALIDITY);
+        mapperFactory.createMailboxMapper(session).create(MailboxPath.forUser(USER, "name"), UID_VALIDITY).block();
         mailboxManagerManagement.deleteMailboxes(USER.asString());
         assertThat(mapperFactory.createMailboxMapper(session).list().collectList().block()).isEmpty();
     }
 
     @Test
     void deleteMailboxesShouldDeleteInbox() throws Exception {
-        mapperFactory.createMailboxMapper(session).create(MailboxPath.inbox(USER), UID_VALIDITY);
+        mapperFactory.createMailboxMapper(session).create(MailboxPath.inbox(USER), UID_VALIDITY).block();
         mailboxManagerManagement.deleteMailboxes(USER.asString());
         assertThat(mapperFactory.createMailboxMapper(session).list().collectList().block()).isEmpty();
     }
 
     @Test
     void deleteMailboxesShouldDeleteMailboxesChildren() throws Exception {
-        mapperFactory.createMailboxMapper(session).create(MailboxPath.forUser(USER, "INBOX.test"), UID_VALIDITY);
+        mapperFactory.createMailboxMapper(session).create(MailboxPath.forUser(USER, "INBOX.test"), UID_VALIDITY).block();
         mailboxManagerManagement.deleteMailboxes(USER.asString());
         assertThat(mapperFactory.createMailboxMapper(session).list().collectList().block()).isEmpty();
     }
 
     @Test
     void deleteMailboxesShouldNotDeleteMailboxesBelongingToNotPrivateNamespace() throws Exception {
-        Mailbox mailbox = mapperFactory.createMailboxMapper(session).create(new MailboxPath("#top", USER, "name"), UID_VALIDITY);
+        Mailbox mailbox = mapperFactory.createMailboxMapper(session).create(new MailboxPath("#top", USER, "name"), UID_VALIDITY).block();
         mailboxManagerManagement.deleteMailboxes(USER.asString());
         assertThat(mapperFactory.createMailboxMapper(session).list().collectList().block()).containsExactly(mailbox);
     }
 
     @Test
     void deleteMailboxesShouldNotDeleteMailboxesBelongingToOtherUsers() throws Exception {
-        Mailbox mailbox = mapperFactory.createMailboxMapper(session).create(MailboxPath.forUser(Username.of("userbis"), "name"), UID_VALIDITY);
+        Mailbox mailbox = mapperFactory.createMailboxMapper(session).create(MailboxPath.forUser(Username.of("userbis"), "name"), UID_VALIDITY).block();
         mailboxManagerManagement.deleteMailboxes(USER.asString());
         assertThat(mapperFactory.createMailboxMapper(session).list().collectList().block()).containsExactly(mailbox);
     }
 
     @Test
     void deleteMailboxesShouldDeleteMailboxesWithEmptyNames() throws Exception {
-        mapperFactory.createMailboxMapper(session).create(MailboxPath.forUser(USER, ""), UID_VALIDITY);
+        mapperFactory.createMailboxMapper(session).create(MailboxPath.forUser(USER, ""), UID_VALIDITY).block();
         mailboxManagerManagement.deleteMailboxes(USER.asString());
         assertThat(mapperFactory.createMailboxMapper(session).list().collectList().block()).isEmpty();
     }
@@ -121,9 +121,9 @@ public class MailboxManagementTest {
 
     @Test
     void deleteMailboxesShouldDeleteMultipleMailboxes() throws Exception {
-        mapperFactory.createMailboxMapper(session).create(MailboxPath.forUser(USER, "name"), UID_VALIDITY);
-        mapperFactory.createMailboxMapper(session).create(MailboxPath.forUser(USER, "INBOX"), UID_VALIDITY);
-        mapperFactory.createMailboxMapper(session).create(MailboxPath.forUser(USER, "INBOX.test"), UID_VALIDITY);
+        mapperFactory.createMailboxMapper(session).create(MailboxPath.forUser(USER, "name"), UID_VALIDITY).block();
+        mapperFactory.createMailboxMapper(session).create(MailboxPath.forUser(USER, "INBOX"), UID_VALIDITY).block();
+        mapperFactory.createMailboxMapper(session).create(MailboxPath.forUser(USER, "INBOX.test"), UID_VALIDITY).block();
         mailboxManagerManagement.deleteMailboxes(USER.asString());
         assertThat(mapperFactory.createMailboxMapper(session).list().collectList().block()).isEmpty();
     }
@@ -141,7 +141,7 @@ public class MailboxManagementTest {
     @Test
     void createMailboxShouldThrowIfMailboxAlreadyExists() throws Exception {
         MailboxPath path = MailboxPath.forUser(USER, "name");
-        mapperFactory.createMailboxMapper(session).create(path, UID_VALIDITY);
+        mapperFactory.createMailboxMapper(session).create(path, UID_VALIDITY).block();
 
         assertThatThrownBy(() -> mailboxManagerManagement.createMailbox(MailboxConstants.USER_NAMESPACE, USER.asString(), "name"))
             .isInstanceOf(RuntimeException.class)
@@ -151,7 +151,7 @@ public class MailboxManagementTest {
     @Test
     void createMailboxShouldNotCreateAdditionalMailboxesIfMailboxAlreadyExists() throws Exception {
         MailboxPath path = MailboxPath.forUser(USER, "name");
-        Mailbox mailbox = mapperFactory.createMailboxMapper(session).create(path, UID_VALIDITY);
+        Mailbox mailbox = mapperFactory.createMailboxMapper(session).create(path, UID_VALIDITY).block();
 
         assertThat(mapperFactory.createMailboxMapper(session).list().collectList().block()).containsExactly(mailbox);
     }
@@ -195,12 +195,12 @@ public class MailboxManagementTest {
     @Test
     void listMailboxesShouldReturnUserMailboxes() throws Exception {
         MailboxMapper mapper = mapperFactory.createMailboxMapper(session);
-        mapper.create(new MailboxPath("#top", USER, "name1"), UID_VALIDITY);
-        mapper.create(MailboxPath.forUser(USER, "name2"), UID_VALIDITY);
-        mapper.create(MailboxPath.forUser(Username.of("other_user"), "name3"), UID_VALIDITY);
-        mapper.create(MailboxPath.forUser(USER, "name4"), UID_VALIDITY);
-        mapper.create(MailboxPath.forUser(USER, "INBOX"), UID_VALIDITY);
-        mapper.create(MailboxPath.forUser(USER, "INBOX.toto"), UID_VALIDITY);
+        mapper.create(new MailboxPath("#top", USER, "name1"), UID_VALIDITY).block();
+        mapper.create(MailboxPath.forUser(USER, "name2"), UID_VALIDITY).block();
+        mapper.create(MailboxPath.forUser(Username.of("other_user"), "name3"), UID_VALIDITY).block();
+        mapper.create(MailboxPath.forUser(USER, "name4"), UID_VALIDITY).block();
+        mapper.create(MailboxPath.forUser(USER, "INBOX"), UID_VALIDITY).block();
+        mapper.create(MailboxPath.forUser(USER, "INBOX.toto"), UID_VALIDITY).block();
         assertThat(mailboxManagerManagement.listMailboxes(USER.asString())).containsOnly("name2", "name4", "INBOX", "INBOX.toto");
     }
 
@@ -218,35 +218,35 @@ public class MailboxManagementTest {
 
     @Test
     void deleteMailboxShouldDeleteGivenMailbox() throws Exception {
-        mapperFactory.createMailboxMapper(session).create(MailboxPath.forUser(USER, "name"), UID_VALIDITY);
+        mapperFactory.createMailboxMapper(session).create(MailboxPath.forUser(USER, "name"), UID_VALIDITY).block();
         mailboxManagerManagement.deleteMailbox(MailboxConstants.USER_NAMESPACE, USER.asString(), "name");
         assertThat(mapperFactory.createMailboxMapper(session).list().collectList().block()).isEmpty();
     }
 
     @Test
     void deleteMailboxShouldNotDeleteGivenMailboxIfWrongNamespace() throws Exception {
-        Mailbox mailbox = mapperFactory.createMailboxMapper(session).create(new MailboxPath("#top", USER, "name"), UID_VALIDITY);
+        Mailbox mailbox = mapperFactory.createMailboxMapper(session).create(new MailboxPath("#top", USER, "name"), UID_VALIDITY).block();
         mailboxManagerManagement.deleteMailbox(MailboxConstants.USER_NAMESPACE, USER.asString(), "name");
         assertThat(mapperFactory.createMailboxMapper(session).list().collectList().block()).containsOnly(mailbox);
     }
 
     @Test
     void deleteMailboxShouldNotDeleteGivenMailboxIfWrongUser() throws Exception {
-        Mailbox mailbox = mapperFactory.createMailboxMapper(session).create(MailboxPath.forUser(Username.of("userbis"), "name"), UID_VALIDITY);
+        Mailbox mailbox = mapperFactory.createMailboxMapper(session).create(MailboxPath.forUser(Username.of("userbis"), "name"), UID_VALIDITY).block();
         mailboxManagerManagement.deleteMailbox(MailboxConstants.USER_NAMESPACE, USER.asString(), "name");
         assertThat(mapperFactory.createMailboxMapper(session).list().collectList().block()).containsOnly(mailbox);
     }
 
     @Test
     void deleteMailboxShouldNotDeleteGivenMailboxIfWrongName() throws Exception {
-        Mailbox mailbox = mapperFactory.createMailboxMapper(session).create(MailboxPath.forUser(USER, "wrong_name"), UID_VALIDITY);
+        Mailbox mailbox = mapperFactory.createMailboxMapper(session).create(MailboxPath.forUser(USER, "wrong_name"), UID_VALIDITY).block();
         mailboxManagerManagement.deleteMailbox(MailboxConstants.USER_NAMESPACE, USER.asString(), "name");
         assertThat(mapperFactory.createMailboxMapper(session).list().collectList().block()).containsOnly(mailbox);
     }
 
     @Test
     void importEmlFileToMailboxShouldImportEmlFileToGivenMailbox() throws Exception {
-        Mailbox mailbox = mapperFactory.createMailboxMapper(session).create(MailboxPath.forUser(USER, "name"), UID_VALIDITY);
+        Mailbox mailbox = mapperFactory.createMailboxMapper(session).create(MailboxPath.forUser(USER, "name"), UID_VALIDITY).block();
         String emlpath = ClassLoader.getSystemResource("eml/frnog.eml").getFile();
         mailboxManagerManagement.importEmlFileToMailbox(MailboxConstants.USER_NAMESPACE, USER.asString(), "name", emlpath);
 
@@ -261,7 +261,7 @@ public class MailboxManagementTest {
 
     @Test
     void importEmlFileToMailboxShouldNotImportEmlFileWithWrongPathToGivenMailbox() throws Exception {
-        Mailbox mailbox = mapperFactory.createMailboxMapper(session).create(MailboxPath.forUser(USER, "name"), UID_VALIDITY);
+        Mailbox mailbox = mapperFactory.createMailboxMapper(session).create(MailboxPath.forUser(USER, "name"), UID_VALIDITY).block();
         String emlpath = ClassLoader.getSystemResource("eml/frnog.eml").getFile();
         mailboxManagerManagement.importEmlFileToMailbox(MailboxConstants.USER_NAMESPACE, USER.asString(), "name", "wrong_path" + emlpath);
 
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/RandomStoring.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/RandomStoring.java
index 6501e03..683e853 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/RandomStoring.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/RandomStoring.java
@@ -117,7 +117,7 @@ public class RandomStoring extends GenericMailet {
             MailboxSession session = mailboxManager.createSystemSession(username);
             return mailboxManager
                 .search(MailboxQuery.privateMailboxesBuilder(session).build(), session)
-                .stream()
+                .toStream()
                 .map(metaData -> new ReroutingInfos(metaData.getPath().getName(), username));
         } catch (Exception e) {
             throw new RuntimeException(e);
diff --git a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/GetMailboxesMethod.java b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/GetMailboxesMethod.java
index 43396a7..aa87311 100644
--- a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/GetMailboxesMethod.java
+++ b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/GetMailboxesMethod.java
@@ -167,7 +167,7 @@ public class GetMailboxesMethod implements Method {
     }
 
     private Flux<MailboxMetaData> getAllMailboxesMetaData(MailboxSession mailboxSession) {
-        return mailboxManager.searchReactive(
+        return mailboxManager.search(
             MailboxQuery.builder()
                 .matchesAllMailboxNames()
                 .build(),
diff --git a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/GetMailboxesMethodTest.java b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/GetMailboxesMethodTest.java
index f47ede8..58c795c 100644
--- a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/GetMailboxesMethodTest.java
+++ b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/GetMailboxesMethodTest.java
@@ -109,7 +109,7 @@ public class GetMailboxesMethodTest {
             .thenReturn(ImmutableList.of(new MailboxPath("namespace", Username.of("user"), "name")));
         when(mockedMailboxManager.getMailbox(any(MailboxPath.class), any()))
             .thenThrow(new MailboxException());
-        when(mockedMailboxManager.searchReactive(any(), any()))
+        when(mockedMailboxManager.search(any(), any()))
             .thenReturn(Flux.empty());
         GetMailboxesMethod testee = new GetMailboxesMethod(mockedMailboxManager, quotaRootResolver, quotaManager, mailboxFactory, new DefaultMetricFactory());
 
diff --git a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/MailboxFactoryTest.java b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/MailboxFactoryTest.java
index f235996..bf7feb4 100644
--- a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/MailboxFactoryTest.java
+++ b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/MailboxFactoryTest.java
@@ -353,7 +353,7 @@ public class MailboxFactoryTest {
                 .asAddition()),
             mailboxSession);
         MailboxMetaData metaData = mailboxManager.search(MailboxQuery.privateMailboxesBuilder(mailboxSession).build(), mailboxSession)
-            .stream()
+            .toStream()
             .filter(metadata -> metadata.getPath().equals(mailboxPath))
             .findFirst()
             .get();
diff --git a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/event/PropagateLookupRightListenerTest.java b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/event/PropagateLookupRightListenerTest.java
index 8f9ad5f..a9381a4 100644
--- a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/event/PropagateLookupRightListenerTest.java
+++ b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/event/PropagateLookupRightListenerTest.java
@@ -121,9 +121,9 @@ public class PropagateLookupRightListenerTest {
 
     @Test
     public void eventShouldDoNothingWhenNewACLIsTheSameAsTheOldOne() throws Exception {
-        Mailbox grandChildMailbox = mailboxMapper.getMailboxMapper(mailboxSession).findMailboxById(grandChildMailboxId);
+        Mailbox grandChildMailbox = mailboxMapper.getMailboxMapper(mailboxSession).findMailboxById(grandChildMailboxId).block();
         mailboxMapper.getMailboxMapper(mailboxSession).setACL(grandChildMailbox, new MailboxACL(
-            new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Lookup))));
+            new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Lookup)))).block();
 
         storeRightManager.applyRightsCommand(
             GRAND_CHILD_MAILBOX,
@@ -162,9 +162,9 @@ public class PropagateLookupRightListenerTest {
 
     @Test
     public void eventShouldUpdateParentWhenMailboxACLUpdateLookupRight() throws Exception {
-        Mailbox grandChildMailbox = mailboxMapper.getMailboxMapper(mailboxSession).findMailboxById(grandChildMailboxId);
+        Mailbox grandChildMailbox = mailboxMapper.getMailboxMapper(mailboxSession).findMailboxById(grandChildMailboxId).block();
         mailboxMapper.getMailboxMapper(mailboxSession).setACL(grandChildMailbox, new MailboxACL(
-            new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Write))));
+            new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Write)))).block();
 
         storeRightManager.setRights(
             GRAND_CHILD_MAILBOX,
@@ -183,9 +183,9 @@ public class PropagateLookupRightListenerTest {
 
     @Test
     public void eventShouldUpdateAllParentWhenMailboxACLUpdateLookupRight() throws Exception {
-        Mailbox grandChildMailbox = mailboxMapper.getMailboxMapper(mailboxSession).findMailboxById(grandChildMailboxId);
+        Mailbox grandChildMailbox = mailboxMapper.getMailboxMapper(mailboxSession).findMailboxById(grandChildMailboxId).block();
         mailboxMapper.getMailboxMapper(mailboxSession).setACL(grandChildMailbox, new MailboxACL(
-            new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Write))));
+            new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Write)))).block();
 
         storeRightManager.setRights(
             GRAND_CHILD_MAILBOX,
@@ -209,9 +209,9 @@ public class PropagateLookupRightListenerTest {
 
     @Test
     public void eventShouldDoNothingWhenMailboxACLRemoveLookupRight() throws Exception {
-        Mailbox grandChildMailbox = mailboxMapper.getMailboxMapper(mailboxSession).findMailboxById(grandChildMailboxId);
+        Mailbox grandChildMailbox = mailboxMapper.getMailboxMapper(mailboxSession).findMailboxById(grandChildMailboxId).block();
         mailboxMapper.getMailboxMapper(mailboxSession).setACL(grandChildMailbox, new MailboxACL(
-            new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Write, Right.Lookup))));
+            new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Write, Right.Lookup)))).block();
 
         storeRightManager.applyRightsCommand(
             GRAND_CHILD_MAILBOX,
@@ -267,9 +267,9 @@ public class PropagateLookupRightListenerTest {
 
     @Test
     public void eventShouldUpdateNewParentWhenRenameMailboxWhichContainLookupRight() throws Exception {
-        Mailbox childMailbox = mailboxMapper.getMailboxMapper(mailboxSession).findMailboxById(childMailboxId);
+        Mailbox childMailbox = mailboxMapper.getMailboxMapper(mailboxSession).findMailboxById(childMailboxId).block();
         mailboxMapper.getMailboxMapper(mailboxSession).setACL(childMailbox, new MailboxACL(
-            new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Write, Right.Lookup))));
+            new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Write, Right.Lookup)))).block();
 
         storeMailboxManager.renameMailbox(CHILD_MAILBOX, MailboxPath.forUser(OWNER_USER, "shared1.sub1New"), mailboxSession);
 
@@ -283,9 +283,9 @@ public class PropagateLookupRightListenerTest {
 
     @Test
     public void eventShouldNotUpdateNewParentWhenRenameMailboxWhichDoesContainLookupRight() throws Exception {
-        Mailbox childMailbox = mailboxMapper.getMailboxMapper(mailboxSession).findMailboxById(childMailboxId);
+        Mailbox childMailbox = mailboxMapper.getMailboxMapper(mailboxSession).findMailboxById(childMailboxId).block();
         mailboxMapper.getMailboxMapper(mailboxSession).setACL(childMailbox, new MailboxACL(
-            new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Write))));
+            new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Write)))).block();
 
         storeMailboxManager.renameMailbox(CHILD_MAILBOX, MailboxPath.forUser(OWNER_USER, "shared1.sub1New"), mailboxSession);
 
@@ -299,9 +299,9 @@ public class PropagateLookupRightListenerTest {
 
     @Test
     public void eventShouldUpdateAllNewParentWhenRenameMailboxWhichContainLookupRight() throws Exception {
-        Mailbox grandChildMailbox = mailboxMapper.getMailboxMapper(mailboxSession).findMailboxById(grandChildMailboxId);
+        Mailbox grandChildMailbox = mailboxMapper.getMailboxMapper(mailboxSession).findMailboxById(grandChildMailboxId).block();
         mailboxMapper.getMailboxMapper(mailboxSession).setACL(grandChildMailbox, new MailboxACL(
-            new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Write, Right.Lookup))));
+            new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Write, Right.Lookup)))).block();
 
         storeMailboxManager.renameMailbox(GRAND_CHILD_MAILBOX, MailboxPath.forUser(OWNER_USER, "shared1.sub1.sub2"), mailboxSession);
 
diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxGetMethod.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxGetMethod.scala
index 5b72d8f..a37cb19 100644
--- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxGetMethod.scala
+++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MailboxGetMethod.scala
@@ -86,7 +86,7 @@ class MailboxGetMethod @Inject() (serializer: Serializer,
   }
 
   private def getAllMailboxesMetaData(mailboxSession: MailboxSession): SMono[Seq[MailboxMetaData]] =
-    SFlux.fromPublisher(mailboxManager.searchReactive(MailboxQuery.builder.matchesAllMailboxNames.build, mailboxSession))
+    SFlux.fromPublisher(mailboxManager.search(MailboxQuery.builder.matchesAllMailboxNames.build, mailboxSession))
       .collectSeq()
 
   private def getMailboxOrThrow(mailboxSession: MailboxSession,
diff --git a/server/protocols/webadmin/webadmin-jmap/src/main/java/org/apache/james/webadmin/data/jmap/MessageFastViewProjectionCorrector.java b/server/protocols/webadmin/webadmin-jmap/src/main/java/org/apache/james/webadmin/data/jmap/MessageFastViewProjectionCorrector.java
index 5bfd792..f23e13c 100644
--- a/server/protocols/webadmin/webadmin-jmap/src/main/java/org/apache/james/webadmin/data/jmap/MessageFastViewProjectionCorrector.java
+++ b/server/protocols/webadmin/webadmin-jmap/src/main/java/org/apache/james/webadmin/data/jmap/MessageFastViewProjectionCorrector.java
@@ -187,16 +187,15 @@ public class MessageFastViewProjectionCorrector {
     }
 
     private Flux<ProjectionEntry> listUserMailboxMessages(Progress progress, MailboxSession session) {
-        try {
-            return listUsersMailboxes(session)
-                .flatMap(mailboxMetadata -> retrieveMailbox(session, mailboxMetadata), MAILBOX_CONCURRENCY)
-                .flatMap(Throwing.function(messageManager -> listAllMailboxMessages(messageManager, session)
-                    .map(message -> new ProjectionEntry(messageManager, message.getUid(), session))), MAILBOX_CONCURRENCY);
-        } catch (MailboxException e) {
-            LOGGER.error("JMAP fastview re-computation aborted for {} as we failed listing user mailboxes", session.getUser(), e);
-            progress.incrementFailedUserCount();
-            return Flux.empty();
-        }
+        return listUsersMailboxes(session)
+            .flatMap(mailboxMetadata -> retrieveMailbox(session, mailboxMetadata), MAILBOX_CONCURRENCY)
+            .flatMap(Throwing.function(messageManager -> listAllMailboxMessages(messageManager, session)
+                .map(message -> new ProjectionEntry(messageManager, message.getUid(), session))), MAILBOX_CONCURRENCY)
+            .onErrorResume(MailboxException.class, e -> {
+                LOGGER.error("JMAP fastview re-computation aborted for {} as we failed listing user mailboxes", session.getUser(), e);
+                progress.incrementFailedUserCount();
+                return Flux.empty();
+            });
     }
 
     private Mono<Result> correctProjection(ProjectionEntry entry, Progress progress) {
@@ -223,8 +222,8 @@ public class MessageFastViewProjectionCorrector {
             .switchIfEmpty(Mono.just(Result.COMPLETED));
     }
 
-    private Flux<MailboxMetaData> listUsersMailboxes(MailboxSession session) throws MailboxException {
-        return Flux.fromIterable(mailboxManager.search(MailboxQuery.privateMailboxesBuilder(session).build(), session));
+    private Flux<MailboxMetaData> listUsersMailboxes(MailboxSession session) {
+        return mailboxManager.search(MailboxQuery.privateMailboxesBuilder(session).build(), session);
     }
 
     private Mono<MessageManager> retrieveMailbox(MailboxSession session, MailboxMetaData mailboxMetadata) {
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserMailboxesService.java b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserMailboxesService.java
index 8f78beb..6938f5e 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserMailboxesService.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserMailboxesService.java
@@ -128,7 +128,7 @@ public class UserMailboxesService {
         return mailboxManager.search(
             MailboxQuery.privateMailboxesBuilder(mailboxSession).build(),
             mailboxSession)
-            .stream();
+            .toStream();
     }
 
 }
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
index f6eb6b5..ff3dbfb 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
@@ -44,6 +44,7 @@ import static org.mockito.Mockito.when;
 
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Stream;
 
 import org.apache.james.core.Username;
 import org.apache.james.json.DTOConverter;
@@ -86,10 +87,10 @@ import org.junit.jupiter.api.Test;
 import org.mockito.ArgumentCaptor;
 import org.mockito.Mockito;
 
-import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 
 import io.restassured.RestAssured;
+import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
 
 class UserMailboxesRoutesTest {
@@ -895,7 +896,7 @@ class UserMailboxesRoutesTest {
             MailboxId mailboxId = InMemoryId.of(12);
             when(mailboxManager.search(any(MailboxQuery.class), any()))
                 .thenReturn(
-                        ImmutableList.of(
+                        Flux.just(
                                 MailboxMetaData.unselectableMailbox(
                                         MailboxPath.forUser(USERNAME, MAILBOX_NAME), mailboxId, '.')));
             doThrow(new RuntimeException()).when(mailboxManager).deleteMailbox(any(MailboxPath.class), any());
@@ -908,7 +909,7 @@ class UserMailboxesRoutesTest {
 
         @Test
         void deleteShouldGenerateInternalErrorOnUnknownExceptionOnSearch() throws Exception {
-            when(mailboxManager.search(any(MailboxQuery.class), any())).thenThrow(new RuntimeException());
+            when(mailboxManager.search(any(MailboxQuery.class), any())).thenReturn(Flux.error(new RuntimeException()));
 
             when()
                 .delete(MAILBOX_NAME)
@@ -921,7 +922,7 @@ class UserMailboxesRoutesTest {
             MailboxId mailboxId = InMemoryId.of(12);
             when(mailboxManager.search(any(MailboxQuery.class), any()))
                 .thenReturn(
-                        ImmutableList.of(
+                        Flux.just(
                                 MailboxMetaData.unselectableMailbox(MailboxPath.forUser(USERNAME, MAILBOX_NAME), mailboxId, '.')));
             doThrow(new MailboxException()).when(mailboxManager).deleteMailbox(any(MailboxPath.class), any());
 
@@ -933,7 +934,7 @@ class UserMailboxesRoutesTest {
 
         @Test
         void deleteShouldGenerateInternalErrorOnUnknownMailboxExceptionOnSearch() throws Exception {
-            when(mailboxManager.search(any(MailboxQuery.class), any())).thenThrow(new MailboxException());
+            when(mailboxManager.search(any(MailboxQuery.class), any())).thenReturn(Flux.error(new MailboxException()));
 
             when()
                 .delete(MAILBOX_NAME)
@@ -943,6 +944,10 @@ class UserMailboxesRoutesTest {
 
         @Test
         void deleteShouldReturnOkOnMailboxDoesNotExists() throws Exception {
+            MailboxMetaData metaData = mock(MailboxMetaData.class);
+            when(metaData.getPath()).thenReturn(MailboxPath.forUser(USERNAME, MAILBOX_NAME));
+            doReturn(Flux.just(metaData))
+                .when(mailboxManager).search(any(MailboxQuery.class), any(MailboxSession.class));
             doThrow(new MailboxNotFoundException(MAILBOX_NAME)).when(mailboxManager).deleteMailbox(any(MailboxPath.class), any());
 
             when()
@@ -953,7 +958,7 @@ class UserMailboxesRoutesTest {
 
         @Test
         void deleteShouldGenerateInternalErrorOnUnknownExceptionWhenListingMailboxes() throws Exception {
-            doThrow(new RuntimeException()).when(mailboxManager).search(any(MailboxQuery.class), any());
+            when(mailboxManager.search(any(MailboxQuery.class), any())).thenReturn(Flux.error(new RuntimeException()));
 
             when()
                 .delete()
@@ -963,7 +968,7 @@ class UserMailboxesRoutesTest {
 
         @Test
         void deleteShouldGenerateInternalErrorOnMailboxExceptionWhenListingMailboxes() throws Exception {
-            doThrow(new MailboxException()).when(mailboxManager).search(any(MailboxQuery.class), any());
+            when(mailboxManager.search(any(MailboxQuery.class), any())).thenReturn(Flux.error(new MailboxException()));
 
             when()
                 .delete()
@@ -977,7 +982,7 @@ class UserMailboxesRoutesTest {
             MailboxId mailboxId = InMemoryId.of(12);
             when(mailboxManager.search(any(MailboxQuery.class), any()))
                 .thenReturn(
-                        ImmutableList.of(
+                        Flux.just(
                                 MailboxMetaData.unselectableMailbox(MailboxPath.forUser(USERNAME, "any"), mailboxId, '.')));
             doThrow(new RuntimeException()).when(mailboxManager).deleteMailbox(any(MailboxPath.class), any());
 
@@ -992,7 +997,7 @@ class UserMailboxesRoutesTest {
             MailboxId mailboxId = InMemoryId.of(12);
             when(mailboxManager.search(any(MailboxQuery.class), any()))
                 .thenReturn(
-                        ImmutableList.of(MailboxMetaData.unselectableMailbox(MailboxPath.forUser(USERNAME, "any"), mailboxId, '.')));
+                        Flux.just(MailboxMetaData.unselectableMailbox(MailboxPath.forUser(USERNAME, "any"), mailboxId, '.')));
             doThrow(new MailboxNotFoundException("any")).when(mailboxManager).deleteMailbox(any(MailboxPath.class), any());
 
             when()
@@ -1006,7 +1011,7 @@ class UserMailboxesRoutesTest {
             MailboxId mailboxId = InMemoryId.of(12);
             when(mailboxManager.search(any(MailboxQuery.class), any()))
                 .thenReturn(
-                        ImmutableList.of(MailboxMetaData.unselectableMailbox(MailboxPath.forUser(USERNAME, "any"), mailboxId, '.')));
+                        Flux.just(MailboxMetaData.unselectableMailbox(MailboxPath.forUser(USERNAME, "any"), mailboxId, '.')));
             doThrow(new MailboxException()).when(mailboxManager).deleteMailbox(any(MailboxPath.class), any());
 
             when()
@@ -1037,7 +1042,7 @@ class UserMailboxesRoutesTest {
 
         @Test
         void getMailboxesShouldGenerateInternalErrorOnUnknownException() throws Exception {
-            doThrow(new RuntimeException()).when(mailboxManager).search(any(MailboxQuery.class), any());
+            when(mailboxManager.search(any(MailboxQuery.class), any())).thenReturn(Flux.error(new RuntimeException()));
 
             when()
                 .get()
@@ -1047,7 +1052,7 @@ class UserMailboxesRoutesTest {
 
         @Test
         void getMailboxesShouldGenerateInternalErrorOnUnknownMailboxException() throws Exception {
-            doThrow(new MailboxException()).when(mailboxManager).search(any(MailboxQuery.class), any());
+            when(mailboxManager.search(any(MailboxQuery.class), any())).thenReturn(Flux.error(new MailboxException()));
 
             when()
                 .get()


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


[james-project] 08/12: JAMES-3167 Add MailboxReactorUtils

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 013d7a5d91e05b69934041ce8614b3b865e71d6f
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Wed May 27 14:07:06 2020 +0200

    JAMES-3167 Add MailboxReactorUtils
---
 .../james/mailbox/store/MailboxReactorUtils.java   | 52 +++++++++++++++++++++
 .../mailbox/store/MailboxReactorUtilsTest.java     | 54 ++++++++++++++++++++++
 2 files changed, 106 insertions(+)

diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/MailboxReactorUtils.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/MailboxReactorUtils.java
new file mode 100644
index 0000000..c8e3cd3
--- /dev/null
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/MailboxReactorUtils.java
@@ -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;
+
+import java.util.Optional;
+
+import org.apache.james.mailbox.exception.MailboxException;
+
+import reactor.core.publisher.Mono;
+
+public abstract class MailboxReactorUtils {
+    public static <T> T block(Mono<T> publisher) throws MailboxException {
+        try {
+            return publisher.block();
+        } catch (RuntimeException e) {
+            if (e.getCause() instanceof MailboxException) {
+                throw (MailboxException) e.getCause();
+            }
+
+            throw e;
+        }
+    }
+    
+    public static <T> Optional<T> blockOptional(Mono<T> publisher) throws MailboxException {
+        try {
+            return publisher.blockOptional();
+        } catch (RuntimeException e) {
+            if (e.getCause() instanceof MailboxException) {
+                throw (MailboxException) e.getCause();
+            }
+
+            throw e;
+        }
+    }
+}
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/MailboxReactorUtilsTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MailboxReactorUtilsTest.java
new file mode 100644
index 0000000..caf5e2f
--- /dev/null
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MailboxReactorUtilsTest.java
@@ -0,0 +1,54 @@
+/****************************************************************
+ * 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;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.apache.james.mailbox.exception.MailboxException;
+import org.junit.jupiter.api.Test;
+
+import reactor.core.publisher.Mono;
+
+class MailboxReactorUtilsTest {
+    @Test
+    void blockJustShouldReturnTheValue() throws Exception {
+        assertThat(MailboxReactorUtils.block(Mono.just(42)))
+            .isEqualTo(42);
+    }
+
+    @Test
+    void blockEmptyShouldReturnNull() throws Exception {
+        assertThat((Integer) MailboxReactorUtils.block(Mono.empty()))
+            .isNull();
+    }
+
+    @Test
+    void blockErrorMailboxExceptionShouldThrowMailboxException() {
+        assertThatThrownBy(() -> MailboxReactorUtils.block(Mono.error(new MailboxException())))
+            .isInstanceOf(MailboxException.class);
+    }
+
+    @Test
+    void blockErrorRuntimeExceptionShouldThrowRuntimeException() {
+        assertThatThrownBy(() -> MailboxReactorUtils.block(Mono.error(new RuntimeException())))
+            .isInstanceOf(RuntimeException.class);
+    }
+}
\ No newline at end of file


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


[james-project] 01/12: JAMES-3253 RemoteDelivery maxRetries configuration examples should be valid

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 91617ef29e34f1cd77aa519f775fe840dac4d247
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Jun 19 13:49:02 2020 +0700

    JAMES-3253 RemoteDelivery maxRetries configuration examples should be valid
---
 .../run/guice/cassandra-ldap/destination/conf/mailetcontainer.xml       | 2 +-
 .../guice/cassandra-rabbitmq-ldap/destination/conf/mailetcontainer.xml  | 2 +-
 .../run/guice/cassandra-rabbitmq/destination/conf/mailetcontainer.xml   | 2 +-
 dockerfiles/run/guice/cassandra/destination/conf/mailetcontainer.xml    | 2 +-
 dockerfiles/run/guice/jpa-smtp/destination/conf/mailetcontainer.xml     | 2 +-
 dockerfiles/run/guice/jpa/destination/conf/mailetcontainer.xml          | 2 +-
 dockerfiles/run/guice/memory/destination/conf/mailetcontainer.xml       | 2 +-
 dockerfiles/run/spring/destination/conf/mailetcontainer.xml             | 2 +-
 server/app/src/main/resources/mailetcontainer.xml                       | 2 +-
 server/container/cli-integration/src/test/resources/mailetcontainer.xml | 2 +-
 .../guice/cassandra-guice/src/test/resources/mailetcontainer.xml        | 2 +-
 .../guice/cassandra-ldap-guice/src/test/resources/mailetcontainer.xml   | 2 +-
 .../cassandra-rabbitmq-guice/src/test/resources/mailetcontainer.xml     | 2 +-
 .../src/test/resources/mailetcontainer.xml                              | 2 +-
 server/container/guice/jpa-guice/src/test/resources/mailetcontainer.xml | 2 +-
 .../container/guice/jpa-smtp/sample-configuration/mailetcontainer.xml   | 2 +-
 .../guice/memory-guice/sample-configuration/mailetcontainer.xml         | 2 +-
 .../container/guice/memory-guice/src/test/resources/mailetcontainer.xml | 2 +-
 .../java/org/apache/james/mailets/configuration/CommonProcessors.java   | 2 +-
 .../src/test/resources/mailetcontainer.xml                              | 2 +-
 .../src/test/resources/mailetcontainer.xml                              | 2 +-
 .../src/test/resources/mailetcontainer.xml                              | 2 +-
 .../src/test/resources/mailetcontainer.xml                              | 2 +-
 .../src/test/resources/mailetcontainer.xml                              | 2 +-
 .../src/test/resources/mailetcontainer.xml                              | 2 +-
 .../src/test/resources/mailetcontainer.xml                              | 2 +-
 26 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/dockerfiles/run/guice/cassandra-ldap/destination/conf/mailetcontainer.xml b/dockerfiles/run/guice/cassandra-ldap/destination/conf/mailetcontainer.xml
index c022be2..017d7c2 100644
--- a/dockerfiles/run/guice/cassandra-ldap/destination/conf/mailetcontainer.xml
+++ b/dockerfiles/run/guice/cassandra-ldap/destination/conf/mailetcontainer.xml
@@ -88,7 +88,7 @@
             <mailet match="All" class="RemoteDelivery">
                 <outgoingQueue>outgoing</outgoingQueue>
                 <delayTime>5000, 100000, 500000</delayTime>
-                <maxRetries>25</maxRetries>
+                <maxRetries>3</maxRetries>
                 <maxDnsProblemRetries>0</maxDnsProblemRetries>
                 <deliveryThreads>10</deliveryThreads>
                 <sendpartial>true</sendpartial>
diff --git a/dockerfiles/run/guice/cassandra-rabbitmq-ldap/destination/conf/mailetcontainer.xml b/dockerfiles/run/guice/cassandra-rabbitmq-ldap/destination/conf/mailetcontainer.xml
index 28aa44e..1e621ba 100644
--- a/dockerfiles/run/guice/cassandra-rabbitmq-ldap/destination/conf/mailetcontainer.xml
+++ b/dockerfiles/run/guice/cassandra-rabbitmq-ldap/destination/conf/mailetcontainer.xml
@@ -89,7 +89,7 @@
             <mailet match="All" class="RemoteDelivery">
                 <outgoingQueue>outgoing</outgoingQueue>
                 <delayTime>5000, 100000, 500000</delayTime>
-                <maxRetries>25</maxRetries>
+                <maxRetries>3</maxRetries>
                 <maxDnsProblemRetries>0</maxDnsProblemRetries>
                 <deliveryThreads>10</deliveryThreads>
                 <sendpartial>true</sendpartial>
diff --git a/dockerfiles/run/guice/cassandra-rabbitmq/destination/conf/mailetcontainer.xml b/dockerfiles/run/guice/cassandra-rabbitmq/destination/conf/mailetcontainer.xml
index 28aa44e..1e621ba 100644
--- a/dockerfiles/run/guice/cassandra-rabbitmq/destination/conf/mailetcontainer.xml
+++ b/dockerfiles/run/guice/cassandra-rabbitmq/destination/conf/mailetcontainer.xml
@@ -89,7 +89,7 @@
             <mailet match="All" class="RemoteDelivery">
                 <outgoingQueue>outgoing</outgoingQueue>
                 <delayTime>5000, 100000, 500000</delayTime>
-                <maxRetries>25</maxRetries>
+                <maxRetries>3</maxRetries>
                 <maxDnsProblemRetries>0</maxDnsProblemRetries>
                 <deliveryThreads>10</deliveryThreads>
                 <sendpartial>true</sendpartial>
diff --git a/dockerfiles/run/guice/cassandra/destination/conf/mailetcontainer.xml b/dockerfiles/run/guice/cassandra/destination/conf/mailetcontainer.xml
index 28aa44e..1e621ba 100644
--- a/dockerfiles/run/guice/cassandra/destination/conf/mailetcontainer.xml
+++ b/dockerfiles/run/guice/cassandra/destination/conf/mailetcontainer.xml
@@ -89,7 +89,7 @@
             <mailet match="All" class="RemoteDelivery">
                 <outgoingQueue>outgoing</outgoingQueue>
                 <delayTime>5000, 100000, 500000</delayTime>
-                <maxRetries>25</maxRetries>
+                <maxRetries>3</maxRetries>
                 <maxDnsProblemRetries>0</maxDnsProblemRetries>
                 <deliveryThreads>10</deliveryThreads>
                 <sendpartial>true</sendpartial>
diff --git a/dockerfiles/run/guice/jpa-smtp/destination/conf/mailetcontainer.xml b/dockerfiles/run/guice/jpa-smtp/destination/conf/mailetcontainer.xml
index 6a90e85..e0ee151 100644
--- a/dockerfiles/run/guice/jpa-smtp/destination/conf/mailetcontainer.xml
+++ b/dockerfiles/run/guice/jpa-smtp/destination/conf/mailetcontainer.xml
@@ -69,7 +69,7 @@
             <mailet match="relay-allowed" class="RemoteDelivery">
                 <outgoingQueue>outgoing</outgoingQueue>
                 <delayTime>5000, 100000, 500000</delayTime>
-                <maxRetries>25</maxRetries>
+                <maxRetries>3</maxRetries>
                 <maxDnsProblemRetries>0</maxDnsProblemRetries>
                 <deliveryThreads>10</deliveryThreads>
                 <sendpartial>true</sendpartial>
diff --git a/dockerfiles/run/guice/jpa/destination/conf/mailetcontainer.xml b/dockerfiles/run/guice/jpa/destination/conf/mailetcontainer.xml
index 062093d..45f75ce 100644
--- a/dockerfiles/run/guice/jpa/destination/conf/mailetcontainer.xml
+++ b/dockerfiles/run/guice/jpa/destination/conf/mailetcontainer.xml
@@ -82,7 +82,7 @@
             <mailet match="All" class="RemoteDelivery">
                 <outgoingQueue>outgoing</outgoingQueue>
                 <delayTime>5000, 100000, 500000</delayTime>
-                <maxRetries>25</maxRetries>
+                <maxRetries>3</maxRetries>
                 <maxDnsProblemRetries>0</maxDnsProblemRetries>
                 <deliveryThreads>10</deliveryThreads>
                 <sendpartial>true</sendpartial>
diff --git a/dockerfiles/run/guice/memory/destination/conf/mailetcontainer.xml b/dockerfiles/run/guice/memory/destination/conf/mailetcontainer.xml
index 0881d66..af849fd 100644
--- a/dockerfiles/run/guice/memory/destination/conf/mailetcontainer.xml
+++ b/dockerfiles/run/guice/memory/destination/conf/mailetcontainer.xml
@@ -89,7 +89,7 @@
             <mailet match="All" class="RemoteDelivery">
                 <outgoingQueue>outgoing</outgoingQueue>
                 <delayTime>5000, 100000, 500000</delayTime>
-                <maxRetries>25</maxRetries>
+                <maxRetries>3</maxRetries>
                 <maxDnsProblemRetries>0</maxDnsProblemRetries>
                 <deliveryThreads>10</deliveryThreads>
                 <sendpartial>true</sendpartial>
diff --git a/dockerfiles/run/spring/destination/conf/mailetcontainer.xml b/dockerfiles/run/spring/destination/conf/mailetcontainer.xml
index 90de4e5..49237c8 100644
--- a/dockerfiles/run/spring/destination/conf/mailetcontainer.xml
+++ b/dockerfiles/run/spring/destination/conf/mailetcontainer.xml
@@ -84,7 +84,7 @@
             <mailet match="All" class="RemoteDelivery">
                 <outgoingQueue>outgoing</outgoingQueue>
                 <delayTime>5000, 100000, 500000</delayTime>
-                <maxRetries>25</maxRetries>
+                <maxRetries>3</maxRetries>
                 <maxDnsProblemRetries>0</maxDnsProblemRetries>
                 <deliveryThreads>10</deliveryThreads>
                 <sendpartial>true</sendpartial>
diff --git a/server/app/src/main/resources/mailetcontainer.xml b/server/app/src/main/resources/mailetcontainer.xml
index 43b1a87..e443e33 100644
--- a/server/app/src/main/resources/mailetcontainer.xml
+++ b/server/app/src/main/resources/mailetcontainer.xml
@@ -317,7 +317,7 @@ Regards, Postmaster XXX.YYY
           <delayTime>4 * 15 minutes, 2 * 3 hours, 18 * 6 hours</delayTime>
           -->
           <delayTime>5000, 100000, 500000</delayTime>
-          <maxRetries>25</maxRetries>
+          <maxRetries>3</maxRetries>
             
           <!-- The max reties which will used if no A or MX record for the domain was found. -->
           <!-- If 0 it will fail on first time -->
diff --git a/server/container/cli-integration/src/test/resources/mailetcontainer.xml b/server/container/cli-integration/src/test/resources/mailetcontainer.xml
index cb2c0dc..5322187 100644
--- a/server/container/cli-integration/src/test/resources/mailetcontainer.xml
+++ b/server/container/cli-integration/src/test/resources/mailetcontainer.xml
@@ -68,7 +68,7 @@
             <mailet match="relay-allowed" class="RemoteDelivery">
                 <outgoingQueue>outgoing</outgoingQueue>
                 <delayTime>5000, 100000, 500000</delayTime>
-                <maxRetries>25</maxRetries>
+                <maxRetries>3</maxRetries>
                 <maxDnsProblemRetries>0</maxDnsProblemRetries>
                 <deliveryThreads>10</deliveryThreads>
                 <sendpartial>true</sendpartial>
diff --git a/server/container/guice/cassandra-guice/src/test/resources/mailetcontainer.xml b/server/container/guice/cassandra-guice/src/test/resources/mailetcontainer.xml
index 8f3139d..4549bd2 100644
--- a/server/container/guice/cassandra-guice/src/test/resources/mailetcontainer.xml
+++ b/server/container/guice/cassandra-guice/src/test/resources/mailetcontainer.xml
@@ -84,7 +84,7 @@
             <mailet match="relay-allowed" class="RemoteDelivery">
                 <outgoingQueue>outgoing</outgoingQueue>
                 <delayTime>5000, 100000, 500000</delayTime>
-                <maxRetries>25</maxRetries>
+                <maxRetries>3</maxRetries>
                 <maxDnsProblemRetries>0</maxDnsProblemRetries>
                 <deliveryThreads>10</deliveryThreads>
                 <sendpartial>true</sendpartial>
diff --git a/server/container/guice/cassandra-ldap-guice/src/test/resources/mailetcontainer.xml b/server/container/guice/cassandra-ldap-guice/src/test/resources/mailetcontainer.xml
index 8fb07dd..c2f0cc0 100644
--- a/server/container/guice/cassandra-ldap-guice/src/test/resources/mailetcontainer.xml
+++ b/server/container/guice/cassandra-ldap-guice/src/test/resources/mailetcontainer.xml
@@ -69,7 +69,7 @@
             <mailet match="relay-allowed" class="RemoteDelivery">
                 <outgoingQueue>outgoing</outgoingQueue>
                 <delayTime>5000, 100000, 500000</delayTime>
-                <maxRetries>25</maxRetries>
+                <maxRetries>3</maxRetries>
                 <maxDnsProblemRetries>0</maxDnsProblemRetries>
                 <deliveryThreads>10</deliveryThreads>
                 <sendpartial>true</sendpartial>
diff --git a/server/container/guice/cassandra-rabbitmq-guice/src/test/resources/mailetcontainer.xml b/server/container/guice/cassandra-rabbitmq-guice/src/test/resources/mailetcontainer.xml
index 4478ff4..0f6b8dd 100644
--- a/server/container/guice/cassandra-rabbitmq-guice/src/test/resources/mailetcontainer.xml
+++ b/server/container/guice/cassandra-rabbitmq-guice/src/test/resources/mailetcontainer.xml
@@ -77,7 +77,7 @@
             <mailet match="relay-allowed" class="RemoteDelivery">
                 <outgoingQueue>outgoing</outgoingQueue>
                 <delayTime>5000, 100000, 500000</delayTime>
-                <maxRetries>25</maxRetries>
+                <maxRetries>3</maxRetries>
                 <maxDnsProblemRetries>0</maxDnsProblemRetries>
                 <deliveryThreads>10</deliveryThreads>
                 <sendpartial>true</sendpartial>
diff --git a/server/container/guice/cassandra-rabbitmq-ldap-guice/src/test/resources/mailetcontainer.xml b/server/container/guice/cassandra-rabbitmq-ldap-guice/src/test/resources/mailetcontainer.xml
index 8fb07dd..c2f0cc0 100644
--- a/server/container/guice/cassandra-rabbitmq-ldap-guice/src/test/resources/mailetcontainer.xml
+++ b/server/container/guice/cassandra-rabbitmq-ldap-guice/src/test/resources/mailetcontainer.xml
@@ -69,7 +69,7 @@
             <mailet match="relay-allowed" class="RemoteDelivery">
                 <outgoingQueue>outgoing</outgoingQueue>
                 <delayTime>5000, 100000, 500000</delayTime>
-                <maxRetries>25</maxRetries>
+                <maxRetries>3</maxRetries>
                 <maxDnsProblemRetries>0</maxDnsProblemRetries>
                 <deliveryThreads>10</deliveryThreads>
                 <sendpartial>true</sendpartial>
diff --git a/server/container/guice/jpa-guice/src/test/resources/mailetcontainer.xml b/server/container/guice/jpa-guice/src/test/resources/mailetcontainer.xml
index ea73265..e03f3e5 100644
--- a/server/container/guice/jpa-guice/src/test/resources/mailetcontainer.xml
+++ b/server/container/guice/jpa-guice/src/test/resources/mailetcontainer.xml
@@ -68,7 +68,7 @@
             <mailet match="relay-allowed" class="RemoteDelivery">
                 <outgoingQueue>outgoing</outgoingQueue>
                 <delayTime>5000, 100000, 500000</delayTime>
-                <maxRetries>25</maxRetries>
+                <maxRetries>3</maxRetries>
                 <maxDnsProblemRetries>0</maxDnsProblemRetries>
                 <deliveryThreads>10</deliveryThreads>
                 <sendpartial>true</sendpartial>
diff --git a/server/container/guice/jpa-smtp/sample-configuration/mailetcontainer.xml b/server/container/guice/jpa-smtp/sample-configuration/mailetcontainer.xml
index 8eebb45..0317de4 100644
--- a/server/container/guice/jpa-smtp/sample-configuration/mailetcontainer.xml
+++ b/server/container/guice/jpa-smtp/sample-configuration/mailetcontainer.xml
@@ -64,7 +64,7 @@
             <mailet match="relay-allowed" class="RemoteDelivery">
                 <outgoingQueue>outgoing</outgoingQueue>
                 <delayTime>5000, 100000, 500000</delayTime>
-                <maxRetries>25</maxRetries>
+                <maxRetries>3</maxRetries>
                 <maxDnsProblemRetries>0</maxDnsProblemRetries>
                 <deliveryThreads>10</deliveryThreads>
                 <sendpartial>true</sendpartial>
diff --git a/server/container/guice/memory-guice/sample-configuration/mailetcontainer.xml b/server/container/guice/memory-guice/sample-configuration/mailetcontainer.xml
index 6b29c87..9ed6c89 100644
--- a/server/container/guice/memory-guice/sample-configuration/mailetcontainer.xml
+++ b/server/container/guice/memory-guice/sample-configuration/mailetcontainer.xml
@@ -65,7 +65,7 @@
             <mailet match="relay-allowed" class="RemoteDelivery">
                 <outgoingQueue>outgoing</outgoingQueue>
                 <delayTime>5000, 100000, 500000</delayTime>
-                <maxRetries>25</maxRetries>
+                <maxRetries>3</maxRetries>
                 <maxDnsProblemRetries>0</maxDnsProblemRetries>
                 <deliveryThreads>10</deliveryThreads>
                 <sendpartial>true</sendpartial>
diff --git a/server/container/guice/memory-guice/src/test/resources/mailetcontainer.xml b/server/container/guice/memory-guice/src/test/resources/mailetcontainer.xml
index c3b4204..7d68583 100644
--- a/server/container/guice/memory-guice/src/test/resources/mailetcontainer.xml
+++ b/server/container/guice/memory-guice/src/test/resources/mailetcontainer.xml
@@ -87,7 +87,7 @@
             <mailet match="HasMailAttribute=RelayAllowed" class="RemoteDelivery">
                 <outgoingQueue>outgoing</outgoingQueue>
                 <delayTime>5000, 100000, 500000</delayTime>
-                <maxRetries>25</maxRetries>
+                <maxRetries>3</maxRetries>
                 <maxDnsProblemRetries>0</maxDnsProblemRetries>
                 <deliveryThreads>10</deliveryThreads>
                 <sendpartial>true</sendpartial>
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/CommonProcessors.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/CommonProcessors.java
index b2c09a2..e3b021b 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/CommonProcessors.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/CommonProcessors.java
@@ -114,7 +114,7 @@ public class CommonProcessors {
                         .mailet(RemoteDelivery.class)
                         .addProperty("outgoingQueue", "outgoing")
                         .addProperty("delayTime", "5000, 100000, 500000")
-                        .addProperty("maxRetries", "25")
+                        .addProperty("maxRetries", "3")
                         .addProperty("maxDnsProblemRetries", "0")
                         .addProperty("deliveryThreads", "10")
                         .addProperty("sendpartial", "true")
diff --git a/server/protocols/jmap-draft-integration-testing/cassandra-jmap-draft-integration-testing/src/test/resources/mailetcontainer.xml b/server/protocols/jmap-draft-integration-testing/cassandra-jmap-draft-integration-testing/src/test/resources/mailetcontainer.xml
index 09189f4..f63f535 100644
--- a/server/protocols/jmap-draft-integration-testing/cassandra-jmap-draft-integration-testing/src/test/resources/mailetcontainer.xml
+++ b/server/protocols/jmap-draft-integration-testing/cassandra-jmap-draft-integration-testing/src/test/resources/mailetcontainer.xml
@@ -86,7 +86,7 @@
             <mailet match="relay-allowed" class="RemoteDelivery">
                 <outgoingQueue>outgoing</outgoingQueue>
                 <delayTime>5000, 100000, 500000</delayTime>
-                <maxRetries>25</maxRetries>
+                <maxRetries>3</maxRetries>
                 <maxDnsProblemRetries>0</maxDnsProblemRetries>
                 <deliveryThreads>10</deliveryThreads>
                 <sendpartial>true</sendpartial>
diff --git a/server/protocols/jmap-draft-integration-testing/memory-jmap-draft-integration-testing/src/test/resources/mailetcontainer.xml b/server/protocols/jmap-draft-integration-testing/memory-jmap-draft-integration-testing/src/test/resources/mailetcontainer.xml
index e62bd0e..849d564 100644
--- a/server/protocols/jmap-draft-integration-testing/memory-jmap-draft-integration-testing/src/test/resources/mailetcontainer.xml
+++ b/server/protocols/jmap-draft-integration-testing/memory-jmap-draft-integration-testing/src/test/resources/mailetcontainer.xml
@@ -87,7 +87,7 @@
             <mailet match="relay-allowed" class="RemoteDelivery">
                 <outgoingQueue>outgoing</outgoingQueue>
                 <delayTime>5000, 100000, 500000</delayTime>
-                <maxRetries>25</maxRetries>
+                <maxRetries>3</maxRetries>
                 <maxDnsProblemRetries>0</maxDnsProblemRetries>
                 <deliveryThreads>10</deliveryThreads>
                 <sendpartial>true</sendpartial>
diff --git a/server/protocols/jmap-draft-integration-testing/rabbitmq-jmap-draft-integration-testing/src/test/resources/mailetcontainer.xml b/server/protocols/jmap-draft-integration-testing/rabbitmq-jmap-draft-integration-testing/src/test/resources/mailetcontainer.xml
index 09189f4..f63f535 100644
--- a/server/protocols/jmap-draft-integration-testing/rabbitmq-jmap-draft-integration-testing/src/test/resources/mailetcontainer.xml
+++ b/server/protocols/jmap-draft-integration-testing/rabbitmq-jmap-draft-integration-testing/src/test/resources/mailetcontainer.xml
@@ -86,7 +86,7 @@
             <mailet match="relay-allowed" class="RemoteDelivery">
                 <outgoingQueue>outgoing</outgoingQueue>
                 <delayTime>5000, 100000, 500000</delayTime>
-                <maxRetries>25</maxRetries>
+                <maxRetries>3</maxRetries>
                 <maxDnsProblemRetries>0</maxDnsProblemRetries>
                 <deliveryThreads>10</deliveryThreads>
                 <sendpartial>true</sendpartial>
diff --git a/server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/resources/mailetcontainer.xml b/server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/resources/mailetcontainer.xml
index 09189f4..f63f535 100644
--- a/server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/resources/mailetcontainer.xml
+++ b/server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/resources/mailetcontainer.xml
@@ -86,7 +86,7 @@
             <mailet match="relay-allowed" class="RemoteDelivery">
                 <outgoingQueue>outgoing</outgoingQueue>
                 <delayTime>5000, 100000, 500000</delayTime>
-                <maxRetries>25</maxRetries>
+                <maxRetries>3</maxRetries>
                 <maxDnsProblemRetries>0</maxDnsProblemRetries>
                 <deliveryThreads>10</deliveryThreads>
                 <sendpartial>true</sendpartial>
diff --git a/server/protocols/jmap-rfc-8621-integration-tests/memory-jmap-rfc-8621-integration-tests/src/test/resources/mailetcontainer.xml b/server/protocols/jmap-rfc-8621-integration-tests/memory-jmap-rfc-8621-integration-tests/src/test/resources/mailetcontainer.xml
index e62bd0e..849d564 100644
--- a/server/protocols/jmap-rfc-8621-integration-tests/memory-jmap-rfc-8621-integration-tests/src/test/resources/mailetcontainer.xml
+++ b/server/protocols/jmap-rfc-8621-integration-tests/memory-jmap-rfc-8621-integration-tests/src/test/resources/mailetcontainer.xml
@@ -87,7 +87,7 @@
             <mailet match="relay-allowed" class="RemoteDelivery">
                 <outgoingQueue>outgoing</outgoingQueue>
                 <delayTime>5000, 100000, 500000</delayTime>
-                <maxRetries>25</maxRetries>
+                <maxRetries>3</maxRetries>
                 <maxDnsProblemRetries>0</maxDnsProblemRetries>
                 <deliveryThreads>10</deliveryThreads>
                 <sendpartial>true</sendpartial>
diff --git a/server/protocols/webadmin-integration-test/distributed-webadmin-integration-test/src/test/resources/mailetcontainer.xml b/server/protocols/webadmin-integration-test/distributed-webadmin-integration-test/src/test/resources/mailetcontainer.xml
index d0bc644..f8b5bfd 100644
--- a/server/protocols/webadmin-integration-test/distributed-webadmin-integration-test/src/test/resources/mailetcontainer.xml
+++ b/server/protocols/webadmin-integration-test/distributed-webadmin-integration-test/src/test/resources/mailetcontainer.xml
@@ -71,7 +71,7 @@
             <mailet match="relay-allowed" class="RemoteDelivery">
                 <outgoingQueue>outgoing</outgoingQueue>
                 <delayTime>5000, 100000, 500000</delayTime>
-                <maxRetries>25</maxRetries>
+                <maxRetries>3</maxRetries>
                 <maxDnsProblemRetries>0</maxDnsProblemRetries>
                 <deliveryThreads>10</deliveryThreads>
                 <sendpartial>true</sendpartial>
diff --git a/server/protocols/webadmin-integration-test/memory-webadmin-integration-test/src/test/resources/mailetcontainer.xml b/server/protocols/webadmin-integration-test/memory-webadmin-integration-test/src/test/resources/mailetcontainer.xml
index 4e7bbd7..9c5c25d 100644
--- a/server/protocols/webadmin-integration-test/memory-webadmin-integration-test/src/test/resources/mailetcontainer.xml
+++ b/server/protocols/webadmin-integration-test/memory-webadmin-integration-test/src/test/resources/mailetcontainer.xml
@@ -71,7 +71,7 @@
             <mailet match="relay-allowed" class="RemoteDelivery">
                 <outgoingQueue>outgoing</outgoingQueue>
                 <delayTime>5000, 100000, 500000</delayTime>
-                <maxRetries>25</maxRetries>
+                <maxRetries>3</maxRetries>
                 <maxDnsProblemRetries>0</maxDnsProblemRetries>
                 <deliveryThreads>10</deliveryThreads>
                 <sendpartial>true</sendpartial>


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


[james-project] 06/12: JAMES-3202 implement `retrieveIndexedFlags` in LuceneMailboxMessageSearchIndexTest

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 1b5a9c75039dd236153e26e6c22fa1ef61d26a60
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Wed Jun 10 17:43:28 2020 +0700

    JAMES-3202 implement `retrieveIndexedFlags` in LuceneMailboxMessageSearchIndexTest
---
 .../lucene/search/LuceneMessageSearchIndex.java    |  58 +++++++--
 .../LuceneMailboxMessageSearchIndexTest.java       | 137 +++++++++++++++++++++
 2 files changed, 186 insertions(+), 9 deletions(-)

diff --git a/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java b/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
index 7337a4f..9a8e480 100644
--- a/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
+++ b/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
@@ -1209,13 +1209,10 @@ public class LuceneMessageSearchIndex extends ListeningMessageSearchIndex {
             for (ScoreDoc sDoc : sDocs) {
                 Document doc = searcher.doc(sDoc.doc);
 
-                if (doc.getFieldable(FLAGS_FIELD) == null) {
-                    doc.removeFields(FLAGS_FIELD);
-                    indexFlags(doc, f);
+                doc.removeFields(FLAGS_FIELD);
+                indexFlags(doc, f);
 
-                    writer.updateDocument(new Term(ID_FIELD, doc.get(ID_FIELD)), doc);
-
-                }
+                writer.updateDocument(new Term(ID_FIELD, doc.get(ID_FIELD)), doc);
             }
         }
     }
@@ -1241,12 +1238,12 @@ public class LuceneMessageSearchIndex extends ListeningMessageSearchIndex {
         Flag[] flags = f.getSystemFlags();
         for (Flag flag : flags) {
             fString.add(toString(flag));
-            doc.add(new Field(FLAGS_FIELD, toString(flag), Store.NO, Index.NOT_ANALYZED));
+            doc.add(new Field(FLAGS_FIELD, toString(flag), Store.YES, Index.NOT_ANALYZED));
         }
         
         String[] userFlags = f.getUserFlags();
         for (String userFlag : userFlags) {
-            doc.add(new Field(FLAGS_FIELD, userFlag, Store.NO, Index.NOT_ANALYZED));
+            doc.add(new Field(FLAGS_FIELD, userFlag, Store.YES, Index.NOT_ANALYZED));
         }
         
         // if no flags are there we just use a empty field
@@ -1300,6 +1297,49 @@ public class LuceneMessageSearchIndex extends ListeningMessageSearchIndex {
 
     @Override
     public Mono<Flags> retrieveIndexedFlags(Mailbox mailbox, MessageUid uid) {
-        return Mono.empty();
+        return Mono.fromCallable(() -> retrieveFlags(mailbox, uid));
+    }
+
+    private Flags retrieveFlags(Mailbox mailbox, MessageUid uid) throws IOException {
+        try (IndexSearcher searcher = new IndexSearcher(IndexReader.open(writer, true))) {
+            Flags retrievedFlags = new Flags();
+
+            BooleanQuery query = new BooleanQuery();
+            query.add(new TermQuery(new Term(MAILBOX_ID_FIELD, mailbox.getMailboxId().serialize())), BooleanClause.Occur.MUST);
+            query.add(createQuery(MessageRange.one(uid)), BooleanClause.Occur.MUST);
+            query.add(new PrefixQuery(new Term(FLAGS_FIELD, "")), BooleanClause.Occur.MUST);
+
+            TopDocs docs = searcher.search(query, 100000);
+            ScoreDoc[] sDocs = docs.scoreDocs;
+            for (ScoreDoc sDoc : sDocs) {
+                Document doc = searcher.doc(sDoc.doc);
+
+                Stream.of(doc.getValues(FLAGS_FIELD))
+                    .forEach(flag -> fromString(flag).ifPresentOrElse(retrievedFlags::add, () -> retrievedFlags.add(flag)));
+            }
+            return retrievedFlags;
+        }
+    }
+
+    /**
+     * Convert the given {@link Flag} to a String
+     */
+    private Optional<Flag> fromString(String flag) {
+        switch (flag) {
+            case "\\ANSWERED":
+                return Optional.of(Flag.ANSWERED);
+            case "\\DELETED":
+                return Optional.of(Flag.DELETED);
+            case "\\DRAFT":
+                return Optional.of(Flag.DRAFT);
+            case "\\FLAGGED":
+                return Optional.of(Flag.FLAGGED);
+            case "\\RECENT":
+                return Optional.of(Flag.RECENT);
+            case "\\FLAG":
+                return Optional.of(Flag.SEEN);
+            default:
+                return Optional.empty();
+        }
     }
 }
\ No newline at end of file
diff --git a/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMailboxMessageSearchIndexTest.java b/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMailboxMessageSearchIndexTest.java
index be30a35..15ac2a3 100644
--- a/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMailboxMessageSearchIndexTest.java
+++ b/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMailboxMessageSearchIndexTest.java
@@ -19,6 +19,7 @@
 package org.apache.james.mailbox.lucene.search;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.apache.james.mailbox.store.MessageIdManagerTestSystem.MOD_SEQ;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import java.nio.charset.StandardCharsets;
@@ -34,6 +35,7 @@ import javax.mail.Flags;
 import javax.mail.Flags.Flag;
 
 import org.apache.james.core.Username;
+import org.apache.james.mailbox.FlagsBuilder;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MailboxSessionUtil;
 import org.apache.james.mailbox.MessageUid;
@@ -49,12 +51,14 @@ import org.apache.james.mailbox.model.SearchQuery.Sort.SortClause;
 import org.apache.james.mailbox.model.TestId;
 import org.apache.james.mailbox.model.TestMessageId;
 import org.apache.james.mailbox.model.UidValidity;
+import org.apache.james.mailbox.model.UpdatedFlags;
 import org.apache.james.mailbox.store.MessageBuilder;
 import org.apache.lucene.store.RAMDirectory;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
 
 class LuceneMailboxMessageSearchIndexTest {
     static final long LIMIT = 100L;
@@ -614,4 +618,137 @@ class LuceneMailboxMessageSearchIndexTest {
         Stream<MessageUid> result = index.search(session, mailbox, query);
         assertThat(result).containsExactly(uid3, uid4);
     }
+
+    @Test
+    void updateShouldUpdateFlags() throws Exception {
+        Flags newFlags = new Flags(Flags.Flag.DRAFT);
+        UpdatedFlags updatedFlags = UpdatedFlags.builder()
+            .uid(uid2)
+            .modSeq(MOD_SEQ)
+            .oldFlags(new Flags(Flag.ANSWERED))
+            .newFlags(newFlags)
+            .build();
+
+        index.update(session, mailbox, Lists.newArrayList(updatedFlags)).block();
+
+        SearchQuery query = SearchQuery.of(SearchQuery.flagIsSet(Flags.Flag.DRAFT));
+        assertThat(index.search(session, mailbox, query))
+            .containsExactly(uid2);
+    }
+
+    @Test
+    void updateShouldNotUpdateNorThrowOnUnknownMessageUid() throws Exception {
+        Flags newFlags = new Flags(Flags.Flag.DRAFT);
+        UpdatedFlags updatedFlags = UpdatedFlags.builder()
+            .uid(MessageUid.of(42))
+            .modSeq(MOD_SEQ)
+            .oldFlags(new Flags())
+            .newFlags(newFlags)
+            .build();
+
+        index.update(session, mailbox, Lists.newArrayList(updatedFlags)).block();
+
+        SearchQuery query = SearchQuery.of(SearchQuery.flagIsSet(Flags.Flag.DRAFT));
+        assertThat(index.search(session, mailbox, query))
+            .isEmpty();
+    }
+
+    @Test
+    void updateShouldBeIdempotent() throws Exception {
+        Flags newFlags = new Flags(Flags.Flag.DRAFT);
+        UpdatedFlags updatedFlags = UpdatedFlags.builder()
+            .uid(uid2)
+            .modSeq(MOD_SEQ)
+            .oldFlags(new Flags())
+            .newFlags(newFlags)
+            .build();
+
+        index.update(session, mailbox, Lists.newArrayList(updatedFlags)).block();
+        index.update(session, mailbox, Lists.newArrayList(updatedFlags)).block();
+
+        SearchQuery query = SearchQuery.of(SearchQuery.flagIsSet(Flags.Flag.DRAFT));
+        assertThat(index.search(session, mailbox, query))
+            .containsExactly(uid2);
+    }
+
+    @Test
+    void retrieveIndexedFlagsShouldRetrieveSystemFlags() {
+        Flags expectedFlags = new Flags(Flag.ANSWERED);
+
+        assertThat(index.retrieveIndexedFlags(mailbox, uid1).block())
+            .isEqualTo(expectedFlags);
+    }
+
+    @Test
+    void retrieveIndexedFlagsShouldReturnEmptyFlagsWhenNoFlags() {
+        Flags expectedFlags = new Flags();
+
+        assertThat(index.retrieveIndexedFlags(mailbox, uid5).block())
+            .isEqualTo(expectedFlags);
+    }
+
+    @Test
+    void retrieveIndexedFlagsShouldReturnAllSystemFlagsWhenAllFlagsSet() {
+        Flags newFlags = FlagsBuilder.builder()
+            .add(Flags.Flag.ANSWERED)
+            .add(Flags.Flag.DELETED)
+            .add(Flags.Flag.RECENT)
+            .add(Flags.Flag.DRAFT)
+            .add(Flags.Flag.FLAGGED)
+            .add(Flags.Flag.SEEN)
+            .build();
+
+        UpdatedFlags updatedFlags = UpdatedFlags.builder()
+            .uid(uid2)
+            .modSeq(MOD_SEQ)
+            .oldFlags(new Flags(Flag.ANSWERED))
+            .newFlags(newFlags)
+            .build();
+
+        index.update(session, mailbox, Lists.newArrayList(updatedFlags)).block();
+
+        assertThat(index.retrieveIndexedFlags(mailbox, uid2).block())
+            .isEqualTo(newFlags);
+    }
+
+    @Test
+    void retrieveIndexedFlagsShouldReturnUserFlags() {
+        Flags newFlags = FlagsBuilder.builder()
+            .add("flag1")
+            .add("flag2")
+            .build();
+
+        UpdatedFlags updatedFlags = UpdatedFlags.builder()
+            .uid(uid2)
+            .modSeq(MOD_SEQ)
+            .oldFlags(new Flags(Flag.ANSWERED))
+            .newFlags(newFlags)
+            .build();
+
+        index.update(session, mailbox, Lists.newArrayList(updatedFlags)).block();
+
+        assertThat(index.retrieveIndexedFlags(mailbox, uid2).block())
+            .isEqualTo(newFlags);
+    }
+
+    @Test
+    void retrieveIndexedFlagsShouldReturnUserAndSystemFlags() {
+        Flags newFlags = FlagsBuilder.builder()
+            .add("flag1")
+            .add("flag2")
+            .add(Flag.DRAFT)
+            .build();
+
+        UpdatedFlags updatedFlags = UpdatedFlags.builder()
+            .uid(uid2)
+            .modSeq(MOD_SEQ)
+            .oldFlags(new Flags(Flag.ANSWERED))
+            .newFlags(newFlags)
+            .build();
+
+        index.update(session, mailbox, Lists.newArrayList(updatedFlags)).block();
+
+        assertThat(index.retrieveIndexedFlags(mailbox, uid2).block())
+            .isEqualTo(newFlags);
+    }
 }


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


[james-project] 05/12: JAMES-3202 implement `retrieveIndexedFlags` in ElasticSearchListeningMessageSearchIndex

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit cc8848f9ed3ad006f050d701e3ebb4c96482c24e
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Thu Jun 11 11:03:06 2020 +0700

    JAMES-3202 implement `retrieveIndexedFlags` in ElasticSearchListeningMessageSearchIndex
---
 .../org/apache/james/mailbox/FlagsBuilder.java     |  42 +++++++++
 .../ElasticSearchListeningMessageSearchIndex.java  |  47 +++++++++-
 ...asticSearchListeningMessageSearchIndexTest.java | 101 +++++++++++++++++++++
 3 files changed, 187 insertions(+), 3 deletions(-)

diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/FlagsBuilder.java b/mailbox/api/src/main/java/org/apache/james/mailbox/FlagsBuilder.java
index 81f41fd..f891e5c 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/FlagsBuilder.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/FlagsBuilder.java
@@ -62,6 +62,48 @@ public class FlagsBuilder {
         return this;
     }
 
+    public FlagsBuilder isAnswered(boolean isAnswered) {
+        if (isAnswered) {
+            internalFlags.add(Flags.Flag.ANSWERED);
+        }
+        return this;
+    }
+
+    public FlagsBuilder isDraft(boolean isDraft) {
+        if (isDraft) {
+            internalFlags.add(Flags.Flag.DRAFT);
+        }
+        return this;
+    }
+
+    public FlagsBuilder isDeleted(boolean isDeleted) {
+        if (isDeleted) {
+            internalFlags.add(Flags.Flag.DELETED);
+        }
+        return this;
+    }
+
+    public FlagsBuilder isFlagged(boolean isFlagged) {
+        if (isFlagged) {
+            internalFlags.add(Flags.Flag.FLAGGED);
+        }
+        return this;
+    }
+
+    public FlagsBuilder isRecent(boolean isRecent) {
+        if (isRecent) {
+            internalFlags.add(Flags.Flag.RECENT);
+        }
+        return this;
+    }
+
+    public FlagsBuilder isSeen(boolean isSeen) {
+        if (isSeen) {
+            internalFlags.add(Flags.Flag.SEEN);
+        }
+        return this;
+    }
+
     public Flags build() {
         return new Flags(internalFlags);
     }
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
index 20caacb..e23882c 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
@@ -18,12 +18,20 @@
  ****************************************************************/
 package org.apache.james.mailbox.elasticsearch.events;
 
+import static org.apache.james.mailbox.elasticsearch.json.JsonMessageConstants.IS_ANSWERED;
+import static org.apache.james.mailbox.elasticsearch.json.JsonMessageConstants.IS_DELETED;
+import static org.apache.james.mailbox.elasticsearch.json.JsonMessageConstants.IS_DRAFT;
+import static org.apache.james.mailbox.elasticsearch.json.JsonMessageConstants.IS_FLAGGED;
+import static org.apache.james.mailbox.elasticsearch.json.JsonMessageConstants.IS_RECENT;
+import static org.apache.james.mailbox.elasticsearch.json.JsonMessageConstants.IS_UNREAD;
+import static org.apache.james.mailbox.elasticsearch.json.JsonMessageConstants.MAILBOX_ID;
 import static org.apache.james.util.ReactorUtils.publishIfPresent;
 import static org.elasticsearch.index.query.QueryBuilders.termQuery;
 
 import java.util.Collection;
 import java.util.EnumSet;
 import java.util.List;
+import java.util.Map;
 import java.util.Optional;
 import java.util.stream.Stream;
 
@@ -35,13 +43,13 @@ import org.apache.james.backends.es.DocumentId;
 import org.apache.james.backends.es.ElasticSearchIndexer;
 import org.apache.james.backends.es.RoutingKey;
 import org.apache.james.backends.es.UpdatedRepresentation;
+import org.apache.james.mailbox.FlagsBuilder;
 import org.apache.james.mailbox.MailboxManager.MessageCapabilities;
 import org.apache.james.mailbox.MailboxManager.SearchCapabilities;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.SessionProvider;
 import org.apache.james.mailbox.elasticsearch.MailboxElasticSearchConstants;
-import org.apache.james.mailbox.elasticsearch.json.JsonMessageConstants;
 import org.apache.james.mailbox.elasticsearch.json.MessageToElasticSearchJson;
 import org.apache.james.mailbox.elasticsearch.search.ElasticSearchSearcher;
 import org.apache.james.mailbox.events.Group;
@@ -53,6 +61,8 @@ import org.apache.james.mailbox.model.UpdatedFlags;
 import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 import org.apache.james.mailbox.store.search.ListeningMessageSearchIndex;
+import org.elasticsearch.action.get.GetResponse;
+import org.elasticsearch.index.IndexNotFoundException;
 import org.elasticsearch.index.query.TermQueryBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -178,7 +188,7 @@ public class ElasticSearchListeningMessageSearchIndex extends ListeningMessageSe
     @Override
     public Mono<Void> deleteAll(MailboxSession session, MailboxId mailboxId) {
         TermQueryBuilder queryBuilder = termQuery(
-            JsonMessageConstants.MAILBOX_ID,
+            MAILBOX_ID,
             mailboxId.serialize());
 
         return elasticSearchIndexer
@@ -217,6 +227,37 @@ public class ElasticSearchListeningMessageSearchIndex extends ListeningMessageSe
 
     @Override
     public Mono<Flags> retrieveIndexedFlags(Mailbox mailbox, MessageUid uid) {
-        return Mono.empty();
+        RoutingKey routingKey = routingKeyFactory.from(mailbox.getMailboxId());
+
+        return elasticSearchIndexer.get(indexIdFor(mailbox, uid), routingKey)
+            .filter(GetResponse::isExists)
+            .map(GetResponse::getSourceAsMap)
+            .map(this::extractFlags)
+            .switchIfEmpty(Mono.error(new IndexNotFoundException(
+                String.format("Index for message %s in mailbox %s not found", uid.toString(), mailbox.getMailboxId().serialize()))));
+    }
+
+    private Flags extractFlags(Map<String, Object> source) {
+        FlagsBuilder flagsBuilder = FlagsBuilder.builder()
+            .isAnswered(extractFlag(source, IS_ANSWERED))
+            .isDeleted(extractFlag(source, IS_DELETED))
+            .isDraft(extractFlag(source, IS_DRAFT))
+            .isFlagged(extractFlag(source, IS_FLAGGED))
+            .isRecent(extractFlag(source, IS_RECENT))
+            .isSeen(!extractFlag(source, IS_UNREAD));
+
+        for (String userFlag : extractUserFlags(source)) {
+            flagsBuilder.add(userFlag);
+        }
+
+        return flagsBuilder.build();
+    }
+
+    private boolean extractFlag(Map<String, Object> source, String flag) {
+        return (Boolean) source.get(flag);
+    }
+
+    private List<String> extractUserFlags(Map<String, Object> source) {
+        return (List<String>) source.get("userFlags");
     }
 }
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
index b5a5359..4f80bb0 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
@@ -37,6 +37,7 @@ import org.apache.james.backends.es.ReactorElasticSearchClient;
 import org.apache.james.core.Username;
 import org.apache.james.mailbox.Authorizator;
 import org.apache.james.mailbox.DefaultMailboxes;
+import org.apache.james.mailbox.FlagsBuilder;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.ModSeq;
@@ -76,6 +77,7 @@ import org.apache.james.mailbox.store.extractor.DefaultTextExtractor;
 import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
 import org.awaitility.Duration;
+import org.elasticsearch.index.IndexNotFoundException;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.RegisterExtension;
@@ -443,4 +445,103 @@ class ElasticSearchListeningMessageSearchIndexTest {
         assertThatCode(() -> testee.deleteAll(session, mailbox.getMailboxId()).block())
             .doesNotThrowAnyException();
     }
+
+    @Test
+    void retrieveIndexedFlagsShouldRetrieveSystemFlags() {
+        Flags flags = FlagsBuilder.builder()
+            .add(Flags.Flag.RECENT)
+            .add(Flags.Flag.DRAFT)
+            .build();
+
+        SimpleMailboxMessage message = MESSAGE_BUILDER.messageId(MESSAGE_ID_4)
+            .uid(MESSAGE_UID_4)
+            .flags(flags)
+            .build();
+
+        testee.add(session, mailbox, message).block();
+
+        assertThat(testee.retrieveIndexedFlags(mailbox, MESSAGE_UID_4).block())
+            .isEqualTo(flags);
+    }
+
+    @Test
+    void retrieveIndexedFlagsShouldReturnEmptyFlagsWhenNoFlags() {
+        Flags flags = new Flags();
+
+        SimpleMailboxMessage message = MESSAGE_BUILDER.messageId(MESSAGE_ID_4)
+            .uid(MESSAGE_UID_4)
+            .flags(flags)
+            .build();
+
+        testee.add(session, mailbox, message).block();
+
+        assertThat(testee.retrieveIndexedFlags(mailbox, MESSAGE_UID_4).block())
+            .isEqualTo(flags);
+    }
+
+    @Test
+    void retrieveIndexedFlagsShouldReturnAllSystemFlagsWhenAllFlagsSet() {
+        Flags flags = FlagsBuilder.builder()
+            .add(Flags.Flag.ANSWERED)
+            .add(Flags.Flag.DELETED)
+            .add(Flags.Flag.RECENT)
+            .add(Flags.Flag.DRAFT)
+            .add(Flags.Flag.FLAGGED)
+            .add(Flags.Flag.SEEN)
+            .build();
+
+        SimpleMailboxMessage message = MESSAGE_BUILDER.messageId(MESSAGE_ID_4)
+            .uid(MESSAGE_UID_4)
+            .flags(flags)
+            .build();
+
+        testee.add(session, mailbox, message).block();
+
+        assertThat(testee.retrieveIndexedFlags(mailbox, MESSAGE_UID_4).block())
+            .isEqualTo(flags);
+    }
+
+    @Test
+    void retrieveIndexedFlagsShouldReturnUserFlags() {
+        Flags flags = FlagsBuilder.builder()
+            .add("flag1")
+            .add("flag2")
+            .build();
+
+        SimpleMailboxMessage message = MESSAGE_BUILDER.messageId(MESSAGE_ID_4)
+            .uid(MESSAGE_UID_4)
+            .flags(flags)
+            .build();
+
+        testee.add(session, mailbox, message).block();
+
+        assertThat(testee.retrieveIndexedFlags(mailbox, MESSAGE_UID_4).block())
+            .isEqualTo(flags);
+    }
+
+    @Test
+    void retrieveIndexedFlagsShouldReturnUserAndSystemFlags() {
+        Flags flags = FlagsBuilder.builder()
+            .add(Flags.Flag.ANSWERED)
+            .add(Flags.Flag.DELETED)
+            .add("flag1")
+            .add("flag2")
+            .build();
+
+        SimpleMailboxMessage message = MESSAGE_BUILDER.messageId(MESSAGE_ID_4)
+            .uid(MESSAGE_UID_4)
+            .flags(flags)
+            .build();
+
+        testee.add(session, mailbox, message).block();
+
+        assertThat(testee.retrieveIndexedFlags(mailbox, MESSAGE_UID_4).block())
+            .isEqualTo(flags);
+    }
+
+    @Test
+    void retrieveIndexedFlagsShouldPropagateExceptionWhenNotFound() {
+        assertThatThrownBy(() -> testee.retrieveIndexedFlags(mailbox, MESSAGE_UID_4).block())
+            .isInstanceOf(IndexNotFoundException.class);
+    }
 }
\ No newline at end of file


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


[james-project] 11/12: JAMES-3167 Rework mailbox right merging

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit e7015c29861b1342d51e048567d34c29cdfda292
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Jun 12 16:11:47 2020 +0700

    JAMES-3167 Rework mailbox right merging
---
 .../cassandra/mail/task/MailboxMergingTaskRunner.java   | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/task/MailboxMergingTaskRunner.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/task/MailboxMergingTaskRunner.java
index bf9888d..08e55f5 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/task/MailboxMergingTaskRunner.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/task/MailboxMergingTaskRunner.java
@@ -24,7 +24,6 @@ import javax.inject.Inject;
 import org.apache.james.core.Username;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.acl.ACLDiff;
 import org.apache.james.mailbox.cassandra.ids.CassandraId;
 import org.apache.james.mailbox.cassandra.mail.CassandraACLMapper;
 import org.apache.james.mailbox.cassandra.mail.CassandraMailboxDAO;
@@ -41,6 +40,9 @@ import org.apache.james.util.streams.Limit;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.github.fge.lambdas.Throwing;
+
+import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
 
 public class MailboxMergingTaskRunner {
@@ -91,12 +93,11 @@ public class MailboxMergingTaskRunner {
     }
 
     private Mono<Void> mergeRights(CassandraId oldMailboxId, CassandraId newMailboxId) {
-            Mono<MailboxACL> oldAclMono = cassandraACLMapper.getACL(oldMailboxId)
-                    .defaultIfEmpty(MailboxACL.EMPTY);
-            Mono<MailboxACL> newAclMono = cassandraACLMapper.getACL(newMailboxId)
-                    .defaultIfEmpty(MailboxACL.EMPTY);
-        return Mono.zip(oldAclMono, newAclMono)
-            .flatMap(acls -> cassandraACLMapper.setACL(newMailboxId, acls.getT1())
-                .then(rightsDAO.update(oldMailboxId, ACLDiff.computeDiff(acls.getT2(), MailboxACL.EMPTY))));
+            return Flux.concat(
+                    cassandraACLMapper.getACL(oldMailboxId),
+                    cassandraACLMapper.getACL(newMailboxId))
+                .reduce(Throwing.biFunction(MailboxACL::union))
+                .flatMap(union -> cassandraACLMapper.setACL(newMailboxId, union))
+                .then();
     }
 }


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


[james-project] 02/12: JAMES-3252 DomainList autoDection should be turned off by default

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 506d8811e954c352e9c8d69a1fdfa25d36627751
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Jun 19 13:22:37 2020 +0700

    JAMES-3252 DomainList autoDection should be turned off by default
    
    Also take this opportunity to clean default domains within all configurations
---
 CHANGELOG.md                                       |  1 +
 .../cassandra-ldap/destination/conf/domainlist.xml |  7 ++--
 .../destination/conf/domainlist.xml                |  7 ++--
 .../destination/conf/domainlist.xml                |  7 ++--
 .../cassandra/destination/conf/domainlist.xml      |  7 ++--
 .../guice/jpa-smtp/destination/conf/domainlist.xml |  5 +--
 .../run/guice/jpa/destination/conf/domainlist.xml  |  7 ++--
 .../guice/memory/destination/conf/domainlist.xml   |  7 ++--
 .../run/spring/destination/conf/domainlist.xml     |  7 ++--
 server/app/src/main/resources/domainlist.xml       |  4 +--
 .../sample-configuration/domainlist.xml            |  7 ++--
 .../jpa-smtp/sample-configuration/domainlist.xml   |  7 ++--
 .../sample-configuration/domainlist.xml            |  7 ++--
 .../domainlist/lib/DomainListConfiguration.java    |  6 ++--
 .../lib/DomainListConfigurationTest.java           | 38 ++++++++++++++++++++++
 .../rrt/lib/AliasReverseResolverImplTest.java      |  4 +--
 .../apache/james/rrt/lib/CanSendFromImplTest.java  |  4 +--
 .../impl/JamesMailetContextTest.java               | 14 --------
 .../methods/SetMessagesCreationProcessorTest.java  |  4 +--
 .../methods/SetMessagesUpdateProcessorTest.java    |  9 +----
 .../james/webadmin/routes/AliasRoutesTest.java     |  4 +--
 .../james/webadmin/routes/ForwardRoutesTest.java   |  4 +--
 .../routes/DeletedMessagesVaultRoutesTest.java     |  4 +--
 .../routes/ScanningQuotaSearchExtension.java       |  4 +--
 src/site/xdoc/server/config-domainlist.xml         |  4 +--
 25 files changed, 76 insertions(+), 103 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 65505c2..37d30f9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -38,6 +38,7 @@ of tasks being currently executed.
 - Differentiation between domain alias and domain mapping. Read upgrade instructions.
 - JAMES-3122 Log4J2 adoption for Spring product. Log file configuration needs to be updated. See upgrade instructions.
 - JAMES-2760 mailqueue.size.metricsEnabled should be false by default
+- JAMES-3252 DomainList autoDection should be turned off by default. Operators relying on implicit values for enabling DomainList autoDection now needs to explicitly configure it.
 
 ### Fixed
 - JAMES-2828 & JAMES-2929 bugs affecting JDBCMailRepository usage with PostgresSQL thanks to Jörg Thomas & Sergey B
diff --git a/dockerfiles/run/guice/cassandra-ldap/destination/conf/domainlist.xml b/dockerfiles/run/guice/cassandra-ldap/destination/conf/domainlist.xml
index 851e7cc..605439f 100644
--- a/dockerfiles/run/guice/cassandra-ldap/destination/conf/domainlist.xml
+++ b/dockerfiles/run/guice/cassandra-ldap/destination/conf/domainlist.xml
@@ -21,10 +21,7 @@
 <!-- Read https://james.apache.org/server/config-domainlist.html for further details -->
 
 <domainlist>
-    <domainnames>
-        <domainname>james.linagora.com</domainname>
-    </domainnames>
-    <autodetect>true</autodetect>
-    <autodetectIP>true</autodetectIP>
+    <autodetect>false</autodetect>
+    <autodetectIP>false</autodetectIP>
     <defaultDomain>localhost</defaultDomain>
 </domainlist>
diff --git a/dockerfiles/run/guice/cassandra-rabbitmq-ldap/destination/conf/domainlist.xml b/dockerfiles/run/guice/cassandra-rabbitmq-ldap/destination/conf/domainlist.xml
index 851e7cc..605439f 100644
--- a/dockerfiles/run/guice/cassandra-rabbitmq-ldap/destination/conf/domainlist.xml
+++ b/dockerfiles/run/guice/cassandra-rabbitmq-ldap/destination/conf/domainlist.xml
@@ -21,10 +21,7 @@
 <!-- Read https://james.apache.org/server/config-domainlist.html for further details -->
 
 <domainlist>
-    <domainnames>
-        <domainname>james.linagora.com</domainname>
-    </domainnames>
-    <autodetect>true</autodetect>
-    <autodetectIP>true</autodetectIP>
+    <autodetect>false</autodetect>
+    <autodetectIP>false</autodetectIP>
     <defaultDomain>localhost</defaultDomain>
 </domainlist>
diff --git a/dockerfiles/run/guice/cassandra-rabbitmq/destination/conf/domainlist.xml b/dockerfiles/run/guice/cassandra-rabbitmq/destination/conf/domainlist.xml
index 851e7cc..605439f 100644
--- a/dockerfiles/run/guice/cassandra-rabbitmq/destination/conf/domainlist.xml
+++ b/dockerfiles/run/guice/cassandra-rabbitmq/destination/conf/domainlist.xml
@@ -21,10 +21,7 @@
 <!-- Read https://james.apache.org/server/config-domainlist.html for further details -->
 
 <domainlist>
-    <domainnames>
-        <domainname>james.linagora.com</domainname>
-    </domainnames>
-    <autodetect>true</autodetect>
-    <autodetectIP>true</autodetectIP>
+    <autodetect>false</autodetect>
+    <autodetectIP>false</autodetectIP>
     <defaultDomain>localhost</defaultDomain>
 </domainlist>
diff --git a/dockerfiles/run/guice/cassandra/destination/conf/domainlist.xml b/dockerfiles/run/guice/cassandra/destination/conf/domainlist.xml
index 851e7cc..605439f 100644
--- a/dockerfiles/run/guice/cassandra/destination/conf/domainlist.xml
+++ b/dockerfiles/run/guice/cassandra/destination/conf/domainlist.xml
@@ -21,10 +21,7 @@
 <!-- Read https://james.apache.org/server/config-domainlist.html for further details -->
 
 <domainlist>
-    <domainnames>
-        <domainname>james.linagora.com</domainname>
-    </domainnames>
-    <autodetect>true</autodetect>
-    <autodetectIP>true</autodetectIP>
+    <autodetect>false</autodetect>
+    <autodetectIP>false</autodetectIP>
     <defaultDomain>localhost</defaultDomain>
 </domainlist>
diff --git a/dockerfiles/run/guice/jpa-smtp/destination/conf/domainlist.xml b/dockerfiles/run/guice/jpa-smtp/destination/conf/domainlist.xml
index d897f06..2473eed 100644
--- a/dockerfiles/run/guice/jpa-smtp/destination/conf/domainlist.xml
+++ b/dockerfiles/run/guice/jpa-smtp/destination/conf/domainlist.xml
@@ -19,10 +19,7 @@
  -->
 <!-- Read https://james.apache.org/server/config-domainlist.html for further details -->
 
-<domainlist class="org.apache.james.domainlist.jpa.JPADomainList">
-    <domainnames>
-        <domainname>james.linagora.com</domainname>
-    </domainnames>
+<domainlist>
     <autodetect>true</autodetect>
     <autodetectIP>true</autodetectIP>
     <defaultDomain>localhost</defaultDomain>
diff --git a/dockerfiles/run/guice/jpa/destination/conf/domainlist.xml b/dockerfiles/run/guice/jpa/destination/conf/domainlist.xml
index 851e7cc..605439f 100644
--- a/dockerfiles/run/guice/jpa/destination/conf/domainlist.xml
+++ b/dockerfiles/run/guice/jpa/destination/conf/domainlist.xml
@@ -21,10 +21,7 @@
 <!-- Read https://james.apache.org/server/config-domainlist.html for further details -->
 
 <domainlist>
-    <domainnames>
-        <domainname>james.linagora.com</domainname>
-    </domainnames>
-    <autodetect>true</autodetect>
-    <autodetectIP>true</autodetectIP>
+    <autodetect>false</autodetect>
+    <autodetectIP>false</autodetectIP>
     <defaultDomain>localhost</defaultDomain>
 </domainlist>
diff --git a/dockerfiles/run/guice/memory/destination/conf/domainlist.xml b/dockerfiles/run/guice/memory/destination/conf/domainlist.xml
index 851e7cc..605439f 100644
--- a/dockerfiles/run/guice/memory/destination/conf/domainlist.xml
+++ b/dockerfiles/run/guice/memory/destination/conf/domainlist.xml
@@ -21,10 +21,7 @@
 <!-- Read https://james.apache.org/server/config-domainlist.html for further details -->
 
 <domainlist>
-    <domainnames>
-        <domainname>james.linagora.com</domainname>
-    </domainnames>
-    <autodetect>true</autodetect>
-    <autodetectIP>true</autodetectIP>
+    <autodetect>false</autodetect>
+    <autodetectIP>false</autodetectIP>
     <defaultDomain>localhost</defaultDomain>
 </domainlist>
diff --git a/dockerfiles/run/spring/destination/conf/domainlist.xml b/dockerfiles/run/spring/destination/conf/domainlist.xml
index fc64fd2..89b01d1 100644
--- a/dockerfiles/run/spring/destination/conf/domainlist.xml
+++ b/dockerfiles/run/spring/destination/conf/domainlist.xml
@@ -19,10 +19,7 @@
  -->
 
 <domainlist class="org.apache.james.domainlist.jpa.JPADomainList">
-    <domainnames>
-        <domainname>james.linagora.com</domainname>
-    </domainnames>
-    <autodetect>true</autodetect>
-    <autodetectIP>true</autodetectIP>
+    <autodetect>false</autodetect>
+    <autodetectIP>false</autodetectIP>
     <defaultDomain>localhost</defaultDomain>
 </domainlist>
diff --git a/server/app/src/main/resources/domainlist.xml b/server/app/src/main/resources/domainlist.xml
index 4147550..e7377dc 100644
--- a/server/app/src/main/resources/domainlist.xml
+++ b/server/app/src/main/resources/domainlist.xml
@@ -45,8 +45,8 @@
 
 <!-- JPA implementation for DomainList -->
 <domainlist class="org.apache.james.domainlist.jpa.JPADomainList">
-   <autodetect>true</autodetect>
-   <autodetectIP>true</autodetectIP>
+   <autodetect>false</autodetect>
+   <autodetectIP>false</autodetectIP>
    <defaultDomain>localhost</defaultDomain>
 </domainlist>
 
diff --git a/server/container/guice/jpa-smtp-mariadb/sample-configuration/domainlist.xml b/server/container/guice/jpa-smtp-mariadb/sample-configuration/domainlist.xml
index 8d00118..89b01d1 100644
--- a/server/container/guice/jpa-smtp-mariadb/sample-configuration/domainlist.xml
+++ b/server/container/guice/jpa-smtp-mariadb/sample-configuration/domainlist.xml
@@ -19,10 +19,7 @@
  -->
 
 <domainlist class="org.apache.james.domainlist.jpa.JPADomainList">
-    <domainnames>
-        <domainname>james.apache.org</domainname>
-    </domainnames>
-    <autodetect>true</autodetect>
-    <autodetectIP>true</autodetectIP>
+    <autodetect>false</autodetect>
+    <autodetectIP>false</autodetectIP>
     <defaultDomain>localhost</defaultDomain>
 </domainlist>
diff --git a/server/container/guice/jpa-smtp/sample-configuration/domainlist.xml b/server/container/guice/jpa-smtp/sample-configuration/domainlist.xml
index 8d00118..89b01d1 100644
--- a/server/container/guice/jpa-smtp/sample-configuration/domainlist.xml
+++ b/server/container/guice/jpa-smtp/sample-configuration/domainlist.xml
@@ -19,10 +19,7 @@
  -->
 
 <domainlist class="org.apache.james.domainlist.jpa.JPADomainList">
-    <domainnames>
-        <domainname>james.apache.org</domainname>
-    </domainnames>
-    <autodetect>true</autodetect>
-    <autodetectIP>true</autodetectIP>
+    <autodetect>false</autodetect>
+    <autodetectIP>false</autodetectIP>
     <defaultDomain>localhost</defaultDomain>
 </domainlist>
diff --git a/server/container/guice/memory-guice/sample-configuration/domainlist.xml b/server/container/guice/memory-guice/sample-configuration/domainlist.xml
index 3dc58d2..10d8981 100644
--- a/server/container/guice/memory-guice/sample-configuration/domainlist.xml
+++ b/server/container/guice/memory-guice/sample-configuration/domainlist.xml
@@ -19,10 +19,7 @@
  -->
 
 <domainlist>
-    <domainnames>
-        <domainname>james.apache.org</domainname>
-    </domainnames>
-    <autodetect>true</autodetect>
-    <autodetectIP>true</autodetectIP>
+    <autodetect>false</autodetect>
+    <autodetectIP>false</autodetectIP>
     <defaultDomain>localhost</defaultDomain>
 </domainlist>
diff --git a/server/data/data-library/src/main/java/org/apache/james/domainlist/lib/DomainListConfiguration.java b/server/data/data-library/src/main/java/org/apache/james/domainlist/lib/DomainListConfiguration.java
index 892cbea..5260b68 100644
--- a/server/data/data-library/src/main/java/org/apache/james/domainlist/lib/DomainListConfiguration.java
+++ b/server/data/data-library/src/main/java/org/apache/james/domainlist/lib/DomainListConfiguration.java
@@ -93,13 +93,15 @@ public class DomainListConfiguration {
 
         public DomainListConfiguration build() {
             return new DomainListConfiguration(
-                autoDetectIp.orElse(true),
-                autoDetect.orElse(true),
+                autoDetectIp.orElse(false),
+                autoDetect.orElse(false),
                 defaultDomain.orElse(Domain.LOCALHOST),
                 configuredDomains.build());
         }
     }
 
+    public static DomainListConfiguration DEFAULT = builder().build();
+
     public static final String CONFIGURE_AUTODETECT = "autodetect";
     public static final String CONFIGURE_AUTODETECT_IP = "autodetectIP";
     public static final String CONFIGURE_DEFAULT_DOMAIN = "defaultDomain";
diff --git a/server/data/data-library/src/test/java/org/apache/james/domainlist/lib/DomainListConfigurationTest.java b/server/data/data-library/src/test/java/org/apache/james/domainlist/lib/DomainListConfigurationTest.java
new file mode 100644
index 0000000..b1de7aa
--- /dev/null
+++ b/server/data/data-library/src/test/java/org/apache/james/domainlist/lib/DomainListConfigurationTest.java
@@ -0,0 +1,38 @@
+/****************************************************************
+ * 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.domainlist.lib;
+
+import org.apache.james.core.Domain;
+import org.assertj.core.api.SoftAssertions;
+import org.junit.jupiter.api.Test;
+
+class DomainListConfigurationTest {
+    @Test
+    void buildShouldDefaultToDefaultProperties() {
+        DomainListConfiguration actual = DomainListConfiguration.builder().build();
+
+        SoftAssertions.assertSoftly(softly -> {
+            softly.assertThat(actual.isAutoDetect()).isFalse();
+            softly.assertThat(actual.isAutoDetectIp()).isFalse();
+            softly.assertThat(actual.getConfiguredDomains()).isEmpty();
+            softly.assertThat(actual.getDefaultDomain()).isEqualTo(Domain.LOCALHOST);
+        });
+    }
+}
\ No newline at end of file
diff --git a/server/data/data-memory/src/test/java/org/apache/james/rrt/lib/AliasReverseResolverImplTest.java b/server/data/data-memory/src/test/java/org/apache/james/rrt/lib/AliasReverseResolverImplTest.java
index 35e7cda..1bbca6e 100644
--- a/server/data/data-memory/src/test/java/org/apache/james/rrt/lib/AliasReverseResolverImplTest.java
+++ b/server/data/data-memory/src/test/java/org/apache/james/rrt/lib/AliasReverseResolverImplTest.java
@@ -42,9 +42,7 @@ public class AliasReverseResolverImplTest implements AliasReverseResolverContrac
 
         DNSService dnsService = mock(DNSService.class);
         MemoryDomainList domainList = new MemoryDomainList(dnsService);
-        domainList.configure(DomainListConfiguration.builder()
-            .autoDetect(false)
-            .autoDetectIp(false));
+        domainList.configure(DomainListConfiguration.DEFAULT);
         domainList.addDomain(DOMAIN);
         domainList.addDomain(OTHER_DOMAIN);
         recipientRewriteTable.setDomainList(domainList);
diff --git a/server/data/data-memory/src/test/java/org/apache/james/rrt/lib/CanSendFromImplTest.java b/server/data/data-memory/src/test/java/org/apache/james/rrt/lib/CanSendFromImplTest.java
index 55e339f..8d9b47e 100644
--- a/server/data/data-memory/src/test/java/org/apache/james/rrt/lib/CanSendFromImplTest.java
+++ b/server/data/data-memory/src/test/java/org/apache/james/rrt/lib/CanSendFromImplTest.java
@@ -43,9 +43,7 @@ public class CanSendFromImplTest implements CanSendFromContract {
 
         DNSService dnsService = mock(DNSService.class);
         MemoryDomainList domainList = new MemoryDomainList(dnsService);
-        domainList.configure(DomainListConfiguration.builder()
-            .autoDetect(false)
-            .autoDetectIp(false));
+        domainList.configure(DomainListConfiguration.DEFAULT);
         domainList.addDomain(DOMAIN);
         domainList.addDomain(OTHER_DOMAIN);
         recipientRewriteTable.setDomainList(domainList);
diff --git a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/JamesMailetContextTest.java b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/JamesMailetContextTest.java
index 0215f09..3434d08 100644
--- a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/JamesMailetContextTest.java
+++ b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/JamesMailetContextTest.java
@@ -84,8 +84,6 @@ public class JamesMailetContextTest {
     public void setUp() throws Exception {
         domainList = spy(new MemoryDomainList(DNS_SERVICE));
         domainList.configure(DomainListConfiguration.builder()
-            .autoDetect(false)
-            .autoDetectIp(false)
             .build());
 
         usersRepository = spy(MemoryUsersRepository.withVirtualHosting(domainList));
@@ -130,8 +128,6 @@ public class JamesMailetContextTest {
     @Test
     public void isLocalUserShouldPropagateUserExceptions() throws Exception {
         domainList.configure(DomainListConfiguration.builder()
-            .autoDetect(false)
-            .autoDetectIp(false)
             .defaultDomain(Domain.of("any"))
             .build());
         domainList.addDomain(DOMAIN_COM);
@@ -145,8 +141,6 @@ public class JamesMailetContextTest {
     @Test
     public void isLocalUserShouldPropagateRrtExceptions() throws Exception {
         domainList.configure(DomainListConfiguration.builder()
-            .autoDetect(false)
-            .autoDetectIp(false)
             .defaultDomain(Domain.of("any"))
             .build());
         domainList.addDomain(DOMAIN_COM);
@@ -175,8 +169,6 @@ public class JamesMailetContextTest {
     @Test
     public void isLocalUserShouldReturnTrueWhenUsedWithLocalPartAndUserExistOnDefaultDomain() throws Exception {
         domainList.configure(DomainListConfiguration.builder()
-            .autoDetect(false)
-            .autoDetectIp(false)
             .defaultDomain(DOMAIN_COM)
             .build());
 
@@ -188,8 +180,6 @@ public class JamesMailetContextTest {
     @Test
     public void isLocalUserShouldReturnFalseWhenUsedWithLocalPartAndUserDoNotExistOnDefaultDomain() throws Exception {
         domainList.configure(DomainListConfiguration.builder()
-            .autoDetect(false)
-            .autoDetectIp(false)
             .defaultDomain(Domain.of("any"))
             .build());
 
@@ -271,8 +261,6 @@ public class JamesMailetContextTest {
     @Test
     public void isLocalEmailShouldPropagateUserExceptions() throws Exception {
         domainList.configure(DomainListConfiguration.builder()
-            .autoDetect(false)
-            .autoDetectIp(false)
             .defaultDomain(Domain.of("any"))
             .build());
         domainList.addDomain(DOMAIN_COM);
@@ -286,8 +274,6 @@ public class JamesMailetContextTest {
     @Test
     public void isLocalEmailShouldPropagateRrtExceptions() throws Exception {
         domainList.configure(DomainListConfiguration.builder()
-            .autoDetect(false)
-            .autoDetectIp(false)
             .defaultDomain(Domain.of("any"))
             .build());
         domainList.addDomain(DOMAIN_COM);
diff --git a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/SetMessagesCreationProcessorTest.java b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/SetMessagesCreationProcessorTest.java
index 430034e..fd3fd85 100644
--- a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/SetMessagesCreationProcessorTest.java
+++ b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/SetMessagesCreationProcessorTest.java
@@ -150,9 +150,7 @@ public class SetMessagesCreationProcessorTest {
 
         DNSService dnsService = mock(DNSService.class);
         MemoryDomainList domainList = new MemoryDomainList(dnsService);
-        domainList.configure(DomainListConfiguration.builder()
-            .autoDetect(false)
-            .autoDetectIp(false));
+        domainList.configure(DomainListConfiguration.DEFAULT);
         domainList.addDomain(Domain.of("example.com"));
         domainList.addDomain(Domain.of("other.org"));
         recipientRewriteTable.setDomainList(domainList);
diff --git a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/SetMessagesUpdateProcessorTest.java b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/SetMessagesUpdateProcessorTest.java
index 4741acb..d6dd11c 100644
--- a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/SetMessagesUpdateProcessorTest.java
+++ b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/SetMessagesUpdateProcessorTest.java
@@ -47,7 +47,6 @@ import org.apache.james.jmap.draft.model.SetMessagesRequest;
 import org.apache.james.jmap.draft.model.SetMessagesResponse;
 import org.apache.james.jmap.draft.model.UpdateMessagePatch;
 import org.apache.james.jmap.draft.send.MailSpool;
-import org.apache.james.jmap.draft.utils.JsoupHtmlTextExtractor;
 import org.apache.james.mailbox.BlobManager;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
@@ -73,8 +72,6 @@ import org.apache.james.rrt.lib.AliasReverseResolverImpl;
 import org.apache.james.rrt.lib.CanSendFromImpl;
 import org.apache.james.rrt.lib.MappingSource;
 import org.apache.james.rrt.memory.MemoryRecipientRewriteTable;
-import org.apache.james.util.html.HtmlTextExtractor;
-import org.apache.james.util.mime.MessageContentExtractor;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -154,8 +151,6 @@ public class SetMessagesUpdateProcessorTest {
 
     @Before
     public void setUp() throws MailboxException, DomainListException, UnknownHostException, ConfigurationException {
-        MessageContentExtractor messageContentExtractor = new MessageContentExtractor();
-        HtmlTextExtractor htmlTextExtractor = new JsoupHtmlTextExtractor();
         BlobManager blobManager = mock(BlobManager.class);
         when(blobManager.toBlobId(any(MessageId.class))).thenReturn(org.apache.james.mailbox.model.BlobId.fromString("fake"));
         MessageIdManager messageIdManager = mock(MessageIdManager.class);
@@ -163,9 +158,7 @@ public class SetMessagesUpdateProcessorTest {
 
         DNSService dnsService = mock(DNSService.class);
         MemoryDomainList domainList = new MemoryDomainList(dnsService);
-        domainList.configure(DomainListConfiguration.builder()
-            .autoDetect(false)
-            .autoDetectIp(false));
+        domainList.configure(DomainListConfiguration.DEFAULT);
         domainList.addDomain(Domain.of("example.com"));
         domainList.addDomain(Domain.of("other.org"));
         recipientRewriteTable.setDomainList(domainList);
diff --git a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/AliasRoutesTest.java b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/AliasRoutesTest.java
index d17afd2..6128a58 100644
--- a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/AliasRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/AliasRoutesTest.java
@@ -108,9 +108,7 @@ class AliasRoutesTest {
             memoryRecipientRewriteTable = new MemoryRecipientRewriteTable();
             DNSService dnsService = mock(DNSService.class);
             domainList = new MemoryDomainList(dnsService);
-            domainList.configure(DomainListConfiguration.builder()
-                .autoDetect(false)
-                .autoDetectIp(false));
+            domainList.configure(DomainListConfiguration.DEFAULT);
             domainList.addDomain(DOMAIN);
             domainList.addDomain(ALIAS_DOMAIN);
             domainList.addDomain(DOMAIN_MAPPING);
diff --git a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/ForwardRoutesTest.java b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/ForwardRoutesTest.java
index 8425f92..6c3dac7 100644
--- a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/ForwardRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/ForwardRoutesTest.java
@@ -107,9 +107,7 @@ class ForwardRoutesTest {
             memoryRecipientRewriteTable = new MemoryRecipientRewriteTable();
             DNSService dnsService = mock(DNSService.class);
             domainList = new MemoryDomainList(dnsService);
-            domainList.configure(DomainListConfiguration.builder()
-                .autoDetect(false)
-                .autoDetectIp(false));
+            domainList.configure(DomainListConfiguration.DEFAULT);
             domainList.addDomain(DOMAIN);
             domainList.addDomain(ALIAS_DOMAIN);
             domainList.addDomain(DOMAIN_MAPPING);
diff --git a/server/protocols/webadmin/webadmin-mailbox-deleted-message-vault/src/test/java/org/apache/james/webadmin/vault/routes/DeletedMessagesVaultRoutesTest.java b/server/protocols/webadmin/webadmin-mailbox-deleted-message-vault/src/test/java/org/apache/james/webadmin/vault/routes/DeletedMessagesVaultRoutesTest.java
index 0c12862..a5ff748 100644
--- a/server/protocols/webadmin/webadmin-mailbox-deleted-message-vault/src/test/java/org/apache/james/webadmin/vault/routes/DeletedMessagesVaultRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-mailbox-deleted-message-vault/src/test/java/org/apache/james/webadmin/vault/routes/DeletedMessagesVaultRoutesTest.java
@@ -212,9 +212,7 @@ class DeletedMessagesVaultRoutesTest {
     private MemoryUsersRepository createUsersRepository() throws Exception {
         DNSService dnsService = mock(DNSService.class);
         MemoryDomainList domainList = new MemoryDomainList(dnsService);
-        domainList.configure(DomainListConfiguration.builder()
-            .autoDetect(false)
-            .autoDetectIp(false));
+        domainList.configure(DomainListConfiguration.DEFAULT);
         domainList.addDomain(DOMAIN);
 
         MemoryUsersRepository usersRepository = MemoryUsersRepository.withVirtualHosting(domainList);
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/ScanningQuotaSearchExtension.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/ScanningQuotaSearchExtension.java
index 997476c..3f1848e 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/ScanningQuotaSearchExtension.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/ScanningQuotaSearchExtension.java
@@ -50,9 +50,7 @@ public class ScanningQuotaSearchExtension implements ParameterResolver, BeforeEa
 
             DNSService dnsService = mock(DNSService.class);
             MemoryDomainList domainList = new MemoryDomainList(dnsService);
-            domainList.configure(DomainListConfiguration.builder()
-                .autoDetect(false)
-                .autoDetectIp(false));
+            domainList.configure(DomainListConfiguration.DEFAULT);
             MemoryUsersRepository usersRepository = MemoryUsersRepository.withVirtualHosting(domainList);
 
 
diff --git a/src/site/xdoc/server/config-domainlist.xml b/src/site/xdoc/server/config-domainlist.xml
index 8337e0d..eb0e61d 100644
--- a/src/site/xdoc/server/config-domainlist.xml
+++ b/src/site/xdoc/server/config-domainlist.xml
@@ -43,10 +43,10 @@ to determine when a mail is intended for local delivery - Only applicable for XM
         <dt><strong>autodetect</strong></dt>
         <dd>true or false - If autodetect is true, James wil attempt to discover its own host name AND 
 use any explicitly specified servernames. 
-If autodetect is false, James will use only the specified domainnames.</dd>
+If autodetect is false, James will use only the specified domainnames. Defaults to false.</dd>
         <dt><strong>autodetectIP</strong></dt>
         <dd>true or false - If autodetectIP is not false, James will also allow add the IP address for each servername. 
-The automatic IP detection is to support RFC 2821, Sec 4.1.3, address literals.</dd>
+The automatic IP detection is to support RFC 2821, Sec 4.1.3, address literals. Defaults to false.</dd>
         <dt><strong>defaultDomain</strong></dt>
         <dd>Set the default domain which will be used if an email is send to a recipient without a domain part.
             If not defaultdomain is set the first domain of the DomainList get used. If the default is not yet contained by the Domain List, the domain will be created upon start.</dd>


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


[james-project] 10/12: JAMES-3167 Improve MailboxManagerTest coverage to avoid bug detection upon MPT IMAP tests run

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 2aefb065783bb07ea6090d896494032714a9a358
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Tue Jun 9 09:53:53 2020 +0700

    JAMES-3167 Improve MailboxManagerTest coverage to avoid bug detection upon MPT IMAP tests run
---
 .../apache/james/mailbox/MailboxManagerTest.java    | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
index 603483b..3d92d48 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
@@ -1742,6 +1742,27 @@ public abstract class MailboxManagerTest<T extends MailboxManager> {
         }
 
         @Test
+        void renamingMailboxByPathShouldThrowWhenFromNotFound() throws Exception {
+            MailboxSession session = mailboxManager.createSystemSession(USER_1);
+
+            MailboxPath originPath = MailboxPath.forUser(USER_1, "origin");
+            MailboxPath destinationPath = MailboxPath.forUser(USER_1, "destination");
+
+            assertThatThrownBy(() -> mailboxManager.renameMailbox(originPath, destinationPath, session))
+                .isInstanceOf(MailboxNotFoundException.class);
+        }
+
+        @Test
+        void renamingMailboxByIdShouldThrowWhenFromNotFound() throws Exception {
+            MailboxSession session = mailboxManager.createSystemSession(USER_1);
+
+            MailboxPath notFound = MailboxPath.forUser(USER_1, "notFound");
+
+            assertThatThrownBy(() -> mailboxManager.deleteMailbox(notFound, session))
+                .isInstanceOf(MailboxNotFoundException.class);
+        }
+
+        @Test
         void user2ShouldNotBeAbleToDeleteUser1Mailbox() throws Exception {
             MailboxSession sessionUser1 = mailboxManager.createSystemSession(USER_1);
             MailboxSession sessionUser2 = mailboxManager.createSystemSession(USER_2);


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


[james-project] 04/12: JAMES-3202 Add `retrieveIndexedFlags` in MessageSearchIndex API

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 683504103a573c06b24211931acc6f1cd63847ab
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Wed Jun 10 17:40:32 2020 +0700

    JAMES-3202 Add `retrieveIndexedFlags` in MessageSearchIndex API
---
 .../ElasticSearchListeningMessageSearchIndex.java  |   6 +
 ...asticSearchListeningMessageSearchIndexTest.java |   3 +-
 .../lucene/search/LuceneMessageSearchIndex.java    |   5 +
 .../store/search/LazyMessageSearchIndex.java       | 307 +++++++++++----------
 .../store/search/ListeningMessageSearchIndex.java  |   7 +
 .../org/apache/james/FakeMessageSearchIndex.java   |   7 +
 6 files changed, 184 insertions(+), 151 deletions(-)

diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
index 091db6b..20caacb 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
@@ -29,6 +29,7 @@ import java.util.stream.Stream;
 
 import javax.inject.Inject;
 import javax.inject.Named;
+import javax.mail.Flags;
 
 import org.apache.james.backends.es.DocumentId;
 import org.apache.james.backends.es.ElasticSearchIndexer;
@@ -213,4 +214,9 @@ public class ElasticSearchListeningMessageSearchIndex extends ListeningMessageSe
             LOGGER.error("No messageUid for {} in mailbox {}", searchResult.getMessageUid(), searchResult.getMailboxId());
         }
     }
+
+    @Override
+    public Mono<Flags> retrieveIndexedFlags(Mailbox mailbox, MessageUid uid) {
+        return Mono.empty();
+    }
 }
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
index 5b617bc..b5a5359 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
@@ -92,9 +92,11 @@ class ElasticSearchListeningMessageSearchIndexTest {
     static final MessageUid MESSAGE_UID_1 = MessageUid.of(25);
     static final MessageUid MESSAGE_UID_2 = MessageUid.of(26);
     static final MessageUid MESSAGE_UID_3 = MessageUid.of(27);
+    static final MessageUid MESSAGE_UID_4 = MessageUid.of(28);
     static final MessageId MESSAGE_ID_1 = TestMessageId.of(18L);
     static final MessageId MESSAGE_ID_2 = TestMessageId.of(19L);
     static final MessageId MESSAGE_ID_3 = TestMessageId.of(20L);
+    static final MessageId MESSAGE_ID_4 = TestMessageId.of(21L);
 
     static final SimpleMailboxMessage.Builder MESSAGE_BUILDER = SimpleMailboxMessage.builder()
         .mailboxId(MAILBOX_ID)
@@ -441,5 +443,4 @@ class ElasticSearchListeningMessageSearchIndexTest {
         assertThatCode(() -> testee.deleteAll(session, mailbox.getMailboxId()).block())
             .doesNotThrowAnyException();
     }
-
 }
\ No newline at end of file
diff --git a/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java b/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
index d3da37c..7337a4f 100644
--- a/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
+++ b/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
@@ -1297,4 +1297,9 @@ public class LuceneMessageSearchIndex extends ListeningMessageSearchIndex {
     public void commit() throws IOException {
         writer.commit();
     }
+
+    @Override
+    public Mono<Flags> retrieveIndexedFlags(Mailbox mailbox, MessageUid uid) {
+        return Mono.empty();
+    }
 }
\ No newline at end of file
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java
index eac5ee5..459cc22 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java
@@ -1,150 +1,157 @@
-/****************************************************************
- * 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.search;
-
-import java.util.Collection;
-import java.util.EnumSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.stream.Stream;
-
-import org.apache.james.mailbox.MailboxManager;
-import org.apache.james.mailbox.MailboxManager.SearchCapabilities;
-import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.MessageUid;
-import org.apache.james.mailbox.SessionProvider;
-import org.apache.james.mailbox.events.Group;
-import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.exception.UnsupportedSearchException;
-import org.apache.james.mailbox.model.Mailbox;
-import org.apache.james.mailbox.model.MailboxId;
-import org.apache.james.mailbox.model.MessageId;
-import org.apache.james.mailbox.model.MessageRange;
-import org.apache.james.mailbox.model.SearchQuery;
-import org.apache.james.mailbox.model.UpdatedFlags;
-import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
-import org.apache.james.mailbox.store.mail.MessageMapper.FetchType;
-import org.apache.james.mailbox.store.mail.model.MailboxMessage;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.base.Preconditions;
-
-import reactor.core.publisher.Flux;
-import reactor.core.publisher.Mono;
-
-/**
- * {@link ListeningMessageSearchIndex} implementation which wraps another {@link ListeningMessageSearchIndex} and will forward all calls to it.
- * 
- * The only special thing about this is that it will index all the mails in the mailbox on the first call of {@link #search(MailboxSession, Mailbox, SearchQuery)}
- * 
- * This class is mostly useful for in-memory indexes or for indexed that should be recreated on every server restart.
- * 
- *
- */
-public class LazyMessageSearchIndex extends ListeningMessageSearchIndex {
-    public static class LazyMessageSearchIndexGroup extends Group {
-
-    }
-
-    private static final Logger LOGGER = LoggerFactory.getLogger(LazyMessageSearchIndex.class);
-    private static final Group GROUP = new LazyMessageSearchIndexGroup();
-
-    private final ListeningMessageSearchIndex index;
-    private final ConcurrentHashMap<MailboxId, Object> indexed = new ConcurrentHashMap<>();
-    private final MailboxSessionMapperFactory factory;
-    
-    
-    public LazyMessageSearchIndex(ListeningMessageSearchIndex index, MailboxSessionMapperFactory factory, SessionProvider sessionProvider) {
-        super(factory, sessionProvider);
-        this.index = index;
-        this.factory = factory;
-    }
-
-    @Override
-    public Group getDefaultGroup() {
-        return GROUP;
-    }
-    
-    @Override
-    public EnumSet<SearchCapabilities> getSupportedCapabilities(EnumSet<MailboxManager.MessageCapabilities> messageCapabilities) {
-        return EnumSet.noneOf(SearchCapabilities.class);
-    }
-
-    @Override
-    public Mono<Void> add(MailboxSession session, Mailbox mailbox, MailboxMessage message) {
-        return index.add(session, mailbox, message);
-    }
-
-    @Override
-    public Mono<Void> delete(MailboxSession session, Mailbox mailbox, Collection<MessageUid> expungedUids) {
-        return index.delete(session, mailbox, expungedUids);
-    }
-
-    @Override
-    public Mono<Void> deleteAll(MailboxSession session, MailboxId mailboxId) {
-        return index.deleteAll(session, mailboxId);
-    }
-
-    /**
-     * Lazy index the mailbox on first search request if it was not indexed before. After indexing is done it delegate the search request to the wrapped
-     * {@link MessageSearchIndex}. Be aware that concurrent search requests are blocked on the same "not-yet-indexed" mailbox till it the index process was 
-     * complete
-     * 
-     */
-    @Override
-    public Stream<MessageUid> search(MailboxSession session, Mailbox mailbox, SearchQuery searchQuery) throws MailboxException {
-        Preconditions.checkArgument(session != null, "'session' is mandatory");
-        MailboxId id = mailbox.getMailboxId();
-        
-        Object done = indexed.get(id);
-        if (done == null) {
-            done = new Object();
-            Object oldDone = indexed.putIfAbsent(id, done);
-            if (oldDone != null) {
-                done = oldDone;
-            }
-            synchronized (done) {
-                Iterator<MailboxMessage> messages = factory.getMessageMapper(session).findInMailbox(mailbox, MessageRange.all(), FetchType.Full, UNLIMITED);
-                while (messages.hasNext()) {
-                    final MailboxMessage message = messages.next();
-                    try {
-                        add(session, mailbox, message).block();
-                    } catch (Exception e) {
-                        LOGGER.error("Unable to index message {} in mailbox {}", message.getUid(), mailbox.getName(), e);
-                    }
-                }
-            }
-        }
-       
-        return index.search(session, mailbox, searchQuery);
-    }
-
-    @Override
-    public Mono<Void> update(MailboxSession session, Mailbox mailbox, List<UpdatedFlags> updatedFlagsList) {
-        return index.update(session, mailbox, updatedFlagsList);
-    }
-    
-
-    @Override
-    public Flux<MessageId> search(MailboxSession session, Collection<MailboxId> mailboxIds, SearchQuery searchQuery, long limit) throws MailboxException {
-        throw new UnsupportedSearchException();
-    }
-}
+/****************************************************************
+ * 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.search;
+
+import java.util.Collection;
+import java.util.EnumSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Stream;
+
+import javax.mail.Flags;
+
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxManager.SearchCapabilities;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MessageUid;
+import org.apache.james.mailbox.SessionProvider;
+import org.apache.james.mailbox.events.Group;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.exception.UnsupportedSearchException;
+import org.apache.james.mailbox.model.Mailbox;
+import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.MessageId;
+import org.apache.james.mailbox.model.MessageRange;
+import org.apache.james.mailbox.model.SearchQuery;
+import org.apache.james.mailbox.model.UpdatedFlags;
+import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
+import org.apache.james.mailbox.store.mail.MessageMapper.FetchType;
+import org.apache.james.mailbox.store.mail.model.MailboxMessage;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+
+/**
+ * {@link ListeningMessageSearchIndex} implementation which wraps another {@link ListeningMessageSearchIndex} and will forward all calls to it.
+ * 
+ * The only special thing about this is that it will index all the mails in the mailbox on the first call of {@link #search(MailboxSession, Mailbox, SearchQuery)}
+ * 
+ * This class is mostly useful for in-memory indexes or for indexed that should be recreated on every server restart.
+ * 
+ *
+ */
+public class LazyMessageSearchIndex extends ListeningMessageSearchIndex {
+    public static class LazyMessageSearchIndexGroup extends Group {
+
+    }
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(LazyMessageSearchIndex.class);
+    private static final Group GROUP = new LazyMessageSearchIndexGroup();
+
+    private final ListeningMessageSearchIndex index;
+    private final ConcurrentHashMap<MailboxId, Object> indexed = new ConcurrentHashMap<>();
+    private final MailboxSessionMapperFactory factory;
+    
+    
+    public LazyMessageSearchIndex(ListeningMessageSearchIndex index, MailboxSessionMapperFactory factory, SessionProvider sessionProvider) {
+        super(factory, sessionProvider);
+        this.index = index;
+        this.factory = factory;
+    }
+
+    @Override
+    public Group getDefaultGroup() {
+        return GROUP;
+    }
+    
+    @Override
+    public EnumSet<SearchCapabilities> getSupportedCapabilities(EnumSet<MailboxManager.MessageCapabilities> messageCapabilities) {
+        return EnumSet.noneOf(SearchCapabilities.class);
+    }
+
+    @Override
+    public Mono<Void> add(MailboxSession session, Mailbox mailbox, MailboxMessage message) {
+        return index.add(session, mailbox, message);
+    }
+
+    @Override
+    public Mono<Void> delete(MailboxSession session, Mailbox mailbox, Collection<MessageUid> expungedUids) {
+        return index.delete(session, mailbox, expungedUids);
+    }
+
+    @Override
+    public Mono<Void> deleteAll(MailboxSession session, MailboxId mailboxId) {
+        return index.deleteAll(session, mailboxId);
+    }
+
+    /**
+     * Lazy index the mailbox on first search request if it was not indexed before. After indexing is done it delegate the search request to the wrapped
+     * {@link MessageSearchIndex}. Be aware that concurrent search requests are blocked on the same "not-yet-indexed" mailbox till it the index process was 
+     * complete
+     * 
+     */
+    @Override
+    public Stream<MessageUid> search(MailboxSession session, Mailbox mailbox, SearchQuery searchQuery) throws MailboxException {
+        Preconditions.checkArgument(session != null, "'session' is mandatory");
+        MailboxId id = mailbox.getMailboxId();
+        
+        Object done = indexed.get(id);
+        if (done == null) {
+            done = new Object();
+            Object oldDone = indexed.putIfAbsent(id, done);
+            if (oldDone != null) {
+                done = oldDone;
+            }
+            synchronized (done) {
+                Iterator<MailboxMessage> messages = factory.getMessageMapper(session).findInMailbox(mailbox, MessageRange.all(), FetchType.Full, UNLIMITED);
+                while (messages.hasNext()) {
+                    final MailboxMessage message = messages.next();
+                    try {
+                        add(session, mailbox, message).block();
+                    } catch (Exception e) {
+                        LOGGER.error("Unable to index message {} in mailbox {}", message.getUid(), mailbox.getName(), e);
+                    }
+                }
+            }
+        }
+       
+        return index.search(session, mailbox, searchQuery);
+    }
+
+    @Override
+    public Mono<Void> update(MailboxSession session, Mailbox mailbox, List<UpdatedFlags> updatedFlagsList) {
+        return index.update(session, mailbox, updatedFlagsList);
+    }
+    
+
+    @Override
+    public Flux<MessageId> search(MailboxSession session, Collection<MailboxId> mailboxIds, SearchQuery searchQuery, long limit) throws MailboxException {
+        throw new UnsupportedSearchException();
+    }
+
+    @Override
+    public Mono<Flags> retrieveIndexedFlags(Mailbox mailbox, MessageUid uid) {
+        return index.retrieveIndexedFlags(mailbox, uid);
+    }
+}
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java
index d9ebfe9..59f4260 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java
@@ -21,6 +21,8 @@ package org.apache.james.mailbox.store.search;
 import java.util.Collection;
 import java.util.List;
 
+import javax.mail.Flags;
+
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.SessionProvider;
@@ -142,4 +144,9 @@ public abstract class ListeningMessageSearchIndex implements MessageSearchIndex,
      * @param updatedFlagsList list of flags that were updated
      */
     public abstract Mono<Void> update(MailboxSession session, Mailbox mailbox, List<UpdatedFlags> updatedFlagsList);
+
+    /**
+     * Retrieves flags of an indexed message
+     */
+    public abstract Mono<Flags> retrieveIndexedFlags(Mailbox mailbox, MessageUid uid);
 }
diff --git a/server/container/guice/memory-guice/src/main/java/org/apache/james/FakeMessageSearchIndex.java b/server/container/guice/memory-guice/src/main/java/org/apache/james/FakeMessageSearchIndex.java
index 46fe6d0..3c7beef 100644
--- a/server/container/guice/memory-guice/src/main/java/org/apache/james/FakeMessageSearchIndex.java
+++ b/server/container/guice/memory-guice/src/main/java/org/apache/james/FakeMessageSearchIndex.java
@@ -24,6 +24,8 @@ import java.util.EnumSet;
 import java.util.List;
 import java.util.stream.Stream;
 
+import javax.mail.Flags;
+
 import org.apache.commons.lang3.NotImplementedException;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
@@ -96,4 +98,9 @@ public class FakeMessageSearchIndex extends ListeningMessageSearchIndex {
     public ExecutionMode getExecutionMode() {
         throw new NotImplementedException("not implemented");
     }
+
+    @Override
+    public Mono<Flags> retrieveIndexedFlags(Mailbox mailbox, MessageUid uid) {
+        throw new NotImplementedException("not implemented");
+    }
 }


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


[james-project] 12/12: JAMES-3167 Reactify right management in StoreMessageIdManager

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 3567a93c41ba8e6b23eb893f617d3cedf2856bca
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed Jun 17 15:34:17 2020 +0700

    JAMES-3167 Reactify right management in StoreMessageIdManager
---
 .../james/mailbox/store/StoreMessageIdManager.java | 59 ++++++++++------------
 1 file changed, 26 insertions(+), 33 deletions(-)

diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
index 4ed6fb9..994daad 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
@@ -118,7 +118,7 @@ public class StoreMessageIdManager implements MessageIdManager {
     public void setFlags(Flags newState, MessageManager.FlagsUpdateMode replace, MessageId messageId, List<MailboxId> mailboxIds, MailboxSession mailboxSession) throws MailboxException {
         MessageIdMapper messageIdMapper = mailboxSessionMapperFactory.getMessageIdMapper(mailboxSession);
 
-        assertRightsOnMailboxes(mailboxIds, mailboxSession, Right.Write);
+        MailboxReactorUtils.block(assertRightsOnMailboxes(mailboxIds, mailboxSession, Right.Write));
 
         Multimap<MailboxId, UpdatedFlags> updatedFlags = messageIdMapper.setFlags(messageId, mailboxIds, newState, replace);
         for (Map.Entry<MailboxId, Collection<UpdatedFlags>> entry : updatedFlags.asMap().entrySet()) {
@@ -158,19 +158,19 @@ public class StoreMessageIdManager implements MessageIdManager {
             .map(Throwing.function(messageResultConverter(fetchGroup)).sneakyThrow());
     }
 
-    private ImmutableSet<MailboxId> getAllowedMailboxIds(MailboxSession mailboxSession, List<MailboxMessage> messageList, Right... rights) {
-        return messageList.stream()
-                .map(MailboxMessage::getMailboxId)
-                .distinct()
-                .filter(hasRightsOnMailbox(mailboxSession, rights))
-                .collect(Guavate.toImmutableSet());
+    private ImmutableSet<MailboxId> getAllowedMailboxIds(MailboxSession mailboxSession, List<MailboxMessage> messageList, Right... rights) throws MailboxException {
+        return MailboxReactorUtils.block(Flux.fromIterable(messageList)
+            .map(MailboxMessage::getMailboxId)
+            .distinct()
+            .filterWhen(hasRightsOnMailboxReactive(mailboxSession, rights))
+            .collect(Guavate.toImmutableSet()));
     }
 
     @Override
     public DeleteResult delete(MessageId messageId, List<MailboxId> mailboxIds, MailboxSession mailboxSession) throws MailboxException {
         MessageIdMapper messageIdMapper = mailboxSessionMapperFactory.getMessageIdMapper(mailboxSession);
 
-        assertRightsOnMailboxes(mailboxIds, mailboxSession, Right.DeleteMessages);
+        MailboxReactorUtils.block(assertRightsOnMailboxes(mailboxIds, mailboxSession, Right.DeleteMessages));
 
         List<MailboxMessage> messageList = messageIdMapper
             .find(ImmutableList.of(messageId), MessageMapper.FetchType.Metadata)
@@ -243,7 +243,7 @@ public class StoreMessageIdManager implements MessageIdManager {
 
     @Override
     public void setInMailboxes(MessageId messageId, Collection<MailboxId> targetMailboxIds, MailboxSession mailboxSession) throws MailboxException {
-        assertRightsOnMailboxes(targetMailboxIds, mailboxSession, Right.Read);
+        MailboxReactorUtils.block(assertRightsOnMailboxes(targetMailboxIds, mailboxSession, Right.Read));
 
         List<MailboxMessage> currentMailboxMessages = findRelatedMailboxMessages(messageId, mailboxSession);
 
@@ -276,18 +276,17 @@ public class StoreMessageIdManager implements MessageIdManager {
         }
     }
 
-    private List<MailboxMessage> findRelatedMailboxMessages(MessageId messageId, MailboxSession mailboxSession) {
+    private List<MailboxMessage> findRelatedMailboxMessages(MessageId messageId, MailboxSession mailboxSession) throws MailboxException {
         MessageIdMapper messageIdMapper = mailboxSessionMapperFactory.getMessageIdMapper(mailboxSession);
 
-        return messageIdMapper.find(ImmutableList.of(messageId), MessageMapper.FetchType.Metadata)
-            .stream()
-            .filter(hasRightsOn(mailboxSession, Right.Read))
-            .collect(Guavate.toImmutableList());
+        return MailboxReactorUtils.block(messageIdMapper.findReactive(ImmutableList.of(messageId), MessageMapper.FetchType.Metadata)
+            .filterWhen(hasRightsOn(mailboxSession, Right.Read))
+            .collect(Guavate.toImmutableList()));
     }
 
     private void applyMessageMoves(MailboxSession mailboxSession, List<MailboxMessage> currentMailboxMessages, MessageMoves messageMoves) throws MailboxException {
-        assertRightsOnMailboxes(messageMoves.addedMailboxIds(), mailboxSession, Right.Insert);
-        assertRightsOnMailboxes(messageMoves.removedMailboxIds(), mailboxSession, Right.DeleteMessages);
+        MailboxReactorUtils.block(assertRightsOnMailboxes(messageMoves.addedMailboxIds(), mailboxSession, Right.Insert));
+        MailboxReactorUtils.block(assertRightsOnMailboxes(messageMoves.removedMailboxIds(), mailboxSession, Right.DeleteMessages));
 
         applyMessageMoveNoMailboxChecks(mailboxSession, currentMailboxMessages, messageMoves);
     }
@@ -427,14 +426,8 @@ public class StoreMessageIdManager implements MessageIdManager {
         return mailboxMessage -> mailboxIds.contains(mailboxMessage.getMailboxId());
     }
 
-    private Predicate<MailboxMessage> hasRightsOn(MailboxSession session, Right... rights) {
-        return message -> hasRightsOnMailbox(session, rights).test(message.getMailboxId());
-    }
-
-
-    private Predicate<MailboxId> hasRightsOnMailbox(MailboxSession session, Right... rights) {
-        return Throwing.predicate((MailboxId mailboxId) -> block(Mono.from(rightManager.myRights(mailboxId, session))).contains(rights))
-            .fallbackTo(any -> false);
+    private Function<MailboxMessage, Mono<Boolean>> hasRightsOn(MailboxSession session, Right... rights) {
+        return hasRightsOnMailboxReactive(session, rights).compose(MailboxMessage::getMailboxId);
     }
 
     private Function<MailboxId, Mono<Boolean>> hasRightsOnMailboxReactive(MailboxSession session, Right... rights) {
@@ -443,14 +436,14 @@ public class StoreMessageIdManager implements MessageIdManager {
             .onErrorResume(any -> Mono.just(false));
     }
 
-    private void assertRightsOnMailboxes(Collection<MailboxId> mailboxIds, MailboxSession mailboxSession, Right... rights) throws MailboxNotFoundException {
-        Optional<MailboxId> mailboxForbidden = mailboxIds.stream()
-            .filter(hasRightsOnMailbox(mailboxSession, rights).negate())
-            .findFirst();
-
-        if (mailboxForbidden.isPresent()) {
-            LOGGER.info("Mailbox with Id {} does not belong to {}", mailboxForbidden.get(), mailboxSession.getUser().asString());
-            throw new MailboxNotFoundException(mailboxForbidden.get());
-        }
+    private Mono<Void> assertRightsOnMailboxes(Collection<MailboxId> mailboxIds, MailboxSession mailboxSession, Right... rights) throws MailboxNotFoundException {
+        return Flux.fromIterable(mailboxIds)
+            .filterWhen(hasRightsOnMailboxReactive(mailboxSession, rights).andThen(result -> result.map(b -> !b)))
+            .next()
+            .flatMap(mailboxForbidden -> {
+                LOGGER.info("Mailbox with Id {} does not belong to {}", mailboxForbidden, mailboxSession.getUser().asString());
+                return Mono.error(new MailboxNotFoundException(mailboxForbidden));
+            })
+            .then();
     }
 }


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


[james-project] 03/12: JAMES-3202 Add get document action to ElasticSearchIndexer

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit fae3ecee64473fdd77f12e20e92935c7db62a093
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Tue Jun 9 15:37:43 2020 +0700

    JAMES-3202 Add get document action to ElasticSearchIndexer
---
 .../james/backends/es/ElasticSearchIndexer.java    | 14 ++++++++++++
 .../backends/es/ReactorElasticSearchClient.java    |  6 +++++
 .../backends/es/ElasticSearchIndexerTest.java      | 26 ++++++++++++++++++++++
 3 files changed, 46 insertions(+)

diff --git a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchIndexer.java b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchIndexer.java
index 3b5c8a2..049dcd5 100644
--- a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchIndexer.java
+++ b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchIndexer.java
@@ -24,6 +24,8 @@ import org.apache.commons.lang3.StringUtils;
 import org.elasticsearch.action.bulk.BulkRequest;
 import org.elasticsearch.action.bulk.BulkResponse;
 import org.elasticsearch.action.delete.DeleteRequest;
+import org.elasticsearch.action.get.GetRequest;
+import org.elasticsearch.action.get.GetResponse;
 import org.elasticsearch.action.index.IndexRequest;
 import org.elasticsearch.action.index.IndexResponse;
 import org.elasticsearch.action.update.UpdateRequest;
@@ -120,4 +122,16 @@ public class ElasticSearchIndexer {
     private void checkArgument(String content) {
         Preconditions.checkArgument(content != null, "content should be provided");
     }
+
+    public Mono<GetResponse> get(DocumentId id, RoutingKey routingKey) {
+        return Mono.fromRunnable(() -> {
+                Preconditions.checkNotNull(id);
+                Preconditions.checkNotNull(routingKey);
+            })
+            .then(client.get(new GetRequest(aliasName.getValue())
+                    .type(NodeMappingFactory.DEFAULT_MAPPING_NAME)
+                    .id(id.asString())
+                    .routing(routingKey.asString()),
+                RequestOptions.DEFAULT));
+    }
 }
diff --git a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ReactorElasticSearchClient.java b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ReactorElasticSearchClient.java
index 1636df6..fc6d26e 100644
--- a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ReactorElasticSearchClient.java
+++ b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ReactorElasticSearchClient.java
@@ -37,6 +37,8 @@ import org.elasticsearch.action.explain.ExplainRequest;
 import org.elasticsearch.action.explain.ExplainResponse;
 import org.elasticsearch.action.fieldcaps.FieldCapabilitiesRequest;
 import org.elasticsearch.action.fieldcaps.FieldCapabilitiesResponse;
+import org.elasticsearch.action.get.GetRequest;
+import org.elasticsearch.action.get.GetResponse;
 import org.elasticsearch.action.index.IndexRequest;
 import org.elasticsearch.action.index.IndexResponse;
 import org.elasticsearch.action.main.MainResponse;
@@ -147,6 +149,10 @@ public class ReactorElasticSearchClient implements AutoCloseable {
         return toReactor(listener -> client.searchTemplateAsync(searchTemplateRequest, options, listener));
     }
 
+    public Mono<GetResponse> get(GetRequest getRequest, RequestOptions options) {
+        return toReactor(listener -> client.getAsync(getRequest, options, listener));
+    }
+
     @Override
     public void close() throws IOException {
         client.close();
diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java
index ac320ca..f0c9f9d 100644
--- a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java
@@ -30,6 +30,7 @@ import java.io.IOException;
 import org.awaitility.Awaitility;
 import org.awaitility.Duration;
 import org.awaitility.core.ConditionFactory;
+import org.elasticsearch.action.get.GetResponse;
 import org.elasticsearch.action.search.SearchRequest;
 import org.elasticsearch.action.search.SearchResponse;
 import org.elasticsearch.client.RequestOptions;
@@ -264,4 +265,29 @@ class ElasticSearchIndexerTest {
         assertThatCode(() -> testee.delete(ImmutableList.of(), ROUTING).block())
             .doesNotThrowAnyException();
     }
+
+    @Test
+    void getShouldWork() {
+        DocumentId documentId = DocumentId.fromString("1");
+        String content = "{\"message\":\"trying out Elasticsearch\"}";
+
+        testee.index(documentId, content, useDocumentId(documentId)).block();
+        elasticSearch.awaitForElasticSearch();
+
+        GetResponse getResponse = testee.get(documentId, useDocumentId(documentId)).block();
+
+        assertThat(getResponse.getSourceAsString()).isEqualTo(content);
+    }
+
+    @Test
+    void getShouldThrowWhenIdIsNull() {
+        assertThatThrownBy(() -> testee.get(null, ROUTING).block())
+            .isInstanceOf(NullPointerException.class);
+    }
+
+    @Test
+    void getShouldThrowWhenRoutingKeyIsNull() {
+        assertThatThrownBy(() -> testee.get(DOCUMENT_ID, null).block())
+            .isInstanceOf(NullPointerException.class);
+    }
 }


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