Skip to content

Commit

Permalink
Fix BWC test suite (#1426)
Browse files Browse the repository at this point in the history
* Fix BWC test suite

Signed-off-by: Sicheng Song <[email protected]>

* Debugging BWC

Signed-off-by: Sicheng Song <[email protected]>

* Fix regex expression

Signed-off-by: Sicheng Song <[email protected]>

* Add some doc and examples to explain how fix works

Signed-off-by: Sicheng Song <[email protected]>

---------

Signed-off-by: Sicheng Song <[email protected]>
  • Loading branch information
b4sjoo authored Oct 4, 2023
1 parent d8c1162 commit ab216d5
Showing 1 changed file with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Integer> 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 {
Expand Down

0 comments on commit ab216d5

Please sign in to comment.