From c8a576c50d0d189c44dbafa4f39959b0fdc44774 Mon Sep 17 00:00:00 2001 From: Kathleen DeRusso Date: Mon, 2 Dec 2024 10:54:09 -0500 Subject: [PATCH] Fix test compilation errors --- .../cluster/metadata/InferenceFieldMetadata.java | 4 ++++ .../cluster/metadata/IndexMetadataTests.java | 4 ++-- .../metadata/InferenceFieldMetadataTests.java | 12 +++++------- .../MappingLookupInferenceFieldMapperTests.java | 10 +++------- .../index/query/QueryRewriteContextTests.java | 2 ++ .../filter/ShardBulkInferenceActionFilterTests.java | 12 ++++++------ .../xpack/rank/rrf/RRFRetrieverBuilderTests.java | 8 ++++++-- 7 files changed, 28 insertions(+), 24 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/InferenceFieldMetadata.java b/server/src/main/java/org/elasticsearch/cluster/metadata/InferenceFieldMetadata.java index 584fda7f90b48..271c60e829a87 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/InferenceFieldMetadata.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/InferenceFieldMetadata.java @@ -42,6 +42,10 @@ public final class InferenceFieldMetadata implements SimpleDiffable new InferenceFieldMetadata(null, "inferenceId", "searchInferenceId", new String[0], "queryName")); - assertThrows(NullPointerException.class, () -> new InferenceFieldMetadata("name", null, "searchInferenceId", new String[0], "queryName")); - assertThrows(NullPointerException.class, () -> new InferenceFieldMetadata("name", "inferenceId", null, new String[0], "queryName")); - assertThrows(NullPointerException.class, () -> new InferenceFieldMetadata("name", "inferenceId", "searchInferenceId", null, "queryName")); - assertThrows(NullPointerException.class, () -> new InferenceFieldMetadata("name", "inferenceId", "searchInferenceId", new String[0], null)); + assertThrows(NullPointerException.class, () -> new InferenceFieldMetadata(null, "inferenceId", "searchInferenceId", new String[0])); + assertThrows(NullPointerException.class, () -> new InferenceFieldMetadata("name", null, "searchInferenceId", new String[0])); + assertThrows(NullPointerException.class, () -> new InferenceFieldMetadata("name", "inferenceId", null, new String[0])); + assertThrows(NullPointerException.class, () -> new InferenceFieldMetadata("name", "inferenceId", "searchInferenceId", null)); } } diff --git a/server/src/test/java/org/elasticsearch/index/mapper/MappingLookupInferenceFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/MappingLookupInferenceFieldMapperTests.java index 9f106e10884e0..b1470c1ee5b3b 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/MappingLookupInferenceFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/MappingLookupInferenceFieldMapperTests.java @@ -15,7 +15,6 @@ import org.elasticsearch.plugins.MapperPlugin; import org.elasticsearch.plugins.Plugin; -import java.io.IOException; import java.util.Collection; import java.util.List; import java.util.Map; @@ -47,12 +46,10 @@ public void testInferenceFieldMapper() throws Exception { InferenceFieldMetadata inferenceFieldMetadata = inferenceFieldMetadataMap.get("inference_field"); assertThat(inferenceFieldMetadata.getInferenceId(), equalTo(TestInferenceFieldMapper.INFERENCE_ID)); assertThat(inferenceFieldMetadata.getSourceFields(), arrayContaining("inference_field")); - assertThat(inferenceFieldMetadata.getQueryName(), equalTo(TestInferenceFieldMapper.QUERY_NAME)); inferenceFieldMetadata = inferenceFieldMetadataMap.get("another_inference_field"); assertThat(inferenceFieldMetadata.getInferenceId(), equalTo(TestInferenceFieldMapper.INFERENCE_ID)); assertThat(inferenceFieldMetadata.getSourceFields(), arrayContaining("another_inference_field")); - assertThat(inferenceFieldMetadata.getQueryName(), equalTo(TestInferenceFieldMapper.QUERY_NAME)); } public void testInferenceFieldMapperWithCopyTo() throws Exception { @@ -82,7 +79,6 @@ public void testInferenceFieldMapperWithCopyTo() throws Exception { inferenceFieldMetadata.getSourceFields(), arrayContainingInAnyOrder("another_non_inference_field", "inference_field", "non_inference_field") ); - assertThat(inferenceFieldMetadata.getQueryName(), equalTo(TestInferenceFieldMapper.QUERY_NAME)); } private static class TestInferenceFieldMapperPlugin extends Plugin implements MapperPlugin { @@ -97,8 +93,8 @@ private static class TestInferenceFieldMapper extends FieldMapper implements Inf public static final TypeParser PARSER = new TypeParser((n, c) -> new Builder(n)); public static final String INFERENCE_ID = "test_inference_id"; + public static final String SEARCH_INFERENCE_ID = "test_search_inference_id"; public static final String CONTENT_TYPE = "test_inference_field"; - public static final String QUERY_NAME = "test_query_name"; TestInferenceFieldMapper(String simpleName) { super(simpleName, new TestInferenceFieldMapperFieldType(simpleName), BuilderParams.empty()); @@ -106,7 +102,7 @@ private static class TestInferenceFieldMapper extends FieldMapper implements Inf @Override public InferenceFieldMetadata getMetadata(Set sourcePaths) { - return new InferenceFieldMetadata(fullPath(), INFERENCE_ID, sourcePaths.toArray(new String[0]), QUERY_NAME); + return new InferenceFieldMetadata(fullPath(), INFERENCE_ID, SEARCH_INFERENCE_ID, sourcePaths.toArray(new String[0])); } @Override @@ -115,7 +111,7 @@ public Object getOriginalValue(Map sourceAsMap) { } @Override - protected void parseCreateField(DocumentParserContext context) throws IOException {} + protected void parseCreateField(DocumentParserContext context) {} @Override public Builder getMergeBuilder() { diff --git a/server/src/test/java/org/elasticsearch/index/query/QueryRewriteContextTests.java b/server/src/test/java/org/elasticsearch/index/query/QueryRewriteContextTests.java index d07bcf54fdf09..5dd231ab97886 100644 --- a/server/src/test/java/org/elasticsearch/index/query/QueryRewriteContextTests.java +++ b/server/src/test/java/org/elasticsearch/index/query/QueryRewriteContextTests.java @@ -52,6 +52,7 @@ public void testGetTierPreference() { null, null, null, + null, null ); @@ -79,6 +80,7 @@ public void testGetTierPreference() { null, null, null, + null, null ); diff --git a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/action/filter/ShardBulkInferenceActionFilterTests.java b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/action/filter/ShardBulkInferenceActionFilterTests.java index 6bec917fb003c..940968c0a2e5f 100644 --- a/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/action/filter/ShardBulkInferenceActionFilterTests.java +++ b/x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/action/filter/ShardBulkInferenceActionFilterTests.java @@ -102,7 +102,7 @@ public void testFilterNoop() throws Exception { new BulkItemRequest[0] ); request.setInferenceFieldMap( - Map.of("foo", new InferenceFieldMetadata("foo", "bar", generateRandomStringArray(5, 10, false, false), "baz")) + Map.of("foo", new InferenceFieldMetadata("foo", "bar", "baz", generateRandomStringArray(5, 10, false, false))) ); filter.apply(task, TransportShardBulkAction.ACTION_NAME, request, actionListener, actionFilterChain); awaitLatch(chainExecuted, 10, TimeUnit.SECONDS); @@ -136,11 +136,11 @@ public void testInferenceNotFound() throws Exception { Map inferenceFieldMap = Map.of( "field1", - new InferenceFieldMetadata("field1", model.getInferenceEntityId(), new String[] { "field1" }, "queryName"), + new InferenceFieldMetadata("field1", model.getInferenceEntityId(), new String[] { "field1" }), "field2", - new InferenceFieldMetadata("field2", "inference_0", new String[] { "field2" }, "queryName"), + new InferenceFieldMetadata("field2", "inference_0", new String[] { "field2" }), "field3", - new InferenceFieldMetadata("field3", "inference_0", new String[] { "field3" }, "queryName") + new InferenceFieldMetadata("field3", "inference_0", new String[] { "field3" }) ); BulkItemRequest[] items = new BulkItemRequest[10]; for (int i = 0; i < items.length; i++) { @@ -194,7 +194,7 @@ public void testItemFailures() throws Exception { Map inferenceFieldMap = Map.of( "field1", - new InferenceFieldMetadata("field1", model.getInferenceEntityId(), new String[] { "field1" }, "queryName") + new InferenceFieldMetadata("field1", model.getInferenceEntityId(), new String[] { "field1" }) ); BulkItemRequest[] items = new BulkItemRequest[3]; items[0] = new BulkItemRequest(0, new IndexRequest("index").source("field1", "I am a failure")); @@ -220,7 +220,7 @@ public void testManyRandomDocs() throws Exception { for (int i = 0; i < numInferenceFields; i++) { String field = randomAlphaOfLengthBetween(5, 10); String inferenceId = randomFrom(inferenceModelMap.keySet()); - inferenceFieldMap.put(field, new InferenceFieldMetadata(field, inferenceId, new String[] { field }, "queryName")); + inferenceFieldMap.put(field, new InferenceFieldMetadata(field, inferenceId, new String[] { field })); } int numRequests = atLeast(100); diff --git a/x-pack/plugin/rank-rrf/src/test/java/org/elasticsearch/xpack/rank/rrf/RRFRetrieverBuilderTests.java b/x-pack/plugin/rank-rrf/src/test/java/org/elasticsearch/xpack/rank/rrf/RRFRetrieverBuilderTests.java index d20f0f88aeb16..bdd6d73ec0fbf 100644 --- a/x-pack/plugin/rank-rrf/src/test/java/org/elasticsearch/xpack/rank/rrf/RRFRetrieverBuilderTests.java +++ b/x-pack/plugin/rank-rrf/src/test/java/org/elasticsearch/xpack/rank/rrf/RRFRetrieverBuilderTests.java @@ -54,7 +54,9 @@ public void testRetrieverExtractionErrors() throws IOException { IllegalArgumentException iae = expectThrows( IllegalArgumentException.class, () -> ssb.parseXContent(parser, true, nf -> true) - .rewrite(new QueryRewriteContext(parserConfig(), null, null, null, new PointInTimeBuilder(new BytesArray("pitid")))) + .rewrite( + new QueryRewriteContext(parserConfig(), null, null, null, new PointInTimeBuilder(new BytesArray("pitid")), null) + ) ); assertEquals("[search_after] cannot be used in children of compound retrievers", iae.getMessage()); } @@ -70,7 +72,9 @@ public void testRetrieverExtractionErrors() throws IOException { IllegalArgumentException iae = expectThrows( IllegalArgumentException.class, () -> ssb.parseXContent(parser, true, nf -> true) - .rewrite(new QueryRewriteContext(parserConfig(), null, null, null, new PointInTimeBuilder(new BytesArray("pitid")))) + .rewrite( + new QueryRewriteContext(parserConfig(), null, null, null, new PointInTimeBuilder(new BytesArray("pitid")), null) + ) ); assertEquals("[terminate_after] cannot be used in children of compound retrievers", iae.getMessage()); }