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/02/20 03:27:47 UTC

[james-project] 05/08: JAMES-3056 Distinct on StoreMailboxManager.list()

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 e9e38a5ef2c1e1a9c3193d570db9fb8c78b6d8c9
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Fri Feb 14 10:20:49 2020 +0700

    JAMES-3056 Distinct on StoreMailboxManager.list()
---
 .../CassandraMailboxManagerConsistencyTest.java    | 115 +++++++++++++++++++--
 .../james/mailbox/store/StoreMailboxManager.java   |   1 +
 2 files changed, 110 insertions(+), 6 deletions(-)

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 2278c2a..5ec2154 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
@@ -103,7 +103,7 @@ class CassandraMailboxManagerConsistencyTest {
     }
 
     @Nested
-    class FailsOnCreate {
+    class FailuresDuringCreation {
 
         @Test
         void createMailboxShouldBeConsistentWhenMailboxDaoFails() {
@@ -137,7 +137,7 @@ class CassandraMailboxManagerConsistencyTest {
             }));
         }
 
-        @Disabled("JAMES-3056 createMailbox() return an empty Optional")
+        @Disabled("JAMES-3056 createMailbox() doesn't return mailboxId while it's supposed to")
         @Test
         void createMailboxAfterAFailedCreationShouldCreateTheMailboxWhenMailboxDaoFails() throws Exception {
             doReturn(Mono.error(new RuntimeException("mock exception")))
@@ -174,7 +174,7 @@ class CassandraMailboxManagerConsistencyTest {
             }));
         }
 
