Skip to content

Commit

Permalink
accept multiple failure if one of them is correct in kmeans predictio…
Browse files Browse the repository at this point in the history
…n test

Signed-off-by: HenryL27 <[email protected]>
  • Loading branch information
HenryL27 committed Dec 7, 2023
1 parent a7df1df commit 9a9801f
Showing 1 changed file with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.junit.Before;
import org.junit.Rule;
import org.junit.rules.ExpectedException;
import org.junit.runners.model.MultipleFailureException;
import org.opensearch.action.ActionRequestValidationException;
import org.opensearch.common.action.ActionFuture;
import org.opensearch.ml.action.MLCommonsIntegTestCase;
Expand Down Expand Up @@ -89,14 +90,27 @@ public void testPredictionWithoutDataset_KMeans() {
predictionFuture.actionGet();
}

public void testPredictionWithEmptyDataset_KMeans() {
exceptionRule.expect(IllegalArgumentException.class);
exceptionRule.expectMessage("No document found");
public void testPredictionWithEmptyDataset_KMeans() throws Exception {
MLInputDataset emptySearchInputDataset = emptyQueryInputDataSet(irisIndexName);
MLInput mlInput = MLInput.builder().algorithm(FunctionName.KMEANS).inputDataset(emptySearchInputDataset).build();
MLPredictionTaskRequest predictionRequest = new MLPredictionTaskRequest(kMeansModelId, mlInput, null);
ActionFuture<MLTaskResponse> predictionFuture = client().execute(MLPredictionTaskAction.INSTANCE, predictionRequest);
predictionFuture.actionGet();
Exception e = assertThrows(Exception.class, () -> predictionFuture.actionGet());
boolean foundIllegalArgument = false;
if (e instanceof MultipleFailureException) {
for (Throwable t : ((MultipleFailureException) e).getFailures()) {
if (t instanceof IllegalArgumentException) {
e = (Exception) t;
foundIllegalArgument = true;
break;
}
}
if (!foundIllegalArgument) {
throw e;
}
}
assert (e instanceof IllegalArgumentException);
assert (e.getMessage().equals("No document found"));
}

public void testPredictionWithSearchInput_LogisticRegression() {
Expand Down

0 comments on commit 9a9801f

Please sign in to comment.