diff options
Diffstat (limited to 'config-model/src/test/java/com')
18 files changed, 179 insertions, 130 deletions
diff --git a/config-model/src/test/java/com/yahoo/config/model/provision/ModelProvisioningTest.java b/config-model/src/test/java/com/yahoo/config/model/provision/ModelProvisioningTest.java index af31a09101e..82841b52984 100644 --- a/config-model/src/test/java/com/yahoo/config/model/provision/ModelProvisioningTest.java +++ b/config-model/src/test/java/com/yahoo/config/model/provision/ModelProvisioningTest.java @@ -16,7 +16,6 @@ import com.yahoo.container.core.ApplicationMetadataConfig; import com.yahoo.search.config.QrStartConfig; import com.yahoo.searchdefinition.parser.ParseException; import com.yahoo.vespa.config.search.core.ProtonConfig; -import com.yahoo.vespa.model.AbstractService; import com.yahoo.vespa.model.HostResource; import com.yahoo.vespa.model.HostSystem; import com.yahoo.vespa.model.VespaModel; @@ -51,9 +50,6 @@ import java.util.stream.Collectors; import static com.yahoo.config.model.test.TestUtil.joinLines; import static com.yahoo.vespa.defaults.Defaults.getDefaults; import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.collection.IsIn.isIn; -import static org.hamcrest.core.Every.everyItem; -import static org.hamcrest.core.IsNot.not; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -762,42 +758,6 @@ public class ModelProvisioningTest { assertEquals("Included in addition because it is retired", "default03", model.getAdmin().getSlobroks().get(5).getHostName()); } - @Test - public void testSlobroksAreSpreadOverAllContainerClustersExceptNodeAdmin() { - String services = - "<?xml version='1.0' encoding='utf-8' ?>\n" + - "<services>" + - " <admin version='4.0'/>" + - " <container version='1.0' id='routing'>" + - " <nodes count='10'/>" + - " </container>" + - " <container version='1.0' id='node-admin'>" + - " <nodes count='3'/>" + - " </container>" + - "</services>"; - - int numberOfHosts = 13; - VespaModelTester tester = new VespaModelTester(); - tester.addHosts(numberOfHosts); - tester.setApplicationId("hosted-vespa", "routing", "default"); - VespaModel model = tester.createModel(services, true); - assertThat(model.getRoot().getHostSystem().getHosts().size(), is(numberOfHosts)); - - Set<String> routingHosts = getClusterHostnames(model, "routing"); - assertEquals(10, routingHosts.size()); - - Set<String> nodeAdminHosts = getClusterHostnames(model, "node-admin"); - assertEquals(3, nodeAdminHosts.size()); - - Set<String> slobrokHosts = model.getAdmin().getSlobroks().stream() - .map(AbstractService::getHostName) - .collect(Collectors.toSet()); - assertEquals(3, slobrokHosts.size()); - - assertThat(slobrokHosts, everyItem(isIn(routingHosts))); - assertThat(slobrokHosts, everyItem(not(isIn(nodeAdminHosts)))); - } - private Set<String> getClusterHostnames(VespaModel model, String clusterId) { return model.getHosts().stream() .filter(host -> host.getServices().stream() diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/FieldOfTypeDocumentTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/FieldOfTypeDocumentTestCase.java index 3331bf4cdba..9942b563297 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/FieldOfTypeDocumentTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/FieldOfTypeDocumentTestCase.java @@ -33,7 +33,7 @@ public class FieldOfTypeDocumentTestCase extends SearchDefinitionTestCase { DocumentType musicType = manager.getDocumentType("music"); - assertEquals(5, musicType.getFieldCount()); + assertEquals(3, musicType.getFieldCount()); Field intField = musicType.getField("intfield"); assertEquals(DataType.INT, intField.getDataType()); @@ -41,21 +41,13 @@ public class FieldOfTypeDocumentTestCase extends SearchDefinitionTestCase { assertEquals(DataType.STRING, stringField.getDataType()); Field longField = musicType.getField("longfield"); assertEquals(DataType.LONG, longField.getDataType()); - Field summaryfeatures = musicType.getField("summaryfeatures"); - assertEquals(DataType.STRING, summaryfeatures.getDataType()); - Field rankfeatures = musicType.getField("rankfeatures"); - assertEquals(DataType.STRING, rankfeatures.getDataType()); DocumentType bookType = manager.getDocumentType("book"); - assertEquals(3, bookType.getFieldCount()); + assertEquals(1, bookType.getFieldCount()); Field musicField = bookType.getField("soundtrack"); assertSame(musicType, musicField.getDataType()); - summaryfeatures = musicType.getField("summaryfeatures"); - assertEquals(DataType.STRING, summaryfeatures.getDataType()); - rankfeatures = musicType.getField("rankfeatures"); - assertEquals(DataType.STRING, rankfeatures.getDataType()); } } diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionLoopDetectionTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionLoopDetectionTestCase.java index 0ff8a5cc7ca..9a0dcc7dd07 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionLoopDetectionTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionLoopDetectionTestCase.java @@ -40,7 +40,7 @@ public class RankingExpressionLoopDetectionTestCase { fail("Excepted exception"); } catch (IllegalArgumentException e) { - assertEquals("In search definition 'test', rank profile 'test': The function 'foo' is invalid: Invocation loop: foo -> foo", + assertEquals("In search definition 'test', rank profile 'test': The function 'foo' is invalid: foo is invalid: Invocation loop: foo -> foo", Exceptions.toMessageString(e)); } } @@ -75,7 +75,7 @@ public class RankingExpressionLoopDetectionTestCase { fail("Excepted exception"); } catch (IllegalArgumentException e) { - assertEquals("In search definition 'test', rank profile 'test': The function 'foo' is invalid: Invocation loop: arg(5) -> foo -> arg(5)", + assertEquals("In search definition 'test', rank profile 'test': The function 'foo' is invalid: arg(5) is invalid: foo is invalid: arg(5) is invalid: Invocation loop: arg(5) -> foo -> arg(5)", Exceptions.toMessageString(e)); } } @@ -110,7 +110,7 @@ public class RankingExpressionLoopDetectionTestCase { fail("Excepted exception"); } catch (IllegalArgumentException e) { - assertEquals("In search definition 'test', rank profile 'test': The function 'foo' is invalid: Invocation loop: arg(foo) -> foo -> arg(foo)", + assertEquals("In search definition 'test', rank profile 'test': The function 'foo' is invalid: arg(foo) is invalid: a1 is invalid: foo is invalid: arg(foo) is invalid: Invocation loop: arg(foo) -> foo -> arg(foo)", Exceptions.toMessageString(e)); } } diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/SearchImporterTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/SearchImporterTestCase.java index 89e551fa789..a94c8e76684 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/SearchImporterTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/SearchImporterTestCase.java @@ -45,7 +45,7 @@ public class SearchImporterTestCase extends SearchDefinitionTestCase { SDDocumentType document = search.getDocument(); assertEquals("simple", document.getName()); - assertEquals(25, document.getFieldCount()); + assertEquals(23, document.getFieldCount()); SDField field; Attribute attribute; diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/derived/AbstractExportingTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/derived/AbstractExportingTestCase.java index ef99ec28686..7fbca88cb61 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/derived/AbstractExportingTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/derived/AbstractExportingTestCase.java @@ -3,6 +3,7 @@ package com.yahoo.searchdefinition.derived; import com.yahoo.document.DocumenttypesConfig; import com.yahoo.document.config.DocumentmanagerConfig; +import com.yahoo.search.query.profile.QueryProfileRegistry; import com.yahoo.searchdefinition.Search; import com.yahoo.searchdefinition.SearchBuilder; import com.yahoo.searchdefinition.SearchDefinitionTestCase; @@ -29,11 +30,10 @@ public abstract class AbstractExportingTestCase extends SearchDefinitionTestCase deleteContent(toDir); SearchBuilder builder = SearchBuilder.createFromDirectory(searchDefRoot + dirName + "/"); - //SearchBuilder builder = SearchBuilder.createFromFile(searchDefDir + name + ".sd"); return derive(dirName, searchDefinitionName, builder); } - protected DerivedConfiguration derive(String dirName, String searchDefinitionName, SearchBuilder builder) throws IOException { + private DerivedConfiguration derive(String dirName, String searchDefinitionName, SearchBuilder builder) throws IOException { DerivedConfiguration config = new DerivedConfiguration(builder.getSearch(searchDefinitionName), builder.getRankProfileRegistry(), builder.getQueryProfileRegistry(), @@ -85,14 +85,14 @@ public abstract class AbstractExportingTestCase extends SearchDefinitionTestCase * Asserts config is correctly derived given a builder. * This will fail if the builder contains multiple search definitions. */ - protected DerivedConfiguration assertCorrectDeriving(SearchBuilder builder, String dirName) throws IOException, ParseException { + protected DerivedConfiguration assertCorrectDeriving(SearchBuilder builder, String dirName) throws IOException { builder.build(); DerivedConfiguration derived = derive(dirName, null, builder); assertCorrectConfigFiles(dirName); return derived; } - protected DerivedConfiguration assertCorrectDeriving(SearchBuilder builder, Search search, String name) throws IOException, ParseException { + protected DerivedConfiguration assertCorrectDeriving(SearchBuilder builder, Search search, String name) throws IOException { DerivedConfiguration derived = derive(name, builder, search); assertCorrectConfigFiles(name); return derived; diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/derived/NeuralNetTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/derived/NeuralNetTestCase.java new file mode 100644 index 00000000000..b299c7fa299 --- /dev/null +++ b/config-model/src/test/java/com/yahoo/searchdefinition/derived/NeuralNetTestCase.java @@ -0,0 +1,16 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.derived; + +import com.yahoo.searchdefinition.parser.ParseException; +import org.junit.Test; + +import java.io.IOException; + +public class NeuralNetTestCase extends AbstractExportingTestCase { + + @Test + public void testNeuralNet() throws IOException, ParseException { + assertCorrectDeriving("neuralnet"); + } + +} diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/ImplicitSearchFieldsTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/ImplicitSearchFieldsTestCase.java index b66105009cd..52c36ca240c 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/ImplicitSearchFieldsTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/ImplicitSearchFieldsTestCase.java @@ -25,11 +25,9 @@ public class ImplicitSearchFieldsTestCase extends SearchDefinitionTestCase { SDDocumentType docType = search.getDocument(); assertNotNull(docType); - assertNotNull(docType.getField("rankfeatures")); - assertNotNull(docType.getField("summaryfeatures")); assertNotNull(docType.getField("foo")); assertNotNull(docType.getField("bar")); - assertEquals(4, docType.getFieldCount()); + assertEquals(2, docType.getFieldCount()); } @Test @@ -39,12 +37,10 @@ public class ImplicitSearchFieldsTestCase extends SearchDefinitionTestCase { SDDocumentType docType = search.getDocument(); assertNotNull(docType); - assertNotNull(docType.getField("rankfeatures")); - assertNotNull(docType.getField("summaryfeatures")); assertNotNull(docType.getField("foo")); assertNotNull(docType.getField("bar")); assertNotNull(docType.getField("cox")); - assertEquals(5, docType.getFieldCount()); + assertEquals(3, docType.getFieldCount()); } @Test @@ -54,13 +50,11 @@ public class ImplicitSearchFieldsTestCase extends SearchDefinitionTestCase { SDDocumentType docType = search.getDocument(); assertNotNull(docType); - assertNotNull(docType.getField("rankfeatures")); - assertNotNull(docType.getField("summaryfeatures")); assertNotNull(docType.getField("foo")); assertNotNull(docType.getField("bar")); assertNotNull(docType.getField("baz")); assertNotNull(docType.getField("cox")); - assertEquals(6, docType.getFieldCount()); + assertEquals(4, docType.getFieldCount()); } @Test @@ -70,12 +64,10 @@ public class ImplicitSearchFieldsTestCase extends SearchDefinitionTestCase { SDDocumentType docType = search.getDocument(); assertNotNull(docType); - assertNotNull(docType.getField("rankfeatures")); - assertNotNull(docType.getField("summaryfeatures")); assertNotNull(docType.getField("foo")); assertNotNull(docType.getField("bar")); assertNotNull(docType.getField("baz")); - assertEquals(5, docType.getFieldCount()); + assertEquals(3, docType.getFieldCount()); } @Test @@ -85,11 +77,9 @@ public class ImplicitSearchFieldsTestCase extends SearchDefinitionTestCase { SDDocumentType docType = search.getDocument(); assertNotNull(docType); - assertNotNull(docType.getField("rankfeatures")); - assertNotNull(docType.getField("summaryfeatures")); assertNotNull(docType.getField("foo")); assertNotNull(docType.getField("bar")); - assertEquals(4, docType.getFieldCount()); + assertEquals(2, docType.getFieldCount()); } @Test diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/ImplicitStructTypesTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/ImplicitStructTypesTestCase.java index 88c85452cb3..f2d81414b5a 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/ImplicitStructTypesTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/ImplicitStructTypesTestCase.java @@ -35,8 +35,6 @@ public class ImplicitStructTypesTestCase extends SearchDefinitionTestCase { assertField(docType, "doc_str_sum", DataType.STRING); assertField(docType, "doc_uri", DataType.URI); assertField(docType, "docsum_str", DataType.STRING); - assertField(docType, "rankfeatures", DataType.STRING); - assertField(docType, "summaryfeatures", DataType.STRING); } @SuppressWarnings({ "UnusedDeclaration" }) diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeResolverTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeResolverTestCase.java index 1b917b6f3a3..3b3ce712387 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeResolverTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeResolverTestCase.java @@ -103,7 +103,9 @@ public class RankingExpressionTypeResolverTestCase { fail("Expected exception"); } catch (IllegalArgumentException expected) { - assertEquals("In search definition 'test', rank profile 'my_rank_profile': The first-phase expression is invalid: An if expression must produce compatible types in both alternatives, but the 'true' type is tensor(x[],y[]) while the 'false' type is tensor(z[10])", + assertEquals("In search definition 'test', rank profile 'my_rank_profile': The first-phase expression is invalid: An if expression must produce compatible types in both alternatives, but the 'true' type is tensor(x[],y[]) while the 'false' type is tensor(z[10])" + + "\n'true' branch: attribute(a)" + + "\n'false' branch: attribute(b)", Exceptions.toMessageString(expected)); } } diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorTestCase.java index 80440ac8eb4..1b03825eef1 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithTensorTestCase.java @@ -2,9 +2,10 @@ package com.yahoo.searchdefinition.processing; import com.yahoo.searchdefinition.parser.ParseException; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; /** * @author geirst @@ -138,23 +139,29 @@ public class RankingExpressionWithTensorTestCase { f.assertRankProperty("tensor(x{})", "constant(my_tensor).type", "my_profile"); } - @Rule - public ExpectedException exception = ExpectedException.none(); - @Test public void requireThatInvalidTensorTypeSpecThrowsException() throws ParseException { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("For constant tensor 'my_tensor' in rank profile 'my_profile': Illegal tensor type spec: A tensor type spec must be on the form tensor[<valuetype>]?(dimensionidentifier[{}|[length?]*), but was 'tensor(x)'. Dimension 'x' is on the wrong format. Examples: tensor(x[]), tensor<float>(name{}, x[10])"); - RankProfileSearchFixture f = new RankProfileSearchFixture( - " rank-profile my_profile {\n" + - " constants {\n" + - " my_tensor {\n" + - " value: { {x:1}:1 }\n" + - " type: tensor(x)\n" + - " }\n" + - " }\n" + - " }"); - f.compileRankProfile("my_profile"); + try { + RankProfileSearchFixture f = new RankProfileSearchFixture( + " rank-profile my_profile {\n" + + " constants {\n" + + " my_tensor {\n" + + " value: { {x:1}:1 }\n" + + " type: tensor(x)\n" + + " }\n" + + " }\n" + + " }"); + f.compileRankProfile("my_profile"); + fail("Expected exception"); + } + catch (IllegalArgumentException e) { + assertStartsWith("For constant tensor 'my_tensor' in rank profile 'my_profile': Illegal tensor type spec", + e.getMessage()); + } + } + + private void assertStartsWith(String prefix, String string) { + assertEquals(prefix, string.substring(0, Math.min(prefix.length(), string.length()))); } } 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 d4fcd09e249..1a7eb96483e 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 @@ -23,8 +23,7 @@ public class RankingExpressionsTestCase extends SearchDefinitionTestCase { public void testFunctions() throws IOException, ParseException { RankProfileRegistry rankProfileRegistry = new RankProfileRegistry(); Search search = SearchBuilder.createFromDirectory("src/test/examples/rankingexpressionfunction", - rankProfileRegistry, - new QueryProfileRegistry()).getSearch(); + rankProfileRegistry).getSearch(); RankProfile functionsRankProfile = rankProfileRegistry.get(search, "macros"); Map<String, RankProfile.RankingExpressionFunction> functions = functionsRankProfile.getFunctions(); assertEquals(2, functions.get("titlematch$").function().arguments().size()); @@ -62,9 +61,7 @@ public class RankingExpressionsTestCase extends SearchDefinitionTestCase { @Test(expected = IllegalArgumentException.class) public void testThatIncludingFileInSubdirFails() throws IOException, ParseException { RankProfileRegistry registry = new RankProfileRegistry(); - Search search = SearchBuilder.createFromDirectory("src/test/examples/rankingexpressioninfile", - registry, - new QueryProfileRegistry()).getSearch(); + Search search = SearchBuilder.createFromDirectory("src/test/examples/rankingexpressioninfile", registry).getSearch(); new DerivedConfiguration(search, registry, new QueryProfileRegistry(), new ImportedMlModels()); // rank profile parsing happens during deriving } diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/TensorFieldTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/TensorFieldTestCase.java index f53ca15635f..b6569357495 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/TensorFieldTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/TensorFieldTestCase.java @@ -3,48 +3,68 @@ package com.yahoo.searchdefinition.processing; import com.yahoo.searchdefinition.SearchBuilder; import com.yahoo.searchdefinition.parser.ParseException; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; /** * @author geirst */ public class TensorFieldTestCase { - @Rule - public ExpectedException exception = ExpectedException.none(); - @Test public void requireThatTensorFieldCannotBeOfCollectionType() throws ParseException { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("For search 'test', field 'f1': A field with collection type of tensor is not supported. Use simple type 'tensor' instead."); - SearchBuilder.createFromString(getSd("field f1 type array<tensor(x{})> {}")); + try { + SearchBuilder.createFromString(getSd("field f1 type array<tensor(x{})> {}")); + fail("Expected exception"); + } + catch (IllegalArgumentException e) { + assertEquals("For search 'test', field 'f1': A field with collection type of tensor is not supported. Use simple type 'tensor' instead.", + e.getMessage()); + } } @Test public void requireThatTensorFieldCannotBeIndexField() throws ParseException { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("For search 'test', field 'f1': A field of type 'tensor' cannot be specified as an 'index' field."); - SearchBuilder.createFromString(getSd("field f1 type tensor(x{}) { indexing: index }")); + try { + SearchBuilder.createFromString(getSd("field f1 type tensor(x{}) { indexing: index }")); + fail("Expected exception"); + } + catch (IllegalArgumentException e) { + assertEquals("For search 'test', field 'f1': A field of type 'tensor' cannot be specified as an 'index' field.", + e.getMessage()); + } } @Test public void requireThatTensorAttributeCannotBeFastSearch() throws ParseException { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("For search 'test', field 'f1': An attribute of type 'tensor' cannot be 'fast-search'."); - SearchBuilder.createFromString(getSd("field f1 type tensor(x{}) { indexing: attribute \n attribute: fast-search }")); + try { + SearchBuilder.createFromString(getSd("field f1 type tensor(x{}) { indexing: attribute \n attribute: fast-search }")); + fail("Expected exception"); + } + catch (IllegalArgumentException e) { + assertEquals("For search 'test', field 'f1': An attribute of type 'tensor' cannot be 'fast-search'.", e.getMessage()); + } } @Test public void requireThatIllegalTensorTypeSpecThrowsException() throws ParseException { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("Field type: Illegal tensor type spec: A tensor type spec must be on the form tensor[<valuetype>]?(dimensionidentifier[{}|[length?]*), but was 'tensor(invalid)'. Dimension 'invalid' is on the wrong format. Examples: tensor(x[]), tensor<float>(name{}, x[10])"); - SearchBuilder.createFromString(getSd("field f1 type tensor(invalid) { indexing: attribute }")); + try { + SearchBuilder.createFromString(getSd("field f1 type tensor(invalid) { indexing: attribute }")); + fail("Expected exception"); + } + catch (IllegalArgumentException e) { + assertStartsWith("Field type: Illegal tensor type spec:", e.getMessage()); + } } private static String getSd(String field) { return "search test {\n document test {\n" + field + "}\n}\n"; } + private void assertStartsWith(String prefix, String string) { + assertEquals(prefix, string.substring(0, Math.min(prefix.length(), string.length()))); + } + } diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/TensorTransformTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/TensorTransformTestCase.java index fe150b51961..15c1d24ce33 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/TensorTransformTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/TensorTransformTestCase.java @@ -58,8 +58,8 @@ public class TensorTransformTestCase extends SearchDefinitionTestCase { "max(attribute(tensor_field_1),x)"); assertTransformedExpression("1+reduce(attribute(tensor_field_1),max,x)", "1 + max(attribute(tensor_field_1),x)"); - assertTransformedExpression("if(attribute(double_field),1+reduce(attribute(tensor_field_1),max,x),attribute(tensor_field_1))", - "if(attribute(double_field),1 + max(attribute(tensor_field_1),x),attribute(tensor_field_1))"); + assertTransformedExpression("if(attribute(double_field),1+reduce(attribute(tensor_field_1),max,x),reduce(attribute(tensor_field_1),sum,x))", + "if(attribute(double_field),1 + max(attribute(tensor_field_1),x),reduce(attribute(tensor_field_1), sum, x))"); assertTransformedExpression("reduce(max(attribute(tensor_field_1),attribute(tensor_field_2)),max,x)", "max(max(attribute(tensor_field_1),attribute(tensor_field_2)),x)"); assertTransformedExpression("reduce(if(attribute(double_field),attribute(tensor_field_2),attribute(tensor_field_2)),max,x)", diff --git a/config-model/src/test/java/com/yahoo/vespa/model/admin/metricsproxy/MetricsProxyContainerTest.java b/config-model/src/test/java/com/yahoo/vespa/model/admin/metricsproxy/MetricsProxyContainerTest.java index a10a5dcf4cc..d2bf4b601a6 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/admin/metricsproxy/MetricsProxyContainerTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/admin/metricsproxy/MetricsProxyContainerTest.java @@ -9,6 +9,7 @@ import com.yahoo.vespa.model.test.VespaModelTester; import org.junit.Test; import static com.yahoo.config.model.api.container.ContainerServiceType.METRICS_PROXY_CONTAINER; +import static com.yahoo.vespa.model.admin.metricsproxy.MetricsProxyModelTester.CLUSTER_CONFIG_ID; import static com.yahoo.vespa.model.admin.metricsproxy.MetricsProxyModelTester.CONTAINER_CONFIG_ID; import static com.yahoo.vespa.model.admin.metricsproxy.MetricsProxyModelTester.MY_FLAVOR; import static com.yahoo.vespa.model.admin.metricsproxy.MetricsProxyModelTester.getHostedModel; @@ -101,7 +102,9 @@ public class MetricsProxyContainerTest { public void hosted_application_propagates_node_dimensions() { String services = servicesWithContent(); VespaModel hostedModel = getHostedModel(services); - NodeDimensionsConfig config = getNodeDimensionsConfig(hostedModel); + assertEquals(1, hostedModel.getHosts().size()); + String configId = CLUSTER_CONFIG_ID + "/" + hostedModel.getHosts().iterator().next().getHostname(); + NodeDimensionsConfig config = getNodeDimensionsConfig(hostedModel, configId); assertEquals("content", config.dimensions(NodeDimensionNames.CLUSTER_TYPE)); assertEquals("my-content", config.dimensions(NodeDimensionNames.CLUSTER_ID)); diff --git a/config-model/src/test/java/com/yahoo/vespa/model/admin/metricsproxy/MetricsProxyModelTester.java b/config-model/src/test/java/com/yahoo/vespa/model/admin/metricsproxy/MetricsProxyModelTester.java index 81b06e54585..13589c763e2 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/admin/metricsproxy/MetricsProxyModelTester.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/admin/metricsproxy/MetricsProxyModelTester.java @@ -32,7 +32,7 @@ class MetricsProxyModelTester { static final String CLUSTER_CONFIG_ID = "admin/metrics"; // Used for all configs that are produced by the container, not the cluster. - static final String CONTAINER_CONFIG_ID = CLUSTER_CONFIG_ID + "/metricsproxy.0"; + static final String CONTAINER_CONFIG_ID = CLUSTER_CONFIG_ID + "/localhost"; static VespaModel getModel(String servicesXml) { var numberOfHosts = 1; @@ -87,8 +87,8 @@ class MetricsProxyModelTester { return new QrStartConfig((QrStartConfig.Builder) model.getConfig(new QrStartConfig.Builder(), CLUSTER_CONFIG_ID)); } - static NodeDimensionsConfig getNodeDimensionsConfig(VespaModel model) { - return new NodeDimensionsConfig((NodeDimensionsConfig.Builder) model.getConfig(new NodeDimensionsConfig.Builder(), CONTAINER_CONFIG_ID)); + static NodeDimensionsConfig getNodeDimensionsConfig(VespaModel model, String configId) { + return new NodeDimensionsConfig((NodeDimensionsConfig.Builder) model.getConfig(new NodeDimensionsConfig.Builder(), configId)); } static VespaServicesConfig getVespaServicesConfig(String servicesXml) { diff --git a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/ConfigValueChangeValidatorTest.java b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/ConfigValueChangeValidatorTest.java index 3fbfbf33fb3..6d9eabf326b 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/ConfigValueChangeValidatorTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/ConfigValueChangeValidatorTest.java @@ -61,7 +61,7 @@ public class ConfigValueChangeValidatorTest { assertEquals(3, changes.size()); assertComponentsEquals(changes, "default/container.0", 0); assertComponentsEquals(changes, "admin/cluster-controllers/0", 1); - assertComponentsEquals(changes, "admin/metrics/metricsproxy.0", 2); + assertComponentsEquals(changes, "admin/metrics/localhost", 2); } @Test diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/search/test/QueryProfileVariantsTestCase.java b/config-model/src/test/java/com/yahoo/vespa/model/container/search/test/QueryProfileVariantsTestCase.java index 5833bc79ebf..5e559b64bd1 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/container/search/test/QueryProfileVariantsTestCase.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/container/search/test/QueryProfileVariantsTestCase.java @@ -1,6 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.model.container.search.test; +import com.yahoo.config.application.api.DeployLogger; import com.yahoo.search.query.profile.QueryProfile; import com.yahoo.search.query.profile.QueryProfileRegistry; import com.yahoo.search.query.profile.config.QueryProfileXMLReader; @@ -8,6 +9,7 @@ import com.yahoo.vespa.model.container.search.QueryProfiles; import org.junit.Test; import java.io.IOException; +import java.util.logging.Level; import static helpers.CompareConfigTestHelper.assertSerializedConfigFileEquals; import static org.junit.Assert.assertEquals; @@ -22,28 +24,28 @@ public class QueryProfileVariantsTestCase { @Test public void testConfigCreation() throws IOException { QueryProfileRegistry registry = new QueryProfileXMLReader().read(root + "queryprofilevariants"); - QueryProfiles profiles = new QueryProfiles(registry); + QueryProfiles profiles = new QueryProfiles(registry, new SilentDeployLogger()); assertSerializedConfigFileEquals(root + "query-profile-variants-configuration.cfg", profiles.getConfig().toString()); } @Test public void testConfigCreation2() throws IOException { QueryProfileRegistry registry = new QueryProfileXMLReader().read("src/test/java/com/yahoo/vespa/model/container/search/test/queryprofilevariants2"); - QueryProfiles profiles = new QueryProfiles(registry); + QueryProfiles profiles = new QueryProfiles(registry, new SilentDeployLogger()); assertSerializedConfigFileEquals(root + "query-profile-variants2-configuration.cfg", profiles.getConfig().toString()); } @Test public void testConfigCreationNewsBESimple() throws IOException { QueryProfileRegistry registry = new QueryProfileXMLReader().read(root + "newsbesimple"); - QueryProfiles profiles = new QueryProfiles(registry); + QueryProfiles profiles = new QueryProfiles(registry, new SilentDeployLogger()); assertSerializedConfigFileEquals(root + "newsbe-query-profiles-simple.cfg", profiles.getConfig().toString()); } @Test public void testConfigCreationNewsFESimple() throws IOException { QueryProfileRegistry registry = new QueryProfileXMLReader().read(root + "newsfesimple"); - QueryProfiles profiles = new QueryProfiles(registry); + QueryProfiles profiles = new QueryProfiles(registry, new SilentDeployLogger()); assertSerializedConfigFileEquals(root + "newsfe-query-profiles-simple.cfg", profiles.getConfig().toString()); } @@ -63,7 +65,7 @@ public class QueryProfileVariantsTestCase { registry.register(a1); registry.register(profile); - QueryProfiles profiles = new QueryProfiles(registry); + QueryProfiles profiles = new QueryProfiles(registry, new SilentDeployLogger()); assertSerializedConfigFileEquals(root + "variants-of-explicit-compound.cfg", profiles.getConfig().toString()); } @@ -88,7 +90,7 @@ public class QueryProfileVariantsTestCase { registry.register(a2); registry.register(profile); - QueryProfiles profiles = new QueryProfiles(registry); + QueryProfiles profiles = new QueryProfiles(registry, new SilentDeployLogger()); assertSerializedConfigFileEquals(root + "variants-of-explicit-compound-with-reference.cfg", profiles.getConfig().toString()); } @@ -108,8 +110,15 @@ public class QueryProfileVariantsTestCase { registry.register(a1); registry.register(profile); - QueryProfiles profiles = new QueryProfiles(registry); + QueryProfiles profiles = new QueryProfiles(registry, new SilentDeployLogger()); assertSerializedConfigFileEquals(root + "explicit-reference-override.cfg", profiles.getConfig().toString()); } + private static class SilentDeployLogger implements DeployLogger { + + @Override + public void log(Level level, String message) {} + + } + } diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/search/test/QueryProfilesTestCase.java b/config-model/src/test/java/com/yahoo/vespa/model/container/search/test/QueryProfilesTestCase.java index 8c725ecc43c..746e771667f 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/container/search/test/QueryProfilesTestCase.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/container/search/test/QueryProfilesTestCase.java @@ -2,6 +2,7 @@ package com.yahoo.vespa.model.container.search.test; import com.yahoo.component.ComponentId; +import com.yahoo.config.application.api.DeployLogger; import com.yahoo.search.query.profile.QueryProfile; import com.yahoo.search.query.profile.QueryProfileRegistry; import com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry; @@ -11,12 +12,18 @@ import com.yahoo.search.query.profile.types.FieldDescription; import com.yahoo.search.query.profile.types.FieldType; import com.yahoo.search.query.profile.types.QueryProfileType; import com.yahoo.search.query.profile.types.QueryProfileTypeRegistry; +import com.yahoo.searchdefinition.SearchBuilder; +import com.yahoo.searchdefinition.parser.ParseException; import com.yahoo.vespa.model.container.search.QueryProfiles; +import com.yahoo.vespa.model.test.utils.DeployLoggerStub; import org.junit.Test; import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; import static helpers.CompareConfigTestHelper.assertSerializedConfigFileEquals; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -112,15 +119,63 @@ public class QueryProfilesTestCase { registry.register(untypedUser); assertConfig("query-profiles.cfg",registry); + + DeployLoggerStub logger = new DeployLoggerStub(); + new QueryProfiles(registry, logger); + assertTrue(logger.entries.isEmpty()); + } + + @Test + public void testValidation() { + QueryProfileRegistry registry = new QueryProfileRegistry(); + QueryProfileTypeRegistry typeRegistry = registry.getTypeRegistry(); + + QueryProfileType userType = new QueryProfileType("user"); + typeRegistry.register(userType); + + DeployLoggerStub logger = new DeployLoggerStub(); + new QueryProfiles(registry, logger); + assertEquals(1, logger.entries.size()); + assertEquals("This application define query profile types, but has no query profiles referencing them " + + "so they have no effect. " + + "See https://docs.vespa.ai/documentation/query-profiles.html", + logger.entries.get(0).message); + } + + @Test + public void testValidationWithTensorFields() { + QueryProfileRegistry registry = new QueryProfileRegistry(); + QueryProfileTypeRegistry typeRegistry = registry.getTypeRegistry(); + + QueryProfileType userType = new QueryProfileType("user"); + userType.addField(new FieldDescription("vector", FieldType.fromString("tensor(x[5])", typeRegistry))); + userType.addField(new FieldDescription("matrix", FieldType.fromString("tensor(x[5],y[5])", typeRegistry))); + typeRegistry.register(userType); + + DeployLoggerStub logger = new DeployLoggerStub(); + new QueryProfiles(registry, logger); + assertEquals(1, logger.entries.size()); + assertEquals("This application define query profile types, but has no query profiles referencing them " + + "so they have no effect. " + + "In particular, the tensors (vector, matrix) will be interpreted as strings, not tensors if sent in requests. " + + "See https://docs.vespa.ai/documentation/query-profiles.html", + logger.entries.get(0).message); } protected void assertConfig(String correctFileName, QueryProfileRegistry check) throws IOException { assertSerializedConfigFileEquals(root + "/" + correctFileName, - com.yahoo.text.StringUtilities.implodeMultiline(com.yahoo.config.ConfigInstance.serialize(new QueryProfiles(check).getConfig()))); + com.yahoo.text.StringUtilities.implodeMultiline(com.yahoo.config.ConfigInstance.serialize(new QueryProfiles(check, new SilentDeployLogger()).getConfig()))); // Also assert that the correct config config can actually be read as a config source QueryProfileConfigurer configurer = new QueryProfileConfigurer("file:" + root + "empty.cfg"); configurer.shutdown(); } + private static class SilentDeployLogger implements DeployLogger { + + @Override + public void log(Level level, String message) {} + + } + } |