-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds integration test for invalid method parameters
Signed-off-by: Tejas Shah <[email protected]>
- Loading branch information
Showing
3 changed files
with
153 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
src/test/java/org/opensearch/knn/index/query/InvalidSearchQueryIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package org.opensearch.knn.index.query; | ||
|
||
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; | ||
import lombok.AllArgsConstructor; | ||
import lombok.SneakyThrows; | ||
import org.opensearch.client.Request; | ||
import org.opensearch.client.ResponseException; | ||
import org.opensearch.common.xcontent.XContentFactory; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
import org.opensearch.knn.KNNRestTestCase; | ||
|
||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
|
||
import static com.carrotsearch.randomizedtesting.RandomizedTest.$; | ||
import static com.carrotsearch.randomizedtesting.RandomizedTest.$$; | ||
|
||
@AllArgsConstructor | ||
public class InvalidSearchQueryIT extends KNNRestTestCase { | ||
|
||
private String description; | ||
private XContentBuilder xContentBuilder; | ||
|
||
@ParametersFactory(argumentFormatting = "description:%1$s; request:%2$s, expectedexception:%3$s") | ||
public static Collection<Object[]> parameters() throws IOException { | ||
return Arrays.asList( | ||
$$( | ||
$( | ||
"Empty method_parameter", | ||
XContentFactory.jsonBuilder() | ||
.startObject() | ||
.startObject("query") | ||
.startObject("knn") | ||
.startObject(FIELD_NAME) | ||
.field("vector", new float[] { 1.0f, 2.0f }) | ||
.field("k", 1) | ||
.startObject("method_parameter") | ||
.endObject() | ||
.endObject() | ||
.endObject() | ||
.endObject() | ||
.endObject() | ||
), | ||
$( | ||
"ef_search string", | ||
XContentFactory.jsonBuilder() | ||
.startObject() | ||
.startObject("query") | ||
.startObject("knn") | ||
.startObject(FIELD_NAME) | ||
.field("vector", new float[] { 1.0f, 2.0f }) | ||
.field("k", 1) | ||
.startObject("method_parameter") | ||
.field("ef_search", "string value") | ||
.endObject() | ||
.endObject() | ||
.endObject() | ||
.endObject() | ||
.endObject() | ||
), | ||
$( | ||
"ef_search less than 0", | ||
XContentFactory.jsonBuilder() | ||
.startObject() | ||
.startObject("query") | ||
.startObject("knn") | ||
.startObject(FIELD_NAME) | ||
.field("vector", new float[] { 1.0f, 2.0f }) | ||
.field("k", 1) | ||
.startObject("method_parameter") | ||
.field("ef_search", -1) | ||
.endObject() | ||
.endObject() | ||
.endObject() | ||
.endObject() | ||
.endObject() | ||
), | ||
$( | ||
"nprobes string", | ||
XContentFactory.jsonBuilder() | ||
.startObject() | ||
.startObject("query") | ||
.startObject("knn") | ||
.startObject(FIELD_NAME) | ||
.field("vector", new float[] { 1.0f, 2.0f }) | ||
.field("k", 1) | ||
.startObject("method_parameter") | ||
.field("nprobes", "string value") | ||
.endObject() | ||
.endObject() | ||
.endObject() | ||
.endObject() | ||
.endObject() | ||
), | ||
$( | ||
"nprobes less than 0", | ||
XContentFactory.jsonBuilder() | ||
.startObject() | ||
.startObject("query") | ||
.startObject("knn") | ||
.startObject(FIELD_NAME) | ||
.field("vector", new float[] { 1.0f, 2.0f }) | ||
.field("k", 1) | ||
.startObject("method_parameter") | ||
.field("nprobes", -10) | ||
.endObject() | ||
.endObject() | ||
.endObject() | ||
.endObject() | ||
.endObject() | ||
) | ||
) | ||
); | ||
} | ||
|
||
@SneakyThrows | ||
public void testEndToEnd_whenMethodIsHNSWFlat_thenSucceed() { | ||
Request request = new Request("POST", "/dummy_index/_search"); | ||
request.setJsonEntity(xContentBuilder.toString()); | ||
|
||
request.addParameter("size", Integer.toString(10)); | ||
request.addParameter("explain", Boolean.toString(true)); | ||
request.addParameter("search_type", "query_then_fetch"); | ||
|
||
expectThrows(ResponseException.class, () -> client().performRequest(request)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters