From 656e755c584897d298fcf95bea5376f1fb1c13f5 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Wed, 29 Mar 2023 12:25:00 +0200 Subject: Use CompoundName.from in tests and construction of static objects. --- .../profile/config/test/XmlReadingTestCase.java | 32 ++++++++++++---------- ...ProfileGetInComplexStructureMicroBenchmark.java | 4 +-- .../test/QueryProfileGetMicroBenchmark.java | 4 +-- .../query/profile/test/QueryProfileTestCase.java | 4 +-- .../profile/test/QueryProfileVariantsTestCase.java | 13 +++++---- .../query/profile/types/test/NameTestCase.java | 6 +--- .../types/test/QueryProfileTypeTestCase.java | 2 +- .../java/com/yahoo/search/test/QueryTestCase.java | 6 ++-- 8 files changed, 34 insertions(+), 37 deletions(-) (limited to 'container-search/src/test/java') diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/XmlReadingTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/XmlReadingTestCase.java index dcb41dc5e31..326c7985a5f 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/XmlReadingTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/XmlReadingTestCase.java @@ -3,10 +3,8 @@ package com.yahoo.search.query.profile.config.test; import com.yahoo.jdisc.http.HttpRequest.Method; import com.yahoo.container.jdisc.HttpRequest; -import com.yahoo.language.Language; import com.yahoo.language.process.Embedder; import com.yahoo.processing.request.CompoundName; -import com.yahoo.search.query.profile.types.test.QueryProfileTypeTestCase; import com.yahoo.tensor.Tensor; import com.yahoo.tensor.TensorType; import com.yahoo.yolean.Exceptions; @@ -25,7 +23,11 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * @author bratseth @@ -77,8 +79,8 @@ public class XmlReadingTestCase { CompiledQueryProfile defaultProfile = cRegistry.getComponent("default"); assertNull(defaultProfile.getType()); assertEquals("20", defaultProfile.get("hits")); - assertFalse(defaultProfile.isOverridable(new CompoundName("hits"), null)); - assertFalse(defaultProfile.isOverridable(new CompoundName("user.trusted"), null)); + assertFalse(defaultProfile.isOverridable(CompoundName.from("hits"), null)); + assertFalse(defaultProfile.isOverridable(CompoundName.from("user.trusted"), null)); assertEquals("false", defaultProfile.get("user.trusted")); CompiledQueryProfile referencingProfile = cRegistry.getComponent("referencingModelSettings"); @@ -97,7 +99,7 @@ public class XmlReadingTestCase { assertEquals("rootType", rootProfile.getType().getId().getName()); assertEquals(30, rootProfile.get("hits")); //assertEquals(3, rootProfile.get("traceLevel")); - assertTrue(rootProfile.isOverridable(new CompoundName("hits"), null)); + assertTrue(rootProfile.isOverridable(CompoundName.from("hits"), null)); query = new Query(request, rootProfile); assertEquals(3, query.getTrace().getLevel()); @@ -231,8 +233,8 @@ public class XmlReadingTestCase { assertEquals("a.b.c-value", new Query("?d1=d1v", profile).properties().get("a.b.c")); assertEquals("a.b.c-variant-value", new Query("?d1=d1v&d2=d2v", profile).properties().get("a.b.c")); - assertTrue(profile.isOverridable(new CompoundName("a.b.c"), Map.of("d1", "d1v"))); - assertFalse(profile.isOverridable(new CompoundName("a.b.c"), Map.of("d1", "d1v", "d2", "d2v"))); + assertTrue(profile.isOverridable(CompoundName.from("a.b.c"), Map.of("d1", "d1v"))); + assertFalse(profile.isOverridable(CompoundName.from("a.b.c"), Map.of("d1", "d1v", "d2", "d2v"))); } @Test @@ -479,18 +481,18 @@ public class XmlReadingTestCase { QueryProfileType type1 = registry.getTypeRegistry().getComponent("type1"); assertEquals(TensorType.fromSpec("tensor(x[1])"), - type1.getFieldType(new CompoundName("ranking.features.query(tensor_1)")).asTensorType()); - assertNull(type1.getFieldType(new CompoundName("ranking.features.query(tensor_2)"))); - assertNull(type1.getFieldType(new CompoundName("ranking.features.query(tensor_3)"))); + type1.getFieldType(CompoundName.from("ranking.features.query(tensor_1)")).asTensorType()); + assertNull(type1.getFieldType(CompoundName.from("ranking.features.query(tensor_2)"))); + assertNull(type1.getFieldType(CompoundName.from("ranking.features.query(tensor_3)"))); assertEquals(TensorType.fromSpec("tensor(key{})"), - type1.getFieldType(new CompoundName("ranking.features.query(tensor_4)")).asTensorType()); + type1.getFieldType(CompoundName.from("ranking.features.query(tensor_4)")).asTensorType()); QueryProfileType type2 = registry.getTypeRegistry().getComponent("type2"); - assertNull(type2.getFieldType(new CompoundName("ranking.features.query(tensor_1)"))); + assertNull(type2.getFieldType(CompoundName.from("ranking.features.query(tensor_1)"))); assertEquals(TensorType.fromSpec("tensor(x[2])"), - type2.getFieldType(new CompoundName("ranking.features.query(tensor_2)")).asTensorType()); + type2.getFieldType(CompoundName.from("ranking.features.query(tensor_2)")).asTensorType()); assertEquals(TensorType.fromSpec("tensor(x[3])"), - type2.getFieldType(new CompoundName("ranking.features.query(tensor_3)")).asTensorType()); + type2.getFieldType(CompoundName.from("ranking.features.query(tensor_3)")).asTensorType()); Query queryProfile1 = new Query.Builder().setQueryProfile(registry.getComponent("profile1")) .setRequest("?query=test&ranking.features.query(tensor_1)=[1.200]") diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileGetInComplexStructureMicroBenchmark.java b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileGetInComplexStructureMicroBenchmark.java index cd5a8e08aa9..080aef25c5f 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileGetInComplexStructureMicroBenchmark.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileGetInComplexStructureMicroBenchmark.java @@ -65,8 +65,8 @@ public class QueryProfileGetInComplexStructureMicroBenchmark { Map dimensionValues=createDimensionValueMap(); String prefix=generatePrefix(); final int dotInterval=1000000; - final CompoundName found = new CompoundName(prefix + "a"); - final CompoundName notFound = new CompoundName(prefix + "nonexisting"); + final CompoundName found = CompoundName.from(prefix + "a"); + final CompoundName notFound = CompoundName.from(prefix + "nonexisting"); for (int i=0; idotInterval && i%(dotInterval)==0) System.out.print("."); diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileGetMicroBenchmark.java b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileGetMicroBenchmark.java index d38a1d64910..1123feb1b01 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileGetMicroBenchmark.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileGetMicroBenchmark.java @@ -57,8 +57,8 @@ public class QueryProfileGetMicroBenchmark { private void getValues(int count,Query query) { final int dotInterval=10000000; - CompoundName found = new CompoundName(propertyPrefix + "property1"); - CompoundName notFound = new CompoundName(propertyPrefix + "nonExisting"); + CompoundName found = CompoundName.from(propertyPrefix + "property1"); + CompoundName notFound = CompoundName.from(propertyPrefix + "nonExisting"); for (int i=0; idotInterval && i%(count/dotInterval)==0) System.out.print("."); diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileTestCase.java index cd4cb32df2e..7d5a2137770 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileTestCase.java @@ -534,7 +534,7 @@ public class QueryProfileTestCase { p.set("a.b", "a.b-value", null); { - Map values = p.compile(null).listValuesWithSources(new CompoundName(""), new HashMap<>(), null); + Map values = p.compile(null).listValuesWithSources(CompoundName.empty, new HashMap<>(), null); assertEquals(2, values.size()); assertEquals("a-value", values.get("a").value()); assertEquals("test", values.get("a").source()); @@ -543,7 +543,7 @@ public class QueryProfileTestCase { } { - Map values = p.compile(null).listValuesWithSources(new CompoundName("a"), new HashMap<>(), null); + Map values = p.compile(null).listValuesWithSources(CompoundName.from("a"), new HashMap<>(), null); assertEquals(1, values.size()); assertEquals("a.b-value", values.get("b").value()); assertEquals("test", values.get("b").source()); diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileVariantsTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileVariantsTestCase.java index 1a6cfee75a5..36ff33ffd97 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileVariantsTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/test/QueryProfileVariantsTestCase.java @@ -5,7 +5,6 @@ import ai.vespa.cloud.ApplicationId; import ai.vespa.cloud.Environment; import ai.vespa.cloud.Zone; import ai.vespa.cloud.ZoneInfo; -import com.yahoo.jdisc.application.Application; import com.yahoo.jdisc.http.HttpRequest.Method; import com.yahoo.container.jdisc.HttpRequest; import com.yahoo.processing.request.CompoundName; @@ -28,7 +27,9 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author bratseth @@ -133,7 +134,7 @@ public class QueryProfileVariantsTestCase { base.set("a.b", 1, new String[]{null, null, "d3-val"}, registry); QueryProfileVariant aVariants = base.getVariants().getVariants().get(0); assertEquals("[d1, d2, d3]", - ((QueryProfile) base.getVariants().getVariants().get(0).values().get("a")).getDimensions().toString(), + ((QueryProfile) aVariants.values().get("a")).getDimensions().toString(), "Variant dimensions are not overridden by the referenced dimensions"); } @@ -184,7 +185,7 @@ public class QueryProfileVariantsTestCase { { Map values = cRegistry.findQueryProfile("test") - .listValuesWithSources(new CompoundName(""), + .listValuesWithSources(CompoundName.empty, new HashMap<>(), null); assertEquals(1, values.size()); @@ -195,7 +196,7 @@ public class QueryProfileVariantsTestCase { { Map values = cRegistry.findQueryProfile("test") - .listValuesWithSources(new CompoundName(""), + .listValuesWithSources(CompoundName.empty, toMap("x=x1", "y=y1", "z=z1"), null); assertEquals(2, values.size()); @@ -1456,7 +1457,7 @@ public class QueryProfileVariantsTestCase { return context; } - public static final Map toMap(String... bindings) { + public static Map toMap(String... bindings) { Map context = new HashMap<>(); for (String binding : bindings) { String[] entry = binding.split("="); diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/NameTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/NameTestCase.java index 37991f7f14f..982ebd80fbd 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/NameTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/NameTestCase.java @@ -55,7 +55,7 @@ public class NameTestCase { @Test void testComponentIdAsCompoundName() { String name = "a/b"; - assertEquals(new CompoundName(name), new QueryProfileType(name).getComponentIdAsCompoundName()); + assertEquals(CompoundName.from(name), new QueryProfileType(name).getComponentIdAsCompoundName()); } private void assertLegalName(String name) { @@ -89,10 +89,6 @@ public class NameTestCase { } } - private void assertIllegalFieldName(String name) { - assertIllegalFieldName(name,"Could not set '" + name + "' to 'anyValue'","Illegal name '" + name + "'"); - } - /** Checks that this is illegal both for profiles and types */ private void assertIllegalFieldName(String name, String expectedHighError, String expectedLowError) { try { diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/QueryProfileTypeTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/QueryProfileTypeTestCase.java index 21a9b2fe399..4000c48bfed 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/QueryProfileTypeTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/QueryProfileTypeTestCase.java @@ -761,7 +761,7 @@ public class QueryProfileTypeTestCase { } private void assertNotPermitted(QueryProfile profile,String name,Object value) { - String localName = new CompoundName(name).last(); + String localName = CompoundName.from(name).last(); try { profile.set(name, value, registry); fail("Should fail setting " + name + " to " + value); diff --git a/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java b/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java index 748a20801d1..63655da0784 100644 --- a/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java @@ -2,7 +2,6 @@ package com.yahoo.search.test; import com.yahoo.component.chain.Chain; -import com.yahoo.data.JsonProducer; import com.yahoo.language.Language; import com.yahoo.language.Linguistics; import com.yahoo.language.detect.Detection; @@ -16,7 +15,6 @@ import com.yahoo.prelude.Index; import com.yahoo.prelude.IndexFacts; import com.yahoo.prelude.IndexModel; import com.yahoo.prelude.SearchDefinition; -import com.yahoo.prelude.fastsearch.FastHit; import com.yahoo.prelude.query.AndItem; import com.yahoo.prelude.query.AndSegmentItem; import com.yahoo.prelude.query.CompositeItem; @@ -145,7 +143,7 @@ public class QueryTestCase { @Test void testCloneWithConnectivity() { List l = List.of("a", "b", "c", "a"); - printIt(l.stream().filter(i -> isA(i)).toList()); + printIt(l.stream().filter(this::isA).toList()); printIt(l.stream().filter(i -> !isA(i)).toList()); Query q = new Query(); @@ -314,7 +312,7 @@ public class QueryTestCase { profile.set("myField", "Profile: %{queryProfile}", null); Query query = new Query(QueryTestCase.httpEncode("/search?queryProfile=myProfile"), profile.compile(null)); - String source = query.properties().getInstance(com.yahoo.search.query.profile.QueryProfileProperties.class).getQueryProfile().listValuesWithSources(new CompoundName(""), query.getHttpRequest().propertyMap(), query.properties()).get("myField").source(); + String source = query.properties().getInstance(com.yahoo.search.query.profile.QueryProfileProperties.class).getQueryProfile().listValuesWithSources(CompoundName.empty, query.getHttpRequest().propertyMap(), query.properties()).get("myField").source(); assertEquals("myProfile", source); } -- cgit v1.2.3