From 4c90ed26b4c5b70b8502250e8bf5e56dd328985c Mon Sep 17 00:00:00 2001 From: David Kyle Date: Tue, 26 Sep 2023 09:51:19 +0100 Subject: [PATCH] Fix test with empty result --- .../ml/inference/results/TextExpansionResultsTests.java | 7 ++++++- .../inference/integration/TestInferenceServicePlugin.java | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/inference/results/TextExpansionResultsTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/inference/results/TextExpansionResultsTests.java index 104838921a43..c3b2fbf6fb55 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/inference/results/TextExpansionResultsTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/inference/results/TextExpansionResultsTests.java @@ -16,8 +16,13 @@ import java.util.stream.Collectors; public class TextExpansionResultsTests extends InferenceResultsTestCase { + public static TextExpansionResults createRandomResults() { - int numTokens = randomIntBetween(0, 20); + return createRandomResults(0, 20); + } + + public static TextExpansionResults createRandomResults(int min, int max) { + int numTokens = randomIntBetween(min, max); List tokenList = new ArrayList<>(); for (int i = 0; i < numTokens; i++) { tokenList.add(new TextExpansionResults.WeightedToken(Integer.toString(i), (float) randomDoubleBetween(0.0, 5.0, false))); diff --git a/x-pack/plugin/inference/src/internalClusterTest/java/org/elasticsearch/xpack/inference/integration/TestInferenceServicePlugin.java b/x-pack/plugin/inference/src/internalClusterTest/java/org/elasticsearch/xpack/inference/integration/TestInferenceServicePlugin.java index af81a8378a86..b9b0d68054ef 100644 --- a/x-pack/plugin/inference/src/internalClusterTest/java/org/elasticsearch/xpack/inference/integration/TestInferenceServicePlugin.java +++ b/x-pack/plugin/inference/src/internalClusterTest/java/org/elasticsearch/xpack/inference/integration/TestInferenceServicePlugin.java @@ -103,7 +103,7 @@ public TestServiceModel parseConfigLenient(String modelId, TaskType taskType, Ma @Override public void infer(Model model, String input, Map taskSettings, ActionListener listener) { switch (model.getTaskType()) { - case SPARSE_EMBEDDING -> listener.onResponse(TextExpansionResultsTests.createRandomResults()); + case SPARSE_EMBEDDING -> listener.onResponse(TextExpansionResultsTests.createRandomResults(1, 10)); default -> listener.onFailure( new ElasticsearchStatusException( TaskType.unsupportedTaskTypeErrorMsg(model.getTaskType(), NAME),