diff options
author | Jon Bratseth <bratseth@gmail.com> | 2022-05-31 23:32:02 +0200 |
---|---|---|
committer | gjoranv <gv@verizonmedia.com> | 2022-06-08 11:45:23 +0200 |
commit | 1463c41b72fb46fa3bd57be965b0d0681749944d (patch) | |
tree | 9f98272202c5405476e548e88805224c804dd668 /container-search/src/test/java/com | |
parent | d8c94dd62a910e8f66bbe341fa96eef6bb3f1121 (diff) |
Remove on Vespa 8
Diffstat (limited to 'container-search/src/test/java/com')
2 files changed, 59 insertions, 68 deletions
diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/QueryProfileConfigurationTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/QueryProfileConfigurationTestCase.java index 84bb82f3851..29a8969233b 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/QueryProfileConfigurationTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/QueryProfileConfigurationTestCase.java @@ -5,10 +5,7 @@ import com.yahoo.search.Query; import com.yahoo.search.query.profile.QueryProfile; import com.yahoo.search.query.profile.QueryProfileProperties; import com.yahoo.search.query.profile.compiled.CompiledQueryProfile; -import com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry; import com.yahoo.search.query.profile.config.QueryProfileConfigurer; -import com.yahoo.search.query.profile.config.QueryProfilesConfig; -import com.yahoo.search.query.profile.config.QueryProfilesConfig.Queryprofile; import com.yahoo.search.test.QueryTestCase; import org.junit.Test; @@ -29,27 +26,27 @@ public class QueryProfileConfigurationTestCase { @Test public void testConfiguration() { - QueryProfileConfigurer configurer= - new QueryProfileConfigurer("file:" + CONFIG_DIR + "query-profiles-configuration.cfg"); - QueryProfile profile=configurer.getCurrentRegistry().getComponent("default"); + var profile = QueryProfileConfigurer.createFromConfigId("file:" + CONFIG_DIR + "query-profiles-configuration.cfg") + .getComponent("default"); - assertEquals("a-value",profile.get("a")); - assertEquals("b-value",profile.get("b")); - assertEquals("c.d-value",profile.get("c.d")); + assertEquals("a-value", profile.get("a")); + assertEquals("b-value", profile.get("b")); + assertEquals("c.d-value", profile.get("c.d")); assertFalse(profile.isDeclaredOverridable("c.d", null)); - assertEquals("e-value-inherited1",profile.get("e")); - assertEquals("g.d2-value-inherited1",profile.get("g.d2")); // Even though we make an explicit reference to one not having this value, we still inherit it - assertEquals("a-value-subprofile1",profile.get("sub1.a")); - assertEquals("c.d-value-subprofile1",profile.get("sub1.c.d")); - assertEquals("a-value-subprofile2",profile.get("sub2.a")); - assertEquals("c.d-value-subprofile2",profile.get("sub2.c.d")); - assertEquals("e-value-subprofile3",profile.get("g.e")); + assertEquals("e-value-inherited1", profile.get("e")); + assertEquals("g.d2-value-inherited1", profile.get("g.d2")); // Even though we make an explicit reference to one not having this value, we still inherit it + assertEquals("a-value-subprofile1", profile.get("sub1.a")); + assertEquals("c.d-value-subprofile1", profile.get("sub1.c.d")); + assertEquals("a-value-subprofile2", profile.get("sub2.a")); + assertEquals("c.d-value-subprofile2", profile.get("sub2.c.d")); + assertEquals("e-value-subprofile3", profile.get("g.e")); } @Test public void testBug3197426() { - QueryProfileConfigurer configurer = new QueryProfileConfigurer("file:" + CONFIG_DIR + "bug3197426.cfg"); - CompiledQueryProfile profile = configurer.getCurrentRegistry().getComponent("default").compile(null); + var profile = QueryProfileConfigurer.createFromConfigId("file:" + CONFIG_DIR + "bug3197426.cfg") + .getComponent("default").compile(null); + Map<String, Object> properties = new QueryProfileProperties(profile).listProperties("source.image"); assertEquals("yes", properties.get("mlr")); assertEquals("zh-Hant", properties.get("language")); @@ -67,44 +64,42 @@ public class QueryProfileConfigurationTestCase { @Test public void testVariantConfiguration() { - QueryProfileConfigurer configurer= - new QueryProfileConfigurer("file:" + CONFIG_DIR + "query-profile-variants-configuration.cfg"); + var registry = QueryProfileConfigurer.createFromConfigId("file:" + CONFIG_DIR + "query-profile-variants-configuration.cfg"); // Variant 1 - QueryProfile variants1 =configurer.getCurrentRegistry().getComponent("variants1"); - assertGet("x1.y1.a","a",new String[] { "x1","y1" }, variants1); - assertGet("x1.y1.b","b",new String[] { "x1","y1" }, variants1); - assertGet("x1.y?.a","a",new String[] { "x1","zz" }, variants1); - assertGet("x?.y1.a","a",new String[] { "zz","y1" }, variants1); - assertGet("a-deflt","a",new String[] { "z1","z2" }, variants1); + QueryProfile variants1 = registry.getComponent("variants1"); + assertGet("x1.y1.a", "a", new String[] { "x1","y1" }, variants1); + assertGet("x1.y1.b", "b", new String[] { "x1","y1" }, variants1); + assertGet("x1.y?.a", "a", new String[] { "x1","zz" }, variants1); + assertGet("x?.y1.a", "a", new String[] { "zz","y1" }, variants1); + assertGet("a-deflt", "a", new String[] { "z1","z2" }, variants1); // ...inherited - assertGet("parent1-value","parent1",new String[] { "x1","y1" }, variants1); - assertGet("parent2-value","parent2",new String[] { "x1","y1" }, variants1); - assertGet(null,"parent1",new String[] { "x1","y2" }, variants1); - assertGet(null,"parent2",new String[] { "x1","y2" }, variants1); + assertGet("parent1-value", "parent1", new String[] { "x1","y1" }, variants1); + assertGet("parent2-value", "parent2", new String[] { "x1","y1" }, variants1); + assertGet(null, "parent1", new String[] { "x1","y2" }, variants1); + assertGet(null, "parent2", new String[] { "x1","y2" }, variants1); // Variant 2 - QueryProfile variants2 =configurer.getCurrentRegistry().getComponent("variants2"); - assertGet("variant2:y1.c","c",new String[] { "*","y1" }, variants2); - assertGet("variant2:y2.c","c",new String[] { "*","y2" }, variants2); - assertGet("variant2:c-df","c",new String[] { "*","z1" }, variants2); - assertGet("variant2:c-df","c",new String[] { }, variants2); - assertGet("variant2:c-df","c",new String[] { "*" }, variants2); - assertGet(null, "d",new String[] { "*","y1" }, variants2); + QueryProfile variants2 = registry.getComponent("variants2"); + assertGet("variant2:y1.c", "c", new String[] { "*","y1" }, variants2); + assertGet("variant2:y2.c", "c", new String[] { "*","y2" }, variants2); + assertGet("variant2:c-df", "c", new String[] { "*","z1" }, variants2); + assertGet("variant2:c-df", "c", new String[] { }, variants2); + assertGet("variant2:c-df", "c", new String[] { "*" }, variants2); + assertGet(null, "d", new String[] { "*","y1" }, variants2); // Reference following from variant 1 - assertGet("variant2:y1.c","toVariants.c",new String[] { "**", "y1" } , variants1); - assertGet("variant3:c-df","toVariants.c",new String[] { "x1", "**" } , variants1); - assertGet("variant3:y1.c","toVariants.c",new String[] { "x1", "y1" } , variants1); // variant3 by order priority - assertGet("variant3:y2.c","toVariants.c",new String[] { "x1", "y2" } , variants1); + assertGet("variant2:y1.c", "toVariants.c", new String[] { "**", "y1" } , variants1); + assertGet("variant3:c-df", "toVariants.c", new String[] { "x1", "**" } , variants1); + assertGet("variant3:y1.c", "toVariants.c", new String[] { "x1", "y1" } , variants1); // variant3 by order priority + assertGet("variant3:y2.c", "toVariants.c", new String[] { "x1", "y2" } , variants1); } @Test public void testVariantConfigurationThroughQueryLookup() { - QueryProfileConfigurer configurer= - new QueryProfileConfigurer("file:" + CONFIG_DIR + "query-profile-variants-configuration.cfg"); + var registry = QueryProfileConfigurer.createFromConfigId("file:" + CONFIG_DIR + "query-profile-variants-configuration.cfg") + .compile(); - CompiledQueryProfileRegistry registry = configurer.getCurrentRegistry().compile(); CompiledQueryProfile variants1 = registry.getComponent("variants1"); // Variant 1 @@ -138,10 +133,9 @@ public class QueryProfileConfigurationTestCase { public void testVariant2ConfigurationThroughQueryLookup() { final double delta = 0.0000001; - QueryProfileConfigurer configurer= - new QueryProfileConfigurer("file:" + CONFIG_DIR + "query-profile-variants2.cfg"); + var registry = QueryProfileConfigurer.createFromConfigId("file:" + CONFIG_DIR + "query-profile-variants2.cfg") + .compile(); - CompiledQueryProfileRegistry registry = configurer.getCurrentRegistry().compile(); Query query = new Query(QueryTestCase.httpEncode("?query=heh&queryProfile=multi&myindex=default&myquery=lo ve&tracelevel=5"), registry.findQueryProfile("multi")); assertEquals("love", query.properties().get("model.queryString")); @@ -154,11 +148,12 @@ public class QueryProfileConfigurationTestCase { assertEquals(-30, query.getRanking().getFeatures().getDouble("query(scorelimit)").getAsDouble(), delta); } - private void assertGet(String expectedValue,String parameter,String[] dimensionValues,QueryProfile profile) { - Map<String,String> context=new HashMap<>(); - for (int i=0; i<dimensionValues.length; i++) - context.put(profile.getVariants().getDimensions().get(i),dimensionValues[i]); // Lookup dim. names to ease test... - assertEquals("Looking up '" + parameter + "' for '" + Arrays.toString(dimensionValues) + "'",expectedValue,profile.get(parameter, context, null)); + private void assertGet(String expectedValue, String parameter, String[] dimensionValues, QueryProfile profile) { + Map<String, String> context = new HashMap<>(); + for (int i = 0; i<dimensionValues.length; i++) + context.put(profile.getVariants().getDimensions().get(i), dimensionValues[i]); // Lookup dim. names to ease test... + assertEquals("Looking up '" + parameter + "' for '" + Arrays.toString(dimensionValues) + "'", + expectedValue, profile.get(parameter, context, null)); } } diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/TypedProfilesConfigurationTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/TypedProfilesConfigurationTestCase.java index 0531d847c9e..944ee6d79ef 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/config/test/TypedProfilesConfigurationTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/config/test/TypedProfilesConfigurationTestCase.java @@ -1,11 +1,9 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.query.profile.config.test; -import com.yahoo.search.query.profile.QueryProfileRegistry; import com.yahoo.search.query.profile.config.QueryProfileConfigurer; import com.yahoo.search.query.profile.types.FieldDescription; import com.yahoo.search.query.profile.types.QueryProfileType; -import com.yahoo.search.query.profile.types.QueryProfileTypeRegistry; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -20,45 +18,43 @@ public class TypedProfilesConfigurationTestCase { /** Asserts that everything is read correctly from this configuration */ @Test public void testIt() { - QueryProfileConfigurer configurer= - new QueryProfileConfigurer("file:src/test/java/com/yahoo/search/query/profile/config/test/typed-profiles.cfg"); - QueryProfileRegistry registry=configurer.getCurrentRegistry(); - QueryProfileTypeRegistry types=registry.getTypeRegistry(); + var registry = QueryProfileConfigurer.createFromConfigId("file:src/test/java/com/yahoo/search/query/profile/config/test/typed-profiles.cfg"); + var types = registry.getTypeRegistry(); // Assert that each type was read correctly - QueryProfileType testType=types.getComponent("testtype"); - assertEquals("testtype",testType.getId().getName()); + QueryProfileType testType = types.getComponent("testtype"); + assertEquals("testtype", testType.getId().getName()); assertFalse(testType.isStrict()); assertFalse(testType.getMatchAsPath()); - assertEquals(7,testType.fields().size()); - assertEquals("myString",testType.getField("myString").getName()); + assertEquals(7, testType.fields().size()); + assertEquals("myString", testType.getField("myString").getName()); assertTrue(testType.getField("myString").isMandatory()); assertTrue(testType.getField("myString").isOverridable()); assertFalse(testType.getField("myInteger").isMandatory()); assertFalse(testType.getField("myInteger").isOverridable()); FieldDescription field= testType.getField("myUserQueryProfile"); - assertEquals("reference to a query profile of type 'user'",field.getType().toInstanceDescription()); + assertEquals("reference to a query profile of type 'user'", field.getType().toInstanceDescription()); assertTrue(field.getAliases().contains("myqp")); assertTrue(field.getAliases().contains("user-profile")); QueryProfileType testTypeStrict=types.getComponent("testtypestrict"); assertTrue(testTypeStrict.isStrict()); assertTrue(testTypeStrict.getMatchAsPath()); - assertEquals(7,testTypeStrict.fields().size()); + assertEquals(7, testTypeStrict.fields().size()); assertEquals("reference to a query profile of type 'userstrict'", testTypeStrict.getField("myUserQueryProfile").getType().toInstanceDescription()); QueryProfileType user=types.getComponent("user"); assertFalse(user.isStrict()); assertFalse(user.getMatchAsPath()); - assertEquals(2,user.fields().size()); - assertEquals(String.class,user.getField("myUserString").getType().getValueClass()); + assertEquals(2, user.fields().size()); + assertEquals(String.class, user.getField("myUserString").getType().getValueClass()); - QueryProfileType userStrict=types.getComponent("userstrict"); + QueryProfileType userStrict = types.getComponent("userstrict"); assertTrue(userStrict.isStrict()); assertFalse(userStrict.getMatchAsPath()); - assertEquals(2,userStrict.fields().size()); + assertEquals(2, userStrict.fields().size()); } } |