james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [3/9] james-project git commit: JAMES-2544 UpdatableTickingClock should not be responsible of time increase decision
Date Tue, 02 Oct 2018 02:57:05 GMT
JAMES-2544 UpdatableTickingClock should not be responsible of time increase decision


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

Branch: refs/heads/master
Commit: 2b960b103f7213145bb8e417c25159a6353e8bdf
Parents: 2729742
Author: Benoit Tellier <btellier@linagora.com>
Authored: Fri Sep 28 17:18:50 2018 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Tue Oct 2 09:19:58 2018 +0700

----------------------------------------------------------------------
 .../james/queue/api/MailQueueContract.java      |  52 +++----
 .../queue/api/MailQueueMetricContract.java      |   2 +-
 .../queue/api/ManageableMailQueueContract.java  | 138 +++++++++----------
 .../queue/rabbitmq/RabbitMQMailQueueTest.java   |  51 ++++++-
 .../queue/rabbitmq/UpdatableTickingClock.java   |  61 --------
 5 files changed, 144 insertions(+), 160 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/2b960b10/server/queue/queue-api/src/test/java/org/apache/james/queue/api/MailQueueContract.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-api/src/test/java/org/apache/james/queue/api/MailQueueContract.java
b/server/queue/queue-api/src/test/java/org/apache/james/queue/api/MailQueueContract.java
index e2df16f..25c05f9 100644
--- a/server/queue/queue-api/src/test/java/org/apache/james/queue/api/MailQueueContract.java
+++ b/server/queue/queue-api/src/test/java/org/apache/james/queue/api/MailQueueContract.java
@@ -35,7 +35,6 @@ import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
-import java.util.stream.Stream;
 
 import javax.mail.internet.MimeMessage;
 
