summaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2022-05-13 12:14:09 +0200
committerGitHub <noreply@github.com>2022-05-13 12:14:09 +0200
commit64b4e9c4236bbf924230dcc4750094da30496b63 (patch)
tree810f8b8d2d070ac7e21704ea00ae3b20b62e5f2c /config-model/src/test/java/com
parent1df3b3c59251bd4fd1b099ae5cfb4c280313e76d (diff)
Revert "Bratseth/constants cleanup take 2"
Diffstat (limited to 'config-model/src/test/java/com')
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/RankProfileRegistryTest.java4
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/RankProfileTestCase.java2
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/RankingConstantTest.java58
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/SchemaTestCase.java35
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/derived/AbstractExportingTestCase.java1
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/derived/LiteralBoostTestCase.java4
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithOnnxTestCase.java11
-rw-r--r--config-model/src/test/java/com/yahoo/vespa/model/application/validation/ConstantValidatorTest.java34
-rw-r--r--config-model/src/test/java/com/yahoo/vespa/model/application/validation/RankingConstantsValidatorTest.java30
-rw-r--r--config-model/src/test/java/com/yahoo/vespa/model/ml/ImportedModelTester.java21
10 files changed, 99 insertions, 101 deletions
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/RankProfileRegistryTest.java b/config-model/src/test/java/com/yahoo/searchdefinition/RankProfileRegistryTest.java
index cbbb53d8ec8..d07f4513c3c 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/RankProfileRegistryTest.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/RankProfileRegistryTest.java
@@ -36,7 +36,7 @@ public class RankProfileRegistryTest {
public void testRankProfileDuplicateNameIsIllegal() {
Schema schema = new Schema("foo", MockApplicationPackage.createEmpty());
RankProfileRegistry rankProfileRegistry = RankProfileRegistry.createRankProfileRegistryWithBuiltinRankProfiles(schema);
- RankProfile barRankProfile = new RankProfile("bar", schema, rankProfileRegistry);
+ RankProfile barRankProfile = new RankProfile("bar", schema, rankProfileRegistry, schema.rankingConstants());
rankProfileRegistry.add(barRankProfile);
rankProfileRegistry.add(barRankProfile);
}
@@ -48,7 +48,7 @@ public class RankProfileRegistryTest {
for (String rankProfileName : RankProfileRegistry.overridableRankProfileNames) {
assertNull(rankProfileRegistry.get(schema, rankProfileName).getFunctions().get("foo"));
- RankProfile rankProfileWithAddedFunction = new RankProfile(rankProfileName, schema, rankProfileRegistry);
+ RankProfile rankProfileWithAddedFunction = new RankProfile(rankProfileName, schema, rankProfileRegistry, schema.rankingConstants());
rankProfileWithAddedFunction.addFunction(new ExpressionFunction("foo", RankingExpression.from("1+2")), true);
rankProfileRegistry.add(rankProfileWithAddedFunction);
assertNotNull(rankProfileRegistry.get(schema, rankProfileName).getFunctions().get("foo"));
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 50f930dde86..03b504bb821 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/RankProfileTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/RankProfileTestCase.java
@@ -52,7 +52,7 @@ public class RankProfileTestCase extends AbstractSchemaTestCase {
a.setRankType(RankType.IDENTITY);
document.addField("b", DataType.STRING);
schema.addDocument(document);
- RankProfile child = new RankProfile("child", schema, rankProfileRegistry);
+ RankProfile child = new RankProfile("child", schema, rankProfileRegistry, schema.rankingConstants());
child.inherit("default");
rankProfileRegistry.add(child);
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/RankingConstantTest.java b/config-model/src/test/java/com/yahoo/searchdefinition/RankingConstantTest.java
index 3aab1a7bbe6..6eb74dede62 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/RankingConstantTest.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/RankingConstantTest.java
@@ -30,7 +30,7 @@ public class RankingConstantTest {
RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
ApplicationBuilder schemaBuilder = new ApplicationBuilder(rankProfileRegistry);
schemaBuilder.addSchema(joinLines(
- "schema test {",
+ "search test {",
" document test { }",
" rank-profile my_rank_profile {",
" first-phase {",
@@ -46,12 +46,12 @@ public class RankingConstantTest {
schemaBuilder.build(true);
Schema schema = schemaBuilder.getSchema();
- Iterator<RankProfile.Constant> constantIterator = schema.constants().values().iterator();
- RankProfile.Constant constant = constantIterator.next();
- assertEquals(TENSOR_NAME, constant.name().simpleArgument().get());
- assertEquals(TENSOR_FILE, constant.valuePath().get());
- assertEquals(TENSOR_TYPE, constant.type().toString());
- assertEquals(DistributableResource.PathType.FILE, constant.pathType().get());
+ Iterator<RankingConstant> constantIterator = schema.rankingConstants().asMap().values().iterator();
+ RankingConstant constant = constantIterator.next();
+ assertEquals(TENSOR_NAME, constant.getName());
+ assertEquals(TENSOR_FILE, constant.getFileName());
+ assertEquals(TENSOR_TYPE, constant.getType());
+ assertEquals(RankingConstant.PathType.FILE, constant.getPathType());
assertFalse(constantIterator.hasNext());
}
@@ -63,7 +63,7 @@ public class RankingConstantTest {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("must have a type");
schemaBuilder.addSchema(joinLines(
- "schema test {",
+ "search test {",
" document test { }",
" constant foo {",
" file: bar.baz",
@@ -79,7 +79,7 @@ public class RankingConstantTest {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("must have a file");
schemaBuilder.addSchema(joinLines(
- "schema test {",
+ "search test {",
" document test { }",
" constant foo {",
" type: tensor(x[])",
@@ -93,7 +93,7 @@ public class RankingConstantTest {
RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
ApplicationBuilder schemaBuilder = new ApplicationBuilder(rankProfileRegistry);
schemaBuilder.addSchema(joinLines(
- "schema test {",
+ "search test {",
" document test { }",
" constant foo {",
" type: tensor(x{})",
@@ -103,8 +103,8 @@ public class RankingConstantTest {
));
schemaBuilder.build(true);
Schema schema = schemaBuilder.getSchema();
- RankProfile.Constant constant = schema.constants().values().iterator().next();
- assertEquals("simplename", constant.valuePath().get());
+ RankingConstant constant = schema.rankingConstants().asMap().values().iterator().next();
+ assertEquals("simplename", constant.getFileName());
}
@Test
@@ -112,7 +112,7 @@ public class RankingConstantTest {
RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
ApplicationBuilder schemaBuilder = new ApplicationBuilder(rankProfileRegistry);
schemaBuilder.addSchema(joinLines(
- "schema test {",
+ "search test {",
" document test { }",
" constant foo {",
" type: tensor(x{})",
@@ -122,9 +122,9 @@ public class RankingConstantTest {
));
schemaBuilder.build(true);
Schema schema = schemaBuilder.getSchema();
- RankProfile.Constant constant = schema.constants().values().iterator().next();
- assertEquals(DistributableResource.PathType.URI, constant.pathType().get());
- assertEquals("http://somewhere.far.away/in/another-galaxy", constant.valuePath().get());
+ RankingConstant constant = schema.rankingConstants().asMap().values().iterator().next();
+ assertEquals(RankingConstant.PathType.URI, constant.getPathType());
+ assertEquals("http://somewhere.far.away/in/another-galaxy", constant.getUri());
}
@Test
@@ -132,7 +132,7 @@ public class RankingConstantTest {
RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
ApplicationBuilder schemaBuilder = new ApplicationBuilder(rankProfileRegistry);
schemaBuilder.addSchema(joinLines(
- "schema test {",
+ "search test {",
" document test { }",
" constant foo {",
" type: tensor(x{})",
@@ -142,9 +142,9 @@ public class RankingConstantTest {
));
schemaBuilder.build(true);
Schema schema = schemaBuilder.getSchema();
- RankProfile.Constant constant = schema.constants().values().iterator().next();
- assertEquals(DistributableResource.PathType.URI, constant.pathType().get());
- assertEquals("https://somewhere.far.away:4443/in/another-galaxy", constant.valuePath().get());
+ RankingConstant constant = schema.rankingConstants().asMap().values().iterator().next();
+ assertEquals(RankingConstant.PathType.URI, constant.getPathType());
+ assertEquals("https://somewhere.far.away:4443/in/another-galaxy", constant.getUri());
}
@Test
@@ -152,7 +152,7 @@ public class RankingConstantTest {
RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
ApplicationBuilder schemaBuilder = new ApplicationBuilder(rankProfileRegistry);
schemaBuilder.addSchema(joinLines(
- "schema test {",
+ "search test {",
" document test { }",
" constant foo {",
" type: tensor(x{})",
@@ -162,9 +162,9 @@ public class RankingConstantTest {
));
schemaBuilder.build(true);
Schema schema = schemaBuilder.getSchema();
- RankProfile.Constant constant = schema.constants().values().iterator().next();
- assertEquals(DistributableResource.PathType.URI, constant.pathType().get());
- assertEquals("http://somewhere.far.away:4080/in/another-galaxy", constant.valuePath().get());
+ RankingConstant constant = schema.rankingConstants().asMap().values().iterator().next();
+ assertEquals(RankingConstant.PathType.URI, constant.getPathType());
+ assertEquals("http://somewhere.far.away:4080/in/another-galaxy", constant.getUri());
}
@Test
@@ -172,7 +172,7 @@ public class RankingConstantTest {
RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
ApplicationBuilder schemaBuilder = new ApplicationBuilder(rankProfileRegistry);
schemaBuilder.addSchema(joinLines(
- "schema test {",
+ "search test {",
" document test { }",
" constant foo {",
" type: tensor(x{})",
@@ -182,9 +182,9 @@ public class RankingConstantTest {
));
schemaBuilder.build(true);
Schema schema = schemaBuilder.getSchema();
- RankProfile.Constant constant = schema.constants().values().iterator().next();
- assertEquals(DistributableResource.PathType.URI, constant.pathType().get());
- assertEquals("http:somewhere.far.away/in/another-galaxy", constant.valuePath().get());
+ RankingConstant constant = schema.rankingConstants().asMap().values().iterator().next();
+ assertEquals(RankingConstant.PathType.URI, constant.getPathType());
+ assertEquals("http:somewhere.far.away/in/another-galaxy", constant.getUri());
}
@Test
@@ -196,7 +196,7 @@ public class RankingConstantTest {
"<URI_PATH> ...";
try {
schemaBuilder.addSchema(joinLines(
- "schema test {",
+ "search test {",
" document test { }",
" constant foo {",
" type: tensor(x{})",
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/SchemaTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/SchemaTestCase.java
index 65f4dab3650..4b40da9e289 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/SchemaTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/SchemaTestCase.java
@@ -122,9 +122,10 @@ public class SchemaTestCase {
" indexing: input pf1 | lowercase | index | attribute | summary" +
" }" +
" rank-profile child1_profile inherits parent_profile {" +
- " constants {" +
- " child1_constant tensor<float>(x{},y{}): file:constants/my_constant_tensor_file.json" +
- " }" +
+ " }" +
+ " constant child1_constant {" +
+ " file: constants/my_constant_tensor_file.json" +
+ " type: tensor<float>(x{},y{})" +
" }" +
" onnx-model child1_model {" +
" file: models/my_model.onnx" +
@@ -187,13 +188,11 @@ public class SchemaTestCase {
assertNotNull(child1.getExtraField("child1_field"));
assertNotNull(builder.getRankProfileRegistry().get(child1, "parent_profile"));
assertNotNull(builder.getRankProfileRegistry().get(child1, "child1_profile"));
- var child1profile = builder.getRankProfileRegistry().get(child1, "child1_profile");
assertEquals("parent_profile", builder.getRankProfileRegistry().get(child1, "child1_profile").inheritedNames().get(0));
- assertNotNull(child1.constants().get(FeatureNames.asConstantFeature("parent_constant")));
- assertNotNull(child1profile.constants().get(FeatureNames.asConstantFeature("child1_constant")));
- assertTrue(child1.constants().containsKey(FeatureNames.asConstantFeature("parent_constant")));
- assertTrue(child1profile.constants().containsKey(FeatureNames.asConstantFeature("child1_constant")));
- assertTrue(child1profile.constants().containsKey(FeatureNames.asConstantFeature("parent_constant")));
+ assertNotNull(child1.rankingConstants().get("parent_constant"));
+ assertNotNull(child1.rankingConstants().get("child1_constant"));
+ assertTrue(child1.rankingConstants().asMap().containsKey("parent_constant"));
+ assertTrue(child1.rankingConstants().asMap().containsKey("child1_constant"));
assertNotNull(child1.onnxModels().get("parent_model"));
assertNotNull(child1.onnxModels().get("child1_model"));
assertTrue(child1.onnxModels().asMap().containsKey("parent_model"));
@@ -225,10 +224,10 @@ public class SchemaTestCase {
assertNotNull(builder.getRankProfileRegistry().get(child2, "parent_profile"));
assertNotNull(builder.getRankProfileRegistry().get(child2, "child2_profile"));
assertEquals("parent_profile", builder.getRankProfileRegistry().get(child2, "child2_profile").inheritedNames().get(0));
- assertNotNull(child2.constants().get(FeatureNames.asConstantFeature("parent_constant")));
- assertNotNull(child2.constants().get(FeatureNames.asConstantFeature("child2_constant")));
- assertTrue(child2.constants().containsKey(FeatureNames.asConstantFeature("parent_constant")));
- assertTrue(child2.constants().containsKey(FeatureNames.asConstantFeature("child2_constant")));
+ assertNotNull(child2.rankingConstants().get("parent_constant"));
+ assertNotNull(child2.rankingConstants().get("child2_constant"));
+ assertTrue(child2.rankingConstants().asMap().containsKey("parent_constant"));
+ assertTrue(child2.rankingConstants().asMap().containsKey("child2_constant"));
assertNotNull(child2.onnxModels().get("parent_model"));
assertNotNull(child2.onnxModels().get("child2_model"));
assertTrue(child2.onnxModels().asMap().containsKey("parent_model"));
@@ -318,8 +317,8 @@ public class SchemaTestCase {
builder.build(true);
var application = builder.application();
- assertInheritedFromParent(application.schemas().get("child"), builder.getRankProfileRegistry());
- assertInheritedFromParent(application.schemas().get("grandchild"), builder.getRankProfileRegistry());
+ assertInheritedFromParent(application.schemas().get("child"), application, builder.getRankProfileRegistry());
+ assertInheritedFromParent(application.schemas().get("grandchild"), application, builder.getRankProfileRegistry());
}
@Test
@@ -420,15 +419,15 @@ public class SchemaTestCase {
}
}
- private void assertInheritedFromParent(Schema schema, RankProfileRegistry rankProfileRegistry) {
+ private void assertInheritedFromParent(Schema schema, Application application, RankProfileRegistry rankProfileRegistry) {
assertEquals("pf1", schema.fieldSets().userFieldSets().get("parent_set").getFieldNames().stream().findFirst().get());
assertEquals(Stemming.NONE, schema.getStemming());
assertEquals(Stemming.BEST, schema.getIndex("parent_index").getStemming());
assertNotNull(schema.getField("parent_field"));
assertNotNull(schema.getExtraField("parent_field"));
assertNotNull(rankProfileRegistry.get(schema, "parent_profile"));
- assertNotNull(schema.constants().get(FeatureNames.asConstantFeature("parent_constant")));
- assertTrue(schema.constants().containsKey(FeatureNames.asConstantFeature("parent_constant")));
+ assertNotNull(schema.rankingConstants().get("parent_constant"));
+ assertTrue(schema.rankingConstants().asMap().containsKey("parent_constant"));
assertNotNull(schema.onnxModels().get("parent_model"));
assertTrue(schema.onnxModels().asMap().containsKey("parent_model"));
assertNotNull(schema.getSummary("parent_summary"));
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 615f6be5b4f..992d770d851 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
@@ -71,7 +71,6 @@ public abstract class AbstractExportingTestCase extends AbstractSchemaTestCase {
.produce(builder.getModel(), new DocumentmanagerConfig.Builder()), path);
DerivedConfiguration.exportDocuments(new DocumentTypes().produce(builder.getModel(), new DocumenttypesConfig.Builder()), path);
DerivedConfiguration.exportQueryProfiles(builder.getQueryProfileRegistry(), path);
- config.exportConstants(path);
return config;
}
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/derived/LiteralBoostTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/derived/LiteralBoostTestCase.java
index 70545c15ca0..1e7dd3a2405 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/derived/LiteralBoostTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/derived/LiteralBoostTestCase.java
@@ -38,7 +38,7 @@ public class LiteralBoostTestCase extends AbstractExportingTestCase {
SDField field1 = document.addField("a", DataType.STRING);
field1.parseIndexingScript("{ index }");
field1.setLiteralBoost(20);
- RankProfile other = new RankProfile("other", schema, rankProfileRegistry);
+ RankProfile other = new RankProfile("other", schema, rankProfileRegistry, schema.rankingConstants());
rankProfileRegistry.add(other);
other.addRankSetting(new RankProfile.RankSetting("a", RankProfile.RankSetting.Type.LITERALBOOST, 333));
@@ -70,7 +70,7 @@ public class LiteralBoostTestCase extends AbstractExportingTestCase {
schema.addDocument(document);
SDField field1 = document.addField("a", DataType.STRING);
field1.parseIndexingScript("{ index }");
- RankProfile other = new RankProfile("other", schema, rankProfileRegistry);
+ RankProfile other = new RankProfile("other", schema, rankProfileRegistry, schema.rankingConstants());
rankProfileRegistry.add(other);
other.addRankSetting(new RankProfile.RankSetting("a", RankProfile.RankSetting.Type.LITERALBOOST, 333));
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithOnnxTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithOnnxTestCase.java
index bd6310ffd48..0929e54a360 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithOnnxTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionWithOnnxTestCase.java
@@ -10,7 +10,10 @@ import com.yahoo.path.Path;
import com.yahoo.search.query.profile.QueryProfileRegistry;
import com.yahoo.searchdefinition.FeatureNames;
import com.yahoo.searchdefinition.parser.ParseException;
+import com.yahoo.searchlib.rankingexpression.evaluation.Value;
import com.yahoo.tensor.TensorType;
+import com.yahoo.vespa.model.VespaModel;
+import com.yahoo.vespa.model.ml.ImportedModelTester;
import com.yahoo.yolean.Exceptions;
import org.junit.After;
import org.junit.Test;
@@ -20,8 +23,10 @@ import java.io.FileReader;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -231,7 +236,7 @@ public class RankingExpressionWithOnnxTestCase {
search.assertFirstPhaseExpression(vespaExpressionWithoutConstant, "my_profile_child");
assertNull("Constant overridden by function is not added",
- search.search().constants().get(name + "_Variable"));
+ search.search().rankingConstants().get( name + "_Variable"));
// At this point the expression is stored - copy application to another location which do not have a models dir
Path storedApplicationDirectory = applicationDir.getParentPath().append("copy");
@@ -246,7 +251,7 @@ public class RankingExpressionWithOnnxTestCase {
searchFromStored.assertFirstPhaseExpression(vespaExpressionWithoutConstant, "my_profile");
searchFromStored.assertFirstPhaseExpression(vespaExpressionWithoutConstant, "my_profile_child");
assertNull("Constant overridden by function is not added",
- searchFromStored.search().constants().get(name + "_Variable"));
+ searchFromStored.search().rankingConstants().get( name + "_Variable"));
} finally {
IOUtils.recursiveDeleteDir(storedApplicationDirectory.toFile());
}
@@ -323,7 +328,7 @@ public class RankingExpressionWithOnnxTestCase {
}
private void assertSmallConstant(String name, TensorType type, RankProfileSearchFixture search) {
- var value = search.compiledRankProfile("my_profile").constants().get(FeatureNames.asConstantFeature(name));
+ var value = search.compiledRankProfile("my_profile").getConstants().get(FeatureNames.asConstantFeature(name));
assertNotNull(value);
assertEquals(type, value.type());
}
diff --git a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/ConstantValidatorTest.java b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/ConstantValidatorTest.java
deleted file mode 100644
index ff45038a051..00000000000
--- a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/ConstantValidatorTest.java
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.vespa.model.application.validation;
-
-import com.yahoo.vespa.model.test.utils.VespaModelCreatorWithFilePkg;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-public class ConstantValidatorTest {
-
- @Test
- public void ensure_that_valid_ranking_constants_do_not_fail() {
- new VespaModelCreatorWithFilePkg("src/test/cfg/application/validation/ranking_constants_ok/").create();
- }
-
- @Test
- public void ensure_that_failing_ranking_constants_fails() {
- try {
- new VespaModelCreatorWithFilePkg("src/test/cfg/application/validation/ranking_constants_fail/").create();
- fail();
- } catch (IllegalArgumentException e) {
- String[] lines = e.getMessage().split("\n");
- assertStartsWith("constant(constant_tensor_2) tensor(x[6]): file:tensors/constant_tensor_2.json: Tensor label is not a string", lines[1]);
- assertStartsWith("constant(constant_tensor_3) tensor(cpp{},d{}): file:tensors/constant_tensor_3.json: Tensor dimension 'cd' does not exist", lines[2]);
- assertStartsWith("constant(constant_tensor_4) tensor(x{},y{}): file:tensors/constant_tensor_4.json: Tensor dimension 'z' does not exist", lines[3]);
- }
- }
-
- private void assertStartsWith(String prefix, String value) {
- assertEquals(prefix, value.substring(0, prefix.length()));
- }
-
-}
diff --git a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/RankingConstantsValidatorTest.java b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/RankingConstantsValidatorTest.java
new file mode 100644
index 00000000000..f6fa73dce74
--- /dev/null
+++ b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/RankingConstantsValidatorTest.java
@@ -0,0 +1,30 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.model.application.validation;
+
+import com.yahoo.vespa.model.test.utils.VespaModelCreatorWithFilePkg;
+import org.junit.Test;
+
+import static com.yahoo.vespa.model.application.validation.RankingConstantsValidator.TensorValidationException;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+public class RankingConstantsValidatorTest {
+
+ @Test
+ public void ensure_that_valid_ranking_constants_do_not_fail() {
+ new VespaModelCreatorWithFilePkg("src/test/cfg/application/validation/ranking_constants_ok/").create();
+ }
+
+ @Test
+ public void ensure_that_failing_ranking_constants_fails() {
+ try {
+ new VespaModelCreatorWithFilePkg("src/test/cfg/application/validation/ranking_constants_fail/").create();
+ fail();
+ } catch (TensorValidationException e) {
+ assertTrue(e.getMessage().contains("Ranking constant 'constant_tensor_2' (tensors/constant_tensor_2.json): Tensor label is not a string (VALUE_NUMBER_INT)"));
+ assertTrue(e.getMessage().contains("Ranking constant 'constant_tensor_3' (tensors/constant_tensor_3.json): Tensor dimension 'cd' does not exist"));
+ assertTrue(e.getMessage().contains("Ranking constant 'constant_tensor_4' (tensors/constant_tensor_4.json): Tensor dimension 'z' does not exist"));
+ }
+ }
+
+}
diff --git a/config-model/src/test/java/com/yahoo/vespa/model/ml/ImportedModelTester.java b/config-model/src/test/java/com/yahoo/vespa/model/ml/ImportedModelTester.java
index 556d91acb70..a1fc13adf5c 100644
--- a/config-model/src/test/java/com/yahoo/vespa/model/ml/ImportedModelTester.java
+++ b/config-model/src/test/java/com/yahoo/vespa/model/ml/ImportedModelTester.java
@@ -1,12 +1,14 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.ml;
+import com.google.common.collect.ImmutableList;
import com.yahoo.config.model.ApplicationPackageTester;
import ai.vespa.rankingexpression.importer.configmodelview.MlModelImporter;
import com.yahoo.config.model.deploy.DeployState;
import com.yahoo.io.GrowableByteBuffer;
import com.yahoo.io.IOUtils;
import com.yahoo.path.Path;
+import com.yahoo.searchdefinition.RankingConstant;
import ai.vespa.rankingexpression.importer.lightgbm.LightGBMImporter;
import ai.vespa.rankingexpression.importer.onnx.OnnxImporter;
import ai.vespa.rankingexpression.importer.tensorflow.TensorFlowImporter;
@@ -19,12 +21,10 @@ import org.xml.sax.SAXException;
import java.io.IOException;
import java.io.UncheckedIOException;
-import java.util.List;
import java.util.Optional;
import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
/**
* Helper for testing of imported models.
@@ -34,11 +34,11 @@ import static org.junit.Assert.assertNotNull;
*/
public class ImportedModelTester {
- private final List<MlModelImporter> importers = List.of(new TensorFlowImporter(),
- new OnnxImporter(),
- new LightGBMImporter(),
- new XGBoostImporter(),
- new VespaImporter());
+ private final ImmutableList<MlModelImporter> importers = ImmutableList.of(new TensorFlowImporter(),
+ new OnnxImporter(),
+ new LightGBMImporter(),
+ new XGBoostImporter(),
+ new VespaImporter());
private final String modelName;
private final Path applicationDir;
@@ -69,10 +69,9 @@ public class ImportedModelTester {
public void assertLargeConstant(String constantName, VespaModel model, Optional<Long> expectedSize) {
try {
Path constantApplicationPackagePath = Path.fromString("models.generated/" + modelName + "/constants").append(constantName + ".tbf");
- var constant = model.rankProfileList().constants().asMap().get(constantName);
- assertNotNull(constant);
- assertEquals(constantName, constant.getName());
- assertTrue(constant.getFileName().endsWith(constantApplicationPackagePath.toString()));
+ RankingConstant rankingConstant = model.rankingConstants().get(constantName);
+ assertEquals(constantName, rankingConstant.getName());
+ assertTrue(rankingConstant.getFileName().endsWith(constantApplicationPackagePath.toString()));
if (expectedSize.isPresent()) {
Path constantPath = applicationDir.append(constantApplicationPackagePath);