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 rc...@apache.org on 2020/02/18 02:48:16 UTC

[james-project] 05/08: JAMES-3056 renaming mailboxes doesn't need ACL to be involved

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

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

commit 05c0fab6e0334f71cf378d126f4597aea4e20d22
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Wed Feb 12 16:51:11 2020 +0700

    JAMES-3056 renaming mailboxes doesn't need ACL to be involved
---
 .../cassandra/mail/CassandraMailboxMapper.java     | 16 ++--
 .../cassandra/mail/CassandraMailboxMapperTest.java | 94 ----------------------
 2 files changed, 8 insertions(+), 102 deletions(-)

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 09ed684..5b01741 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
@@ -21,7 +21,6 @@ package org.apache.james.mailbox.cassandra.mail;
 
 import java.util.Collections;
 import java.util.List;
-import java.util.Optional;
 import java.util.StringTokenizer;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
@@ -177,13 +176,14 @@ public class CassandraMailboxMapper implements MailboxMapper {
     }
 
     private boolean trySave(Mailbox cassandraMailbox, CassandraId cassandraId) {
-        boolean isCreated = mailboxPathV2DAO.save(cassandraMailbox.generateAssociatedPath(), cassandraId).block();
-        if (isCreated) {
-            Optional<Mailbox> simpleMailbox = retrieveMailbox(cassandraId).blockOptional();
-            simpleMailbox.ifPresent(mbx -> mailboxPathV2DAO.delete(mbx.generateAssociatedPath()).block());
-            mailboxDAO.save(cassandraMailbox).block();
-        }
-        return isCreated;
+        return mailboxPathV2DAO.save(cassandraMailbox.generateAssociatedPath(), cassandraId)
+            .filter(isCreated -> isCreated)
+            .flatMap(mailboxHasCreated -> mailboxDAO.retrieveMailbox(cassandraId)
+                .flatMap(mailbox -> mailboxPathV2DAO.delete(mailbox.generateAssociatedPath()))
+                .then(mailboxDAO.save(cassandraMailbox))
+                .thenReturn(true))
+            .switchIfEmpty(Mono.just(false))
+            .block();
     }
 
     private CassandraId retrieveId(Mailbox cassandraMailbox) {
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 b2854eb..e62e158 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
@@ -162,68 +162,6 @@ class CassandraMailboxMapperTest {
         }
 
         @Test
-        void saveOnRenameThenFailToGetACLShouldBeConsistentWhenFindByInbox() throws Exception {
-            testee.save(inbox);
-
-            when(aclMapper.getACL(inboxId))
-                .thenReturn(Mono.error(new RuntimeException("mock exception")))
-                .thenCallRealMethod();
-
-            doQuietly(() -> testee.save(inboxRenamed));
-
-            SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-                softly(softly)
-                    .assertThat(testee.findMailboxById(inboxId))
-                    .isEqualTo(inbox);
-                softly(softly)
-                    .assertThat(testee.findMailboxByPath(inboxPath))
-                    .isEqualTo(inbox);
-                softly.assertThat(testee.findMailboxWithPathLike(inboxSearchQuery))
-                    .hasOnlyOneElementSatisfying(searchMailbox -> softly(softly)
-                        .assertThat(searchMailbox)
-                        .isEqualTo(inbox));
-            }));
-        }
-
-        @Disabled("JAMES-3056 returning two mailboxes with same name and id")
-        @Test
-        void saveOnRenameThenFailToGetACLShouldBeConsistentWhenFindAll() throws Exception {
-            testee.save(inbox);
-
-            when(aclMapper.getACL(inboxId))
-                .thenReturn(Mono.error(new RuntimeException("mock exception")))
-                .thenCallRealMethod();
-
-            doQuietly(() -> testee.save(inboxRenamed));
-
-            SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-                softly.assertThat(testee.findMailboxWithPathLike(allMailboxesSearchQuery))
-                    .hasOnlyOneElementSatisfying(searchMailbox -> softly(softly)
-                        .assertThat(searchMailbox)
-                        .isEqualTo(inbox));
-            }));
-        }
-
-        @Disabled("JAMES-3056 find by renamed name returns unexpected results")
-        @Test
-        void saveOnRenameThenFailToGetACLShouldBeConsistentWhenFindByRenamedInbox() throws Exception {
-            testee.save(inbox);
-
-            when(aclMapper.getACL(inboxId))
-                .thenReturn(Mono.error(new RuntimeException("mock exception")))
-                .thenCallRealMethod();
-
-            doQuietly(() -> testee.save(inboxRenamed));
-
-            SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-                softly.assertThatThrownBy(() -> testee.findMailboxByPath(inboxPathRenamed))
-                    .isInstanceOf(MailboxNotFoundException.class);
-                softly.assertThat(testee.findMailboxWithPathLike(inboxRenamedSearchQuery))
-                    .isEmpty();
-            }));
-        }
-
-        @Test
         void saveOnRenameThenFailToRetrieveMailboxShouldBeConsistentWhenFindByInbox() throws Exception {
             testee.save(inbox);
 
@@ -506,38 +444,6 @@ class CassandraMailboxMapperTest {
 
         @Disabled("JAMES-3056 mailbox name is not updated to INBOX_RENAMED")
         @Test
-        void renameAfterRenameFailOnGetACLShouldRenameTheMailbox() throws Exception {
-            testee.save(inbox);
-
-            when(aclMapper.getACL(inboxId))
-                .thenReturn(Mono.error(new RuntimeException("mock exception")))
-                .thenCallRealMethod();
-
-            doQuietly(() -> testee.save(inboxRenamed));
-            doQuietly(() -> testee.save(inboxRenamed));
-
-            SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
-                softly(softly)
-                    .assertThat(testee.findMailboxById(inboxId))
-                    .isEqualTo(inboxRenamed);
-                softly(softly)
-                    .assertThat(testee.findMailboxByPath(inboxPathRenamed))
-                    .isEqualTo(inboxRenamed);
-                softly.assertThat(testee.findMailboxWithPathLike(inboxSearchQuery))
-                    .isEmpty();
-                softly.assertThat(testee.findMailboxWithPathLike(inboxRenamedSearchQuery))
-                    .hasOnlyOneElementSatisfying(searchMailbox -> softly(softly)
-                        .assertThat(searchMailbox)
-                        .isEqualTo(inboxRenamed));
-                softly.assertThat(testee.findMailboxWithPathLike(allMailboxesSearchQuery))
-                    .hasOnlyOneElementSatisfying(searchMailbox -> softly(softly)
-                        .assertThat(searchMailbox)
-                        .isEqualTo(inboxRenamed));
-            }));
-        }
-
-        @Disabled("JAMES-3056 mailbox name is not updated to INBOX_RENAMED")
-        @Test
         void renameAfterRenameFailOnDeletePathShouldRenameTheMailbox() throws Exception {
             testee.save(inbox);
 


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