diff options
Diffstat (limited to 'config-model/src/test/java')
4 files changed, 240 insertions, 24 deletions
diff --git a/config-model/src/test/java/com/yahoo/schema/NoNormalizersTestCase.java b/config-model/src/test/java/com/yahoo/schema/NoNormalizersTestCase.java new file mode 100644 index 00000000000..6e2efadfa2c --- /dev/null +++ b/config-model/src/test/java/com/yahoo/schema/NoNormalizersTestCase.java @@ -0,0 +1,172 @@ +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.schema; + +import com.yahoo.search.query.profile.QueryProfileRegistry; +import com.yahoo.schema.parser.ParseException; +import com.yahoo.yolean.Exceptions; +import ai.vespa.rankingexpression.importer.configmodelview.ImportedMlModels; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +/** + * Tests rank profiles with normalizers in bad places + * + * @author arnej + */ +public class NoNormalizersTestCase extends AbstractSchemaTestCase { + + void compileSchema(String schema) throws ParseException { + RankProfileRegistry registry = new RankProfileRegistry(); + var qp = new QueryProfileRegistry(); + ApplicationBuilder builder = new ApplicationBuilder(registry, qp); + builder.addSchema(schema); + builder.build(true); + for (RankProfile rp : registry.all()) { + rp.compile(qp, new ImportedMlModels()); + } + } + + @Test + void requireThatNormalizerInFirstPhaseIsChecked() throws ParseException { + try { + compileSchema(""" + search test { + document test { } + rank-profile p1 { + first-phase { + expression: normalize_linear(nativeRank) + } + } + } + """); + fail(); + } catch (IllegalArgumentException e) { + assertEquals("Rank profile 'p1' is invalid: " + + "Cannot use normalize_linear(nativeRank) from first-phase expression, only valid in global-phase expression", + Exceptions.toMessageString(e)); + } + } + + @Test + void requireThatNormalizerInSecondPhaseIsChecked() throws ParseException { + try { + compileSchema(""" + search test { + document test { + field title type string { + indexing: index + } + } + rank-profile p2 { + function foobar() { + expression: 42 + reciprocal_rank(whatever, 1.0) + } + function whatever() { + expression: fieldMatch(title) + } + first-phase { + expression: nativeRank + } + second-phase { + expression: foobar + } + } + } + """); + fail(); + } catch (IllegalArgumentException e) { + assertEquals("Rank profile 'p2' is invalid: " + + "Cannot use reciprocal_rank(whatever,1.0) from second-phase expression, only valid in global-phase expression", + Exceptions.toMessageString(e)); + } + } + + @Test + void requireThatNormalizerInMatchFeatureIsChecked() throws ParseException { + try { + compileSchema(""" + search test { + document test { } + rank-profile p3 { + function foobar() { + expression: normalize_linear(nativeRank) + } + first-phase { + expression: nativeRank + } + match-features { + nativeRank + foobar + } + } + } + """); + fail(); + } catch (IllegalArgumentException e) { + assertEquals("Rank profile 'p3' is invalid: " + + "Cannot use normalize_linear(nativeRank) from match-feature foobar, only valid in global-phase expression", + Exceptions.toMessageString(e)); + } + } + + @Test + void requireThatNormalizerInSummaryFeatureIsChecked() throws ParseException { + try { + compileSchema(""" + search test { + document test { } + rank-profile p4 { + function foobar() { + expression: normalize_linear(nativeRank) + } + first-phase { + expression: nativeRank + } + summary-features { + nativeRank + foobar + } + } + } + """); + fail(); + } catch (IllegalArgumentException e) { + assertEquals("Rank profile 'p4' is invalid: " + + "Cannot use normalize_linear(nativeRank) from summary-feature foobar, only valid in global-phase expression", + Exceptions.toMessageString(e)); + } + } + + @Test + void requireThatNormalizerInNormalizerIsChecked() throws ParseException { + try { + compileSchema(""" + search test { + document test { + field title type string { + indexing: index + } + } + rank-profile p5 { + function foobar() { + expression: reciprocal_rank(nativeRank) + } + first-phase { + expression: nativeRank + } + global-phase { + expression: normalize_linear(fieldMatch(title)) + normalize_linear(foobar) + } + } + } + """); + fail(); + } catch (IllegalArgumentException e) { + assertEquals("Rank profile 'p5' is invalid: " + + "Cannot use reciprocal_rank(nativeRank) from normalizer input foobar, only valid in global-phase expression", + Exceptions.toMessageString(e)); + } + } +} diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/AccessLogTest.java b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/AccessLogTest.java index f2e4ec052cb..a38a29893e0 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/AccessLogTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/AccessLogTest.java @@ -16,6 +16,7 @@ import com.yahoo.container.logging.ConnectionLogConfig; import com.yahoo.container.logging.FileConnectionLog; import com.yahoo.container.logging.JSONAccessLog; import com.yahoo.container.logging.VespaAccessLog; +import com.yahoo.jdisc.http.ServerConfig; import com.yahoo.vespa.model.container.ApplicationContainerCluster; import com.yahoo.vespa.model.container.component.Component; import org.junit.jupiter.api.Test; @@ -129,6 +130,7 @@ public class AccessLogTest extends ContainerModelBuilderTestBase { assertEquals("default", config.cluster()); assertEquals(-1, config.queueSize()); assertEquals(256 * 1024, config.bufferSize()); + assertTrue(root.getConfig(ServerConfig.class, "default/container.0/DefaultHttpServer").connectionLog().enabled()); } @Test @@ -141,6 +143,7 @@ public class AccessLogTest extends ContainerModelBuilderTestBase { createModel(root, clusterElem); Component<?, ?> fileConnectionLogComponent = getComponent("default", FileConnectionLog.class.getName()); assertNull(fileConnectionLogComponent); + assertFalse(root.getConfig(ServerConfig.class, "default/container.0/DefaultHttpServer").connectionLog().enabled()); } @Test diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/HandlerBuilderTest.java b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/HandlerBuilderTest.java index 8a7ca27eec5..fdeea85c5a3 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/HandlerBuilderTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/HandlerBuilderTest.java @@ -1,11 +1,11 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.model.container.xml; +import com.yahoo.config.application.api.DeployLogger; import com.yahoo.config.model.ConfigModelContext; import com.yahoo.config.model.builder.xml.test.DomBuilderTest; import com.yahoo.config.model.deploy.DeployState; import com.yahoo.config.model.deploy.TestProperties; -import com.yahoo.config.provision.ApplicationId; import com.yahoo.container.ComponentsConfig; import com.yahoo.container.jdisc.JdiscBindingsConfig; import com.yahoo.container.usability.BindingsOverviewHandler; @@ -15,8 +15,10 @@ import com.yahoo.vespa.model.container.component.Handler; import org.junit.jupiter.api.Test; import org.w3c.dom.Element; +import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.logging.Level; import static com.yahoo.vespa.model.container.ContainerCluster.ROOT_HANDLER_BINDING; import static com.yahoo.vespa.model.container.ContainerCluster.STATE_HANDLER_BINDING_1; @@ -25,7 +27,11 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.hasItem; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * Tests for container model building with custom handlers. @@ -63,6 +69,31 @@ public class HandlerBuilderTest extends ContainerModelBuilderTestBase { } @Test + void warn_on_bindings_shared_by_multiple_handlers() { + class TestDeployLogger implements DeployLogger { + List<String> logs = new ArrayList<>(); + @Override public void log(Level level, String message) { logs.add(message); } + } + var clusterElem = DomBuilderTest.parse( + "<container id='default' version='1.0'>", + " <handler id='myHandler1'>", + " <binding>http://*/myhandler</binding>", + " <binding>https://*/myhandler</binding>", + " </handler>", + " <handler id='myHandler2'>", + " <binding>http://*/myhandler</binding>", + " <binding>https://*/myhandler</binding>", + " </handler>", + "</container>"); + var logger = new TestDeployLogger(); + createModel(root, logger, clusterElem); + assertEquals( + List.of("Binding 'http://*/myhandler' was already in use by handler 'myHandler1', but will now be taken over by handler: myHandler2", + "Binding 'https://*/myhandler' was already in use by handler 'myHandler1', but will now be taken over by handler: myHandler2"), + logger.logs); + } + + @Test void default_root_handler_binding_can_be_stolen_by_user_configured_handler() { Element clusterElem = DomBuilderTest.parse( "<container id='default' version='1.0'>" + diff --git a/config-model/src/test/java/com/yahoo/vespa/model/filedistribution/UserConfiguredFilesTest.java b/config-model/src/test/java/com/yahoo/vespa/model/filedistribution/UserConfiguredFilesTest.java index 92fb89a5c4c..b4a54548062 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/filedistribution/UserConfiguredFilesTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/filedistribution/UserConfiguredFilesTest.java @@ -5,12 +5,15 @@ import com.yahoo.config.FileNode; import com.yahoo.config.FileReference; import com.yahoo.config.ModelReference; import com.yahoo.config.UrlReference; +import com.yahoo.config.application.api.ApplicationPackage; +import com.yahoo.config.application.api.DeployLogger; import com.yahoo.config.application.api.FileRegistry; import com.yahoo.config.model.application.provider.BaseDeployLogger; import com.yahoo.config.model.deploy.TestProperties; import com.yahoo.config.model.producer.UserConfigRepo; import com.yahoo.config.model.test.MockApplicationPackage; import com.yahoo.config.model.test.MockRoot; +import com.yahoo.schema.processing.ReservedRankingExpressionFunctionNamesTestCase; import com.yahoo.vespa.config.ConfigDefinition; import com.yahoo.vespa.config.ConfigDefinitionKey; import com.yahoo.vespa.config.ConfigPayloadBuilder; @@ -27,6 +30,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.logging.Level; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -72,22 +76,19 @@ public class UserConfiguredFilesTest { } private UserConfiguredFiles userConfiguredFiles() { - return new UserConfiguredFiles(fileRegistry, - new BaseDeployLogger(), - new TestProperties(), - new ApplicationContainerCluster.UserConfiguredUrls(), - new MockApplicationPackage.Builder().build()); + return userConfiguredFiles(new MockApplicationPackage.Builder().build()); + } + + private UserConfiguredFiles userConfiguredFiles(ApplicationPackage applicationPackage) { + return userConfiguredFiles(applicationPackage, new BaseDeployLogger()); } - private UserConfiguredFiles userConfiguredFiles(File root, com.yahoo.path.Path path) { + private UserConfiguredFiles userConfiguredFiles(ApplicationPackage applicationPackage, DeployLogger deployLogger) { return new UserConfiguredFiles(fileRegistry, - new BaseDeployLogger(), + deployLogger, new TestProperties(), new ApplicationContainerCluster.UserConfiguredUrls(), - new MockApplicationPackage.Builder() - .withRoot(root) - .withFiles(Map.of(path, "")) - .build()); + applicationPackage); } @BeforeEach @@ -304,17 +305,18 @@ public class UserConfiguredFilesTest { @Test void require_that_using_empty_dir_fails(@TempDir Path tempDir) { String relativeTempDir = tempDir.toString().substring(tempDir.toString().lastIndexOf("target") + 7); - try { - def.addPathDef("pathVal"); - builder.setField("pathVal", relativeTempDir); - fileRegistry.pathToRef.put(relativeTempDir, new FileReference("bazshash")); - userConfiguredFiles(tempDir.toFile().getParentFile(), - com.yahoo.path.Path.fromString(tempDir.toFile().getAbsolutePath())).register(producer); - fail("Should have thrown exception"); - } catch (IllegalArgumentException e) { - assertEquals("Invalid config in services.xml for 'mynamespace.myname': Directory '" + relativeTempDir + "' is empty", - e.getMessage()); - } + ApplicationPackage applicationPackage = + new MockApplicationPackage.Builder() + .withRoot(tempDir.toFile().getParentFile()) + .withFiles(Map.of(com.yahoo.path.Path.fromString(tempDir.toFile().getAbsolutePath()), "")) + .build(); + + var logger = new TestDeployLogger(); + def.addPathDef("pathVal"); + builder.setField("pathVal", relativeTempDir); + fileRegistry.pathToRef.put(relativeTempDir, new FileReference("bazshash")); + userConfiguredFiles(applicationPackage, logger).register(producer); + assertEquals("Directory '" + relativeTempDir + "' is empty", logger.log); } @Test @@ -331,4 +333,12 @@ public class UserConfiguredFilesTest { } } + private static class TestDeployLogger implements DeployLogger { + public String log = ""; + @Override + public void log(Level level, String message) { + log += message; + } + } + } |