From 3cf559bf9caabcc134604d0c5930895f4d692b09 Mon Sep 17 00:00:00 2001 From: Luca Cavanna Date: Thu, 17 Sep 2020 14:45:55 +0200 Subject: [PATCH] Minor cleanup of runtime fields classes (#62531) This commit addresses some compiler warnings in the runtime fields classes --- .../fielddata/BinaryScriptFieldData.java | 2 +- .../fielddata/BooleanScriptDocValues.java | 4 +--- .../fielddata/BooleanScriptFieldData.java | 4 +--- .../fielddata/DateScriptFieldData.java | 4 +--- .../fielddata/DoubleScriptDocValues.java | 3 +-- .../fielddata/DoubleScriptFieldData.java | 4 +--- .../mapper/AbstractFieldScript.java | 2 +- ...AbstractScriptMappedFieldTypeTestCase.java | 22 +++++++++---------- .../mapper/RuntimeFieldMapperTests.java | 10 ++------- 9 files changed, 20 insertions(+), 35 deletions(-) diff --git a/x-pack/plugin/runtime-fields/src/main/java/org/elasticsearch/xpack/runtimefields/fielddata/BinaryScriptFieldData.java b/x-pack/plugin/runtime-fields/src/main/java/org/elasticsearch/xpack/runtimefields/fielddata/BinaryScriptFieldData.java index e70ef6e860b..e2445bc4211 100644 --- a/x-pack/plugin/runtime-fields/src/main/java/org/elasticsearch/xpack/runtimefields/fielddata/BinaryScriptFieldData.java +++ b/x-pack/plugin/runtime-fields/src/main/java/org/elasticsearch/xpack/runtimefields/fielddata/BinaryScriptFieldData.java @@ -59,7 +59,7 @@ public abstract class BinaryScriptFieldData implements IndexFieldData ScriptContext newContext(String name, Class factoryClass) { - return new ScriptContext( + return new ScriptContext<>( name + "_script_field", factoryClass, /* diff --git a/x-pack/plugin/runtime-fields/src/test/java/org/elasticsearch/xpack/runtimefields/mapper/AbstractScriptMappedFieldTypeTestCase.java b/x-pack/plugin/runtime-fields/src/test/java/org/elasticsearch/xpack/runtimefields/mapper/AbstractScriptMappedFieldTypeTestCase.java index f5f9e2663e2..18b8f93b3b5 100644 --- a/x-pack/plugin/runtime-fields/src/test/java/org/elasticsearch/xpack/runtimefields/mapper/AbstractScriptMappedFieldTypeTestCase.java +++ b/x-pack/plugin/runtime-fields/src/test/java/org/elasticsearch/xpack/runtimefields/mapper/AbstractScriptMappedFieldTypeTestCase.java @@ -86,15 +86,15 @@ abstract class AbstractScriptMappedFieldTypeTestCase extends ESTestCase { return context; } - public void testExistsQueryIsExpensive() throws IOException { + public void testExistsQueryIsExpensive() { checkExpensiveQuery(MappedFieldType::existsQuery); } - public void testExistsQueryInLoop() throws IOException { + public void testExistsQueryInLoop() { checkLoop(MappedFieldType::existsQuery); } - public void testRangeQueryWithShapeRelationIsError() throws IOException { + public void testRangeQueryWithShapeRelationIsError() { Exception e = expectThrows( IllegalArgumentException.class, () -> simpleMappedFieldType().rangeQuery(1, 2, true, true, ShapeRelation.DISJOINT, null, null, null) @@ -105,27 +105,27 @@ abstract class AbstractScriptMappedFieldTypeTestCase extends ESTestCase { ); } - public void testRangeQueryIsExpensive() throws IOException { + public void testRangeQueryIsExpensive() { checkExpensiveQuery(this::randomRangeQuery); } - public void testRangeQueryInLoop() throws IOException { + public void testRangeQueryInLoop() { checkLoop(this::randomRangeQuery); } - public void testTermQueryIsExpensive() throws IOException { + public void testTermQueryIsExpensive() { checkExpensiveQuery(this::randomTermQuery); } - public void testTermQueryInLoop() throws IOException { + public void testTermQueryInLoop() { checkLoop(this::randomTermQuery); } - public void testTermsQueryIsExpensive() throws IOException { + public void testTermsQueryIsExpensive() { checkExpensiveQuery(this::randomTermsQuery); } - public void testTermsQueryInLoop() throws IOException { + public void testTermsQueryInLoop() { checkLoop(this::randomTermsQuery); } @@ -163,7 +163,7 @@ abstract class AbstractScriptMappedFieldTypeTestCase extends ESTestCase { return reader.document(docId).getBinaryValue("_source").utf8ToString(); } - protected final void checkExpensiveQuery(BiConsumer queryBuilder) throws IOException { + protected final void checkExpensiveQuery(BiConsumer queryBuilder) { Exception e = expectThrows(ElasticsearchException.class, () -> queryBuilder.accept(simpleMappedFieldType(), mockContext(false))); assertThat( e.getMessage(), @@ -171,7 +171,7 @@ abstract class AbstractScriptMappedFieldTypeTestCase extends ESTestCase { ); } - protected final void checkLoop(BiConsumer queryBuilder) throws IOException { + protected final void checkLoop(BiConsumer queryBuilder) { Exception e = expectThrows(IllegalArgumentException.class, () -> queryBuilder.accept(loopFieldType(), mockContext())); assertThat(e.getMessage(), equalTo("Cyclic dependency detected while resolving runtime fields: test -> test")); } diff --git a/x-pack/plugin/runtime-fields/src/test/java/org/elasticsearch/xpack/runtimefields/mapper/RuntimeFieldMapperTests.java b/x-pack/plugin/runtime-fields/src/test/java/org/elasticsearch/xpack/runtimefields/mapper/RuntimeFieldMapperTests.java index 18133580190..bd448e3febf 100644 --- a/x-pack/plugin/runtime-fields/src/test/java/org/elasticsearch/xpack/runtimefields/mapper/RuntimeFieldMapperTests.java +++ b/x-pack/plugin/runtime-fields/src/test/java/org/elasticsearch/xpack/runtimefields/mapper/RuntimeFieldMapperTests.java @@ -35,6 +35,7 @@ import java.io.IOException; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.HashSet; import java.util.Set; import static org.hamcrest.Matchers.equalTo; @@ -381,14 +382,7 @@ public class RuntimeFieldMapperTests extends MapperTestCase { }; public Set> getSupportedContexts() { - return org.elasticsearch.common.collect.Set.of( - BooleanFieldScript.CONTEXT, - DateFieldScript.CONTEXT, - DoubleFieldScript.CONTEXT, - IpFieldScript.CONTEXT, - StringFieldScript.CONTEXT, - LongFieldScript.CONTEXT - ); + return new HashSet<>(new RuntimeFields().getContexts()); } }; }