Skip to content

Commit 05529d9

Browse files
committed
Adapt BWC layer checks for Exceptions to include v5.0.2 support
The PR #21694 was initially planned to go into v6.0.0 and v5.1.0. Due to another PR relying on this one though for backport to v5.0.2, #21694 must go to v5.0.2 as well. As such, the initial backward compatibility rules established by the PR must be changed to include v5.0.2 and above.
1 parent ce45095 commit 05529d9

3 files changed

Lines changed: 11 additions & 4 deletions

File tree

core/src/main/java/org/elasticsearch/ElasticsearchException.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
*/
5151
public class ElasticsearchException extends RuntimeException implements ToXContent, Writeable {
5252

53+
public static final Version V_5_0_2_UNRELEASED = Version.fromId(5000299);
5354
public static final Version UNKNOWN_VERSION_ADDED = Version.fromId(0);
5455
public static final String REST_EXCEPTION_SKIP_CAUSE = "rest.exception.cause.skip";
5556
public static final String REST_EXCEPTION_SKIP_STACK_TRACE = "rest.exception.stacktrace.skip";
@@ -711,9 +712,9 @@ enum ElasticsearchExceptionHandle {
711712
STATUS_EXCEPTION(org.elasticsearch.ElasticsearchStatusException.class, org.elasticsearch.ElasticsearchStatusException::new, 145,
712713
UNKNOWN_VERSION_ADDED),
713714
TASK_CANCELLED_EXCEPTION(org.elasticsearch.tasks.TaskCancelledException.class,
714-
org.elasticsearch.tasks.TaskCancelledException::new, 146, UNKNOWN_VERSION_ADDED),
715+
org.elasticsearch.tasks.TaskCancelledException::new, 146, Version.V_5_1_0),
715716
SHARD_LOCK_OBTAIN_FAILED_EXCEPTION(org.elasticsearch.env.ShardLockObtainFailedException.class,
716-
org.elasticsearch.env.ShardLockObtainFailedException::new, 147, Version.V_5_1_0);
717+
org.elasticsearch.env.ShardLockObtainFailedException::new, 147, V_5_0_2_UNRELEASED);
717718

718719

719720
final Class<? extends ElasticsearchException> exceptionClass;

core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,11 @@ public void testElasticsearchRemoteException() throws IOException {
865865
public void testShardLockObtainFailedException() throws IOException {
866866
ShardId shardId = new ShardId("foo", "_na_", 1);
867867
ShardLockObtainFailedException orig = new ShardLockObtainFailedException(shardId, "boom");
868-
Version version = VersionUtils.randomVersionBetween(random(), Version.V_5_1_0, Version.CURRENT);
868+
Version version = VersionUtils.randomVersionBetween(random(), Version.V_5_0_0, Version.CURRENT);
869+
if (version.before(ElasticsearchException.V_5_0_2_UNRELEASED)) {
870+
// remove this once 5_0_2 is released randomVersionBetween asserts that this version is in the constant table.
871+
version = ElasticsearchException.V_5_0_2_UNRELEASED;
872+
}
869873
ShardLockObtainFailedException ex = serialize(orig, version);
870874
assertEquals(orig.getMessage(), ex.getMessage());
871875
assertEquals(orig.getShardId(), ex.getShardId());
@@ -874,7 +878,7 @@ public void testShardLockObtainFailedException() throws IOException {
874878
public void testBWCShardLockObtainFailedException() throws IOException {
875879
ShardId shardId = new ShardId("foo", "_na_", 1);
876880
ShardLockObtainFailedException orig = new ShardLockObtainFailedException(shardId, "boom");
877-
Exception ex = serialize((Exception)orig, Version.V_5_0_0);
881+
Exception ex = serialize((Exception)orig, randomFrom(Version.V_5_0_0, Version.V_5_0_1));
878882
assertThat(ex, instanceOf(NotSerializableExceptionWrapper.class));
879883
assertEquals("shard_lock_obtain_failed_exception: [foo][1]: boom", ex.getMessage());
880884
}

core/src/test/java/org/elasticsearch/VersionTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ public void testLuceneVersionIsSameOnMinorRelease() {
267267
// see comment in Version.java about this test
268268
public void testUnknownVersions() {
269269
assertUnknownVersion(V_20_0_0_UNRELEASED);
270+
// once we release 5.0.2 and it's added to Version.java we need to remove this constant
271+
assertUnknownVersion(ElasticsearchException.V_5_0_2_UNRELEASED);
270272
expectThrows(AssertionError.class, () -> assertUnknownVersion(Version.CURRENT));
271273
}
272274

0 commit comments

Comments
 (0)