Skip to content

Commit

Permalink
Fix expectations of IndexVersionTests#testLuceneVersionOnUnknownVersi…
Browse files Browse the repository at this point in the history
…ons. (#99799)

This test tests the following:
 - an unknown version has the Lucene version of the previous Elasticsearch version
 - an unknown version older than the first known version is on the previous Lucene major version
 - an unknown version in the future is on the same Lucene version as the current Lucene version

Co-authored-by: Simon Cooper <simon.cooper@elastic.co>
  • Loading branch information
jpountz and thecoop authored Sep 22, 2023
1 parent 0efa678 commit 0587965
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions server/src/test/java/org/elasticsearch/index/IndexVersionTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,23 +199,20 @@ public void testParseLenient() {

public void testLuceneVersionOnUnknownVersions() {
// between two known versions, should use the lucene version of the previous version
IndexVersion version = IndexVersionUtils.getPreviousVersion();
final IndexVersion nextVersion = IndexVersion.fromId(version.id() + 100);
if (IndexVersionUtils.allReleasedVersions().contains(nextVersion) == false) {
// the version is not known, we make an assumption the Lucene version stays the same
assertThat(version.luceneVersion(), equalTo(nextVersion.luceneVersion()));
} else {
// the version is known, the most we can assert is that the Lucene version is not earlier
// Version does not implement Comparable :(
assertTrue(nextVersion.luceneVersion().onOrAfter(version.luceneVersion()));
}
IndexVersion previousVersion = IndexVersionUtils.getPreviousVersion();
IndexVersion currentVersion = IndexVersion.current();
int intermediateVersionId = previousVersion.id() + randomInt(currentVersion.id() - previousVersion.id() - 1);
IndexVersion intermediateVersion = IndexVersion.fromId(intermediateVersionId);
// the version is either the previous version or between the previous version and the current version excluded, so it is assumed to
// use the same Lucene version as the previous version
assertThat(intermediateVersion.luceneVersion(), equalTo(previousVersion.luceneVersion()));

// too old version, major should be the oldest supported lucene version minus 1
version = IndexVersion.fromId(5020199);
assertThat(version.luceneVersion().major, equalTo(IndexVersionUtils.getFirstVersion().luceneVersion().major - 1));
IndexVersion oldVersion = IndexVersion.fromId(5020199);
assertThat(oldVersion.luceneVersion().major, equalTo(IndexVersionUtils.getFirstVersion().luceneVersion().major - 1));

// future version, should be the same version as today
version = IndexVersion.fromId(IndexVersion.current().id() + 100);
assertThat(version.luceneVersion(), equalTo(IndexVersion.current().luceneVersion()));
IndexVersion futureVersion = IndexVersion.fromId(currentVersion.id() + 100);
assertThat(futureVersion.luceneVersion(), equalTo(currentVersion.luceneVersion()));
}
}

0 comments on commit 0587965

Please sign in to comment.