Repository: james-project
Updated Branches:
  refs/heads/master 0a11a4410 -> 20e6f63b9


JAMES-1898 Correct Cassandra implementation


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

Branch: refs/heads/master
Commit: 4ed7c609a2c07a3cd0e83230cf30f4e8c19509bd
Parents: 4ecc8ba
Author: Benoit Tellier <btell...@linagora.com>
Authored: Mon Dec 26 16:15:10 2016 +0700
Committer: Benoit Tellier <btell...@linagora.com>
Committed: Mon Dec 26 16:21:46 2016 +0700

----------------------------------------------------------------------
 .../cassandra/mail/AttachmentLoader.java        |  5 +--
 .../mail/CassandraMessageIdMapper.java          |  8 +++--
 .../cassandra/mail/CassandraMessageMapper.java  |  9 ++++--
 .../cassandra/mail/AttachmentLoaderTest.java    | 32 +++++++++++++++++---
 4 files changed, 44 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/4ed7c609/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/AttachmentLoader.java
----------------------------------------------------------------------
diff --git 
a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/AttachmentLoader.java
 
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/AttachmentLoader.java
index 1152627..c07c033 100644
--- 
a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/AttachmentLoader.java
+++ 
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/AttachmentLoader.java
@@ -19,6 +19,7 @@
 package org.apache.james.mailbox.cassandra.mail;
 
 import java.util.Collection;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.function.Function;
@@ -40,14 +41,14 @@ public class AttachmentLoader {
         this.attachmentMapper = attachmentMapper;
     }
 
