Skip to content

Commit f760b40

Browse files
authored
Broaden index versions tested to cover v7 versions for some analysis tests (#119024)
This replaces usages of MINIMUM_COMPATIBLE with MINIMUM_READONLY_COMPATIBLE as a lower bound when randomizing the index version in some tests. This provides more coverage as it relies on readonly versions as opposed to only those that can be written to.
1 parent d103036 commit f760b40

File tree

7 files changed

+24
-20
lines changed

7 files changed

+24
-20
lines changed

modules/analysis-common/src/test/java/org/elasticsearch/analysis/common/SynonymsAnalysisTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public void testSynonymWordDeleteByAnalyzer() throws IOException {
118118
// Test with an index version where lenient should always be false by default
119119
IndexVersion randomNonLenientIndexVersion = IndexVersionUtils.randomVersionBetween(
120120
random(),
121-
IndexVersions.MINIMUM_COMPATIBLE,
121+
IndexVersions.MINIMUM_READONLY_COMPATIBLE,
122122
IndexVersions.INDEX_SORTING_ON_NESTED
123123
);
124124
assertIsNotLenient.accept(randomNonLenientIndexVersion, false);
@@ -177,7 +177,7 @@ public void testSynonymWordDeleteByAnalyzerFromFile() throws IOException {
177177
// Test with an index version where lenient should always be false by default
178178
IndexVersion randomNonLenientIndexVersion = IndexVersionUtils.randomVersionBetween(
179179
random(),
180-
IndexVersions.MINIMUM_COMPATIBLE,
180+
IndexVersions.MINIMUM_READONLY_COMPATIBLE,
181181
IndexVersions.INDEX_SORTING_ON_NESTED
182182
);
183183
assertIsNotLenient.accept(randomNonLenientIndexVersion, false);
@@ -231,7 +231,7 @@ public void testExpandSynonymWordDeleteByAnalyzer() throws IOException {
231231
// Test with an index version where lenient should always be false by default
232232
IndexVersion randomNonLenientIndexVersion = IndexVersionUtils.randomVersionBetween(
233233
random(),
234-
IndexVersions.MINIMUM_COMPATIBLE,
234+
IndexVersions.MINIMUM_READONLY_COMPATIBLE,
235235
IndexVersions.INDEX_SORTING_ON_NESTED
236236
);
237237
assertIsNotLenient.accept(randomNonLenientIndexVersion, false);
@@ -338,7 +338,7 @@ public void testShingleFilters() {
338338
Settings settings = Settings.builder()
339339
.put(
340340
IndexMetadata.SETTING_VERSION_CREATED,
341-
IndexVersionUtils.randomVersionBetween(random(), IndexVersions.MINIMUM_COMPATIBLE, IndexVersion.current())
341+
IndexVersionUtils.randomVersionBetween(random(), IndexVersions.MINIMUM_READONLY_COMPATIBLE, IndexVersion.current())
342342
)
343343
.put("path.home", createTempDir().toString())
344344
.put("index.analysis.filter.synonyms.type", "synonym")
@@ -392,7 +392,7 @@ public void testPreconfiguredTokenFilters() throws IOException {
392392
Settings settings = Settings.builder()
393393
.put(
394394
IndexMetadata.SETTING_VERSION_CREATED,
395-
IndexVersionUtils.randomVersionBetween(random(), IndexVersions.MINIMUM_COMPATIBLE, IndexVersion.current())
395+
IndexVersionUtils.randomVersionBetween(random(), IndexVersions.MINIMUM_READONLY_COMPATIBLE, IndexVersion.current())
396396
)
397397
.put("path.home", createTempDir().toString())
398398
.build();
@@ -424,7 +424,7 @@ public void testDisallowedTokenFilters() throws IOException {
424424
Settings settings = Settings.builder()
425425
.put(
426426
IndexMetadata.SETTING_VERSION_CREATED,
427-
IndexVersionUtils.randomVersionBetween(random(), IndexVersions.MINIMUM_COMPATIBLE, IndexVersion.current())
427+
IndexVersionUtils.randomVersionBetween(random(), IndexVersions.MINIMUM_READONLY_COMPATIBLE, IndexVersion.current())
428428
)
429429
.put("path.home", createTempDir().toString())
430430
.putList("common_words", "a", "b")

modules/analysis-common/src/test/java/org/elasticsearch/analysis/common/UniqueTokenFilterTests.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,7 @@ public void testOldVersionGetXUniqueTokenFilter() throws IOException {
124124
Settings settings = Settings.builder()
125125
.put(
126126
IndexMetadata.SETTING_VERSION_CREATED,
127-
IndexVersionUtils.randomVersionBetween(
128-
random(),
129-
IndexVersions.MINIMUM_COMPATIBLE,
130-
IndexVersionUtils.getPreviousVersion(IndexVersions.UNIQUE_TOKEN_FILTER_POS_FIX)
131-
)
127+
IndexVersionUtils.randomPreviousCompatibleVersion(random(), IndexVersions.UNIQUE_TOKEN_FILTER_POS_FIX)
132128
)
133129
.build();
134130
IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", settings);

plugins/analysis-phonetic/src/test/java/org/elasticsearch/plugin/analysis/phonetic/AnalysisPhoneticFactoryTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void testDisallowedWithSynonyms() throws IOException {
4444
Settings settings = Settings.builder()
4545
.put(
4646
IndexMetadata.SETTING_VERSION_CREATED,
47-
IndexVersionUtils.randomVersionBetween(random(), IndexVersions.MINIMUM_COMPATIBLE, IndexVersion.current())
47+
IndexVersionUtils.randomVersionBetween(random(), IndexVersions.MINIMUM_READONLY_COMPATIBLE, IndexVersion.current())
4848
)
4949
.put("path.home", createTempDir().toString())
5050
.build();

server/src/test/java/org/elasticsearch/index/analysis/PreBuiltAnalyzerTests.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ public void testThatInstancesAreTheSameAlwaysForKeywordAnalyzer() {
5555
PreBuiltAnalyzers.KEYWORD.getAnalyzer(IndexVersion.current()),
5656
is(PreBuiltAnalyzers.KEYWORD.getAnalyzer(IndexVersions.MINIMUM_COMPATIBLE))
5757
);
58+
assertThat(
59+
PreBuiltAnalyzers.KEYWORD.getAnalyzer(IndexVersion.current()),
60+
is(PreBuiltAnalyzers.KEYWORD.getAnalyzer(IndexVersions.MINIMUM_READONLY_COMPATIBLE))
61+
);
5862
}
5963

6064
public void testThatInstancesAreCachedAndReused() {

server/src/test/java/org/elasticsearch/index/similarity/SimilarityServiceTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public float score(float freq, long norm) {
7474
};
7575
IllegalArgumentException e = expectThrows(
7676
IllegalArgumentException.class,
77-
() -> SimilarityService.validateSimilarity(IndexVersions.MINIMUM_COMPATIBLE, negativeScoresSim)
77+
() -> SimilarityService.validateSimilarity(IndexVersions.MINIMUM_READONLY_COMPATIBLE, negativeScoresSim)
7878
);
7979
assertThat(e.getMessage(), Matchers.containsString("Similarities should not return negative scores"));
8080

@@ -99,7 +99,7 @@ public float score(float freq, long norm) {
9999
};
100100
e = expectThrows(
101101
IllegalArgumentException.class,
102-
() -> SimilarityService.validateSimilarity(IndexVersions.MINIMUM_COMPATIBLE, decreasingScoresWithFreqSim)
102+
() -> SimilarityService.validateSimilarity(IndexVersions.MINIMUM_READONLY_COMPATIBLE, decreasingScoresWithFreqSim)
103103
);
104104
assertThat(e.getMessage(), Matchers.containsString("Similarity scores should not decrease when term frequency increases"));
105105

@@ -124,7 +124,7 @@ public float score(float freq, long norm) {
124124
};
125125
e = expectThrows(
126126
IllegalArgumentException.class,
127-
() -> SimilarityService.validateSimilarity(IndexVersions.MINIMUM_COMPATIBLE, increasingScoresWithNormSim)
127+
() -> SimilarityService.validateSimilarity(IndexVersions.MINIMUM_READONLY_COMPATIBLE, increasingScoresWithNormSim)
128128
);
129129
assertThat(e.getMessage(), Matchers.containsString("Similarity scores should not increase when norm increases"));
130130
}

server/src/test/java/org/elasticsearch/script/VectorScoreScriptUtilsTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ public void testFloatVectorClassBindings() throws IOException {
5151
BinaryDenseVectorScriptDocValuesTests.wrap(
5252
new float[][] { docVector },
5353
ElementType.FLOAT,
54-
IndexVersions.MINIMUM_COMPATIBLE
54+
IndexVersions.MINIMUM_READONLY_COMPATIBLE
5555
),
5656
"test",
5757
ElementType.FLOAT,
5858
dims,
59-
IndexVersions.MINIMUM_COMPATIBLE
59+
IndexVersions.MINIMUM_READONLY_COMPATIBLE
6060
),
6161
new BinaryDenseVectorDocValuesField(
6262
BinaryDenseVectorScriptDocValuesTests.wrap(new float[][] { docVector }, ElementType.FLOAT, IndexVersion.current()),
@@ -303,12 +303,12 @@ public void testByteVsFloatSimilarity() throws IOException {
303303
BinaryDenseVectorScriptDocValuesTests.wrap(
304304
new float[][] { docVector },
305305
ElementType.FLOAT,
306-
IndexVersions.MINIMUM_COMPATIBLE
306+
IndexVersions.MINIMUM_READONLY_COMPATIBLE
307307
),
308308
"field0",
309309
ElementType.FLOAT,
310310
dims,
311-
IndexVersions.MINIMUM_COMPATIBLE
311+
IndexVersions.MINIMUM_READONLY_COMPATIBLE
312312
),
313313
new BinaryDenseVectorDocValuesField(
314314
BinaryDenseVectorScriptDocValuesTests.wrap(new float[][] { docVector }, ElementType.FLOAT, IndexVersion.current()),

server/src/test/java/org/elasticsearch/script/field/vectors/DenseVectorTests.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ public void testFloatVsListQueryVector() {
6969
assertEquals(knn.cosineSimilarity(arrayQV), knn.cosineSimilarity(listQV), 0.001f);
7070
assertEquals(knn.cosineSimilarity((Object) listQV), knn.cosineSimilarity((Object) arrayQV), 0.001f);
7171

72-
for (IndexVersion indexVersion : List.of(IndexVersions.MINIMUM_COMPATIBLE, IndexVersion.current())) {
72+
for (IndexVersion indexVersion : List.of(
73+
IndexVersions.MINIMUM_READONLY_COMPATIBLE,
74+
IndexVersions.MINIMUM_COMPATIBLE,
75+
IndexVersion.current()
76+
)) {
7377
BytesRef value = BinaryDenseVectorScriptDocValuesTests.mockEncodeDenseVector(docVector, ElementType.FLOAT, indexVersion);
7478
BinaryDenseVector bdv = new BinaryDenseVector(docVector, value, dims, indexVersion);
7579

0 commit comments

Comments
 (0)