You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2018/05/28 01:06:11 UTC
[01/13] james-project git commit: JAMES-2403 Introduce
QuotaRatioMappingFactory
Repository: james-project
Updated Branches:
refs/heads/master 99549a88e -> f8b587a7a
JAMES-2403 Introduce QuotaRatioMappingFactory
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/74b87be4
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/74b87be4
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/74b87be4
Branch: refs/heads/master
Commit: 74b87be45d2554768c4d239bc117a823fb2e17a2
Parents: 251def1
Author: Antoine Duprat <ad...@linagora.com>
Authored: Tue May 22 15:41:53 2018 +0200
Committer: benwa <bt...@linagora.com>
Committed: Mon May 28 08:04:11 2018 +0700
----------------------------------------------------------------------
.../james/backends/es/NodeMappingFactory.java | 1 +
.../plugin/quota-search-elasticsearch/pom.xml | 44 +++++++++++++
.../QuotaRatioElasticSearchConstants.java | 36 +++++++++++
.../elasticsearch/QuotaRatioMappingFactory.java | 67 ++++++++++++++++++++
.../json/JsonMessageConstants.java | 28 ++++++++
mailbox/pom.xml | 1 +
6 files changed, 177 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/74b87be4/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/NodeMappingFactory.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/NodeMappingFactory.java b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/NodeMappingFactory.java
index e72ac1d..36db27e 100644
--- a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/NodeMappingFactory.java
+++ b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/NodeMappingFactory.java
@@ -28,6 +28,7 @@ public class NodeMappingFactory {
public static final String BOOLEAN = "boolean";
public static final String TYPE = "type";
public static final String LONG = "long";
+ public static final String DOUBLE = "double";
public static final String INDEX = "index";
public static final String NOT_ANALYZED = "not_analyzed";
public static final String STRING = "string";
http://git-wip-us.apache.org/repos/asf/james-project/blob/74b87be4/mailbox/plugin/quota-search-elasticsearch/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/pom.xml b/mailbox/plugin/quota-search-elasticsearch/pom.xml
new file mode 100644
index 0000000..1aa3cc0
--- /dev/null
+++ b/mailbox/plugin/quota-search-elasticsearch/pom.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <artifactId>apache-james-mailbox</artifactId>
+ <groupId>org.apache.james</groupId>
+ <version>3.1.0-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>apache-james-mailbox-quota-search-elasticsearch</artifactId>
+ <name>Apache James :: Mailbox :: Plugin :: Quota Search :: ElasticSearcj</name>
+ <description>Apache James Mailbox ElasticSearch implementation for quota search</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>apache-james-backends-es</artifactId>
+ </dependency>
+ </dependencies>
+
+
+</project>
http://git-wip-us.apache.org/repos/asf/james-project/blob/74b87be4/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaRatioElasticSearchConstants.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaRatioElasticSearchConstants.java b/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaRatioElasticSearchConstants.java
new file mode 100644
index 0000000..d2db3a0
--- /dev/null
+++ b/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaRatioElasticSearchConstants.java
@@ -0,0 +1,36 @@
+/****************************************************************
+ * 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.quota.search.elasticsearch;
+
+import org.apache.james.backends.es.AliasName;
+import org.apache.james.backends.es.IndexName;
+import org.apache.james.backends.es.TypeName;
+
+public interface QuotaRatioElasticSearchConstants {
+
+ interface InjectionNames {
+ String QUOTA_RATIO = "quotaRatio";
+ }
+
+ AliasName DEFAULT_QUOTA_RATIO_WRITE_ALIAS = new AliasName("quotaRatioWriteAlias");
+ AliasName DEFAULT_QUOTA_RATIO_READ_ALIAS = new AliasName("quotaRatioReadAlias");
+ IndexName DEFAULT_QUOTA_RATIO_INDEX = new IndexName("quota_ratio_v1");
+ TypeName QUOTA_RATIO_TYPE = new TypeName("quotaRatio");
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/74b87be4/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaRatioMappingFactory.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaRatioMappingFactory.java b/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaRatioMappingFactory.java
new file mode 100644
index 0000000..128f1d1
--- /dev/null
+++ b/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaRatioMappingFactory.java
@@ -0,0 +1,67 @@
+/****************************************************************
+ * 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.quota.search.elasticsearch;
+
+import static org.apache.james.backends.es.NodeMappingFactory.DOUBLE;
+import static org.apache.james.backends.es.NodeMappingFactory.INDEX;
+import static org.apache.james.backends.es.NodeMappingFactory.NOT_ANALYZED;
+import static org.apache.james.backends.es.NodeMappingFactory.PROPERTIES;
+import static org.apache.james.backends.es.NodeMappingFactory.STRING;
+import static org.apache.james.backends.es.NodeMappingFactory.TYPE;
+import static org.apache.james.quota.search.elasticsearch.json.JsonMessageConstants.DOMAIN;
+import static org.apache.james.quota.search.elasticsearch.json.JsonMessageConstants.QUOTA_RATIO;
+import static org.apache.james.quota.search.elasticsearch.json.JsonMessageConstants.USER;
+import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
+
+import java.io.IOException;
+
+import org.elasticsearch.common.xcontent.XContentBuilder;
+
+public class QuotaRatioMappingFactory {
+
+ public static XContentBuilder getMappingContent() {
+ try {
+ return jsonBuilder()
+ .startObject()
+
+ .startObject(QuotaRatioElasticSearchConstants.QUOTA_RATIO_TYPE.getValue())
+ .startObject(PROPERTIES)
+
+ .startObject(USER)
+ .field(TYPE, STRING)
+ .field(INDEX, NOT_ANALYZED)
+ .endObject()
+
+ .startObject(DOMAIN)
+ .field(TYPE, STRING)
+ .field(INDEX, NOT_ANALYZED)
+ .endObject()
+
+ .startObject(QUOTA_RATIO)
+ .field(TYPE, DOUBLE)
+ .endObject()
+ .endObject()
+ .endObject()
+ .endObject();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/74b87be4/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/json/JsonMessageConstants.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/json/JsonMessageConstants.java b/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/json/JsonMessageConstants.java
new file mode 100644
index 0000000..8f930ff
--- /dev/null
+++ b/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/json/JsonMessageConstants.java
@@ -0,0 +1,28 @@
+/****************************************************************
+ * 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.quota.search.elasticsearch.json;
+
+public interface JsonMessageConstants {
+
+ String USER = "user";
+ String DOMAIN = "domain";
+ String QUOTA_RATIO = "quotaRatio";
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/74b87be4/mailbox/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/pom.xml b/mailbox/pom.xml
index 4db6033..2fa50dd 100644
--- a/mailbox/pom.xml
+++ b/mailbox/pom.xml
@@ -57,6 +57,7 @@
<module>plugin/quota-mailing-cassandra</module>
<module>plugin/quota-mailing-memory</module>
<module>plugin/quota-search</module>
+ <module>plugin/quota-search-elasticsearch</module>
<module>plugin/quota-search-scanning</module>
<module>plugin/spamassassin</module>
</modules>
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[03/13] james-project git commit: JAMES-2403 Fix Eclipse warnings
Posted by bt...@apache.org.
JAMES-2403 Fix Eclipse warnings
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/74b6d80b
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/74b6d80b
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/74b6d80b
Branch: refs/heads/master
Commit: 74b6d80b51c4b97f2bb54258c14d7d08f5ac9827
Parents: 99549a8
Author: Raphael Ouazana <ra...@linagora.com>
Authored: Tue May 22 15:53:43 2018 +0200
Committer: benwa <bt...@linagora.com>
Committed: Mon May 28 08:04:11 2018 +0700
----------------------------------------------------------------------
.../test/java/org/apache/james/util/TimeConverterTest.java | 8 ++++----
.../apache/james/webadmin/routes/MailQueueRoutesTest.java | 2 +-
2 files changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/74b6d80b/server/container/util/src/test/java/org/apache/james/util/TimeConverterTest.java
----------------------------------------------------------------------
diff --git a/server/container/util/src/test/java/org/apache/james/util/TimeConverterTest.java b/server/container/util/src/test/java/org/apache/james/util/TimeConverterTest.java
index 9c52e11..2a826c1 100644
--- a/server/container/util/src/test/java/org/apache/james/util/TimeConverterTest.java
+++ b/server/container/util/src/test/java/org/apache/james/util/TimeConverterTest.java
@@ -39,21 +39,21 @@ public class TimeConverterTest {
@Test
public void getMilliSecondsShouldUseProvidedUnitWhenNoUnitAmountAsString() {
//Given
- long expected = 2;
+ long expected = 2000;
//When
long actual = TimeConverter.getMilliSeconds("2", TimeConverter.Unit.SECONDS);
//Then
- assertThat(actual).isEqualTo(2000);
+ assertThat(actual).isEqualTo(expected);
}
@Test
public void getMilliSecondsShouldNotUseProvidedUnitWhenNoUnitAmountAsString() {
//Given
- long expected = 2;
+ long expected = 120000;
//When
long actual = TimeConverter.getMilliSeconds("2 minutes", TimeConverter.Unit.SECONDS);
//Then
- assertThat(actual).isEqualTo(120000);
+ assertThat(actual).isEqualTo(expected);
}
@Test
http://git-wip-us.apache.org/repos/asf/james-project/blob/74b6d80b/server/protocols/webadmin/webadmin-mailqueue/src/test/java/org/apache/james/webadmin/routes/MailQueueRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailqueue/src/test/java/org/apache/james/webadmin/routes/MailQueueRoutesTest.java b/server/protocols/webadmin/webadmin-mailqueue/src/test/java/org/apache/james/webadmin/routes/MailQueueRoutesTest.java
index 3add507..3cfaef9 100644
--- a/server/protocols/webadmin/webadmin-mailqueue/src/test/java/org/apache/james/webadmin/routes/MailQueueRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-mailqueue/src/test/java/org/apache/james/webadmin/routes/MailQueueRoutesTest.java
@@ -602,7 +602,7 @@ public class MailQueueRoutesTest {
class HttpBodies {
@Test
- public void deleteMailsTasksShouldCompleteWhenSenderIsValid() throws Exception{
+ public void deleteMailsTasksShouldCompleteWhenSenderIsValid() throws Exception {
mailQueueFactory.createQueue(FIRST_QUEUE);
String taskId = with()
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[12/13] james-project git commit: JAMES-2403 Correct method
visibility in ScanningQuotaSearcher
Posted by bt...@apache.org.
JAMES-2403 Correct method visibility in ScanningQuotaSearcher
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/95c44232
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/95c44232
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/95c44232
Branch: refs/heads/master
Commit: 95c44232b33c14c8de2481ad6087a6e1ba7d3ad3
Parents: 35b7ec7
Author: benwa <bt...@linagora.com>
Authored: Thu May 24 11:57:03 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Mon May 28 08:05:35 2018 +0700
----------------------------------------------------------------------
.../james/quota/search/scanning/ClauseConverter.java | 12 ++++++------
.../quota/search/scanning/ScanningQuotaSearcher.java | 4 ++--
2 files changed, 8 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/95c44232/mailbox/plugin/quota-search-scanning/src/main/java/org/apache/james/quota/search/scanning/ClauseConverter.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-scanning/src/main/java/org/apache/james/quota/search/scanning/ClauseConverter.java b/mailbox/plugin/quota-search-scanning/src/main/java/org/apache/james/quota/search/scanning/ClauseConverter.java
index 43e158c..f1d9035 100644
--- a/mailbox/plugin/quota-search-scanning/src/main/java/org/apache/james/quota/search/scanning/ClauseConverter.java
+++ b/mailbox/plugin/quota-search-scanning/src/main/java/org/apache/james/quota/search/scanning/ClauseConverter.java
@@ -62,34 +62,34 @@ public class ClauseConverter {
.orElse(user -> true);
}
- public Predicate<User> toPredicate(QuotaClause clause) {
+ private Predicate<User> toPredicate(QuotaClause clause) {
return toPredicates.get(clause.getClass())
.apply(clause);
}
- public Predicate<User> moreThanToPredicate(QuotaClause clause) {
+ private Predicate<User> moreThanToPredicate(QuotaClause clause) {
QuotaClause.MoreThan moreThan = (QuotaClause.MoreThan) clause;
return user -> retrieveUserRatio(user) >= moreThan.getQuotaBoundary().getRatio();
}
- public Predicate<User> lessThanToPredicate(QuotaClause clause) {
+ private Predicate<User> lessThanToPredicate(QuotaClause clause) {
QuotaClause.LessThan lessThan = (QuotaClause.LessThan) clause;
return user -> retrieveUserRatio(user) <= lessThan.getQuotaBoundary().getRatio();
}
- public Predicate<User> hasDomainToPredicate(QuotaClause clause) {
+ private Predicate<User> hasDomainToPredicate(QuotaClause clause) {
QuotaClause.HasDomain hasDomain = (QuotaClause.HasDomain) clause;
return user -> user.getDomainPart()
.map(hasDomain.getDomain()::equals)
.orElse(false);
}
- public Predicate<User> andToPredicate(QuotaClause clause) {
+ private Predicate<User> andToPredicate(QuotaClause clause) {
QuotaClause.And and = (QuotaClause.And) clause;
return andToPredicate(and);
}
- public double retrieveUserRatio(User user) {
+ private double retrieveUserRatio(User user) {
try {
QuotaRoot quotaRoot = quotaRootResolver.forUser(user);
Quota<QuotaSize> storageQuota = quotaManager.getStorageQuota(quotaRoot);
http://git-wip-us.apache.org/repos/asf/james-project/blob/95c44232/mailbox/plugin/quota-search-scanning/src/main/java/org/apache/james/quota/search/scanning/ScanningQuotaSearcher.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-scanning/src/main/java/org/apache/james/quota/search/scanning/ScanningQuotaSearcher.java b/mailbox/plugin/quota-search-scanning/src/main/java/org/apache/james/quota/search/scanning/ScanningQuotaSearcher.java
index 8d388d0..9aaf2c2 100644
--- a/mailbox/plugin/quota-search-scanning/src/main/java/org/apache/james/quota/search/scanning/ScanningQuotaSearcher.java
+++ b/mailbox/plugin/quota-search-scanning/src/main/java/org/apache/james/quota/search/scanning/ScanningQuotaSearcher.java
@@ -58,13 +58,13 @@ public class ScanningQuotaSearcher implements QuotaSearcher {
.collect(Guavate.toImmutableList());
}
- public Stream<User> limit(Stream<User> results, Limit limit) {
+ private Stream<User> limit(Stream<User> results, Limit limit) {
return limit.getValue()
.map(results::limit)
.orElse(results);
}
- public Iterator<String> listUsers() {
+ private Iterator<String> listUsers() {
try {
return usersRepository.list();
} catch (UsersRepositoryException e) {
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[06/13] james-project git commit: JAMES-2403 Convert
QuotaRatioToElasticSearchJson to Json
Posted by bt...@apache.org.
JAMES-2403 Convert QuotaRatioToElasticSearchJson to Json
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/86f192c7
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/86f192c7
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/86f192c7
Branch: refs/heads/master
Commit: 86f192c7c9c5b3cd178f5ec14a2644fc01c257b5
Parents: b28fdf9
Author: Antoine Duprat <ad...@linagora.com>
Authored: Wed May 23 14:10:41 2018 +0200
Committer: benwa <bt...@linagora.com>
Committed: Mon May 28 08:05:35 2018 +0700
----------------------------------------------------------------------
.../plugin/quota-search-elasticsearch/pom.xml | 15 ++++
.../json/QuotaRatioToElasticSearchJson.java | 50 +++++++++++++
.../json/QuotaRatioToElasticSearchJsonTest.java | 75 ++++++++++++++++++++
.../src/test/resources/quotaRatio.json | 1 +
.../src/test/resources/quotaRatioNoDomain.json | 1 +
5 files changed, 142 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/86f192c7/mailbox/plugin/quota-search-elasticsearch/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/pom.xml b/mailbox/plugin/quota-search-elasticsearch/pom.xml
index 2cd0d2f..32b9f2f 100644
--- a/mailbox/plugin/quota-search-elasticsearch/pom.xml
+++ b/mailbox/plugin/quota-search-elasticsearch/pom.xml
@@ -39,6 +39,16 @@
<artifactId>apache-james-backends-es</artifactId>
</dependency>
<dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>apache-james-mailbox-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>apache-james-mailbox-api</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
@@ -66,6 +76,11 @@
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>net.javacrumbs.json-unit</groupId>
+ <artifactId>json-unit-fluent</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
http://git-wip-us.apache.org/repos/asf/james-project/blob/86f192c7/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioToElasticSearchJson.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioToElasticSearchJson.java b/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioToElasticSearchJson.java
new file mode 100644
index 0000000..ad8f975
--- /dev/null
+++ b/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioToElasticSearchJson.java
@@ -0,0 +1,50 @@
+/****************************************************************
+ * 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.quota.search.elasticsearch.json;
+
+import javax.inject.Inject;
+
+import org.apache.james.core.Domain;
+import org.apache.james.mailbox.MailboxListener.QuotaUsageUpdatedEvent;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
+
+public class QuotaRatioToElasticSearchJson {
+
+ private final ObjectMapper mapper;
+
+ @Inject
+ public QuotaRatioToElasticSearchJson() {
+ this.mapper = new ObjectMapper();
+ this.mapper.registerModule(new Jdk8Module());
+ }
+
+ public String convertToJson(String user, QuotaUsageUpdatedEvent event) throws JsonProcessingException {
+ return mapper.writeValueAsString(QuotaRatioAsJson.builder()
+ .user(user)
+ .domain(event.getQuotaRoot().getDomain().map(Domain::asString))
+ .quotaRatio(Math.max(
+ event.getCountQuota().getRatio(),
+ event.getSizeQuota().getRatio()))
+ .build());
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/86f192c7/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioToElasticSearchJsonTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioToElasticSearchJsonTest.java b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioToElasticSearchJsonTest.java
new file mode 100644
index 0000000..cdd618e
--- /dev/null
+++ b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioToElasticSearchJsonTest.java
@@ -0,0 +1,75 @@
+/****************************************************************
+ * 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.quota.search.elasticsearch.json;
+
+import static net.javacrumbs.jsonunit.core.Option.IGNORING_ARRAY_ORDER;
+import static net.javacrumbs.jsonunit.fluent.JsonFluentAssert.assertThatJson;
+
+import java.io.IOException;
+import java.time.Instant;
+import java.util.Optional;
+
+import org.apache.james.core.Domain;
+import org.apache.james.mailbox.MailboxListener.QuotaUsageUpdatedEvent;
+import org.apache.james.mailbox.mock.MockMailboxSession;
+import org.apache.james.mailbox.model.QuotaRoot;
+import org.apache.james.mailbox.quota.QuotaFixture;
+import org.apache.james.util.ClassLoaderUtils;
+import org.junit.jupiter.api.Test;
+
+public class QuotaRatioToElasticSearchJsonTest {
+
+ @Test
+ public void quotaRatioShouldBeWellConvertedToJson() throws IOException {
+ String user = "user@domain.org";
+ QuotaUsageUpdatedEvent event = new QuotaUsageUpdatedEvent(
+ new MockMailboxSession(user),
+ QuotaRoot.quotaRoot("any", Optional.of(Domain.of("domain.org"))),
+ QuotaFixture.Counts._52_PERCENT,
+ QuotaFixture.Sizes._55_PERCENT,
+ Instant.now());
+
+
+ QuotaRatioToElasticSearchJson quotaRatioToElasticSearchJson = new QuotaRatioToElasticSearchJson();
+ String convertToJson = quotaRatioToElasticSearchJson.convertToJson(user, event);
+
+ assertThatJson(convertToJson)
+ .when(IGNORING_ARRAY_ORDER)
+ .isEqualTo(ClassLoaderUtils.getSystemResourceAsString("quotaRatio.json"));
+ }
+
+ @Test
+ public void quotaRatioShouldBeWellConvertedToJsonWhenNoDomain() throws IOException {
+ String user = "user";
+ QuotaUsageUpdatedEvent event = new QuotaUsageUpdatedEvent(
+ new MockMailboxSession(user),
+ QuotaRoot.quotaRoot("any", Optional.empty()),
+ QuotaFixture.Counts._52_PERCENT,
+ QuotaFixture.Sizes._55_PERCENT,
+ Instant.now());
+
+
+ QuotaRatioToElasticSearchJson quotaRatioToElasticSearchJson = new QuotaRatioToElasticSearchJson();
+ String convertToJson = quotaRatioToElasticSearchJson.convertToJson(user, event);
+
+ assertThatJson(convertToJson)
+ .when(IGNORING_ARRAY_ORDER)
+ .isEqualTo(ClassLoaderUtils.getSystemResourceAsString("quotaRatioNoDomain.json"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/86f192c7/mailbox/plugin/quota-search-elasticsearch/src/test/resources/quotaRatio.json
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/src/test/resources/quotaRatio.json b/mailbox/plugin/quota-search-elasticsearch/src/test/resources/quotaRatio.json
new file mode 100644
index 0000000..8b39489
--- /dev/null
+++ b/mailbox/plugin/quota-search-elasticsearch/src/test/resources/quotaRatio.json
@@ -0,0 +1 @@
+{"user":"user@domain.org","domain":"domain.org","quotaRatio":0.55}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/86f192c7/mailbox/plugin/quota-search-elasticsearch/src/test/resources/quotaRatioNoDomain.json
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/src/test/resources/quotaRatioNoDomain.json b/mailbox/plugin/quota-search-elasticsearch/src/test/resources/quotaRatioNoDomain.json
new file mode 100644
index 0000000..b3e2f2e
--- /dev/null
+++ b/mailbox/plugin/quota-search-elasticsearch/src/test/resources/quotaRatioNoDomain.json
@@ -0,0 +1 @@
+{"user":"user","domain":null,"quotaRatio":0.55}
\ 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
[04/13] james-project git commit: JAMES-2403 Fix typo in
QuotaClauseTest
Posted by bt...@apache.org.
JAMES-2403 Fix typo in QuotaClauseTest
QuotaClauseTest should not implement QuotaClause...
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/251def19
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/251def19
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/251def19
Branch: refs/heads/master
Commit: 251def193bae5352eab4d43e71598f1f93f0967b
Parents: a0da5c1
Author: Raphael Ouazana <ra...@linagora.com>
Authored: Wed May 23 17:15:02 2018 +0200
Committer: benwa <bt...@linagora.com>
Committed: Mon May 28 08:04:11 2018 +0700
----------------------------------------------------------------------
.../test/java/org/apache/james/quota/search/QuotaClauseTest.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/251def19/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaClauseTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaClauseTest.java b/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaClauseTest.java
index 09e6f4e..ff7a5ab 100644
--- a/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaClauseTest.java
+++ b/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaClauseTest.java
@@ -30,7 +30,7 @@ import org.junit.jupiter.api.Test;
import nl.jqno.equalsverifier.EqualsVerifier;
-public class QuotaClauseTest implements QuotaClause {
+public class QuotaClauseTest {
@Test
public void lessThanShouldMatchBeanContract() {
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[10/13] james-project git commit: JAMES-2403 ElasticSearch
implementation of QuotaSearcher
Posted by bt...@apache.org.
JAMES-2403 ElasticSearch implementation of QuotaSearcher
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/dd95f7c5
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/dd95f7c5
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/dd95f7c5
Branch: refs/heads/master
Commit: dd95f7c5567cecc99ca38b62238881811fb49d48
Parents: f534186
Author: Raphael Ouazana <ra...@linagora.com>
Authored: Wed May 23 18:17:01 2018 +0200
Committer: benwa <bt...@linagora.com>
Committed: Mon May 28 08:05:35 2018 +0700
----------------------------------------------------------------------
.../plugin/quota-search-elasticsearch/pom.xml | 35 ++++++
.../ElasticSearchQuotaSearcher.java | 90 +++++++++++++++
.../elasticsearch/QuotaQueryConverter.java | 103 +++++++++++++++++
...ticSearchQuotaSearchTestSystemExtension.java | 112 +++++++++++++++++++
.../ElasticSearchQuotaSearcherTest.java | 28 +++++
.../elasticsearch/QuotaQueryConverterTest.java | 83 ++++++++++++++
.../MemoryQuotaSearchTestSystemExtension.java | 4 +-
.../quota/search/QuotaSearchTestSystem.java | 8 +-
.../quota/search/QuotaSearcherContract.java | 10 ++
9 files changed, 471 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/dd95f7c5/mailbox/plugin/quota-search-elasticsearch/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/pom.xml b/mailbox/plugin/quota-search-elasticsearch/pom.xml
index 79b9ef1..7509c9a 100644
--- a/mailbox/plugin/quota-search-elasticsearch/pom.xml
+++ b/mailbox/plugin/quota-search-elasticsearch/pom.xml
@@ -56,11 +56,41 @@
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
+ <artifactId>apache-james-mailbox-memory</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>apache-james-mailbox-memory</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
<artifactId>apache-james-mailbox-quota-search</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>apache-james-mailbox-quota-search</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>james-core</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>james-server-data-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>james-server-data-memory</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
@@ -89,6 +119,11 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>net.javacrumbs.json-unit</groupId>
<artifactId>json-unit-fluent</artifactId>
<scope>test</scope>
http://git-wip-us.apache.org/repos/asf/james-project/blob/dd95f7c5/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaSearcher.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaSearcher.java b/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaSearcher.java
new file mode 100644
index 0000000..7e0857b
--- /dev/null
+++ b/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaSearcher.java
@@ -0,0 +1,90 @@
+/****************************************************************
+ * 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.quota.search.elasticsearch;
+
+import static org.apache.james.quota.search.elasticsearch.QuotaRatioElasticSearchConstants.QUOTA_RATIO_TYPE;
+import static org.apache.james.quota.search.elasticsearch.json.JsonMessageConstants.USER;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Stream;
+
+import org.apache.james.backends.es.AliasName;
+import org.apache.james.backends.es.search.ScrollIterable;
+import org.apache.james.core.User;
+import org.apache.james.quota.search.QuotaQuery;
+import org.apache.james.quota.search.QuotaSearcher;
+import org.elasticsearch.action.search.SearchRequestBuilder;
+import org.elasticsearch.client.Client;
+import org.elasticsearch.common.unit.TimeValue;
+import org.elasticsearch.search.sort.SortBuilders;
+import org.elasticsearch.search.sort.SortOrder;
+
+import com.github.steveash.guavate.Guavate;
+
+public class ElasticSearchQuotaSearcher implements QuotaSearcher {
+ private static final TimeValue TIMEOUT = new TimeValue(60000);
+
+ private final Client client;
+ private final AliasName readAlias;
+ private final QuotaQueryConverter quotaQueryConverter;
+
+ public ElasticSearchQuotaSearcher(Client client, AliasName readAlias) {
+ this.client = client;
+ this.readAlias = readAlias;
+ this.quotaQueryConverter = new QuotaQueryConverter();
+ }
+
+ @Override
+ public List<User> search(QuotaQuery query) {
+ Stream<User> results = new ScrollIterable(client, prepareSearch(query))
+ .stream()
+ .flatMap(searchResponse -> Arrays.stream(searchResponse.getHits()
+ .getHits()))
+ .map(hit -> hit.field(USER))
+ .map(field -> (String) field.getValue())
+ .map(User::fromUsername)
+ .skip(query.getOffset().getValue());
+
+ return query.getLimit().getValue()
+ .map(results::limit)
+ .orElse(results)
+ .collect(Guavate.toImmutableList());
+ }
+
+ public SearchRequestBuilder prepareSearch(QuotaQuery query) {
+ SearchRequestBuilder searchRequestBuilder = client.prepareSearch(readAlias.getValue())
+ .setTypes(QUOTA_RATIO_TYPE.getValue())
+ .setScroll(TIMEOUT)
+ .addFields(USER)
+ .setQuery(quotaQueryConverter.from(query));
+
+ query.getLimit()
+ .getValue()
+ .ifPresent(searchRequestBuilder::setSize);
+
+ searchRequestBuilder.addSort(
+ SortBuilders.fieldSort(USER)
+ .order(SortOrder.ASC));
+
+ return searchRequestBuilder;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/dd95f7c5/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaQueryConverter.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaQueryConverter.java b/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaQueryConverter.java
new file mode 100644
index 0000000..b02d8ac
--- /dev/null
+++ b/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaQueryConverter.java
@@ -0,0 +1,103 @@
+/****************************************************************
+ * 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.quota.search.elasticsearch;
+
+import static org.apache.james.quota.search.elasticsearch.json.JsonMessageConstants.DOMAIN;
+import static org.apache.james.quota.search.elasticsearch.json.JsonMessageConstants.QUOTA_RATIO;
+import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
+import static org.elasticsearch.index.query.QueryBuilders.rangeQuery;
+import static org.elasticsearch.index.query.QueryBuilders.termQuery;
+
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+
+import org.apache.james.quota.search.QuotaClause;
+import org.apache.james.quota.search.QuotaClause.And;
+import org.apache.james.quota.search.QuotaClause.HasDomain;
+import org.apache.james.quota.search.QuotaClause.LessThan;
+import org.apache.james.quota.search.QuotaClause.MoreThan;
+import org.apache.james.quota.search.QuotaQuery;
+import org.elasticsearch.index.query.BoolQueryBuilder;
+import org.elasticsearch.index.query.QueryBuilder;
+import org.elasticsearch.index.query.RangeQueryBuilder;
+import org.elasticsearch.index.query.TermQueryBuilder;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableMap.Builder;
+
+public class QuotaQueryConverter {
+ private final Map<Class<? extends QuotaClause>, Function<QuotaClause, QueryBuilder>> clauseConverter;
+
+ public QuotaQueryConverter() {
+ Builder<Class<? extends QuotaClause>, Function<QuotaClause, QueryBuilder>> builder = ImmutableMap.builder();
+
+ builder.put(HasDomain.class, this::convertHasDomain);
+ builder.put(And.class, this::disableNestedAnd);
+ builder.put(MoreThan.class, this::convertMoreThan);
+ builder.put(LessThan.class, this::convertLessThan);
+
+ clauseConverter = builder.build();
+ }
+
+ public QueryBuilder from(QuotaQuery query) {
+ List<QuotaClause> clauses = query.getClause().getClauses();
+ if (clauses.isEmpty()) {
+ return matchAllQuery();
+ }
+ if (clauses.size() == 1) {
+ return singleClauseAsESQuery(clauses.get(0));
+ }
+
+ return clausesAsAndESQuery(clauses);
+ }
+
+ private BoolQueryBuilder clausesAsAndESQuery(List<QuotaClause> clauses) {
+ BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
+ clauses.stream()
+ .map(this::singleClauseAsESQuery)
+ .forEach(boolQueryBuilder::must);
+ return boolQueryBuilder;
+ }
+
+ private QueryBuilder disableNestedAnd(QuotaClause clause) {
+ throw new IllegalArgumentException("Nested \"And\" clauses are not supported");
+ }
+
+ private TermQueryBuilder convertHasDomain(QuotaClause clause) {
+ HasDomain hasDomain = (HasDomain) clause;
+ return termQuery(DOMAIN, hasDomain.getDomain().asString());
+ }
+
+ private RangeQueryBuilder convertMoreThan(QuotaClause clause) {
+ MoreThan moreThan = (MoreThan) clause;
+ return rangeQuery(QUOTA_RATIO).gte(moreThan.getQuotaBoundary().getRatio());
+ }
+
+ private RangeQueryBuilder convertLessThan(QuotaClause clause) {
+ LessThan lessThan = (LessThan) clause;
+ return rangeQuery(QUOTA_RATIO).lte(lessThan.getQuotaBoundary().getRatio());
+ }
+
+ private QueryBuilder singleClauseAsESQuery(QuotaClause clause) {
+ return clauseConverter.get(clause.getClass()).apply(clause);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/dd95f7c5/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaSearchTestSystemExtension.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaSearchTestSystemExtension.java b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaSearchTestSystemExtension.java
new file mode 100644
index 0000000..d4dc2a2
--- /dev/null
+++ b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaSearchTestSystemExtension.java
@@ -0,0 +1,112 @@
+/****************************************************************
+ * 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.quota.search.elasticsearch;
+
+import static org.mockito.Mockito.mock;
+
+import java.util.concurrent.Executors;
+
+import org.apache.james.backends.es.ElasticSearchIndexer;
+import org.apache.james.backends.es.EmbeddedElasticSearch;
+import org.apache.james.backends.es.IndexCreationFactory;
+import org.apache.james.backends.es.NodeMappingFactory;
+import org.apache.james.backends.es.utils.TestingClientProvider;
+import org.apache.james.dnsservice.api.DNSService;
+import org.apache.james.domainlist.memory.MemoryDomainList;
+import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
+import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources;
+import org.apache.james.mailbox.mock.MockMailboxSession;
+import org.apache.james.quota.search.QuotaSearchTestSystem;
+import org.apache.james.quota.search.elasticsearch.events.ElasticSearchQuotaMailboxListener;
+import org.apache.james.quota.search.elasticsearch.json.QuotaRatioToElasticSearchJson;
+import org.apache.james.user.memory.MemoryUsersRepository;
+import org.elasticsearch.client.Client;
+import org.junit.jupiter.api.extension.AfterEachCallback;
+import org.junit.jupiter.api.extension.BeforeEachCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.ParameterContext;
+import org.junit.jupiter.api.extension.ParameterResolutionException;
+import org.junit.jupiter.api.extension.ParameterResolver;
+import org.junit.rules.TemporaryFolder;
+
+public class ElasticSearchQuotaSearchTestSystemExtension implements ParameterResolver, BeforeEachCallback, AfterEachCallback {
+
+ private TemporaryFolder temporaryFolder = new TemporaryFolder();
+ private EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder, QuotaRatioElasticSearchConstants.DEFAULT_QUOTA_RATIO_INDEX);
+
+ @Override
+ public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
+ return (parameterContext.getParameter().getType() == QuotaSearchTestSystem.class);
+ }
+
+ @Override
+ public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
+ try {
+ Client client = NodeMappingFactory.applyMapping(
+ new IndexCreationFactory()
+ .useIndex(QuotaRatioElasticSearchConstants.DEFAULT_QUOTA_RATIO_INDEX)
+ .addAlias(QuotaRatioElasticSearchConstants.DEFAULT_QUOTA_RATIO_READ_ALIAS)
+ .addAlias(QuotaRatioElasticSearchConstants.DEFAULT_QUOTA_RATIO_WRITE_ALIAS)
+ .createIndexAndAliases(new TestingClientProvider(embeddedElasticSearch.getNode()).get()),
+ QuotaRatioElasticSearchConstants.DEFAULT_QUOTA_RATIO_INDEX,
+ QuotaRatioElasticSearchConstants.QUOTA_RATIO_TYPE,
+ QuotaRatioMappingFactory.getMappingContent());
+
+ InMemoryIntegrationResources.Resources resources = new InMemoryIntegrationResources().createResources(new SimpleGroupMembershipResolver());
+
+ MemoryUsersRepository usersRepository = MemoryUsersRepository.withVirtualHosting();
+
+ DNSService dnsService = mock(DNSService.class);
+ MemoryDomainList domainList = new MemoryDomainList(dnsService);
+ usersRepository.setDomainList(domainList);
+
+ ElasticSearchQuotaMailboxListener listener = new ElasticSearchQuotaMailboxListener(
+ new ElasticSearchIndexer(client, Executors.newSingleThreadExecutor(),
+ QuotaRatioElasticSearchConstants.DEFAULT_QUOTA_RATIO_WRITE_ALIAS,
+ QuotaRatioElasticSearchConstants.QUOTA_RATIO_TYPE),
+ new QuotaRatioToElasticSearchJson());
+
+ resources.getMailboxManager()
+ .addGlobalListener(listener, new MockMailboxSession("ANY"));
+
+ return new QuotaSearchTestSystem(
+ resources.getMaxQuotaManager(),
+ resources.getMailboxManager(),
+ new ElasticSearchQuotaSearcher(client,
+ QuotaRatioElasticSearchConstants.DEFAULT_QUOTA_RATIO_READ_ALIAS),
+ usersRepository, domainList,
+ () -> embeddedElasticSearch.awaitForElasticSearch());
+ } catch (Exception e) {
+ throw new ParameterResolutionException("Error while resolving parameter", e);
+ }
+ }
+
+ @Override
+ public void beforeEach(ExtensionContext context) throws Exception {
+ temporaryFolder.create();
+ embeddedElasticSearch.before();
+ }
+
+ @Override
+ public void afterEach(ExtensionContext context) {
+ embeddedElasticSearch.after();
+ temporaryFolder.delete();
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/dd95f7c5/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaSearcherTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaSearcherTest.java b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaSearcherTest.java
new file mode 100644
index 0000000..ad26532
--- /dev/null
+++ b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaSearcherTest.java
@@ -0,0 +1,28 @@
+/****************************************************************
+ * 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.quota.search.elasticsearch;
+
+import org.apache.james.quota.search.QuotaSearcherContract;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+@ExtendWith(ElasticSearchQuotaSearchTestSystemExtension.class)
+public class ElasticSearchQuotaSearcherTest implements QuotaSearcherContract {
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/dd95f7c5/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/QuotaQueryConverterTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/QuotaQueryConverterTest.java b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/QuotaQueryConverterTest.java
new file mode 100644
index 0000000..86daa88
--- /dev/null
+++ b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/QuotaQueryConverterTest.java
@@ -0,0 +1,83 @@
+/****************************************************************
+ * 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.quota.search.elasticsearch;
+
+import static org.apache.james.quota.search.elasticsearch.json.JsonMessageConstants.QUOTA_RATIO;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
+import static org.elasticsearch.index.query.QueryBuilders.rangeQuery;
+import static org.elasticsearch.index.query.QueryBuilders.termQuery;
+
+import org.apache.james.core.Domain;
+import org.apache.james.quota.search.QuotaBoundary;
+import org.apache.james.quota.search.QuotaQuery;
+import org.apache.james.quota.search.elasticsearch.json.JsonMessageConstants;
+import org.elasticsearch.index.query.QueryBuilder;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+class QuotaQueryConverterTest {
+ private QuotaQueryConverter testee;
+
+ @BeforeEach
+ void setup() {
+ testee = new QuotaQueryConverter();
+ }
+
+ @Test
+ void fromShouldReturnMatchAllWhenEmptyClauses() {
+ QuotaQuery query = QuotaQuery.builder().build();
+ QueryBuilder expected = matchAllQuery();
+
+ QueryBuilder actual = testee.from(query);
+
+ assertThat(actual).isEqualToComparingFieldByField(expected);
+ }
+
+ @Test
+ void fromShouldReturnDomainMatchWhenOnlyDomain() {
+ QuotaQuery query = QuotaQuery.builder().hasDomain(Domain.of("my.tld")).build();
+ QueryBuilder expected = termQuery(JsonMessageConstants.DOMAIN, "my.tld");
+
+ QueryBuilder actual = testee.from(query);
+
+ assertThat(actual).isEqualToComparingFieldByField(expected);
+ }
+
+ @Test
+ void fromShouldReturnQuotaRatioMatchWhenLessThan() {
+ QuotaQuery query = QuotaQuery.builder().lessThan(new QuotaBoundary(0.1)).build();
+ QueryBuilder expected = rangeQuery(QUOTA_RATIO).lte(0.1);
+
+ QueryBuilder actual = testee.from(query);
+
+ assertThat(actual).isEqualToComparingFieldByField(expected);
+ }
+
+ @Test
+ void fromShouldReturnQuotaRatioMatchWhenMoreThan() {
+ QuotaQuery query = QuotaQuery.builder().moreThan(new QuotaBoundary(0.1)).build();
+ QueryBuilder expected = rangeQuery(QUOTA_RATIO).gte(0.1);
+
+ QueryBuilder actual = testee.from(query);
+
+ assertThat(actual).isEqualToComparingFieldByField(expected);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/dd95f7c5/mailbox/plugin/quota-search-scanning/src/test/java/org/apache/james/quota/search/scanning/MemoryQuotaSearchTestSystemExtension.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-scanning/src/test/java/org/apache/james/quota/search/scanning/MemoryQuotaSearchTestSystemExtension.java b/mailbox/plugin/quota-search-scanning/src/test/java/org/apache/james/quota/search/scanning/MemoryQuotaSearchTestSystemExtension.java
index 6bd1df3..27b08d2 100644
--- a/mailbox/plugin/quota-search-scanning/src/test/java/org/apache/james/quota/search/scanning/MemoryQuotaSearchTestSystemExtension.java
+++ b/mailbox/plugin/quota-search-scanning/src/test/java/org/apache/james/quota/search/scanning/MemoryQuotaSearchTestSystemExtension.java
@@ -34,6 +34,8 @@ import org.junit.jupiter.api.extension.ParameterResolver;
public class MemoryQuotaSearchTestSystemExtension implements ParameterResolver {
+ private static final Runnable NO_AWAIT = () -> {};
+
@Override
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
return (parameterContext.getParameter().getType() == QuotaSearchTestSystem.class);
@@ -55,7 +57,7 @@ public class MemoryQuotaSearchTestSystemExtension implements ParameterResolver {
resources.getMailboxManager(),
new ScanningQuotaSearcher(usersRepository,
new ClauseConverter(resources.getQuotaRootResolver(), resources.getQuotaManager())),
- usersRepository, domainList);
+ usersRepository, domainList, NO_AWAIT);
} catch (Exception e) {
throw new ParameterResolutionException("Error while resolving parameter", e);
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/dd95f7c5/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaSearchTestSystem.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaSearchTestSystem.java b/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaSearchTestSystem.java
index 88e4591..5710a60 100644
--- a/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaSearchTestSystem.java
+++ b/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaSearchTestSystem.java
@@ -30,13 +30,15 @@ public class QuotaSearchTestSystem {
private final QuotaSearcher quotaSearcher;
private final UsersRepository usersRepository;
private final DomainList domainList;
+ private final Runnable await;
- public QuotaSearchTestSystem(MaxQuotaManager maxQuotaManager, MailboxManager mailboxManager, QuotaSearcher quotaSearcher, UsersRepository usersRepository, DomainList domainList) {
+ public QuotaSearchTestSystem(MaxQuotaManager maxQuotaManager, MailboxManager mailboxManager, QuotaSearcher quotaSearcher, UsersRepository usersRepository, DomainList domainList, Runnable await) {
this.maxQuotaManager = maxQuotaManager;
this.mailboxManager = mailboxManager;
this.quotaSearcher = quotaSearcher;
this.usersRepository = usersRepository;
this.domainList = domainList;
+ this.await = await;
}
public MaxQuotaManager getMaxQuotaManager() {
@@ -58,4 +60,8 @@ public class QuotaSearchTestSystem {
public DomainList getDomainList() {
return domainList;
}
+
+ public void await() {
+ await.run();
+ }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/dd95f7c5/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaSearcherContract.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaSearcherContract.java b/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaSearcherContract.java
index 247d902..0abfc21 100644
--- a/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaSearcherContract.java
+++ b/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaSearcherContract.java
@@ -59,6 +59,7 @@ public interface QuotaSearcherContract {
appendMessage(testSystem, Simpson.BART, withSize(49));
appendMessage(testSystem, Simpson.HOMER, withSize(50));
appendMessage(testSystem, Simpson.LISA, withSize(51));
+ testSystem.await();
assertThat(
testSystem.getQuotaSearcher()
@@ -78,6 +79,7 @@ public interface QuotaSearcherContract {
appendMessage(testSystem, Simpson.BART, withSize(49));
appendMessage(testSystem, Simpson.HOMER, withSize(50));
appendMessage(testSystem, Simpson.LISA, withSize(51));
+ testSystem.await();
assertThat(
testSystem.getQuotaSearcher()
@@ -98,6 +100,7 @@ public interface QuotaSearcherContract {
appendMessage(testSystem, Simpson.HOMER, withSize(51));
appendMessage(testSystem, Simpson.LISA, withSize(60));
appendMessage(testSystem, BENOIT_AT_DOMAIN_TLD, withSize(80));
+ testSystem.await();
assertThat(
testSystem.getQuotaSearcher()
@@ -119,6 +122,7 @@ public interface QuotaSearcherContract {
appendMessage(testSystem, Simpson.BART, withSize(49));
appendMessage(testSystem, Simpson.LISA, withSize(51));
appendMessage(testSystem, BENOIT_AT_DOMAIN_TLD, withSize(50));
+ testSystem.await();
assertThat(
testSystem.getQuotaSearcher()
@@ -139,6 +143,7 @@ public interface QuotaSearcherContract {
appendMessage(testSystem, Simpson.BART, withSize(49));
appendMessage(testSystem, Simpson.LISA, withSize(51));
appendMessage(testSystem, BENOIT_AT_DOMAIN_TLD, withSize(50));
+ testSystem.await();
assertThat(
testSystem.getQuotaSearcher()
@@ -161,6 +166,7 @@ public interface QuotaSearcherContract {
appendMessage(testSystem, Alphabet.ABA, withSize(50));
appendMessage(testSystem, Alphabet.ACB, withSize(51));
appendMessage(testSystem, Alphabet.ABB, withSize(50));
+ testSystem.await();
assertThat(
testSystem.getQuotaSearcher()
@@ -181,6 +187,7 @@ public interface QuotaSearcherContract {
appendMessage(testSystem, Alphabet.ABA, withSize(50));
appendMessage(testSystem, Alphabet.ACB, withSize(51));
appendMessage(testSystem, Alphabet.ABB, withSize(50));
+ testSystem.await();
assertThat(
testSystem.getQuotaSearcher()
@@ -202,6 +209,7 @@ public interface QuotaSearcherContract {
appendMessage(testSystem, Alphabet.ABA, withSize(50));
appendMessage(testSystem, Alphabet.ACB, withSize(51));
appendMessage(testSystem, Alphabet.ABB, withSize(50));
+ testSystem.await();
assertThat(
testSystem.getQuotaSearcher()
@@ -224,6 +232,7 @@ public interface QuotaSearcherContract {
appendMessage(testSystem, Simpson.HOMER, withSize(50));
appendMessage(testSystem, Simpson.LISA, withSize(51));
appendMessage(testSystem, BENOIT_AT_DOMAIN_TLD, withSize(50));
+ testSystem.await();
assertThat(
testSystem.getQuotaSearcher()
@@ -245,6 +254,7 @@ public interface QuotaSearcherContract {
appendMessage(testSystem, Alphabet.ABA, withSize(50));
appendMessage(testSystem, Alphabet.ACB, withSize(51));
appendMessage(testSystem, Alphabet.ABB, withSize(50));
+ testSystem.await();
assertThat(
testSystem.getQuotaSearcher()
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[02/13] james-project git commit: JAMES-2403 Extract and move
QuotaFixture to mailbox-api
Posted by bt...@apache.org.
JAMES-2403 Extract and move QuotaFixture to mailbox-api
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/0257046e
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/0257046e
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/0257046e
Branch: refs/heads/master
Commit: 0257046e8d1e2b3c16d7d5b64933a33069a0013f
Parents: 74b6d80
Author: benwa <bt...@linagora.com>
Authored: Thu May 24 09:15:59 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Mon May 28 08:04:11 2018 +0700
----------------------------------------------------------------------
.../james/mailbox/quota/QuotaFixture.java | 108 +++++++++++++++++++
.../QuotaThresholdConfigurationChangesTest.java | 4 +-
.../QuotaThresholdMailingIntegrationTest.java | 4 +-
.../subscribers/QuotaThresholdNoticeTest.java | 4 +-
.../quota/model/QuotaThresholdFixture.java | 88 ---------------
.../mailbox/quota/model/QuotaThresholdTest.java | 2 +-
.../quota/model/QuotaThresholdsTest.java | 2 +-
7 files changed, 116 insertions(+), 96 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/0257046e/mailbox/api/src/test/java/org/apache/james/mailbox/quota/QuotaFixture.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/quota/QuotaFixture.java b/mailbox/api/src/test/java/org/apache/james/mailbox/quota/QuotaFixture.java
new file mode 100644
index 0000000..740f8c4
--- /dev/null
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/quota/QuotaFixture.java
@@ -0,0 +1,108 @@
+/****************************************************************
+ * 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.mailbox.quota;
+
+import org.apache.james.mailbox.model.Quota;
+
+public interface QuotaFixture {
+ interface Counts {
+ Quota<QuotaCount> _32_PERCENT = Quota.<QuotaCount>builder()
+ .used(QuotaCount.count(32))
+ .computedLimit(QuotaCount.count(100))
+ .build();
+
+ Quota<QuotaCount> _40_PERCENT = Quota.<QuotaCount>builder()
+ .used(QuotaCount.count(40))
+ .computedLimit(QuotaCount.count(100))
+ .build();
+
+ Quota<QuotaCount> _52_PERCENT = Quota.<QuotaCount>builder()
+ .used(QuotaCount.count(52))
+ .computedLimit(QuotaCount.count(100))
+ .build();
+
+ Quota<QuotaCount> _72_PERCENT = Quota.<QuotaCount>builder()
+ .used(QuotaCount.count(72))
+ .computedLimit(QuotaCount.count(100))
+ .build();
+
+ Quota<QuotaCount> _82_PERCENT = Quota.<QuotaCount>builder()
+ .used(QuotaCount.count(82))
+ .computedLimit(QuotaCount.count(100))
+ .build();
+
+ Quota<QuotaCount> _85_PERCENT = Quota.<QuotaCount>builder()
+ .used(QuotaCount.count(85))
+ .computedLimit(QuotaCount.count(100))
+ .build();
+
+ Quota<QuotaCount> _92_PERCENT = Quota.<QuotaCount>builder()
+ .used(QuotaCount.count(92))
+ .computedLimit(QuotaCount.count(100))
+ .build();
+
+ Quota<QuotaCount> _UNLIMITED = Quota.<QuotaCount>builder()
+ .used(QuotaCount.count(92))
+ .computedLimit(QuotaCount.unlimited())
+ .build();
+ }
+
+ interface Sizes {
+ Quota<QuotaSize> _30_PERCENT = Quota.<QuotaSize>builder()
+ .used(QuotaSize.size(30))
+ .computedLimit(QuotaSize.size(100))
+ .build();
+ Quota<QuotaSize> _42_PERCENT = Quota.<QuotaSize>builder()
+ .used(QuotaSize.size(42))
+ .computedLimit(QuotaSize.size(100))
+ .build();
+
+ Quota<QuotaSize> _55_PERCENT = Quota.<QuotaSize>builder()
+ .used(QuotaSize.size(55))
+ .computedLimit(QuotaSize.size(100))
+ .build();
+
+ Quota<QuotaSize> _60_PERCENT = Quota.<QuotaSize>builder()
+ .used(QuotaSize.size(60))
+ .computedLimit(QuotaSize.size(100))
+ .build();
+
+ Quota<QuotaSize> _75_PERCENT = Quota.<QuotaSize>builder()
+ .used(QuotaSize.size(75))
+ .computedLimit(QuotaSize.size(100))
+ .build();
+
+ Quota<QuotaSize> _82_PERCENT = Quota.<QuotaSize>builder()
+ .used(QuotaSize.size(82))
+ .computedLimit(QuotaSize.size(100))
+ .build();
+
+ Quota<QuotaSize> _92_PERCENT = Quota.<QuotaSize>builder()
+ .used(QuotaSize.size(92))
+ .computedLimit(QuotaSize.size(100))
+ .build();
+
+ Quota<QuotaSize> _992_PERTHOUSAND = Quota.<QuotaSize>builder()
+ .used(QuotaSize.size(992))
+ .computedLimit(QuotaSize.size(1000))
+ .build();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/0257046e/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdConfigurationChangesTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdConfigurationChangesTest.java b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdConfigurationChangesTest.java
index 166d86c..4876b3a 100644
--- a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdConfigurationChangesTest.java
+++ b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdConfigurationChangesTest.java
@@ -30,9 +30,9 @@ import static org.assertj.core.api.Assertions.assertThat;
import org.apache.james.eventsourcing.eventstore.EventStore;
import org.apache.james.mailbox.MailboxListener.QuotaUsageUpdatedEvent;
+import org.apache.james.mailbox.quota.QuotaFixture.Counts;
+import org.apache.james.mailbox.quota.QuotaFixture.Sizes;
import org.apache.james.mailbox.quota.mailing.QuotaMailingListenerConfiguration;
-import org.apache.james.mailbox.quota.model.QuotaThresholdFixture.Quotas.Counts;
-import org.apache.james.mailbox.quota.model.QuotaThresholdFixture.Quotas.Sizes;
import org.apache.mailet.base.test.FakeMailContext;
import org.junit.jupiter.api.Test;
http://git-wip-us.apache.org/repos/asf/james-project/blob/0257046e/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdMailingIntegrationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdMailingIntegrationTest.java b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdMailingIntegrationTest.java
index 362246f..2dbc69b 100644
--- a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdMailingIntegrationTest.java
+++ b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdMailingIntegrationTest.java
@@ -39,9 +39,9 @@ import java.util.concurrent.TimeUnit;
import org.apache.james.eventsourcing.eventstore.EventStore;
import org.apache.james.mailbox.MailboxListener.QuotaUsageUpdatedEvent;
+import org.apache.james.mailbox.quota.QuotaFixture.Counts;
+import org.apache.james.mailbox.quota.QuotaFixture.Sizes;
import org.apache.james.mailbox.quota.mailing.QuotaMailingListenerConfiguration;
-import org.apache.james.mailbox.quota.model.QuotaThresholdFixture.Quotas.Counts;
-import org.apache.james.mailbox.quota.model.QuotaThresholdFixture.Quotas.Sizes;
import org.apache.james.util.concurrency.ConcurrentTestRunner;
import org.apache.mailet.base.test.FakeMailContext;
import org.junit.jupiter.api.Test;
http://git-wip-us.apache.org/repos/asf/james-project/blob/0257046e/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/subscribers/QuotaThresholdNoticeTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/subscribers/QuotaThresholdNoticeTest.java b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/subscribers/QuotaThresholdNoticeTest.java
index 071c063..576ae0a 100644
--- a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/subscribers/QuotaThresholdNoticeTest.java
+++ b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/subscribers/QuotaThresholdNoticeTest.java
@@ -32,13 +32,13 @@ import java.util.Optional;
import org.apache.james.filesystem.api.FileSystem;
import org.apache.james.mailbox.model.Quota;
import org.apache.james.mailbox.quota.QuotaCount;
+import org.apache.james.mailbox.quota.QuotaFixture.Counts;
+import org.apache.james.mailbox.quota.QuotaFixture.Sizes;
import org.apache.james.mailbox.quota.QuotaSize;
import org.apache.james.mailbox.quota.mailing.QuotaMailingListenerConfiguration;
import org.apache.james.mailbox.quota.mailing.QuotaMailingListenerConfiguration.RenderingInformation;
import org.apache.james.mailbox.quota.model.HistoryEvolution;
import org.apache.james.mailbox.quota.model.QuotaThresholdChange;
-import org.apache.james.mailbox.quota.model.QuotaThresholdFixture.Quotas.Counts;
-import org.apache.james.mailbox.quota.model.QuotaThresholdFixture.Quotas.Sizes;
import org.apache.james.server.core.JamesServerResourceLoader;
import org.apache.james.server.core.filesystem.FileSystemImpl;
import org.assertj.core.api.SoftAssertions;
http://git-wip-us.apache.org/repos/asf/james-project/blob/0257046e/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdFixture.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdFixture.java b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdFixture.java
index 9adac91..d5ed137 100644
--- a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdFixture.java
+++ b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdFixture.java
@@ -24,10 +24,7 @@ import java.time.Instant;
import java.util.Optional;
import org.apache.james.mailbox.mock.MockMailboxSession;
-import org.apache.james.mailbox.model.Quota;
import org.apache.james.mailbox.model.QuotaRoot;
-import org.apache.james.mailbox.quota.QuotaCount;
-import org.apache.james.mailbox.quota.QuotaSize;
import org.apache.james.mailbox.quota.mailing.QuotaMailingListenerConfiguration;
import org.apache.mailet.base.MailAddressFixture;
import org.apache.mailet.base.test.FakeMailContext;
@@ -41,91 +38,6 @@ public interface QuotaThresholdFixture {
QuotaThreshold _95 = new QuotaThreshold(0.95);
QuotaThreshold _99 = new QuotaThreshold(0.99);
- interface Quotas {
- interface Counts {
- Quota<QuotaCount> _32_PERCENT = Quota.<QuotaCount>builder()
- .used(QuotaCount.count(32))
- .computedLimit(QuotaCount.count(100))
- .build();
-
- Quota<QuotaCount> _40_PERCENT = Quota.<QuotaCount>builder()
- .used(QuotaCount.count(40))
- .computedLimit(QuotaCount.count(100))
- .build();
-
- Quota<QuotaCount> _52_PERCENT = Quota.<QuotaCount>builder()
- .used(QuotaCount.count(52))
- .computedLimit(QuotaCount.count(100))
- .build();
-
- Quota<QuotaCount> _72_PERCENT = Quota.<QuotaCount>builder()
- .used(QuotaCount.count(72))
- .computedLimit(QuotaCount.count(100))
- .build();
-
- Quota<QuotaCount> _82_PERCENT = Quota.<QuotaCount>builder()
- .used(QuotaCount.count(82))
- .computedLimit(QuotaCount.count(100))
- .build();
-
- Quota<QuotaCount> _85_PERCENT = Quota.<QuotaCount>builder()
- .used(QuotaCount.count(85))
- .computedLimit(QuotaCount.count(100))
- .build();
-
- Quota<QuotaCount> _92_PERCENT = Quota.<QuotaCount>builder()
- .used(QuotaCount.count(92))
- .computedLimit(QuotaCount.count(100))
- .build();
-
- Quota<QuotaCount> _UNLIMITED = Quota.<QuotaCount>builder()
- .used(QuotaCount.count(92))
- .computedLimit(QuotaCount.unlimited())
- .build();
- }
-
- interface Sizes {
- Quota<QuotaSize> _30_PERCENT = Quota.<QuotaSize>builder()
- .used(QuotaSize.size(30))
- .computedLimit(QuotaSize.size(100))
- .build();
- Quota<QuotaSize> _42_PERCENT = Quota.<QuotaSize>builder()
- .used(QuotaSize.size(42))
- .computedLimit(QuotaSize.size(100))
- .build();
-
- Quota<QuotaSize> _55_PERCENT = Quota.<QuotaSize>builder()
- .used(QuotaSize.size(55))
- .computedLimit(QuotaSize.size(100))
- .build();
-
- Quota<QuotaSize> _60_PERCENT = Quota.<QuotaSize>builder()
- .used(QuotaSize.size(60))
- .computedLimit(QuotaSize.size(100))
- .build();
-
- Quota<QuotaSize> _75_PERCENT = Quota.<QuotaSize>builder()
- .used(QuotaSize.size(75))
- .computedLimit(QuotaSize.size(100))
- .build();
-
- Quota<QuotaSize> _82_PERCENT = Quota.<QuotaSize>builder()
- .used(QuotaSize.size(82))
- .computedLimit(QuotaSize.size(100))
- .build();
-
- Quota<QuotaSize> _92_PERCENT = Quota.<QuotaSize>builder()
- .used(QuotaSize.size(92))
- .computedLimit(QuotaSize.size(100))
- .build();
-
- Quota<QuotaSize> _992_PERTHOUSAND = Quota.<QuotaSize>builder()
- .used(QuotaSize.size(992))
- .computedLimit(QuotaSize.size(1000))
- .build();
- }
- }
-
interface TestConstants {
Duration GRACE_PERIOD = Duration.ofDays(1);
QuotaMailingListenerConfiguration DEFAULT_CONFIGURATION = QuotaMailingListenerConfiguration.builder()
http://git-wip-us.apache.org/repos/asf/james-project/blob/0257046e/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdTest.java b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdTest.java
index f46eb38..ca2f5b0 100644
--- a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdTest.java
+++ b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdTest.java
@@ -27,8 +27,8 @@ import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.apache.james.mailbox.model.Quota;
+import org.apache.james.mailbox.quota.QuotaFixture.Sizes;
import org.apache.james.mailbox.quota.QuotaSize;
-import org.apache.james.mailbox.quota.model.QuotaThresholdFixture.Quotas.Sizes;
import org.junit.jupiter.api.Test;
import nl.jqno.equalsverifier.EqualsVerifier;
http://git-wip-us.apache.org/repos/asf/james-project/blob/0257046e/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdsTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdsTest.java b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdsTest.java
index b959c1d..b871296 100644
--- a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdsTest.java
+++ b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdsTest.java
@@ -26,8 +26,8 @@ import static org.apache.james.mailbox.quota.model.QuotaThresholdFixture._99;
import static org.assertj.core.api.Assertions.assertThat;
import org.apache.james.mailbox.model.Quota;
+import org.apache.james.mailbox.quota.QuotaFixture.Sizes;
import org.apache.james.mailbox.quota.QuotaSize;
-import org.apache.james.mailbox.quota.model.QuotaThresholdFixture.Quotas.Sizes;
import org.junit.jupiter.api.Test;
import com.google.common.collect.ImmutableList;
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[05/13] james-project git commit: JAMES-2403 Make
ElasticSearchIndexer method names more generic
Posted by bt...@apache.org.
JAMES-2403 Make ElasticSearchIndexer method names more generic
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/a0da5c19
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/a0da5c19
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/a0da5c19
Branch: refs/heads/master
Commit: a0da5c199b0e3e1b3ca3e27d7bf4315c8e53be26
Parents: 0257046
Author: Antoine Duprat <ad...@linagora.com>
Authored: Tue May 22 15:50:38 2018 +0200
Committer: benwa <bt...@linagora.com>
Committed: Mon May 28 08:04:11 2018 +0700
----------------------------------------------------------------------
.../james/backends/es/ElasticSearchIndexer.java | 6 +--
.../backends/es/ElasticSearchIndexerTest.java | 40 ++++++++++----------
...lasticSearchListeningMessageSearchIndex.java | 8 ++--
...icSearchListeningMessageSearchIndexTest.java | 18 ++++-----
4 files changed, 36 insertions(+), 36 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/a0da5c19/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchIndexer.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchIndexer.java b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchIndexer.java
index ec3f161..b7fb311 100644
--- a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchIndexer.java
+++ b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchIndexer.java
@@ -63,7 +63,7 @@ public class ElasticSearchIndexer {
this.typeName = typeName;
}
- public IndexResponse indexMessage(String id, String content) {
+ public IndexResponse index(String id, String content) {
checkArgument(content);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Indexing {}: {}", id, StringUtils.left(content, DEBUG_MAX_LENGTH_CONTENT));
@@ -73,7 +73,7 @@ public class ElasticSearchIndexer {
.get();
}
- public Optional<BulkResponse> updateMessages(List<UpdatedRepresentation> updatedDocumentParts) {
+ public Optional<BulkResponse> update(List<UpdatedRepresentation> updatedDocumentParts) {
try {
Preconditions.checkNotNull(updatedDocumentParts);
BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
@@ -90,7 +90,7 @@ public class ElasticSearchIndexer {
}
}
- public Optional<BulkResponse> deleteMessages(List<String> ids) {
+ public Optional<BulkResponse> delete(List<String> ids) {
try {
BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
ids.forEach(id -> bulkRequestBuilder.add(
http://git-wip-us.apache.org/repos/asf/james-project/blob/a0da5c19/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java
index 29f6226..e05b35c 100644
--- a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java
@@ -68,7 +68,7 @@ public class ElasticSearchIndexerTest {
String messageId = "1";
String content = "{\"message\": \"trying out Elasticsearch\"}";
- testee.indexMessage(messageId, content);
+ testee.index(messageId, content);
embeddedElasticSearch.awaitForElasticSearch();
try (Client client = node.client()) {
@@ -82,7 +82,7 @@ public class ElasticSearchIndexerTest {
@Test(expected = IllegalArgumentException.class)
public void indexMessageShouldThrowWhenJsonIsNull() throws InterruptedException {
- testee.indexMessage("1", null);
+ testee.index("1", null);
}
@Test
@@ -90,10 +90,10 @@ public class ElasticSearchIndexerTest {
String messageId = "1";
String content = "{\"message\": \"trying out Elasticsearch\",\"field\":\"Should be unchanged\"}";
- testee.indexMessage(messageId, content);
+ testee.index(messageId, content);
embeddedElasticSearch.awaitForElasticSearch();
- testee.updateMessages(Lists.newArrayList(new UpdatedRepresentation(messageId, "{\"message\": \"mastering out Elasticsearch\"}")));
+ testee.update(Lists.newArrayList(new UpdatedRepresentation(messageId, "{\"message\": \"mastering out Elasticsearch\"}")));
embeddedElasticSearch.awaitForElasticSearch();
try (Client client = node.client()) {
@@ -115,22 +115,22 @@ public class ElasticSearchIndexerTest {
@Test(expected = IllegalArgumentException.class)
public void updateMessageShouldThrowWhenJsonIsNull() throws InterruptedException {
- testee.updateMessages(Lists.newArrayList(new UpdatedRepresentation("1", null)));
+ testee.update(Lists.newArrayList(new UpdatedRepresentation("1", null)));
}
@Test(expected = IllegalArgumentException.class)
public void updateMessageShouldThrowWhenIdIsNull() throws InterruptedException {
- testee.updateMessages(Lists.newArrayList(new UpdatedRepresentation(null, "{\"message\": \"mastering out Elasticsearch\"}")));
+ testee.update(Lists.newArrayList(new UpdatedRepresentation(null, "{\"message\": \"mastering out Elasticsearch\"}")));
}
@Test(expected = IllegalArgumentException.class)
public void updateMessageShouldThrowWhenJsonIsEmpty() throws InterruptedException {
- testee.updateMessages(Lists.newArrayList(new UpdatedRepresentation("1", "")));
+ testee.update(Lists.newArrayList(new UpdatedRepresentation("1", "")));
}
@Test(expected = IllegalArgumentException.class)
public void updateMessageShouldThrowWhenIdIsEmpty() throws InterruptedException {
- testee.updateMessages(Lists.newArrayList(new UpdatedRepresentation("", "{\"message\": \"mastering out Elasticsearch\"}")));
+ testee.update(Lists.newArrayList(new UpdatedRepresentation("", "{\"message\": \"mastering out Elasticsearch\"}")));
}
@Test
@@ -138,7 +138,7 @@ public class ElasticSearchIndexerTest {
String messageId = "1:2";
String content = "{\"message\": \"trying out Elasticsearch\", \"property\":\"1\"}";
- testee.indexMessage(messageId, content);
+ testee.index(messageId, content);
embeddedElasticSearch.awaitForElasticSearch();
testee.deleteAllMatchingQuery(termQuery("property", "1"));
@@ -158,17 +158,17 @@ public class ElasticSearchIndexerTest {
String messageId = "1:1";
String content = "{\"message\": \"trying out Elasticsearch\", \"property\":\"1\"}";
- testee.indexMessage(messageId, content);
+ testee.index(messageId, content);
String messageId2 = "1:2";
String content2 = "{\"message\": \"trying out Elasticsearch 2\", \"property\":\"1\"}";
- testee.indexMessage(messageId2, content2);
+ testee.index(messageId2, content2);
String messageId3 = "2:3";
String content3 = "{\"message\": \"trying out Elasticsearch 3\", \"property\":\"2\"}";
- testee.indexMessage(messageId3, content3);
+ testee.index(messageId3, content3);
embeddedElasticSearch.awaitForElasticSearch();
testee.deleteAllMatchingQuery(termQuery("property", "1"));
@@ -188,10 +188,10 @@ public class ElasticSearchIndexerTest {
String messageId = "1:2";
String content = "{\"message\": \"trying out Elasticsearch\"}";
- testee.indexMessage(messageId, content);
+ testee.index(messageId, content);
embeddedElasticSearch.awaitForElasticSearch();
- testee.deleteMessages(Lists.newArrayList(messageId));
+ testee.delete(Lists.newArrayList(messageId));
embeddedElasticSearch.awaitForElasticSearch();
try (Client client = node.client()) {
@@ -208,20 +208,20 @@ public class ElasticSearchIndexerTest {
String messageId = "1:1";
String content = "{\"message\": \"trying out Elasticsearch\", \"mailboxId\":\"1\"}";
- testee.indexMessage(messageId, content);
+ testee.index(messageId, content);
String messageId2 = "1:2";
String content2 = "{\"message\": \"trying out Elasticsearch 2\", \"mailboxId\":\"1\"}";
- testee.indexMessage(messageId2, content2);
+ testee.index(messageId2, content2);
String messageId3 = "2:3";
String content3 = "{\"message\": \"trying out Elasticsearch 3\", \"mailboxId\":\"2\"}";
- testee.indexMessage(messageId3, content3);
+ testee.index(messageId3, content3);
embeddedElasticSearch.awaitForElasticSearch();
- testee.deleteMessages(Lists.newArrayList(messageId, messageId3));
+ testee.delete(Lists.newArrayList(messageId, messageId3));
embeddedElasticSearch.awaitForElasticSearch();
try (Client client = node.client()) {
@@ -235,11 +235,11 @@ public class ElasticSearchIndexerTest {
@Test
public void updateMessagesShouldNotThrowWhenEmptyList() throws Exception {
- testee.updateMessages(Lists.newArrayList());
+ testee.update(Lists.newArrayList());
}
@Test
public void deleteMessagesShouldNotThrowWhenEmptyList() throws Exception {
- testee.deleteMessages(Lists.newArrayList());
+ testee.delete(Lists.newArrayList());
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a0da5c19/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
index a367e59..ed008ef 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
@@ -128,7 +128,7 @@ public class ElasticSearchListeningMessageSearchIndex extends ListeningMessageSe
mailbox.getMailboxId(),
session.getUser().getUserName(),
message.getUid());
- elasticSearchIndexer.indexMessage(indexIdFor(mailbox, message.getUid()), messageToElasticSearchJson.convertToJson(message, ImmutableList.of(session.getUser())));
+ elasticSearchIndexer.index(indexIdFor(mailbox, message.getUid()), messageToElasticSearchJson.convertToJson(message, ImmutableList.of(session.getUser())));
} catch (Exception e) {
try {
LOGGER.warn("Indexing mailbox {}-{} of user {} on message {} without attachments ",
@@ -137,7 +137,7 @@ public class ElasticSearchListeningMessageSearchIndex extends ListeningMessageSe
session.getUser().getUserName(),
message.getUid(),
e);
- elasticSearchIndexer.indexMessage(indexIdFor(mailbox, message.getUid()), messageToElasticSearchJson.convertToJsonWithoutAttachment(message, ImmutableList.of(session.getUser())));
+ elasticSearchIndexer.index(indexIdFor(mailbox, message.getUid()), messageToElasticSearchJson.convertToJsonWithoutAttachment(message, ImmutableList.of(session.getUser())));
} catch (JsonProcessingException e1) {
LOGGER.error("Error when indexing mailbox {}-{} of user {} on message {} without its attachment",
mailbox.getName(),
@@ -152,7 +152,7 @@ public class ElasticSearchListeningMessageSearchIndex extends ListeningMessageSe
@Override
public void delete(MailboxSession session, Mailbox mailbox, List<MessageUid> expungedUids) throws MailboxException {
try {
- elasticSearchIndexer.deleteMessages(expungedUids.stream()
+ elasticSearchIndexer.delete(expungedUids.stream()
.map(uid -> indexIdFor(mailbox, uid))
.collect(Collectors.toList()));
} catch (Exception e) {
@@ -177,7 +177,7 @@ public class ElasticSearchListeningMessageSearchIndex extends ListeningMessageSe
@Override
public void update(MailboxSession session, Mailbox mailbox, List<UpdatedFlags> updatedFlagsList) throws MailboxException {
try {
- elasticSearchIndexer.updateMessages(updatedFlagsList.stream()
+ elasticSearchIndexer.update(updatedFlagsList.stream()
.map(updatedFlags -> createUpdatedDocumentPartFromUpdatedFlags(mailbox, updatedFlags))
.collect(Collectors.toList()));
} catch (Exception e) {
http://git-wip-us.apache.org/repos/asf/james-project/blob/a0da5c19/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
index 0f1325c..280f476 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
@@ -102,7 +102,7 @@ public class ElasticSearchListeningMessageSearchIndexTest {
testee.add(session, mailbox, message);
//Then
- verify(elasticSearchIndexer).indexMessage(eq(ELASTIC_SEARCH_ID), eq(EXPECTED_JSON_CONTENT));
+ verify(elasticSearchIndexer).index(eq(ELASTIC_SEARCH_ID), eq(EXPECTED_JSON_CONTENT));
}
@SuppressWarnings("unchecked")
@@ -125,7 +125,7 @@ public class ElasticSearchListeningMessageSearchIndexTest {
testee.add(session, mailbox, message);
//Then
- verify(elasticSearchIndexer).indexMessage(eq(ELASTIC_SEARCH_ID), eq(EXPECTED_JSON_CONTENT));
+ verify(elasticSearchIndexer).index(eq(ELASTIC_SEARCH_ID), eq(EXPECTED_JSON_CONTENT));
}
private MailboxMessage mockedMessage(MessageUid messageId) throws IOException {
@@ -166,14 +166,14 @@ public class ElasticSearchListeningMessageSearchIndexTest {
.thenReturn(MAILBOX_ID);
BulkResponse expectedBulkResponse = mock(BulkResponse.class);
- when(elasticSearchIndexer.deleteMessages(any(List.class)))
+ when(elasticSearchIndexer.delete(any(List.class)))
.thenReturn(Optional.of(expectedBulkResponse));
//When
testee.delete(session, mailbox, Lists.newArrayList(MESSAGE_UID));
//Then
- verify(elasticSearchIndexer).deleteMessages(eq(Lists.newArrayList(ELASTIC_SEARCH_ID)));
+ verify(elasticSearchIndexer).delete(eq(Lists.newArrayList(ELASTIC_SEARCH_ID)));
}
@Test
@@ -189,14 +189,14 @@ public class ElasticSearchListeningMessageSearchIndexTest {
.thenReturn(MAILBOX_ID);
BulkResponse expectedBulkResponse = mock(BulkResponse.class);
- when(elasticSearchIndexer.deleteMessages(any(List.class)))
+ when(elasticSearchIndexer.delete(any(List.class)))
.thenReturn(Optional.of(expectedBulkResponse));
//When
testee.delete(session, mailbox, Lists.newArrayList(MESSAGE_UID, messageId2, messageId3, messageId4, messageId5));
//Then
- verify(elasticSearchIndexer).deleteMessages(eq(Lists.newArrayList(ELASTIC_SEARCH_ID, "12:2", "12:3", "12:4", "12:5")));
+ verify(elasticSearchIndexer).delete(eq(Lists.newArrayList(ELASTIC_SEARCH_ID, "12:2", "12:3", "12:4", "12:5")));
}
@Test
@@ -207,7 +207,7 @@ public class ElasticSearchListeningMessageSearchIndexTest {
when(mailbox.getMailboxId())
.thenReturn(MAILBOX_ID);
- when(elasticSearchIndexer.deleteMessages(any(List.class)))
+ when(elasticSearchIndexer.delete(any(List.class)))
.thenThrow(new ElasticsearchException(""));
//When
@@ -241,7 +241,7 @@ public class ElasticSearchListeningMessageSearchIndexTest {
//Then
ImmutableList<UpdatedRepresentation> expectedUpdatedRepresentations = ImmutableList.of(new UpdatedRepresentation(ELASTIC_SEARCH_ID, "json updated content"));
- verify(elasticSearchIndexer).updateMessages(expectedUpdatedRepresentations);
+ verify(elasticSearchIndexer).update(expectedUpdatedRepresentations);
}
@Test
@@ -259,7 +259,7 @@ public class ElasticSearchListeningMessageSearchIndexTest {
.thenReturn(MAILBOX_ID);
ImmutableList<UpdatedRepresentation> expectedUpdatedRepresentations = ImmutableList.of(new UpdatedRepresentation(ELASTIC_SEARCH_ID, "json updated content"));
- when(elasticSearchIndexer.updateMessages(expectedUpdatedRepresentations))
+ when(elasticSearchIndexer.update(expectedUpdatedRepresentations))
.thenThrow(new ElasticsearchException(""));
//When
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[09/13] james-project git commit: JAMES-2403 Introduce
ElasticSearchQuotaMailboxListener
Posted by bt...@apache.org.
JAMES-2403 Introduce ElasticSearchQuotaMailboxListener
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/f534186b
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/f534186b
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/f534186b
Branch: refs/heads/master
Commit: f534186be6e5679b02e76e4dcbbd1456f4e01be6
Parents: 86f192c
Author: Antoine Duprat <ad...@linagora.com>
Authored: Wed May 23 15:48:25 2018 +0200
Committer: benwa <bt...@linagora.com>
Committed: Mon May 28 08:05:35 2018 +0700
----------------------------------------------------------------------
.../plugin/quota-search-elasticsearch/pom.xml | 14 ++-
.../ElasticSearchQuotaMailboxListener.java | 80 +++++++++++++
.../ElasticSearchQuotaMailboxListenerTest.java | 113 +++++++++++++++++++
.../james/quota/search/QuotaSearchFixture.java | 36 ++++++
pom.xml | 6 +
5 files changed, 248 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/f534186b/mailbox/plugin/quota-search-elasticsearch/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/pom.xml b/mailbox/plugin/quota-search-elasticsearch/pom.xml
index 32b9f2f..79b9ef1 100644
--- a/mailbox/plugin/quota-search-elasticsearch/pom.xml
+++ b/mailbox/plugin/quota-search-elasticsearch/pom.xml
@@ -30,7 +30,7 @@
</parent>
<artifactId>apache-james-mailbox-quota-search-elasticsearch</artifactId>
- <name>Apache James :: Mailbox :: Plugin :: Quota Search :: ElasticSearcj</name>
+ <name>Apache James :: Mailbox :: Plugin :: Quota Search :: ElasticSearch</name>
<description>Apache James Mailbox ElasticSearch implementation for quota search</description>
<dependencies>
@@ -40,6 +40,12 @@
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
+ <artifactId>apache-james-backends-es</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
<artifactId>apache-james-mailbox-api</artifactId>
</dependency>
<dependency>
@@ -49,6 +55,12 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>apache-james-mailbox-quota-search</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
http://git-wip-us.apache.org/repos/asf/james-project/blob/f534186b/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListener.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListener.java b/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListener.java
new file mode 100644
index 0000000..b08ca97
--- /dev/null
+++ b/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListener.java
@@ -0,0 +1,80 @@
+/****************************************************************
+ * 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.quota.search.elasticsearch.events;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import org.apache.james.backends.es.ElasticSearchIndexer;
+import org.apache.james.mailbox.Event;
+import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.mailbox.MailboxSession.User;
+import org.apache.james.quota.search.elasticsearch.QuotaRatioElasticSearchConstants;
+import org.apache.james.quota.search.elasticsearch.json.QuotaRatioToElasticSearchJson;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+
+public class ElasticSearchQuotaMailboxListener implements MailboxListener {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ElasticSearchQuotaMailboxListener.class);
+
+ private final ElasticSearchIndexer indexer;
+ private final QuotaRatioToElasticSearchJson quotaRatioToElasticSearchJson;
+
+ @Inject
+ public ElasticSearchQuotaMailboxListener(
+ @Named(QuotaRatioElasticSearchConstants.InjectionNames.QUOTA_RATIO) ElasticSearchIndexer indexer,
+ QuotaRatioToElasticSearchJson quotaRatioToElasticSearchJson) {
+ this.indexer = indexer;
+ this.quotaRatioToElasticSearchJson = quotaRatioToElasticSearchJson;
+ }
+
+ @Override
+ public ListenerType getType() {
+ return ListenerType.ONCE;
+ }
+
+ @Override
+ public ExecutionMode getExecutionMode() {
+ return ExecutionMode.ASYNCHRONOUS;
+ }
+
+ @Override
+ public void event(Event event) {
+ try {
+ if (event instanceof QuotaUsageUpdatedEvent) {
+ handleEvent(getUser(event), (QuotaUsageUpdatedEvent) event);
+ }
+ } catch (Exception e) {
+ LOGGER.error("Can not index quota ratio", e);
+ }
+ }
+
+ private void handleEvent(User user, QuotaUsageUpdatedEvent event) throws JsonProcessingException {
+ indexer.index(user.getUserName(),
+ quotaRatioToElasticSearchJson.convertToJson(user.getUserName(), event));
+ }
+
+ private User getUser(Event event) {
+ return event.getSession()
+ .getUser();
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f534186b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java
new file mode 100644
index 0000000..afee385
--- /dev/null
+++ b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java
@@ -0,0 +1,113 @@
+/****************************************************************
+ * 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.quota.search.elasticsearch.events;
+
+import static org.apache.james.quota.search.QuotaSearchFixture.TestConstants.BOB_SESSION;
+import static org.apache.james.quota.search.QuotaSearchFixture.TestConstants.NOW;
+import static org.apache.james.quota.search.QuotaSearchFixture.TestConstants.QUOTAROOT;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
+
+import java.util.concurrent.Executors;
+
+import org.apache.james.backends.es.ElasticSearchIndexer;
+import org.apache.james.backends.es.EmbeddedElasticSearch;
+import org.apache.james.backends.es.IndexCreationFactory;
+import org.apache.james.backends.es.NodeMappingFactory;
+import org.apache.james.backends.es.utils.TestingClientProvider;
+import org.apache.james.mailbox.Event;
+import org.apache.james.mailbox.MailboxListener.QuotaUsageUpdatedEvent;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.quota.QuotaFixture.Counts;
+import org.apache.james.mailbox.quota.QuotaFixture.Sizes;
+import org.apache.james.quota.search.elasticsearch.QuotaRatioElasticSearchConstants;
+import org.apache.james.quota.search.elasticsearch.QuotaRatioMappingFactory;
+import org.apache.james.quota.search.elasticsearch.json.QuotaRatioToElasticSearchJson;
+import org.elasticsearch.action.search.SearchResponse;
+import org.elasticsearch.client.Client;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.RuleChain;
+import org.junit.rules.TemporaryFolder;
+
+public class ElasticSearchQuotaMailboxListenerTest {
+
+ private static final int BATCH_SIZE = 1;
+ private static final MailboxSession MAILBOX_SESSION = null;
+ private static final Event EVENT = () -> MAILBOX_SESSION;
+
+ private TemporaryFolder temporaryFolder = new TemporaryFolder();
+ private EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder, QuotaRatioElasticSearchConstants.DEFAULT_QUOTA_RATIO_INDEX);
+
+ @Rule
+ public RuleChain ruleChain = RuleChain.outerRule(temporaryFolder).around(embeddedElasticSearch);
+ private ElasticSearchQuotaMailboxListener quotaMailboxListener;
+ private Client client;
+
+ @Before
+ public void setUp() {
+ client = NodeMappingFactory.applyMapping(
+ new IndexCreationFactory()
+ .useIndex(QuotaRatioElasticSearchConstants.DEFAULT_QUOTA_RATIO_INDEX)
+ .addAlias(QuotaRatioElasticSearchConstants.DEFAULT_QUOTA_RATIO_READ_ALIAS)
+ .addAlias(QuotaRatioElasticSearchConstants.DEFAULT_QUOTA_RATIO_WRITE_ALIAS)
+ .createIndexAndAliases(new TestingClientProvider(embeddedElasticSearch.getNode()).get()),
+ QuotaRatioElasticSearchConstants.DEFAULT_QUOTA_RATIO_INDEX,
+ QuotaRatioElasticSearchConstants.QUOTA_RATIO_TYPE,
+ QuotaRatioMappingFactory.getMappingContent());
+
+ quotaMailboxListener = new ElasticSearchQuotaMailboxListener(
+ new ElasticSearchIndexer(client,
+ Executors.newSingleThreadExecutor(),
+ QuotaRatioElasticSearchConstants.DEFAULT_QUOTA_RATIO_WRITE_ALIAS,
+ QuotaRatioElasticSearchConstants.QUOTA_RATIO_TYPE,
+ BATCH_SIZE),
+ new QuotaRatioToElasticSearchJson());
+ }
+
+ @Test
+ public void eventShouldDoNothingWhenNoQuotaEvent() throws Exception {
+ quotaMailboxListener.event(EVENT);
+
+ embeddedElasticSearch.awaitForElasticSearch();
+
+ SearchResponse searchResponse = client.prepareSearch(QuotaRatioElasticSearchConstants.DEFAULT_QUOTA_RATIO_READ_ALIAS.getValue())
+ .setTypes(QuotaRatioElasticSearchConstants.QUOTA_RATIO_TYPE.getValue())
+ .setQuery(matchAllQuery())
+ .execute()
+ .get();
+ assertThat(searchResponse.getHits().totalHits()).isEqualTo(0);
+ }
+
+ @Test
+ public void eventShouldIndexEventWhenQuotaEvent() throws Exception {
+ quotaMailboxListener.event(new QuotaUsageUpdatedEvent(BOB_SESSION, QUOTAROOT, Counts._52_PERCENT, Sizes._55_PERCENT, NOW));
+
+ embeddedElasticSearch.awaitForElasticSearch();
+
+ SearchResponse searchResponse = client.prepareSearch(QuotaRatioElasticSearchConstants.DEFAULT_QUOTA_RATIO_READ_ALIAS.getValue())
+ .setTypes(QuotaRatioElasticSearchConstants.QUOTA_RATIO_TYPE.getValue())
+ .setQuery(matchAllQuery())
+ .execute()
+ .get();
+ assertThat(searchResponse.getHits().totalHits()).isEqualTo(1);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/f534186b/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaSearchFixture.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaSearchFixture.java b/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaSearchFixture.java
new file mode 100644
index 0000000..515a004
--- /dev/null
+++ b/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaSearchFixture.java
@@ -0,0 +1,36 @@
+/****************************************************************
+ * 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.quota.search;
+
+import java.time.Instant;
+import java.util.Optional;
+
+import org.apache.james.mailbox.mock.MockMailboxSession;
+import org.apache.james.mailbox.model.QuotaRoot;
+
+public interface QuotaSearchFixture {
+
+ interface TestConstants {
+ String BOB = "bob@domain";
+ MockMailboxSession BOB_SESSION = new MockMailboxSession(BOB);
+ Instant NOW = Instant.now();
+ QuotaRoot QUOTAROOT = QuotaRoot.quotaRoot("any", Optional.empty());
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f534186b/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index a968be1..3ee4ec4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -847,6 +847,12 @@
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
+ <artifactId>apache-james-mailbox-quota-mailing</artifactId>
+ <type>test-jar</type>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
<artifactId>apache-james-mailbox-spring</artifactId>
<version>${project.version}</version>
</dependency>
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[07/13] james-project git commit: JAMES-2403 Type safety for read and
write ElasticSearch alias
Posted by bt...@apache.org.
JAMES-2403 Type safety for read and write ElasticSearch alias
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/35b7ec7e
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/35b7ec7e
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/35b7ec7e
Branch: refs/heads/master
Commit: 35b7ec7ea32455c708e7ad375dfe81dc4c345c7c
Parents: 4f49aea
Author: benwa <bt...@linagora.com>
Authored: Thu May 24 11:50:31 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Mon May 28 08:05:35 2018 +0700
----------------------------------------------------------------------
.../james/backends/es/ElasticSearchIndexer.java | 2 +-
.../apache/james/backends/es/ReadAliasName.java | 26 ++++++++++++++++
.../james/backends/es/WriteAliasName.java | 26 ++++++++++++++++
.../MailboxElasticSearchConstants.java | 7 +++--
.../elasticsearch/MailboxIndexCreationUtil.java | 7 +++--
.../search/ElasticSearchSearcher.java | 3 +-
.../ElasticSearchQuotaSearcher.java | 3 +-
.../QuotaRatioElasticSearchConstants.java | 7 +++--
.../mailbox/ElasticSearchConfiguration.java | 31 ++++++++++----------
9 files changed, 85 insertions(+), 27 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/35b7ec7e/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchIndexer.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchIndexer.java b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchIndexer.java
index b7fb311..039b109 100644
--- a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchIndexer.java
+++ b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchIndexer.java
@@ -47,7 +47,7 @@ public class ElasticSearchIndexer {
private final TypeName typeName;
public ElasticSearchIndexer(Client client, ExecutorService executor,
- AliasName aliasName,
+ WriteAliasName aliasName,
TypeName typeName) {
this(client, executor, aliasName, typeName, DEFAULT_BATCH_SIZE);
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/35b7ec7e/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ReadAliasName.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ReadAliasName.java b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ReadAliasName.java
new file mode 100644
index 0000000..22c47d6
--- /dev/null
+++ b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ReadAliasName.java
@@ -0,0 +1,26 @@
+/****************************************************************
+ * 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.backends.es;
+
+public class ReadAliasName extends AliasName {
+ public ReadAliasName(String value) {
+ super(value);
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/35b7ec7e/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/WriteAliasName.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/WriteAliasName.java b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/WriteAliasName.java
new file mode 100644
index 0000000..4c829c9
--- /dev/null
+++ b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/WriteAliasName.java
@@ -0,0 +1,26 @@
+/****************************************************************
+ * 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.backends.es;
+
+public class WriteAliasName extends AliasName {
+ public WriteAliasName(String value) {
+ super(value);
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/35b7ec7e/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticSearchConstants.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticSearchConstants.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticSearchConstants.java
index c347738..79797f4 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticSearchConstants.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticSearchConstants.java
@@ -19,9 +19,10 @@
package org.apache.james.mailbox.elasticsearch;
-import org.apache.james.backends.es.AliasName;
import org.apache.james.backends.es.IndexName;
+import org.apache.james.backends.es.ReadAliasName;
import org.apache.james.backends.es.TypeName;
+import org.apache.james.backends.es.WriteAliasName;
public interface MailboxElasticSearchConstants {
@@ -29,8 +30,8 @@ public interface MailboxElasticSearchConstants {
String MAILBOX = "mailbox";
}
- AliasName DEFAULT_MAILBOX_WRITE_ALIAS = new AliasName("mailboxWriteAlias");
- AliasName DEFAULT_MAILBOX_READ_ALIAS = new AliasName("mailboxReadAlias");
+ WriteAliasName DEFAULT_MAILBOX_WRITE_ALIAS = new WriteAliasName("mailboxWriteAlias");
+ ReadAliasName DEFAULT_MAILBOX_READ_ALIAS = new ReadAliasName("mailboxReadAlias");
IndexName DEFAULT_MAILBOX_INDEX = new IndexName("mailbox_v1");
TypeName MESSAGE_TYPE = new TypeName("message");
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/35b7ec7e/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxIndexCreationUtil.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxIndexCreationUtil.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxIndexCreationUtil.java
index 1b92cec..89c7227 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxIndexCreationUtil.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxIndexCreationUtil.java
@@ -19,17 +19,18 @@
package org.apache.james.mailbox.elasticsearch;
-import org.apache.james.backends.es.AliasName;
import org.apache.james.backends.es.IndexCreationFactory;
import org.apache.james.backends.es.IndexName;
import org.apache.james.backends.es.NodeMappingFactory;
+import org.apache.james.backends.es.ReadAliasName;
+import org.apache.james.backends.es.WriteAliasName;
import org.elasticsearch.client.Client;
public class MailboxIndexCreationUtil {
public static Client prepareClient(Client client,
- AliasName readAlias,
- AliasName writeAlias,
+ ReadAliasName readAlias,
+ WriteAliasName writeAlias,
IndexName indexName) {
return NodeMappingFactory.applyMapping(
http://git-wip-us.apache.org/repos/asf/james-project/blob/35b7ec7e/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java
index 68b6a32..3b36de0 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java
@@ -24,6 +24,7 @@ import java.util.Optional;
import java.util.stream.Stream;
import org.apache.james.backends.es.AliasName;
+import org.apache.james.backends.es.ReadAliasName;
import org.apache.james.backends.es.TypeName;
import org.apache.james.backends.es.search.ScrollIterable;
import org.apache.james.mailbox.MessageUid;
@@ -62,7 +63,7 @@ public class ElasticSearchSearcher {
public ElasticSearchSearcher(Client client, QueryConverter queryConverter, int size,
MailboxId.Factory mailboxIdFactory, MessageId.Factory messageIdFactory,
- AliasName aliasName, TypeName typeName) {
+ ReadAliasName aliasName, TypeName typeName) {
this.client = client;
this.queryConverter = queryConverter;
this.size = size;
http://git-wip-us.apache.org/repos/asf/james-project/blob/35b7ec7e/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaSearcher.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaSearcher.java b/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaSearcher.java
index 7e0857b..21d55a8 100644
--- a/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaSearcher.java
+++ b/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaSearcher.java
@@ -27,6 +27,7 @@ import java.util.List;
import java.util.stream.Stream;
import org.apache.james.backends.es.AliasName;
+import org.apache.james.backends.es.ReadAliasName;
import org.apache.james.backends.es.search.ScrollIterable;
import org.apache.james.core.User;
import org.apache.james.quota.search.QuotaQuery;
@@ -46,7 +47,7 @@ public class ElasticSearchQuotaSearcher implements QuotaSearcher {
private final AliasName readAlias;
private final QuotaQueryConverter quotaQueryConverter;
- public ElasticSearchQuotaSearcher(Client client, AliasName readAlias) {
+ public ElasticSearchQuotaSearcher(Client client, ReadAliasName readAlias) {
this.client = client;
this.readAlias = readAlias;
this.quotaQueryConverter = new QuotaQueryConverter();
http://git-wip-us.apache.org/repos/asf/james-project/blob/35b7ec7e/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaRatioElasticSearchConstants.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaRatioElasticSearchConstants.java b/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaRatioElasticSearchConstants.java
index d2db3a0..6ce049f 100644
--- a/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaRatioElasticSearchConstants.java
+++ b/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaRatioElasticSearchConstants.java
@@ -19,9 +19,10 @@
package org.apache.james.quota.search.elasticsearch;
-import org.apache.james.backends.es.AliasName;
import org.apache.james.backends.es.IndexName;
+import org.apache.james.backends.es.ReadAliasName;
import org.apache.james.backends.es.TypeName;
+import org.apache.james.backends.es.WriteAliasName;
public interface QuotaRatioElasticSearchConstants {
@@ -29,8 +30,8 @@ public interface QuotaRatioElasticSearchConstants {
String QUOTA_RATIO = "quotaRatio";
}
- AliasName DEFAULT_QUOTA_RATIO_WRITE_ALIAS = new AliasName("quotaRatioWriteAlias");
- AliasName DEFAULT_QUOTA_RATIO_READ_ALIAS = new AliasName("quotaRatioReadAlias");
+ WriteAliasName DEFAULT_QUOTA_RATIO_WRITE_ALIAS = new WriteAliasName("quotaRatioWriteAlias");
+ ReadAliasName DEFAULT_QUOTA_RATIO_READ_ALIAS = new ReadAliasName("quotaRatioReadAlias");
IndexName DEFAULT_QUOTA_RATIO_INDEX = new IndexName("quota_ratio_v1");
TypeName QUOTA_RATIO_TYPE = new TypeName("quotaRatio");
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/35b7ec7e/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchConfiguration.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchConfiguration.java b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchConfiguration.java
index f4ed4c9..c19bd96 100644
--- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchConfiguration.java
+++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchConfiguration.java
@@ -26,8 +26,9 @@ import java.util.Optional;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
-import org.apache.james.backends.es.AliasName;
import org.apache.james.backends.es.IndexName;
+import org.apache.james.backends.es.ReadAliasName;
+import org.apache.james.backends.es.WriteAliasName;
import org.apache.james.mailbox.elasticsearch.IndexAttachments;
import org.apache.james.mailbox.elasticsearch.MailboxElasticSearchConstants;
import org.apache.james.util.Host;
@@ -80,8 +81,8 @@ public class ElasticSearchConfiguration {
int minDelay = configuration.getInt(ELASTICSEARCH_RETRY_CONNECTION_MIN_DELAY, DEFAULT_CONNECTION_MIN_DELAY);
IndexAttachments indexAttachments = provideIndexAttachments(configuration);
ImmutableList<Host> hosts = getHosts(configuration);
- AliasName readAlias = computeMailboxReadAlias(configuration);
- AliasName writeAlias = computeMailboxWriteAlias(configuration);
+ ReadAliasName readAlias = computeMailboxReadAlias(configuration);
+ WriteAliasName writeAlias = computeMailboxWriteAlias(configuration);
IndexName indexName = computeMailboxIndexName(configuration);
return new ElasticSearchConfiguration(
@@ -105,21 +106,21 @@ public class ElasticSearchConfiguration {
.orElse(MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX);
}
- public static AliasName computeMailboxWriteAlias(PropertiesConfiguration configuration) {
+ public static WriteAliasName computeMailboxWriteAlias(PropertiesConfiguration configuration) {
return OptionalUtils.or(
Optional.ofNullable(configuration.getString(ELASTICSEARCH_ALIAS_WRITE_MAILBOX_NAME))
- .map(AliasName::new),
+ .map(WriteAliasName::new),
Optional.ofNullable(configuration.getString(ELASTICSEARCH_ALIAS_WRITE_NAME))
- .map(AliasName::new))
+ .map(WriteAliasName::new))
.orElse(MailboxElasticSearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS);
}
- public static AliasName computeMailboxReadAlias(PropertiesConfiguration configuration) {
+ public static ReadAliasName computeMailboxReadAlias(PropertiesConfiguration configuration) {
return OptionalUtils.or(
Optional.ofNullable(configuration.getString(ELASTICSEARCH_ALIAS_READ_MAILBOX_NAME))
- .map(AliasName::new),
+ .map(ReadAliasName::new),
Optional.ofNullable(configuration.getString(ELASTICSEARCH_ALIAS_READ_NAME))
- .map(AliasName::new))
+ .map(ReadAliasName::new))
.orElse(MailboxElasticSearchConstants.DEFAULT_MAILBOX_READ_ALIAS);
}
@@ -167,16 +168,16 @@ public class ElasticSearchConfiguration {
private final ImmutableList<Host> hosts;
private final IndexName indexMailboxName;
- private final AliasName readAliasMailboxName;
- private final AliasName writeAliasMailboxName;
+ private final ReadAliasName readAliasMailboxName;
+ private final WriteAliasName writeAliasMailboxName;
private final int nbShards;
private final int nbReplica;
private final int minDelay;
private final int maxRetries;
private final IndexAttachments indexAttachment;
- public ElasticSearchConfiguration(ImmutableList<Host> hosts, IndexName indexMailboxName, AliasName readAliasMailboxName,
- AliasName writeAliasMailboxName, int nbShards, int nbReplica, int minDelay,
+ public ElasticSearchConfiguration(ImmutableList<Host> hosts, IndexName indexMailboxName, ReadAliasName readAliasMailboxName,
+ WriteAliasName writeAliasMailboxName, int nbShards, int nbReplica, int minDelay,
int maxRetries, IndexAttachments indexAttachment) {
this.hosts = hosts;
this.indexMailboxName = indexMailboxName;
@@ -197,11 +198,11 @@ public class ElasticSearchConfiguration {
return indexMailboxName;
}
- public AliasName getReadAliasMailboxName() {
+ public ReadAliasName getReadAliasMailboxName() {
return readAliasMailboxName;
}
- public AliasName getWriteAliasMailboxName() {
+ public WriteAliasName getWriteAliasMailboxName() {
return writeAliasMailboxName;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[11/13] james-project git commit: JAMES-2403 Provide a helper for
index/alias/mapping creation
Posted by bt...@apache.org.
JAMES-2403 Provide a helper for index/alias/mapping creation
We can do a similar refactoring in mailbox-elasticsearch
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/4f49aea9
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/4f49aea9
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/4f49aea9
Branch: refs/heads/master
Commit: 4f49aea96d344bd7ea0981edacd833633dda7bdb
Parents: dd95f7c
Author: benwa <bt...@linagora.com>
Authored: Thu May 24 11:32:14 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Mon May 28 08:05:35 2018 +0700
----------------------------------------------------------------------
.../elasticsearch/MailboxIndexCreationUtil.java | 52 ++++++++++++++++++++
.../ElasticSearchIntegrationTest.java | 13 +----
.../QuotaSearchIndexCreationUtil.java | 52 ++++++++++++++++++++
...ticSearchQuotaSearchTestSystemExtension.java | 13 +----
.../ElasticSearchQuotaMailboxListenerTest.java | 15 ++----
.../host/ElasticSearchHostSystem.java | 15 ++----
.../mailbox/ElasticSearchMailboxModule.java | 23 ++-------
.../james/modules/TestElasticSearchModule.java | 16 +-----
8 files changed, 121 insertions(+), 78 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/4f49aea9/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxIndexCreationUtil.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxIndexCreationUtil.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxIndexCreationUtil.java
new file mode 100644
index 0000000..1b92cec
--- /dev/null
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxIndexCreationUtil.java
@@ -0,0 +1,52 @@
+/****************************************************************
+ * 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.mailbox.elasticsearch;
+
+import org.apache.james.backends.es.AliasName;
+import org.apache.james.backends.es.IndexCreationFactory;
+import org.apache.james.backends.es.IndexName;
+import org.apache.james.backends.es.NodeMappingFactory;
+import org.elasticsearch.client.Client;
+
+public class MailboxIndexCreationUtil {
+
+ public static Client prepareClient(Client client,
+ AliasName readAlias,
+ AliasName writeAlias,
+ IndexName indexName) {
+
+ return NodeMappingFactory.applyMapping(
+ new IndexCreationFactory()
+ .useIndex(indexName)
+ .addAlias(readAlias)
+ .addAlias(writeAlias)
+ .createIndexAndAliases(client),
+ indexName,
+ MailboxElasticSearchConstants.MESSAGE_TYPE,
+ MailboxMappingFactory.getMappingContent());
+ }
+
+ public static Client prepareDefaultClient(Client client) {
+ return prepareClient(client,
+ MailboxElasticSearchConstants.DEFAULT_MAILBOX_READ_ALIAS,
+ MailboxElasticSearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS,
+ MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX);
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/4f49aea9/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
index 444422f..e8b8aae 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
@@ -27,8 +27,6 @@ import java.util.concurrent.Executors;
import org.apache.james.backends.es.ElasticSearchIndexer;
import org.apache.james.backends.es.EmbeddedElasticSearch;
-import org.apache.james.backends.es.IndexCreationFactory;
-import org.apache.james.backends.es.NodeMappingFactory;
import org.apache.james.backends.es.utils.TestingClientProvider;
import org.apache.james.mailbox.MessageManager;
import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
@@ -93,15 +91,8 @@ public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest
@Override
protected void initializeMailboxManager() throws Exception {
- Client client = NodeMappingFactory.applyMapping(
- new IndexCreationFactory()
- .useIndex(MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX)
- .addAlias(MailboxElasticSearchConstants.DEFAULT_MAILBOX_READ_ALIAS)
- .addAlias(MailboxElasticSearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS)
- .createIndexAndAliases(new TestingClientProvider(embeddedElasticSearch.getNode()).get()),
- MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX,
- MailboxElasticSearchConstants.MESSAGE_TYPE,
- MailboxMappingFactory.getMappingContent());
+ Client client = MailboxIndexCreationUtil.prepareDefaultClient(
+ new TestingClientProvider(embeddedElasticSearch.getNode()).get());
storeMailboxManager = new InMemoryIntegrationResources()
.createMailboxManager(new SimpleGroupMembershipResolver());
http://git-wip-us.apache.org/repos/asf/james-project/blob/4f49aea9/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaSearchIndexCreationUtil.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaSearchIndexCreationUtil.java b/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaSearchIndexCreationUtil.java
new file mode 100644
index 0000000..98a4698
--- /dev/null
+++ b/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/QuotaSearchIndexCreationUtil.java
@@ -0,0 +1,52 @@
+/****************************************************************
+ * 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.quota.search.elasticsearch;
+
+import org.apache.james.backends.es.AliasName;
+import org.apache.james.backends.es.IndexCreationFactory;
+import org.apache.james.backends.es.IndexName;
+import org.apache.james.backends.es.NodeMappingFactory;
+import org.elasticsearch.client.Client;
+
+public class QuotaSearchIndexCreationUtil {
+
+ public static Client prepareClient(Client client,
+ AliasName readAlias,
+ AliasName writeAlias,
+ IndexName indexName) {
+
+ return NodeMappingFactory.applyMapping(
+ new IndexCreationFactory()
+ .useIndex(indexName)
+ .addAlias(readAlias)
+ .addAlias(writeAlias)
+ .createIndexAndAliases(client),
+ indexName,
+ QuotaRatioElasticSearchConstants.QUOTA_RATIO_TYPE,
+ QuotaRatioMappingFactory.getMappingContent());
+ }
+
+ public static Client prepareDefaultClient(Client client) {
+ return prepareClient(client,
+ QuotaRatioElasticSearchConstants.DEFAULT_QUOTA_RATIO_READ_ALIAS,
+ QuotaRatioElasticSearchConstants.DEFAULT_QUOTA_RATIO_WRITE_ALIAS,
+ QuotaRatioElasticSearchConstants.DEFAULT_QUOTA_RATIO_INDEX);
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/4f49aea9/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaSearchTestSystemExtension.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaSearchTestSystemExtension.java b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaSearchTestSystemExtension.java
index d4dc2a2..0c45f70 100644
--- a/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaSearchTestSystemExtension.java
+++ b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/ElasticSearchQuotaSearchTestSystemExtension.java
@@ -25,8 +25,6 @@ import java.util.concurrent.Executors;
import org.apache.james.backends.es.ElasticSearchIndexer;
import org.apache.james.backends.es.EmbeddedElasticSearch;
-import org.apache.james.backends.es.IndexCreationFactory;
-import org.apache.james.backends.es.NodeMappingFactory;
import org.apache.james.backends.es.utils.TestingClientProvider;
import org.apache.james.dnsservice.api.DNSService;
import org.apache.james.domainlist.memory.MemoryDomainList;
@@ -59,15 +57,8 @@ public class ElasticSearchQuotaSearchTestSystemExtension implements ParameterRes
@Override
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
try {
- Client client = NodeMappingFactory.applyMapping(
- new IndexCreationFactory()
- .useIndex(QuotaRatioElasticSearchConstants.DEFAULT_QUOTA_RATIO_INDEX)
- .addAlias(QuotaRatioElasticSearchConstants.DEFAULT_QUOTA_RATIO_READ_ALIAS)
- .addAlias(QuotaRatioElasticSearchConstants.DEFAULT_QUOTA_RATIO_WRITE_ALIAS)
- .createIndexAndAliases(new TestingClientProvider(embeddedElasticSearch.getNode()).get()),
- QuotaRatioElasticSearchConstants.DEFAULT_QUOTA_RATIO_INDEX,
- QuotaRatioElasticSearchConstants.QUOTA_RATIO_TYPE,
- QuotaRatioMappingFactory.getMappingContent());
+ Client client = QuotaSearchIndexCreationUtil.prepareDefaultClient(
+ new TestingClientProvider(embeddedElasticSearch.getNode()).get());
InMemoryIntegrationResources.Resources resources = new InMemoryIntegrationResources().createResources(new SimpleGroupMembershipResolver());
http://git-wip-us.apache.org/repos/asf/james-project/blob/4f49aea9/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java
index afee385..076e956 100644
--- a/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java
+++ b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java
@@ -29,8 +29,6 @@ import java.util.concurrent.Executors;
import org.apache.james.backends.es.ElasticSearchIndexer;
import org.apache.james.backends.es.EmbeddedElasticSearch;
-import org.apache.james.backends.es.IndexCreationFactory;
-import org.apache.james.backends.es.NodeMappingFactory;
import org.apache.james.backends.es.utils.TestingClientProvider;
import org.apache.james.mailbox.Event;
import org.apache.james.mailbox.MailboxListener.QuotaUsageUpdatedEvent;
@@ -38,7 +36,7 @@ import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.quota.QuotaFixture.Counts;
import org.apache.james.mailbox.quota.QuotaFixture.Sizes;
import org.apache.james.quota.search.elasticsearch.QuotaRatioElasticSearchConstants;
-import org.apache.james.quota.search.elasticsearch.QuotaRatioMappingFactory;
+import org.apache.james.quota.search.elasticsearch.QuotaSearchIndexCreationUtil;
import org.apache.james.quota.search.elasticsearch.json.QuotaRatioToElasticSearchJson;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.Client;
@@ -64,15 +62,8 @@ public class ElasticSearchQuotaMailboxListenerTest {
@Before
public void setUp() {
- client = NodeMappingFactory.applyMapping(
- new IndexCreationFactory()
- .useIndex(QuotaRatioElasticSearchConstants.DEFAULT_QUOTA_RATIO_INDEX)
- .addAlias(QuotaRatioElasticSearchConstants.DEFAULT_QUOTA_RATIO_READ_ALIAS)
- .addAlias(QuotaRatioElasticSearchConstants.DEFAULT_QUOTA_RATIO_WRITE_ALIAS)
- .createIndexAndAliases(new TestingClientProvider(embeddedElasticSearch.getNode()).get()),
- QuotaRatioElasticSearchConstants.DEFAULT_QUOTA_RATIO_INDEX,
- QuotaRatioElasticSearchConstants.QUOTA_RATIO_TYPE,
- QuotaRatioMappingFactory.getMappingContent());
+ client = QuotaSearchIndexCreationUtil.prepareDefaultClient(
+ new TestingClientProvider(embeddedElasticSearch.getNode()).get());
quotaMailboxListener = new ElasticSearchQuotaMailboxListener(
new ElasticSearchIndexer(client,
http://git-wip-us.apache.org/repos/asf/james-project/blob/4f49aea9/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java b/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
index cc8af21..1d05e91 100644
--- a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
+++ b/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
@@ -28,8 +28,6 @@ import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.NotImplementedException;
import org.apache.james.backends.es.ElasticSearchIndexer;
import org.apache.james.backends.es.EmbeddedElasticSearch;
-import org.apache.james.backends.es.IndexCreationFactory;
-import org.apache.james.backends.es.NodeMappingFactory;
import org.apache.james.backends.es.utils.TestingClientProvider;
import org.apache.james.imap.api.process.ImapProcessor;
import org.apache.james.imap.encode.main.DefaultImapEncoderFactory;
@@ -39,7 +37,7 @@ import org.apache.james.mailbox.MailboxManager;
import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
import org.apache.james.mailbox.elasticsearch.IndexAttachments;
import org.apache.james.mailbox.elasticsearch.MailboxElasticSearchConstants;
-import org.apache.james.mailbox.elasticsearch.MailboxMappingFactory;
+import org.apache.james.mailbox.elasticsearch.MailboxIndexCreationUtil;
import org.apache.james.mailbox.elasticsearch.events.ElasticSearchListeningMessageSearchIndex;
import org.apache.james.mailbox.elasticsearch.json.MessageToElasticSearchJson;
import org.apache.james.mailbox.elasticsearch.query.CriterionConverter;
@@ -89,15 +87,8 @@ public class ElasticSearchHostSystem extends JamesImapHostSystem {
}
private void initFields() throws MailboxException {
- Client client = NodeMappingFactory.applyMapping(
- new IndexCreationFactory()
- .useIndex(MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX)
- .addAlias(MailboxElasticSearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS)
- .addAlias(MailboxElasticSearchConstants.DEFAULT_MAILBOX_READ_ALIAS)
- .createIndexAndAliases(new TestingClientProvider(embeddedElasticSearch.getNode()).get()),
- MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX,
- MailboxElasticSearchConstants.MESSAGE_TYPE,
- MailboxMappingFactory.getMappingContent());
+ Client client = MailboxIndexCreationUtil.prepareDefaultClient(
+ new TestingClientProvider(embeddedElasticSearch.getNode()).get());
InMemoryMailboxSessionMapperFactory factory = new InMemoryMailboxSessionMapperFactory();
InMemoryMessageId.Factory messageIdFactory = new InMemoryMessageId.Factory();
http://git-wip-us.apache.org/repos/asf/james-project/blob/4f49aea9/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java
index a530529..27baee3 100644
--- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java
+++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java
@@ -33,11 +33,9 @@ import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.james.backends.es.ClientProviderImpl;
import org.apache.james.backends.es.ElasticSearchIndexer;
-import org.apache.james.backends.es.IndexCreationFactory;
-import org.apache.james.backends.es.NodeMappingFactory;
import org.apache.james.mailbox.elasticsearch.IndexAttachments;
import org.apache.james.mailbox.elasticsearch.MailboxElasticSearchConstants;
-import org.apache.james.mailbox.elasticsearch.MailboxMappingFactory;
+import org.apache.james.mailbox.elasticsearch.MailboxIndexCreationUtil;
import org.apache.james.mailbox.elasticsearch.events.ElasticSearchListeningMessageSearchIndex;
import org.apache.james.mailbox.elasticsearch.query.QueryConverter;
import org.apache.james.mailbox.elasticsearch.search.ElasticSearchSearcher;
@@ -126,25 +124,14 @@ public class ElasticSearchMailboxModule extends AbstractModule {
Client client = ClientProviderImpl.fromHosts(configuration.getHosts()).get();
- createMailboxIndexCreationFactory(configuration).createIndexAndAliases(client);
-
- NodeMappingFactory.applyMapping(client,
- configuration.getIndexMailboxName(),
- MailboxElasticSearchConstants.MESSAGE_TYPE,
- MailboxMappingFactory.getMappingContent());
+ MailboxIndexCreationUtil.prepareClient(client,
+ configuration.getReadAliasMailboxName(),
+ configuration.getWriteAliasMailboxName(),
+ configuration.getIndexMailboxName());
return client;
}
- protected IndexCreationFactory createMailboxIndexCreationFactory(ElasticSearchConfiguration configuration) {
- return new IndexCreationFactory()
- .useIndex(configuration.getIndexMailboxName())
- .addAlias(configuration.getReadAliasMailboxName())
- .addAlias(configuration.getWriteAliasMailboxName())
- .nbShards(configuration.getNbShards())
- .nbReplica(configuration.getNbReplica());
- }
-
@Provides
@Singleton
public IndexAttachments provideIndexAttachments(ElasticSearchConfiguration configuration) {
http://git-wip-us.apache.org/repos/asf/james-project/blob/4f49aea9/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
index 8a35f9a..e8e41d7 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
@@ -22,11 +22,8 @@ package org.apache.james.modules;
import javax.inject.Singleton;
import org.apache.james.backends.es.EmbeddedElasticSearch;
-import org.apache.james.backends.es.IndexCreationFactory;
-import org.apache.james.backends.es.NodeMappingFactory;
import org.apache.james.backends.es.utils.TestingClientProvider;
-import org.apache.james.mailbox.elasticsearch.MailboxElasticSearchConstants;
-import org.apache.james.mailbox.elasticsearch.MailboxMappingFactory;
+import org.apache.james.mailbox.elasticsearch.MailboxIndexCreationUtil;
import org.elasticsearch.client.Client;
import com.google.inject.AbstractModule;
@@ -49,15 +46,6 @@ public class TestElasticSearchModule extends AbstractModule {
@Singleton
protected Client provideClientProvider() {
Client client = new TestingClientProvider(embeddedElasticSearch.getNode()).get();
-
- new IndexCreationFactory()
- .useIndex(MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX)
- .addAlias(MailboxElasticSearchConstants.DEFAULT_MAILBOX_READ_ALIAS)
- .addAlias(MailboxElasticSearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS)
- .createIndexAndAliases(client);
- return NodeMappingFactory.applyMapping(client,
- MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX,
- MailboxElasticSearchConstants.MESSAGE_TYPE,
- MailboxMappingFactory.getMappingContent());
+ return MailboxIndexCreationUtil.prepareDefaultClient(client);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[08/13] james-project git commit: JAMES-2403 Introduce
QuotaRatioAsJson
Posted by bt...@apache.org.
JAMES-2403 Introduce QuotaRatioAsJson
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/b28fdf99
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/b28fdf99
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/b28fdf99
Branch: refs/heads/master
Commit: b28fdf993ffeccd6ccf962f50579e5d4f1b920c2
Parents: 74b87be
Author: Antoine Duprat <ad...@linagora.com>
Authored: Wed May 23 13:51:53 2018 +0200
Committer: benwa <bt...@linagora.com>
Committed: Mon May 28 08:05:35 2018 +0700
----------------------------------------------------------------------
.../plugin/quota-search-elasticsearch/pom.xml | 28 +++++
.../elasticsearch/json/QuotaRatioAsJson.java | 118 +++++++++++++++++++
.../json/QuotaRatioAsJsonTest.java | 83 +++++++++++++
3 files changed, 229 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/b28fdf99/mailbox/plugin/quota-search-elasticsearch/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/pom.xml b/mailbox/plugin/quota-search-elasticsearch/pom.xml
index 1aa3cc0..2cd0d2f 100644
--- a/mailbox/plugin/quota-search-elasticsearch/pom.xml
+++ b/mailbox/plugin/quota-search-elasticsearch/pom.xml
@@ -38,6 +38,34 @@
<groupId>${project.groupId}</groupId>
<artifactId>apache-james-backends-es</artifactId>
</dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.datatype</groupId>
+ <artifactId>jackson-datatype-jdk8</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>nl.jqno.equalsverifier</groupId>
+ <artifactId>equalsverifier</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.platform</groupId>
+ <artifactId>junit-platform-launcher</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
http://git-wip-us.apache.org/repos/asf/james-project/blob/b28fdf99/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioAsJson.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioAsJson.java b/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioAsJson.java
new file mode 100644
index 0000000..ec8e597
--- /dev/null
+++ b/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioAsJson.java
@@ -0,0 +1,118 @@
+/****************************************************************
+ * 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.quota.search.elasticsearch.json;
+
+import java.util.Objects;
+import java.util.Optional;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+
+public class QuotaRatioAsJson {
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static class Builder {
+
+ private String user;
+ private Optional<String> domain;
+ private Double quotaRatio;
+
+ private Builder() {
+ domain = Optional.empty();
+ }
+
+ public Builder user(String user) {
+ this.user = user;
+ return this;
+ }
+
+ public Builder domain(Optional<String> domain) {
+ this.domain = domain;
+ return this;
+ }
+
+ public Builder quotaRatio(double quotaRatio) {
+ this.quotaRatio = quotaRatio;
+ return this;
+ }
+
+ public QuotaRatioAsJson build() {
+ Preconditions.checkState(!Strings.isNullOrEmpty(user), "'user' is mandatory");
+ Preconditions.checkNotNull(quotaRatio, "'quotaRatio' is mandatory");
+
+ return new QuotaRatioAsJson(user, domain, quotaRatio);
+ }
+ }
+
+ private final String user;
+ private final Optional<String> domain;
+ private final double quotaRatio;
+
+ private QuotaRatioAsJson(String user, Optional<String> domain, double quotaRatio) {
+ this.user = user;
+ this.domain = domain;
+ this.quotaRatio = quotaRatio;
+ }
+
+ @JsonProperty(JsonMessageConstants.USER)
+ public String getUser() {
+ return user;
+ }
+
+ @JsonProperty(JsonMessageConstants.DOMAIN)
+ public Optional<String> getDomain() {
+ return domain;
+ }
+
+ @JsonProperty(JsonMessageConstants.QUOTA_RATIO)
+ public double getQuotaRatio() {
+ return quotaRatio;
+ }
+
+ @Override
+ public final boolean equals(Object o) {
+ if (o instanceof QuotaRatioAsJson) {
+ QuotaRatioAsJson that = (QuotaRatioAsJson) o;
+
+ return Objects.equals(this.quotaRatio, that.quotaRatio)
+ && Objects.equals(this.user, that.user)
+ && Objects.equals(this.domain, that.domain);
+ }
+ return false;
+ }
+
+ @Override
+ public final int hashCode() {
+ return Objects.hash(user, domain, quotaRatio);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("quotaRatio", quotaRatio)
+ .add("user", user)
+ .add("domain", domain)
+ .toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/b28fdf99/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioAsJsonTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioAsJsonTest.java b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioAsJsonTest.java
new file mode 100644
index 0000000..e0b9c14
--- /dev/null
+++ b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioAsJsonTest.java
@@ -0,0 +1,83 @@
+/****************************************************************
+ * 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.quota.search.elasticsearch.json;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.util.Optional;
+
+import org.junit.jupiter.api.Test;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+
+public class QuotaRatioAsJsonTest {
+
+ @Test
+ public void shouldMatchBeanContract() {
+ EqualsVerifier.forClass(QuotaRatioAsJson.class)
+ .allFieldsShouldBeUsed()
+ .verify();
+ }
+
+ @Test
+ public void buildShouldThrownWhenUserIsNull() {
+ assertThatThrownBy(() -> QuotaRatioAsJson.builder()
+ .build())
+ .isInstanceOf(IllegalStateException.class);
+ }
+
+ @Test
+ public void buildShouldThrownWhenUserIsEmpty() {
+ assertThatThrownBy(() -> QuotaRatioAsJson.builder()
+ .user("")
+ .build())
+ .isInstanceOf(IllegalStateException.class);
+ }
+
+ @Test
+ public void buildShouldThrownWhenQuotaRatioIsNull() {
+ assertThatThrownBy(() -> QuotaRatioAsJson.builder()
+ .user("user")
+ .build())
+ .isInstanceOf(NullPointerException.class);
+ }
+
+ @Test
+ public void getDomainShouldReturnEmptyWhenNone() {
+ QuotaRatioAsJson quotaRatioAsJson = QuotaRatioAsJson.builder()
+ .user("user")
+ .quotaRatio(0.3)
+ .build();
+
+ assertThat(quotaRatioAsJson.getDomain()).isEmpty();
+ }
+
+ @Test
+ public void getDomainShouldReturnTheDomainWhenGiven() {
+ String domain = "domain";
+ QuotaRatioAsJson quotaRatioAsJson = QuotaRatioAsJson.builder()
+ .user("user")
+ .domain(Optional.of(domain))
+ .quotaRatio(0.2)
+ .build();
+
+ assertThat(quotaRatioAsJson.getDomain()).contains(domain);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[13/13] james-project git commit: JAMES-2403 Retrieving the max ratio
should be defined once
Posted by bt...@apache.org.
JAMES-2403 Retrieving the max ratio should be defined once
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/f8b587a7
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/f8b587a7
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/f8b587a7
Branch: refs/heads/master
Commit: f8b587a7a5d76d3da614a07b95e69c1fe07ea5d5
Parents: 95c4423
Author: Antoine Duprat <ad...@linagora.com>
Authored: Thu May 24 13:27:13 2018 +0200
Committer: benwa <bt...@linagora.com>
Committed: Mon May 28 08:05:36 2018 +0700
----------------------------------------------------------------------
.../apache/james/mailbox/model/QuotaRatio.java | 80 ++++++++++++++++++++
.../james/mailbox/model/QuotaRatioTest.java | 79 +++++++++++++++++++
.../elasticsearch/json/QuotaRatioAsJson.java | 14 ++--
.../json/QuotaRatioToElasticSearchJson.java | 5 +-
.../json/QuotaRatioAsJsonTest.java | 29 ++++++-
.../quota/search/scanning/ClauseConverter.java | 3 +-
.../james/webadmin/dto/OccupationRatioDTO.java | 10 ++-
7 files changed, 205 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/f8b587a7/mailbox/api/src/main/java/org/apache/james/mailbox/model/QuotaRatio.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/QuotaRatio.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/QuotaRatio.java
new file mode 100644
index 0000000..5ba6bf1
--- /dev/null
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/QuotaRatio.java
@@ -0,0 +1,80 @@
+/****************************************************************
+ * 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.mailbox.model;
+
+import java.util.Objects;
+
+import org.apache.james.mailbox.quota.QuotaCount;
+import org.apache.james.mailbox.quota.QuotaSize;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Preconditions;
+
+public class QuotaRatio {
+
+ public static QuotaRatio from(Quota<QuotaSize> quotaSize, Quota<QuotaCount> quotaCount) {
+ return new QuotaRatio(quotaSize, quotaCount);
+ }
+
+ private final Quota<QuotaSize> quotaSize;
+ private final Quota<QuotaCount> quotaCount;
+
+ private QuotaRatio(Quota<QuotaSize> quotaSize, Quota<QuotaCount> quotaCount) {
+ Preconditions.checkNotNull(quotaSize, "'quotaSize' is mandatory");
+ Preconditions.checkNotNull(quotaCount, "'quotaCount' is mandatory");
+ this.quotaSize = quotaSize;
+ this.quotaCount = quotaCount;
+ }
+
+ public Quota<QuotaSize> getQuotaSize() {
+ return quotaSize;
+ }
+
+ public Quota<QuotaCount> getQuotaCount() {
+ return quotaCount;
+ }
+
+ public double max() {
+ return Math.max(quotaSize.getRatio(), quotaCount.getRatio());
+ }
+
+ @Override
+ public final boolean equals(Object o) {
+ if (o instanceof QuotaRatio) {
+ QuotaRatio quotaRatio = (QuotaRatio) o;
+
+ return Objects.equals(this.quotaSize, quotaRatio.quotaSize)
+ && Objects.equals(this.quotaCount, quotaRatio.quotaCount);
+ }
+ return false;
+ }
+
+ @Override
+ public final int hashCode() {
+ return Objects.hash(quotaSize, quotaCount);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("quotaSize", quotaSize)
+ .add("quotaCount", quotaCount)
+ .toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f8b587a7/mailbox/api/src/test/java/org/apache/james/mailbox/model/QuotaRatioTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/QuotaRatioTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/QuotaRatioTest.java
new file mode 100644
index 0000000..182caf6
--- /dev/null
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/QuotaRatioTest.java
@@ -0,0 +1,79 @@
+/****************************************************************
+ * 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.mailbox.model;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.apache.james.mailbox.quota.QuotaCount;
+import org.apache.james.mailbox.quota.QuotaSize;
+import org.junit.jupiter.api.Test;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+
+public class QuotaRatioTest {
+
+ private static final Quota<QuotaSize> QUOTA_SIZE = Quota.<QuotaSize> builder()
+ .used(QuotaSize.size(15))
+ .computedLimit(QuotaSize.size(60))
+ .build();
+ private static final Quota<QuotaCount> QUOTA_COUNT = Quota.<QuotaCount> builder()
+ .used(QuotaCount.count(1))
+ .computedLimit(QuotaCount.count(2))
+ .build();
+
+ @Test
+ public void shouldMatchBeanContact() {
+ EqualsVerifier.forClass(QuotaRatio.class)
+ .allFieldsShouldBeUsed()
+ .verify();
+ }
+
+ @Test
+ public void quotaRatioShouldThrowWhenQuotaSizeIsNull() {
+ assertThatThrownBy(() -> QuotaRatio.from(null, QUOTA_COUNT))
+ .isInstanceOf(NullPointerException.class);
+ }
+
+ @Test
+ public void quotaRatioShouldThrowWhenQuotaCountIsNull() {
+ assertThatThrownBy(() -> QuotaRatio.from(QUOTA_SIZE, null))
+ .isInstanceOf(NullPointerException.class);
+ }
+
+ @Test
+ public void quotaSizeShouldReturnTheQuotaSize() {
+ QuotaRatio quotaRatio = QuotaRatio.from(QUOTA_SIZE, QUOTA_COUNT);
+ assertThat(quotaRatio.getQuotaSize()).isEqualTo(QUOTA_SIZE);
+ }
+
+ @Test
+ public void quotaCountShouldReturnTheQuotaCount() {
+ QuotaRatio quotaRatio = QuotaRatio.from(QUOTA_SIZE, QUOTA_COUNT);
+ assertThat(quotaRatio.getQuotaCount()).isEqualTo(QUOTA_COUNT);
+ }
+
+ @Test
+ public void maxShouldReturnTheMaxRatio() {
+ double max = QuotaRatio.from(QUOTA_SIZE, QUOTA_COUNT)
+ .max();
+
+ assertThat(max).isEqualTo(0.5);
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f8b587a7/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioAsJson.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioAsJson.java b/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioAsJson.java
index ec8e597..4084727 100644
--- a/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioAsJson.java
+++ b/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioAsJson.java
@@ -21,6 +21,8 @@ package org.apache.james.quota.search.elasticsearch.json;
import java.util.Objects;
import java.util.Optional;
+import org.apache.james.mailbox.model.QuotaRatio;
+
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
@@ -36,7 +38,7 @@ public class QuotaRatioAsJson {
private String user;
private Optional<String> domain;
- private Double quotaRatio;
+ private QuotaRatio quotaRatio;
private Builder() {
domain = Optional.empty();
@@ -52,7 +54,7 @@ public class QuotaRatioAsJson {
return this;
}
- public Builder quotaRatio(double quotaRatio) {
+ public Builder quotaRatio(QuotaRatio quotaRatio) {
this.quotaRatio = quotaRatio;
return this;
}
@@ -67,9 +69,9 @@ public class QuotaRatioAsJson {
private final String user;
private final Optional<String> domain;
- private final double quotaRatio;
+ private final QuotaRatio quotaRatio;
- private QuotaRatioAsJson(String user, Optional<String> domain, double quotaRatio) {
+ private QuotaRatioAsJson(String user, Optional<String> domain, QuotaRatio quotaRatio) {
this.user = user;
this.domain = domain;
this.quotaRatio = quotaRatio;
@@ -86,8 +88,8 @@ public class QuotaRatioAsJson {
}
@JsonProperty(JsonMessageConstants.QUOTA_RATIO)
- public double getQuotaRatio() {
- return quotaRatio;
+ public double getMaxQuotaRatio() {
+ return quotaRatio.max();
}
@Override
http://git-wip-us.apache.org/repos/asf/james-project/blob/f8b587a7/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioToElasticSearchJson.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioToElasticSearchJson.java b/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioToElasticSearchJson.java
index ad8f975..a03577f 100644
--- a/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioToElasticSearchJson.java
+++ b/mailbox/plugin/quota-search-elasticsearch/src/main/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioToElasticSearchJson.java
@@ -23,6 +23,7 @@ import javax.inject.Inject;
import org.apache.james.core.Domain;
import org.apache.james.mailbox.MailboxListener.QuotaUsageUpdatedEvent;
+import org.apache.james.mailbox.model.QuotaRatio;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -42,9 +43,7 @@ public class QuotaRatioToElasticSearchJson {
return mapper.writeValueAsString(QuotaRatioAsJson.builder()
.user(user)
.domain(event.getQuotaRoot().getDomain().map(Domain::asString))
- .quotaRatio(Math.max(
- event.getCountQuota().getRatio(),
- event.getSizeQuota().getRatio()))
+ .quotaRatio(QuotaRatio.from(event.getSizeQuota(), event.getCountQuota()))
.build());
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f8b587a7/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioAsJsonTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioAsJsonTest.java b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioAsJsonTest.java
index e0b9c14..fb16937 100644
--- a/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioAsJsonTest.java
+++ b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioAsJsonTest.java
@@ -23,12 +23,25 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.util.Optional;
+import org.apache.james.mailbox.model.Quota;
+import org.apache.james.mailbox.model.QuotaRatio;
+import org.apache.james.mailbox.quota.QuotaCount;
+import org.apache.james.mailbox.quota.QuotaSize;
import org.junit.jupiter.api.Test;
import nl.jqno.equalsverifier.EqualsVerifier;
public class QuotaRatioAsJsonTest {
+ private static final Quota<QuotaSize> QUOTA_SIZE = Quota.<QuotaSize> builder()
+ .used(QuotaSize.size(15))
+ .computedLimit(QuotaSize.size(60))
+ .build();
+ private static final Quota<QuotaCount> QUOTA_COUNT = Quota.<QuotaCount> builder()
+ .used(QuotaCount.count(1))
+ .computedLimit(QuotaCount.count(2))
+ .build();
+
@Test
public void shouldMatchBeanContract() {
EqualsVerifier.forClass(QuotaRatioAsJson.class)
@@ -63,7 +76,7 @@ public class QuotaRatioAsJsonTest {
public void getDomainShouldReturnEmptyWhenNone() {
QuotaRatioAsJson quotaRatioAsJson = QuotaRatioAsJson.builder()
.user("user")
- .quotaRatio(0.3)
+ .quotaRatio(QuotaRatio.from(QUOTA_SIZE, QUOTA_COUNT))
.build();
assertThat(quotaRatioAsJson.getDomain()).isEmpty();
@@ -75,9 +88,21 @@ public class QuotaRatioAsJsonTest {
QuotaRatioAsJson quotaRatioAsJson = QuotaRatioAsJson.builder()
.user("user")
.domain(Optional.of(domain))
- .quotaRatio(0.2)
+ .quotaRatio(QuotaRatio.from(QUOTA_SIZE, QUOTA_COUNT))
.build();
assertThat(quotaRatioAsJson.getDomain()).contains(domain);
}
+
+ @Test
+ public void getMaxQuotaRatioShouldReturnTheMaxQuotaRatio() {
+ String domain = "domain";
+ QuotaRatioAsJson quotaRatioAsJson = QuotaRatioAsJson.builder()
+ .user("user")
+ .domain(Optional.of(domain))
+ .quotaRatio(QuotaRatio.from(QUOTA_SIZE, QUOTA_COUNT))
+ .build();
+
+ assertThat(quotaRatioAsJson.getMaxQuotaRatio()).isEqualTo(0.5);
+ }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f8b587a7/mailbox/plugin/quota-search-scanning/src/main/java/org/apache/james/quota/search/scanning/ClauseConverter.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-scanning/src/main/java/org/apache/james/quota/search/scanning/ClauseConverter.java b/mailbox/plugin/quota-search-scanning/src/main/java/org/apache/james/quota/search/scanning/ClauseConverter.java
index f1d9035..c527a70 100644
--- a/mailbox/plugin/quota-search-scanning/src/main/java/org/apache/james/quota/search/scanning/ClauseConverter.java
+++ b/mailbox/plugin/quota-search-scanning/src/main/java/org/apache/james/quota/search/scanning/ClauseConverter.java
@@ -28,6 +28,7 @@ import javax.inject.Inject;
import org.apache.james.core.User;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.model.Quota;
+import org.apache.james.mailbox.model.QuotaRatio;
import org.apache.james.mailbox.model.QuotaRoot;
import org.apache.james.mailbox.quota.QuotaCount;
import org.apache.james.mailbox.quota.QuotaManager;
@@ -95,7 +96,7 @@ public class ClauseConverter {
Quota<QuotaSize> storageQuota = quotaManager.getStorageQuota(quotaRoot);
Quota<QuotaCount> messageQuota = quotaManager.getMessageQuota(quotaRoot);
- return Math.max(storageQuota.getRatio(), messageQuota.getRatio());
+ return QuotaRatio.from(storageQuota, messageQuota).max();
} catch (MailboxException e) {
throw new RuntimeException(e);
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f8b587a7/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/dto/OccupationRatioDTO.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/dto/OccupationRatioDTO.java b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/dto/OccupationRatioDTO.java
index 1358f13..2189aa2 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/dto/OccupationRatioDTO.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/dto/OccupationRatioDTO.java
@@ -20,6 +20,7 @@
package org.apache.james.webadmin.dto;
import org.apache.james.mailbox.model.Quota;
+import org.apache.james.mailbox.model.QuotaRatio;
import org.apache.james.mailbox.quota.QuotaCount;
import org.apache.james.mailbox.quota.QuotaSize;
@@ -28,15 +29,18 @@ public class OccupationRatioDTO {
public static OccupationRatioDTO from(Quota<QuotaSize> sizeQuota, Quota<QuotaCount> countQuota) {
return new OccupationRatioDTO(
sizeQuota.getRatio(),
- countQuota.getRatio());
+ countQuota.getRatio(),
+ QuotaRatio.from(sizeQuota, countQuota).max());
}
private final double size;
private final double count;
+ private final double max;
- private OccupationRatioDTO(double size, double count) {
+ private OccupationRatioDTO(double size, double count, double max) {
this.size = size;
this.count = count;
+ this.max = max;
}
public double getSize() {
@@ -48,6 +52,6 @@ public class OccupationRatioDTO {
}
public double getMax() {
- return Math.max(size, count);
+ return max;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org