-    public Collection<MessageAttachment> 
getAttachments(Set<CassandraMessageDAO.MessageAttachmentRepresentation> 
attachmentRepresentations) {
+    public Collection<MessageAttachment> 
getAttachments(List<CassandraMessageDAO.MessageAttachmentRepresentation> 
attachmentRepresentations) {
         Map<AttachmentId, Attachment> attachmentsById = 
attachmentsById(attachmentRepresentations.stream()
             
.map(CassandraMessageDAO.MessageAttachmentRepresentation::getAttachmentId)
             .collect(Guavate.toImmutableSet()));
 
         return attachmentRepresentations.stream()
             .map(representation -> 
constructMessageAttachment(attachmentsById.get(representation.getAttachmentId()),
 representation))
-            .collect(Guavate.toImmutableSet());
+            .collect(Guavate.toImmutableList());
     }
 
     private MessageAttachment constructMessageAttachment(Attachment 
attachment, CassandraMessageDAO.MessageAttachmentRepresentation 
messageAttachmentRepresentation) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/4ed7c609/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageIdMapper.java
----------------------------------------------------------------------
diff --git 
a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageIdMapper.java
 
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageIdMapper.java
index a87edd4..2a756cf 100644
--- 
a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageIdMapper.java
+++ 
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageIdMapper.java
@@ -115,11 +115,15 @@ public class CassandraMessageIdMapper implements 
MessageIdMapper {
 
     private Function<Pair<CassandraMessageDAO.MessageWithoutAttachment, 
Stream<CassandraMessageDAO.MessageAttachmentRepresentation>>, 
Pair<CassandraMessageDAO.MessageWithoutAttachment, Stream<MessageAttachment>>> 
loadAttachments() {
         return pair -> Pair.of(pair.getLeft(),
-            new 
AttachmentLoader(attachmentMapper).getAttachments(pair.getRight().collect(Guavate.toImmutableSet())).stream());
+            new AttachmentLoader(attachmentMapper)
+                
.getAttachments(pair.getRight().collect(Guavate.toImmutableList()))
+                .stream());
     }
 
     private FunctionChainer<Pair<CassandraMessageDAO.MessageWithoutAttachment, 
Stream<MessageAttachment>>, SimpleMailboxMessage> toMailboxMessages() {
-        return Throwing.function(pair -> 
pair.getLeft().toMailboxMessage(pair.getRight().collect(Guavate.toImmutableList())));
+        return Throwing.function(pair -> pair.getLeft()
+            .toMailboxMessage(pair.getRight()
+                .collect(Guavate.toImmutableList())));
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/4ed7c609/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
----------------------------------------------------------------------
diff --git 
a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
 
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
index 5817bcc..69ae3ad 100644
--- 
a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
+++ 
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
@@ -151,8 +151,13 @@ public class CassandraMessageMapper implements 
MessageMapper {
 
     private Stream<SimpleMailboxMessage> 
retrieveMessages(List<ComposedMessageIdWithMetaData> messageIds, FetchType 
fetchType, Optional<Integer> limit) {
         return messageDAO.retrieveMessages(messageIds, fetchType, limit).join()
-                .map(pair -> Pair.of(pair.getLeft(), new 
AttachmentLoader(attachmentMapper).getAttachments(pair.getRight().collect(Guavate.toImmutableSet()))))
-                .map(Throwing.function(pair -> 
pair.getLeft().toMailboxMessage(pair.getRight().stream().collect(Guavate.toImmutableList()))));
+            .map(pair -> Pair.of(pair.getLeft(), new 
AttachmentLoader(attachmentMapper)
+                .getAttachments(pair.getRight()
+                    .collect(Guavate.toImmutableList()))))
+            .map(Throwing.function(pair -> pair.getLeft()
+                .toMailboxMessage(pair.getRight()
+                    .stream()
+                    .collect(Guavate.toImmutableList()))));
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/4ed7c609/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/AttachmentLoaderTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/AttachmentLoaderTest.java
 
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/AttachmentLoaderTest.java
index 72e0607..999a26f 100644
--- 
a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/AttachmentLoaderTest.java
+++ 
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/AttachmentLoaderTest.java
@@ -39,7 +39,6 @@ import org.junit.Test;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Sets;
 
 public class AttachmentLoaderTest {
 
@@ -53,6 +52,31 @@ public class AttachmentLoaderTest {
     }
 
     @Test
+    public void getAttachmentsShouldWorkWithDuplicatedAttachments() {
+        AttachmentId attachmentId = AttachmentId.from("1");
+        Set<AttachmentId> attachmentIds = ImmutableSet.of(attachmentId);
+
+        Attachment attachment = Attachment.builder()
+            .attachmentId(attachmentId)
+            .bytes("attachment".getBytes())
+            .type("type")
+            .build();
+        when(attachmentMapper.getAttachments(attachmentIds))
+            .thenReturn(ImmutableList.of(attachment));
+
+        Optional<String> name = Optional.of("name1");
+        Optional<Cid> cid = Optional.empty();
+        boolean isInlined = false;
+        CassandraMessageDAO.MessageAttachmentRepresentation 
attachmentRepresentation = new 
CassandraMessageDAO.MessageAttachmentRepresentation(attachmentId, name, cid, 
isInlined);
+
+        Collection<MessageAttachment> attachments = 
testee.getAttachments(ImmutableList.of(attachmentRepresentation, 
attachmentRepresentation));
+
+        MessageAttachment expectedAttachment = new 
MessageAttachment(attachment, OptionalConverter.toGuava(name), 
OptionalConverter.toGuava(cid), isInlined);
+        assertThat(attachments).hasSize(2)
+            .containsOnly(expectedAttachment, expectedAttachment);
+    }
+
+    @Test
     public void getAttachmentsShouldWorkWithDuplicatedIds() {
         AttachmentId attachmentId = AttachmentId.from("1");
         Set<AttachmentId> attachmentIds = ImmutableSet.of(attachmentId);
@@ -72,7 +96,7 @@ public class AttachmentLoaderTest {
         CassandraMessageDAO.MessageAttachmentRepresentation 
attachmentRepresentation1 = new 
CassandraMessageDAO.MessageAttachmentRepresentation(attachmentId, name1, cid, 
isInlined);
         CassandraMessageDAO.MessageAttachmentRepresentation 
attachmentRepresentation2 = new 
CassandraMessageDAO.MessageAttachmentRepresentation(attachmentId, name2, cid, 
isInlined);
 
-        Collection<MessageAttachment> attachments = 
testee.getAttachments(Sets.newHashSet(attachmentRepresentation1, 
attachmentRepresentation2));
+        Collection<MessageAttachment> attachments = 
testee.getAttachments(ImmutableList.of(attachmentRepresentation1, 
attachmentRepresentation2));
 
         assertThat(attachments).hasSize(2)
             .containsOnly(new MessageAttachment(attachment, 
OptionalConverter.toGuava(name1), OptionalConverter.toGuava(cid), isInlined),
@@ -105,7 +129,7 @@ public class AttachmentLoaderTest {
         CassandraMessageDAO.MessageAttachmentRepresentation 
attachmentRepresentation1 = new 
CassandraMessageDAO.MessageAttachmentRepresentation(attachmentId1, name1, cid, 
isInlined);
         CassandraMessageDAO.MessageAttachmentRepresentation 
attachmentRepresentation2 = new 
CassandraMessageDAO.MessageAttachmentRepresentation(attachmentId2, name2, cid, 
isInlined);
 
-        Collection<MessageAttachment> attachments = 
testee.getAttachments(Sets.newHashSet(attachmentRepresentation1, 
attachmentRepresentation2));
+        Collection<MessageAttachment> attachments = 
testee.getAttachments(ImmutableList.of(attachmentRepresentation1, 
attachmentRepresentation2));
 
         assertThat(attachments).hasSize(2)
             .containsOnly(new MessageAttachment(attachment1, 
OptionalConverter.toGuava(name1), OptionalConverter.toGuava(cid), isInlined),
@@ -125,7 +149,7 @@ public class AttachmentLoaderTest {
         when(attachmentMapper.getAttachments(attachmentIds))
             .thenReturn(ImmutableList.of(attachment));
 
-        Collection<MessageAttachment> attachments = 
testee.getAttachments(Sets.newHashSet());
+        Collection<MessageAttachment> attachments = 
testee.getAttachments(ImmutableList.of());
 
         assertThat(attachments).isEmpty();
     }


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

Reply via email to