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/04/29 09:02:37 UTC

[james-project] 01/05: JAMES-2810 Use a nested class for Consistency related test

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 388ad76cda785ebd1a687bd2a2e923b3233c13a3
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Sat Apr 25 12:41:49 2020 +0700

    JAMES-2810 Use a nested class for Consistency related test
    
     - Allows separate execution
     - Better expresses the intent
---
 .../CassandraDeletedMessageMetadataVaultTest.java  | 378 +++++++++++----------
 1 file changed, 191 insertions(+), 187 deletions(-)

diff --git a/mailbox/plugin/deleted-messages-vault-cassandra/src/test/java/org/apache/james/vault/metadata/CassandraDeletedMessageMetadataVaultTest.java b/mailbox/plugin/deleted-messages-vault-cassandra/src/test/java/org/apache/james/vault/metadata/CassandraDeletedMessageMetadataVaultTest.java
index 543646a..172385c 100644
--- a/mailbox/plugin/deleted-messages-vault-cassandra/src/test/java/org/apache/james/vault/metadata/CassandraDeletedMessageMetadataVaultTest.java
+++ b/mailbox/plugin/deleted-messages-vault-cassandra/src/test/java/org/apache/james/vault/metadata/CassandraDeletedMessageMetadataVaultTest.java
@@ -42,6 +42,7 @@ import org.apache.james.mailbox.inmemory.InMemoryMessageId;
 import org.apache.james.vault.dto.DeletedMessageWithStorageInformationConverter;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Nested;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.RegisterExtension;
 
@@ -75,247 +76,250 @@ public class CassandraDeletedMessageMetadataVaultTest implements DeletedMessageM
         return testee;
     }
 
