james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [8/8] james-project git commit: JAMES-2544 Avoid negative bucketIds in RabbitMQMailQueue
Date Tue, 04 Dec 2018 08:49:01 GMT
JAMES-2544 Avoid negative bucketIds in RabbitMQMailQueue


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

Branch: refs/heads/master
Commit: d78ea34ecec0618e6581ebb8844805bc0a0d7aa6
Parents: acdb0da
Author: Benoit Tellier <btellier@linagora.com>
Authored: Tue Dec 4 10:52:02 2018 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Tue Dec 4 15:48:14 2018 +0700

----------------------------------------------------------------------
 .../view/cassandra/CassandraMailQueueMailStore.java         | 2 +-
 .../apache/james/queue/rabbitmq/RabbitMQMailQueueTest.java  | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/d78ea34e/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueMailStore.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueMailStore.java
b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueMailStore.java
index 550ac16..41c28a9 100644
--- a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueMailStore.java
+++ b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueMailStore.java
@@ -79,7 +79,7 @@ public class CassandraMailQueueMailStore {
 
     private BucketId computedBucketId(Mail mail) {
         int mailKeyHashCode = mail.getName().hashCode();
-        int bucketIdValue = mailKeyHashCode % configuration.getBucketCount();
+        int bucketIdValue = Math.abs(mailKeyHashCode) % configuration.getBucketCount();
         return BucketId.of(bucketIdValue);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/d78ea34e/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueTest.java
----------------------------------------------------------------------
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 0db32d6..a3b69d9 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
@@ -23,6 +23,7 @@ import static java.time.temporal.ChronoUnit.HOURS;
 import static org.apache.james.backend.rabbitmq.RabbitMQFixture.DEFAULT_MANAGEMENT_CREDENTIAL;
 import static org.apache.james.queue.api.Mails.defaultMail;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatCode;
 
 import java.time.Duration;
 import java.time.Instant;
@@ -218,6 +219,14 @@ public class RabbitMQMailQueueTest implements ManageableMailQueueContract,
MailQ
         assertThat(initialized).isTrue();
     }
 
+    @Test
+    void enQueueShouldNotThrowOnMailNameWithNegativeHash() {
+        String negativehashedString = "this sting will have a negative hash"; //hash value:
-1256871313
+        
+        assertThatCode(() -> getMailQueue().enQueue(defaultMail().name(negativehashedString).build()))
+            .doesNotThrowAnyException();
+    }
+
     @Disabled("JAMES-2614 RabbitMQMailQueueTest::concurrentEnqueueDequeueShouldNotFail is
unstable." +
         "The related test is disabled, and need to be re-enabled after investigation and
a fix.")
     @Test


---------------------------------------------------------------------
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