james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From matth...@apache.org
Subject [09/18] james-project git commit: MAILBOX-304 Piloting blobDAO should be a responsibility of AttachmentMapper
Date Mon, 11 Sep 2017 08:56:32 GMT
MAILBOX-304 Piloting blobDAO should be a responsibility of AttachmentMapper


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/588e164a
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/588e164a
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/588e164a

Branch: refs/heads/master
Commit: 588e164a1b1730fc7eab76fbefc621e2fcf9fb64
Parents: 43e21af
Author: benwa <btellier@linagora.com>
Authored: Thu Sep 7 11:02:49 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Thu Sep 7 11:02:49 2017 +0700

----------------------------------------------------------------------
 .../CassandraMailboxSessionMapperFactory.java   |  11 +-
 .../mail/CassandraAttachmentDAOV2.java          | 117 +++++++++++++------
 .../mail/CassandraAttachmentMapper.java         |  40 +++++--
 .../CassandraSubscriptionManagerTest.java       |   3 +
 ...estCassandraMailboxSessionMapperFactory.java |   4 +-
 .../mail/CassandraAttachmentDAOV2Test.java      |  22 ++--
 .../CassandraAttachmentFallbackTestTest.java    |  16 ++-
 7 files changed, 150 insertions(+), 63 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/588e164a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxSessionMapperFactory.java
----------------------------------------------------------------------
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 aa7d765..1c1539d 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
@@ -29,6 +29,7 @@ import org.apache.james.mailbox.cassandra.mail.CassandraApplicableFlagDAO;
 import org.apache.james.mailbox.cassandra.mail.CassandraAttachmentDAO;
 import org.apache.james.mailbox.cassandra.mail.CassandraAttachmentDAOV2;
 import org.apache.james.mailbox.cassandra.mail.CassandraAttachmentMapper;
+import org.apache.james.mailbox.cassandra.mail.CassandraBlobsDAO;
 import org.apache.james.mailbox.cassandra.mail.CassandraDeletedMessageDAO;
 import org.apache.james.mailbox.cassandra.mail.CassandraFirstUnseenDAO;
 import org.apache.james.mailbox.cassandra.mail.CassandraIndexTableHandler;
@@ -76,9 +77,10 @@ public class CassandraMailboxSessionMapperFactory extends MailboxSessionMapperFa
     private final CassandraApplicableFlagDAO applicableFlagDAO;
     private final CassandraAttachmentDAO attachmentDAO;
     private final CassandraAttachmentDAOV2 attachmentDAOV2;
+    private final CassandraDeletedMessageDAO deletedMessageDAO;
+    private final CassandraBlobsDAO blobsDAO;
     private CassandraUtils cassandraUtils;
     private CassandraConfiguration cassandraConfiguration;
