From 403798ea97e490fb8c7db05a30bfc6ae0b81ef1b Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Mon, 19 Feb 2024 15:11:12 -0800 Subject: [PATCH] Fix BWC test suite (#1426) (#2135) * Fix BWC test suite Signed-off-by: Sicheng Song * Debugging BWC Signed-off-by: Sicheng Song * Fix regex expression Signed-off-by: Sicheng Song * Add some doc and examples to explain how fix works Signed-off-by: Sicheng Song --------- Signed-off-by: Sicheng Song (cherry picked from commit ab216d5fcf9ed4db5128df29e1d6669dce0a1dc1) Co-authored-by: Sicheng Song --- .../MLCommonsBackwardsCompatibilityIT.java | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 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 00b4440b36..5e16bf2c4c 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,13 @@ 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; import org.apache.http.HttpEntity; @@ -312,8 +318,26 @@ 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) { - return (Integer.parseInt(osVersion.substring(2, 3)) > 4) || (Integer.parseInt(osVersion.substring(0, 1)) > 2); + 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) > olderMajorVersion || osVersionArrayList.get(1) > olderMinorVersion); + } else { + throw new IllegalArgumentException("osVersion is not valid, osVersion is: " + osVersion); + } } private void verifyMlResponse(String uri) throws Exception {