From 6cbcff43bd5ebfb077a464c79038a5e0fc305ac6 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Wed, 11 Aug 2021 16:00:11 -0400 Subject: [PATCH] Expand DocumentMapperTests (backport of #76368) (#76378) Adds a test for setting the maximum number of dimensions setting and tests the names and types of the metadata fields in the index. Previously we just asserted the count of metadata fields. That made it hard to read failures. --- .../index/mapper/DocumentMapperTests.java | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/index/mapper/DocumentMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/DocumentMapperTests.java index e704e896270e9..b1b9525bbd221 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/DocumentMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/DocumentMapperTests.java @@ -23,13 +23,18 @@ 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.HashMap; +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; @@ -288,7 +293,35 @@ 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> 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(RoutingFieldMapper.class) + .item(SeqNoFieldMapper.class) + .item(SourceFieldMapper.class) + .item(TypeFieldMapper.class) + .item(VersionFieldMapper.class) + ); + List 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(RoutingFieldMapper.CONTENT_TYPE) + .item(SeqNoFieldMapper.CONTENT_TYPE) + .item(SourceFieldMapper.CONTENT_TYPE) + .item(TypeFieldMapper.NAME) + .item(VersionFieldMapper.CONTENT_TYPE) + ); } }