You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2018/08/04 01:20:18 UTC

[03/16] james-project git commit: JAMES-2514 Remove Cassandra specific long mailbox name handling

JAMES-2514 Remove Cassandra specific long mailbox name handling


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

Branch: refs/heads/master
Commit: ef145fe1bb879d794e37dd770f44868648b22140
Parents: ea54521
Author: Benoit Tellier <bt...@linagora.com>
Authored: Thu Aug 2 17:28:23 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Sat Aug 4 08:17:14 2018 +0700

----------------------------------------------------------------------
 .../cassandra/mail/CassandraMailboxMapper.java  | 54 +++++--------
 .../mail/utils/DriverExceptionHelper.java       | 54 -------------
 .../mail/utils/DriverExceptionHelperTest.java   | 85 --------------------
 3 files changed, 20 insertions(+), 173 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/ef145fe1/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapper.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapper.java
index 92f6f461..5dee291 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapper.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapper.java
@@ -25,7 +25,6 @@ import java.util.Map;
 import java.util.Optional;
 import java.util.StringTokenizer;
 import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.CompletionException;
 import java.util.concurrent.CompletionStage;
 import java.util.function.Function;
 import java.util.regex.Pattern;
@@ -36,7 +35,6 @@ import javax.inject.Inject;
 
 import org.apache.james.mailbox.acl.ACLDiff;
 import org.apache.james.mailbox.cassandra.ids.CassandraId;
-import org.apache.james.mailbox.cassandra.mail.utils.DriverExceptionHelper;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.exception.MailboxExistsException;
 import org.apache.james.mailbox.exception.MailboxNotFoundException;
