james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [07/15] james-project git commit: JAMES-2090 Read configuration object from properties
Date Thu, 06 Jul 2017 12:13:13 GMT
JAMES-2090 Read configuration object 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/4695c7a7
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/4695c7a7
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/4695c7a7

Branch: refs/heads/master
Commit: 4695c7a7d55454561d6e36b2701cac1e03f83bec
Parents: 35ab6bd
Author: benwa <btellier@linagora.com>
Authored: Wed Jul 5 11:14:56 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Thu Jul 6 08:48:51 2017 +0700

----------------------------------------------------------------------
 .../cassandra/CassandraConfiguration.java       | 45 ++++++++++++++
 .../cassandra/utils/CassandraUtils.java         |  3 +
 .../modules/mailbox/CassandraSessionModule.java | 39 +++++++++++-
 .../mailbox/CassandraSessionModuleTest.java     | 65 ++++++++++++++++++++
 .../modules/mailbox/cassandra.properties        |  9 +++
 5 files changed, 160 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/4695c7a7/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/CassandraConfiguration.java
----------------------------------------------------------------------
diff --git a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/CassandraConfiguration.java
b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/CassandraConfiguration.java
index 3d985d4..ff3cad9 100644
--- a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/CassandraConfiguration.java
+++ b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/CassandraConfiguration.java
@@ -104,6 +104,51 @@ public class CassandraConfiguration {
             return this;
         }
 