-    private final CassandraDeletedMessageDAO deletedMessageDAO;
 
     @Inject
     public CassandraMailboxSessionMapperFactory(CassandraUidProvider uidProvider, CassandraModSeqProvider
modSeqProvider, Session session,
@@ -86,8 +88,8 @@ public class CassandraMailboxSessionMapperFactory extends MailboxSessionMapperFa
                                                 CassandraMessageIdDAO messageIdDAO, CassandraMessageIdToImapUidDAO
imapUidDAO,
                                                 CassandraMailboxCounterDAO mailboxCounterDAO,
CassandraMailboxRecentsDAO mailboxRecentsDAO, CassandraMailboxDAO mailboxDAO,
                                                 CassandraMailboxPathDAO mailboxPathDAO, CassandraFirstUnseenDAO
firstUnseenDAO, CassandraApplicableFlagDAO applicableFlagDAO,
-                                                CassandraAttachmentDAO attachmentDAO, CassandraAttachmentDAOV2
attachmentDAOV2, CassandraDeletedMessageDAO deletedMessageDAO, CassandraUtils cassandraUtils,
-                                                CassandraConfiguration cassandraConfiguration)
{
+                                                CassandraAttachmentDAO attachmentDAO, CassandraAttachmentDAOV2
attachmentDAOV2, CassandraDeletedMessageDAO deletedMessageDAO,
+                                                CassandraBlobsDAO blobsDAO, CassandraUtils
cassandraUtils, CassandraConfiguration cassandraConfiguration) {
         this.uidProvider = uidProvider;
         this.modSeqProvider = modSeqProvider;
         this.session = session;
@@ -103,6 +105,7 @@ public class CassandraMailboxSessionMapperFactory extends MailboxSessionMapperFa
         this.attachmentDAOV2 = attachmentDAOV2;
         this.deletedMessageDAO = deletedMessageDAO;
         this.applicableFlagDAO = applicableFlagDAO;
+        this.blobsDAO = blobsDAO;
         this.cassandraUtils = cassandraUtils;
         this.cassandraConfiguration = cassandraConfiguration;
         this.indexTableHandler = new CassandraIndexTableHandler(
@@ -147,7 +150,7 @@ public class CassandraMailboxSessionMapperFactory extends MailboxSessionMapperFa
 
     @Override
     public AttachmentMapper createAttachmentMapper(MailboxSession mailboxSession) {
-        return new CassandraAttachmentMapper(attachmentDAO, attachmentDAOV2);
+        return new CassandraAttachmentMapper(attachmentDAO, attachmentDAOV2, blobsDAO);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/588e164a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentDAOV2.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentDAOV2.java
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentDAOV2.java
index 4a6037e..98cd0e5 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentDAOV2.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentDAOV2.java
@@ -31,6 +31,7 @@ import static org.apache.james.mailbox.cassandra.table.CassandraAttachmentV2Tabl
 import static org.apache.james.mailbox.cassandra.table.CassandraAttachmentV2Table.TABLE_NAME;
 import static org.apache.james.mailbox.cassandra.table.CassandraAttachmentV2Table.TYPE;
 
+import java.util.Objects;
 import java.util.Optional;
 import java.util.concurrent.CompletableFuture;
 
@@ -47,15 +48,85 @@ import com.datastax.driver.core.Session;
 import com.google.common.base.Preconditions;
 
 public class CassandraAttachmentDAOV2 {
+    public static class DAOAttachmentModel {
+        private final AttachmentId attachmentId;
+        private final BlobId blobId;
+        private final String type;
+        private final long size;
+
+        private DAOAttachmentModel(AttachmentId attachmentId, BlobId blobId, String type,
long size) {
+            this.attachmentId = attachmentId;
+            this.blobId = blobId;
+            this.type = type;
+            this.size = size;
+        }
+
+        public AttachmentId getAttachmentId() {
+            return attachmentId;
+        }
+
+        public org.apache.james.mailbox.cassandra.ids.BlobId getBlobId() {
+            return blobId;
+        }
+
+        public String getType() {
+            return type;
+        }
+
+        public long getSize() {
+            return size;
+        }
+
+        public Attachment toAttachment(byte[] data) {
+            return Attachment.builder()
+                .attachmentId(attachmentId)
+                .type(type)
+                .bytes(data)
+                .build();
+        }
+
+        @Override
+        public final boolean equals(Object o) {
+            if (o instanceof DAOAttachmentModel) {
+                DAOAttachmentModel that = (DAOAttachmentModel) o;
+
+                return Objects.equals(this.size, that.size)
+                    && Objects.equals(this.attachmentId, that.attachmentId)
+                    && Objects.equals(this.blobId, that.blobId)
+                    && Objects.equals(this.type, that.type);
+            }
+            return false;
+        }
+
+        @Override
+        public final int hashCode() {
+            return Objects.hash(attachmentId, blobId, type, size);
+        }
+    }
+
+    public static DAOAttachmentModel from(Attachment attachment, BlobId blobId) {
+        return new DAOAttachmentModel(
+            attachment.getAttachmentId(),
+            blobId,
+            attachment.getType(),
+            attachment.getSize());
+    }
+
+    private static DAOAttachmentModel fromRow(Row row) {
+        return new DAOAttachmentModel(
+            AttachmentId.from(row.getString(ID)),
+            BlobId.from(row.getString(BLOB_ID)),
+            row.getString(TYPE),
+            row.getLong(SIZE));
+    }
+
     private final CassandraAsyncExecutor cassandraAsyncExecutor;
     private final PreparedStatement insertStatement;
-    private final CassandraBlobsDAO blobsDAO;
     private final PreparedStatement selectStatement;
 
     @Inject
-    public CassandraAttachmentDAOV2(Session session, CassandraBlobsDAO blobsDAO) {
+    public CassandraAttachmentDAOV2(Session session) {
         this.cassandraAsyncExecutor = new CassandraAsyncExecutor(session);
-        this.blobsDAO = blobsDAO;
 
         this.selectStatement = prepareSelect(session);
         this.insertStatement = prepareInsert(session);
@@ -77,42 +148,22 @@ public class CassandraAttachmentDAOV2 {
             .where(eq(ID_AS_UUID, bindMarker(ID_AS_UUID))));
     }
 
-    public CompletableFuture<Optional<Attachment>> getAttachment(AttachmentId
attachmentId) {
+    public CompletableFuture<Optional<DAOAttachmentModel>> getAttachment(AttachmentId
attachmentId) {
         Preconditions.checkArgument(attachmentId != null);
         return cassandraAsyncExecutor.executeSingleRow(
             selectStatement.bind()
                 .setUUID(ID_AS_UUID, attachmentId.asUUID()))
-            .thenCompose(this::attachment);
-    }
-
-    public CompletableFuture<Void> storeAttachment(Attachment attachment) {
-        return blobsDAO.save(attachment.getBytes())
-            // BlobDAO supports saving null blobs. But attachments ensure there blobs are
never null. Hence optional unboxing is safe here.
-            .thenApply(Optional::get)
-            .thenApply(blobId ->
-                insertStatement.bind()
-                    .setUUID(ID_AS_UUID, attachment.getAttachmentId().asUUID())
-                    .setString(ID, attachment.getAttachmentId().getId())
-                    .setLong(SIZE, attachment.getSize())
-                    .setString(TYPE, attachment.getType())
-                    .setString(BLOB_ID, blobId.getId()))
-            .thenCompose(cassandraAsyncExecutor::executeVoid);
+            .thenApply(row -> row.map(CassandraAttachmentDAOV2::fromRow));
     }
 
-    private CompletableFuture<Optional<Attachment>> attachment(Optional<Row>
rowOptional) {
-        if (rowOptional.isPresent()) {
-            return attachment(rowOptional.get())
-                .thenApply(Optional::of);
-        }
-        return CompletableFuture.completedFuture(Optional.empty());
+    public CompletableFuture<Void> storeAttachment(DAOAttachmentModel attachment) {
+        return cassandraAsyncExecutor.executeVoid(
+            insertStatement.bind()
+                .setUUID(ID_AS_UUID, attachment.getAttachmentId().asUUID())
+                .setString(ID, attachment.getAttachmentId().getId())
+                .setLong(SIZE, attachment.getSize())
+                .setString(TYPE, attachment.getType())
+                .setString(BLOB_ID, attachment.getBlobId().getId()));
     }
 
-    private CompletableFuture<Attachment> attachment(Row row) {
-        return blobsDAO.read(BlobId.from(row.getString(BLOB_ID)))
-            .thenApply(bytes -> Attachment.builder()
-                .attachmentId(AttachmentId.from(row.getString(ID)))
-                .bytes(bytes)
-                .type(row.getString(TYPE))
-                .build());
-    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/588e164a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java
index 8c2b970..3d5e256 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java
@@ -28,12 +28,14 @@ import java.util.stream.Stream;
 
 import javax.inject.Inject;
 
+import org.apache.james.mailbox.cassandra.mail.CassandraAttachmentDAOV2.DAOAttachmentModel;
 import org.apache.james.mailbox.exception.AttachmentNotFoundException;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.Attachment;
 import org.apache.james.mailbox.model.AttachmentId;
 import org.apache.james.mailbox.store.mail.AttachmentMapper;
 import org.apache.james.util.FluentFutureStream;
+import org.jetbrains.annotations.Nullable;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -46,11 +48,13 @@ public class CassandraAttachmentMapper implements AttachmentMapper {
 
     private final CassandraAttachmentDAO attachmentDAO;
     private final CassandraAttachmentDAOV2 attachmentDAOV2;
+    private final CassandraBlobsDAO blobsDAO;
 
     @Inject
-    public CassandraAttachmentMapper(CassandraAttachmentDAO attachmentDAO, CassandraAttachmentDAOV2
attachmentDAOV2) {
+    public CassandraAttachmentMapper(CassandraAttachmentDAO attachmentDAO, CassandraAttachmentDAOV2
attachmentDAOV2, CassandraBlobsDAO blobsDAO) {
         this.attachmentDAO = attachmentDAO;
         this.attachmentDAOV2 = attachmentDAOV2;
+        this.blobsDAO = blobsDAO;
     }
 
     @Override
@@ -65,12 +69,21 @@ public class CassandraAttachmentMapper implements AttachmentMapper {
     @Override
     public Attachment getAttachment(AttachmentId attachmentId) throws AttachmentNotFoundException
{
         Preconditions.checkArgument(attachmentId != null);
-        return attachmentDAOV2.getAttachment(attachmentId)
-            .thenCompose(v2Value -> fallbackToV1(attachmentId, v2Value))
+        return getAttachmentInternal(attachmentId)
             .join()
             .orElseThrow(() -> new AttachmentNotFoundException(attachmentId.getId()));
     }
 
+    @Nullable
+    private CompletionStage<Optional<Attachment>> retrievePayload(Optional<DAOAttachmentModel>
input) {
+        if (!input.isPresent()) {
+            return CompletableFuture.completedFuture(Optional.empty());
+        }
+        DAOAttachmentModel model = input.get();
+        return blobsDAO.read(model.getBlobId())
+            .thenApply(bytes -> Optional.of(model.toAttachment(bytes)));
+    }
+
     @Override
     public List<Attachment> getAttachments(Collection<AttachmentId> attachmentIds)
{
         return getAttachmentsAsFuture(attachmentIds).join();
@@ -82,8 +95,7 @@ public class CassandraAttachmentMapper implements AttachmentMapper {
         Stream<CompletableFuture<Optional<Attachment>>> attachments = attachmentIds
                 .stream()
                 .distinct()
-                .map(id -> attachmentDAOV2.getAttachment(id)
-                    .thenCompose(v2Value -> fallbackToV1(id, v2Value))
+                .map(id -> getAttachmentInternal(id)
                     .thenApply(finalValue -> logNotFound(id, finalValue)));
 
         return FluentFutureStream
@@ -91,6 +103,12 @@ public class CassandraAttachmentMapper implements AttachmentMapper {
             .collect(Guavate.toImmutableList());
     }
 
+    private CompletableFuture<Optional<Attachment>> getAttachmentInternal(AttachmentId
id) {
+        return attachmentDAOV2.getAttachment(id)
+            .thenCompose(this::retrievePayload)
+            .thenCompose(v2Value -> fallbackToV1(id, v2Value));
+    }
+
     private CompletionStage<Optional<Attachment>> fallbackToV1(AttachmentId attachmentId,
Optional<Attachment> v2Value) {
         if (v2Value.isPresent()) {
             return CompletableFuture.completedFuture(v2Value);
@@ -100,17 +118,25 @@ public class CassandraAttachmentMapper implements AttachmentMapper {
 
     @Override
     public void storeAttachment(Attachment attachment) throws MailboxException {
-        attachmentDAOV2.storeAttachment(attachment).join();
+        storeAttachmentAsync(attachment).join();
     }
 
     @Override
     public void storeAttachments(Collection<Attachment> attachments) throws MailboxException
{
         FluentFutureStream.of(
             attachments.stream()
-                .map(attachmentDAOV2::storeAttachment))
+                .map(this::storeAttachmentAsync))
             .join();
     }
 
+    public CompletableFuture<Void> storeAttachmentAsync(Attachment attachment) {
+        return blobsDAO.save(attachment.getBytes())
+            // BlobDAO supports saving null blobs. But attachments ensure there blobs are
never null. Hence optional unboxing is safe here.
+            .thenApply(Optional::get)
+            .thenApply(blobId -> CassandraAttachmentDAOV2.from(attachment, blobId))
+            .thenCompose(attachmentDAOV2::storeAttachment);
+    }
+
     private Optional<Attachment> logNotFound(AttachmentId attachmentId, Optional<Attachment>
optional) {
         if (!optional.isPresent()) {
             LOGGER.warn("Failed retrieving attachment {}", attachmentId);

http://git-wip-us.apache.org/repos/asf/james-project/blob/588e164a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraSubscriptionManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraSubscriptionManagerTest.java
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraSubscriptionManagerTest.java
index c9c02ef..7e94b3c 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraSubscriptionManagerTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraSubscriptionManagerTest.java
@@ -29,6 +29,7 @@ import org.apache.james.mailbox.SubscriptionManager;
 import org.apache.james.mailbox.cassandra.mail.CassandraApplicableFlagDAO;
 import org.apache.james.mailbox.cassandra.mail.CassandraAttachmentDAO;
 import org.apache.james.mailbox.cassandra.mail.CassandraAttachmentDAOV2;
+import org.apache.james.mailbox.cassandra.mail.CassandraBlobsDAO;
 import org.apache.james.mailbox.cassandra.mail.CassandraDeletedMessageDAO;
 import org.apache.james.mailbox.cassandra.mail.CassandraFirstUnseenDAO;
 import org.apache.james.mailbox.cassandra.mail.CassandraMailboxCounterDAO;
@@ -89,6 +90,7 @@ public class CassandraSubscriptionManagerTest extends AbstractSubscriptionManage
         CassandraAttachmentDAO attachmentDAO = null;
         CassandraDeletedMessageDAO deletedMessageDAO = null;
         CassandraAttachmentDAOV2 attachmentDAOV2 = null;
+        CassandraBlobsDAO cassandraBlobsDAO = null;
         return new CassandraSubscriptionManager(
             new CassandraMailboxSessionMapperFactory(
                 new CassandraUidProvider(cassandra.getConf()),
@@ -106,6 +108,7 @@ public class CassandraSubscriptionManagerTest extends AbstractSubscriptionManage
                 attachmentDAO,
                 attachmentDAOV2,
                 deletedMessageDAO,
+                cassandraBlobsDAO,
                 CassandraUtils.WITH_DEFAULT_CONFIGURATION,
                 CassandraConfiguration.DEFAULT_CONFIGURATION));
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/588e164a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/TestCassandraMailboxSessionMapperFactory.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/TestCassandraMailboxSessionMapperFactory.java
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/TestCassandraMailboxSessionMapperFactory.java
index a22d06e..78667ce 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/TestCassandraMailboxSessionMapperFactory.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/TestCassandraMailboxSessionMapperFactory.java
@@ -59,9 +59,9 @@ public class TestCassandraMailboxSessionMapperFactory {
             new CassandraFirstUnseenDAO(session),
             new CassandraApplicableFlagDAO(session),
             new CassandraAttachmentDAO(session),
-            new CassandraAttachmentDAOV2(session, cassandraBlobsDAO),
+            new CassandraAttachmentDAOV2(session),
             new CassandraDeletedMessageDAO(session),
-            CassandraUtils.WITH_DEFAULT_CONFIGURATION,
+            cassandraBlobsDAO, CassandraUtils.WITH_DEFAULT_CONFIGURATION,
             CassandraConfiguration.DEFAULT_CONFIGURATION);
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/588e164a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentDAOV2Test.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentDAOV2Test.java
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentDAOV2Test.java
index 130ef19..82b66e0 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentDAOV2Test.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentDAOV2Test.java
@@ -26,9 +26,9 @@ import java.util.Optional;
 
 import org.apache.james.backends.cassandra.CassandraCluster;
 import org.apache.james.backends.cassandra.DockerCassandraRule;
-import org.apache.james.backends.cassandra.init.CassandraModuleComposite;
+import org.apache.james.mailbox.cassandra.ids.BlobId;
+import org.apache.james.mailbox.cassandra.mail.CassandraAttachmentDAOV2.DAOAttachmentModel;
 import org.apache.james.mailbox.cassandra.modules.CassandraAttachmentModule;
-import org.apache.james.mailbox.cassandra.modules.CassandraBlobModule;
 import org.apache.james.mailbox.model.Attachment;
 import org.apache.james.mailbox.model.AttachmentId;
 import org.junit.After;
@@ -48,16 +48,12 @@ public class CassandraAttachmentDAOV2Test {
 
     @Before
     public void setUp() throws Exception {
-        CassandraModuleComposite compositeModule = new CassandraModuleComposite(
-            new CassandraAttachmentModule(),
-            new CassandraBlobModule());
-
         cassandra = CassandraCluster.create(
-            compositeModule,
+            new CassandraAttachmentModule(),
             cassandraServer.getIp(),
             cassandraServer.getBindingPort());
 
-        testee = new CassandraAttachmentDAOV2(cassandra.getConf(), new CassandraBlobsDAO(cassandra.getConf()));
+        testee = new CassandraAttachmentDAOV2(cassandra.getConf());
     }
 
     @After
@@ -67,7 +63,7 @@ public class CassandraAttachmentDAOV2Test {
 
     @Test
     public void getAttachmentShouldReturnEmptyWhenAbsent() {
-        Optional<Attachment> attachment = testee.getAttachment(ATTACHMENT_ID).join();
+        Optional<DAOAttachmentModel> attachment = testee.getAttachment(ATTACHMENT_ID).join();
 
         assertThat(attachment).isEmpty();
     }
@@ -79,10 +75,12 @@ public class CassandraAttachmentDAOV2Test {
             .type("application/json")
             .bytes("{\"property\":`\"value\"}".getBytes(StandardCharsets.UTF_8))
             .build();
-        testee.storeAttachment(attachment).join();
+        BlobId blobId = BlobId.from("blobId");
+        DAOAttachmentModel model = CassandraAttachmentDAOV2.from(attachment, blobId);
+        testee.storeAttachment(model).join();
 
-        Optional<Attachment> actual = testee.getAttachment(ATTACHMENT_ID).join();
+        Optional<DAOAttachmentModel> actual = testee.getAttachment(ATTACHMENT_ID).join();
 
-        assertThat(actual).contains(attachment);
+        assertThat(actual).contains(model);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/588e164a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentFallbackTestTest.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentFallbackTestTest.java
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentFallbackTestTest.java
index 45f03e2..5626d6a 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentFallbackTestTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentFallbackTestTest.java
@@ -27,6 +27,7 @@ import java.nio.charset.StandardCharsets;
 import org.apache.james.backends.cassandra.CassandraCluster;
 import org.apache.james.backends.cassandra.DockerCassandraRule;
 import org.apache.james.backends.cassandra.init.CassandraModuleComposite;
+import org.apache.james.mailbox.cassandra.ids.BlobId;
 import org.apache.james.mailbox.cassandra.modules.CassandraAttachmentModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraBlobModule;
 import org.apache.james.mailbox.exception.AttachmentNotFoundException;
@@ -50,6 +51,7 @@ public class CassandraAttachmentFallbackTestTest {
     private CassandraAttachmentDAOV2 attachmentDAOV2;
     private CassandraAttachmentDAO attachmentDAO;
     private CassandraAttachmentMapper attachmentMapper;
+    private CassandraBlobsDAO blobsDAO;
 
     @Before
     public void setUp() throws Exception {
@@ -62,9 +64,10 @@ public class CassandraAttachmentFallbackTestTest {
             cassandraServer.getIp(),
             cassandraServer.getBindingPort());
 
-        attachmentDAOV2 = new CassandraAttachmentDAOV2(cassandra.getConf(), new CassandraBlobsDAO(cassandra.getConf()));
+        attachmentDAOV2 = new CassandraAttachmentDAOV2(cassandra.getConf());
         attachmentDAO = new CassandraAttachmentDAO(cassandra.getConf());
-        attachmentMapper = new CassandraAttachmentMapper(attachmentDAO, attachmentDAOV2);
+        blobsDAO = new CassandraBlobsDAO(cassandra.getConf());
+        attachmentMapper = new CassandraAttachmentMapper(attachmentDAO, attachmentDAOV2,
blobsDAO);
     }
 
     @After
@@ -97,7 +100,8 @@ public class CassandraAttachmentFallbackTestTest {
             .bytes("{\"property\":`\"different\"}".getBytes(StandardCharsets.UTF_8))
             .build();
 
-        attachmentDAOV2.storeAttachment(attachment).join();
+        BlobId blobId = blobsDAO.save(attachment.getBytes()).join().get();
+        attachmentDAOV2.storeAttachment(CassandraAttachmentDAOV2.from(attachment, blobId)).join();
         attachmentDAO.storeAttachment(otherAttachment).join();
 
         assertThat(attachmentMapper.getAttachment(ATTACHMENT_ID_1))
@@ -131,7 +135,8 @@ public class CassandraAttachmentFallbackTestTest {
             .bytes("{\"property\":`\"different\"}".getBytes(StandardCharsets.UTF_8))
             .build();
 
-        attachmentDAOV2.storeAttachment(attachment).join();
+        BlobId blobId = blobsDAO.save(attachment.getBytes()).join().get();
+        attachmentDAOV2.storeAttachment(CassandraAttachmentDAOV2.from(attachment, blobId)).join();
         attachmentDAO.storeAttachment(otherAttachment).join();
 
         assertThat(attachmentMapper.getAttachments(ImmutableList.of(ATTACHMENT_ID_1)))
@@ -165,7 +170,8 @@ public class CassandraAttachmentFallbackTestTest {
             .bytes("{\"property\":`\"different\"}".getBytes(StandardCharsets.UTF_8))
             .build();
 
-        attachmentDAOV2.storeAttachment(attachment).join();
+        BlobId blobId = blobsDAO.save(attachment.getBytes()).join().get();
+        attachmentDAOV2.storeAttachment(CassandraAttachmentDAOV2.from(attachment, blobId)).join();
         attachmentDAO.storeAttachment(otherAttachment).join();
 
         assertThat(attachmentMapper.getAttachments(ImmutableList.of(ATTACHMENT_ID_1, ATTACHMENT_ID_2)))


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


Mime
View raw message