Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand DocumentMapperTests #76368

Merged
merged 1 commit into from
Aug 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@
import org.elasticsearch.index.mapper.MapperService.MergeReason;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;

import static io.github.nik9000.mapmatcher.ListMatcher.matchesList;
import static io.github.nik9000.mapmatcher.MapMatcher.assertMap;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
Expand Down Expand Up @@ -284,20 +290,60 @@ public void testEmptyDocumentMapper() {
assertNotNull(documentMapper.idFieldMapper());
assertNotNull(documentMapper.sourceMapper());
assertNotNull(documentMapper.IndexFieldMapper());
assertEquals(10, documentMapper.mappers().getMapping().getMetadataMappersMap().size());
assertEquals(10, documentMapper.mappers().getMatchingFieldNames("*").size());
List<Class<?>> metadataMappers = new ArrayList<>(documentMapper.mappers().getMapping().getMetadataMappersMap().keySet());
Collections.sort(metadataMappers, Comparator.comparing(c -> c.getSimpleName()));
assertMap(
metadataMappers,
matchesList().item(DocCountFieldMapper.class)
.item(FieldNamesFieldMapper.class)
.item(IdFieldMapper.class)
.item(IgnoredFieldMapper.class)
.item(IndexFieldMapper.class)
.item(NestedPathFieldMapper.class)
.item(RoutingFieldMapper.class)
.item(SeqNoFieldMapper.class)
.item(SourceFieldMapper.class)
.item(VersionFieldMapper.class)
);
List<String> matching = new ArrayList<>(documentMapper.mappers().getMatchingFieldNames("*"));
Collections.sort(matching);
assertMap(
matching,
matchesList().item(DocCountFieldMapper.CONTENT_TYPE)
.item(FieldNamesFieldMapper.CONTENT_TYPE)
.item(IdFieldMapper.CONTENT_TYPE)
.item(IgnoredFieldMapper.CONTENT_TYPE)
.item(IndexFieldMapper.CONTENT_TYPE)
.item(NestedPathFieldMapper.NAME)
.item(RoutingFieldMapper.CONTENT_TYPE)
.item(SeqNoFieldMapper.CONTENT_TYPE)
.item(SourceFieldMapper.CONTENT_TYPE)
.item(VersionFieldMapper.CONTENT_TYPE)
);
}

public void testTooManyDimensionFields() {
// By default no more than 16 dimensions per document are supported
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> createDocumentMapper(mapping(b -> {
for (int i = 0; i < 17; i++) {
int max;
Settings settings;
if (randomBoolean()) {
max = 16; // By default no more than 16 dimensions per document are supported
settings = getIndexSettings();
} else {
max = between(1, 10000);
settings = Settings.builder()
.put(getIndexSettings())
.put(MapperService.INDEX_MAPPING_DIMENSION_FIELDS_LIMIT_SETTING.getKey(), max)
.put(MapperService.INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING.getKey(), max + 1)
.build();
}
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> createMapperService(settings, mapping(b -> {
for (int i = 0; i <= max; i++) {
b.startObject("field" + i)
.field("type", randomFrom("ip", "keyword", "long", "integer", "byte", "short"))
.field("dimension", true)
.endObject();
}
})));
assertThat(e.getMessage(), containsString("Limit of total dimension fields [16] has been exceeded"));
assertThat(e.getMessage(), containsString("Limit of total dimension fields [" + max + "] has been exceeded"));
}
}