Skip to content

Commit

Permalink
Re-adding test from 7.x line
Browse files Browse the repository at this point in the history
  • Loading branch information
cbuescher committed Dec 19, 2024
1 parent b085b0a commit 6cc76ac
Showing 1 changed file with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.core.CheckedConsumer;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.index.analysis.AnalyzerScope;
import org.elasticsearch.index.analysis.IndexAnalyzers;
import org.elasticsearch.index.analysis.NamedAnalyzer;
Expand All @@ -60,6 +61,7 @@
import java.util.Set;
import java.util.function.Function;

import static org.elasticsearch.index.mapper.CompletionFieldMapper.COMPLETION_CONTEXTS_LIMIT;
import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.containsString;
Expand Down Expand Up @@ -757,7 +759,7 @@ public void testLimitOfContextMappings() throws Throwable {
.startObject("suggest")
.field("type", "completion")
.startArray("contexts");
for (int i = 0; i < CompletionFieldMapper.COMPLETION_CONTEXTS_LIMIT + 1; i++) {
for (int i = 0; i < COMPLETION_CONTEXTS_LIMIT + 1; i++) {
mappingBuilder.startObject();
mappingBuilder.field("name", Integer.toString(i));
mappingBuilder.field("type", "category");
Expand All @@ -769,7 +771,7 @@ public void testLimitOfContextMappings() throws Throwable {
MapperParsingException e = expectThrows(MapperParsingException.class, () -> createDocumentMapper(fieldMapping(b -> {
b.field("type", "completion");
b.startArray("contexts");
for (int i = 0; i < CompletionFieldMapper.COMPLETION_CONTEXTS_LIMIT + 1; i++) {
for (int i = 0; i < COMPLETION_CONTEXTS_LIMIT + 1; i++) {
b.startObject();
b.field("name", Integer.toString(i));
b.field("type", "category");
Expand All @@ -780,8 +782,24 @@ public void testLimitOfContextMappings() throws Throwable {
assertTrue(
e.getMessage(),
e.getMessage()
.contains("Limit of completion field contexts [" + CompletionFieldMapper.COMPLETION_CONTEXTS_LIMIT + "] has been exceeded")
.contains("Limit of completion field contexts [" + COMPLETION_CONTEXTS_LIMIT + "] has been exceeded")
);

// test pre-8 deprecation warnings
createDocumentMapper(IndexVersions.V_7_0_0, fieldMapping(b -> {
b.field("type", "completion");
b.startArray("contexts");
for (int i = 0; i < COMPLETION_CONTEXTS_LIMIT + 1; i++) {
b.startObject();
b.field("name", Integer.toString(i));
b.field("type", "category");
b.endObject();
}
b.endArray();
}));
assertCriticalWarnings("You have defined more than [" + COMPLETION_CONTEXTS_LIMIT + "] completion contexts" +
" in the mapping for field [field]. The maximum allowed number of completion contexts in a mapping will be limited to " +
"[" + COMPLETION_CONTEXTS_LIMIT + "] starting in version [8.0].");
}

private static CompletionFieldMapper.CompletionInputMetadata randomCompletionMetadata() {
Expand Down

0 comments on commit 6cc76ac

Please sign in to comment.