-        @Disabled("JAMES-3056 createMailbox() return an empty Optional")
+        @Disabled("JAMES-3056 createMailbox() doesn't return mailboxId while it's supposed to")
         @Test
         void createMailboxAfterDeletingShouldCreateTheMailboxWhenMailboxDaoFails() throws Exception {
             doReturn(Mono.error(new RuntimeException("mock exception")))
@@ -215,7 +215,7 @@ class CassandraMailboxManagerConsistencyTest {
     }
 
     @Nested
-    class FailsOnRename {
+    class FailuresDuringRenaming {
 
         @Test
         void renameShouldBeConsistentWhenMailboxDaoFails() throws Exception {
@@ -367,7 +367,7 @@ class CassandraMailboxManagerConsistencyTest {
     }
 
     @Nested
-    class FailsOnDelete {
+    class FailuresOnDeletion {
 
         @Nested
         class DeleteOnce {
@@ -463,6 +463,110 @@ class CassandraMailboxManagerConsistencyTest {
         }
 
         @Nested
+        class DeleteOnceThenCreate {
+
+            @Test
+            void createMailboxShouldCreateWhenMailboxDaoFailsOnDeleteByPath() throws Exception {
+                testee.createMailbox(inboxPath, mailboxSession);
+
+                doReturn(Mono.error(new RuntimeException("mock exception")))
+                    .doCallRealMethod()
+                    .when(mailboxDAO)
+                    .delete(any(CassandraId.class));
+
+                doQuietly(() -> testee.deleteMailbox(inboxPath, mailboxSession));
+                MailboxId inboxId = testee.createMailbox(inboxPath, mailboxSession)
+                    .get();
+
+                SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
+                    softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+                        .hasOnlyOneElementSatisfying(mailboxMetaData -> {
+                            softly.assertThat(mailboxMetaData.getId()).isEqualTo(inboxId);
+                            softly.assertThat(mailboxMetaData.getPath()).isEqualTo(inboxPath);
+                        });
+                    softly.assertThat(testee.list(mailboxSession))
+                        .containsExactly(inboxPath);
+                }));
+            }
+
+            @Test
+            void createMailboxShouldCreateWhenMailboxDaoFailsOnDeleteById() throws Exception {
+                MailboxId inboxId = testee.createMailbox(inboxPath, mailboxSession)
+                    .get();
+
+                doReturn(Mono.error(new RuntimeException("mock exception")))
+                    .doCallRealMethod()
+                    .when(mailboxDAO)
+                    .delete(any(CassandraId.class));
+
+                doQuietly(() -> testee.deleteMailbox(inboxId, mailboxSession));
+                MailboxId inboxNewId = testee.createMailbox(inboxPath, mailboxSession)
+                    .get();
+
+                SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
+                    softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+                        .hasOnlyOneElementSatisfying(mailboxMetaData -> {
+                            softly.assertThat(mailboxMetaData.getId()).isEqualTo(inboxNewId);
+                            softly.assertThat(mailboxMetaData.getPath()).isEqualTo(inboxPath);
+                        });
+                    softly.assertThat(testee.list(mailboxSession))
+                        .containsExactly(inboxPath);
+                }));
+            }
+
+            @Disabled("JAMES-3056 cannot create because mailbox already exists")
+            @Test
+            void createMailboxShouldCreateWhenMailboxPathDaoFailsOnDeleteByPath() throws Exception {
+                testee.createMailbox(inboxPath, mailboxSession);
+
+                doReturn(Mono.error(new RuntimeException("mock exception")))
+                    .doCallRealMethod()
+                    .when(mailboxPathV2DAO)
+                    .delete(inboxPath);
+
+                doQuietly(() -> testee.deleteMailbox(inboxPath, mailboxSession));
+                MailboxId inboxNewId = testee.createMailbox(inboxPath, mailboxSession)
+                    .get();
+
+                SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
+                    softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+                        .hasOnlyOneElementSatisfying(mailboxMetaData -> {
+                            softly.assertThat(mailboxMetaData.getId()).isEqualTo(inboxNewId);
+                            softly.assertThat(mailboxMetaData.getPath()).isEqualTo(inboxPath);
+                        });
+                    softly.assertThat(testee.list(mailboxSession))
+                        .containsExactly(inboxPath);
+                }));
+            }
+
+            @Disabled("JAMES-3056 cannot create because mailbox already exists")
+            @Test
+            void createMailboxShouldCreateWhenMailboxPathDaoFailsOnDeleteById() throws Exception {
+                MailboxId inboxId = testee.createMailbox(inboxPath, mailboxSession)
+                    .get();
+
+                doReturn(Mono.error(new RuntimeException("mock exception")))
+                    .doCallRealMethod()
+                    .when(mailboxPathV2DAO)
+                    .delete(inboxPath);
+
+                doQuietly(() -> testee.deleteMailbox(inboxId, mailboxSession));
+                MailboxId inboxNewId = testee.createMailbox(inboxPath, mailboxSession)
+                    .get();
+
+                SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
+                    softly.assertThat(testee.search(allMailboxesSearchQuery, mailboxSession))
+                        .hasOnlyOneElementSatisfying(mailboxMetaData -> {
+                            softly.assertThat(mailboxMetaData.getId()).isEqualTo(inboxNewId);
+                            softly.assertThat(mailboxMetaData.getPath()).isEqualTo(inboxPath);
+                        });
+                    softly.assertThat(testee.list(mailboxSession))
+                        .containsExactly(inboxPath);
+                }));
+            }
+        }
+
+        @Nested
         class DeleteTwice {
 
             @Disabled("JAMES-3056 list() returns one element with inboxPath")
@@ -552,7 +656,6 @@ class CassandraMailboxManagerConsistencyTest {
         @Nested
         class DeleteTwiceThenCreate {
 
-            @Disabled("JAMES-3056 list() returns two element with inboxPath being duplicated")
             @Test
             void createMailboxShouldCreateWhenMailboxDaoFailsOnDeleteByPath() throws Exception {
                 testee.createMailbox(inboxPath, mailboxSession);
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 f023f5f..31f7f7b 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
@@ -742,6 +742,7 @@ public class StoreMailboxManager implements MailboxManager {
             .list()
             .stream()
             .map(Mailbox::generateAssociatedPath)
+            .distinct()
             .collect(Guavate.toImmutableList());
     }
 


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