@@ -88,33 +86,25 @@ public class CassandraMailboxMapper implements MailboxMapper {
 
     @Override
     public Mailbox findMailboxByPath(MailboxPath path) throws MailboxException {
-        try {
-            return mailboxPathV2DAO.retrieveId(path)
-                .thenCompose(cassandraIdOptional ->
-                    cassandraIdOptional
-                        .map(CassandraIdAndPath::getCassandraId)
-                        .map(this::retrieveMailbox)
-                        .orElseGet(Throwing.supplier(() -> fromPreviousTable(path))))
-                .join()
-                .orElseThrow(() -> new MailboxNotFoundException(path));
-        } catch (CompletionException e) {
-            throw DriverExceptionHelper.handleStorageException(e);
-        }
+        return mailboxPathV2DAO.retrieveId(path)
+            .thenCompose(cassandraIdOptional ->
+                cassandraIdOptional
+                    .map(CassandraIdAndPath::getCassandraId)
+                    .map(this::retrieveMailbox)
+                    .orElseGet(Throwing.supplier(() -> fromPreviousTable(path))))
+            .join()
+            .orElseThrow(() -> new MailboxNotFoundException(path));
     }
 
-    private CompletableFuture<Optional<SimpleMailbox>> fromPreviousTable(MailboxPath path) throws MailboxException {
-        try {
-            return mailboxPathDAO.retrieveId(path)
-                .thenCompose(cassandraIdOptional ->
-                    cassandraIdOptional
-                        .map(CassandraIdAndPath::getCassandraId)
-                        .map(this::retrieveMailbox)
-                        .orElse(CompletableFuture.completedFuture(Optional.empty())))
-                .thenCompose(maybeMailbox -> maybeMailbox.map(this::migrate)
-                    .orElse(CompletableFuture.completedFuture(maybeMailbox)));
-        } catch (CompletionException e) {
-            throw DriverExceptionHelper.handleStorageException(e);
-        }
+    private CompletableFuture<Optional<SimpleMailbox>> fromPreviousTable(MailboxPath path) {
+        return mailboxPathDAO.retrieveId(path)
+            .thenCompose(cassandraIdOptional ->
+                cassandraIdOptional
+                    .map(CassandraIdAndPath::getCassandraId)
+                    .map(this::retrieveMailbox)
+                    .orElse(CompletableFuture.completedFuture(Optional.empty())))
+            .thenCompose(maybeMailbox -> maybeMailbox.map(this::migrate)
+                .orElse(CompletableFuture.completedFuture(maybeMailbox)));
     }
 
     private CompletableFuture<Optional<SimpleMailbox>> migrate(SimpleMailbox mailbox) {
@@ -197,13 +187,9 @@ public class CassandraMailboxMapper implements MailboxMapper {
 
         CassandraId cassandraId = retrieveId(cassandraMailbox);
         cassandraMailbox.setMailboxId(cassandraId);
-        try {
-            boolean applied = trySave(cassandraMailbox, cassandraId).join();
-            if (!applied) {
-                throw new MailboxExistsException(mailbox.generateAssociatedPath().asString());
-            }
-        } catch (CompletionException e) {
-            throw DriverExceptionHelper.handleStorageException(e);
+        boolean applied = trySave(cassandraMailbox, cassandraId).join();
+        if (!applied) {
+            throw new MailboxExistsException(mailbox.generateAssociatedPath().asString());
         }
         return cassandraId;
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/ef145fe1/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/utils/DriverExceptionHelper.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/utils/DriverExceptionHelper.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/utils/DriverExceptionHelper.java
deleted file mode 100644
index f5d669e..0000000
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/utils/DriverExceptionHelper.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/****************************************************************
- * 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.mailbox.cassandra.mail.utils;
-
-import java.util.concurrent.CompletionException;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.exception.TooLongMailboxNameException;
-
-import com.datastax.driver.core.exceptions.InvalidQueryException;
-
-public class DriverExceptionHelper {
-    public static final String VALUES_MAY_NOT_BE_LARGER_THAN_64_K = "Index expression values may not be larger than 64K";
-    public static final String CLUSTERING_COLUMNS_IS_TOO_LONG = "The sum of all clustering columns is too long";
-
-    public static MailboxException handleStorageException(CompletionException e) throws MailboxException {
-        if (e.getCause() instanceof InvalidQueryException) {
-            return handleInvalidQuery((InvalidQueryException) e.getCause());
-        }
-        throw e;
-    }
-
-    public static MailboxException handleInvalidQuery(InvalidQueryException cause) throws MailboxException {
-        if (isTooLong(cause)) {
-            throw new TooLongMailboxNameException("too long mailbox name");
-        }
-        throw new MailboxException("Error while interacting with cassandra storage", cause);
-    }
-
-    public static boolean isTooLong(InvalidQueryException e) {
-        String errorMessage = e.getMessage();
-        return StringUtils.containsIgnoreCase(errorMessage, VALUES_MAY_NOT_BE_LARGER_THAN_64_K)
-            || StringUtils.containsIgnoreCase(errorMessage, CLUSTERING_COLUMNS_IS_TOO_LONG);
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/ef145fe1/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/utils/DriverExceptionHelperTest.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/utils/DriverExceptionHelperTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/utils/DriverExceptionHelperTest.java
deleted file mode 100644
index c8ae149..0000000
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/utils/DriverExceptionHelperTest.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/****************************************************************
- * 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.mailbox.cassandra.mail.utils;
-
-import static org.apache.james.mailbox.cassandra.mail.utils.DriverExceptionHelper.CLUSTERING_COLUMNS_IS_TOO_LONG;
-import static org.apache.james.mailbox.cassandra.mail.utils.DriverExceptionHelper.VALUES_MAY_NOT_BE_LARGER_THAN_64_K;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-
-import java.util.concurrent.CompletionException;
-
-import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.exception.TooLongMailboxNameException;
-import org.junit.Test;
-
-import com.datastax.driver.core.exceptions.InvalidQueryException;
-
-public class DriverExceptionHelperTest {
-
-    @Test
-    public void handleStorageExceptionShouldPropagateWhenNoCause() {
-        CompletionException completionException = new CompletionException() {};
-
-        assertThatThrownBy(() ->
-            DriverExceptionHelper.handleStorageException(completionException))
-                .isEqualTo(completionException);
-    }
-
-    @Test
-    public void handleStorageExceptionShouldPropagateWhenCauseIsNotInvalidQuery() {
-        CompletionException exception = new CompletionException("message", new RuntimeException());
-
-        assertThatThrownBy(() ->
-            DriverExceptionHelper.handleStorageException(exception))
-                .isEqualTo(exception);
-    }
-
-    @Test
-    public void handleStorageExceptionShouldUnwrapWhenCauseIsInvalidQuery() {
-        InvalidQueryException invalidQueryException = new InvalidQueryException("message");
-        CompletionException exception = new CompletionException("message", invalidQueryException);
-
-        assertThatThrownBy(() ->
-            DriverExceptionHelper.handleStorageException(exception))
-                .isInstanceOf(MailboxException.class)
-                .hasCause(invalidQueryException);
-    }
-
-    @Test
-    public void handleStorageExceptionShouldThrowTooLongWhenClusteringColumnsTooLong() {
-        InvalidQueryException invalidQueryException = new InvalidQueryException(CLUSTERING_COLUMNS_IS_TOO_LONG);
-        CompletionException exception = new CompletionException("message", invalidQueryException);
-
-        assertThatThrownBy(() ->
-            DriverExceptionHelper.handleStorageException(exception))
-                .isInstanceOf(TooLongMailboxNameException.class);
-    }
-
-    @Test
-    public void handleStorageExceptionShouldThrowTooLongWhenValueMoreThan64K() {
-        InvalidQueryException invalidQueryException = new InvalidQueryException(VALUES_MAY_NOT_BE_LARGER_THAN_64_K);
-        CompletionException exception = new CompletionException("message", invalidQueryException);
-
-        assertThatThrownBy(() ->
-            DriverExceptionHelper.handleStorageException(exception))
-                .isInstanceOf(TooLongMailboxNameException.class);
-    }
-
-}
\ 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