@@ -57,16 +56,21 @@ public interface MailQueueContract {
 
     MailQueue getMailQueue();
 
+    default void enQueue(Mail mail) throws MailQueue.MailQueueException {
+        getMailQueue().enQueue(mail);
+    }
+
     @Test
     default void queueShouldSupportBigMail() throws Exception {
         String name = "name1";
         // 12 MB of text
         String messageText = Strings.repeat("0123456789\r\n", 1024 * 1024);
-        getMailQueue().enQueue(defaultMail()
+        FakeMail mail = defaultMail()
             .name(name)
             .mimeMessage(MimeMessageBuilder.mimeMessageBuilder()
                 .setText(messageText))
-            .build());
+            .build();
+        enQueue(mail);
 
         MailQueue.MailQueueItem mailQueueItem = getMailQueue().deQueue();
         assertThat(mailQueueItem.getMail().getName())
@@ -75,7 +79,7 @@ public interface MailQueueContract {
 
     @Test
     default void queueShouldPreserveMailRecipients() throws Exception {
-        getMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .recipients(RECIPIENT1, RECIPIENT2)
             .build());
 
@@ -86,7 +90,7 @@ public interface MailQueueContract {
 
     @Test
     default void queueShouldPreserveNullSender() throws Exception {
-        getMailQueue().enQueue(FakeMail.builder()
+        enQueue(FakeMail.builder()
             .name("name")
             .mimeMessage(createMimeMessage())
             .recipients(RECIPIENT1, RECIPIENT2)
@@ -101,7 +105,7 @@ public interface MailQueueContract {
 
     @Test
     default void queueShouldPreserveMailSender() throws Exception {
-        getMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .sender(SENDER)
             .build());
 
@@ -113,7 +117,7 @@ public interface MailQueueContract {
     @Test
     default void queueShouldPreserveMimeMessage() throws Exception {
         MimeMessage originalMimeMessage = createMimeMessage();
-        getMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .mimeMessage(originalMimeMessage)
             .build());
 
@@ -126,7 +130,7 @@ public interface MailQueueContract {
     default void queueShouldPreserveMailAttribute() throws Exception {
         String attributeName = "any";
         String attributeValue = "value";
-        getMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .attribute(attributeName, attributeValue)
             .build());
 
@@ -138,7 +142,7 @@ public interface MailQueueContract {
     @Test
     default void queueShouldPreserveErrorMessage() throws Exception {
         String errorMessage = "ErrorMessage";
-        getMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .errorMessage(errorMessage)
             .build());
 
@@ -150,7 +154,7 @@ public interface MailQueueContract {
     @Test
     default void queueShouldPreserveState() throws Exception {
         String state = "state";
-        getMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .state(state)
             .build());
 
@@ -162,7 +166,7 @@ public interface MailQueueContract {
     @Test
     default void queueShouldPreserveRemoteAddress() throws Exception {
         String remoteAddress = "remote";
-        getMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .remoteAddr(remoteAddress)
             .build());
 
@@ -174,7 +178,7 @@ public interface MailQueueContract {
     @Test
     default void queueShouldPreserveRemoteHost() throws Exception {
         String remoteHost = "remote";
-        getMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .remoteHost(remoteHost)
             .build());
 
@@ -186,7 +190,7 @@ public interface MailQueueContract {
     @Test
     default void queueShouldPreserveLastUpdated() throws Exception {
         Date lastUpdated = new Date();
-        getMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .lastUpdated(lastUpdated)
             .build());
 
@@ -198,7 +202,7 @@ public interface MailQueueContract {
     @Test
     default void queueShouldPreserveName() throws Exception {
         String expectedName = "name";
-        getMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name(expectedName)
             .build());
 
@@ -213,7 +217,7 @@ public interface MailQueueContract {
             .name("any")
             .value("any")
             .build();
-        getMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .addHeaderForRecipient(header, RECIPIENT1)
             .build());
 
@@ -227,7 +231,7 @@ public interface MailQueueContract {
     default void queueShouldPreserveNonStringMailAttribute() throws Exception {
         String attributeName = "any";
         SerializableAttribute attributeValue = new SerializableAttribute("value");
-        getMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
                 .attribute(attributeName, attributeValue)
                 .build());
 
@@ -240,11 +244,11 @@ public interface MailQueueContract {
     @Test
     default void dequeueShouldBeFifo() throws Exception {
         String firstExpectedName = "name1";
-        getMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name(firstExpectedName)
             .build());
         String secondExpectedName = "name2";
-        getMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name(secondExpectedName)
             .build());
 
@@ -258,10 +262,10 @@ public interface MailQueueContract {
 
     @Test
     default void dequeueCanBeChainedBeforeAck() throws Exception {
-        getMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name1")
             .build());
-        getMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name2")
             .build());
 
@@ -276,10 +280,10 @@ public interface MailQueueContract {
 
     @Test
     default void dequeueCouldBeInterleavingWithOutOfOrderAck() throws Exception {
-        getMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name1")
             .build());
-        getMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name2")
             .build());
 
@@ -293,7 +297,7 @@ public interface MailQueueContract {
 
     @Test
     default void dequeueShouldAllowRetrieveFailItems() throws Exception {
-        getMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name1")
             .build());
 
@@ -307,7 +311,7 @@ public interface MailQueueContract {
 
     @Test
     default void dequeueShouldNotReturnInProcessingEmails(ExecutorService executorService)
throws Exception {
-        getMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name")
             .build());
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/2b960b10/server/queue/queue-api/src/test/java/org/apache/james/queue/api/MailQueueMetricContract.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-api/src/test/java/org/apache/james/queue/api/MailQueueMetricContract.java
b/server/queue/queue-api/src/test/java/org/apache/james/queue/api/MailQueueMetricContract.java
index f80bee9..c6de9f6 100644
--- a/server/queue/queue-api/src/test/java/org/apache/james/queue/api/MailQueueMetricContract.java
+++ b/server/queue/queue-api/src/test/java/org/apache/james/queue/api/MailQueueMetricContract.java
@@ -51,7 +51,7 @@ public interface MailQueueMetricContract extends MailQueueContract {
     default void enQueueMail(Integer times) throws Exception {
         IntStream
             .rangeClosed(1, times)
-            .forEach(Throwing.intConsumer(time -> getMailQueue().enQueue(fakeMail())));
+            .forEach(Throwing.intConsumer(time -> enQueue(fakeMail())));
     }
 
     default void deQueueMail(Integer times) throws Exception {

http://git-wip-us.apache.org/repos/asf/james-project/blob/2b960b10/server/queue/queue-api/src/test/java/org/apache/james/queue/api/ManageableMailQueueContract.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-api/src/test/java/org/apache/james/queue/api/ManageableMailQueueContract.java
b/server/queue/queue-api/src/test/java/org/apache/james/queue/api/ManageableMailQueueContract.java
index 9bc503c..6520288 100644
--- a/server/queue/queue-api/src/test/java/org/apache/james/queue/api/ManageableMailQueueContract.java
+++ b/server/queue/queue-api/src/test/java/org/apache/james/queue/api/ManageableMailQueueContract.java
@@ -48,7 +48,7 @@ public interface ManageableMailQueueContract extends MailQueueContract {
 
     @Test
     default void getSizeShouldReturnMessageCount() throws Exception {
-        getManageableMailQueue().enQueue(defaultMail().build());
+        enQueue(defaultMail().build());
 
         long size = getManageableMailQueue().getSize();
 
@@ -57,8 +57,8 @@ public interface ManageableMailQueueContract extends MailQueueContract {
 
     @Test
     default void getSizeShouldReturnMessageCountWhenSeveralMails() throws Exception {
-        getManageableMailQueue().enQueue(defaultMail().name("1").build());
-        getManageableMailQueue().enQueue(defaultMail().name("2").build());
+        enQueue(defaultMail().name("1").build());
+        enQueue(defaultMail().name("2").build());
 
         long size = getManageableMailQueue().getSize();
 
@@ -67,7 +67,7 @@ public interface ManageableMailQueueContract extends MailQueueContract {
 
     @Test
     default void dequeueShouldDecreaseQueueSize() throws Exception {
-        getManageableMailQueue().enQueue(defaultMail().build());
+        enQueue(defaultMail().build());
 
         getManageableMailQueue().deQueue().done(true);
 
@@ -78,7 +78,7 @@ public interface ManageableMailQueueContract extends MailQueueContract {
 
     @Test
     default void noAckShouldNotDecreaseSize() throws Exception {
-        getManageableMailQueue().enQueue(defaultMail().build());
+        enQueue(defaultMail().build());
 
         getManageableMailQueue().deQueue().done(false);
 
@@ -89,7 +89,7 @@ public interface ManageableMailQueueContract extends MailQueueContract {
 
     @Test
     default void processedMailsShouldNotDecreaseSize() throws Exception {
-        getManageableMailQueue().enQueue(defaultMail().build());
+        enQueue(defaultMail().build());
 
         getManageableMailQueue().deQueue();
 
@@ -107,7 +107,7 @@ public interface ManageableMailQueueContract extends MailQueueContract
{
 
     @Test
     default void browseShouldReturnSingleElement() throws Exception {
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name")
             .build());
 
@@ -120,13 +120,13 @@ public interface ManageableMailQueueContract extends MailQueueContract
{
 
     @Test
     default void browseShouldReturnElementsInOrder() throws Exception {
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name1")
             .build());
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name2")
             .build());
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name3")
             .build());
 
@@ -140,13 +140,13 @@ public interface ManageableMailQueueContract extends MailQueueContract
{
 
     @Test
     default void dequeueShouldNotFailWhenBrowsing() throws Exception {
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name1")
             .build());
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name2")
             .build());
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name3")
             .build());
 
@@ -158,13 +158,13 @@ public interface ManageableMailQueueContract extends MailQueueContract
{
 
     @Test
     default void browseShouldNotFailWhenConcurrentDequeue() throws Exception {
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name1")
             .build());
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name2")
             .build());
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name3")
             .build());
 
@@ -177,13 +177,13 @@ public interface ManageableMailQueueContract extends MailQueueContract
{
 
     @Test
     default void dequeueShouldNotFailWhenBrowsingIterating() throws Exception {
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name1")
             .build());
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name2")
             .build());
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name3")
             .build());
 
@@ -196,13 +196,13 @@ public interface ManageableMailQueueContract extends MailQueueContract
{
 
     @Test
     default void browseShouldNotFailWhenConcurrentDequeueWhenIterating() throws Exception
{
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name1")
             .build());
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name2")
             .build());
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name3")
             .build());
 
@@ -216,19 +216,19 @@ public interface ManageableMailQueueContract extends MailQueueContract
{
 
     @Test
     default void enqueueShouldNotFailWhenBrowsing() throws Exception {
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name1")
             .build());
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name2")
             .build());
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name3")
             .build());
 
         getManageableMailQueue().browse();
 
-        assertThatCode(() -> getManageableMailQueue().enQueue(defaultMail()
+        assertThatCode(() -> enQueue(defaultMail()
             .name("name4")
             .build())).doesNotThrowAnyException();
 
@@ -236,19 +236,19 @@ public interface ManageableMailQueueContract extends MailQueueContract
{
 
     @Test
     default void browseShouldNotFailWhenConcurrentEnqueue() throws Exception {
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name1")
             .build());
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name2")
             .build());
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name3")
             .build());
 
         ManageableMailQueue.MailQueueIterator items = getManageableMailQueue().browse();
 
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name4")
             .build());
 
@@ -257,13 +257,13 @@ public interface ManageableMailQueueContract extends MailQueueContract
{
 
     @Test
     default void enqueueShouldNotFailWhenBrowsingIterating() throws Exception {
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name1")
             .build());
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name2")
             .build());
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name3")
             .build());
 
@@ -271,7 +271,7 @@ public interface ManageableMailQueueContract extends MailQueueContract
{
         items.next();
 
         assertThatCode(() ->
-            getManageableMailQueue().enQueue(defaultMail()
+            enQueue(defaultMail()
                 .name("name4")
                 .build()))
             .doesNotThrowAnyException();
@@ -280,20 +280,20 @@ public interface ManageableMailQueueContract extends MailQueueContract
{
 
     @Test
     default void browseShouldNotFailWhenConcurrentEnqueueWhenIterating() throws Exception
{
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name1")
             .build());
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name2")
             .build());
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name3")
             .build());
 
         ManageableMailQueue.MailQueueIterator items = getManageableMailQueue().browse();
         items.next();
 
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name2")
             .build());
 
@@ -302,13 +302,13 @@ public interface ManageableMailQueueContract extends MailQueueContract
{
 
     @Test
     default void clearShouldNotFailWhenBrowsingIterating() throws Exception {
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name1")
             .build());
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name2")
             .build());
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name3")
             .build());
 
@@ -322,13 +322,13 @@ public interface ManageableMailQueueContract extends MailQueueContract
{
 
     @Test
     default void browseShouldNotFailWhenConcurrentClearWhenIterating() throws Exception {
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name1")
             .build());
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name2")
             .build());
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name3")
             .build());
 
@@ -342,13 +342,13 @@ public interface ManageableMailQueueContract extends MailQueueContract
{
 
     @Test
     default void flushShouldNotFailWhenBrowsingIterating() throws Exception {
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name1")
             .build());
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name2")
             .build());
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name3")
             .build());
 
@@ -362,13 +362,13 @@ public interface ManageableMailQueueContract extends MailQueueContract
{
 
     @Test
     default void browseShouldNotFailWhenConcurrentFlushWhenIterating() throws Exception {
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name1")
             .build());
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name2")
             .build());
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name3")
             .build());
 
@@ -382,13 +382,13 @@ public interface ManageableMailQueueContract extends MailQueueContract
{
 
     @Test
     default void removeShouldNotFailWhenBrowsingIterating() throws Exception {
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name1")
             .build());
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name2")
             .build());
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name3")
             .build());
 
@@ -402,13 +402,13 @@ public interface ManageableMailQueueContract extends MailQueueContract
{
 
     @Test
     default void browseShouldNotFailWhenConcurrentRemoveWhenIterating() throws Exception
{
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name1")
             .build());
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name2")
             .build());
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name3")
             .build());
 
@@ -422,13 +422,13 @@ public interface ManageableMailQueueContract extends MailQueueContract
{
 
     @Test
     default void browsingShouldNotAffectDequeue() throws Exception {
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name1")
             .build());
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name2")
             .build());
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name3")
             .build());
 
@@ -442,10 +442,10 @@ public interface ManageableMailQueueContract extends MailQueueContract
{
 
     @Test
     default void removeByNameShouldRemoveSpecificEmail() throws Exception {
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name1")
             .build());
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name2")
             .build());
 
@@ -459,11 +459,11 @@ public interface ManageableMailQueueContract extends MailQueueContract
{
 
     @Test
     default void removeBySenderShouldRemoveSpecificEmail() throws Exception {
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .sender(OTHER_AT_LOCAL)
             .name("name1")
             .build());
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .sender(SENDER)
             .name("name2")
             .build());
@@ -478,11 +478,11 @@ public interface ManageableMailQueueContract extends MailQueueContract
{
 
     @Test
     default void removeByRecipientShouldRemoveSpecificEmail() throws Exception {
-        getManageableMailQueue().enQueue(defaultMailNoRecipient()
+        enQueue(defaultMailNoRecipient()
             .name("name1")
             .recipient(RECIPIENT1)
             .build());
-        getManageableMailQueue().enQueue(defaultMailNoRecipient()
+        enQueue(defaultMailNoRecipient()
             .name("name2")
             .recipient(RECIPIENT2)
             .build());
@@ -497,11 +497,11 @@ public interface ManageableMailQueueContract extends MailQueueContract
{
 
     @Test
     default void removeByRecipientShouldRemoveSpecificEmailWhenMultipleRecipients() throws
Exception {
-        getManageableMailQueue().enQueue(defaultMailNoRecipient()
+        enQueue(defaultMailNoRecipient()
             .name("name1")
             .recipients(RECIPIENT1, RECIPIENT2)
             .build());
-        getManageableMailQueue().enQueue(defaultMailNoRecipient()
+        enQueue(defaultMailNoRecipient()
             .name("name2")
             .recipients(RECIPIENT1, RECIPIENT3)
             .build());
@@ -541,10 +541,10 @@ public interface ManageableMailQueueContract extends MailQueueContract
{
 
     @Test
     default void clearShouldRemoveAllElements() throws Exception {
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name1")
             .build());
-        getManageableMailQueue().enQueue(defaultMail()
+        enQueue(defaultMail()
             .name("name2")
             .build());
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/2b960b10/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 7715d40..fec2988 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,8 +23,10 @@ import static java.time.temporal.ChronoUnit.HOURS;
 import static org.apache.james.queue.api.Mails.defaultMail;
 import static org.assertj.core.api.Assertions.assertThat;
 
+import java.time.Clock;
 import java.time.Duration;
 import java.time.Instant;
+import java.time.ZoneId;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ThreadLocalRandom;
 import java.util.function.Function;
@@ -33,6 +35,7 @@ import java.util.stream.Stream;
 
 import javax.mail.internet.MimeMessage;
 
+import org.apache.commons.lang3.NotImplementedException;
 import org.apache.james.backend.rabbitmq.DockerRabbitMQ;
 import org.apache.james.backend.rabbitmq.RabbitChannelPool;
 import org.apache.james.backend.rabbitmq.RabbitMQConfiguration;
@@ -49,6 +52,7 @@ import org.apache.james.blob.cassandra.CassandraBlobsDAO;
 import org.apache.james.blob.mail.MimeMessagePartsId;
 import org.apache.james.blob.mail.MimeMessageStore;
 import org.apache.james.queue.api.MailQueue;
+import org.apache.james.queue.api.MailQueueContract;
 import org.apache.james.queue.api.MailQueueMetricContract;
 import org.apache.james.queue.api.MailQueueMetricExtension;
 import org.apache.james.queue.api.ManageableMailQueue;
@@ -88,6 +92,13 @@ public class RabbitMQMailQueueTest implements ManageableMailQueueContract,
MailQ
 
     private RabbitMQMailQueueFactory mailQueueFactory;
     private UpdatableTickingClock clock;
+    private RabbitMQMailQueue mailQueue;
+
+    @Override
+    public void enQueue(Mail mail) throws MailQueue.MailQueueException {
+        ManageableMailQueueContract.super.enQueue(mail);
+        clock.tick();
+    }
 
     @BeforeEach
     void setup(DockerRabbitMQ rabbitMQ, CassandraCluster cassandra, MailQueueMetricExtension.MailQueueMetricTestSystem
metricTestSystem) throws Exception {
@@ -122,16 +133,17 @@ public class RabbitMQMailQueueTest implements ManageableMailQueueContract,
MailQ
             clock);
         RabbitMQManagementApi mqManagementApi = new RabbitMQManagementApi(rabbitMQ.managementUri(),
new RabbitMQManagementCredentials("guest", "guest".toCharArray()));
         mailQueueFactory = new RabbitMQMailQueueFactory(rabbitClient, mqManagementApi, factory);
+        mailQueue = mailQueueFactory.createQueue(SPOOL);
     }
 
     @Override
     public MailQueue getMailQueue() {
-        return mailQueueFactory.createQueue(SPOOL);
+        return mailQueue;
     }
 
     @Override
     public ManageableMailQueue getManageableMailQueue() {
-        return mailQueueFactory.createQueue(SPOOL);
+        return mailQueue;
     }
 
     @Test
@@ -212,10 +224,8 @@ public class RabbitMQMailQueueTest implements ManageableMailQueueContract,
MailQ
     }
 
     private void enqueueSomeMails(Function<Integer, String> namePattern, int emailCount)
{
-        ManageableMailQueue mailQueue = getManageableMailQueue();
-
         IntStream.rangeClosed(1, emailCount)
-            .forEach(Throwing.intConsumer(i -> mailQueue.enQueue(defaultMail()
+            .forEach(Throwing.intConsumer(i -> enQueue(defaultMail()
                 .name(namePattern.apply(i))
                 .build())));
     }
@@ -225,4 +235,35 @@ public class RabbitMQMailQueueTest implements ManageableMailQueueContract,
MailQ
         IntStream.rangeClosed(1, times)
             .forEach(Throwing.intConsumer(bucketId -> mailQueue.deQueue().done(true)));
     }
+
+    private static class UpdatableTickingClock extends Clock {
+        private Instant currentInstant;
+
+        UpdatableTickingClock(Instant currentInstant) {
+            this.currentInstant = currentInstant;
+        }
+
+        void setInstant(Instant instant) {
+            currentInstant = instant;
+        }
+
+        @Override
+        public ZoneId getZone() {
+            throw new NotImplementedException("No timezone attached to this clock");
+        }
+
+        @Override
+        public Clock withZone(ZoneId zone) {
+            throw new NotImplementedException("No timezone attached to this clock");
+        }
+
+        @Override
+        public Instant instant() {
+            return currentInstant;
+        }
+
+        synchronized void tick() {
+            currentInstant = currentInstant.plusMillis(1);
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/2b960b10/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/UpdatableTickingClock.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/UpdatableTickingClock.java
b/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/UpdatableTickingClock.java
deleted file mode 100644
index cd22449..0000000
--- a/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/UpdatableTickingClock.java
+++ /dev/null
@@ -1,61 +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.queue.rabbitmq;
-
-import java.time.Clock;
-import java.time.Instant;
-import java.time.ZoneId;
-
-import org.apache.commons.lang3.NotImplementedException;
-
-public class UpdatableTickingClock extends Clock {
-    private Instant currentInstant;
-
-    public UpdatableTickingClock(Instant currentInstant) {
-        this.currentInstant = currentInstant;
-    }
-
-    public void setInstant(Instant instant) {
-        currentInstant = instant;
-    }
-
-    @Override
-    public ZoneId getZone() {
-        throw new NotImplementedException("No timezone attached to this clock");
-    }
-
-    @Override
-    public Clock withZone(ZoneId zone) {
-        throw new NotImplementedException("No timezone attached to this clock");
-    }
-
-    @Override
-    public synchronized Instant instant() {
-        try {
-            return currentInstant;
-        } finally {
-            tick();
-        }
-    }
-
-    private void tick() {
-        currentInstant = currentInstant.plusMillis(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