Skip to content

Commit

Permalink
Remove test only MapperBuilderContext constructor (elastic#109964)
Browse files Browse the repository at this point in the history
MapperBuilderContext has a constructor that is only used in 3 places by tests. It is misleading in that
it sets hardcoded values for most of the arguments that are necessary to create a meaningful context object.
There's the risk that it gets called from production code, which we want to avoid, hence this commit removes
such constructor in favour of moving the constants to test code.
  • Loading branch information
javanna authored Jun 20, 2024
1 parent 9335566 commit cfd873c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ public static MapperBuilderContext root(boolean isSourceSynthetic, boolean isDat
private final ObjectMapper.Dynamic dynamic;
private final MergeReason mergeReason;

MapperBuilderContext(String path) {
this(path, false, false, false, ObjectMapper.Defaults.DYNAMIC, MergeReason.MAPPING_UPDATE);
}

MapperBuilderContext(
String path,
boolean isSourceSynthetic,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public void testFieldAliasWithDifferentNestedScopes() {

private static FieldMapper createFieldMapper(String parent, String name) {
return new BooleanFieldMapper.Builder(name, ScriptCompiler.NONE, false, IndexVersion.current()).build(
new MapperBuilderContext(parent)
new MapperBuilderContext(parent, false, false, false, ObjectMapper.Defaults.DYNAMIC, MapperService.MergeReason.MAPPING_UPDATE)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,16 @@ private static RootObjectMapper createRootSubobjectFalseLeafWithDots() {

private static ObjectMapper.Builder createObjectSubobjectsFalseLeafWithDots() {
KeywordFieldMapper.Builder fieldBuilder = new KeywordFieldMapper.Builder("host.name", IndexVersion.current());
KeywordFieldMapper fieldMapper = fieldBuilder.build(new MapperBuilderContext("foo.metrics"));
KeywordFieldMapper fieldMapper = fieldBuilder.build(
new MapperBuilderContext(
"foo.metrics",
false,
false,
false,
ObjectMapper.Defaults.DYNAMIC,
MapperService.MergeReason.MAPPING_UPDATE
)
);
assertEquals("host.name", fieldMapper.simpleName());
assertEquals("foo.metrics.host.name", fieldMapper.name());
return new ObjectMapper.Builder("foo", ObjectMapper.Defaults.SUBOBJECTS).add(
Expand All @@ -342,7 +351,16 @@ private static ObjectMapper.Builder createObjectSubobjectsFalseLeafWithDots() {

private ObjectMapper.Builder createObjectSubobjectsFalseLeafWithMultiField() {
TextFieldMapper.Builder fieldBuilder = createTextKeywordMultiField("host.name");
TextFieldMapper textKeywordMultiField = fieldBuilder.build(new MapperBuilderContext("foo.metrics"));
TextFieldMapper textKeywordMultiField = fieldBuilder.build(
new MapperBuilderContext(
"foo.metrics",
false,
false,
false,
ObjectMapper.Defaults.DYNAMIC,
MapperService.MergeReason.MAPPING_UPDATE
)
);
assertEquals("host.name", textKeywordMultiField.simpleName());
assertEquals("foo.metrics.host.name", textKeywordMultiField.name());
FieldMapper fieldMapper = textKeywordMultiField.multiFields.iterator().next();
Expand Down

0 comments on commit cfd873c

Please sign in to comment.