-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HSEARCH-3934 Support custom settings on index update
- Loading branch information
Showing
3 changed files
with
275 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
216 changes: 216 additions & 0 deletions
216
...lasticsearch/schema/management/ElasticsearchIndexSchemaManagerUpdateCustomSettingsIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
/* | ||
* Hibernate Search, full-text search for your domain model | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.search.integrationtest.backend.elasticsearch.schema.management; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import static org.hibernate.search.util.impl.test.JsonHelper.assertJsonEquals; | ||
|
||
import org.hibernate.search.backend.elasticsearch.analysis.ElasticsearchAnalysisConfigurationContext; | ||
import org.hibernate.search.backend.elasticsearch.analysis.ElasticsearchAnalysisConfigurer; | ||
import org.hibernate.search.backend.elasticsearch.cfg.ElasticsearchIndexSettings; | ||
import org.hibernate.search.integrationtest.backend.elasticsearch.testsupport.categories.RequiresIndexOpenClose; | ||
import org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper; | ||
import org.hibernate.search.util.common.SearchException; | ||
import org.hibernate.search.util.common.impl.Futures; | ||
import org.hibernate.search.util.impl.integrationtest.backend.elasticsearch.rule.TestElasticsearchClient; | ||
import org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappedIndex; | ||
import org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingSchemaManagementStrategy; | ||
import org.hibernate.search.util.impl.test.annotation.TestForIssue; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
|
||
/** | ||
* Tests related to index custom settings when updating indexes. | ||
*/ | ||
@Category(RequiresIndexOpenClose.class) | ||
@TestForIssue(jiraKey = "HSEARCH-3934") | ||
public class ElasticsearchIndexSchemaManagerUpdateCustomSettingsIT { | ||
|
||
@Rule | ||
public final SearchSetupHelper setupHelper = new SearchSetupHelper(); | ||
|
||
@Rule | ||
public TestElasticsearchClient elasticsearchClient = new TestElasticsearchClient(); | ||
|
||
private final StubMappedIndex index = StubMappedIndex.withoutFields(); | ||
|
||
@Test | ||
public void nothingToDo() { | ||
elasticsearchClient.index( index.name() ).deleteAndCreate( "index", | ||
" { " + | ||
" 'number_of_shards': '3', " + | ||
" 'number_of_replicas': '3', " + | ||
" 'analysis': { " + | ||
" 'analyzer': { " + | ||
" 'my_standard-english': { " + | ||
" 'type': 'standard', " + | ||
" 'stopwords': '_english_' " + | ||
" }, " + | ||
" 'my_analyzer_ngram': { " + | ||
" 'type': 'custom', " + | ||
" 'tokenizer': 'my_analyzer_ngram_tokenizer' " + | ||
" } " + | ||
" }, " + | ||
" 'tokenizer': { " + | ||
" 'my_analyzer_ngram_tokenizer': { " + | ||
" 'type': 'ngram', " + | ||
" 'min_gram': '5', " + | ||
" 'max_gram': '6' " + | ||
" } " + | ||
" } " + | ||
" } " + | ||
" } " | ||
); | ||
|
||
setupAndUpdateIndex(); | ||
|
||
assertJsonEquals( | ||
" { " + | ||
" 'analyzer': { " + | ||
" 'my_standard-english': { " + | ||
" 'type': 'standard', " + | ||
" 'stopwords': '_english_' " + | ||
" }, " + | ||
" 'my_analyzer_ngram': { " + | ||
" 'type': 'custom', " + | ||
" 'tokenizer': 'my_analyzer_ngram_tokenizer' " + | ||
" } " + | ||
" }, " + | ||
" 'tokenizer': { " + | ||
" 'my_analyzer_ngram_tokenizer': { " + | ||
" 'type': 'ngram', " + | ||
" 'min_gram': '5', " + | ||
" 'max_gram': '6' " + | ||
" } " + | ||
" } " + | ||
" } ", | ||
elasticsearchClient.index( index.name() ).settings( "index.analysis" ).get() | ||
); | ||
|
||
assertThat( elasticsearchClient.index( index.name() ).settings( "index.number_of_shards" ).get() ) | ||
.isEqualTo( "\"3\"" ); | ||
assertThat( elasticsearchClient.index( index.name() ).settings( "index.number_of_replicas" ).get() ) | ||
.isEqualTo( "\"3\"" ); | ||
} | ||
|
||
@Test | ||
public void change_analysis() { | ||
elasticsearchClient.index( index.name() ).deleteAndCreate( "index", | ||
" { " + | ||
" 'number_of_shards': '3', " + | ||
" 'number_of_replicas': '3', " + | ||
" 'analysis': { " + | ||
" 'analyzer': { " + | ||
" 'my_standard-english': { " + | ||
" 'type': 'standard', " + | ||
" 'stopwords': '_english_' " + | ||
" }, " + | ||
" 'my_analyzer_ngram': { " + | ||
" 'type': 'custom', " + | ||
" 'tokenizer': 'my_analyzer_ngram_tokenizer' " + | ||
" } " + | ||
" }, " + | ||
" 'tokenizer': { " + | ||
" 'my_analyzer_ngram_tokenizer': { " + | ||
" 'type': 'ngram', " + | ||
" 'min_gram': '2', " + | ||
" 'max_gram': '3' " + | ||
" } " + | ||
" } " + | ||
" } " + | ||
" } " | ||
); | ||
|
||
setupAndUpdateIndex(); | ||
|
||
assertJsonEquals( | ||
" { " + | ||
" 'analyzer': { " + | ||
" 'my_standard-english': { " + | ||
" 'type': 'standard', " + | ||
" 'stopwords': '_english_' " + | ||
" }, " + | ||
" 'my_analyzer_ngram': { " + | ||
" 'type': 'custom', " + | ||
" 'tokenizer': 'my_analyzer_ngram_tokenizer' " + | ||
" } " + | ||
" }, " + | ||
" 'tokenizer': { " + | ||
" 'my_analyzer_ngram_tokenizer': { " + | ||
" 'type': 'ngram', " + | ||
" 'min_gram': '5', " + | ||
" 'max_gram': '6' " + | ||
" } " + | ||
" } " + | ||
" } ", | ||
elasticsearchClient.index( index.name() ).settings( "index.analysis" ).get() | ||
); | ||
|
||
assertThat( elasticsearchClient.index( index.name() ).settings( "index.number_of_shards" ).get() ) | ||
.isEqualTo( "\"3\"" ); | ||
assertThat( elasticsearchClient.index( index.name() ).settings( "index.number_of_replicas" ).get() ) | ||
.isEqualTo( "\"3\"" ); | ||
} | ||
|
||
@Test | ||
public void change_numberOfShards() { | ||
elasticsearchClient.index( index.name() ).deleteAndCreate( "index", | ||
" { " + | ||
" 'number_of_shards': '7', " + | ||
" 'number_of_replicas': '3', " + | ||
" 'analysis': { " + | ||
" 'analyzer': { " + | ||
" 'my_standard-english': { " + | ||
" 'type': 'standard', " + | ||
" 'stopwords': '_english_' " + | ||
" }, " + | ||
" 'my_analyzer_ngram': { " + | ||
" 'type': 'custom', " + | ||
" 'tokenizer': 'my_analyzer_ngram_tokenizer' " + | ||
" } " + | ||
" }, " + | ||
" 'tokenizer': { " + | ||
" 'my_analyzer_ngram_tokenizer': { " + | ||
" 'type': 'ngram', " + | ||
" 'min_gram': '2', " + | ||
" 'max_gram': '3' " + | ||
" } " + | ||
" } " + | ||
" } " + | ||
" } " | ||
); | ||
|
||
assertThatThrownBy( () -> setupAndUpdateIndex() ) | ||
.isInstanceOf( SearchException.class ) | ||
.hasMessageContainingAll( | ||
"Unable to update settings", "index.number_of_shards" ); | ||
} | ||
|
||
private void setupAndUpdateIndex() { | ||
setupHelper.start() | ||
.withSchemaManagement( StubMappingSchemaManagementStrategy.DROP_ON_SHUTDOWN_ONLY ) | ||
.withBackendProperty( | ||
// use an empty analysis configurer, | ||
// so that we have only the custom settings definitions | ||
ElasticsearchIndexSettings.ANALYSIS_CONFIGURER, | ||
(ElasticsearchAnalysisConfigurer) (ElasticsearchAnalysisConfigurationContext context) -> { | ||
// No-op | ||
} | ||
) | ||
.withIndexProperty( index.name(), ElasticsearchIndexSettings.SCHEMA_MANAGEMENT_SETTINGS_FILE, | ||
"custom-index-settings/valid.json" | ||
) | ||
.withIndex( index ) | ||
.setup(); | ||
|
||
Futures.unwrappedExceptionJoin( index.schemaManager().createOrUpdate() ); | ||
} | ||
|
||
} |