james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [2/7] james-project git commit: JAMES-2390 Guava <-> Java8 Future handling limitation
Date Tue, 08 May 2018 02:17:21 GMT
JAMES-2390 Guava <-> Java8 Future handling limitation

With Guava -> Java future conversions, we can not collect then join. It is throwing:

```
java.util.concurrent.CompletionException: com.datastax.driver.core.exceptions.NoHostAvailableException:
All host(s) tried for query failed (tried: localhost/127.0.0.1:32789 (com.datastax.driver.core.exceptions.OperationTimedOutException:
[localhost/127.0.0.1:32789] Timed out waiting for server response))
```

We should join then collect.


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

Branch: refs/heads/master
Commit: 3081d9ab79444a642a782748d2bde20187c9eaad
Parents: 9180da4
Author: benwa <btellier@linagora.com>
Authored: Sun May 6 09:39:02 2018 +0700
Committer: benwa <btellier@linagora.com>
Committed: Tue May 8 09:15:36 2018 +0700

----------------------------------------------------------------------
 .../cassandra/mail/CassandraAttachmentMapper.java      |  2 +-
 .../cassandra/mail/CassandraAttachmentOwnerDAO.java    | 10 +++-------
 .../mail/CassandraAttachmentOwnerDAOTest.java          | 13 +++++++++++++
 3 files changed, 17 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/3081d9ab/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 ef0294b..678b10b 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
@@ -148,7 +148,7 @@ public class CassandraAttachmentMapper implements AttachmentMapper {
 
     @Override
     public Collection<Username> getOwners(AttachmentId attachmentId) throws MailboxException
{
-        return ownerDAO.retrieveOwners(attachmentId).join();
+        return ownerDAO.retrieveOwners(attachmentId).join().collect(Guavate.toImmutableList());
     }
 
     public CompletableFuture<Void> storeAttachmentAsync(Attachment attachment, MessageId
ownerMessageId) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/3081d9ab/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentOwnerDAO.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentOwnerDAO.java
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentOwnerDAO.java
index 1be5175..e92757c 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentOwnerDAO.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentOwnerDAO.java
@@ -28,7 +28,6 @@ import static org.apache.james.mailbox.cassandra.table.CassandraAttachmentOwnerT
 import static org.apache.james.mailbox.cassandra.table.CassandraAttachmentOwnerTable.OWNER;
 import static org.apache.james.mailbox.cassandra.table.CassandraAttachmentOwnerTable.TABLE_NAME;
 
-import java.util.Collection;
 import java.util.concurrent.CompletableFuture;
 import java.util.stream.Stream;
 
@@ -42,8 +41,6 @@ import org.apache.james.mailbox.store.mail.model.Username;
 import com.datastax.driver.core.PreparedStatement;
 import com.datastax.driver.core.Row;
 import com.datastax.driver.core.Session;
-import com.github.steveash.guavate.Guavate;
-import com.google.common.collect.ImmutableList;
 
 public class CassandraAttachmentOwnerDAO {
 
@@ -82,7 +79,7 @@ public class CassandraAttachmentOwnerDAO {
                 .setString(OWNER, owner.getValue()));
     }
 
-    public CompletableFuture<Collection<Username>> retrieveOwners(AttachmentId
attachmentId) {
+    public CompletableFuture<Stream<Username>> retrieveOwners(AttachmentId attachmentId)
{
         return executor.execute(
             selectStatement.bind()
                 .setUUID(ID, attachmentId.asUUID()))
@@ -90,9 +87,8 @@ public class CassandraAttachmentOwnerDAO {
             .thenApply(this::toOwners);
     }
 
-    private ImmutableList<Username> toOwners(Stream<Row> stream) {
+    private Stream<Username> toOwners(Stream<Row> stream) {
         return stream.map(row -> row.getString(OWNER))
-            .map(Username::fromRawValue)
-            .collect(Guavate.toImmutableList());
+            .map(Username::fromRawValue);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/3081d9ab/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentOwnerDAOTest.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentOwnerDAOTest.java
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentOwnerDAOTest.java
index 9f75612..758ae57 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentOwnerDAOTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentOwnerDAOTest.java
@@ -21,6 +21,8 @@ package org.apache.james.mailbox.cassandra.mail;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
+import java.util.stream.IntStream;
+
 import org.apache.james.backends.cassandra.CassandraCluster;
 import org.apache.james.backends.cassandra.DockerCassandraRule;
 import org.apache.james.backends.cassandra.utils.CassandraUtils;
@@ -73,4 +75,15 @@ public class CassandraAttachmentOwnerDAOTest {
         assertThat(testee.retrieveOwners(ATTACHMENT_ID).join())
             .containsOnly(OWNER_1, OWNER_2);
     }
+
+    @Test
+    public void retrieveOwnersShouldNotThrowWhenMoreReferencesThanPaging() {
+        int referenceCountExceedingPaging = 5050;
+        IntStream.range(0, referenceCountExceedingPaging)
+            .boxed()
+            .forEach(i -> testee.addOwner(ATTACHMENT_ID, Username.fromRawValue("owner"
+ i)).join());
+
+        assertThat(testee.retrieveOwners(ATTACHMENT_ID).join())
+            .hasSize(referenceCountExceedingPaging);
+    }
 }
\ 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


Mime
View raw message