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/07/28 03:20:28 UTC

[james-project] branch master updated (26268b1 -> 2de38df)

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

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


    from 26268b1  JAMES-3224 Use CassandraConsistenciesConfiguration for default consistency levels
     new e104e7c  JAMES-3344 Upgrade Bouncy Castle to last version
     new 810c97e  [Refactoring] Migrate GenericMailetTest to Junit 5
     new fcf79b5  [Refactoring] Migrate MailetPipelineLoggingTest to Junit 5
     new 6b640ca  [Refactoring] Migrate MailetUtilTest to Junit 5
     new fe001ce  [Refactoring] Migrate MatcherInverterTest to Junit 5
     new 8bea2b4  [Refactoring] Migrate StringUtilsTest to Junit 5
     new fb3dc2a  [Refactoring] Migrate ICalendarParserTest to Junit 5
     new 0953a85  [Refactoring] Migrate ICALToHeadersTest to Junit 5
     new f2351ec  [Refactoring] Migrate ICALAttributeDTOTest to Junit 5
     new be74e50  [Refactoring] Migrate DefaultDescriptorsExtractorTest to Junit 5
     new 75ad3e2  JAMES-3318 Remove BlobStore::delete from BlobStore contract
     new 71187b5  JAMES-3318 BlobStoreDeletedMessageVault should use DumbBlobStore for effective deletion
     new f4ff554  JAMES-3318 Deduplication BlobStore::delete should be a noop operation
     new aa0e6e7  JAMES-3319 FetchType is no longer relevant to fetch messageDao rows
     new f9a8477  JAMES-3319 Actual Message & Attachment deletion for mailbox/cassandra
     new ecbd1c3  JAMES-3319 Tests for CassandraMailRepository blob deletion
     new 1bcc8f7  JAMES-3319 Decrease the test count for storingAndRemovingMessagesConcurrentlyShouldLeadToConsistentResult
     new b5c4607  JAMES-3319 Rewrite a failure test to leverage Cassandra instrumentation
     new 87a0d25  JAMES-3319 Tests for CassandraMailRepository blob deletion
     new 948f29a  JAMES-3319 Rely on Cassandra instrumentation for CassandraMailRepository failure tests
     new ff850ea  JAMES-3319 Simplify CassandraMailRepository constructors
     new 74311ad  JAMES-3319 Actual blob deletion for CassandraMailRepository
     new 110947c  JAMES-3319 MimeMessageStore should support deletion
     new d27ac6a  JAMES-3310 Make DeletedMessageVaultHook failure sensitive
     new 2de38df  JAMES-3157 Fix support for bench profiles

The 25 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:
 JenkinsfileStressTests.groovy                      |   4 +-
 .../CassandraMailboxSessionMapperFactory.java      |   2 +-
 .../mailbox/cassandra/DeleteMessageListener.java   |  20 ++-
 .../cassandra/mail/CassandraMessageDAO.java        |  73 +++------
 .../cassandra/mail/MessageRepresentation.java      |  15 +-
 .../cassandra/table/CassandraMessageV2Table.java   |   7 -
 .../cassandra/CassandraMailboxManagerTest.java     |  24 +++
 .../cassandra/mail/CassandraMessageDAOTest.java    |   3 +-
 .../cassandra/mail/CassandraMessageMapperTest.java |   3 +-
 .../mailbox/cassandra/mail/utils/GuiceUtils.java   |   2 +-
 .../james/vault/DeletedMessageVaultHook.java       |   1 +
 .../vault/blob/BlobStoreDeletedMessageVault.java   |   7 +-
 .../james/vault/DeletedMessageVaultHookTest.java   |   9 +-
 .../blob/BlobStoreDeletedMessageVaultTest.java     |   9 +-
 .../tools/indexer/CassandraReIndexerImplTest.java  |   2 +-
 .../org/apache/mailet/base/GenericMailetTest.java  |  28 ++--
 .../mailet/base/MailetPipelineLoggingTest.java     |  31 ++--
 .../org/apache/mailet/base/MailetUtilTest.java     | 128 ++++++++-------
 .../apache/mailet/base/MatcherInverterTest.java    |  15 +-
 .../org/apache/mailet/base/StringUtilsTest.java    |  31 ++--
 .../james/transport/mailets/ICALToHeadersTest.java |  82 +++++-----
 .../transport/mailets/ICalendarParserTest.java     |  84 +++++-----
 .../mailets/model/ICALAttributeDTOTest.java        |  95 +++++------
 .../mailet/DefaultDescriptorsExtractorTest.java    |  20 +--
 pom.xml                                            |   2 +-
 .../apache/james/blob/api/BlobStoreContract.java   |   2 +-
 .../blob/cassandra/CassandraBlobStoreFactory.java  |   6 +-
 .../CassandraPassTroughBlobStoreTest.java          |   3 +-
 .../blob/cassandra/cache/CachedBlobStoreTest.java  |   3 +-
 .../main/java/org/apache/james/blob/api/Store.java |   9 ++
 .../memory/MemoryBlobStorePassThroughTest.java     |   3 +-
 .../blob/objectstorage/ObjectStorageBlobStore.java |   5 +
 .../ObjectStorageBlobStoreAWSCryptoTest.java       |  13 --
 .../ObjectStorageBlobStoreAWSNamespaceTest.java    |  13 --
 ...tStorageBlobStoreAWSPrefixAndNamespaceTest.java |  13 --
 .../ObjectStorageBlobStoreAWSPrefixTest.java       |  13 --
 .../ObjectStorageBlobStoreAWSTest.java             |  13 --
 .../deduplication/DeDuplicationBlobStore.scala     |   2 +-
 .../james/blob/mail/MimeMessageStoreTest.java      |  30 ++++
 .../modules/blobstore/BlobStoreModulesChooser.java |   1 +
 .../james/modules/blobstore/NoopDumbBlobStore.java |  83 ++++++++++
 .../mailrepository/MailRepositoryContract.java     |   2 +-
 .../cassandra/CassandraMailRepository.java         |  35 +++--
 .../cassandra/CassandraMailRepositoryTest.java     | 101 +++++++++---
 ...aMailRepositoryWithFakeImplementationsTest.java | 173 +++++++--------------
 .../routes/DeletedMessagesVaultRoutesTest.java     |   9 +-
 .../RabbitMQMailQueueConfigurationChangeTest.java  |   3 +-
 .../queue/rabbitmq/RabbitMQMailQueueTest.java      |   3 +-
 48 files changed, 669 insertions(+), 566 deletions(-)
 create mode 100644 server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/modules/blobstore/NoopDumbBlobStore.java


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


[james-project] 21/25: JAMES-3319 Simplify CassandraMailRepository constructors

Posted by rc...@apache.org.
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 ff850eac496b19ac149ff7940ffc979558cb563f
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Jul 24 11:56:43 2020 +0700

    JAMES-3319 Simplify CassandraMailRepository constructors
---
 .../james/mailrepository/cassandra/CassandraMailRepository.java   | 8 +-------
 .../mailrepository/cassandra/CassandraMailRepositoryTest.java     | 4 ++--
 .../CassandraMailRepositoryWithFakeImplementationsTest.java       | 2 +-
 3 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/server/mailrepository/mailrepository-cassandra/src/main/java/org/apache/james/mailrepository/cassandra/CassandraMailRepository.java b/server/mailrepository/mailrepository-cassandra/src/main/java/org/apache/james/mailrepository/cassandra/CassandraMailRepository.java
index 134d969..f2b5168 100644
--- a/server/mailrepository/mailrepository-cassandra/src/main/java/org/apache/james/mailrepository/cassandra/CassandraMailRepository.java
+++ b/server/mailrepository/mailrepository-cassandra/src/main/java/org/apache/james/mailrepository/cassandra/CassandraMailRepository.java
@@ -51,17 +51,11 @@ public class CassandraMailRepository implements MailRepository {
     CassandraMailRepository(MailRepositoryUrl url, CassandraMailRepositoryKeysDAO keysDAO,
                             CassandraMailRepositoryCountDAO countDAO, CassandraMailRepositoryMailDaoAPI mailDAO,
                             MimeMessageStore.Factory mimeMessageStoreFactory) {
-        this(url, keysDAO, countDAO, mailDAO, mimeMessageStoreFactory.mimeMessageStore());
-    }
-
-    CassandraMailRepository(MailRepositoryUrl url, CassandraMailRepositoryKeysDAO keysDAO,
-                            CassandraMailRepositoryCountDAO countDAO, CassandraMailRepositoryMailDaoAPI mailDAO,
-                            Store<MimeMessage, MimeMessagePartsId> mimeMessageStore) {
         this.url = url;
         this.keysDAO = keysDAO;
         this.countDAO = countDAO;
         this.mailDAO = mailDAO;
-        this.mimeMessageStore = mimeMessageStore;
+        this.mimeMessageStore = mimeMessageStoreFactory.mimeMessageStore();
     }
 
     @Override
diff --git a/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryTest.java b/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryTest.java
index 9ff4496..6d6e443 100644
--- a/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryTest.java
+++ b/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryTest.java
@@ -70,7 +70,7 @@ class CassandraMailRepositoryTest {
                 .passthrough();
 
             cassandraMailRepository = new CassandraMailRepository(URL,
-                keysDAO, countDAO, mailDAO, MimeMessageStore.factory(blobStore).mimeMessageStore());
+                keysDAO, countDAO, mailDAO, MimeMessageStore.factory(blobStore));
         }
 
         @Override
@@ -111,7 +111,7 @@ class CassandraMailRepositoryTest {
                 .deduplication();
 
             cassandraMailRepository = new CassandraMailRepository(URL,
-                keysDAO, countDAO, mailDAO, MimeMessageStore.factory(blobStore).mimeMessageStore());
+                keysDAO, countDAO, mailDAO, MimeMessageStore.factory(blobStore));
         }
 
         @Override
diff --git a/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryWithFakeImplementationsTest.java b/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryWithFakeImplementationsTest.java
index 027f1e9..a420ac5 100644
--- a/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryWithFakeImplementationsTest.java
+++ b/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryWithFakeImplementationsTest.java
@@ -70,7 +70,7 @@ class CassandraMailRepositoryWithFakeImplementationsTest {
             .passthrough();
 
         cassandraMailRepository = new CassandraMailRepository(URL,
-            keysDAO, countDAO, mailDAO, MimeMessageStore.factory(blobStore).mimeMessageStore());
+            keysDAO, countDAO, mailDAO, MimeMessageStore.factory(blobStore));
     }
 
     @Nested


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


[james-project] 05/25: [Refactoring] Migrate MatcherInverterTest to Junit 5

Posted by rc...@apache.org.
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 fe001cef1953af268b4ce413cc01c99eb5ef174a
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Fri Jul 24 14:55:10 2020 +0700

    [Refactoring] Migrate MatcherInverterTest to Junit 5
---
 .../java/org/apache/mailet/base/MatcherInverterTest.java  | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/mailet/base/src/test/java/org/apache/mailet/base/MatcherInverterTest.java b/mailet/base/src/test/java/org/apache/mailet/base/MatcherInverterTest.java
