Skip to content

Commit b26f5c9

Browse files
authored
[8.19] Clean up semantic text field mapper tests (#127853) (#127927)
* Clean up semantic text field mapper tests (#127853) (cherry picked from commit 9e542c0) # Conflicts: # x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/mapper/SemanticInferenceMetadataFieldsMapperTests.java # x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/mapper/SemanticTextFieldMapperTests.java * Fix getRandomCompatibleIndexVersion
1 parent c77870e commit b26f5c9

File tree

3 files changed

+20
-31
lines changed

3 files changed

+20
-31
lines changed

test/framework/src/main/java/org/elasticsearch/index/mapper/MapperServiceTestCase.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ protected final MapperService createMapperService(Settings settings, String mapp
210210
protected final MapperService createMapperService(IndexVersion indexVersion, Settings settings, XContentBuilder mappings)
211211
throws IOException {
212212
MapperService mapperService = createMapperService(indexVersion, settings, () -> true, mappings);
213-
merge(mapperService, mappings);
214213
return mapperService;
215214
}
216215

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/mapper/SemanticInferenceMetadataFieldsMapperTests.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,6 @@
2222
import java.util.Collections;
2323

2424
public class SemanticInferenceMetadataFieldsMapperTests extends MapperServiceTestCase {
25-
26-
static IndexVersion getRandomCompatibleIndexVersion(boolean useLegacyFormat) {
27-
return getRandomCompatibleIndexVersion(useLegacyFormat, IndexVersion.current());
28-
}
29-
30-
static IndexVersion getRandomCompatibleIndexVersion(boolean useLegacyFormat, IndexVersion maxVersion) {
31-
if (useLegacyFormat) {
32-
if (randomBoolean()) {
33-
return IndexVersionUtils.randomVersionBetween(random(), IndexVersions.INFERENCE_METADATA_FIELDS_BACKPORT, maxVersion);
34-
}
35-
return IndexVersionUtils.randomPreviousCompatibleVersion(random(), IndexVersions.INFERENCE_METADATA_FIELDS_BACKPORT);
36-
} else {
37-
return IndexVersionUtils.randomVersionBetween(random(), IndexVersions.INFERENCE_METADATA_FIELDS_BACKPORT, maxVersion);
38-
}
39-
}
40-
4125
@Override
4226
protected Collection<? extends Plugin> getPlugins() {
4327
return Collections.singletonList(new InferencePlugin(Settings.EMPTY));
@@ -61,4 +45,19 @@ public void testFieldHasValueWithEmptyFieldInfos() {
6145
public MappedFieldType getMappedFieldType() {
6246
return new SemanticInferenceMetadataFieldsMapper.FieldType();
6347
}
48+
49+
static IndexVersion getRandomCompatibleIndexVersion(boolean useLegacyFormat) {
50+
if (useLegacyFormat) {
51+
// Randomly choose an index version compatible with the legacy semantic text format
52+
return IndexVersionUtils.randomVersionBetween(random(), IndexVersions.SEMANTIC_TEXT_FIELD_TYPE, IndexVersion.current());
53+
} else {
54+
// Randomly choose an index version compatible with the new semantic text format
55+
return IndexVersionUtils.randomVersionBetween(
56+
random(),
57+
IndexVersions.INFERENCE_METADATA_FIELDS_BACKPORT,
58+
IndexVersion.current()
59+
);
60+
}
61+
}
62+
6463
}

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/mapper/SemanticTextFieldMapperTests.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -153,35 +153,27 @@ protected Supplier<ModelRegistry> getModelRegistry() {
153153

154154
private MapperService createMapperService(XContentBuilder mappings, boolean useLegacyFormat) throws IOException {
155155
IndexVersion indexVersion = SemanticInferenceMetadataFieldsMapperTests.getRandomCompatibleIndexVersion(useLegacyFormat);
156-
return createMapperService(mappings, useLegacyFormat, indexVersion, indexVersion, false);
156+
return createMapperService(mappings, useLegacyFormat, indexVersion, indexVersion);
157157
}
158158

159159
private MapperService createMapperService(XContentBuilder mappings, boolean useLegacyFormat, IndexVersion minIndexVersion)
160160
throws IOException {
161-
return createMapperService(mappings, useLegacyFormat, minIndexVersion, IndexVersion.current(), false);
161+
return createMapperService(mappings, useLegacyFormat, minIndexVersion, IndexVersion.current());
162162
}
163163

164164
private MapperService createMapperService(
165165
XContentBuilder mappings,
166166
boolean useLegacyFormat,
167167
IndexVersion minIndexVersion,
168-
IndexVersion maxIndexVersion,
169-
boolean propagateIndexVersion
168+
IndexVersion maxIndexVersion
170169
) throws IOException {
171170
validateIndexVersion(minIndexVersion, useLegacyFormat);
172171
IndexVersion indexVersion = IndexVersionUtils.randomVersionBetween(random(), minIndexVersion, maxIndexVersion);
173172
var settings = Settings.builder()
174173
.put(IndexMetadata.SETTING_INDEX_VERSION_CREATED.getKey(), indexVersion)
175174
.put(InferenceMetadataFieldsMapper.USE_LEGACY_SEMANTIC_TEXT_FORMAT.getKey(), useLegacyFormat)
176175
.build();
177-
// TODO - This is added, because we discovered a bug where the index version was not being correctly propagated
178-
// in our mappings even though we were specifying the index version in settings. We will fix this in a followup and
179-
// remove the boolean flag accordingly.
180-
if (propagateIndexVersion) {
181-
return createMapperService(indexVersion, settings, mappings);
182-
} else {
183-
return createMapperService(settings, mappings);
184-
}
176+
return createMapperService(indexVersion, settings, mappings);
185177
}
186178

187179
private static void validateIndexVersion(IndexVersion indexVersion, boolean useLegacyFormat) {
@@ -1187,8 +1179,7 @@ public void testDefaultIndexOptions() throws IOException {
11871179
}),
11881180
useLegacyFormat,
11891181
IndexVersions.INFERENCE_METADATA_FIELDS_BACKPORT,
1190-
IndexVersionUtils.getPreviousVersion(IndexVersions.SEMANTIC_TEXT_DEFAULTS_TO_BBQ_BACKPORT_8_X),
1191-
true
1182+
IndexVersionUtils.getPreviousVersion(IndexVersions.SEMANTIC_TEXT_DEFAULTS_TO_BBQ_BACKPORT_8_X)
11921183
);
11931184
assertSemanticTextField(mapperService, "field", true, null, defaultDenseVectorIndexOptions());
11941185

0 commit comments

Comments
 (0)