From 4e574597ee5b088c32ede0815d4a41a948a2df71 Mon Sep 17 00:00:00 2001 From: Sicheng Song Date: Tue, 3 Oct 2023 23:05:17 +0000 Subject: [PATCH 1/4] Fix BWC test suite Signed-off-by: Sicheng Song --- .../ml/bwc/MLCommonsBackwardsCompatibilityIT.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plugin/src/test/java/org/opensearch/ml/bwc/MLCommonsBackwardsCompatibilityIT.java b/plugin/src/test/java/org/opensearch/ml/bwc/MLCommonsBackwardsCompatibilityIT.java index 00b4440b36..3f82d16c2e 100644 --- a/plugin/src/test/java/org/opensearch/ml/bwc/MLCommonsBackwardsCompatibilityIT.java +++ b/plugin/src/test/java/org/opensearch/ml/bwc/MLCommonsBackwardsCompatibilityIT.java @@ -10,6 +10,8 @@ import java.io.IOException; import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.stream.Collectors; import org.apache.http.HttpEntity; @@ -313,7 +315,13 @@ private String getModelIdWithFunctionName(FunctionName functionName) throws IOEx } private boolean isNewerVersion(String osVersion) { - return (Integer.parseInt(osVersion.substring(2, 3)) > 4) || (Integer.parseInt(osVersion.substring(0, 1)) > 2); + Pattern pattern = Pattern.compile("\\d+(?=\\.)"); + Matcher matcher = pattern.matcher(osVersion); + if (matcher.groupCount() >= 2) { + return (Integer.parseInt(matcher.group(1)) > 4) || (Integer.parseInt(matcher.group(0)) > 2); + } else { + throw new IllegalArgumentException("osVersion is not valid, osVersion is: " + osVersion); + } } private void verifyMlResponse(String uri) throws Exception { From ea2ce809e34fc105376b63bb7b768bdee598e3ba Mon Sep 17 00:00:00 2001 From: Sicheng Song Date: Tue, 3 Oct 2023 23:39:08 +0000 Subject: [PATCH 2/4] Debugging BWC Signed-off-by: Sicheng Song --- .../org/opensearch/ml/bwc/MLCommonsBackwardsCompatibilityIT.java | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin/src/test/java/org/opensearch/ml/bwc/MLCommonsBackwardsCompatibilityIT.java b/plugin/src/test/java/org/opensearch/ml/bwc/MLCommonsBackwardsCompatibilityIT.java index 3f82d16c2e..a0dfd951cd 100644 --- a/plugin/src/test/java/org/opensearch/ml/bwc/MLCommonsBackwardsCompatibilityIT.java +++ b/plugin/src/test/java/org/opensearch/ml/bwc/MLCommonsBackwardsCompatibilityIT.java @@ -317,6 +317,7 @@ private String getModelIdWithFunctionName(FunctionName functionName) throws IOEx private boolean isNewerVersion(String osVersion) { Pattern pattern = Pattern.compile("\\d+(?=\\.)"); Matcher matcher = pattern.matcher(osVersion); + assertEquals(matcher.groupCount(), 2); if (matcher.groupCount() >= 2) { return (Integer.parseInt(matcher.group(1)) > 4) || (Integer.parseInt(matcher.group(0)) > 2); } else { From 79e45f21d63a76c0d5e73ab735460cc9fa761e8b Mon Sep 17 00:00:00 2001 From: Sicheng Song Date: Wed, 4 Oct 2023 01:05:39 +0000 Subject: [PATCH 3/4] Fix regex expression Signed-off-by: Sicheng Song --- .../ml/bwc/MLCommonsBackwardsCompatibilityIT.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/plugin/src/test/java/org/opensearch/ml/bwc/MLCommonsBackwardsCompatibilityIT.java b/plugin/src/test/java/org/opensearch/ml/bwc/MLCommonsBackwardsCompatibilityIT.java index a0dfd951cd..84dd8499cb 100644 --- a/plugin/src/test/java/org/opensearch/ml/bwc/MLCommonsBackwardsCompatibilityIT.java +++ b/plugin/src/test/java/org/opensearch/ml/bwc/MLCommonsBackwardsCompatibilityIT.java @@ -9,7 +9,11 @@ import static org.opensearch.ml.common.input.parameter.clustering.KMeansParams.DistanceType.COSINE; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -317,9 +321,12 @@ private String getModelIdWithFunctionName(FunctionName functionName) throws IOEx private boolean isNewerVersion(String osVersion) { Pattern pattern = Pattern.compile("\\d+(?=\\.)"); Matcher matcher = pattern.matcher(osVersion); - assertEquals(matcher.groupCount(), 2); - if (matcher.groupCount() >= 2) { - return (Integer.parseInt(matcher.group(1)) > 4) || (Integer.parseInt(matcher.group(0)) > 2); + ArrayList osVersionArrayList = new ArrayList<>(); + while (matcher.find()) { + osVersionArrayList.add(Integer.parseInt(matcher.group())); + } + if (osVersionArrayList.size() >= 2) { + return (osVersionArrayList.get(0) > 2 || osVersionArrayList.get(1) > 4); } else { throw new IllegalArgumentException("osVersion is not valid, osVersion is: " + osVersion); } From df8bc471f278045ffbfcd52411acc3954403dc47 Mon Sep 17 00:00:00 2001 From: Sicheng Song Date: Wed, 4 Oct 2023 17:48:04 +0000 Subject: [PATCH 4/4] Add some doc and examples to explain how fix works Signed-off-by: Sicheng Song --- .../ml/bwc/MLCommonsBackwardsCompatibilityIT.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plugin/src/test/java/org/opensearch/ml/bwc/MLCommonsBackwardsCompatibilityIT.java b/plugin/src/test/java/org/opensearch/ml/bwc/MLCommonsBackwardsCompatibilityIT.java index 84dd8499cb..5e16bf2c4c 100644 --- a/plugin/src/test/java/org/opensearch/ml/bwc/MLCommonsBackwardsCompatibilityIT.java +++ b/plugin/src/test/java/org/opensearch/ml/bwc/MLCommonsBackwardsCompatibilityIT.java @@ -318,15 +318,23 @@ private String getModelIdWithFunctionName(FunctionName functionName) throws IOEx return modelIdSet.iterator().next().toString(); } + /** + * This method compares our current ML plugin version + * to the older ML plugin version used in the BWC test, + * which is 2.4.0 at this time. + */ private boolean isNewerVersion(String osVersion) { + Integer olderMajorVersion = 2; + Integer olderMinorVersion = 4; Pattern pattern = Pattern.compile("\\d+(?=\\.)"); Matcher matcher = pattern.matcher(osVersion); + // e.g. If current OS Version is "2.11.0", the osVersionArrayList will be like [2, 11]. ArrayList osVersionArrayList = new ArrayList<>(); while (matcher.find()) { osVersionArrayList.add(Integer.parseInt(matcher.group())); } if (osVersionArrayList.size() >= 2) { - return (osVersionArrayList.get(0) > 2 || osVersionArrayList.get(1) > 4); + return (osVersionArrayList.get(0) > olderMajorVersion || osVersionArrayList.get(1) > olderMinorVersion); } else { throw new IllegalArgumentException("osVersion is not valid, osVersion is: " + osVersion); }