Skip to content

Commit be045bd

Browse files
committed
Fix RemoteVersion comparison to prioritize OpenSearch over Elasticsearch
Signed-off-by: Hyunsang Han <[email protected]>
1 parent e823da8 commit be045bd

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

modules/reindex/src/main/java/org/opensearch/index/reindex/remote/RemoteVersion.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ public int compareTo(RemoteVersion other) {
9696
return 1;
9797
}
9898

99+
if (this.isOpenSearch != other.isOpenSearch) {
100+
return this.isOpenSearch ? 1 : -1;
101+
}
102+
99103
int result = Integer.compare(this.major, other.major);
100104
if (result != 0) {
101105
return result;

modules/reindex/src/test/java/org/opensearch/index/reindex/remote/RemoteVersionTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ public void testVersionComparison() {
3636
// Test compareTo()
3737
assertTrue(RemoteVersion.ELASTICSEARCH_1_0_0.compareTo(RemoteVersion.ELASTICSEARCH_2_0_0) < 0);
3838
assertTrue(RemoteVersion.ELASTICSEARCH_2_0_0.compareTo(RemoteVersion.ELASTICSEARCH_1_0_0) > 0);
39+
assertTrue(RemoteVersion.ELASTICSEARCH_2_0_0.compareTo(RemoteVersion.ELASTICSEARCH_2_0_0) == 0);
3940

4041
// Test OpenSearch vs Elasticsearch versions with same numbers
41-
assertEquals(0, RemoteVersion.ELASTICSEARCH_2_0_0.compareTo(RemoteVersion.OPENSEARCH_2_0_0));
42+
assertTrue(RemoteVersion.ELASTICSEARCH_2_0_0.compareTo(RemoteVersion.OPENSEARCH_2_0_0) < 0);
43+
assertTrue(RemoteVersion.OPENSEARCH_2_0_0.compareTo(RemoteVersion.ELASTICSEARCH_2_0_0) > 0);
4244
}
4345

4446
public void testVersionFromString() {

0 commit comments

Comments
 (0)