index 0bd29f7..68cd987 100644
--- a/mailet/base/src/test/java/org/apache/mailet/base/MatcherInverterTest.java
+++ b/mailet/base/src/test/java/org/apache/mailet/base/MatcherInverterTest.java
@@ -29,19 +29,19 @@ import javax.mail.MessagingException;
 import org.apache.james.core.MailAddress;
 import org.apache.mailet.Mail;
 import org.apache.mailet.base.test.FakeMail;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-public class MatcherInverterTest {
+class MatcherInverterTest {
 
     @Test
-    public void testAllMatch() throws MessagingException {
+    void testAllMatch() throws MessagingException {
         MatcherInverter inverter = new MatcherInverter(new GenericMatcher() {
-
             @Override
             public Collection<MailAddress> match(Mail mail) throws MessagingException {
                 return null;
             }
         });
+
         FakeMail mail = FakeMail.builder()
                 .name("mail")
                 .recipient(new MailAddress("user", "domain"))
@@ -51,7 +51,7 @@ public class MatcherInverterTest {
     }
 
     @Test
-    public void testNonMatch() throws MessagingException {
+    void testNonMatch() throws MessagingException {
         final MailAddress address1 = new MailAddress("user", "domain");
         final MailAddress address2 = new MailAddress("user", "domain2");
 
@@ -62,6 +62,7 @@ public class MatcherInverterTest {
                 return mail.getRecipients();
             }
         });
+
         FakeMail mail = FakeMail.builder()
                 .name("mail")
                 .recipients(address1, address2)
@@ -71,17 +72,17 @@ public class MatcherInverterTest {
     }
 
     @Test
-    public void testOneMatch() throws MessagingException {
+    void testOneMatch() throws MessagingException {
         final MailAddress address1 = new MailAddress("user", "domain");
         final MailAddress address2 = new MailAddress("user", "domain2");
 
         MatcherInverter inverter = new MatcherInverter(new GenericMatcher() {
-
             @Override
             public Collection<MailAddress> match(Mail mail) throws MessagingException {
                 return Arrays.asList(address1);
             }
         });
+
         FakeMail mail = FakeMail.builder()
                 .name("mail")
                 .recipients(address1, address2)


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


[james-project] 16/25: JAMES-3319 Tests for CassandraMailRepository blob deletion

Posted by rc...@apache.org.
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 ecbd1c3b5df2fb8fd9f8cb36eadcd1eb5ca419fe
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Jul 24 11:30:05 2020 +0700

    JAMES-3319 Tests for CassandraMailRepository blob deletion
    
    Tests are conducted out both on Deduplication & Passthrough BlobStores
---
 .../cassandra/mail/CassandraMessageDAOTest.java    |   3 +-
 .../mailbox/cassandra/mail/utils/GuiceUtils.java   |   2 +-
 .../blob/cassandra/CassandraBlobStoreFactory.java  |   6 +-
 .../blob/cassandra/cache/CachedBlobStoreTest.java  |   3 +-
 .../cassandra/CassandraMailRepositoryTest.java     | 100 +++++++++++++++++----
 ...aMailRepositoryWithFakeImplementationsTest.java |   6 +-
 .../RabbitMQMailQueueConfigurationChangeTest.java  |   3 +-
 .../queue/rabbitmq/RabbitMQMailQueueTest.java      |   3 +-
 8 files changed, 96 insertions(+), 30 deletions(-)

diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAOTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAOTest.java
index a58595c..7fa6f49 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAOTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAOTest.java
@@ -86,7 +86,8 @@ class CassandraMessageDAOTest {
     void setUp(CassandraCluster cassandra) {
         messageIdFactory = new CassandraMessageId.Factory();
         messageId = messageIdFactory.generate();
-        BlobStore blobStore = CassandraBlobStoreFactory.forTesting(cassandra.getConf());
+        BlobStore blobStore = CassandraBlobStoreFactory.forTesting(cassandra.getConf())
+            .passthrough();
         HashBlobId.Factory blobIdFactory = new HashBlobId.Factory();
         testee = new CassandraMessageDAO(
             cassandra.getConf(),
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/utils/GuiceUtils.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/utils/GuiceUtils.java
index 39e539d..a6d8883 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/utils/GuiceUtils.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/utils/GuiceUtils.java
@@ -59,7 +59,7 @@ public class GuiceUtils {
         return Modules.combine(
             binder -> binder.bind(MessageId.Factory.class).toInstance(messageIdFactory),
             binder -> binder.bind(BlobId.Factory.class).toInstance(new HashBlobId.Factory()),
-            binder -> binder.bind(BlobStore.class).toProvider(() -> CassandraBlobStoreFactory.forTesting(session)),
+            binder -> binder.bind(BlobStore.class).toProvider(() -> CassandraBlobStoreFactory.forTesting(session).passthrough()),
             binder -> binder.bind(Session.class).toInstance(session),
             binder -> binder.bind(CassandraTypesProvider.class).toInstance(typesProvider),
             binder -> binder.bind(CassandraConfiguration.class).toInstance(configuration),
diff --git a/server/blob/blob-cassandra/src/main/java/org/apache/james/blob/cassandra/CassandraBlobStoreFactory.java b/server/blob/blob-cassandra/src/main/java/org/apache/james/blob/cassandra/CassandraBlobStoreFactory.java
index f1d0576..5dc2d8f 100644
--- a/server/blob/blob-cassandra/src/main/java/org/apache/james/blob/cassandra/CassandraBlobStoreFactory.java
+++ b/server/blob/blob-cassandra/src/main/java/org/apache/james/blob/cassandra/CassandraBlobStoreFactory.java
@@ -20,7 +20,6 @@
 package org.apache.james.blob.cassandra;
 
 import org.apache.james.backends.cassandra.init.configuration.CassandraConfiguration;
-import org.apache.james.blob.api.BlobStore;
 import org.apache.james.blob.api.BucketName;
 import org.apache.james.blob.api.HashBlobId;
 import org.apache.james.server.blob.deduplication.BlobStoreFactory;
@@ -28,14 +27,13 @@ import org.apache.james.server.blob.deduplication.BlobStoreFactory;
 import com.datastax.driver.core.Session;
 
 public class CassandraBlobStoreFactory {
-    public static BlobStore forTesting(Session session) {
+    public static BlobStoreFactory.RequireStoringStrategy forTesting(Session session) {
         HashBlobId.Factory blobIdFactory = new HashBlobId.Factory();
         CassandraBucketDAO bucketDAO = new CassandraBucketDAO(blobIdFactory, session);
         CassandraDefaultBucketDAO defaultBucketDAO = new CassandraDefaultBucketDAO(session);
         CassandraDumbBlobStore dumbBlobStore = new CassandraDumbBlobStore(defaultBucketDAO, bucketDAO, CassandraConfiguration.DEFAULT_CONFIGURATION, BucketName.DEFAULT);
         return BlobStoreFactory.builder().dumbBlobStore(dumbBlobStore)
             .blobIdFactory(blobIdFactory)
-            .defaultBucketName()
-            .passthrough();
+            .defaultBucketName();
     }
 }
diff --git a/server/blob/blob-cassandra/src/test/java/org/apache/james/blob/cassandra/cache/CachedBlobStoreTest.java b/server/blob/blob-cassandra/src/test/java/org/apache/james/blob/cassandra/cache/CachedBlobStoreTest.java
index 34ed1be..bf0a405 100644
--- a/server/blob/blob-cassandra/src/test/java/org/apache/james/blob/cassandra/cache/CachedBlobStoreTest.java
+++ b/server/blob/blob-cassandra/src/test/java/org/apache/james/blob/cassandra/cache/CachedBlobStoreTest.java
@@ -74,7 +74,8 @@ public class CachedBlobStoreTest implements BlobStoreContract {
 
     @BeforeEach
     void setUp(CassandraCluster cassandra) {
-        backend = CassandraBlobStoreFactory.forTesting(cassandra.getConf());
+        backend = CassandraBlobStoreFactory.forTesting(cassandra.getConf())
+            .passthrough();
         CassandraCacheConfiguration cacheConfig = new CassandraCacheConfiguration.Builder()
             .sizeThresholdInBytes(EIGHT_KILOBYTES.length + 1)
             .timeOut(Duration.ofSeconds(60))
diff --git a/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryTest.java b/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryTest.java
index 0a3be14..3011e98 100644
--- a/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryTest.java
+++ b/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryTest.java
@@ -19,6 +19,9 @@
 
 package org.apache.james.mailrepository.cassandra;
 
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatCode;
+
 import org.apache.james.backends.cassandra.CassandraCluster;
 import org.apache.james.backends.cassandra.CassandraClusterExtension;
 import org.apache.james.backends.cassandra.components.CassandraModule;
@@ -30,14 +33,16 @@ import org.apache.james.blob.cassandra.CassandraBlobModule;
 import org.apache.james.blob.cassandra.CassandraBlobStoreFactory;
 import org.apache.james.blob.mail.MimeMessageStore;
 import org.apache.james.mailrepository.MailRepositoryContract;
+import org.apache.james.mailrepository.api.MailKey;
 import org.apache.james.mailrepository.api.MailRepository;
 import org.apache.james.mailrepository.api.MailRepositoryUrl;
 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;
 
-class CassandraMailRepositoryTest implements MailRepositoryContract {
+class CassandraMailRepositoryTest {
     static final MailRepositoryUrl URL = MailRepositoryUrl.from("proto://url");
     static final HashBlobId.Factory BLOB_ID_FACTORY = new HashBlobId.Factory();
 
@@ -50,29 +55,86 @@ class CassandraMailRepositoryTest implements MailRepositoryContract {
 
     CassandraMailRepository cassandraMailRepository;
 
+    @Nested
+    class PassThroughTest implements MailRepositoryContract {
+        @BeforeEach
+        void setup(CassandraCluster cassandra) {
+            CassandraMailRepositoryMailDAO v1 = new CassandraMailRepositoryMailDAO(cassandra.getConf(), BLOB_ID_FACTORY, cassandra.getTypesProvider());
+            CassandraMailRepositoryMailDaoV2 v2 = new CassandraMailRepositoryMailDaoV2(cassandra.getConf(), BLOB_ID_FACTORY);
+            CassandraMailRepositoryMailDaoAPI mailDAO = new MergingCassandraMailRepositoryMailDao(v1, v2);
+            CassandraMailRepositoryKeysDAO keysDAO = new CassandraMailRepositoryKeysDAO(cassandra.getConf(), CassandraUtils.WITH_DEFAULT_CONFIGURATION);
+            CassandraMailRepositoryCountDAO countDAO = new CassandraMailRepositoryCountDAO(cassandra.getConf());
+            BlobStore blobStore = CassandraBlobStoreFactory.forTesting(cassandra.getConf())
+                .passthrough();
 
-    @BeforeEach
-    void setup(CassandraCluster cassandra) {
-        CassandraMailRepositoryMailDAO v1 = new CassandraMailRepositoryMailDAO(cassandra.getConf(), BLOB_ID_FACTORY, cassandra.getTypesProvider());
-        CassandraMailRepositoryMailDaoV2 v2 = new CassandraMailRepositoryMailDaoV2(cassandra.getConf(), BLOB_ID_FACTORY);
-        CassandraMailRepositoryMailDaoAPI mailDAO = new MergingCassandraMailRepositoryMailDao(v1, v2);
-        CassandraMailRepositoryKeysDAO keysDAO = new CassandraMailRepositoryKeysDAO(cassandra.getConf(), CassandraUtils.WITH_DEFAULT_CONFIGURATION);
-        CassandraMailRepositoryCountDAO countDAO = new CassandraMailRepositoryCountDAO(cassandra.getConf());
-        BlobStore blobStore = CassandraBlobStoreFactory.forTesting(cassandra.getConf());
+            cassandraMailRepository = new CassandraMailRepository(URL,
+                keysDAO, countDAO, mailDAO, MimeMessageStore.factory(blobStore).mimeMessageStore());
+        }
 
-        cassandraMailRepository = new CassandraMailRepository(URL,
-            keysDAO, countDAO, mailDAO, MimeMessageStore.factory(blobStore).mimeMessageStore());
-    }
+        @Override
+        public MailRepository retrieveRepository() {
+            return cassandraMailRepository;
+        }
+
+        @Test
+        @Disabled("key is unique in Cassandra")
+        @Override
+        public void sizeShouldBeIncrementedByOneWhenDuplicates() {
+        }
+
+        @Disabled("Failing")
+        @Test
+        void removeShouldDeleteStoredBlobs(CassandraCluster cassandra) throws Exception {
+            MailRepository testee = retrieveRepository();
 
-    @Override
-    public MailRepository retrieveRepository() {
-        return cassandraMailRepository;
+            MailKey key1 = testee.store(createMail(MAIL_1));
+
+            testee.remove(key1);
+
+            assertThat(cassandra.getConf().execute("SELECT * FROM blobs;"))
+                .isEmpty();
+        }
     }
 
-    @Test
-    @Disabled("key is unique in Cassandra")
-    @Override
-    public void sizeShouldBeIncrementedByOneWhenDuplicates() {
+    @Nested
+    class DeDuplicationTest implements MailRepositoryContract {
+        @BeforeEach
+        void setup(CassandraCluster cassandra) {
+            CassandraMailRepositoryMailDAO v1 = new CassandraMailRepositoryMailDAO(cassandra.getConf(), BLOB_ID_FACTORY, cassandra.getTypesProvider());
+            CassandraMailRepositoryMailDaoV2 v2 = new CassandraMailRepositoryMailDaoV2(cassandra.getConf(), BLOB_ID_FACTORY);
+            CassandraMailRepositoryMailDaoAPI mailDAO = new MergingCassandraMailRepositoryMailDao(v1, v2);
+            CassandraMailRepositoryKeysDAO keysDAO = new CassandraMailRepositoryKeysDAO(cassandra.getConf(), CassandraUtils.WITH_DEFAULT_CONFIGURATION);
+            CassandraMailRepositoryCountDAO countDAO = new CassandraMailRepositoryCountDAO(cassandra.getConf());
+            BlobStore blobStore = CassandraBlobStoreFactory.forTesting(cassandra.getConf())
+                .deduplication();
+
+            cassandraMailRepository = new CassandraMailRepository(URL,
+                keysDAO, countDAO, mailDAO, MimeMessageStore.factory(blobStore).mimeMessageStore());
+        }
+
+        @Override
+        public MailRepository retrieveRepository() {
+            return cassandraMailRepository;
+        }
+
+        @Test
+        @Disabled("key is unique in Cassandra")
+        @Override
+        public void sizeShouldBeIncrementedByOneWhenDuplicates() {
+        }
+
+        @Test
+        void removeShouldNotAffectMailsWithTheSameContent() throws Exception {
+            MailRepository testee = retrieveRepository();
+
+            MailKey key1 = testee.store(createMail(MAIL_1));
+            MailKey key2 = testee.store(createMail(MAIL_2));
+
+            testee.remove(key1);
+
+            assertThatCode(() -> testee.retrieve(key2))
+                .doesNotThrowAnyException();
+        }
     }
 
 }
\ No newline at end of file
diff --git a/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryWithFakeImplementationsTest.java b/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryWithFakeImplementationsTest.java
index 648a6e9..60f6ad9 100644
--- a/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryWithFakeImplementationsTest.java
+++ b/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryWithFakeImplementationsTest.java
@@ -128,7 +128,8 @@ class CassandraMailRepositoryWithFakeImplementationsTest {
             FailingMailDAO mailDAO = new FailingMailDAO();
             keysDAO = new CassandraMailRepositoryKeysDAO(cassandra.getConf(), CassandraUtils.WITH_DEFAULT_CONFIGURATION);
             CassandraMailRepositoryCountDAO countDAO = new CassandraMailRepositoryCountDAO(cassandra.getConf());
-            BlobStore blobStore = CassandraBlobStoreFactory.forTesting(cassandra.getConf());
+            BlobStore blobStore = CassandraBlobStoreFactory.forTesting(cassandra.getConf())
+                .passthrough();
 
             cassandraMailRepository = new CassandraMailRepository(URL,
                     keysDAO, countDAO, mailDAO, MimeMessageStore.factory(blobStore).mimeMessageStore());
@@ -213,7 +214,8 @@ class CassandraMailRepositoryWithFakeImplementationsTest {
             CassandraMailRepositoryMailDaoAPI mailDAO = new CassandraMailRepositoryMailDAO(cassandra.getConf(), BLOB_ID_FACTORY, cassandra.getTypesProvider());
             FailingKeysDAO keysDAO = new FailingKeysDAO(cassandra.getConf(), CassandraUtils.WITH_DEFAULT_CONFIGURATION);
             countDAO = new CassandraMailRepositoryCountDAO(cassandra.getConf());
-            BlobStore blobStore = CassandraBlobStoreFactory.forTesting(cassandra.getConf());
+            BlobStore blobStore = CassandraBlobStoreFactory.forTesting(cassandra.getConf())
+                .passthrough();
 
             cassandraMailRepository = new CassandraMailRepository(URL,
                     keysDAO, countDAO, mailDAO, MimeMessageStore.factory(blobStore).mimeMessageStore());
diff --git a/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueConfigurationChangeTest.java b/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueConfigurationChangeTest.java
index a863ef8..6831937 100644
--- a/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueConfigurationChangeTest.java
+++ b/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueConfigurationChangeTest.java
@@ -94,7 +94,8 @@ class RabbitMQMailQueueConfigurationChangeTest {
 
     @BeforeEach
     void setup(CassandraCluster cassandra) throws Exception {
-        BlobStore blobStore = CassandraBlobStoreFactory.forTesting(cassandra.getConf());
+        BlobStore blobStore = CassandraBlobStoreFactory.forTesting(cassandra.getConf())
+            .passthrough();
         mimeMessageStoreFactory = MimeMessageStore.factory(blobStore);
         clock = new UpdatableTickingClock(IN_SLICE_1);
         mqManagementApi = new RabbitMQMailQueueManagement(rabbitMQExtension.managementAPI());
diff --git a/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueTest.java b/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueTest.java
index c6d0691..a8b044d 100644
--- a/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueTest.java
+++ b/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueTest.java
@@ -702,7 +702,8 @@ class RabbitMQMailQueueTest {
     private void setUp(CassandraCluster cassandra,
                        MailQueueMetricExtension.MailQueueMetricTestSystem metricTestSystem,
                        RabbitMQMailQueueConfiguration configuration) throws Exception {
-        BlobStore blobStore = CassandraBlobStoreFactory.forTesting(cassandra.getConf());
+        BlobStore blobStore = CassandraBlobStoreFactory.forTesting(cassandra.getConf())
+            .passthrough();
         MimeMessageStore.Factory mimeMessageStoreFactory = MimeMessageStore.factory(blobStore);
         clock = new UpdatableTickingClock(IN_SLICE_1);
 


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


[james-project] 13/25: JAMES-3318 Deduplication BlobStore::delete should be a noop operation

Posted by rc...@apache.org.
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 f4ff55414bbcbf8878260d27848bd6440a6c521f
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Jul 24 09:41:13 2020 +0700

    JAMES-3318 Deduplication BlobStore::delete should be a noop operation
    
    Later on we should implement reference tracking to be able to implement Garbage Collection.
---
 .../org/apache/james/blob/objectstorage/ObjectStorageBlobStore.java   | 4 +---
 .../james/server/blob/deduplication/DeDuplicationBlobStore.scala      | 2 +-
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBlobStore.java b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBlobStore.java
index cd7c7b3..088405a 100644
--- a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBlobStore.java
+++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBlobStore.java
@@ -210,9 +210,7 @@ public class ObjectStorageBlobStore implements BlobStore {
 
     @Override
     public Mono<Void> delete(BucketName bucketName, BlobId blobId) {
-        ObjectStorageBucketName resolvedBucketName = bucketNameResolver.resolve(bucketName);
-        return Mono.<Void>fromRunnable(() -> blobStore.removeBlob(resolvedBucketName.asString(), blobId.asString()))
-            .subscribeOn(Schedulers.elastic());
+        return Mono.empty();
     }
 
     // Workaround while waiting for DumbBlobStore extraction
diff --git a/server/blob/blob-storage-strategy/src/main/scala/org/apache/james/server/blob/deduplication/DeDuplicationBlobStore.scala b/server/blob/blob-storage-strategy/src/main/scala/org/apache/james/server/blob/deduplication/DeDuplicationBlobStore.scala
index 5bd663f..c012e6e 100644
--- a/server/blob/blob-storage-strategy/src/main/scala/org/apache/james/server/blob/deduplication/DeDuplicationBlobStore.scala
+++ b/server/blob/blob-storage-strategy/src/main/scala/org/apache/james/server/blob/deduplication/DeDuplicationBlobStore.scala
@@ -95,6 +95,6 @@ class DeDuplicationBlobStore @Inject()(dumbBlobStore: DumbBlobStore,
     Preconditions.checkNotNull(bucketName)
     Preconditions.checkNotNull(blobId)
 
-    dumbBlobStore.delete(bucketName, blobId)
+    SMono.empty
   }
 }


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


[james-project] 15/25: JAMES-3319 Actual Message & Attachment deletion for mailbox/cassandra

Posted by rc...@apache.org.
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 f9a847739145a3baf11ba7aced4ba06157561295
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Jul 24 16:52:27 2020 +0700

    JAMES-3319 Actual Message & Attachment deletion for mailbox/cassandra
---
 .../CassandraMailboxSessionMapperFactory.java      |  2 +-
 .../mailbox/cassandra/DeleteMessageListener.java   | 20 ++++++++++--
 .../cassandra/mail/CassandraMessageDAO.java        | 38 ++++++++++++----------
 .../cassandra/mail/MessageRepresentation.java      | 15 ++++++++-
 .../cassandra/CassandraMailboxManagerTest.java     | 24 ++++++++++++++
 5 files changed, 77 insertions(+), 22 deletions(-)

diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxSessionMapperFactory.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxSessionMapperFactory.java
index def8f71..e51364c 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxSessionMapperFactory.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxSessionMapperFactory.java
@@ -206,6 +206,6 @@ public class CassandraMailboxSessionMapperFactory extends MailboxSessionMapperFa
     public DeleteMessageListener deleteMessageListener() {
         return new DeleteMessageListener(imapUidDAO, messageIdDAO, messageDAO, attachmentDAOV2, ownerDAO,
             attachmentMessageIdDAO, aclMapper, userMailboxRightsDAO, applicableFlagDAO, firstUnseenDAO, deletedMessageDAO,
-            mailboxCounterDAO, mailboxRecentsDAO);
+            mailboxCounterDAO, mailboxRecentsDAO, blobStore);
     }
 }
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/DeleteMessageListener.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/DeleteMessageListener.java
index e7e3627..d4a3ea7 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/DeleteMessageListener.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/DeleteMessageListener.java
@@ -26,6 +26,7 @@ import java.util.function.Predicate;
 
 import javax.inject.Inject;
 
+import org.apache.james.blob.api.BlobStore;
 import org.apache.james.mailbox.acl.ACLDiff;
 import org.apache.james.mailbox.cassandra.ids.CassandraId;
 import org.apache.james.mailbox.cassandra.ids.CassandraMessageId;
@@ -88,13 +89,14 @@ public class DeleteMessageListener implements MailboxListener.GroupMailboxListen
     private final CassandraDeletedMessageDAO deletedMessageDAO;
     private final CassandraMailboxCounterDAO counterDAO;
     private final CassandraMailboxRecentsDAO recentsDAO;
+    private final BlobStore blobStore;
 
     @Inject
     public DeleteMessageListener(CassandraMessageIdToImapUidDAO imapUidDAO, CassandraMessageIdDAO messageIdDAO, CassandraMessageDAO messageDAO,
                                  CassandraAttachmentDAOV2 attachmentDAO, CassandraAttachmentOwnerDAO ownerDAO,
                                  CassandraAttachmentMessageIdDAO attachmentMessageIdDAO, CassandraACLMapper aclMapper,
                                  CassandraUserMailboxRightsDAO rightsDAO, CassandraApplicableFlagDAO applicableFlagDAO,
-                                 CassandraFirstUnseenDAO firstUnseenDAO, CassandraDeletedMessageDAO deletedMessageDAO, CassandraMailboxCounterDAO counterDAO, CassandraMailboxRecentsDAO recentsDAO) {
+                                 CassandraFirstUnseenDAO firstUnseenDAO, CassandraDeletedMessageDAO deletedMessageDAO, CassandraMailboxCounterDAO counterDAO, CassandraMailboxRecentsDAO recentsDAO, BlobStore blobStore) {
         this.imapUidDAO = imapUidDAO;
         this.messageIdDAO = messageIdDAO;
         this.messageDAO = messageDAO;
@@ -108,6 +110,7 @@ public class DeleteMessageListener implements MailboxListener.GroupMailboxListen
         this.deletedMessageDAO = deletedMessageDAO;
         this.counterDAO = counterDAO;
         this.recentsDAO = recentsDAO;
+        this.blobStore = blobStore;
     }
 
     @Override
@@ -172,6 +175,7 @@ public class DeleteMessageListener implements MailboxListener.GroupMailboxListen
             .filterWhen(this::isReferenced)
             .flatMap(id -> readMessage(id)
                 .flatMap(message -> deleteUnreferencedAttachments(message).thenReturn(message))
+                .flatMap(this::deleteMessageBlobs)
                 .flatMap(this::deleteAttachmentMessageIds)
                 .then(messageDAO.delete(messageId)));
     }
@@ -181,10 +185,19 @@ public class DeleteMessageListener implements MailboxListener.GroupMailboxListen
             .filterWhen(id -> isReferenced(id, excludedId))
             .flatMap(id -> readMessage(id)
                 .flatMap(message -> deleteUnreferencedAttachments(message).thenReturn(message))
+                .flatMap(this::deleteMessageBlobs)
                 .flatMap(this::deleteAttachmentMessageIds)
                 .then(messageDAO.delete(messageId)));
     }
 
+    private Mono<MessageRepresentation> deleteMessageBlobs(MessageRepresentation message) {
+        return Flux.merge(
+                blobStore.delete(blobStore.getDefaultBucketName(), message.getHeaderId()),
+                blobStore.delete(blobStore.getDefaultBucketName(), message.getBodyId()))
+            .then()
+            .thenReturn(message);
+    }
+
     private Mono<MessageRepresentation> readMessage(CassandraMessageId id) {
         return messageDAO.retrieveMessage(id, MessageMapper.FetchType.Metadata);
     }
@@ -193,7 +206,10 @@ public class DeleteMessageListener implements MailboxListener.GroupMailboxListen
         return Flux.fromIterable(message.getAttachments())
             .filterWhen(attachment -> ownerDAO.retrieveOwners(attachment.getAttachmentId()).hasElements().map(negate()))
             .filterWhen(attachment -> hasOtherMessagesReferences(message, attachment))
-            .concatMap(attachment -> attachmentDAO.delete(attachment.getAttachmentId()))
+            .concatMap(attachment -> attachmentDAO.getAttachment(attachment.getAttachmentId())
+                .map(CassandraAttachmentDAOV2.DAOAttachment::getBlobId)
+                .flatMap(blobId -> Mono.from(blobStore.delete(blobStore.getDefaultBucketName(), blobId)))
+                .then(attachmentDAO.delete(attachment.getAttachmentId())))
             .then();
     }
 
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAO.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAO.java
index a61d01f..7e7f06b 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAO.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAO.java
@@ -245,7 +245,11 @@ public class CassandraMessageDAO {
         }
 
         Row row = rows.one();
-        return buildContentRetriever(fetchType, row).map(content ->
+        BlobId headerId = retrieveBlobId(HEADER_CONTENT, row);
+        BlobId bodyId = retrieveBlobId(BODY_CONTENT, row);
+        int bodyStartOctet = row.getInt(BODY_START_OCTET);
+
+        return buildContentRetriever(fetchType, headerId, bodyId, bodyStartOctet).map(content ->
             new MessageRepresentation(
                 cassandraMessageId,
                 row.getTimestamp(INTERNAL_DATE),
@@ -253,7 +257,9 @@ public class CassandraMessageDAO {
                 row.getInt(BODY_START_OCTET),
                 new SharedByteArrayInputStream(content),
                 getPropertyBuilder(row),
-                getAttachments(row).collect(Guavate.toImmutableList())));
+                getAttachments(row).collect(Guavate.toImmutableList()),
+                headerId,
+                bodyId));
     }
 
     private PropertyBuilder getPropertyBuilder(Row row) {
@@ -293,15 +299,15 @@ public class CassandraMessageDAO {
             .setUUID(MESSAGE_ID, messageId.get()));
     }
 
-    private Mono<byte[]> buildContentRetriever(FetchType fetchType, Row row) {
+    private Mono<byte[]> buildContentRetriever(FetchType fetchType, BlobId headerId, BlobId bodyId, int bodyStartOctet) {
         switch (fetchType) {
             case Full:
-                return getFullContent(row);
+                return getFullContent(headerId, bodyId);
             case Headers:
-                return getHeaderContent(row);
+                return getContent(headerId);
             case Body:
-                return getBodyContent(row)
-                    .map(data -> Bytes.concat(new byte[row.getInt(BODY_START_OCTET)], data));
+                return getContent(bodyId)
+                    .map(data -> Bytes.concat(new byte[bodyStartOctet], data));
             case Metadata:
                 return Mono.just(EMPTY_BYTE_ARRAY);
             default:
@@ -309,20 +315,16 @@ public class CassandraMessageDAO {
         }
     }
 
-    private Mono<byte[]> getFullContent(Row row) {
-        return getHeaderContent(row)
-            .zipWith(getBodyContent(row), Bytes::concat);
-    }
-
-    private Mono<byte[]> getBodyContent(Row row) {
-        return getFieldContent(BODY_CONTENT, row);
+    private Mono<byte[]> getFullContent(BlobId headerId, BlobId bodyId) {
+        return getContent(headerId)
+            .zipWith(getContent(bodyId), Bytes::concat);
     }
 
-    private Mono<byte[]> getHeaderContent(Row row) {
-        return getFieldContent(HEADER_CONTENT, row);
+    private Mono<byte[]> getContent(BlobId blobId) {
+        return Mono.from(blobStore.readBytes(blobStore.getDefaultBucketName(), blobId));
     }
 
-    private Mono<byte[]> getFieldContent(String field, Row row) {
-        return Mono.from(blobStore.readBytes(blobStore.getDefaultBucketName(), blobIdFactory.from(row.getString(field))));
+    private BlobId retrieveBlobId(String field, Row row) {
+        return blobIdFactory.from(row.getString(field));
     }
 }
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/MessageRepresentation.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/MessageRepresentation.java
index 7a9a0b1..7ac496b 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/MessageRepresentation.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/MessageRepresentation.java
@@ -24,6 +24,7 @@ import java.util.List;
 
 import javax.mail.util.SharedByteArrayInputStream;
 
+import org.apache.james.blob.api.BlobId;
 import org.apache.james.mailbox.model.ComposedMessageIdWithMetaData;
 import org.apache.james.mailbox.model.MessageAttachmentMetadata;
 import org.apache.james.mailbox.model.MessageId;
@@ -38,9 +39,11 @@ public class MessageRepresentation {
     private final SharedByteArrayInputStream content;
     private final PropertyBuilder propertyBuilder;
     private final List<MessageAttachmentRepresentation> attachments;
+    private final BlobId headerId;
+    private final BlobId bodyId;
 
     public MessageRepresentation(MessageId messageId, Date internalDate, Long size, Integer bodySize, SharedByteArrayInputStream content,
-                                 PropertyBuilder propertyBuilder, List<MessageAttachmentRepresentation> attachments) {
+                                 PropertyBuilder propertyBuilder, List<MessageAttachmentRepresentation> attachments, BlobId headerId, BlobId bodyId) {
         this.messageId = messageId;
         this.internalDate = internalDate;
         this.size = size;
@@ -48,6 +51,8 @@ public class MessageRepresentation {
         this.content = content;
         this.propertyBuilder = propertyBuilder;
         this.attachments = attachments;
+        this.headerId = headerId;
+        this.bodyId = bodyId;
     }
 
     public SimpleMailboxMessage toMailboxMessage(ComposedMessageIdWithMetaData metadata, List<MessageAttachmentMetadata> attachments) {
@@ -81,4 +86,12 @@ public class MessageRepresentation {
     public List<MessageAttachmentRepresentation> getAttachments() {
         return attachments;
     }
+
+    public BlobId getHeaderId() {
+        return headerId;
+    }
+
+    public BlobId getBodyId() {
+        return bodyId;
+    }
 }
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerTest.java
index 328fcc6..f2a98f2 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerTest.java
@@ -18,6 +18,7 @@
  ****************************************************************/
 package org.apache.james.mailbox.cassandra;
 
+import static com.datastax.driver.core.querybuilder.QueryBuilder.select;
 import static org.apache.james.backends.cassandra.Scenario.Builder.fail;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
@@ -34,6 +35,7 @@ import org.apache.james.backends.cassandra.init.configuration.CassandraConfigura
 import org.apache.james.backends.cassandra.utils.CassandraUtils;
 import org.apache.james.blob.api.BlobStore;
 import org.apache.james.blob.api.HashBlobId;
+import org.apache.james.blob.cassandra.BlobTables;
 import org.apache.james.core.Username;
 import org.apache.james.mailbox.MailboxManagerTest;
 import org.apache.james.mailbox.MailboxSession;
@@ -160,6 +162,28 @@ public class CassandraMailboxManagerTest extends MailboxManagerTest<CassandraMai
         }
 
         @Test
+        void deleteMailboxShouldDeleteMessageAndAttachmentBlobs(CassandraCluster cassandraCluster) throws Exception {
+            inboxManager.appendMessage(MessageManager.AppendCommand.builder()
+                .build(ClassLoaderUtils.getSystemResourceAsByteArray("eml/emailWithOnlyAttachment.eml")), session);
+
+            mailboxManager.deleteMailbox(inbox, session);
+
+            assertThat(cassandraCluster.getConf().execute(select().from(BlobTables.DefaultBucketBlobTable.TABLE_NAME)))
+                .isEmpty();
+        }
+
+        @Test
+        void deleteMessageShouldDeleteMessageAndAttachmentBlobs(CassandraCluster cassandraCluster) throws Exception {
+            AppendResult appendResult = inboxManager.appendMessage(MessageManager.AppendCommand.builder()
+                .build(ClassLoaderUtils.getSystemResourceAsByteArray("eml/emailWithOnlyAttachment.eml")), session);
+
+            inboxManager.delete(ImmutableList.of(appendResult.getId().getUid()), session);
+
+            assertThat(cassandraCluster.getConf().execute(select().from(BlobTables.DefaultBucketBlobTable.TABLE_NAME)))
+                .isEmpty();
+        }
+
+        @Test
         void deleteMailboxShouldEventuallyUnreferenceMessageMetadataWhenDeleteAttachmentFails(CassandraCluster cassandraCluster) throws Exception {
             AppendResult appendResult = inboxManager.appendMessage(MessageManager.AppendCommand.builder()
                 .build(ClassLoaderUtils.getSystemResourceAsByteArray("eml/emailWithOnlyAttachment.eml")), session);


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


[james-project] 12/25: JAMES-3318 BlobStoreDeletedMessageVault should use DumbBlobStore for effective deletion

Posted by rc...@apache.org.
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 71187b503a5b5f012b590289363d0992ed067ca8
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Jul 24 09:26:11 2020 +0700

    JAMES-3318 BlobStoreDeletedMessageVault should use DumbBlobStore for effective deletion
---
 .../vault/blob/BlobStoreDeletedMessageVault.java   |  7 +-
 .../james/vault/DeletedMessageVaultHookTest.java   |  9 ++-
 .../blob/BlobStoreDeletedMessageVaultTest.java     |  9 ++-
 .../blob/objectstorage/ObjectStorageBlobStore.java |  7 ++
 .../modules/blobstore/BlobStoreModulesChooser.java |  1 +
 .../james/modules/blobstore/NoopDumbBlobStore.java | 83 ++++++++++++++++++++++
 .../routes/DeletedMessagesVaultRoutesTest.java     |  9 ++-
 7 files changed, 114 insertions(+), 11 deletions(-)

diff --git a/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/blob/BlobStoreDeletedMessageVault.java b/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/blob/BlobStoreDeletedMessageVault.java
index 8febe09..2bc66b4 100644
--- a/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/blob/BlobStoreDeletedMessageVault.java
+++ b/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/blob/BlobStoreDeletedMessageVault.java
@@ -30,6 +30,7 @@ import javax.inject.Inject;
 
 import org.apache.james.blob.api.BlobStore;
 import org.apache.james.blob.api.BucketName;
+import org.apache.james.blob.api.DumbBlobStore;
 import org.apache.james.blob.api.ObjectNotFoundException;
 import org.apache.james.core.Username;
 import org.apache.james.mailbox.model.MessageId;
@@ -67,6 +68,7 @@ public class BlobStoreDeletedMessageVault implements DeletedMessageVault {
     private final MetricFactory metricFactory;
     private final DeletedMessageMetadataVault messageMetadataVault;
     private final BlobStore blobStore;
+    private final DumbBlobStore dumbBlobStore;
     private final BucketNameGenerator nameGenerator;
     private final Clock clock;
     private final RetentionConfiguration retentionConfiguration;
@@ -74,12 +76,13 @@ public class BlobStoreDeletedMessageVault implements DeletedMessageVault {
 
     @Inject
     public BlobStoreDeletedMessageVault(MetricFactory metricFactory, DeletedMessageMetadataVault messageMetadataVault,
-                                        BlobStore blobStore, BucketNameGenerator nameGenerator,
+                                        BlobStore blobStore, DumbBlobStore dumbBlobStore, BucketNameGenerator nameGenerator,
                                         Clock clock,
                                         RetentionConfiguration retentionConfiguration) {
         this.metricFactory = metricFactory;
         this.messageMetadataVault = messageMetadataVault;
         this.blobStore = blobStore;
+        this.dumbBlobStore = dumbBlobStore;
         this.nameGenerator = nameGenerator;
         this.clock = clock;
         this.retentionConfiguration = retentionConfiguration;
@@ -156,7 +159,7 @@ public class BlobStoreDeletedMessageVault implements DeletedMessageVault {
         return Mono.from(messageMetadataVault.retrieveStorageInformation(username, messageId))
             .flatMap(storageInformation -> Mono.from(messageMetadataVault.remove(storageInformation.getBucketName(), username, messageId))
                 .thenReturn(storageInformation))
-            .flatMap(storageInformation -> Mono.from(blobStore.delete(storageInformation.getBucketName(), storageInformation.getBlobId())))
+            .flatMap(storageInformation -> Mono.from(dumbBlobStore.delete(storageInformation.getBucketName(), storageInformation.getBlobId())))
             .subscribeOn(Schedulers.elastic());
     }
 
diff --git a/mailbox/plugin/deleted-messages-vault/src/test/java/org/apache/james/vault/DeletedMessageVaultHookTest.java b/mailbox/plugin/deleted-messages-vault/src/test/java/org/apache/james/vault/DeletedMessageVaultHookTest.java
index 0fa94af..688574f 100644
--- a/mailbox/plugin/deleted-messages-vault/src/test/java/org/apache/james/vault/DeletedMessageVaultHookTest.java
+++ b/mailbox/plugin/deleted-messages-vault/src/test/java/org/apache/james/vault/DeletedMessageVaultHookTest.java
@@ -30,7 +30,7 @@ import java.time.ZoneOffset;
 import java.util.List;
 
 import org.apache.james.blob.api.HashBlobId;
-import org.apache.james.blob.memory.MemoryBlobStoreFactory;
+import org.apache.james.blob.memory.MemoryDumbBlobStore;
 import org.apache.james.core.MailAddress;
 import org.apache.james.core.MaybeSender;
 import org.apache.james.core.Username;
@@ -50,6 +50,7 @@ import org.apache.james.mailbox.model.MessageRange;
 import org.apache.james.mailbox.model.SearchQuery;
 import org.apache.james.metrics.tests.RecordingMetricFactory;
 import org.apache.james.mime4j.dom.Message;
+import org.apache.james.server.blob.deduplication.BlobStoreFactory;
 import org.apache.james.vault.blob.BlobStoreDeletedMessageVault;
 import org.apache.james.vault.blob.BucketNameGenerator;
 import org.apache.james.vault.memory.metadata.MemoryDeletedMessageMetadataVault;
@@ -108,11 +109,13 @@ class DeletedMessageVaultHookTest {
     @BeforeEach
     void setUp() throws Exception {
         clock = Clock.fixed(DELETION_DATE.toInstant(), ZoneOffset.UTC);
+        MemoryDumbBlobStore dumbBlobStore = new MemoryDumbBlobStore();
         messageVault = new BlobStoreDeletedMessageVault(new RecordingMetricFactory(), new MemoryDeletedMessageMetadataVault(),
-            MemoryBlobStoreFactory.builder()
+            BlobStoreFactory.builder()
+                .dumbBlobStore(dumbBlobStore)
                 .blobIdFactory(new HashBlobId.Factory())
                 .defaultBucketName()
-                .passthrough(), new BucketNameGenerator(clock), clock,
+                .passthrough(), dumbBlobStore, new BucketNameGenerator(clock), clock,
             RetentionConfiguration.DEFAULT);
 
         DeletedMessageConverter deletedMessageConverter = new DeletedMessageConverter();
diff --git a/mailbox/plugin/deleted-messages-vault/src/test/java/org/apache/james/vault/blob/BlobStoreDeletedMessageVaultTest.java b/mailbox/plugin/deleted-messages-vault/src/test/java/org/apache/james/vault/blob/BlobStoreDeletedMessageVaultTest.java
index 28b6506..982fefd 100644
--- a/mailbox/plugin/deleted-messages-vault/src/test/java/org/apache/james/vault/blob/BlobStoreDeletedMessageVaultTest.java
+++ b/mailbox/plugin/deleted-messages-vault/src/test/java/org/apache/james/vault/blob/BlobStoreDeletedMessageVaultTest.java
@@ -40,8 +40,9 @@ import java.time.ZonedDateTime;
 
 import org.apache.james.blob.api.BucketName;
 import org.apache.james.blob.api.HashBlobId;
-import org.apache.james.blob.memory.MemoryBlobStoreFactory;
+import org.apache.james.blob.memory.MemoryDumbBlobStore;
 import org.apache.james.metrics.tests.RecordingMetricFactory;
+import org.apache.james.server.blob.deduplication.BlobStoreFactory;
 import org.apache.james.utils.UpdatableTickingClock;
 import org.apache.james.vault.DeletedMessageVault;
 import org.apache.james.vault.DeletedMessageVaultContract;
@@ -63,12 +64,14 @@ class BlobStoreDeletedMessageVaultTest implements DeletedMessageVaultContract, D
     void setUp() {
         clock = new UpdatableTickingClock(NOW.toInstant());
         metricFactory = new RecordingMetricFactory();
+        MemoryDumbBlobStore dumbBlobStore = new MemoryDumbBlobStore();
         messageVault = new BlobStoreDeletedMessageVault(metricFactory, new MemoryDeletedMessageMetadataVault(),
-            MemoryBlobStoreFactory.builder()
+            BlobStoreFactory.builder()
+                .dumbBlobStore(dumbBlobStore)
                 .blobIdFactory(new HashBlobId.Factory())
                 .defaultBucketName()
                 .passthrough(),
-            new BucketNameGenerator(clock), clock, RetentionConfiguration.DEFAULT);
+            dumbBlobStore, new BucketNameGenerator(clock), clock, RetentionConfiguration.DEFAULT);
     }
 
     @Override
diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBlobStore.java b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBlobStore.java
index 3c45fe8..cd7c7b3 100644
--- a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBlobStore.java
+++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBlobStore.java
@@ -214,4 +214,11 @@ public class ObjectStorageBlobStore implements BlobStore {
         return Mono.<Void>fromRunnable(() -> blobStore.removeBlob(resolvedBucketName.asString(), blobId.asString()))
             .subscribeOn(Schedulers.elastic());
     }
+
+    // Workaround while waiting for DumbBlobStore extraction
+    public Mono<Void> deleteEffectively(BucketName bucketName, BlobId blobId) {
+        ObjectStorageBucketName resolvedBucketName = bucketNameResolver.resolve(bucketName);
+        return Mono.<Void>fromRunnable(() -> blobStore.removeBlob(resolvedBucketName.asString(), blobId.asString()))
+            .subscribeOn(Schedulers.elastic());
+    }
 }
diff --git a/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/modules/blobstore/BlobStoreModulesChooser.java b/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/modules/blobstore/BlobStoreModulesChooser.java
index d790968..c0cdcc2 100644
--- a/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/modules/blobstore/BlobStoreModulesChooser.java
+++ b/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/modules/blobstore/BlobStoreModulesChooser.java
@@ -54,6 +54,7 @@ public class BlobStoreModulesChooser {
         @Override
         protected void configure() {
             install(new ObjectStorageDependenciesModule());
+            bind(DumbBlobStore.class).to(NoopDumbBlobStore.class);
             bind(BlobStore.class)
                 .annotatedWith(Names.named(CachedBlobStore.BACKEND))
                 .to(ObjectStorageBlobStore.class);
diff --git a/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/modules/blobstore/NoopDumbBlobStore.java b/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/modules/blobstore/NoopDumbBlobStore.java
new file mode 100644
index 0000000..9ebc084
--- /dev/null
+++ b/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/modules/blobstore/NoopDumbBlobStore.java
@@ -0,0 +1,83 @@
+/****************************************************************
+ * 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.modules.blobstore;
+
+import java.io.InputStream;
+
+import javax.inject.Inject;
+
+import org.apache.commons.lang3.NotImplementedException;
+import org.apache.james.blob.api.BlobId;
+import org.apache.james.blob.api.BucketName;
+import org.apache.james.blob.api.DumbBlobStore;
+import org.apache.james.blob.api.ObjectNotFoundException;
+import org.apache.james.blob.api.ObjectStoreIOException;
+import org.apache.james.blob.objectstorage.ObjectStorageBlobStore;
+import org.reactivestreams.Publisher;
+
+import com.google.common.io.ByteSource;
+
+
+/**
+ * This class is a workaround while waiting for a real DumbBlobStore to be extracted from ObjectStorageBlobStore
+ */
+public class NoopDumbBlobStore implements DumbBlobStore {
+    private final ObjectStorageBlobStore objectStorageBlobStore;
+
+    @Inject
+    public NoopDumbBlobStore(ObjectStorageBlobStore objectStorageBlobStore) {
+        this.objectStorageBlobStore = objectStorageBlobStore;
+    }
+
+    @Override
+    public InputStream read(BucketName bucketName, BlobId blobId) throws ObjectStoreIOException, ObjectNotFoundException {
+        throw new NotImplementedException("Not implemented");
+    }
+
+    @Override
+    public Publisher<byte[]> readBytes(BucketName bucketName, BlobId blobId) {
+        throw new NotImplementedException("Not implemented");
+    }
+
+    @Override
+    public Publisher<Void> save(BucketName bucketName, BlobId blobId, byte[] data) {
+        throw new NotImplementedException("Not implemented");
+    }
+
+    @Override
+    public Publisher<Void> save(BucketName bucketName, BlobId blobId, InputStream inputStream) {
+        throw new NotImplementedException("Not implemented");
+    }
+
+    @Override
+    public Publisher<Void> save(BucketName bucketName, BlobId blobId, ByteSource content) {
+        throw new NotImplementedException("Not implemented");
+    }
+
+    @Override
+    public Publisher<Void> delete(BucketName bucketName, BlobId blobId) {
+        return objectStorageBlobStore.deleteEffectively(bucketName, blobId);
+    }
+
+    @Override
+    public Publisher<Void> deleteBucket(BucketName bucketName) {
+        throw new NotImplementedException("Not implemented");
+    }
+}
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 1c8d463..cfdb6b3 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
@@ -76,7 +76,7 @@ import org.apache.james.blob.api.BlobStore;
 import org.apache.james.blob.api.BucketName;
 import org.apache.james.blob.api.HashBlobId;
 import org.apache.james.blob.export.api.BlobExportMechanism;
-import org.apache.james.blob.memory.MemoryBlobStoreFactory;
+import org.apache.james.blob.memory.MemoryDumbBlobStore;
 import org.apache.james.core.Domain;
 import org.apache.james.core.MailAddress;
 import org.apache.james.core.MaybeSender;
@@ -102,6 +102,7 @@ import org.apache.james.mailbox.model.MessageResult;
 import org.apache.james.mailbox.model.MultimailboxesSearchQuery;
 import org.apache.james.mailbox.model.SearchQuery;
 import org.apache.james.metrics.tests.RecordingMetricFactory;
+import org.apache.james.server.blob.deduplication.BlobStoreFactory;
 import org.apache.james.task.Hostname;
 import org.apache.james.task.MemoryTaskManager;
 import org.apache.james.user.memory.MemoryUsersRepository;
@@ -181,13 +182,15 @@ class DeletedMessagesVaultRoutesTest {
     @BeforeEach
     void beforeEach() throws Exception {
         blobIdFactory = new HashBlobId.Factory();
-        blobStore = spy(MemoryBlobStoreFactory.builder()
+        MemoryDumbBlobStore dumbBlobStore = new MemoryDumbBlobStore();
+        blobStore = spy(BlobStoreFactory.builder()
+            .dumbBlobStore(dumbBlobStore)
             .blobIdFactory(blobIdFactory)
             .defaultBucketName()
             .passthrough());
         clock = new UpdatableTickingClock(OLD_DELETION_DATE.toInstant());
         vault = spy(new BlobStoreDeletedMessageVault(new RecordingMetricFactory(), new MemoryDeletedMessageMetadataVault(),
-            blobStore, new BucketNameGenerator(clock), clock,
+            blobStore, dumbBlobStore, new BucketNameGenerator(clock), clock,
             RetentionConfiguration.DEFAULT));
         InMemoryIntegrationResources inMemoryResource = InMemoryIntegrationResources.defaultResources();
         mailboxManager = spy(inMemoryResource.getMailboxManager());


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


[james-project] 14/25: JAMES-3319 FetchType is no longer relevant to fetch messageDao rows

Posted by rc...@apache.org.
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 aa0e6e7e0305536ebbfef1f824c95a1d10eb7b05
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Jul 24 14:48:27 2020 +0700

    JAMES-3319 FetchType is no longer relevant to fetch messageDao rows
    
    Before it was as the blobs was hold in this metadata. Now we rely on blobStore, and
    blobIds have zero oberhead on the overall operation: we can afford always fetching the
    blobIds, which enable preparing less statements, and simplifying the code.
---
 .../cassandra/mail/CassandraMessageDAO.java        | 35 ++++------------------
 .../cassandra/table/CassandraMessageV2Table.java   |  7 -----
 .../cassandra/mail/CassandraMessageMapperTest.java |  3 +-
 .../tools/indexer/CassandraReIndexerImplTest.java  |  2 +-
 4 files changed, 7 insertions(+), 40 deletions(-)

diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAO.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAO.java
index 01ca6b9..a61d01f 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAO.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAO.java
@@ -27,16 +27,12 @@ import static org.apache.james.blob.api.BlobStore.StoragePolicy.LOW_COST;
 import static org.apache.james.blob.api.BlobStore.StoragePolicy.SIZE_BASED;
 import static org.apache.james.mailbox.cassandra.table.CassandraMessageIds.MESSAGE_ID;
 import static org.apache.james.mailbox.cassandra.table.CassandraMessageV2Table.ATTACHMENTS;
-import static org.apache.james.mailbox.cassandra.table.CassandraMessageV2Table.BODY;
 import static org.apache.james.mailbox.cassandra.table.CassandraMessageV2Table.BODY_CONTENT;
 import static org.apache.james.mailbox.cassandra.table.CassandraMessageV2Table.BODY_OCTECTS;
 import static org.apache.james.mailbox.cassandra.table.CassandraMessageV2Table.BODY_START_OCTET;
-import static org.apache.james.mailbox.cassandra.table.CassandraMessageV2Table.FIELDS;
 import static org.apache.james.mailbox.cassandra.table.CassandraMessageV2Table.FULL_CONTENT_OCTETS;
-import static org.apache.james.mailbox.cassandra.table.CassandraMessageV2Table.HEADERS;
 import static org.apache.james.mailbox.cassandra.table.CassandraMessageV2Table.HEADER_CONTENT;
 import static org.apache.james.mailbox.cassandra.table.CassandraMessageV2Table.INTERNAL_DATE;
-import static org.apache.james.mailbox.cassandra.table.CassandraMessageV2Table.METADATA;
 import static org.apache.james.mailbox.cassandra.table.CassandraMessageV2Table.PROPERTIES;
 import static org.apache.james.mailbox.cassandra.table.CassandraMessageV2Table.TABLE_NAME;
 import static org.apache.james.mailbox.cassandra.table.CassandraMessageV2Table.TEXTUAL_LINE_COUNT;
@@ -99,10 +95,7 @@ public class CassandraMessageDAO {
     private final CassandraMessageId.Factory messageIdFactory;
     private final PreparedStatement insert;
     private final PreparedStatement delete;
-    private final PreparedStatement selectMetadata;
-    private final PreparedStatement selectHeaders;
-    private final PreparedStatement selectFields;
-    private final PreparedStatement selectBody;
+    private final PreparedStatement select;
     private final PreparedStatement selectAllMessagesWithAttachment;
     private final Cid.CidParser cidParser;
     private final ConsistencyLevel consistencyLevel;
@@ -122,10 +115,7 @@ public class CassandraMessageDAO {
 
         this.insert = prepareInsert(session);
         this.delete = prepareDelete(session);
-        this.selectMetadata = prepareSelect(session, METADATA);
-        this.selectHeaders = prepareSelect(session, HEADERS);
-        this.selectFields = prepareSelect(session, FIELDS);
-        this.selectBody = prepareSelect(session, BODY);
+        this.select = prepareSelect(session);
         this.selectAllMessagesWithAttachment = prepareSelectAllMessagesWithAttachment(session);
         this.cidParser = Cid.parser().relaxed();
     }
@@ -138,8 +128,8 @@ public class CassandraMessageDAO {
             consistenciesConfiguration, messageIdFactory);
     }
 
-    private PreparedStatement prepareSelect(Session session, String[] fields) {
-        return session.prepare(select(fields)
+    private PreparedStatement prepareSelect(Session session) {
+        return session.prepare(select()
             .from(TABLE_NAME)
             .where(eq(MESSAGE_ID, bindMarker(MESSAGE_ID))));
     }
@@ -242,7 +232,7 @@ public class CassandraMessageDAO {
     }
 
     private Mono<ResultSet> retrieveRow(CassandraMessageId messageId, FetchType fetchType) {
-        return cassandraAsyncExecutor.execute(retrieveSelect(fetchType)
+        return cassandraAsyncExecutor.execute(select
             .bind()
             .setUUID(MESSAGE_ID, messageId.get())
             .setConsistencyLevel(consistencyLevel));
@@ -298,21 +288,6 @@ public class CassandraMessageDAO {
             .build();
     }
 
-    private PreparedStatement retrieveSelect(FetchType fetchType) {
-        switch (fetchType) {
-            case Body:
-                return selectBody;
-            case Full:
-                return selectFields;
-            case Headers:
-                return selectHeaders;
-            case Metadata:
-                return selectMetadata;
-            default:
-                throw new RuntimeException("Unknown FetchType " + fetchType);
-        }
-    }
-
     public Mono<Void> delete(CassandraMessageId messageId) {
         return cassandraAsyncExecutor.executeVoid(delete.bind()
             .setUUID(MESSAGE_ID, messageId.get()));
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/table/CassandraMessageV2Table.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/table/CassandraMessageV2Table.java
index 2d41173..8ceb86a 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/table/CassandraMessageV2Table.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/table/CassandraMessageV2Table.java
@@ -19,8 +19,6 @@
 
 package org.apache.james.mailbox.cassandra.table;
 
-import static org.apache.james.mailbox.cassandra.table.CassandraMessageIds.MESSAGE_ID;
-
 public interface CassandraMessageV2Table {
 
     String TABLE_NAME = "messageV2";
@@ -34,11 +32,6 @@ public interface CassandraMessageV2Table {
     String PROPERTIES = "properties";
     String ATTACHMENTS = "attachments";
 
-    String[] FIELDS = { MESSAGE_ID, INTERNAL_DATE, BODY_START_OCTET, FULL_CONTENT_OCTETS, BODY_OCTECTS, BODY_CONTENT, HEADER_CONTENT, TEXTUAL_LINE_COUNT, PROPERTIES, ATTACHMENTS };
-    String[] METADATA = { MESSAGE_ID, INTERNAL_DATE, BODY_START_OCTET, FULL_CONTENT_OCTETS, BODY_OCTECTS, TEXTUAL_LINE_COUNT, PROPERTIES, ATTACHMENTS };
-    String[] HEADERS = { MESSAGE_ID, INTERNAL_DATE, BODY_START_OCTET, FULL_CONTENT_OCTETS, BODY_OCTECTS, HEADER_CONTENT, TEXTUAL_LINE_COUNT, PROPERTIES, ATTACHMENTS };
-    String[] BODY = { MESSAGE_ID, INTERNAL_DATE, BODY_START_OCTET, FULL_CONTENT_OCTETS, BODY_OCTECTS, BODY_CONTENT, TEXTUAL_LINE_COUNT, PROPERTIES, ATTACHMENTS };
-
     interface Properties {
         String NAMESPACE = "namespace";
         String NAME = "name";
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapperTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapperTest.java
index 75e9146..aab3f51 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapperTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapperTest.java
@@ -195,8 +195,7 @@ class CassandraMessageMapperTest extends MessageMapperTest {
 
 
             assertThat(statementRecorder.listExecutedStatements(Selector.preparedStatement(
-                "SELECT messageId,internalDate,bodyStartOctet,fullContentOctets,bodyOctets,bodyContent,headerContent,textualLineCount,properties,attachments " +
-                    "FROM messageV2 WHERE messageId=:messageId;")))
+                "SELECT * FROM messageV2 WHERE messageId=:messageId;")))
                 .hasSize(limit);
         }
 
diff --git a/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/CassandraReIndexerImplTest.java b/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/CassandraReIndexerImplTest.java
index 3d83ee1..cbf263e 100644
--- a/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/CassandraReIndexerImplTest.java
+++ b/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/CassandraReIndexerImplTest.java
@@ -318,7 +318,7 @@ public class CassandraReIndexerImplTest {
             cassandra.getConf()
                 .registerScenario(fail()
                     .forever()
-                    .whenQueryStartsWith("SELECT messageId,internalDate,bodyStartOctet,fullContentOctets,bodyOctets,bodyContent,headerContent,textualLineCount,properties,attachments FROM messageV2 WHERE messageId=:messageId;"));
+                    .whenQueryStartsWith("SELECT * FROM messageV2 WHERE messageId=:messageId;"));
 
             Task task = reIndexer.reIndex(ReIndexer.RunningOptions.DEFAULT);
             task.run();


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


[james-project] 17/25: JAMES-3319 Decrease the test count for storingAndRemovingMessagesConcurrentlyShouldLeadToConsistentResult

Posted by rc...@apache.org.
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 1bcc8f7ef5bb19c05dc94c5b6935571de1a6c3c7
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Jul 24 11:31:18 2020 +0700

    JAMES-3319 Decrease the test count for storingAndRemovingMessagesConcurrentlyShouldLeadToConsistentResult
    
    This takes a long time, we know this test to be stable hence reducing the test count seems desirable.
---
 .../java/org/apache/james/mailrepository/MailRepositoryContract.java    | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/server/mailrepository/mailrepository-api/src/test/java/org/apache/james/mailrepository/MailRepositoryContract.java b/server/mailrepository/mailrepository-api/src/test/java/org/apache/james/mailrepository/MailRepositoryContract.java
index b8cea35..7210620 100644
--- a/server/mailrepository/mailrepository-api/src/test/java/org/apache/james/mailrepository/MailRepositoryContract.java
+++ b/server/mailrepository/mailrepository-api/src/test/java/org/apache/james/mailrepository/MailRepositoryContract.java
@@ -456,7 +456,7 @@ public interface MailRepositoryContract {
         assertThat(testee.retrieve(MAIL_1)).satisfies(actual -> checkMailEquality(actual, mail));
     }
 
-    @RepeatedTest(100)
+    @RepeatedTest(10)
     default void storingAndRemovingMessagesConcurrentlyShouldLeadToConsistentResult() throws Exception {
         MailRepository testee = retrieveRepository();
         int nbKeys = 20;


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


[james-project] 20/25: JAMES-3319 Rely on Cassandra instrumentation for CassandraMailRepository failure tests

Posted by rc...@apache.org.
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 948f29a396b55ab773467f7f7aa7ce439fdf4985
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Jul 24 11:55:09 2020 +0700

    JAMES-3319 Rely on Cassandra instrumentation for CassandraMailRepository failure tests
---
 ...aMailRepositoryWithFakeImplementationsTest.java | 155 +++++++--------------
 1 file changed, 50 insertions(+), 105 deletions(-)

diff --git a/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryWithFakeImplementationsTest.java b/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryWithFakeImplementationsTest.java
index 2f0873a..027f1e9 100644
--- a/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryWithFakeImplementationsTest.java
+++ b/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryWithFakeImplementationsTest.java
@@ -24,14 +24,11 @@ import static org.apache.james.backends.cassandra.Scenario.Builder.fail;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
-import java.util.Optional;
-
 import org.apache.james.backends.cassandra.CassandraCluster;
 import org.apache.james.backends.cassandra.CassandraClusterExtension;
 import org.apache.james.backends.cassandra.components.CassandraModule;
 import org.apache.james.backends.cassandra.utils.CassandraUtils;
 import org.apache.james.backends.cassandra.versions.CassandraSchemaVersionModule;
-import org.apache.james.blob.api.BlobId;
 import org.apache.james.blob.api.BlobStore;
 import org.apache.james.blob.api.HashBlobId;
 import org.apache.james.blob.cassandra.BlobTables;
@@ -39,19 +36,14 @@ import org.apache.james.blob.cassandra.CassandraBlobModule;
 import org.apache.james.blob.cassandra.CassandraBlobStoreFactory;
 import org.apache.james.blob.mail.MimeMessageStore;
 import org.apache.james.core.builder.MimeMessageBuilder;
-import org.apache.james.mailrepository.api.MailKey;
 import org.apache.james.mailrepository.api.MailRepositoryUrl;
 import org.apache.james.server.core.MailImpl;
-import org.apache.mailet.Mail;
 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 com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.Session;
-
-import reactor.core.publisher.Mono;
 
 class CassandraMailRepositoryWithFakeImplementationsTest {
     @RegisterExtension
@@ -64,23 +56,25 @@ class CassandraMailRepositoryWithFakeImplementationsTest {
     private static final MailRepositoryUrl URL = MailRepositoryUrl.from("proto://url");
     private static final HashBlobId.Factory BLOB_ID_FACTORY = new HashBlobId.Factory();
 
+
+    CassandraMailRepository cassandraMailRepository;
+    CassandraMailRepositoryCountDAO countDAO;
+    CassandraMailRepositoryKeysDAO keysDAO;
+
+    @BeforeEach
+    void setup(CassandraCluster cassandra) {
+        CassandraMailRepositoryMailDaoAPI mailDAO = new CassandraMailRepositoryMailDAO(cassandra.getConf(), BLOB_ID_FACTORY, cassandra.getTypesProvider());
+        keysDAO = new CassandraMailRepositoryKeysDAO(cassandra.getConf(), CassandraUtils.WITH_DEFAULT_CONFIGURATION);
+        countDAO = new CassandraMailRepositoryCountDAO(cassandra.getConf());
+        BlobStore blobStore = CassandraBlobStoreFactory.forTesting(cassandra.getConf())
+            .passthrough();
+
+        cassandraMailRepository = new CassandraMailRepository(URL,
+            keysDAO, countDAO, mailDAO, MimeMessageStore.factory(blobStore).mimeMessageStore());
+    }
+
     @Nested
     class FailingStoreTest {
-        CassandraMailRepository cassandraMailRepository;
-        CassandraMailRepositoryKeysDAO keysDAO;
-
-        @BeforeEach
-        void setup(CassandraCluster cassandra) {
-            CassandraMailRepositoryMailDaoAPI mailDAO = new CassandraMailRepositoryMailDAO(cassandra.getConf(), BLOB_ID_FACTORY, cassandra.getTypesProvider());
-            keysDAO = new CassandraMailRepositoryKeysDAO(cassandra.getConf(), CassandraUtils.WITH_DEFAULT_CONFIGURATION);
-            CassandraMailRepositoryCountDAO countDAO = new CassandraMailRepositoryCountDAO(cassandra.getConf());
-            BlobStore blobStore = CassandraBlobStoreFactory.forTesting(cassandra.getConf())
-                .deduplication();
-
-            cassandraMailRepository = new CassandraMailRepository(URL,
-                    keysDAO, countDAO, mailDAO, MimeMessageStore.factory(blobStore).mimeMessageStore());
-        }
-
         @Test
         void keysShouldNotBeStoredWhenStoringMimeMessageHasFailed(CassandraCluster cassandra) throws Exception {
             cassandra.getConf()
@@ -101,8 +95,7 @@ class CassandraMailRepositoryWithFakeImplementationsTest {
                 .build();
 
             assertThatThrownBy(() -> cassandraMailRepository.store(mail))
-                    .isInstanceOf(RuntimeException.class)
-                    .hasMessage("Injected failure");
+                    .isInstanceOf(RuntimeException.class);
 
             assertThat(keysDAO.list(URL).collectList().block()).isEmpty();
         }
@@ -110,47 +103,13 @@ class CassandraMailRepositoryWithFakeImplementationsTest {
 
     @Nested
     class FailingMailDaoTest {
-        CassandraMailRepository cassandraMailRepository;
-        CassandraMailRepositoryKeysDAO keysDAO;
-
-        @BeforeEach
-        void setup(CassandraCluster cassandra) {
-            FailingMailDAO mailDAO = new FailingMailDAO();
-            keysDAO = new CassandraMailRepositoryKeysDAO(cassandra.getConf(), CassandraUtils.WITH_DEFAULT_CONFIGURATION);
-            CassandraMailRepositoryCountDAO countDAO = new CassandraMailRepositoryCountDAO(cassandra.getConf());
-            BlobStore blobStore = CassandraBlobStoreFactory.forTesting(cassandra.getConf())
-                .passthrough();
-
-            cassandraMailRepository = new CassandraMailRepository(URL,
-                    keysDAO, countDAO, mailDAO, MimeMessageStore.factory(blobStore).mimeMessageStore());
-        }
-
-        class FailingMailDAO implements CassandraMailRepositoryMailDaoAPI {
-
-            FailingMailDAO() {
-            }
-
-            @Override
-            public Mono<Void> store(MailRepositoryUrl url, Mail mail, BlobId headerId, BlobId bodyId) {
-                return Mono.error(new RuntimeException("Expected failure while storing mail parts"));
-            }
-
-            @Override
-            public Mono<Void> remove(MailRepositoryUrl url, MailKey key) {
-                return Mono.fromCallable(() -> {
-                    throw new RuntimeException("Expected failure while removing mail parts");
-                });
-
-            }
-
-            @Override
-            public Mono<Optional<CassandraMailRepositoryMailDAO.MailDTO>> read(MailRepositoryUrl url, MailKey key) {
-                return Mono.error(new RuntimeException("Expected failure while reading mail parts"));
-            }
-        }
-
         @Test
-        void keysShouldNotBeStoredWhenStoringMailPartsHasFailed() throws Exception {
+        void keysShouldNotBeStoredWhenStoringMailPartsHasFailed(CassandraCluster cassandra) throws Exception {
+            cassandra.getConf()
+                .registerScenario(fail()
+                    .forever()
+                    .whenQueryStartsWith("INSERT INTO mailRepositoryContent"));
+
             MailImpl mail = MailImpl.builder()
                 .name("mymail")
                 .sender("sender@localhost")
@@ -164,14 +123,18 @@ class CassandraMailRepositoryWithFakeImplementationsTest {
                 .build();
 
             assertThatThrownBy(() -> cassandraMailRepository.store(mail))
-                    .isInstanceOf(RuntimeException.class)
-                    .hasMessage("Expected failure while storing mail parts");
+                    .isInstanceOf(RuntimeException.class);
 
             assertThat(keysDAO.list(URL).collectList().block()).isEmpty();
         }
 
         @Test
         void mimeMessageShouldBeStoredWhenStoringMailPartsHasFailed(CassandraCluster cassandra) throws Exception {
+            cassandra.getConf()
+                .registerScenario(fail()
+                    .forever()
+                    .whenQueryStartsWith("INSERT INTO mailRepositoryContent"));
+
             MailImpl mail = MailImpl.builder()
                 .name("mymail")
                 .sender("sender@localhost")
@@ -185,8 +148,7 @@ class CassandraMailRepositoryWithFakeImplementationsTest {
                 .build();
 
             assertThatThrownBy(() -> cassandraMailRepository.store(mail))
-                    .isInstanceOf(RuntimeException.class)
-                    .hasMessage("Expected failure while storing mail parts");
+                    .isInstanceOf(RuntimeException.class);
 
             ResultSet resultSet = cassandra.getConf().execute(select()
                     .from(BlobTables.DefaultBucketBlobTable.TABLE_NAME));
@@ -196,37 +158,13 @@ class CassandraMailRepositoryWithFakeImplementationsTest {
 
     @Nested
     class FailingKeysDaoTest {
-        CassandraMailRepository cassandraMailRepository;
-        CassandraMailRepositoryCountDAO countDAO;
-
-        @BeforeEach
-        void setup(CassandraCluster cassandra) {
-            CassandraMailRepositoryMailDaoAPI mailDAO = new CassandraMailRepositoryMailDAO(cassandra.getConf(), BLOB_ID_FACTORY, cassandra.getTypesProvider());
-            FailingKeysDAO keysDAO = new FailingKeysDAO(cassandra.getConf(), CassandraUtils.WITH_DEFAULT_CONFIGURATION);
-            countDAO = new CassandraMailRepositoryCountDAO(cassandra.getConf());
-            BlobStore blobStore = CassandraBlobStoreFactory.forTesting(cassandra.getConf())
-                .passthrough();
-
-            cassandraMailRepository = new CassandraMailRepository(URL,
-                    keysDAO, countDAO, mailDAO, MimeMessageStore.factory(blobStore).mimeMessageStore());
-        }
-
-        class FailingKeysDAO extends CassandraMailRepositoryKeysDAO {
-
-            FailingKeysDAO(Session session, CassandraUtils cassandraUtils) {
-                super(session, cassandraUtils);
-            }
-
-            @Override
-            public Mono<Boolean> store(MailRepositoryUrl url, MailKey key) {
-                return Mono.fromCallable(() -> {
-                    throw new RuntimeException("Expected failure while storing keys");
-                });
-            }
-        }
-
         @Test
-        void sizeShouldNotBeIncreasedWhenStoringKeysHasFailed() throws Exception {
+        void sizeShouldNotBeIncreasedWhenStoringKeysHasFailed(CassandraCluster cassandra) throws Exception {
+            cassandra.getConf()
+                .registerScenario(fail()
+                    .forever()
+                    .whenQueryStartsWith("INSERT INTO mailRepositoryKeys (name,mailKey)"));
+
             MailImpl mail = MailImpl.builder()
                 .name("mymail")
                 .sender("sender@localhost")
@@ -240,14 +178,18 @@ class CassandraMailRepositoryWithFakeImplementationsTest {
                 .build();
 
             assertThatThrownBy(() -> cassandraMailRepository.store(mail))
-                    .isInstanceOf(RuntimeException.class)
-                    .hasMessage("Expected failure while storing keys");
+                    .isInstanceOf(RuntimeException.class);
 
             assertThat(countDAO.getCount(URL).block()).isEqualTo(0);
         }
 
         @Test
         void mimeMessageShouldBeStoredWhenStoringKeysHasFailed(CassandraCluster cassandra) throws Exception {
+            cassandra.getConf()
+                .registerScenario(fail()
+                    .forever()
+                    .whenQueryStartsWith("INSERT INTO mailRepositoryKeys (name,mailKey)"));
+
             MailImpl mail = MailImpl.builder()
                 .name("mymail")
                 .sender("sender@localhost")
@@ -261,8 +203,7 @@ class CassandraMailRepositoryWithFakeImplementationsTest {
                 .build();
 
             assertThatThrownBy(() -> cassandraMailRepository.store(mail))
-                    .isInstanceOf(RuntimeException.class)
-                    .hasMessage("Expected failure while storing keys");
+                    .isInstanceOf(RuntimeException.class);
 
             ResultSet resultSet = cassandra.getConf().execute(select()
                     .from(BlobTables.DefaultBucketBlobTable.TABLE_NAME));
@@ -271,6 +212,11 @@ class CassandraMailRepositoryWithFakeImplementationsTest {
 
         @Test
         void mailPartsShouldBeStoredWhenStoringKeysHasFailed(CassandraCluster cassandra) throws Exception {
+            cassandra.getConf()
+                .registerScenario(fail()
+                    .forever()
+                    .whenQueryStartsWith("INSERT INTO mailRepositoryKeys (name,mailKey)"));
+
             MailImpl mail = MailImpl.builder()
                 .name("mymail")
                 .sender("sender@localhost")
@@ -284,8 +230,7 @@ class CassandraMailRepositoryWithFakeImplementationsTest {
                 .build();
 
             assertThatThrownBy(() -> cassandraMailRepository.store(mail))
-                    .isInstanceOf(RuntimeException.class)
-                    .hasMessage("Expected failure while storing keys");
+                    .isInstanceOf(RuntimeException.class);
 
             ResultSet resultSet = cassandra.getConf().execute(select()
                     .from(MailRepositoryTable.CONTENT_TABLE_NAME));


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


[james-project] 09/25: [Refactoring] Migrate ICALAttributeDTOTest to Junit 5

Posted by rc...@apache.org.
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 f2351ec0e817f14a9f70a33a55f5faa73420771e
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Fri Jul 24 17:11:32 2020 +0700

    [Refactoring] Migrate ICALAttributeDTOTest to Junit 5
---
 .../mailets/model/ICALAttributeDTOTest.java        | 95 +++++++++++-----------
 1 file changed, 48 insertions(+), 47 deletions(-)

diff --git a/mailet/icalendar/src/test/java/org/apache/james/transport/mailets/model/ICALAttributeDTOTest.java b/mailet/icalendar/src/test/java/org/apache/james/transport/mailets/model/ICALAttributeDTOTest.java
index 5c69a99..3f577d9 100644
--- a/mailet/icalendar/src/test/java/org/apache/james/transport/mailets/model/ICALAttributeDTOTest.java
+++ b/mailet/icalendar/src/test/java/org/apache/james/transport/mailets/model/ICALAttributeDTOTest.java
@@ -20,6 +20,7 @@
 package org.apache.james.transport.mailets.model;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import java.io.ByteArrayInputStream;
 
@@ -27,27 +28,25 @@ import org.apache.james.core.MailAddress;
 import org.apache.james.transport.mailets.ICal4JConfigurator;
 import org.apache.james.util.ClassLoaderUtils;
 import org.apache.mailet.base.MailAddressFixture;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.assertj.core.api.SoftAssertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import com.github.fge.lambdas.Throwing;
 
 import net.fortuna.ical4j.data.CalendarBuilder;
 import net.fortuna.ical4j.model.Calendar;
 import nl.jqno.equalsverifier.EqualsVerifier;
 
-public class ICALAttributeDTOTest {
+class ICALAttributeDTOTest {
 
-    @BeforeClass
-    public static void setUpIcal4J() {
+    @BeforeAll
+    static void setUpIcal4J() {
         ICal4JConfigurator.configure();
     }
 
-    @Rule
-    public ExpectedException expectedException = ExpectedException.none();
-
     @Test
-    public void buildShouldWork() throws Exception {
+    void buildShouldWork() throws Exception {
         byte[] ics = ClassLoaderUtils.getSystemResourceAsByteArray("ics/meeting.ics");
         Calendar calendar = new CalendarBuilder().build(new ByteArrayInputStream(ics));
 
@@ -59,73 +58,75 @@ public class ICALAttributeDTOTest {
             .recipient(recipient)
             .replyTo(sender);
 
-        assertThat(ical.getRecipient()).isEqualTo(recipient.asString());
-        assertThat(ical.getSender()).isEqualTo(sender.asString());
-        assertThat(ical.getUid())
-            .contains("f1514f44bf39311568d640727cff54e819573448d09d2e5677987ff29caa01a9e047feb2aab16e43439a608f28671ab7" +
-                "c10e754ce92be513f8e04ae9ff15e65a9819cf285a6962bc");
-        assertThat(ical.getMethod()).contains("REQUEST");
-        assertThat(ical.getRecurrenceId()).isEmpty();
-        assertThat(ical.getDtstamp()).contains("20170106T115036Z");
-        assertThat(ical.getSequence()).isEqualTo("0");
-        assertThat(ical.getIcal()).isEqualTo(new String(ics, "UTF-8"));
+        SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
+            softly.assertThat(ical.getRecipient()).isEqualTo(recipient.asString());
+            softly.assertThat(ical.getSender()).isEqualTo(sender.asString());
+            softly.assertThat(ical.getUid())
+                .contains("f1514f44bf39311568d640727cff54e819573448d09d2e5677987ff29caa01a9e047feb2aab16e43439a608f28671ab7" +
+                    "c10e754ce92be513f8e04ae9ff15e65a9819cf285a6962bc");
+            softly.assertThat(ical.getMethod()).contains("REQUEST");
+            softly.assertThat(ical.getRecurrenceId()).isEmpty();
+            softly.assertThat(ical.getDtstamp()).contains("20170106T115036Z");
+            softly.assertThat(ical.getSequence()).isEqualTo("0");
+            softly.assertThat(ical.getIcal()).isEqualTo(new String(ics, "UTF-8"));
+        }));
     }
 
     @Test
-    public void equalsAndHashCodeShouldBeWellImplemented() {
+    void equalsAndHashCodeShouldBeWellImplemented() {
         EqualsVerifier.forClass(ICALAttributeDTO.class).verify();
     }
 
     @Test
-    public void buildShouldThrowOnCalendarWithoutDtstamp() throws Exception {
+    void buildShouldThrowOnCalendarWithoutDtstamp() throws Exception {
         byte[] ics = ClassLoaderUtils.getSystemResourceAsByteArray("ics/meeting_without_dtstamp.ics");
         Calendar calendar = new CalendarBuilder().build(new ByteArrayInputStream(ics));
 
-        expectedException.expect(IllegalStateException.class);
-
         MailAddress recipient = MailAddressFixture.ANY_AT_JAMES;
         MailAddress sender = MailAddressFixture.OTHER_AT_JAMES;
-        ICALAttributeDTO.builder()
-            .from(calendar, ics)
-            .sender(sender)
-            .recipient(recipient)
-            .replyTo(sender);
+
+        assertThatThrownBy(() -> ICALAttributeDTO.builder()
+                .from(calendar, ics)
+                .sender(sender)
+                .recipient(recipient)
+                .replyTo(sender))
+            .isInstanceOf(IllegalStateException.class);
     }
 
     @Test
-    public void buildShouldThrowOnCalendarWithoutUid() throws Exception {
+    void buildShouldThrowOnCalendarWithoutUid() throws Exception {
         byte[] ics = ClassLoaderUtils.getSystemResourceAsByteArray("ics/meeting_without_uid.ics");
         Calendar calendar = new CalendarBuilder().build(new ByteArrayInputStream(ics));
 
-        expectedException.expect(IllegalStateException.class);
-
         MailAddress recipient = MailAddressFixture.ANY_AT_JAMES;
         MailAddress sender = MailAddressFixture.OTHER_AT_JAMES;
-        ICALAttributeDTO.builder()
-            .from(calendar, ics)
-            .sender(sender)
-            .recipient(recipient)
-            .replyTo(sender);
+
+        assertThatThrownBy(() -> ICALAttributeDTO.builder()
+                .from(calendar, ics)
+                .sender(sender)
+                .recipient(recipient)
+                .replyTo(sender))
+            .isInstanceOf(IllegalStateException.class);
     }
 
     @Test
-    public void buildShouldThrowOnCalendarWithoutMethod() throws Exception {
+    void buildShouldThrowOnCalendarWithoutMethod() throws Exception {
         byte[] ics = ClassLoaderUtils.getSystemResourceAsByteArray("ics/meeting_without_method.ics");
         Calendar calendar = new CalendarBuilder().build(new ByteArrayInputStream(ics));
 
-        expectedException.expect(IllegalStateException.class);
-
         MailAddress recipient = MailAddressFixture.ANY_AT_JAMES;
         MailAddress sender = MailAddressFixture.OTHER_AT_JAMES;
-        ICALAttributeDTO.builder()
-            .from(calendar, ics)
-            .sender(sender)
-            .recipient(recipient)
-            .replyTo(sender);
+
+        assertThatThrownBy(() -> ICALAttributeDTO.builder()
+                .from(calendar, ics)
+                .sender(sender)
+                .recipient(recipient)
+                .replyTo(sender))
+            .isInstanceOf(IllegalStateException.class);
     }
 
     @Test
-    public void buildShouldSetDefaultValueWhenCalendarWithoutSequence() throws Exception {
+    void buildShouldSetDefaultValueWhenCalendarWithoutSequence() throws Exception {
         byte[] ics = ClassLoaderUtils.getSystemResourceAsByteArray("ics/meeting_without_sequence.ics");
         Calendar calendar = new CalendarBuilder().build(new ByteArrayInputStream(ics));
 


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


[james-project] 25/25: JAMES-3157 Fix support for bench profiles

Posted by rc...@apache.org.
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 2de38df7c1810d1a3b789d2b56a7114b3a4aefc7
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Fri Jul 17 15:07:35 2020 +0200

    JAMES-3157 Fix support for bench profiles
---
 JenkinsfileStressTests.groovy | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/JenkinsfileStressTests.groovy b/JenkinsfileStressTests.groovy
index 213e7fd..61a5bd6 100644
--- a/JenkinsfileStressTests.groovy
+++ b/JenkinsfileStressTests.groovy
@@ -89,8 +89,8 @@ pipeline {
                                 }
                             }
                             if (params.PROFILE in ["s3", "swift"]) {
-                                sh "docker exec james_run ${jamesCliWithOptions} removedomain localhost"
-                                sh "docker exec james_run ${jamesCliWithOptions} removedomain james.linagora.com"
+                                sh "docker exec james_run ${jamesCliWithOptions} removedomain localhost || true"
+                                sh "docker exec james_run ${jamesCliWithOptions} removedomain james.linagora.com || true"
                                 sh "docker exec james_run ${jamesCliWithOptions} adddomain open-paas.org"
                                 for (int n = 0; n <= 100; n++) {
                                     sh "docker exec james_run ${jamesCliWithOptions} adduser user${n}@open-paas.org secret"


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


[james-project] 03/25: [Refactoring] Migrate MailetPipelineLoggingTest to Junit 5

Posted by rc...@apache.org.
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 fcf79b5c368dcde5e73ae10eb433114e77cb91ff
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Fri Jul 24 14:45:52 2020 +0700

    [Refactoring] Migrate MailetPipelineLoggingTest to Junit 5
---
 .../mailet/base/MailetPipelineLoggingTest.java     | 31 ++++++++++------------
 1 file changed, 14 insertions(+), 17 deletions(-)

diff --git a/mailet/base/src/test/java/org/apache/mailet/base/MailetPipelineLoggingTest.java b/mailet/base/src/test/java/org/apache/mailet/base/MailetPipelineLoggingTest.java
index 18a6a44..e8a8706 100644
--- a/mailet/base/src/test/java/org/apache/mailet/base/MailetPipelineLoggingTest.java
+++ b/mailet/base/src/test/java/org/apache/mailet/base/MailetPipelineLoggingTest.java
@@ -22,18 +22,10 @@ package org.apache.mailet.base;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import org.apache.mailet.Mail;
-import org.junit.Test;
-
-public class MailetPipelineLoggingTest {
-
-    @Test
-    public void getMailetInfoShouldReturnMailetInfoWhenGiven() {
-        assertThat(MailetPipelineLogging.getMailetInfo(new MailetWithMailetInfo()))
-            .isEqualTo("this is my info");
-    }
+import org.junit.jupiter.api.Test;
 
+class MailetPipelineLoggingTest {
     private static class MailetWithMailetInfo extends GenericMailet {
-
         @Override
         public String getMailetInfo() {
             return "this is my info";
@@ -44,16 +36,21 @@ public class MailetPipelineLoggingTest {
         }
     }
 
-    @Test
-    public void getMailetInfoShouldReturnSimpleClassNameWhenMailetInfoIsEmpty() {
-        assertThat(MailetPipelineLogging.getMailetInfo(new MailetWithoutMailetInfo()))
-            .isEqualTo("MailetWithoutMailetInfo");
-    }
-
     private static class MailetWithoutMailetInfo extends GenericMailet {
-
         @Override
         public void service(Mail mail) {
         }
     }
+
+    @Test
+    void getMailetInfoShouldReturnMailetInfoWhenGiven() {
+        assertThat(MailetPipelineLogging.getMailetInfo(new MailetWithMailetInfo()))
+            .isEqualTo("this is my info");
+    }
+
+    @Test
+    void getMailetInfoShouldReturnSimpleClassNameWhenMailetInfoIsEmpty() {
+        assertThat(MailetPipelineLogging.getMailetInfo(new MailetWithoutMailetInfo()))
+            .isEqualTo("MailetWithoutMailetInfo");
+    }
 }
\ 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] 19/25: JAMES-3319 Tests for CassandraMailRepository blob deletion

Posted by rc...@apache.org.
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 87a0d258decc2e1102cb2ae82b02d79c4523af8e
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Jul 24 11:47:55 2020 +0700

    JAMES-3319 Tests for CassandraMailRepository blob deletion
    
    Tests are conducted out both on Deduplication & Passthrough BlobStores
---
 .../james/mailrepository/cassandra/CassandraMailRepositoryTest.java   | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryTest.java b/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryTest.java
index 3011e98..9ff4496 100644
--- a/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryTest.java
+++ b/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryTest.java
@@ -19,6 +19,7 @@
 
 package org.apache.james.mailrepository.cassandra;
 
+import static com.datastax.driver.core.querybuilder.QueryBuilder.select;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatCode;
 
@@ -29,6 +30,7 @@ import org.apache.james.backends.cassandra.utils.CassandraUtils;
 import org.apache.james.backends.cassandra.versions.CassandraSchemaVersionModule;
 import org.apache.james.blob.api.BlobStore;
 import org.apache.james.blob.api.HashBlobId;
+import org.apache.james.blob.cassandra.BlobTables;
 import org.apache.james.blob.cassandra.CassandraBlobModule;
 import org.apache.james.blob.cassandra.CassandraBlobStoreFactory;
 import org.apache.james.blob.mail.MimeMessageStore;
@@ -91,7 +93,7 @@ class CassandraMailRepositoryTest {
 
             testee.remove(key1);
 
-            assertThat(cassandra.getConf().execute("SELECT * FROM blobs;"))
+            assertThat(cassandra.getConf().execute(select().from(BlobTables.DefaultBucketBlobTable.TABLE_NAME)))
                 .isEmpty();
         }
     }


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


[james-project] 02/25: [Refactoring] Migrate GenericMailetTest to Junit 5

Posted by rc...@apache.org.
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 810c97e9938db5611708c26722cce28eb330c553
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Fri Jul 24 14:43:20 2020 +0700

    [Refactoring] Migrate GenericMailetTest to Junit 5
---
 .../org/apache/mailet/base/GenericMailetTest.java  | 28 +++++++++++-----------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/mailet/base/src/test/java/org/apache/mailet/base/GenericMailetTest.java b/mailet/base/src/test/java/org/apache/mailet/base/GenericMailetTest.java
index a8629eb..842a310 100644
--- a/mailet/base/src/test/java/org/apache/mailet/base/GenericMailetTest.java
+++ b/mailet/base/src/test/java/org/apache/mailet/base/GenericMailetTest.java
@@ -24,10 +24,10 @@ import static org.assertj.core.api.Assertions.assertThat;
 import javax.mail.MessagingException;
 
 import org.apache.mailet.Mail;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
-public class GenericMailetTest {
+class GenericMailetTest {
 
     private static class TestingMailet extends GenericMailet {
 
@@ -36,64 +36,64 @@ public class GenericMailetTest {
         }
     }
 
-    private TestingMailet testee;
+    TestingMailet testee;
 
-    @Before
-    public void setup() {
+    @BeforeEach
+    void setup() {
         testee = new TestingMailet();
     }
 
     @Test
-    public void getBooleanParameterShouldReturnFalseWhenValueNullAndDefaultFalse() throws Exception {
+    void getBooleanParameterShouldReturnFalseWhenValueNullAndDefaultFalse() throws Exception {
         String value = null;
         boolean actual = testee.getBooleanParameter(value, false);
         assertThat(actual).isFalse();
     }
     
     @Test
-    public void getBooleanParameterShouldReturnTrueWhenValueTrueAndDefaultFalse() throws Exception {
+    void getBooleanParameterShouldReturnTrueWhenValueTrueAndDefaultFalse() throws Exception {
         String value = "true";
         boolean actual = testee.getBooleanParameter(value, false);
         assertThat(actual).isTrue();
     }
     
     @Test
-    public void getBooleanParameterShouldReturnTrueWhenValueYesAndDefaultFalse() throws Exception {
+    void getBooleanParameterShouldReturnTrueWhenValueYesAndDefaultFalse() throws Exception {
         String value = "yes";
         boolean actual = testee.getBooleanParameter(value, false);
         assertThat(actual).isTrue();
     }
 
     @Test
-    public void getBooleanParameterShouldReturnFalseWhenValueOtherAndDefaultFalse() throws Exception {
+    void getBooleanParameterShouldReturnFalseWhenValueOtherAndDefaultFalse() throws Exception {
         String value = "other";
         boolean actual = testee.getBooleanParameter(value, false);
         assertThat(actual).isFalse();
     }
 
     @Test
-    public void getBooleanParameterShouldReturnTrueWhenValueNullAndDefaultTrue() throws Exception {
+    void getBooleanParameterShouldReturnTrueWhenValueNullAndDefaultTrue() throws Exception {
         String value = null;
         boolean actual = testee.getBooleanParameter(value, true);
         assertThat(actual).isTrue();
     }
 
     @Test
-    public void getBooleanParameterShouldReturnFalseWhenValueNoAndDefaultTrue() throws Exception {
+    void getBooleanParameterShouldReturnFalseWhenValueNoAndDefaultTrue() throws Exception {
         String value = "no";
         boolean actual = testee.getBooleanParameter(value, true);
         assertThat(actual).isFalse();
     }
 
     @Test
-    public void getBooleanParameterShouldReturnFalseWhenValueFalseAndDefaultTrue() throws Exception {
+    void getBooleanParameterShouldReturnFalseWhenValueFalseAndDefaultTrue() throws Exception {
         String value = "false";
         boolean actual = testee.getBooleanParameter(value, true);
         assertThat(actual).isFalse();
     }
 
     @Test
-    public void getBooleanParameterShouldReturnTrueWhenValueOtherAndDefaultTrue() throws Exception {
+    void getBooleanParameterShouldReturnTrueWhenValueOtherAndDefaultTrue() throws Exception {
         String value = "other";
         boolean actual = testee.getBooleanParameter(value, true);
         assertThat(actual).isTrue();


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


[james-project] 22/25: JAMES-3319 Actual blob deletion for CassandraMailRepository

Posted by rc...@apache.org.
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 74311ada30ab2d93e777c2dc3b0b0100e3b6aa55
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Jul 24 13:28:24 2020 +0700

    JAMES-3319 Actual blob deletion for CassandraMailRepository
---
 .../cassandra/CassandraMailRepository.java         | 23 ++++++++++++++++++----
 .../cassandra/CassandraMailRepositoryTest.java     |  5 ++---
 ...aMailRepositoryWithFakeImplementationsTest.java |  2 +-
 3 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/server/mailrepository/mailrepository-cassandra/src/main/java/org/apache/james/mailrepository/cassandra/CassandraMailRepository.java b/server/mailrepository/mailrepository-cassandra/src/main/java/org/apache/james/mailrepository/cassandra/CassandraMailRepository.java
index f2b5168..a0b1805 100644
--- a/server/mailrepository/mailrepository-cassandra/src/main/java/org/apache/james/mailrepository/cassandra/CassandraMailRepository.java
+++ b/server/mailrepository/mailrepository-cassandra/src/main/java/org/apache/james/mailrepository/cassandra/CassandraMailRepository.java
@@ -23,11 +23,13 @@ import static org.apache.james.util.ReactorUtils.publishIfPresent;
 
 import java.util.Collection;
 import java.util.Iterator;
+import java.util.Optional;
 
 import javax.inject.Inject;
 import javax.mail.MessagingException;
 import javax.mail.internet.MimeMessage;
 
+import org.apache.james.blob.api.BlobStore;
 import org.apache.james.blob.api.Store;
 import org.apache.james.blob.mail.MimeMessagePartsId;
 import org.apache.james.blob.mail.MimeMessageStore;
@@ -46,16 +48,18 @@ public class CassandraMailRepository implements MailRepository {
     private final CassandraMailRepositoryCountDAO countDAO;
     private final CassandraMailRepositoryMailDaoAPI mailDAO;
     private final Store<MimeMessage, MimeMessagePartsId> mimeMessageStore;
+    private final BlobStore blobStore;
 
     @Inject
     CassandraMailRepository(MailRepositoryUrl url, CassandraMailRepositoryKeysDAO keysDAO,
                             CassandraMailRepositoryCountDAO countDAO, CassandraMailRepositoryMailDaoAPI mailDAO,
-                            MimeMessageStore.Factory mimeMessageStoreFactory) {
+                            MimeMessageStore.Factory mimeMessageStoreFactory, BlobStore blobStore) {
         this.url = url;
         this.keysDAO = keysDAO;
         this.countDAO = countDAO;
         this.mailDAO = mailDAO;
         this.mimeMessageStore = mimeMessageStoreFactory.mimeMessageStore();
+        this.blobStore = blobStore;
     }
 
     @Override
@@ -127,9 +131,20 @@ public class CassandraMailRepository implements MailRepository {
     }
 
     private Mono<Void> removeAsync(MailKey key) {
-        return keysDAO.remove(url, key)
-            .flatMap(this::decreaseSizeIfDeleted)
-            .then(mailDAO.remove(url, key));
+        return mailDAO.read(url, key)
+            .flatMap(maybeMailDTO ->
+                keysDAO.remove(url, key)
+                    .flatMap(this::decreaseSizeIfDeleted)
+                    .then(mailDAO.remove(url, key))
+                    .then(deleteBlobs(maybeMailDTO)));
+    }
+
+    private Mono<Void> deleteBlobs(Optional<MailDTO> maybeMailDTO) {
+        return Mono.justOrEmpty(maybeMailDTO)
+            .flatMap(mailDTO -> Flux.merge(
+                    blobStore.delete(blobStore.getDefaultBucketName(), mailDTO.getHeaderBlobId()),
+                    blobStore.delete(blobStore.getDefaultBucketName(), mailDTO.getBodyBlobId()))
+                .then());
     }
 
     private Mono<Void> decreaseSizeIfDeleted(Boolean isDeleted) {
diff --git a/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryTest.java b/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryTest.java
index 6d6e443..009b9a7 100644
--- a/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryTest.java
+++ b/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryTest.java
@@ -70,7 +70,7 @@ class CassandraMailRepositoryTest {
                 .passthrough();
 
             cassandraMailRepository = new CassandraMailRepository(URL,
-                keysDAO, countDAO, mailDAO, MimeMessageStore.factory(blobStore));
+                keysDAO, countDAO, mailDAO, MimeMessageStore.factory(blobStore), blobStore);
         }
 
         @Override
@@ -84,7 +84,6 @@ class CassandraMailRepositoryTest {
         public void sizeShouldBeIncrementedByOneWhenDuplicates() {
         }
 
-        @Disabled("Failing")
         @Test
         void removeShouldDeleteStoredBlobs(CassandraCluster cassandra) throws Exception {
             MailRepository testee = retrieveRepository();
@@ -111,7 +110,7 @@ class CassandraMailRepositoryTest {
                 .deduplication();
 
             cassandraMailRepository = new CassandraMailRepository(URL,
-                keysDAO, countDAO, mailDAO, MimeMessageStore.factory(blobStore));
+                keysDAO, countDAO, mailDAO, MimeMessageStore.factory(blobStore), blobStore);
         }
 
         @Override
diff --git a/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryWithFakeImplementationsTest.java b/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryWithFakeImplementationsTest.java
index a420ac5..8bc6d06 100644
--- a/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryWithFakeImplementationsTest.java
+++ b/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryWithFakeImplementationsTest.java
@@ -70,7 +70,7 @@ class CassandraMailRepositoryWithFakeImplementationsTest {
             .passthrough();
 
         cassandraMailRepository = new CassandraMailRepository(URL,
-            keysDAO, countDAO, mailDAO, MimeMessageStore.factory(blobStore));
+            keysDAO, countDAO, mailDAO, MimeMessageStore.factory(blobStore), blobStore);
     }
 
     @Nested


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


[james-project] 01/25: JAMES-3344 Upgrade Bouncy Castle to last version

Posted by rc...@apache.org.
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 e104e7cf3503b023192bd97481064e0471475afa
Author: Raphael Ouazana <ra...@linagora.com>
AuthorDate: Mon Jul 27 17:43:59 2020 +0200

    JAMES-3344 Upgrade Bouncy Castle to last version
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 54cf223..b692eb8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -643,7 +643,7 @@
         <guice.version>4.2.2</guice.version>
         <logback.version>1.2.3</logback.version>
 
-        <bouncycastle.version>1.62</bouncycastle.version>
+        <bouncycastle.version>1.66</bouncycastle.version>
 
         <scala.base>2.13</scala.base>
         <scala.version>${scala.base}.1</scala.version>


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


[james-project] 11/25: JAMES-3318 Remove BlobStore::delete from BlobStore contract

Posted by rc...@apache.org.
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 75ad3e2f0f6e030aa4305e240da433a5cc0896a0
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Jul 24 09:12:24 2020 +0700

    JAMES-3318 Remove BlobStore::delete from BlobStore contract
---
 .../java/org/apache/james/blob/api/BlobStoreContract.java   |  2 +-
 .../blob/cassandra/CassandraPassTroughBlobStoreTest.java    |  3 ++-
 .../james/blob/memory/MemoryBlobStorePassThroughTest.java   |  3 ++-
 .../objectstorage/ObjectStorageBlobStoreAWSCryptoTest.java  | 13 -------------
 .../ObjectStorageBlobStoreAWSNamespaceTest.java             | 13 -------------
 .../ObjectStorageBlobStoreAWSPrefixAndNamespaceTest.java    | 13 -------------
 .../objectstorage/ObjectStorageBlobStoreAWSPrefixTest.java  | 13 -------------
 .../blob/objectstorage/ObjectStorageBlobStoreAWSTest.java   | 13 -------------
 8 files changed, 5 insertions(+), 68 deletions(-)

diff --git a/server/blob/blob-api/src/test/java/org/apache/james/blob/api/BlobStoreContract.java b/server/blob/blob-api/src/test/java/org/apache/james/blob/api/BlobStoreContract.java
index b9f8e1b..92f9063 100644
--- a/server/blob/blob-api/src/test/java/org/apache/james/blob/api/BlobStoreContract.java
+++ b/server/blob/blob-api/src/test/java/org/apache/james/blob/api/BlobStoreContract.java
@@ -39,7 +39,7 @@ import com.google.common.base.Strings;
 
 import reactor.core.publisher.Mono;
 
-public interface BlobStoreContract extends DeleteBlobStoreContract, BucketBlobStoreContract {
+public interface BlobStoreContract extends BucketBlobStoreContract {
 
     static Stream<Arguments> storagePolicies() {
         return Stream.of(
diff --git a/server/blob/blob-cassandra/src/test/java/org/apache/james/blob/cassandra/CassandraPassTroughBlobStoreTest.java b/server/blob/blob-cassandra/src/test/java/org/apache/james/blob/cassandra/CassandraPassTroughBlobStoreTest.java
index 755dc28..2df512e 100644
--- a/server/blob/blob-cassandra/src/test/java/org/apache/james/blob/cassandra/CassandraPassTroughBlobStoreTest.java
+++ b/server/blob/blob-cassandra/src/test/java/org/apache/james/blob/cassandra/CassandraPassTroughBlobStoreTest.java
@@ -27,13 +27,14 @@ import org.apache.james.backends.cassandra.init.configuration.CassandraConfigura
 import org.apache.james.blob.api.BlobId;
 import org.apache.james.blob.api.BlobStore;
 import org.apache.james.blob.api.BucketName;
+import org.apache.james.blob.api.DeleteBlobStoreContract;
 import org.apache.james.blob.api.HashBlobId;
 import org.apache.james.blob.api.MetricableBlobStore;
 import org.apache.james.server.blob.deduplication.BlobStoreFactory;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.extension.RegisterExtension;
 
-public class CassandraPassTroughBlobStoreTest implements CassandraBlobStoreContract {
+public class CassandraPassTroughBlobStoreTest implements DeleteBlobStoreContract, CassandraBlobStoreContract {
     @RegisterExtension
     static CassandraClusterExtension cassandraCluster = new CassandraClusterExtension(CassandraBlobModule.MODULE);
 
diff --git a/server/blob/blob-memory/src/test/java/org/apache/james/blob/memory/MemoryBlobStorePassThroughTest.java b/server/blob/blob-memory/src/test/java/org/apache/james/blob/memory/MemoryBlobStorePassThroughTest.java
index aa72550..3ab634b 100644
--- a/server/blob/blob-memory/src/test/java/org/apache/james/blob/memory/MemoryBlobStorePassThroughTest.java
+++ b/server/blob/blob-memory/src/test/java/org/apache/james/blob/memory/MemoryBlobStorePassThroughTest.java
@@ -21,12 +21,13 @@ package org.apache.james.blob.memory;
 
 import org.apache.james.blob.api.BlobId;
 import org.apache.james.blob.api.BlobStore;
+import org.apache.james.blob.api.DeleteBlobStoreContract;
 import org.apache.james.blob.api.HashBlobId;
 import org.apache.james.blob.api.MetricableBlobStore;
 import org.apache.james.blob.api.MetricableBlobStoreContract;
 import org.junit.jupiter.api.BeforeEach;
 
-public class MemoryBlobStorePassThroughTest implements MetricableBlobStoreContract {
+public class MemoryBlobStorePassThroughTest implements DeleteBlobStoreContract, MetricableBlobStoreContract {
 
     private static final HashBlobId.Factory BLOB_ID_FACTORY = new HashBlobId.Factory();
     private BlobStore blobStore;
diff --git a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobStoreAWSCryptoTest.java b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobStoreAWSCryptoTest.java
index 3a23b22..ffb5c21 100644
--- a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobStoreAWSCryptoTest.java
+++ b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobStoreAWSCryptoTest.java
@@ -35,7 +35,6 @@ import org.apache.james.blob.objectstorage.crypto.CryptoConfig;
 import org.apache.james.blob.objectstorage.swift.Credentials;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.extension.ExtendWith;
 
 @ExtendWith(DockerAwsS3Extension.class)
@@ -87,16 +86,4 @@ public class ObjectStorageBlobStoreAWSCryptoTest implements MetricableBlobStoreC
     public BlobId.Factory blobIdFactory() {
         return BLOB_ID_FACTORY;
     }
-
-    @Override
-    @Disabled("JAMES-2829 Unstable with scality/S3 impl")
-    public void readShouldNotReadPartiallyWhenDeletingConcurrentlyBigBlob() {
-
-    }
-
-    @Override
-    @Disabled("JAMES-2838 Unstable with scality/S3 impl")
-    public void readBytesShouldNotReadPartiallyWhenDeletingConcurrentlyBigBlob() {
-
-    }
 }
diff --git a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobStoreAWSNamespaceTest.java b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobStoreAWSNamespaceTest.java
index 9b17ceb..11d0850 100644
--- a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobStoreAWSNamespaceTest.java
+++ b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobStoreAWSNamespaceTest.java
@@ -34,7 +34,6 @@ import org.apache.james.blob.objectstorage.aws.DockerAwsS3Container;
 import org.apache.james.blob.objectstorage.aws.DockerAwsS3Extension;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.extension.ExtendWith;
 
 @ExtendWith(DockerAwsS3Extension.class)
@@ -80,17 +79,5 @@ public class ObjectStorageBlobStoreAWSNamespaceTest implements MetricableBlobSto
     public BlobId.Factory blobIdFactory() {
         return new HashBlobId.Factory();
     }
-
-    @Override
-    @Disabled("JAMES-2829 Unstable with scality/S3 impl")
-    public void readShouldNotReadPartiallyWhenDeletingConcurrentlyBigBlob() {
-
-    }
-
-    @Override
-    @Disabled("JAMES-2838 Unstable with scality/S3 impl")
-    public void readBytesShouldNotReadPartiallyWhenDeletingConcurrentlyBigBlob() {
-
-    }
 }
 
diff --git a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobStoreAWSPrefixAndNamespaceTest.java b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobStoreAWSPrefixAndNamespaceTest.java
index 4592820..1479f47 100644
--- a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobStoreAWSPrefixAndNamespaceTest.java
+++ b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobStoreAWSPrefixAndNamespaceTest.java
@@ -34,7 +34,6 @@ import org.apache.james.blob.objectstorage.aws.DockerAwsS3Container;
 import org.apache.james.blob.objectstorage.aws.DockerAwsS3Extension;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.extension.ExtendWith;
 
 @ExtendWith(DockerAwsS3Extension.class)
@@ -81,17 +80,5 @@ public class ObjectStorageBlobStoreAWSPrefixAndNamespaceTest implements Metricab
     public BlobId.Factory blobIdFactory() {
         return new HashBlobId.Factory();
     }
-
-    @Override
-    @Disabled("JAMES-2829 Unstable with scality/S3 impl")
-    public void readShouldNotReadPartiallyWhenDeletingConcurrentlyBigBlob() {
-
-    }
-
-    @Override
-    @Disabled("JAMES-2838 Unstable with scality/S3 impl")
-    public void readBytesShouldNotReadPartiallyWhenDeletingConcurrentlyBigBlob() {
-
-    }
 }
 
diff --git a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobStoreAWSPrefixTest.java b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobStoreAWSPrefixTest.java
index 3de820c..48af903 100644
--- a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobStoreAWSPrefixTest.java
+++ b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobStoreAWSPrefixTest.java
@@ -33,7 +33,6 @@ import org.apache.james.blob.objectstorage.aws.DockerAwsS3Container;
 import org.apache.james.blob.objectstorage.aws.DockerAwsS3Extension;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.extension.ExtendWith;
 
 @ExtendWith(DockerAwsS3Extension.class)
@@ -79,17 +78,5 @@ public class ObjectStorageBlobStoreAWSPrefixTest implements MetricableBlobStoreC
     public BlobId.Factory blobIdFactory() {
         return new HashBlobId.Factory();
     }
-
-    @Override
-    @Disabled("JAMES-2829 Unstable with scality/S3 impl")
-    public void readShouldNotReadPartiallyWhenDeletingConcurrentlyBigBlob() {
-
-    }
-
-    @Override
-    @Disabled("JAMES-2838 Unstable with scality/S3 impl")
-    public void readBytesShouldNotReadPartiallyWhenDeletingConcurrentlyBigBlob() {
-
-    }
 }
 
diff --git a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobStoreAWSTest.java b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobStoreAWSTest.java
index 1e66e98..cc16ad0 100644
--- a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobStoreAWSTest.java
+++ b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobStoreAWSTest.java
@@ -33,7 +33,6 @@ import org.apache.james.blob.objectstorage.aws.DockerAwsS3Container;
 import org.apache.james.blob.objectstorage.aws.DockerAwsS3Extension;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.extension.ExtendWith;
 
 @ExtendWith(DockerAwsS3Extension.class)
@@ -79,16 +78,4 @@ public class ObjectStorageBlobStoreAWSTest implements MetricableBlobStoreContrac
     public BlobId.Factory blobIdFactory() {
         return BLOB_ID_FACTORY;
     }
-
-    @Override
-    @Disabled("JAMES-2829 Unstable with scality/S3 impl")
-    public void readShouldNotReadPartiallyWhenDeletingConcurrentlyBigBlob() {
-
-    }
-
-    @Override
-    @Disabled("JAMES-2838 Unstable with scality/S3 impl")
-    public void readBytesShouldNotReadPartiallyWhenDeletingConcurrentlyBigBlob() {
-
-    }
 }


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


[james-project] 04/25: [Refactoring] Migrate MailetUtilTest to Junit 5

Posted by rc...@apache.org.
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 6b640caa85e84f3e5e27e352cd1ca1a091ffb110
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Fri Jul 24 14:53:48 2020 +0700

    [Refactoring] Migrate MailetUtilTest to Junit 5
---
 .../org/apache/mailet/base/MailetUtilTest.java     | 128 ++++++++++-----------
 1 file changed, 61 insertions(+), 67 deletions(-)

diff --git a/mailet/base/src/test/java/org/apache/mailet/base/MailetUtilTest.java b/mailet/base/src/test/java/org/apache/mailet/base/MailetUtilTest.java
index 64430ec..88e7460 100644
--- a/mailet/base/src/test/java/org/apache/mailet/base/MailetUtilTest.java
+++ b/mailet/base/src/test/java/org/apache/mailet/base/MailetUtilTest.java
@@ -20,154 +20,148 @@
 package org.apache.mailet.base;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import javax.mail.MessagingException;
 
 import org.apache.mailet.base.test.FakeMailetConfig;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.assertj.core.api.SoftAssertions;
+import org.junit.jupiter.api.Test;
 
-public class MailetUtilTest {
+class MailetUtilTest {
 
-    private static final String A_PARAMETER = "aParameter";
-    public static final int DEFAULT_VALUE = 36;
-
-    @Rule
-    public ExpectedException expectedException = ExpectedException.none();
+    static final String A_PARAMETER = "aParameter";
+    static final int DEFAULT_VALUE = 36;
 
     @Test
-    public void getInitParameterShouldReturnTrueWhenIsValueTrueLowerCase() {
+    void getInitParameterShouldReturnTrueWhenIsValueTrueLowerCase() {
         assertThat(getParameterValued("true", false)).isTrue();
     }
 
     @Test
-    public void getInitParameterShouldReturnTrueWhenIsValueTrueUpperCase() {
+    void getInitParameterShouldReturnTrueWhenIsValueTrueUpperCase() {
         assertThat(getParameterValued("TRUE", false)).isTrue();
     }
 
     @Test
-    public void getInitParameterShouldReturnTrueWhenIsValueTrueMixedCase() {
+    void getInitParameterShouldReturnTrueWhenIsValueTrueMixedCase() {
         assertThat(getParameterValued("trUE", false)).isTrue();
     }
 
     @Test
-    public void getInitParameterShouldReturnFalseWhenIsValueFalseLowerCase() {
+    void getInitParameterShouldReturnFalseWhenIsValueFalseLowerCase() {
         assertThat(getParameterValued("false", true)).isFalse();
     }
 
     @Test
-    public void getInitParameterShouldReturnFalseWhenIsValueFalseUpperCase() {
+    void getInitParameterShouldReturnFalseWhenIsValueFalseUpperCase() {
         assertThat(getParameterValued("FALSE", true)).isFalse();
     }
 
     @Test
-    public void getInitParameterShouldReturnFalseWhenIsValueFalseMixedCase() {
+    void getInitParameterShouldReturnFalseWhenIsValueFalseMixedCase() {
         assertThat(getParameterValued("fALSe", true)).isFalse();
     }
 
     @Test
-    public void getInitParameterShouldReturnDefaultValueAsTrueWhenBadValue() {
-        assertThat(getParameterValued("fals", true)).isTrue();
-        assertThat(getParameterValued("TRU", true)).isTrue();
-        assertThat(getParameterValued("FALSEest", true)).isTrue();
-        assertThat(getParameterValued("", true)).isTrue();
-        assertThat(getParameterValued("gubbins", true)).isTrue();
+    void getInitParameterShouldReturnDefaultValueAsTrueWhenBadValue() {
+        SoftAssertions.assertSoftly(softly -> {
+            softly.assertThat(getParameterValued("fals", true)).isTrue();
+            softly.assertThat(getParameterValued("TRU", true)).isTrue();
+            softly.assertThat(getParameterValued("FALSEest", true)).isTrue();
+            softly.assertThat(getParameterValued("", true)).isTrue();
+            softly.assertThat(getParameterValued("gubbins", true)).isTrue();
+        });
+
     }
 
     @Test
-    public void getInitParameterShouldReturnDefaultValueAsFalseWhenBadValue() {
-        assertThat(getParameterValued("fals", false)).isFalse();
-        assertThat(getParameterValued("TRU", false)).isFalse();
-        assertThat(getParameterValued("FALSEest", false)).isFalse();
-        assertThat(getParameterValued("", false)).isFalse();
-        assertThat(getParameterValued("gubbins", false)).isFalse();
+    void getInitParameterShouldReturnDefaultValueAsFalseWhenBadValue() {
+        SoftAssertions.assertSoftly(softly -> {
+            softly.assertThat(getParameterValued("fals", false)).isFalse();
+            softly.assertThat(getParameterValued("TRU", false)).isFalse();
+            softly.assertThat(getParameterValued("FALSEest", false)).isFalse();
+            softly.assertThat(getParameterValued("", false)).isFalse();
+            softly.assertThat(getParameterValued("gubbins", false)).isFalse();
+        });
     }
 
     @Test
-    public void getInitParameterShouldReturnAbsentWhenNull() {
+    void getInitParameterShouldReturnAbsentWhenNull() {
         FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
                 .build();
+
         assertThat(MailetUtil.getInitParameter(mailetConfig, A_PARAMETER)).isEmpty();
     }
 
     @Test
-    public void getInitParameterAsStrictlyPositiveIntegerShouldThrowOnEmptyString() throws Exception {
-        expectedException.expect(MessagingException.class);
-
-        MailetUtil.getInitParameterAsStrictlyPositiveInteger("");
+    void getInitParameterAsStrictlyPositiveIntegerShouldThrowOnEmptyString() {
+        assertThatThrownBy(() -> MailetUtil.getInitParameterAsStrictlyPositiveInteger(""))
+            .isInstanceOf(MessagingException.class);
     }
 
     @Test
-    public void getInitParameterAsStrictlyPositiveIntegerShouldThrowOnNull() throws Exception {
-        expectedException.expect(MessagingException.class);
-
-        MailetUtil.getInitParameterAsStrictlyPositiveInteger(null);
+    void getInitParameterAsStrictlyPositiveIntegerShouldThrowOnNull() {
+        assertThatThrownBy(() -> MailetUtil.getInitParameterAsStrictlyPositiveInteger(null))
+            .isInstanceOf(MessagingException.class);
     }
 
     @Test
-    public void getInitParameterAsStrictlyPositiveIntegerShouldThrowOnInvalid() throws Exception {
-        expectedException.expect(MessagingException.class);
-
-        MailetUtil.getInitParameterAsStrictlyPositiveInteger("invalid");
+    void getInitParameterAsStrictlyPositiveIntegerShouldThrowOnInvalid() {
+        assertThatThrownBy(() -> MailetUtil.getInitParameterAsStrictlyPositiveInteger("invalid"))
+            .isInstanceOf(MessagingException.class);
     }
 
     @Test
-    public void getInitParameterAsStrictlyPositiveIntegerShouldThrowOnNegativeNumber() throws Exception {
-        expectedException.expect(MessagingException.class);
-
-        MailetUtil.getInitParameterAsStrictlyPositiveInteger("-1");
+    void getInitParameterAsStrictlyPositiveIntegerShouldThrowOnNegativeNumber() {
+        assertThatThrownBy(() -> MailetUtil.getInitParameterAsStrictlyPositiveInteger("-1"))
+            .isInstanceOf(MessagingException.class);
     }
 
     @Test
-    public void getInitParameterAsStrictlyPositiveIntegerShouldThrowOnZero() throws Exception {
-        expectedException.expect(MessagingException.class);
-
-        MailetUtil.getInitParameterAsStrictlyPositiveInteger("0");
+    void getInitParameterAsStrictlyPositiveIntegerShouldThrowOnZero() {
+        assertThatThrownBy(() -> MailetUtil.getInitParameterAsStrictlyPositiveInteger("0"))
+            .isInstanceOf(MessagingException.class);
     }
 
     @Test
-    public void getInitParameterAsStrictlyPositiveIntegerShouldParseCorrectValue() throws Exception {
+    void getInitParameterAsStrictlyPositiveIntegerShouldParseCorrectValue() throws Exception {
         assertThat(MailetUtil.getInitParameterAsStrictlyPositiveInteger("1"))
             .isEqualTo(1);
     }
 
     @Test
-    public void getInitParameterAsStrictlyPositiveIntegerWithDefaultValueShouldThrowOnEmptyString() throws Exception {
-        expectedException.expect(MessagingException.class);
-
-        MailetUtil.getInitParameterAsStrictlyPositiveInteger("", DEFAULT_VALUE);
+    void getInitParameterAsStrictlyPositiveIntegerWithDefaultValueShouldThrowOnEmptyString() {
+        assertThatThrownBy(() -> MailetUtil.getInitParameterAsStrictlyPositiveInteger("", DEFAULT_VALUE))
+            .isInstanceOf(MessagingException.class);
     }
 
     @Test
-    public void getInitParameterAsStrictlyPositiveIntegerWithDefaultValueShouldReturnDefaultValueOnNull() throws Exception {
+    void getInitParameterAsStrictlyPositiveIntegerWithDefaultValueShouldReturnDefaultValueOnNull() throws Exception {
         assertThat(MailetUtil.getInitParameterAsStrictlyPositiveInteger(null, DEFAULT_VALUE))
             .isEqualTo(DEFAULT_VALUE);
     }
 
     @Test
-    public void getInitParameterAsStrictlyPositiveIntegerWithDefaultValueShouldThrowOnInvalid() throws Exception {
-        expectedException.expect(MessagingException.class);
-
-        MailetUtil.getInitParameterAsStrictlyPositiveInteger("invalid", DEFAULT_VALUE);
+    void getInitParameterAsStrictlyPositiveIntegerWithDefaultValueShouldThrowOnInvalid() {
+        assertThatThrownBy(() -> MailetUtil.getInitParameterAsStrictlyPositiveInteger("invalid", DEFAULT_VALUE))
+            .isInstanceOf(MessagingException.class);
     }
 
     @Test
-    public void getInitParameterAsStrictlyPositiveIntegerWithDefaultValueShouldThrowOnNegativeNumber() throws Exception {
-        expectedException.expect(MessagingException.class);
-
-        MailetUtil.getInitParameterAsStrictlyPositiveInteger("-1", DEFAULT_VALUE);
+    void getInitParameterAsStrictlyPositiveIntegerWithDefaultValueShouldThrowOnNegativeNumber() {
+        assertThatThrownBy(() -> MailetUtil.getInitParameterAsStrictlyPositiveInteger("-1", DEFAULT_VALUE))
+            .isInstanceOf(MessagingException.class);
     }
 
     @Test
-    public void getInitParameterAsStrictlyPositiveIntegerWithDefaultValueShouldThrowOnZero() throws Exception {
-        expectedException.expect(MessagingException.class);
-
-        MailetUtil.getInitParameterAsStrictlyPositiveInteger("0", DEFAULT_VALUE);
+    void getInitParameterAsStrictlyPositiveIntegerWithDefaultValueShouldThrowOnZero() {
+        assertThatThrownBy(() -> MailetUtil.getInitParameterAsStrictlyPositiveInteger("0", DEFAULT_VALUE))
+            .isInstanceOf(MessagingException.class);
     }
 
     @Test
-    public void getInitParameterAsStrictlyPositiveIntegerWithDefaultValueShouldParseCorrectValue() throws Exception {
+    void getInitParameterAsStrictlyPositiveIntegerWithDefaultValueShouldParseCorrectValue() throws Exception {
         assertThat(MailetUtil.getInitParameterAsStrictlyPositiveInteger("1", DEFAULT_VALUE))
             .isEqualTo(1);
     }


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


[james-project] 18/25: JAMES-3319 Rewrite a failure test to leverage Cassandra instrumentation

Posted by rc...@apache.org.
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 b5c4607e26f6b0fa28abb77bffe3a40528638895
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Jul 24 11:45:40 2020 +0700

    JAMES-3319 Rewrite a failure test to leverage Cassandra instrumentation
---
 ...aMailRepositoryWithFakeImplementationsTest.java | 32 ++++++++--------------
 1 file changed, 11 insertions(+), 21 deletions(-)

diff --git a/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryWithFakeImplementationsTest.java b/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryWithFakeImplementationsTest.java
index 60f6ad9..2f0873a 100644
--- a/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryWithFakeImplementationsTest.java
+++ b/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryWithFakeImplementationsTest.java
@@ -20,13 +20,12 @@
 package org.apache.james.mailrepository.cassandra;
 
 import static com.datastax.driver.core.querybuilder.QueryBuilder.select;
+import static org.apache.james.backends.cassandra.Scenario.Builder.fail;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import java.util.Optional;
 
-import javax.mail.internet.MimeMessage;
-
 import org.apache.james.backends.cassandra.CassandraCluster;
 import org.apache.james.backends.cassandra.CassandraClusterExtension;
 import org.apache.james.backends.cassandra.components.CassandraModule;
@@ -35,11 +34,9 @@ import org.apache.james.backends.cassandra.versions.CassandraSchemaVersionModule
 import org.apache.james.blob.api.BlobId;
 import org.apache.james.blob.api.BlobStore;
 import org.apache.james.blob.api.HashBlobId;
-import org.apache.james.blob.api.Store;
 import org.apache.james.blob.cassandra.BlobTables;
 import org.apache.james.blob.cassandra.CassandraBlobModule;
 import org.apache.james.blob.cassandra.CassandraBlobStoreFactory;
-import org.apache.james.blob.mail.MimeMessagePartsId;
 import org.apache.james.blob.mail.MimeMessageStore;
 import org.apache.james.core.builder.MimeMessageBuilder;
 import org.apache.james.mailrepository.api.MailKey;
@@ -56,7 +53,6 @@ import com.datastax.driver.core.Session;
 
 import reactor.core.publisher.Mono;
 
-
 class CassandraMailRepositoryWithFakeImplementationsTest {
     @RegisterExtension
     static CassandraClusterExtension extension = new CassandraClusterExtension(
@@ -78,26 +74,20 @@ class CassandraMailRepositoryWithFakeImplementationsTest {
             CassandraMailRepositoryMailDaoAPI mailDAO = new CassandraMailRepositoryMailDAO(cassandra.getConf(), BLOB_ID_FACTORY, cassandra.getTypesProvider());
             keysDAO = new CassandraMailRepositoryKeysDAO(cassandra.getConf(), CassandraUtils.WITH_DEFAULT_CONFIGURATION);
             CassandraMailRepositoryCountDAO countDAO = new CassandraMailRepositoryCountDAO(cassandra.getConf());
+            BlobStore blobStore = CassandraBlobStoreFactory.forTesting(cassandra.getConf())
+                .deduplication();
 
             cassandraMailRepository = new CassandraMailRepository(URL,
-                    keysDAO, countDAO, mailDAO, new FailingStore());
-        }
-
-        class FailingStore implements Store<MimeMessage, MimeMessagePartsId> {
-
-            @Override
-            public Mono<MimeMessagePartsId> save(MimeMessage mimeMessage) {
-                return Mono.error(new RuntimeException("Expected failure while saving"));
-            }
-
-            @Override
-            public Mono<MimeMessage> read(MimeMessagePartsId blobIds) {
-                return Mono.error(new RuntimeException("Expected failure while reading"));
-            }
+                    keysDAO, countDAO, mailDAO, MimeMessageStore.factory(blobStore).mimeMessageStore());
         }
 
         @Test
-        void keysShouldNotBeStoredWhenStoringMimeMessageHasFailed() throws Exception {
+        void keysShouldNotBeStoredWhenStoringMimeMessageHasFailed(CassandraCluster cassandra) throws Exception {
+            cassandra.getConf()
+                .registerScenario(fail()
+                    .forever()
+                    .whenQueryStartsWith("INSERT INTO blobParts (id,chunkNumber,data) VALUES (:id,:chunkNumber,:data);"));
+
             MailImpl mail = MailImpl.builder()
                 .name("mymail")
                 .sender("sender@localhost")
@@ -112,7 +102,7 @@ class CassandraMailRepositoryWithFakeImplementationsTest {
 
             assertThatThrownBy(() -> cassandraMailRepository.store(mail))
                     .isInstanceOf(RuntimeException.class)
-                    .hasMessage("Expected failure while saving");
+                    .hasMessage("Injected failure");
 
             assertThat(keysDAO.list(URL).collectList().block()).isEmpty();
         }


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


[james-project] 10/25: [Refactoring] Migrate DefaultDescriptorsExtractorTest to Junit 5

Posted by rc...@apache.org.
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 be74e500f791f69535ceb296ddee3c4b16c6cdb8
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Fri Jul 24 17:12:43 2020 +0700

    [Refactoring] Migrate DefaultDescriptorsExtractorTest to Junit 5
---
 .../mailet/DefaultDescriptorsExtractorTest.java      | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/mailet/mailetdocs-maven-plugin/src/test/java/org/apache/james/mailet/DefaultDescriptorsExtractorTest.java b/mailet/mailetdocs-maven-plugin/src/test/java/org/apache/james/mailet/DefaultDescriptorsExtractorTest.java
index e9058d7..7be8ee0 100644
--- a/mailet/mailetdocs-maven-plugin/src/test/java/org/apache/james/mailet/DefaultDescriptorsExtractorTest.java
+++ b/mailet/mailetdocs-maven-plugin/src/test/java/org/apache/james/mailet/DefaultDescriptorsExtractorTest.java
@@ -28,26 +28,26 @@ import java.util.List;
 import org.apache.james.mailet.MailetMatcherDescriptor.Type;
 import org.apache.maven.plugin.logging.Log;
 import org.apache.maven.project.MavenProject;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 import com.google.common.collect.ImmutableList;
 
-public class DefaultDescriptorsExtractorTest {
+class DefaultDescriptorsExtractorTest {
 
-    private MavenProject mavenProject;
-    private Log log;
-    private DefaultDescriptorsExtractor testee;
+    MavenProject mavenProject;
+    Log log;
+    DefaultDescriptorsExtractor testee;
 
-    @Before
-    public void setup() {
+    @BeforeEach
+    void setup() {
         mavenProject = mock(MavenProject.class);
         log = mock(Log.class);
         testee = new DefaultDescriptorsExtractor();
     }
 
     @Test
-    public void extractShouldSetExperimentalAttributeWhenScanningMailets() {
+    void extractShouldSetExperimentalAttributeWhenScanningMailets() {
         when(mavenProject.getCompileSourceRoots())
             .thenReturn(ImmutableList.of("src/test/java/org/apache/james/mailet/experimental"));
 
@@ -73,7 +73,7 @@ public class DefaultDescriptorsExtractorTest {
     }
     
     @Test
-    public void extractShouldExcludeAnnotatedClassesWhenScanningMailets() {
+    void extractShouldExcludeAnnotatedClassesWhenScanningMailets() {
         when(mavenProject.getCompileSourceRoots())
             .thenReturn(ImmutableList.of("src/test/java/org/apache/james/mailet/excluded"));
 


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


[james-project] 06/25: [Refactoring] Migrate StringUtilsTest to Junit 5

Posted by rc...@apache.org.
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 8bea2b450d7809d3f756319746404266493d17f3
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Fri Jul 24 14:57:05 2020 +0700

    [Refactoring] Migrate StringUtilsTest to Junit 5
---
 .../org/apache/mailet/base/StringUtilsTest.java    | 31 +++++++++++-----------
 1 file changed, 15 insertions(+), 16 deletions(-)

diff --git a/mailet/base/src/test/java/org/apache/mailet/base/StringUtilsTest.java b/mailet/base/src/test/java/org/apache/mailet/base/StringUtilsTest.java
index 01636ae..4934457 100644
--- a/mailet/base/src/test/java/org/apache/mailet/base/StringUtilsTest.java
+++ b/mailet/base/src/test/java/org/apache/mailet/base/StringUtilsTest.java
@@ -19,45 +19,44 @@
 package org.apache.mailet.base;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Test;
 
 import com.google.common.collect.ImmutableList;
 
-public class StringUtilsTest {
-
-    @Rule
-    public ExpectedException expectedException = ExpectedException.none();
+class StringUtilsTest {
 
     @Test
-    public void listToStringShouldThrowWhenListIsNull() {
-        expectedException.expect(NullPointerException.class);
-        StringUtils.listToString(null);
+    void listToStringShouldThrowWhenListIsNull() {
+        assertThatThrownBy(() -> StringUtils.listToString(null))
+            .isInstanceOf(NullPointerException.class);
     }
 
     @Test
-    public void listToStringShouldReturnOnlyBracketsWhenListIsEmpty() {
+    void listToStringShouldReturnOnlyBracketsWhenListIsEmpty() {
         String listToString = StringUtils.listToString(ImmutableList.<String>of());
+
         assertThat(listToString).isEqualTo("[]");
     }
 
     @Test
-    public void listToStringShouldReturnOneElementWhenListContainsOneElement() {
+    void listToStringShouldReturnOneElementWhenListContainsOneElement() {
         String listToString = StringUtils.listToString(ImmutableList.of("first"));
+
         assertThat(listToString).isEqualTo("[first]");
     }
 
     @Test
-    public void listToStringShouldReturnSeparatedElementsWhenListContainsMultipleElements() {
+    void listToStringShouldReturnSeparatedElementsWhenListContainsMultipleElements() {
         String listToString = StringUtils.listToString(ImmutableList.of("first", "second", "fourth"));
+
         assertThat(listToString).isEqualTo("[first, second, fourth]");
     }
 
     @Test
-    public void listToStringShouldThrowWhenListContainsANullElement() {
-        expectedException.expect(NullPointerException.class);
-        StringUtils.listToString(ImmutableList.of("first", null, "fourth"));
+    void listToStringShouldThrowWhenListContainsANullElement() {
+        assertThatThrownBy(() -> StringUtils.listToString(ImmutableList.of("first", null, "fourth")))
+            .isInstanceOf(NullPointerException.class);
     }
 }


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


[james-project] 07/25: [Refactoring] Migrate ICalendarParserTest to Junit 5

Posted by rc...@apache.org.
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 fb3dc2a92cc13d9718bac8100842951ef5da1f4c
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Fri Jul 24 17:01:58 2020 +0700

    [Refactoring] Migrate ICalendarParserTest to Junit 5
---
 .../transport/mailets/ICalendarParserTest.java     | 84 +++++++++++-----------
 1 file changed, 42 insertions(+), 42 deletions(-)

diff --git a/mailet/icalendar/src/test/java/org/apache/james/transport/mailets/ICalendarParserTest.java b/mailet/icalendar/src/test/java/org/apache/james/transport/mailets/ICalendarParserTest.java
index 117affa..1718d89 100644
--- a/mailet/icalendar/src/test/java/org/apache/james/transport/mailets/ICalendarParserTest.java
+++ b/mailet/icalendar/src/test/java/org/apache/james/transport/mailets/ICalendarParserTest.java
@@ -19,6 +19,7 @@
 package org.apache.james.transport.mailets;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import java.io.Serializable;
 import java.util.Map;
@@ -34,38 +35,33 @@ import org.apache.mailet.AttributeValue;
 import org.apache.mailet.Mail;
 import org.apache.mailet.base.test.FakeMail;
 import org.apache.mailet.base.test.FakeMailetConfig;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Test;
 
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Maps;
 
 import net.fortuna.ical4j.model.Calendar;
 
-public class ICalendarParserTest {
-    private static final String DESTINATION_ATTRIBUTE = "destinationAttribute";
-    private static final String SOURCE_ATTRIBUTE = "sourceAttribute";
+class ICalendarParserTest {
+    static final String DESTINATION_ATTRIBUTE = "destinationAttribute";
+    static final String SOURCE_ATTRIBUTE = "sourceAttribute";
 
-    private static final String DESTINATION_CUSTOM_ATTRIBUTE = "ics.dest.attribute";
-    private static final AttributeName DESTINATION_CUSTOM_ATTRIBUTE_NAME = AttributeName.of(DESTINATION_CUSTOM_ATTRIBUTE);
-    private static final String SOURCE_CUSTOM_ATTRIBUTE = "ics.source.attribute";
-    private static final AttributeName SOURCE_CUSTOM_ATTRIBUTE_NAME = AttributeName.of(SOURCE_CUSTOM_ATTRIBUTE);
+    static final String DESTINATION_CUSTOM_ATTRIBUTE = "ics.dest.attribute";
+    static final AttributeName DESTINATION_CUSTOM_ATTRIBUTE_NAME = AttributeName.of(DESTINATION_CUSTOM_ATTRIBUTE);
+    static final String SOURCE_CUSTOM_ATTRIBUTE = "ics.source.attribute";
+    static final AttributeName SOURCE_CUSTOM_ATTRIBUTE_NAME = AttributeName.of(SOURCE_CUSTOM_ATTRIBUTE);
 
-    private static final String RIGHT_ICAL_VALUE = "BEGIN:VCALENDAR\n" +
+    static final String RIGHT_ICAL_VALUE = "BEGIN:VCALENDAR\n" +
         "END:VCALENDAR";
 
-    private static final String WRONG_ICAL_VALUE = "anyValue";
+    static final String WRONG_ICAL_VALUE = "anyValue";
     @SuppressWarnings("unchecked")
-    public static final Class<Map<String, Calendar>> MAP_STRING_CALENDAR_CLASS = (Class<Map<String, Calendar>>) (Object) Map.class;
+    static final Class<Map<String, Calendar>> MAP_STRING_CALENDAR_CLASS = (Class<Map<String, Calendar>>) (Object) Map.class;
 
-    @Rule
-    public ExpectedException expectedException = ExpectedException.none();
-
-    private ICalendarParser mailet = new ICalendarParser();
+    ICalendarParser mailet = new ICalendarParser();
 
     @Test
-    public void initShouldSetSourceAttributeWhenAbsent() throws Exception {
+    void initShouldSetSourceAttributeWhenAbsent() throws Exception {
         mailet.init(FakeMailetConfig.builder()
             .mailetName("ICalendarParser")
             .build());
@@ -74,7 +70,7 @@ public class ICalendarParserTest {
     }
 
     @Test
-    public void initShouldSetDestinationAttributeWhenAbsent() throws Exception {
+    void initShouldSetDestinationAttributeWhenAbsent() throws Exception {
         mailet.init(FakeMailetConfig.builder()
             .mailetName("ICalendarParser")
             .build());
@@ -83,7 +79,7 @@ public class ICalendarParserTest {
     }
 
     @Test
-    public void initShouldSetSourceAttributeWhenPresent() throws Exception {
+    void initShouldSetSourceAttributeWhenPresent() throws Exception {
         String sourceAttribute = "sourceAttribute";
         mailet.init(FakeMailetConfig.builder()
             .mailetName("ICalendarParser")
@@ -94,7 +90,7 @@ public class ICalendarParserTest {
     }
 
     @Test
-    public void initShouldSetDestinationAttributeWhenPresent() throws Exception {
+    void initShouldSetDestinationAttributeWhenPresent() throws Exception {
         String destinationAttribute = "destinationAttribute";
         mailet.init(FakeMailetConfig.builder()
             .mailetName("ICalendarParser")
@@ -105,31 +101,30 @@ public class ICalendarParserTest {
     }
 
     @Test
-    public void initShouldThrowOnEmptySourceAttribute() throws Exception {
-        expectedException.expect(MessagingException.class);
-
-        mailet.init(FakeMailetConfig.builder()
-            .mailetName("ICalendarParser")
-            .setProperty(ICalendarParser.SOURCE_ATTRIBUTE_PARAMETER_NAME, "")
-            .build());
+    void initShouldThrowOnEmptySourceAttribute() {
+        assertThatThrownBy(() -> mailet.init(FakeMailetConfig.builder()
+                .mailetName("ICalendarParser")
+                .setProperty(ICalendarParser.SOURCE_ATTRIBUTE_PARAMETER_NAME, "")
+                .build()))
+            .isInstanceOf(MessagingException.class);
     }
 
     @Test
-    public void initShouldThrowOnEmptyDestinationAttribute() throws Exception {
-        expectedException.expect(MessagingException.class);
-
-        mailet.init(FakeMailetConfig.builder()
-            .mailetName("ICalendarParser")
-            .setProperty(ICalendarParser.DESTINATION_ATTRIBUTE_PARAMETER_NAME, "")
-            .build());
+    void initShouldThrowOnEmptyDestinationAttribute() {
+        assertThatThrownBy(() -> mailet.init(FakeMailetConfig.builder()
+                .mailetName("ICalendarParser")
+                .setProperty(ICalendarParser.DESTINATION_ATTRIBUTE_PARAMETER_NAME, "")
+                .build()))
+            .isInstanceOf(MessagingException.class);
     }
 
     @Test
-    public void serviceShouldNotSetCalendarDataIntoMailAttributeWhenNoSourceAttribute() throws Exception {
+    void serviceShouldNotSetCalendarDataIntoMailAttributeWhenNoSourceAttribute() throws Exception {
         FakeMailetConfig mailetConfiguration = FakeMailetConfig.builder()
             .mailetName("ICalendarParser")
             .setProperty(DESTINATION_ATTRIBUTE, DESTINATION_CUSTOM_ATTRIBUTE)
             .build();
+
         mailet.init(mailetConfiguration);
 
         Mail mail = FakeMail.builder()
@@ -142,12 +137,13 @@ public class ICalendarParserTest {
     }
 
     @Test
-    public void serviceShouldSetEmptyCalendarDataIntoMailAttributeWhenEmptyICSAttachments() throws Exception {
+    void serviceShouldSetEmptyCalendarDataIntoMailAttributeWhenEmptyICSAttachments() throws Exception {
         FakeMailetConfig mailetConfiguration = FakeMailetConfig.builder()
             .mailetName("ICalendarParser")
             .setProperty(SOURCE_ATTRIBUTE, SOURCE_CUSTOM_ATTRIBUTE)
             .setProperty(DESTINATION_ATTRIBUTE, DESTINATION_CUSTOM_ATTRIBUTE)
             .build();
+
         mailet.init(mailetConfiguration);
 
         Mail mail = FakeMail.builder()
@@ -163,12 +159,13 @@ public class ICalendarParserTest {
     }
 
     @Test
-    public void serviceShouldNotSetCalendarDataIntoMailAttributeWhenSourceAttributeIsNotAMap() throws Exception {
+    void serviceShouldNotSetCalendarDataIntoMailAttributeWhenSourceAttributeIsNotAMap() throws Exception {
         FakeMailetConfig mailetConfiguration = FakeMailetConfig.builder()
             .mailetName("ICalendarParser")
             .setProperty(SOURCE_ATTRIBUTE, SOURCE_CUSTOM_ATTRIBUTE)
             .setProperty(DESTINATION_ATTRIBUTE, DESTINATION_CUSTOM_ATTRIBUTE)
             .build();
+
         mailet.init(mailetConfiguration);
 
         Mail mail = FakeMail.builder()
@@ -183,12 +180,13 @@ public class ICalendarParserTest {
 
     @Test
     @SuppressWarnings("unchecked")
-    public void serviceShouldReturnRightMapOfCalendarWhenRightAttachments() throws Exception {
+    void serviceShouldReturnRightMapOfCalendarWhenRightAttachments() throws Exception {
         FakeMailetConfig mailetConfiguration = FakeMailetConfig.builder()
             .mailetName("ICalendarParser")
             .setProperty(SOURCE_ATTRIBUTE, SOURCE_CUSTOM_ATTRIBUTE)
             .setProperty(DESTINATION_ATTRIBUTE, DESTINATION_CUSTOM_ATTRIBUTE)
             .build();
+
         mailet.init(mailetConfiguration);
 
         Map<String, byte[]> attachments = ImmutableMap.<String, byte[]>builder()
@@ -211,12 +209,13 @@ public class ICalendarParserTest {
     }
 
     @Test
-    public void serviceShouldFilterResultWhenErrorParsing() throws Exception {
+    void serviceShouldFilterResultWhenErrorParsing() throws Exception {
         FakeMailetConfig mailetConfiguration = FakeMailetConfig.builder()
             .mailetName("ICalendarParser")
             .setProperty(SOURCE_ATTRIBUTE, SOURCE_CUSTOM_ATTRIBUTE)
             .setProperty(DESTINATION_ATTRIBUTE, DESTINATION_CUSTOM_ATTRIBUTE)
             .build();
+
         mailet.init(mailetConfiguration);
 
         Map<String, byte[]> attachments = ImmutableMap.<String, byte[]>builder()
@@ -240,17 +239,18 @@ public class ICalendarParserTest {
     }
 
     @Test
-    public void getMailetInfoShouldReturn() throws MessagingException {
+    void getMailetInfoShouldReturn() throws MessagingException {
         assertThat(mailet.getMailetInfo()).isEqualTo("Calendar Parser");
     }
 
     @Test
-    public void parsingShouldBeLenient() throws Exception {
+    void parsingShouldBeLenient() throws Exception {
         FakeMailetConfig mailetConfiguration = FakeMailetConfig.builder()
             .mailetName("ICalendarParser")
             .setProperty(SOURCE_ATTRIBUTE, SOURCE_CUSTOM_ATTRIBUTE)
             .setProperty(DESTINATION_ATTRIBUTE, DESTINATION_CUSTOM_ATTRIBUTE)
             .build();
+
         mailet.init(mailetConfiguration);
 
         Map<String, byte[]> attachments = ImmutableMap.<String, byte[]>builder()


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


[james-project] 23/25: JAMES-3319 MimeMessageStore should support deletion

Posted by rc...@apache.org.
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 110947ca0e66a2a03eb4d6899f4dcd3569b80bd5
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Jul 24 13:38:02 2020 +0700

    JAMES-3319 MimeMessageStore should support deletion
---
 .../main/java/org/apache/james/blob/api/Store.java |  9 +++++++
 .../james/blob/mail/MimeMessageStoreTest.java      | 30 ++++++++++++++++++++++
 .../cassandra/CassandraMailRepository.java         | 22 ++++++++--------
 .../cassandra/CassandraMailRepositoryTest.java     |  4 +--
 ...aMailRepositoryWithFakeImplementationsTest.java |  2 +-
 5 files changed, 52 insertions(+), 15 deletions(-)

diff --git a/server/blob/blob-common/src/main/java/org/apache/james/blob/api/Store.java b/server/blob/blob-common/src/main/java/org/apache/james/blob/api/Store.java
index 0c51da6..8deba51 100644
--- a/server/blob/blob-common/src/main/java/org/apache/james/blob/api/Store.java
+++ b/server/blob/blob-common/src/main/java/org/apache/james/blob/api/Store.java
@@ -23,6 +23,7 @@ import java.util.Collection;
 import java.util.stream.Stream;
 
 import org.apache.commons.lang3.tuple.Pair;
+import org.reactivestreams.Publisher;
 
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
@@ -35,6 +36,8 @@ public interface Store<T, I> {
 
     Mono<T> read(I blobIds);
 
+    Publisher<Void> delete(I blobIds);
+
     class Impl<T, I extends BlobPartsId> implements Store<T, I> {
 
         public interface ValueToSave {
@@ -101,5 +104,11 @@ public interface Store<T, I> {
                 .map(Collection::stream)
                 .map(decoder::decode);
         }
+
+        @Override
+        public Publisher<Void> delete(I blobIds) {
+            return Flux.fromIterable(blobIds.asMap().values())
+                .flatMap(id -> blobStore.delete(blobStore.getDefaultBucketName(), id));
+        }
     }
 }
diff --git a/server/blob/mail-store/src/test/java/org/apache/james/blob/mail/MimeMessageStoreTest.java b/server/blob/mail-store/src/test/java/org/apache/james/blob/mail/MimeMessageStoreTest.java
index bb24ab5..39e278e 100644
--- a/server/blob/mail-store/src/test/java/org/apache/james/blob/mail/MimeMessageStoreTest.java
+++ b/server/blob/mail-store/src/test/java/org/apache/james/blob/mail/MimeMessageStoreTest.java
@@ -20,6 +20,7 @@
 package org.apache.james.blob.mail;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatCode;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import java.nio.charset.StandardCharsets;
@@ -29,6 +30,7 @@ import javax.mail.internet.MimeMessage;
 import org.apache.james.blob.api.BlobId;
 import org.apache.james.blob.api.BlobStore;
 import org.apache.james.blob.api.HashBlobId;
+import org.apache.james.blob.api.ObjectNotFoundException;
 import org.apache.james.blob.api.Store;
 import org.apache.james.blob.memory.MemoryBlobStoreFactory;
 import org.apache.james.core.builder.MimeMessageBuilder;
@@ -84,6 +86,34 @@ class MimeMessageStoreTest {
     }
 
     @Test
+    void readShouldNotReturnDeletedMessage() throws Exception {
+        MimeMessage message = MimeMessageBuilder.mimeMessageBuilder()
+            .addFrom("any@any.com")
+            .addToRecipient("toddy@any.com")
+            .setSubject("Important Mail")
+            .setText("Important mail content")
+            .build();
+
+        MimeMessagePartsId parts = testee.save(message).block();
+
+        Mono.from(testee.delete(parts)).block();
+
+        assertThatThrownBy(() -> testee.read(parts).block())
+            .isInstanceOf(ObjectNotFoundException.class);
+    }
+
+    @Test
+    void deleteShouldNotThrowWhenCalledOnNonExistingData() throws Exception {
+        MimeMessagePartsId parts = MimeMessagePartsId.builder()
+            .headerBlobId(BLOB_ID_FACTORY.randomId())
+            .bodyBlobId(BLOB_ID_FACTORY.randomId())
+            .build();
+
+        assertThatCode(() -> Mono.from(testee.delete(parts)).block())
+            .doesNotThrowAnyException();
+    }
+
+    @Test
     void mailStoreShouldPreserveMailWithoutBody() throws Exception {
         MimeMessage message = MimeMessageBuilder.mimeMessageBuilder()
             .addFrom("any@any.com")
diff --git a/server/mailrepository/mailrepository-cassandra/src/main/java/org/apache/james/mailrepository/cassandra/CassandraMailRepository.java b/server/mailrepository/mailrepository-cassandra/src/main/java/org/apache/james/mailrepository/cassandra/CassandraMailRepository.java
index a0b1805..4024c7f 100644
--- a/server/mailrepository/mailrepository-cassandra/src/main/java/org/apache/james/mailrepository/cassandra/CassandraMailRepository.java
+++ b/server/mailrepository/mailrepository-cassandra/src/main/java/org/apache/james/mailrepository/cassandra/CassandraMailRepository.java
@@ -29,7 +29,6 @@ import javax.inject.Inject;
 import javax.mail.MessagingException;
 import javax.mail.internet.MimeMessage;
 
-import org.apache.james.blob.api.BlobStore;
 import org.apache.james.blob.api.Store;
 import org.apache.james.blob.mail.MimeMessagePartsId;
 import org.apache.james.blob.mail.MimeMessageStore;
@@ -48,18 +47,16 @@ public class CassandraMailRepository implements MailRepository {
     private final CassandraMailRepositoryCountDAO countDAO;
     private final CassandraMailRepositoryMailDaoAPI mailDAO;
     private final Store<MimeMessage, MimeMessagePartsId> mimeMessageStore;
-    private final BlobStore blobStore;
 
     @Inject
     CassandraMailRepository(MailRepositoryUrl url, CassandraMailRepositoryKeysDAO keysDAO,
                             CassandraMailRepositoryCountDAO countDAO, CassandraMailRepositoryMailDaoAPI mailDAO,
-                            MimeMessageStore.Factory mimeMessageStoreFactory, BlobStore blobStore) {
+                            MimeMessageStore.Factory mimeMessageStoreFactory) {
         this.url = url;
         this.keysDAO = keysDAO;
         this.countDAO = countDAO;
         this.mailDAO = mailDAO;
         this.mimeMessageStore = mimeMessageStoreFactory.mimeMessageStore();
-        this.blobStore = blobStore;
     }
 
     @Override
@@ -100,10 +97,7 @@ public class CassandraMailRepository implements MailRepository {
     }
 
     private Mono<Mail> toMail(MailDTO mailDTO) {
-        MimeMessagePartsId parts = MimeMessagePartsId.builder()
-            .headerBlobId(mailDTO.getHeaderBlobId())
-            .bodyBlobId(mailDTO.getBodyBlobId())
-            .build();
+        MimeMessagePartsId parts = blobIds(mailDTO);
 
         return mimeMessageStore.read(parts)
             .map(mimeMessage -> mailDTO.getMailBuilder()
@@ -111,6 +105,13 @@ public class CassandraMailRepository implements MailRepository {
                 .build());
     }
 
+    private MimeMessagePartsId blobIds(MailDTO mailDTO) {
+        return MimeMessagePartsId.builder()
+                .headerBlobId(mailDTO.getHeaderBlobId())
+                .bodyBlobId(mailDTO.getBodyBlobId())
+                .build();
+    }
+
     @Override
     public void remove(Mail mail) {
         removeAsync(MailKey.forMail(mail)).block();
@@ -141,10 +142,7 @@ public class CassandraMailRepository implements MailRepository {
 
     private Mono<Void> deleteBlobs(Optional<MailDTO> maybeMailDTO) {
         return Mono.justOrEmpty(maybeMailDTO)
-            .flatMap(mailDTO -> Flux.merge(
-                    blobStore.delete(blobStore.getDefaultBucketName(), mailDTO.getHeaderBlobId()),
-                    blobStore.delete(blobStore.getDefaultBucketName(), mailDTO.getBodyBlobId()))
-                .then());
+            .flatMap(mailDTO -> Mono.from(mimeMessageStore.delete(blobIds(mailDTO))));
     }
 
     private Mono<Void> decreaseSizeIfDeleted(Boolean isDeleted) {
diff --git a/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryTest.java b/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryTest.java
index 009b9a7..3545bdb 100644
--- a/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryTest.java
+++ b/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryTest.java
@@ -70,7 +70,7 @@ class CassandraMailRepositoryTest {
                 .passthrough();
 
             cassandraMailRepository = new CassandraMailRepository(URL,
-                keysDAO, countDAO, mailDAO, MimeMessageStore.factory(blobStore), blobStore);
+                keysDAO, countDAO, mailDAO, MimeMessageStore.factory(blobStore));
         }
 
         @Override
@@ -110,7 +110,7 @@ class CassandraMailRepositoryTest {
                 .deduplication();
 
             cassandraMailRepository = new CassandraMailRepository(URL,
-                keysDAO, countDAO, mailDAO, MimeMessageStore.factory(blobStore), blobStore);
+                keysDAO, countDAO, mailDAO, MimeMessageStore.factory(blobStore));
         }
 
         @Override
diff --git a/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryWithFakeImplementationsTest.java b/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryWithFakeImplementationsTest.java
index 8bc6d06..a420ac5 100644
--- a/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryWithFakeImplementationsTest.java
+++ b/server/mailrepository/mailrepository-cassandra/src/test/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryWithFakeImplementationsTest.java
@@ -70,7 +70,7 @@ class CassandraMailRepositoryWithFakeImplementationsTest {
             .passthrough();
 
         cassandraMailRepository = new CassandraMailRepository(URL,
-            keysDAO, countDAO, mailDAO, MimeMessageStore.factory(blobStore), blobStore);
+            keysDAO, countDAO, mailDAO, MimeMessageStore.factory(blobStore));
     }
 
     @Nested


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


[james-project] 24/25: JAMES-3310 Make DeletedMessageVaultHook failure sensitive

Posted by rc...@apache.org.
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 d27ac6a60881633033006026cbd328653260746b
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Thu Jul 16 16:15:49 2020 +0200

    JAMES-3310 Make DeletedMessageVaultHook failure sensitive
---
 .../src/main/java/org/apache/james/vault/DeletedMessageVaultHook.java    | 1 +
 1 file changed, 1 insertion(+)

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 99858f1..72cc971 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
@@ -135,6 +135,7 @@ public class DeletedMessageVaultHook implements PreDeletionHook {
         return mapperFactory.getMessageIdMapper(session)
             .findReactive(ImmutableList.of(deletedMessageMailboxContext.getMessageId()), MessageMapper.FetchType.Full)
             .next()
+            .switchIfEmpty(Mono.error(new RuntimeException("Cannot find " + deletedMessageMailboxContext.getMessageId())))
             .map(Throwing.function(mailboxMessage -> Pair.of(mailboxMessage,
                 deletedMessageConverter.convert(deletedMessageMailboxContext, mailboxMessage,
                     ZonedDateTime.ofInstant(clock.instant(), ZoneOffset.UTC)))))


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


[james-project] 08/25: [Refactoring] Migrate ICALToHeadersTest to Junit 5

Posted by rc...@apache.org.
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 0953a854d5bdc8287d567a948d24865d776ceb57
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Fri Jul 24 17:07:09 2020 +0700

    [Refactoring] Migrate ICALToHeadersTest to Junit 5
---
 .../james/transport/mailets/ICALToHeadersTest.java | 82 +++++++++++-----------
 1 file changed, 42 insertions(+), 40 deletions(-)

diff --git a/mailet/icalendar/src/test/java/org/apache/james/transport/mailets/ICALToHeadersTest.java b/mailet/icalendar/src/test/java/org/apache/james/transport/mailets/ICALToHeadersTest.java
index 79bd7ce..04618de 100644
--- a/mailet/icalendar/src/test/java/org/apache/james/transport/mailets/ICALToHeadersTest.java
+++ b/mailet/icalendar/src/test/java/org/apache/james/transport/mailets/ICALToHeadersTest.java
@@ -20,6 +20,7 @@
 package org.apache.james.transport.mailets;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import javax.mail.MessagingException;
 
@@ -29,35 +30,32 @@ import org.apache.mailet.AttributeValue;
 import org.apache.mailet.Mail;
 import org.apache.mailet.base.test.FakeMail;
 import org.apache.mailet.base.test.FakeMailetConfig;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.assertj.core.api.SoftAssertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
+import com.github.fge.lambdas.Throwing;
 import com.google.common.collect.ImmutableMap;
 
 import net.fortuna.ical4j.data.CalendarBuilder;
 import net.fortuna.ical4j.model.Calendar;
 
-public class ICALToHeadersTest {
+class ICALToHeadersTest {
 
-    @Rule
-    public ExpectedException expectedException = ExpectedException.none();
+    ICALToHeader testee;
 
-    private ICALToHeader testee;
-
-    @Before
-    public void setUp() {
+    @BeforeEach
+    void setUp() {
         testee = new ICALToHeader();
     }
 
     @Test
-    public void getMailetInfoShouldReturnExpectedValue() {
+    void getMailetInfoShouldReturnExpectedValue() {
         assertThat(testee.getMailetInfo()).isEqualTo("ICALToHeader Mailet");
     }
 
     @Test
-    public void initShouldSetAttributeWhenAbsent() throws Exception {
+    void initShouldSetAttributeWhenAbsent() throws Exception {
         testee.init(FakeMailetConfig.builder()
             .mailetName("ICALToHeader")
             .build());
@@ -66,7 +64,7 @@ public class ICALToHeadersTest {
     }
 
     @Test
-    public void initShouldSetAttributeWhenPresent() throws Exception {
+    void initShouldSetAttributeWhenPresent() throws Exception {
         String attribute = "attribute";
         testee.init(FakeMailetConfig.builder()
             .mailetName("ICALToHeader")
@@ -77,17 +75,16 @@ public class ICALToHeadersTest {
     }
 
     @Test
-    public void initShouldThrowOnEmptyAttribute() throws Exception {
-        expectedException.expect(MessagingException.class);
-
-        testee.init(FakeMailetConfig.builder()
-            .mailetName("ICALToHeader")
-            .setProperty(ICALToHeader.ATTRIBUTE_PROPERTY, "")
-            .build());
+    void initShouldThrowOnEmptyAttribute() {
+        assertThatThrownBy(() -> testee.init(FakeMailetConfig.builder()
+                .mailetName("ICALToHeader")
+                .setProperty(ICALToHeader.ATTRIBUTE_PROPERTY, "")
+                .build()))
+            .isInstanceOf(MessagingException.class);
     }
 
     @Test
-    public void serviceShouldNotModifyMailsWithoutIcalAttribute() throws Exception {
+    void serviceShouldNotModifyMailsWithoutIcalAttribute() throws Exception {
         testee.init(FakeMailetConfig.builder().build());
         Mail mail = FakeMail.builder()
             .name("mail")
@@ -100,7 +97,7 @@ public class ICALToHeadersTest {
     }
 
     @Test
-    public void serviceShouldNotFailOnMailsWithWrongAttributeType() throws Exception {
+    void serviceShouldNotFailOnMailsWithWrongAttributeType() throws Exception {
         testee.init(FakeMailetConfig.builder().build());
         Mail mail = FakeMail.builder()
             .name("mail")
@@ -114,7 +111,7 @@ public class ICALToHeadersTest {
     }
 
     @Test
-    public void serviceShouldNotFailOnMailsWithWrongParametrizedAttribute() throws Exception {
+    void serviceShouldNotFailOnMailsWithWrongParametrizedAttribute() throws Exception {
         ImmutableMap<String, String> wrongParametrizedMap = ImmutableMap.<String, String>builder()
             .put("key", "value")
             .build();
@@ -132,7 +129,7 @@ public class ICALToHeadersTest {
     }
 
     @Test
-    public void serviceShouldWriteSingleICalendarToHeaders() throws Exception {
+    void serviceShouldWriteSingleICalendarToHeaders() throws Exception {
         Calendar calendar = new CalendarBuilder().build(ClassLoader.getSystemResourceAsStream("ics/meeting.ics"));
         ImmutableMap<String, Calendar> icals = ImmutableMap.<String, Calendar>builder()
             .put("key", calendar)
@@ -147,16 +144,19 @@ public class ICALToHeadersTest {
 
         testee.service(mail);
 
-        assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_METHOD_HEADER)).containsOnly("REQUEST");
-        assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_UID_HEADER))
-            .containsOnly("f1514f44bf39311568d640727cff54e819573448d09d2e5677987ff29caa01a9e047feb2aab16e43439a608f28671ab7c10e754ce92be513f8e04ae9ff15e65a9819cf285a6962bc");
-        assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_DTSTAMP_HEADER)).containsOnly("20170106T115036Z");
-        assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_RECURRENCE_ID_HEADER)).isNull();
-        assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_SEQUENCE_HEADER)).containsOnly("0");
+        SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
+            softly.assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_METHOD_HEADER)).containsOnly("REQUEST");
+            softly.assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_UID_HEADER))
+                .containsOnly("f1514f44bf39311568d640727cff54e819573448d09d2e5677987ff29caa01a9e047feb2aab16e43439a608f28671ab7c10e754ce92be513f8e04ae9ff15e65a9819cf285a6962bc");
+            softly.assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_DTSTAMP_HEADER)).containsOnly("20170106T115036Z");
+            softly.assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_RECURRENCE_ID_HEADER)).isNull();
+            softly.assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_SEQUENCE_HEADER)).containsOnly("0");
+        }));
+
     }
 
     @Test
-    public void serviceShouldNotWriteHeaderWhenPropertyIsAbsent() throws Exception {
+    void serviceShouldNotWriteHeaderWhenPropertyIsAbsent() throws Exception {
         Calendar calendar = new CalendarBuilder().build(ClassLoader.getSystemResourceAsStream("ics/meeting_without_dtstamp.ics"));
         ImmutableMap<String, Calendar> icals = ImmutableMap.<String, Calendar>builder()
             .put("key", calendar)
@@ -171,16 +171,18 @@ public class ICALToHeadersTest {
 
         testee.service(mail);
 
-        assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_METHOD_HEADER)).containsOnly("REQUEST");
-        assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_UID_HEADER))
-            .containsOnly("f1514f44bf39311568d640727cff54e819573448d09d2e5677987ff29caa01a9e047feb2aab16e43439a608f28671ab7c10e754ce92be513f8e04ae9ff15e65a9819cf285a6962bc");
-        assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_DTSTAMP_HEADER)).isNull();
-        assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_RECURRENCE_ID_HEADER)).isNull();
-        assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_SEQUENCE_HEADER)).containsOnly("0");
+        SoftAssertions.assertSoftly(Throwing.consumer(softly -> {
+            softly.assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_METHOD_HEADER)).containsOnly("REQUEST");
+            softly.assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_UID_HEADER))
+                .containsOnly("f1514f44bf39311568d640727cff54e819573448d09d2e5677987ff29caa01a9e047feb2aab16e43439a608f28671ab7c10e754ce92be513f8e04ae9ff15e65a9819cf285a6962bc");
+            softly.assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_DTSTAMP_HEADER)).isNull();
+            softly.assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_RECURRENCE_ID_HEADER)).isNull();
+            softly.assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_SEQUENCE_HEADER)).containsOnly("0");
+        }));
     }
 
     @Test
-    public void serviceShouldWriteOnlyOneICalendarToHeaders() throws Exception {
+    void serviceShouldWriteOnlyOneICalendarToHeaders() throws Exception {
         Calendar calendar = new CalendarBuilder().build(ClassLoader.getSystemResourceAsStream("ics/meeting.ics"));
         Calendar calendar2 = new CalendarBuilder().build(ClassLoader.getSystemResourceAsStream("ics/meeting_2.ics"));
         ImmutableMap<String, Calendar> icals = ImmutableMap.<String, Calendar>builder()
@@ -201,7 +203,7 @@ public class ICALToHeadersTest {
     }
 
     @Test
-    public void serviceShouldNotFailOnEmptyMaps() throws Exception {
+    void serviceShouldNotFailOnEmptyMaps() throws Exception {
         ImmutableMap<String, Calendar> icals = ImmutableMap.<String, Calendar>builder()
             .build();
 


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