james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [1/7] james-project git commit: JAMES-2537 Read CassandraMailQueueViewConfiguration from properties
Date Thu, 22 Nov 2018 10:51:34 GMT
Repository: james-project
Updated Branches:
  refs/heads/master 134b0c533 -> a966c5e7e


JAMES-2537 Read CassandraMailQueueViewConfiguration from properties


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

Branch: refs/heads/master
Commit: 8f9a99039b2ca21b1cd530e069a2c6dfc13cbb7b
Parents: 134b0c5
Author: Benoit Tellier <btellier@linagora.com>
Authored: Thu Nov 22 11:28:27 2018 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Thu Nov 22 11:28:27 2018 +0700

----------------------------------------------------------------------
 .../CassandraMailQueueViewConfiguration.java    | 33 +++++++++++++++
 ...CassandraMailQueueViewConfigurationTest.java | 42 ++++++++++++++++++++
 2 files changed, 75 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/8f9a9903/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/configuration/CassandraMailQueueViewConfiguration.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/configuration/CassandraMailQueueViewConfiguration.java
b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/configuration/CassandraMailQueueViewConfiguration.java
index 46b1f4b..14d08c7 100644
--- a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/configuration/CassandraMailQueueViewConfiguration.java
+++ b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/configuration/CassandraMailQueueViewConfiguration.java
@@ -21,11 +21,16 @@ package org.apache.james.queue.rabbitmq.view.cassandra.configuration;
 
 import java.time.Duration;
 import java.util.Objects;
+import java.util.Optional;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.james.util.TimeConverter;
 
 import com.google.common.base.MoreObjects;
 import com.google.common.base.Preconditions;
 
 public class CassandraMailQueueViewConfiguration {
+
     interface Builder {
         @FunctionalInterface
         interface RequireBucketCount {
@@ -67,6 +72,34 @@ public class CassandraMailQueueViewConfiguration {
         return bucketCount -> updateBrowseStartPace -> sliceWindow -> new Builder.ReadyToBuild(bucketCount,
updateBrowseStartPace, sliceWindow);
     }
 
+    public static int DEFAULT_BUCKET_COUNT = 1;
+    public static Duration DEFAULT_SLICE_WINDOW = Duration.ofHours(1);
+    public static int DEFAULT_UPDATE_BROWSE_START_PACE = 1000;
+    public static CassandraMailQueueViewConfiguration DEFAULT = builder()
+        .bucketCount(DEFAULT_BUCKET_COUNT)
+        .updateBrowseStartPace(DEFAULT_UPDATE_BROWSE_START_PACE)
+        .sliceWindow(DEFAULT_SLICE_WINDOW)
+        .build();
+
+    public static final String BUCKET_COUNT_PROPERTY = "mailqueue.view.bucketCount";
+    public static final String UPDATE_BROWSE_START_PACE_PROPERTY = "mailqueue.view.updateBrowseStartPace";
+    public static final String SLICE_WINDOW_PROPERTY = "mailqueue.view.sliceWindow";
+
+    public static CassandraMailQueueViewConfiguration from(Configuration configuration) {
+        int bucketCount = configuration.getInteger(BUCKET_COUNT_PROPERTY, DEFAULT_BUCKET_COUNT);
+        int updateBrowseStartPace = configuration.getInteger(UPDATE_BROWSE_START_PACE_PROPERTY,
DEFAULT_UPDATE_BROWSE_START_PACE);
+        Optional<String> sliceWindowAsString = Optional.ofNullable(configuration.getString(SLICE_WINDOW_PROPERTY,
null));
+
+        return builder()
+            .bucketCount(bucketCount)
+            .updateBrowseStartPace(updateBrowseStartPace)
+            .sliceWindow(sliceWindowAsString
+                .map(TimeConverter::getMilliSeconds)
+                .map(Duration::ofMillis)
+                .orElse(DEFAULT_SLICE_WINDOW))
+            .build();
+    }
+
     private final int bucketCount;
     private final int updateBrowseStartPace;
     private final Duration sliceWindow;

http://git-wip-us.apache.org/repos/asf/james-project/blob/8f9a9903/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/view/cassandra/configuration/CassandraMailQueueViewConfigurationTest.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/view/cassandra/configuration/CassandraMailQueueViewConfigurationTest.java
b/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/view/cassandra/configuration/CassandraMailQueueViewConfigurationTest.java
index f397305..fe4afc3 100644
--- a/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/view/cassandra/configuration/CassandraMailQueueViewConfigurationTest.java
+++ b/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/view/cassandra/configuration/CassandraMailQueueViewConfigurationTest.java
@@ -19,11 +19,14 @@
 
 package org.apache.james.queue.rabbitmq.view.cassandra.configuration;
 
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatCode;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import java.time.Duration;
 
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.junit.jupiter.api.Nested;
 import org.junit.jupiter.api.Test;
 
 import nl.jqno.equalsverifier.EqualsVerifier;
@@ -113,4 +116,43 @@ class CassandraMailQueueViewConfigurationTest {
                 .build()))
             .isInstanceOf(IllegalArgumentException.class);
     }
+
+    @Nested
+    class FromConfiguration {
+        @Test
+        void fromShouldReturnDefaultForEmptyConfiguration() {
+            CassandraMailQueueViewConfiguration actual = CassandraMailQueueViewConfiguration.from(new
PropertiesConfiguration());
+
+            assertThat(actual)
+                .isEqualTo(CassandraMailQueueViewConfiguration.DEFAULT);
+        }
+
+        @Test
+        void fromShouldReturnConfiguredBucketCount() {
+            PropertiesConfiguration configuration = new PropertiesConfiguration();
+            configuration.addProperty(CassandraMailQueueViewConfiguration.BUCKET_COUNT_PROPERTY,
"8");
+            CassandraMailQueueViewConfiguration actual = CassandraMailQueueViewConfiguration.from(configuration);
+
+            assertThat(actual.getBucketCount()).isEqualTo(8);
+        }
+
+        @Test
+        void fromShouldReturnConfiguredUpdateBrowseStartPace() {
+            PropertiesConfiguration configuration = new PropertiesConfiguration();
+            configuration.addProperty(CassandraMailQueueViewConfiguration.UPDATE_BROWSE_START_PACE_PROPERTY,
"100");
+            CassandraMailQueueViewConfiguration actual = CassandraMailQueueViewConfiguration.from(configuration);
+
+            assertThat(actual.getUpdateBrowseStartPace()).isEqualTo(100);
+        }
+
+        @Test
+        void fromShouldReturnConfiguredSliceWindow() {
+            PropertiesConfiguration configuration = new PropertiesConfiguration();
+            configuration.addProperty(CassandraMailQueueViewConfiguration.SLICE_WINDOW_PROPERTY,
"20min");
+            CassandraMailQueueViewConfiguration actual = CassandraMailQueueViewConfiguration.from(configuration);
+
+            assertThat(actual.getSliceWindow()).isEqualTo(Duration.ofMinutes(20));
+        }
+    }
+
 }
\ 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


Mime
View raw message