You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by rc...@apache.org on 2022/04/07 02:50:15 UTC

[james-project] branch master updated (1e45b3dedb -> 46361578e5)

This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git


    from 1e45b3dedb JAMES-3715 Schedule IMAP IDLE heartbits on the Netty Event loop (#948)
     new 529b663a84 JAMES-3739: Allow specific index' own settings
     new 46361578e5 JAMES-3739: Add tests for specific index' own settings

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../james/backends/es/v7/IndexCreationFactory.java | 13 ++--
 .../backends/es/v7/IndexCreationFactoryTest.java   | 77 ++++++++++++++++++++++
 2 files changed, 86 insertions(+), 4 deletions(-)


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


[james-project] 02/02: JAMES-3739: Add tests for specific index' own settings

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 46361578e52f656bf0a5592130eee881cc613a7f
Author: Quan Tran <hq...@linagora.com>
AuthorDate: Wed Apr 6 09:33:25 2022 +0700

    JAMES-3739: Add tests for specific index' own settings
---
 .../backends/es/v7/IndexCreationFactoryTest.java   | 77 ++++++++++++++++++++++
 1 file changed, 77 insertions(+)

diff --git a/backends-common/elasticsearch-v7/src/test/java/org/apache/james/backends/es/v7/IndexCreationFactoryTest.java b/backends-common/elasticsearch-v7/src/test/java/org/apache/james/backends/es/v7/IndexCreationFactoryTest.java
index 99a399b7a3..5a17a4679a 100644
--- a/backends-common/elasticsearch-v7/src/test/java/org/apache/james/backends/es/v7/IndexCreationFactoryTest.java
+++ b/backends-common/elasticsearch-v7/src/test/java/org/apache/james/backends/es/v7/IndexCreationFactoryTest.java
@@ -19,12 +19,18 @@
 
 package org.apache.james.backends.es.v7;
 
+import static org.apache.james.backends.es.v7.IndexCreationFactory.ANALYZER;
+import static org.apache.james.backends.es.v7.IndexCreationFactory.TOKENIZER;
+import static org.apache.james.backends.es.v7.IndexCreationFactory.TYPE;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
 
 import java.io.IOException;
+import java.util.Optional;
 
 import org.apache.james.backends.es.v7.IndexCreationFactory.IndexCreationCustomElement;
 import org.elasticsearch.ElasticsearchStatusException;
+import org.elasticsearch.common.xcontent.XContentBuilder;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
@@ -34,6 +40,59 @@ class IndexCreationFactoryTest {
     private static final IndexName INDEX_NAME = new IndexName("index");
     private static final ReadAliasName ALIAS_NAME = new ReadAliasName("alias");
 
+    public static XContentBuilder getValidIndexSetting() throws IOException {
+        return jsonBuilder()
+            .startObject()
+                .startObject("settings")
+                    .startObject("index")
+                        .field("max_ngram_diff", 10)
+                    .endObject()
+                    .startObject("analysis")
+                        .startObject(ANALYZER)
+                            .startObject("email_ngram_filter_analyzer")
+                                .field(TOKENIZER, "uax_url_email")
+                                .startArray("filter")
+                                    .value("ngram_filter")
+                                .endArray()
+                            .endObject()
+                        .endObject()
+                        .startObject("filter")
+                            .startObject("ngram_filter")
+                                .field(TYPE, "ngram")
+                                .field("min_gram", 3)
+                                .field("max_gram", 13)
+                            .endObject()
+                        .endObject()
+                    .endObject()
+                .endObject()
+            .endObject();
+    }
+
+    public static XContentBuilder getInvalidIndexSetting() throws IOException {
+        return jsonBuilder()
+            .startObject()
+                .startObject("settings")
+                    .startObject("analysis")
+                        .startObject(ANALYZER)
+                            .startObject("email_ngram_filter_analyzer")
+                                .field(TOKENIZER, "uax_url_email")
+                                .startArray("filter")
+                                    .value("ngram_filter")
+                                .endArray()
+                            .endObject()
+                        .endObject()
+                        .startObject("filter")
+                            .startObject("ngram_filter")
+                                .field(TYPE, "ngram")
+                                .field("min_gram", 3)
+                                .field("max_gram", 13)
+                            .endObject()
+                        .endObject()
+                    .endObject()
+                .endObject()
+            .endObject();
+    }
+
     @RegisterExtension
     public DockerElasticSearchExtension elasticSearch = new DockerElasticSearchExtension();
     private ReactorElasticSearchClient client;
@@ -158,4 +217,22 @@ class IndexCreationFactoryTest {
             .createIndexAndAliases(client);
     }
 
+    @Test
+    void customIndexSettingShouldNotThrowWhenValidSetting() throws IOException {
+        new IndexCreationFactory(ElasticSearchConfiguration.DEFAULT_CONFIGURATION)
+            .useIndex(INDEX_NAME)
+            .addAlias(ALIAS_NAME)
+            .createIndexAndAliases(client, Optional.of(getValidIndexSetting()), Optional.empty());
+    }
+
+    @Test
+    void customIndexSettingShouldThrowWhenInvalidSetting() {
+        assertThatThrownBy(() ->
+            new IndexCreationFactory(ElasticSearchConfiguration.DEFAULT_CONFIGURATION)
+                .useIndex(INDEX_NAME)
+                .addAlias(ALIAS_NAME)
+                .createIndexAndAliases(client, Optional.of(getInvalidIndexSetting()), Optional.empty()))
+            .isInstanceOf(ElasticsearchStatusException.class);
+    }
+
 }
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


[james-project] 01/02: JAMES-3739: Allow specific index' own settings

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 529b663a84b5b6d3f8dbdac0ce1ff8f4a013ca53
Author: Quan Tran <hq...@linagora.com>
AuthorDate: Tue Apr 5 14:35:13 2022 +0700

    JAMES-3739: Allow specific index' own settings
---
 .../apache/james/backends/es/v7/IndexCreationFactory.java   | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/backends-common/elasticsearch-v7/src/main/java/org/apache/james/backends/es/v7/IndexCreationFactory.java b/backends-common/elasticsearch-v7/src/main/java/org/apache/james/backends/es/v7/IndexCreationFactory.java
index 9b89fb5801..a528f509fa 100644
--- a/backends-common/elasticsearch-v7/src/main/java/org/apache/james/backends/es/v7/IndexCreationFactory.java
+++ b/backends-common/elasticsearch-v7/src/main/java/org/apache/james/backends/es/v7/IndexCreationFactory.java
@@ -141,11 +141,15 @@ public class IndexCreationFactory {
                 }
 
                 public ReactorElasticSearchClient createIndexAndAliases(ReactorElasticSearchClient client) {
-                    return build().createIndexAndAliases(client, Optional.empty());
+                    return build().createIndexAndAliases(client, Optional.empty(), Optional.empty());
                 }
 
                 public ReactorElasticSearchClient createIndexAndAliases(ReactorElasticSearchClient client, XContentBuilder mappingContent) {
-                    return build().createIndexAndAliases(client, Optional.of(mappingContent));
+                    return build().createIndexAndAliases(client, Optional.empty(), Optional.of(mappingContent));
+                }
+
+                public ReactorElasticSearchClient createIndexAndAliases(ReactorElasticSearchClient client, Optional<XContentBuilder> indexSettings, Optional<XContentBuilder> mappingContent) {
+                    return build().createIndexAndAliases(client, indexSettings, mappingContent);
                 }
             }
         }
@@ -174,10 +178,11 @@ public class IndexCreationFactory {
             this.customTokenizers = customTokenizers;
         }
 
-        public ReactorElasticSearchClient createIndexAndAliases(ReactorElasticSearchClient client, Optional<XContentBuilder> mappingContent) {
+        public ReactorElasticSearchClient createIndexAndAliases(ReactorElasticSearchClient client, Optional<XContentBuilder> indexSettings,
+                                                                Optional<XContentBuilder> mappingContent) {
             Preconditions.checkNotNull(indexName);
             try {
-                createIndexIfNeeded(client, indexName, generateSetting(), mappingContent);
+                createIndexIfNeeded(client, indexName, indexSettings.orElse(generateSetting()), mappingContent);
                 aliases.forEach(Throwing.<AliasName>consumer(alias -> createAliasIfNeeded(client, indexName, alias))
                     .sneakyThrow());
             } catch (IOException e) {


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org