james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [1/4] james-project git commit: JAMES-1727 Memory mail queue should copy mails instead of just wrapping them
Date Thu, 19 May 2016 10:06:08 GMT
Repository: james-project
Updated Branches:
  refs/heads/master fef500291 -> f6ba5d502


JAMES-1727 Memory mail queue should copy mails instead of just wrapping them


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

Branch: refs/heads/master
Commit: 6090fa4995b0d24079b1bbcca70c21720d574662
Parents: fef5002
Author: Benoit Tellier <btellier@linagora.com>
Authored: Wed Apr 27 17:18:20 2016 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Thu May 19 10:15:57 2016 +0700

----------------------------------------------------------------------
 .../james/modules/server/MemoryMailQueueFactory.java  |  9 ++++++++-
 .../james/server/MemoryMailQueueFactoryTest.java      | 14 ++++++++++----
 2 files changed, 18 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/6090fa49/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/server/MemoryMailQueueFactory.java
----------------------------------------------------------------------
diff --git a/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/server/MemoryMailQueueFactory.java
b/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/server/MemoryMailQueueFactory.java
index 39846ed..df24931 100644
--- a/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/server/MemoryMailQueueFactory.java
+++ b/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/server/MemoryMailQueueFactory.java
@@ -24,6 +24,9 @@ import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.LinkedBlockingDeque;
 import java.util.concurrent.TimeUnit;
 
+import javax.mail.MessagingException;
+
+import org.apache.james.core.MailImpl;
 import org.apache.james.queue.api.MailQueue;
 import org.apache.james.queue.api.MailQueueFactory;
 import org.apache.james.queue.api.MailQueueItemDecoratorFactory;
@@ -77,7 +80,11 @@ public class MemoryMailQueueFactory implements MailQueueFactory {
 
         @Override
         public void enQueue(Mail mail) throws MailQueueException {
-            mailItems.addFirst(new MemoryMailQueueItem(mail));
+            try {
+                mailItems.addFirst(new MemoryMailQueueItem(new MailImpl(mail)));
+            } catch (MessagingException e) {
+                throw new MailQueueException("Error while copying mail " + mail.getName(),
e);
+            }
         }
 
         @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/6090fa49/server/container/guice/memory-guice/src/test/java/org/apache/james/server/MemoryMailQueueFactoryTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/memory-guice/src/test/java/org/apache/james/server/MemoryMailQueueFactoryTest.java
b/server/container/guice/memory-guice/src/test/java/org/apache/james/server/MemoryMailQueueFactoryTest.java
index 560378f..34133e6 100644
--- a/server/container/guice/memory-guice/src/test/java/org/apache/james/server/MemoryMailQueueFactoryTest.java
+++ b/server/container/guice/memory-guice/src/test/java/org/apache/james/server/MemoryMailQueueFactoryTest.java
@@ -45,6 +45,8 @@ public class MemoryMailQueueFactoryTest {
 
     public static final String KEY = "key";
     public static final String BIS = "bis";
+    public static final String NAME_1 = "Name1";
+    public static final String NAME_2 = "Name2";
 
     private MemoryMailQueueFactory memoryMailQueueFactory;
     private ExecutorService executorService;
@@ -88,24 +90,28 @@ public class MemoryMailQueueFactoryTest {
     @Test
     public void dequeueShouldWork() throws Exception{
         Mail mail = new FakeMail();
+        mail.setName(NAME_1);
         memoryMailQueueFactory.getQueue(KEY).enQueue(mail);
-        assertThat(memoryMailQueueFactory.getQueue(KEY).deQueue().getMail()).isEqualTo(mail);
+        assertThat(memoryMailQueueFactory.getQueue(KEY).deQueue().getMail().getName()).startsWith(NAME_1);
     }
 
     @Test
     public void dequeueShouldWorkWithMultipleMessages() throws Exception{
         Mail mail1 = new FakeMail();
         Mail mail2 = new FakeMail();
+        mail1.setName(NAME_1);
+        mail2.setName(NAME_2);
         memoryMailQueueFactory.getQueue(KEY).enQueue(mail1);
         memoryMailQueueFactory.getQueue(KEY).enQueue(mail2);
-        assertThat(memoryMailQueueFactory.getQueue(KEY).deQueue().getMail()).isEqualTo(mail2);
-        assertThat(memoryMailQueueFactory.getQueue(KEY).deQueue().getMail()).isEqualTo(mail1);
+        assertThat(memoryMailQueueFactory.getQueue(KEY).deQueue().getMail().getName()).startsWith(NAME_2);
+        assertThat(memoryMailQueueFactory.getQueue(KEY).deQueue().getMail().getName()).startsWith(NAME_1);
     }
 
     @Test(timeout = 20000)
     public void deQueueShouldWaitForAMailToBeEnqueued() throws Exception {
         CountDownLatch latch = new CountDownLatch(1);
         Mail mail = new FakeMail();
+        mail.setName(NAME_1);
         executorService.submit(() -> {
             try {
                 latch.await();
@@ -117,6 +123,6 @@ public class MemoryMailQueueFactoryTest {
         Future<MailQueueItem> tryDequeue = executorService.submit(() -> memoryMailQueueFactory.getQueue(KEY).deQueue());
         assertThatThrownBy(() -> tryDequeue.get(100, TimeUnit.MILLISECONDS)).isInstanceOf(TimeoutException.class);
         latch.countDown();
-        assertThat(tryDequeue.get().getMail()).isEqualTo(mail);
+        assertThat(tryDequeue.get().getMail().getName()).startsWith(NAME_1);
     }
 }


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