-    @Test
-    void listShouldNotReturnMessagesWhenStorageDAOFailed() {
-        when(storageInformationDAO.referenceStorageInformation(USERNAME, MESSAGE_ID, STORAGE_INFORMATION))
-            .thenReturn(Mono.error(new RuntimeException()));
-
-        try {
-            Mono.from(testee.store(DELETED_MESSAGE)).block();
-        } catch (Exception e) {
-            // ignored
+    @Nested
+    class ConsistencyTest {
+        @Test
+        void listShouldNotReturnMessagesWhenStorageDAOFailed() {
+            when(storageInformationDAO.referenceStorageInformation(USERNAME, MESSAGE_ID, STORAGE_INFORMATION))
+                .thenReturn(Mono.error(new RuntimeException()));
+
+            try {
+                Mono.from(testee.store(DELETED_MESSAGE)).block();
+            } catch (Exception e) {
+                // ignored
+            }
+
+            Stream<DeletedMessageWithStorageInformation> messages = Flux.from(metadataVault().listMessages(BUCKET_NAME, USERNAME)).toStream();
+            assertThat(messages).isEmpty();
         }
 
-        Stream<DeletedMessageWithStorageInformation> messages = Flux.from(metadataVault().listMessages(BUCKET_NAME, USERNAME)).toStream();
-        assertThat(messages).isEmpty();
-    }
+        @Test
+        void listShouldNotReturnMessagesWhenMetadataDAOFailed() {
+            when(metadataDAO.store(DELETED_MESSAGE))
+                .thenReturn(Mono.error(new RuntimeException()));
 
-    @Test
-    void listShouldNotReturnMessagesWhenMetadataDAOFailed() {
-        when(metadataDAO.store(DELETED_MESSAGE))
-            .thenReturn(Mono.error(new RuntimeException()));
+            try {
+                Mono.from(testee.store(DELETED_MESSAGE)).block();
+            } catch (Exception e) {
+                // ignored
+            }
 
-        try {
-            Mono.from(testee.store(DELETED_MESSAGE)).block();
-        } catch (Exception e) {
-            // ignored
+            Stream<DeletedMessageWithStorageInformation> messages = Flux.from(metadataVault().listMessages(BUCKET_NAME, USERNAME)).toStream();
+            assertThat(messages).isEmpty();
         }
 
-        Stream<DeletedMessageWithStorageInformation> messages = Flux.from(metadataVault().listMessages(BUCKET_NAME, USERNAME)).toStream();
-        assertThat(messages).isEmpty();
-    }
-
-    @Test
-    void listShouldReturnMessagesWhenUserPerBucketDAOFailed() {
-        when(userPerBucketDAO.addUser(BUCKET_NAME, USERNAME))
-            .thenReturn(Mono.error(new RuntimeException()));
-
-        try {
-            Mono.from(testee.store(DELETED_MESSAGE)).block();
-        } catch (Exception e) {
-            // ignored
-        }
-
-        Stream<DeletedMessageWithStorageInformation> messages = Flux.from(metadataVault().listMessages(BUCKET_NAME, USERNAME)).toStream();
-        assertThat(messages).contains(DELETED_MESSAGE);
-    }
+        @Test
+        void listShouldReturnMessagesWhenUserPerBucketDAOFailed() {
+            when(userPerBucketDAO.addUser(BUCKET_NAME, USERNAME))
+                .thenReturn(Mono.error(new RuntimeException()));
 
-    @Test
-    void retrieveStorageInformationShouldReturnMetadataWhenUserPerBucketDAOStoreFailed() {
-        when(userPerBucketDAO.addUser(BUCKET_NAME, USERNAME))
-            .thenReturn(Mono.error(new RuntimeException()));
+            try {
+                Mono.from(testee.store(DELETED_MESSAGE)).block();
+            } catch (Exception e) {
+                // ignored
+            }
 
-        try {
-            Mono.from(testee.store(DELETED_MESSAGE)).block();
-        } catch (Exception e) {
-            // ignored
+            Stream<DeletedMessageWithStorageInformation> messages = Flux.from(metadataVault().listMessages(BUCKET_NAME, USERNAME)).toStream();
+            assertThat(messages).contains(DELETED_MESSAGE);
         }
 
-        Optional<StorageInformation> maybeInfo = Mono.from(metadataVault().retrieveStorageInformation(DELETED_MESSAGE.getDeletedMessage().getOwner(),
-            DELETED_MESSAGE.getDeletedMessage().getMessageId()))
-            .blockOptional();
-        assertThat(maybeInfo).isPresent();
-    }
-
-    @Disabled("The bucket being not referenced, the entry will not be dropped. Note that this get corrected by next " +
-        "metadata referenced for this user")
-    @Test
-    void removingBucketShouldCleanUpInvalidStateForList() {
-        when(userPerBucketDAO.addUser(BUCKET_NAME, USERNAME))
-            .thenReturn(Mono.error(new RuntimeException()));
-
-        try {
-            Mono.from(testee.store(DELETED_MESSAGE)).block();
-        } catch (Exception e) {
-            // ignored
+        @Test
+        void retrieveStorageInformationShouldReturnMetadataWhenUserPerBucketDAOStoreFailed() {
+            when(userPerBucketDAO.addUser(BUCKET_NAME, USERNAME))
+                .thenReturn(Mono.error(new RuntimeException()));
+
+            try {
+                Mono.from(testee.store(DELETED_MESSAGE)).block();
+            } catch (Exception e) {
+                // ignored
+            }
+
+            Optional<StorageInformation> maybeInfo = Mono.from(metadataVault().retrieveStorageInformation(DELETED_MESSAGE.getDeletedMessage().getOwner(),
+                DELETED_MESSAGE.getDeletedMessage().getMessageId()))
+                .blockOptional();
+            assertThat(maybeInfo).isPresent();
         }
 
-        Mono.from(testee.removeMetadataRelatedToBucket(BUCKET_NAME)).block();
+        @Disabled("The bucket being not referenced, the entry will not be dropped. Note that this get corrected by next " +
+            "metadata referenced for this user")
+        @Test
+        void removingBucketShouldCleanUpInvalidStateForList() {
+            when(userPerBucketDAO.addUser(BUCKET_NAME, USERNAME))
+                .thenReturn(Mono.error(new RuntimeException()));
 
-        Stream<DeletedMessageWithStorageInformation> messages = Flux.from(metadataVault().listMessages(BUCKET_NAME, USERNAME)).toStream();
-        assertThat(messages).isEmpty();
-    }
+            try {
+                Mono.from(testee.store(DELETED_MESSAGE)).block();
+            } catch (Exception e) {
+                // ignored
+            }
 
-    @Disabled("The bucket being not referenced, the entry will not be dropped. Note that this get corrected by next " +
-        "metadata referenced for this user")
-    @Test
-    void removingBucketShouldCleanUpInvalidStateForRetrievingMetadata() {
-        when(userPerBucketDAO.addUser(BUCKET_NAME, USERNAME))
-            .thenReturn(Mono.error(new RuntimeException()));
+            Mono.from(testee.removeMetadataRelatedToBucket(BUCKET_NAME)).block();
 
-        try {
-            Mono.from(testee.store(DELETED_MESSAGE)).block();
-        } catch (Exception e) {
-            // ignored
+            Stream<DeletedMessageWithStorageInformation> messages = Flux.from(metadataVault().listMessages(BUCKET_NAME, USERNAME)).toStream();
+            assertThat(messages).isEmpty();
         }
 
-        Mono.from(testee.removeMetadataRelatedToBucket(BUCKET_NAME)).block();
+        @Disabled("The bucket being not referenced, the entry will not be dropped. Note that this get corrected by next " +
+            "metadata referenced for this user")
+        @Test
+        void removingBucketShouldCleanUpInvalidStateForRetrievingMetadata() {
+            when(userPerBucketDAO.addUser(BUCKET_NAME, USERNAME))
+                .thenReturn(Mono.error(new RuntimeException()));
 
-        Optional<StorageInformation> maybeInfo = Mono.from(metadataVault().retrieveStorageInformation(DELETED_MESSAGE.getDeletedMessage().getOwner(),
-            DELETED_MESSAGE.getDeletedMessage().getMessageId()))
-            .blockOptional();
-        assertThat(maybeInfo).isEmpty();
-    }
+            try {
+                Mono.from(testee.store(DELETED_MESSAGE)).block();
+            } catch (Exception e) {
+                // ignored
+            }
 
-    @Test
-    void removingBucketShouldBeEventuallyConsistentForList() {
-        when(userPerBucketDAO.addUser(BUCKET_NAME, USERNAME))
-            .thenReturn(Mono.error(new RuntimeException()));
+            Mono.from(testee.removeMetadataRelatedToBucket(BUCKET_NAME)).block();
 
-        try {
-            Mono.from(testee.store(DELETED_MESSAGE)).block();
-        } catch (Exception e) {
-            // ignored
+            Optional<StorageInformation> maybeInfo = Mono.from(metadataVault().retrieveStorageInformation(DELETED_MESSAGE.getDeletedMessage().getOwner(),
+                DELETED_MESSAGE.getDeletedMessage().getMessageId()))
+                .blockOptional();
+            assertThat(maybeInfo).isEmpty();
         }
-        reset(userPerBucketDAO);
-        Mono.from(testee.store(DELETED_MESSAGE_2)).block();
 
-        Mono.from(testee.removeMetadataRelatedToBucket(BUCKET_NAME)).block();
+        @Test
+        void removingBucketShouldBeEventuallyConsistentForList() {
+            when(userPerBucketDAO.addUser(BUCKET_NAME, USERNAME))
+                .thenReturn(Mono.error(new RuntimeException()));
 
-        Stream<DeletedMessageWithStorageInformation> messages = Flux.from(metadataVault().listMessages(BUCKET_NAME, USERNAME)).toStream();
-        assertThat(messages).isEmpty();
-    }
+            try {
+                Mono.from(testee.store(DELETED_MESSAGE)).block();
+            } catch (Exception e) {
+                // ignored
+            }
+            reset(userPerBucketDAO);
+            Mono.from(testee.store(DELETED_MESSAGE_2)).block();
 
-    @Test
-    void removingBucketShouldBeEventuallyConsistentForMetadata() {
-        when(userPerBucketDAO.addUser(BUCKET_NAME, USERNAME))
-            .thenReturn(Mono.error(new RuntimeException()));
+            Mono.from(testee.removeMetadataRelatedToBucket(BUCKET_NAME)).block();
 
-        try {
-            Mono.from(testee.store(DELETED_MESSAGE)).block();
-        } catch (Exception e) {
-            // ignored
+            Stream<DeletedMessageWithStorageInformation> messages = Flux.from(metadataVault().listMessages(BUCKET_NAME, USERNAME)).toStream();
+            assertThat(messages).isEmpty();
         }
-        reset(userPerBucketDAO);
-        Mono.from(testee.store(DELETED_MESSAGE_2)).block();
 
-        Mono.from(testee.removeMetadataRelatedToBucket(BUCKET_NAME)).block();
+        @Test
+        void removingBucketShouldBeEventuallyConsistentForMetadata() {
+            when(userPerBucketDAO.addUser(BUCKET_NAME, USERNAME))
+                .thenReturn(Mono.error(new RuntimeException()));
 
-        Optional<StorageInformation> maybeInfo = Mono.from(metadataVault().retrieveStorageInformation(DELETED_MESSAGE.getDeletedMessage().getOwner(),
-            DELETED_MESSAGE.getDeletedMessage().getMessageId()))
-            .blockOptional();
-        assertThat(maybeInfo).isEmpty();
-    }
+            try {
+                Mono.from(testee.store(DELETED_MESSAGE)).block();
+            } catch (Exception e) {
+                // ignored
+            }
+            reset(userPerBucketDAO);
+            Mono.from(testee.store(DELETED_MESSAGE_2)).block();
 
-    @Test
-    void directDeletionShouldCleanUpInvalidStateForList() {
-        when(userPerBucketDAO.addUser(BUCKET_NAME, USERNAME))
-            .thenReturn(Mono.error(new RuntimeException()));
+            Mono.from(testee.removeMetadataRelatedToBucket(BUCKET_NAME)).block();
 
-        try {
-            Mono.from(testee.store(DELETED_MESSAGE)).block();
-        } catch (Exception e) {
-            // ignored
+            Optional<StorageInformation> maybeInfo = Mono.from(metadataVault().retrieveStorageInformation(DELETED_MESSAGE.getDeletedMessage().getOwner(),
+                DELETED_MESSAGE.getDeletedMessage().getMessageId()))
+                .blockOptional();
+            assertThat(maybeInfo).isEmpty();
         }
 
-        Mono.from(metadataVault().remove(BUCKET_NAME,
-            DELETED_MESSAGE.getDeletedMessage().getOwner(),
-            DELETED_MESSAGE.getDeletedMessage().getMessageId()))
-            .block();
+        @Test
+        void directDeletionShouldCleanUpInvalidStateForList() {
+            when(userPerBucketDAO.addUser(BUCKET_NAME, USERNAME))
+                .thenReturn(Mono.error(new RuntimeException()));
 
-        Stream<DeletedMessageWithStorageInformation> messages = Flux.from(metadataVault().listMessages(BUCKET_NAME, USERNAME)).toStream();
-        assertThat(messages).isEmpty();
-    }
+            try {
+                Mono.from(testee.store(DELETED_MESSAGE)).block();
+            } catch (Exception e) {
+                // ignored
+            }
 
-    @Test
-    void directDeletionShouldCleanUpInvalidStateForRetrievingMetadata() {
-        when(userPerBucketDAO.addUser(BUCKET_NAME, USERNAME))
-            .thenReturn(Mono.error(new RuntimeException()));
+            Mono.from(metadataVault().remove(BUCKET_NAME,
+                DELETED_MESSAGE.getDeletedMessage().getOwner(),
+                DELETED_MESSAGE.getDeletedMessage().getMessageId()))
+                .block();
 
-        try {
-            Mono.from(testee.store(DELETED_MESSAGE)).block();
-        } catch (Exception e) {
-            // ignored
+            Stream<DeletedMessageWithStorageInformation> messages = Flux.from(metadataVault().listMessages(BUCKET_NAME, USERNAME)).toStream();
+            assertThat(messages).isEmpty();
         }
 
-        Mono.from(metadataVault().remove(BUCKET_NAME,
-            DELETED_MESSAGE.getDeletedMessage().getOwner(),
-            DELETED_MESSAGE.getDeletedMessage().getMessageId()))
-            .block();
+        @Test
+        void directDeletionShouldCleanUpInvalidStateForRetrievingMetadata() {
+            when(userPerBucketDAO.addUser(BUCKET_NAME, USERNAME))
+                .thenReturn(Mono.error(new RuntimeException()));
+
+            try {
+                Mono.from(testee.store(DELETED_MESSAGE)).block();
+            } catch (Exception e) {
+                // ignored
+            }
+
+            Mono.from(metadataVault().remove(BUCKET_NAME,
+                DELETED_MESSAGE.getDeletedMessage().getOwner(),
+                DELETED_MESSAGE.getDeletedMessage().getMessageId()))
+                .block();
+
+            Optional<StorageInformation> maybeInfo = Mono.from(metadataVault().retrieveStorageInformation(DELETED_MESSAGE.getDeletedMessage().getOwner(),
+                DELETED_MESSAGE.getDeletedMessage().getMessageId()))
+                .blockOptional();
+            assertThat(maybeInfo).isEmpty();
+        }
 
-        Optional<StorageInformation> maybeInfo = Mono.from(metadataVault().retrieveStorageInformation(DELETED_MESSAGE.getDeletedMessage().getOwner(),
-            DELETED_MESSAGE.getDeletedMessage().getMessageId()))
-            .blockOptional();
-        assertThat(maybeInfo).isEmpty();
-    }
+        @Test
+        void retentionShouldBeRetriableWhenUserPerBucketDAOFails() {
+            Mono.from(testee.store(DELETED_MESSAGE)).block();
 
-    @Test
-    void retentionShouldBeRetriableWhenUserPerBucketDAOFails() {
-        Mono.from(testee.store(DELETED_MESSAGE)).block();
+            when(userPerBucketDAO.deleteBucket(BUCKET_NAME))
+                .thenReturn(Mono.error(new RuntimeException()));
 
-        when(userPerBucketDAO.deleteBucket(BUCKET_NAME))
-            .thenReturn(Mono.error(new RuntimeException()));
+            try {
+                Mono.from(testee.removeMetadataRelatedToBucket(BUCKET_NAME)).block();
+            } catch (Exception e) {
+                // ignored
+            }
 
-        try {
+            reset(userPerBucketDAO);
             Mono.from(testee.removeMetadataRelatedToBucket(BUCKET_NAME)).block();
-        } catch (Exception e) {
-            // ignored
-        }
 
-        reset(userPerBucketDAO);
-        Mono.from(testee.removeMetadataRelatedToBucket(BUCKET_NAME)).block();
+            Stream<DeletedMessageWithStorageInformation> messages = Flux.from(metadataVault().listMessages(BUCKET_NAME, USERNAME)).toStream();
+            assertThat(messages).isEmpty();
+        }
 
-        Stream<DeletedMessageWithStorageInformation> messages = Flux.from(metadataVault().listMessages(BUCKET_NAME, USERNAME)).toStream();
-        assertThat(messages).isEmpty();
-    }
+        @Test
+        void retentionShouldBeRetriableWhenMetadataDAOFails() {
+            Mono.from(testee.store(DELETED_MESSAGE)).block();
 
-    @Test
-    void retentionShouldBeRetriableWhenMetadataDAOFails() {
-        Mono.from(testee.store(DELETED_MESSAGE)).block();
+            when(metadataDAO.deleteInBucket(BUCKET_NAME, USERNAME))
+                .thenReturn(Mono.error(new RuntimeException()));
 
-        when(metadataDAO.deleteInBucket(BUCKET_NAME, USERNAME))
-            .thenReturn(Mono.error(new RuntimeException()));
+            try {
+                Mono.from(testee.removeMetadataRelatedToBucket(BUCKET_NAME)).block();
+            } catch (Exception e) {
+                // ignored
+            }
 
-        try {
+            reset(metadataDAO);
             Mono.from(testee.removeMetadataRelatedToBucket(BUCKET_NAME)).block();
-        } catch (Exception e) {
-            // ignored
-        }
 
-        reset(metadataDAO);
-        Mono.from(testee.removeMetadataRelatedToBucket(BUCKET_NAME)).block();
+            Stream<DeletedMessageWithStorageInformation> messages = Flux.from(metadataVault().listMessages(BUCKET_NAME, USERNAME)).toStream();
+            assertThat(messages).isEmpty();
+        }
 
-        Stream<DeletedMessageWithStorageInformation> messages = Flux.from(metadataVault().listMessages(BUCKET_NAME, USERNAME)).toStream();
-        assertThat(messages).isEmpty();
-    }
+        @Test
+        void retentionShouldBeRetriableWhenStorageInformationDAOFails() {
+            Mono.from(testee.store(DELETED_MESSAGE)).block();
 
-    @Test
-    void retentionShouldBeRetriableWhenStorageInformationDAOFails() {
-        Mono.from(testee.store(DELETED_MESSAGE)).block();
+            when(storageInformationDAO.deleteStorageInformation(USERNAME, MESSAGE_ID))
+                .thenReturn(Mono.error(new RuntimeException()));
 
-        when(storageInformationDAO.deleteStorageInformation(USERNAME, MESSAGE_ID))
-            .thenReturn(Mono.error(new RuntimeException()));
+            try {
+                Mono.from(testee.removeMetadataRelatedToBucket(BUCKET_NAME)).block();
+            } catch (Exception e) {
+                // ignored
+            }
 
-        try {
+            reset(storageInformationDAO);
             Mono.from(testee.removeMetadataRelatedToBucket(BUCKET_NAME)).block();
-        } catch (Exception e) {
-            // ignored
-        }
 
-        reset(storageInformationDAO);
-        Mono.from(testee.removeMetadataRelatedToBucket(BUCKET_NAME)).block();
-
-        Stream<DeletedMessageWithStorageInformation> messages = Flux.from(metadataVault().listMessages(BUCKET_NAME, USERNAME)).toStream();
-        assertThat(messages).isEmpty();
+            Stream<DeletedMessageWithStorageInformation> messages = Flux.from(metadataVault().listMessages(BUCKET_NAME, USERNAME)).toStream();
+            assertThat(messages).isEmpty();
+        }
     }
 }
\ 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