diff options
Diffstat (limited to 'config-model/src/test/java/com/yahoo/searchdefinition')
5 files changed, 72 insertions, 7 deletions
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/RankProfileTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/RankProfileTestCase.java index 8f3fbfc9de9..69789d09dc2 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/RankProfileTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/RankProfileTestCase.java @@ -118,8 +118,13 @@ public class RankProfileTestCase extends SchemaTestCase { @Test public void requireThatSidewaysInheritanceIsImpossible() throws ParseException { + verifySidewaysInheritance(false); + verifySidewaysInheritance(true); + } + private void verifySidewaysInheritance(boolean enforce) throws ParseException { RankProfileRegistry registry = new RankProfileRegistry(); - SearchBuilder builder = new SearchBuilder(registry, setupQueryProfileTypes()); + SearchBuilder builder = new SearchBuilder(registry, setupQueryProfileTypes(), + new TestProperties().enforceRankProfileInheritance(enforce)); builder.importString(joinLines( "schema child1 {", " document child1 {", @@ -163,7 +168,15 @@ public class RankProfileTestCase extends SchemaTestCase { "}")); try { builder.build(true); + if (enforce) { + fail("Sideways inheritance should have been enforced"); + } else { + assertNotNull(builder.getSearch("child2")); + assertNotNull(builder.getSearch("child1")); + assertTrue(registry.get("child1", "child").inherits("parent")); + } } catch (IllegalArgumentException e) { + if (!enforce) fail("Sideways inheritance should have been allowed"); assertEquals("rank-profile 'child' inherits 'parent', but it does not exist anywhere in the inheritance of search 'child1'.", e.getMessage()); } } diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionInliningTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionInliningTestCase.java index d7143281977..d87278a9ca1 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionInliningTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionInliningTestCase.java @@ -2,8 +2,10 @@ package com.yahoo.searchdefinition; import com.yahoo.collections.Pair; +import com.yahoo.config.application.api.DeployLogger; import com.yahoo.config.model.application.provider.MockFileRegistry; import com.yahoo.config.model.deploy.TestProperties; +import com.yahoo.config.model.test.MockApplicationPackage; import com.yahoo.search.query.profile.QueryProfileRegistry; import com.yahoo.searchdefinition.derived.AttributeFields; import com.yahoo.searchdefinition.derived.RawRankProfile; @@ -11,7 +13,9 @@ import com.yahoo.searchdefinition.parser.ParseException; import ai.vespa.rankingexpression.importer.configmodelview.ImportedMlModels; import org.junit.Test; +import java.util.ArrayList; import java.util.Optional; +import java.util.logging.Level; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -26,7 +30,7 @@ public class RankingExpressionInliningTestCase extends SchemaTestCase { RankProfileRegistry rankProfileRegistry = new RankProfileRegistry(); SearchBuilder builder = new SearchBuilder(rankProfileRegistry); builder.importString( - "search test {\n" + + "search test {\n" + " document test { \n" + " field a type double { \n" + " indexing: attribute \n" + @@ -186,6 +190,39 @@ public class RankingExpressionInliningTestCase extends SchemaTestCase { assertEquals("attribute(b) + 1", getRankingExpression("D", test, s)); } + @Test + public void testFunctionInliningWithReplacement() throws ParseException { + RankProfileRegistry rankProfileRegistry = new RankProfileRegistry(); + MockDeployLogger deployLogger = new MockDeployLogger(); + SearchBuilder builder = new SearchBuilder(MockApplicationPackage.createEmpty(), + new MockFileRegistry(), + deployLogger, + new TestProperties(), + rankProfileRegistry, + new QueryProfileRegistry()); + builder.importString( + "search test {\n" + + " document test { }\n" + + " rank-profile test {\n" + + " first-phase {\n" + + " expression: foo\n" + + " }\n" + + " function foo(x) {\n" + + " expression: x + x\n" + + " }\n" + + " function inline foo() {\n" + // replaces previous "foo" during parsing + " expression: foo(2)\n" + + " }\n" + + " }\n" + + "}\n"); + builder.build(); + Search s = builder.getSearch(); + RankProfile test = rankProfileRegistry.get(s, "test").compile(new QueryProfileRegistry(), new ImportedMlModels()); + assertEquals("foo(2)", test.getFirstPhaseRanking().getRoot().toString()); + assertTrue("Does not contain expected warning", deployLogger.contains("Function 'foo' replaces " + + "a previous function with the same name in rank profile 'test'")); + } + /** * Expression evaluation has no stack so function arguments are bound at config time creating a separate version of * each function for each binding, using hashes to name the bound variants of the function. @@ -221,4 +258,17 @@ public class RankingExpressionInliningTestCase extends SchemaTestCase { return censorBindingHash(rankExpression.get()); } + private static class MockDeployLogger implements DeployLogger { + private final ArrayList<String> msgs = new ArrayList<>(); + + @Override + public void log(Level level, String message) { + msgs.add(message); + } + + public boolean contains(String expected) { + return msgs.stream().anyMatch(msg -> msg.equals(expected)); + } + } + } diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/derived/ExportingTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/derived/ExportingTestCase.java index 8ef04752800..12263521dcb 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/derived/ExportingTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/derived/ExportingTestCase.java @@ -9,7 +9,6 @@ import org.junit.Test; import java.io.IOException; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; /** * Tests exporting @@ -106,7 +105,7 @@ public class ExportingTestCase extends AbstractExportingTestCase { @Test public void testRankExpression() throws IOException, ParseException { assertCorrectDeriving("rankexpression", null, - new TestProperties().useExternalRankExpression(true).largeRankExpressionLimit(1024), new TestableDeployLogger()); + new TestProperties().largeRankExpressionLimit(1024), new TestableDeployLogger()); } @Test diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankProfileSearchFixture.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankProfileSearchFixture.java index 010b33597f3..9c363ea0628 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankProfileSearchFixture.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankProfileSearchFixture.java @@ -24,6 +24,8 @@ import ai.vespa.rankingexpression.importer.xgboost.XGBoostImporter; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import static org.junit.Assert.assertEquals; @@ -43,6 +45,7 @@ class RankProfileSearchFixture { private final QueryProfileRegistry queryProfileRegistry; private final Search search; private final Map<String, RankProfile> compiledRankProfiles = new HashMap<>(); + private final ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); public RankProfileRegistry getRankProfileRegistry() { return rankProfileRegistry; @@ -105,7 +108,7 @@ class RankProfileSearchFixture { public RankProfile compileRankProfile(String rankProfile, Path applicationDir) { RankProfile compiled = rankProfileRegistry.get(search, rankProfile) .compile(queryProfileRegistry, - new ImportedMlModels(applicationDir.toFile(), importers)); + new ImportedMlModels(applicationDir.toFile(), executor, importers)); compiledRankProfiles.put(rankProfile, compiled); return compiled; } diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionsTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionsTestCase.java index 00ac5ac5405..b81fe7a02cc 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionsTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionsTestCase.java @@ -36,7 +36,7 @@ public class RankingExpressionsTestCase extends SchemaTestCase { @Test public void testFunctions() throws IOException, ParseException { - ModelContext.Properties deployProperties = new TestProperties().useExternalRankExpression(true); + ModelContext.Properties deployProperties = new TestProperties(); RankProfileRegistry rankProfileRegistry = new RankProfileRegistry(); Search search = createSearch("src/test/examples/rankingexpressionfunction", deployProperties, rankProfileRegistry); RankProfile functionsRankProfile = rankProfileRegistry.get(search, "macros"); @@ -115,7 +115,7 @@ public class RankingExpressionsTestCase extends SchemaTestCase { @Test public void testLargeInheritedFunctions() throws IOException, ParseException { - ModelContext.Properties properties = new TestProperties().useExternalRankExpression(true).largeRankExpressionLimit(50); + ModelContext.Properties properties = new TestProperties().largeRankExpressionLimit(50); RankProfileRegistry rankProfileRegistry = new RankProfileRegistry(); LargeRankExpressions largeExpressions = new LargeRankExpressions(new MockFileRegistry()); QueryProfileRegistry queryProfiles = new QueryProfileRegistry(); |