Skip to content

Commit

Permalink
Broaden index versions tested to cover v7 versions for some analysis …
Browse files Browse the repository at this point in the history
…tests

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.
  • Loading branch information
javanna committed Dec 18, 2024
1 parent 9cc362b commit 79c836a
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void testSynonymWordDeleteByAnalyzer() throws IOException {
// Test with an index version where lenient should always be false by default
IndexVersion randomNonLenientIndexVersion = IndexVersionUtils.randomVersionBetween(
random(),
IndexVersions.MINIMUM_COMPATIBLE,
IndexVersions.MINIMUM_READONLY_COMPATIBLE,
IndexVersions.INDEX_SORTING_ON_NESTED
);
assertIsNotLenient.accept(randomNonLenientIndexVersion, false);
Expand Down Expand Up @@ -177,7 +177,7 @@ public void testSynonymWordDeleteByAnalyzerFromFile() throws IOException {
// Test with an index version where lenient should always be false by default
IndexVersion randomNonLenientIndexVersion = IndexVersionUtils.randomVersionBetween(
random(),
IndexVersions.MINIMUM_COMPATIBLE,
IndexVersions.MINIMUM_READONLY_COMPATIBLE,
IndexVersions.INDEX_SORTING_ON_NESTED
);
assertIsNotLenient.accept(randomNonLenientIndexVersion, false);
Expand Down Expand Up @@ -231,7 +231,7 @@ public void testExpandSynonymWordDeleteByAnalyzer() throws IOException {
// Test with an index version where lenient should always be false by default
IndexVersion randomNonLenientIndexVersion = IndexVersionUtils.randomVersionBetween(
random(),
IndexVersions.MINIMUM_COMPATIBLE,
IndexVersions.MINIMUM_READONLY_COMPATIBLE,
IndexVersions.INDEX_SORTING_ON_NESTED
);
assertIsNotLenient.accept(randomNonLenientIndexVersion, false);
Expand Down Expand Up @@ -338,7 +338,7 @@ public void testShingleFilters() {
Settings settings = Settings.builder()
.put(
IndexMetadata.SETTING_VERSION_CREATED,
IndexVersionUtils.randomVersionBetween(random(), IndexVersions.MINIMUM_COMPATIBLE, IndexVersion.current())
IndexVersionUtils.randomVersionBetween(random(), IndexVersions.MINIMUM_READONLY_COMPATIBLE, IndexVersion.current())
)
.put("path.home", createTempDir().toString())
.put("index.analysis.filter.synonyms.type", "synonym")
Expand Down Expand Up @@ -392,7 +392,7 @@ public void testPreconfiguredTokenFilters() throws IOException {
Settings settings = Settings.builder()
.put(
IndexMetadata.SETTING_VERSION_CREATED,
IndexVersionUtils.randomVersionBetween(random(), IndexVersions.MINIMUM_COMPATIBLE, IndexVersion.current())
IndexVersionUtils.randomVersionBetween(random(), IndexVersions.MINIMUM_READONLY_COMPATIBLE, IndexVersion.current())
)
.put("path.home", createTempDir().toString())
.build();
Expand Down Expand Up @@ -424,7 +424,7 @@ public void testDisallowedTokenFilters() throws IOException {
Settings settings = Settings.builder()
.put(
IndexMetadata.SETTING_VERSION_CREATED,
IndexVersionUtils.randomVersionBetween(random(), IndexVersions.MINIMUM_COMPATIBLE, IndexVersion.current())
IndexVersionUtils.randomVersionBetween(random(), IndexVersions.MINIMUM_READONLY_COMPATIBLE, IndexVersion.current())
)
.put("path.home", createTempDir().toString())
.putList("common_words", "a", "b")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,7 @@ public void testOldVersionGetXUniqueTokenFilter() throws IOException {
Settings settings = Settings.builder()
.put(
IndexMetadata.SETTING_VERSION_CREATED,
IndexVersionUtils.randomVersionBetween(
random(),
IndexVersions.MINIMUM_COMPATIBLE,
IndexVersionUtils.getPreviousVersion(IndexVersions.UNIQUE_TOKEN_FILTER_POS_FIX)
)
IndexVersionUtils.randomPreviousCompatibleVersion(random(), IndexVersions.UNIQUE_TOKEN_FILTER_POS_FIX)
)
.build();
IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void testDisallowedWithSynonyms() throws IOException {
Settings settings = Settings.builder()
.put(
IndexMetadata.SETTING_VERSION_CREATED,
IndexVersionUtils.randomVersionBetween(random(), IndexVersions.MINIMUM_COMPATIBLE, IndexVersion.current())
IndexVersionUtils.randomVersionBetween(random(), IndexVersions.MINIMUM_READONLY_COMPATIBLE, IndexVersion.current())
)
.put("path.home", createTempDir().toString())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public void testThatInstancesAreTheSameAlwaysForKeywordAnalyzer() {
PreBuiltAnalyzers.KEYWORD.getAnalyzer(IndexVersion.current()),
is(PreBuiltAnalyzers.KEYWORD.getAnalyzer(IndexVersions.MINIMUM_COMPATIBLE))
);
assertThat(
PreBuiltAnalyzers.KEYWORD.getAnalyzer(IndexVersion.current()),
is(PreBuiltAnalyzers.KEYWORD.getAnalyzer(IndexVersions.MINIMUM_READONLY_COMPATIBLE))
);
}

public void testThatInstancesAreCachedAndReused() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public float score(float freq, long norm) {
};
IllegalArgumentException e = expectThrows(
IllegalArgumentException.class,
() -> SimilarityService.validateSimilarity(IndexVersions.MINIMUM_COMPATIBLE, negativeScoresSim)
() -> SimilarityService.validateSimilarity(IndexVersions.MINIMUM_READONLY_COMPATIBLE, negativeScoresSim)
);
assertThat(e.getMessage(), Matchers.containsString("Similarities should not return negative scores"));

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

Expand All @@ -124,7 +124,7 @@ public float score(float freq, long norm) {
};
e = expectThrows(
IllegalArgumentException.class,
() -> SimilarityService.validateSimilarity(IndexVersions.MINIMUM_COMPATIBLE, increasingScoresWithNormSim)
() -> SimilarityService.validateSimilarity(IndexVersions.MINIMUM_READONLY_COMPATIBLE, increasingScoresWithNormSim)
);
assertThat(e.getMessage(), Matchers.containsString("Similarity scores should not increase when norm increases"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ public void testFloatVectorClassBindings() throws IOException {
BinaryDenseVectorScriptDocValuesTests.wrap(
new float[][] { docVector },
ElementType.FLOAT,
IndexVersions.MINIMUM_COMPATIBLE
IndexVersions.MINIMUM_READONLY_COMPATIBLE
),
"test",
ElementType.FLOAT,
dims,
IndexVersions.MINIMUM_COMPATIBLE
IndexVersions.MINIMUM_READONLY_COMPATIBLE
),
new BinaryDenseVectorDocValuesField(
BinaryDenseVectorScriptDocValuesTests.wrap(new float[][] { docVector }, ElementType.FLOAT, IndexVersion.current()),
Expand Down Expand Up @@ -303,12 +303,12 @@ public void testByteVsFloatSimilarity() throws IOException {
BinaryDenseVectorScriptDocValuesTests.wrap(
new float[][] { docVector },
ElementType.FLOAT,
IndexVersions.MINIMUM_COMPATIBLE
IndexVersions.MINIMUM_READONLY_COMPATIBLE
),
"field0",
ElementType.FLOAT,
dims,
IndexVersions.MINIMUM_COMPATIBLE
IndexVersions.MINIMUM_READONLY_COMPATIBLE
),
new BinaryDenseVectorDocValuesField(
BinaryDenseVectorScriptDocValuesTests.wrap(new float[][] { docVector }, ElementType.FLOAT, IndexVersion.current()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ public void testFloatVsListQueryVector() {
assertEquals(knn.cosineSimilarity(arrayQV), knn.cosineSimilarity(listQV), 0.001f);
assertEquals(knn.cosineSimilarity((Object) listQV), knn.cosineSimilarity((Object) arrayQV), 0.001f);

for (IndexVersion indexVersion : List.of(IndexVersions.MINIMUM_COMPATIBLE, IndexVersion.current())) {
for (IndexVersion indexVersion : List.of(
IndexVersions.MINIMUM_READONLY_COMPATIBLE,
IndexVersions.MINIMUM_COMPATIBLE,
IndexVersion.current()
)) {
BytesRef value = BinaryDenseVectorScriptDocValuesTests.mockEncodeDenseVector(docVector, ElementType.FLOAT, indexVersion);
BinaryDenseVector bdv = new BinaryDenseVector(docVector, value, dims, indexVersion);

Expand Down

0 comments on commit 79c836a

Please sign in to comment.