james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [2/9] james-project git commit: JAMES-2544 Slightly improve slicing tests
Date Tue, 02 Oct 2018 02:57:04 GMT
JAMES-2544 Slightly improve slicing tests


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

Branch: refs/heads/master
Commit: 272974218338721d88bf4edae5a2de68b24a680e
Parents: d165649
Author: Benoit Tellier <btellier@linagora.com>
Authored: Thu Sep 27 15:56:14 2018 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Tue Oct 2 09:19:57 2018 +0700

----------------------------------------------------------------------
 .../queue/rabbitmq/RabbitMQMailQueueTest.java   | 35 +++++++++++---------
 1 file changed, 20 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/27297421/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 f4e404f..7715d40 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
@@ -27,6 +27,7 @@ import java.time.Duration;
 import java.time.Instant;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ThreadLocalRandom;
+import java.util.function.Function;
 import java.util.stream.IntStream;
 import java.util.stream.Stream;
 
@@ -78,7 +79,7 @@ public class RabbitMQMailQueueTest implements ManageableMailQueueContract,
MailQ
     private static final Instant IN_SLICE_2 = IN_SLICE_1.plus(1, HOURS);
     private static final Instant IN_SLICE_3 = IN_SLICE_1.plus(2, HOURS);
     private static final Instant IN_SLICE_5 = IN_SLICE_1.plus(4, HOURS);
-    private static final Instant IN_SLICE_6 = IN_SLICE_1.plus(6, HOURS);
+    private static final Instant IN_SLICE_7 = IN_SLICE_1.plus(6, HOURS);
 
     @RegisterExtension
     static CassandraClusterExtension cassandraCluster = new CassandraClusterExtension(CassandraModule.aggregateModules(
@@ -139,18 +140,18 @@ public class RabbitMQMailQueueTest implements ManageableMailQueueContract,
MailQ
         int emailCount = 5;
 
         clock.setInstant(IN_SLICE_1);
-        enqueueMailsInSlice(1, emailCount);
+        enqueueSomeMails(namePatternForSlice(1), emailCount);
 
         clock.setInstant(IN_SLICE_2);
-        enqueueMailsInSlice(2, emailCount);
+        enqueueSomeMails(namePatternForSlice(2), emailCount);
 
         clock.setInstant(IN_SLICE_3);
-        enqueueMailsInSlice(3, emailCount);
+        enqueueSomeMails(namePatternForSlice(3), emailCount);
 
         clock.setInstant(IN_SLICE_5);
-        enqueueMailsInSlice(5, emailCount);
+        enqueueSomeMails(namePatternForSlice(5), emailCount);
 
-        clock.setInstant(IN_SLICE_6);
+        clock.setInstant(IN_SLICE_7);
         Stream<String> names = Iterators.toStream(mailQueue.browse())
             .map(ManageableMailQueue.MailQueueItemView::getMail)
             .map(Mail::getName);
@@ -168,18 +169,18 @@ public class RabbitMQMailQueueTest implements ManageableMailQueueContract,
MailQ
         int emailCount = 5;
 
         clock.setInstant(IN_SLICE_1);
-        enqueueMailsInSlice(1, emailCount);
+        enqueueSomeMails(namePatternForSlice(1), emailCount);
 
         clock.setInstant(IN_SLICE_2);
-        enqueueMailsInSlice(2, emailCount);
+        enqueueSomeMails(namePatternForSlice(2), emailCount);
 
         clock.setInstant(IN_SLICE_3);
-        enqueueMailsInSlice(3, emailCount);
+        enqueueSomeMails(namePatternForSlice(3), emailCount);
 
         clock.setInstant(IN_SLICE_5);
-        enqueueMailsInSlice(5, emailCount);
+        enqueueSomeMails(namePatternForSlice(5), emailCount);
 
-        clock.setInstant(IN_SLICE_6);
+        clock.setInstant(IN_SLICE_7);
         dequeueMails(5);
         dequeueMails(5);
         dequeueMails(3);
@@ -192,6 +193,10 @@ public class RabbitMQMailQueueTest implements ManageableMailQueueContract,
MailQ
             .containsExactly("3-4", "3-5", "5-1", "5-2", "5-3", "5-4", "5-5");
     }
 
+    private Function<Integer, String> namePatternForSlice(int sliceId) {
+        return i -> sliceId + "-" + i;
+    }
+
     @Test
     void mailQueueShouldBeInitializedWhenCreating(CassandraCluster cassandra) {
         String name = "myQueue";
@@ -205,13 +210,13 @@ public class RabbitMQMailQueueTest implements ManageableMailQueueContract,
MailQ
     @Override
     public void constructorShouldRegisterGetQueueSizeGauge(MailQueueMetricExtension.MailQueueMetricTestSystem
testSystem) {
     }
-    
-    private void enqueueMailsInSlice(int slice, int emailCount) {
+
+    private void enqueueSomeMails(Function<Integer, String> namePattern, int emailCount)
{
         ManageableMailQueue mailQueue = getManageableMailQueue();
 
         IntStream.rangeClosed(1, emailCount)
-            .forEach(Throwing.intConsumer(bucketId -> mailQueue.enQueue(defaultMail()
-                .name(slice + "-" + bucketId)
+            .forEach(Throwing.intConsumer(i -> mailQueue.enQueue(defaultMail()
+                .name(namePattern.apply(i))
                 .build())));
     }
 


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