+        public Builder messageReadChunkSize(Optional<Integer> value) {
+            value.ifPresent(this::messageReadChunkSize);
+            return this;
+        }
+
+        public Builder expungeChunkSize(Optional<Integer> value) {
+            value.ifPresent(this::expungeChunkSize);
+            return this;
+        }
+
+        public Builder flagsUpdateChunkSize(Optional<Integer> value) {
+            value.ifPresent(this::flagsUpdateChunkSize);
+            return this;
+        }
+
+        public Builder flagsUpdateMessageIdMaxRetry(Optional<Integer> value) {
+            value.ifPresent(this::flagsUpdateMessageIdMaxRetry);
+            return this;
+        }
+
+        public Builder flagsUpdateMessageMaxRetry(Optional<Integer> value) {
+            value.ifPresent(this::flagsUpdateMessageMaxRetry);
+            return this;
+        }
+
+        public Builder modSeqMaxRetry(Optional<Integer> value) {
+            value.ifPresent(this::modSeqMaxRetry);
+            return this;
+        }
+
+        public Builder uidMaxRetry(Optional<Integer> value) {
+            value.ifPresent(this::uidMaxRetry);
+            return this;
+        }
+
+        public Builder aclMaxRetry(Optional<Integer> value) {
+            value.ifPresent(this::aclMaxRetry);
+            return this;
+        }
+
+        public Builder fetchNextPageInAdvanceRow(Optional<Integer> value) {
+            value.ifPresent(this::fetchNextPageInAdvanceRow);
+            return this;
+        }
+
         public CassandraConfiguration build() {
             return new CassandraConfiguration(aclMaxRetry.orElse(DEFAULT_ACL_MAX_RETRY),
                 messageReadChunkSize.orElse(DEFAULT_MESSAGE_CHUNK_SIZE_ON_READ),

http://git-wip-us.apache.org/repos/asf/james-project/blob/4695c7a7/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/utils/CassandraUtils.java
----------------------------------------------------------------------
diff --git a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/utils/CassandraUtils.java
b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/utils/CassandraUtils.java
index adef1c0..c224b57 100644
--- a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/utils/CassandraUtils.java
+++ b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/utils/CassandraUtils.java
@@ -22,6 +22,8 @@ package org.apache.james.backends.cassandra.utils;
 import java.util.stream.Stream;
 import java.util.stream.StreamSupport;
 
+import javax.inject.Inject;
+
 import org.apache.james.backends.cassandra.CassandraConfiguration;
 
 import com.datastax.driver.core.ResultSet;
@@ -33,6 +35,7 @@ public class CassandraUtils {
 
     private final CassandraConfiguration cassandraConfiguration;
 
+    @Inject
     public CassandraUtils(CassandraConfiguration cassandraConfiguration) {
         this.cassandraConfiguration = cassandraConfiguration;
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/4695c7a7/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java
b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java
index f20aa98..9b4806f 100644
--- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java
+++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java
@@ -54,6 +54,7 @@ import com.datastax.driver.core.QueryLogger;
 import com.datastax.driver.core.Session;
 import com.datastax.driver.core.exceptions.NoHostAvailableException;
 import com.github.steveash.guavate.Guavate;
+import com.google.common.annotations.VisibleForTesting;
 import com.google.inject.AbstractModule;
 import com.google.inject.Provides;
 import com.google.inject.Scopes;
@@ -76,11 +77,19 @@ public class CassandraSessionModule extends AbstractModule {
     private static final int DEFAULT_READ_TIMEOUT_MILLIS = 5000;
     private static final int DEFAULT_CONNECT_TIMEOUT_MILLIS = 5000;
     private static final String BATCHSIZES_FILE_NAME = "batchsizes";
+    private static final String MAILBOX_MAX_RETRY_ACL = "mailbox.max.retry.acl";
+    private static final String MAILBOX_MAX_RETRY_MODSEQ = "mailbox.max.retry.modseq";
+    private static final String MAILBOX_MAX_RETRY_UID = "mailbox.max.retry.uid";
+    private static final String MAILBOX_MAX_RETRY_MESSAGE_FLAGS_UPDATE = "mailbox.max.retry.message.flags.update";
+    private static final String MAILBOX_MAX_RETRY_MESSAGE_ID_FLAGS_UPDATE = "mailbox.max.retry.message.id.flags.update";
+    private static final String FETCH_ADVANCE_ROW_COUNT = "fetch.advance.row.count";
+    private static final String CHUNK_SIZE_FLAGS_UPDATE = "chunk.size.flags.update";
+    private static final String CHUNK_SIZE_MESSAGE_READ = "chunk.size.message.read";
+    private static final String CHUNK_SIZE_EXPUNGE = "chunk.size.expunge";
 
     @Override
     protected void configure() {
         bind(ScheduledExecutorService.class).toProvider(ScheduledExecutorServiceProvider.class);
-        bind(CassandraConfiguration.class).toInstance(CassandraConfiguration.DEFAULT_CONFIGURATION);
         bind(CassandraUtils.class).in(Scopes.SINGLETON);
 
         Multibinder<CassandraModule> cassandraDataDefinitions = Multibinder.newSetBinder(binder(),
CassandraModule.class);
@@ -243,6 +252,34 @@ public class CassandraSessionModule extends AbstractModule {
         return new AsyncRetryExecutor(scheduler);
     }
 
+    @VisibleForTesting
+    @Provides
+    @Singleton
+    CassandraConfiguration provideCassandraConfiguration(CassandraSessionConfiguration sessionConfiguration)
throws ConfigurationException {
+        PropertiesConfiguration propertiesConfiguration = sessionConfiguration.getConfiguration();
+
+        return CassandraConfiguration.builder()
+            .aclMaxRetry(Optional.ofNullable(
+                propertiesConfiguration.getInteger(MAILBOX_MAX_RETRY_ACL, null)))
+            .modSeqMaxRetry(Optional.ofNullable(
+                propertiesConfiguration.getInteger(MAILBOX_MAX_RETRY_MODSEQ, null)))
+            .uidMaxRetry(Optional.ofNullable(
+                propertiesConfiguration.getInteger(MAILBOX_MAX_RETRY_UID, null)))
+            .flagsUpdateMessageMaxRetry(Optional.ofNullable(
+                propertiesConfiguration.getInteger(MAILBOX_MAX_RETRY_MESSAGE_FLAGS_UPDATE,
null)))
+            .flagsUpdateMessageIdMaxRetry(Optional.ofNullable(
+                propertiesConfiguration.getInteger(MAILBOX_MAX_RETRY_MESSAGE_ID_FLAGS_UPDATE,
null)))
+            .fetchNextPageInAdvanceRow(Optional.ofNullable(
+                propertiesConfiguration.getInteger(FETCH_ADVANCE_ROW_COUNT, null)))
+            .flagsUpdateChunkSize(Optional.ofNullable(
+                propertiesConfiguration.getInteger(CHUNK_SIZE_FLAGS_UPDATE, null)))
+            .messageReadChunkSize(Optional.ofNullable(
+                propertiesConfiguration.getInteger(CHUNK_SIZE_MESSAGE_READ, null)))
+            .expungeChunkSize(Optional.ofNullable(
+                propertiesConfiguration.getInteger(CHUNK_SIZE_EXPUNGE, null)))
+            .build();
+    }
+
     private PropertiesConfiguration getConfiguration(PropertiesProvider propertiesProvider)
throws ConfigurationException {
         try {
             return propertiesProvider.getConfiguration("cassandra");

http://git-wip-us.apache.org/repos/asf/james-project/blob/4695c7a7/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/CassandraSessionModuleTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/CassandraSessionModuleTest.java
b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/CassandraSessionModuleTest.java
new file mode 100644
index 0000000..893f76d
--- /dev/null
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/CassandraSessionModuleTest.java
@@ -0,0 +1,65 @@
+/****************************************************************
+ * 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.modules.mailbox;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.james.backends.cassandra.CassandraConfiguration;
+import org.junit.Before;
+import org.junit.Test;
+
+public class CassandraSessionModuleTest {
+
+    private CassandraSessionModule cassandraSessionModule;
+
+    @Before
+    public void setUp() {
+        cassandraSessionModule = new CassandraSessionModule();
+    }
+
+    @Test
+    public void provideCassandraConfigurationShouldReturnDefaultOnEmptyConfigurationFile()
throws ConfigurationException {
+        CassandraConfiguration configuration = cassandraSessionModule.provideCassandraConfiguration(PropertiesConfiguration::new);
+
+        assertThat(configuration).isEqualTo(CassandraConfiguration.DEFAULT_CONFIGURATION);
+    }
+
+    @Test
+    public void provideCassandraConfigurationShouldReturnRightConfigurationFile() throws
ConfigurationException {
+        CassandraConfiguration configuration = cassandraSessionModule.provideCassandraConfiguration(
+            () -> new PropertiesConfiguration(ClassLoader.getSystemResource("modules/mailbox/cassandra.properties")));
+
+        assertThat(configuration)
+            .isEqualTo(CassandraConfiguration.builder()
+                .aclMaxRetry(1)
+                .modSeqMaxRetry(2)
+                .uidMaxRetry(3)
+                .flagsUpdateMessageMaxRetry(4)
+                .flagsUpdateMessageIdMaxRetry(5)
+                .fetchNextPageInAdvanceRow(6)
+                .flagsUpdateChunkSize(7)
+                .messageReadChunkSize(8)
+                .expungeChunkSize(9)
+                .build());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/4695c7a7/server/container/guice/cassandra-guice/src/test/resources/modules/mailbox/cassandra.properties
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/resources/modules/mailbox/cassandra.properties
b/server/container/guice/cassandra-guice/src/test/resources/modules/mailbox/cassandra.properties
new file mode 100644
index 0000000..217be79
--- /dev/null
+++ b/server/container/guice/cassandra-guice/src/test/resources/modules/mailbox/cassandra.properties
@@ -0,0 +1,9 @@
+mailbox.max.retry.acl=1
+mailbox.max.retry.modseq=2
+mailbox.max.retry.uid=3
+mailbox.max.retry.message.flags.update=4
+mailbox.max.retry.message.id.flags.update=5
+fetch.advance.row.count=6
+chunk.size.flags.update=7
+chunk.size.message.read=8
+chunk.size.expunge=9


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