diff options
Diffstat (limited to 'config-model/src/test/java/com/yahoo')
14 files changed, 188 insertions, 100 deletions
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/AttributeSettingsTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/AttributeSettingsTestCase.java index 7b2ed2d7a7f..2a58618e11f 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/AttributeSettingsTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/AttributeSettingsTestCase.java @@ -74,6 +74,14 @@ public class AttributeSettingsTestCase extends AbstractSchemaTestCase { assertWeightedSet(schema, "f8", true, false); assertWeightedSet(schema, "f9", false, true); assertWeightedSet(schema, "f10", false, true); + + assertAttrSettings(schema, "f4", false, false, false); + assertAttrSettings(schema, "f5", true, true, true); + assertAttrSettings(schema, "f6", false, false, false); + assertAttrSettings(schema, "f7", false, false, false); + assertAttrSettings(schema, "f8", false, false, false); + assertAttrSettings(schema, "f9", false, false, false); + assertAttrSettings(schema, "f10", false, false, false); } private void assertWeightedSet(Schema schema, String name, boolean createIfNonExistent, boolean removeIfZero) { @@ -82,13 +90,21 @@ public class AttributeSettingsTestCase extends AbstractSchemaTestCase { Attribute a4 = f4.getAttributes().get(f4.getName()); assertEquals(Attribute.Type.STRING, a4.getType()); assertEquals(Attribute.CollectionType.WEIGHTEDSET, a4.getCollectionType()); - assertFalse(a4.isHuge()); - assertFalse(a4.isFastSearch()); - assertFalse(a4.isFastAccess()); assertEquals(a4.isRemoveIfZero(), removeIfZero); assertEquals(a4.isCreateIfNonExistent(), createIfNonExistent); } + private void assertAttrSettings(Schema schema, String name, boolean fastAccess, boolean fastSearch, boolean paged) { + SDField f4 = (SDField) schema.getDocument().getField(name); + assertEquals(1, f4.getAttributes().size()); + Attribute a4 = f4.getAttributes().get(f4.getName()); + assertEquals(Attribute.Type.STRING, a4.getType()); + assertEquals(Attribute.CollectionType.WEIGHTEDSET, a4.getCollectionType()); + assertEquals(a4.isFastSearch(), fastSearch); + assertEquals(a4.isFastAccess(), fastAccess); + assertEquals(a4.isPaged(), paged); + } + @Test public void requireThatFastAccessCanBeSet() throws IOException, ParseException { Schema schema = ApplicationBuilder.buildFromFile("src/test/examples/attributesettings.sd"); diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/MultipleSummariesTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/MultipleSummariesTestCase.java index 0fcc6e09b02..1bf07aff9d5 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/MultipleSummariesTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/MultipleSummariesTestCase.java @@ -1,6 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.searchdefinition; +import com.yahoo.config.model.deploy.TestProperties; import com.yahoo.searchdefinition.parser.ParseException; import org.junit.Test; @@ -12,8 +13,11 @@ import java.io.IOException; * @author bratseth */ public class MultipleSummariesTestCase extends AbstractSchemaTestCase { + @Test public void testArrayImporting() throws IOException, ParseException { - ApplicationBuilder.buildFromFile("src/test/examples/multiplesummaries.sd"); + var builder = new ApplicationBuilder(new TestProperties().setExperimentalSdParsing(true)); + builder.addSchemaFile("src/test/examples/multiplesummaries.sd"); + builder.build(true); } } 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 94d25deb16a..e297beef026 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionInliningTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionInliningTestCase.java @@ -192,14 +192,19 @@ public class RankingExpressionInliningTestCase extends AbstractSchemaTestCase { @Test public void testFunctionInliningWithReplacement() throws ParseException { + checkFunctionReplacement(false); + checkFunctionReplacement(true); + } + + public void checkFunctionReplacement(boolean useXPP) throws ParseException { RankProfileRegistry rankProfileRegistry = new RankProfileRegistry(); MockDeployLogger deployLogger = new MockDeployLogger(); ApplicationBuilder builder = new ApplicationBuilder(MockApplicationPackage.createEmpty(), - new MockFileRegistry(), - deployLogger, - new TestProperties(), - rankProfileRegistry, - new QueryProfileRegistry()); + new MockFileRegistry(), + deployLogger, + new TestProperties().setExperimentalSdParsing(useXPP), + rankProfileRegistry, + new QueryProfileRegistry()); builder.addSchema( "search test {\n" + " document test { }\n" + @@ -219,8 +224,8 @@ public class RankingExpressionInliningTestCase extends AbstractSchemaTestCase { Schema s = builder.getSchema(); 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'")); + assertTrue("Does not contain expected warning", + deployLogger.contains("Function 'foo' is defined twice in rank profile 'test'")); } /** diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/StructTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/StructTestCase.java index c27dd9dfdfb..32f82f44ad0 100755 --- a/config-model/src/test/java/com/yahoo/searchdefinition/StructTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/StructTestCase.java @@ -1,10 +1,13 @@ + // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.searchdefinition; +import com.yahoo.config.model.deploy.TestProperties; import com.yahoo.document.config.DocumenttypesConfig; import com.yahoo.document.config.DocumentmanagerConfig; import com.yahoo.searchdefinition.derived.Deriver; import com.yahoo.searchdefinition.parser.ParseException; +import org.junit.Ignore; import org.junit.Test; import java.io.IOException; import static org.junit.Assert.fail; @@ -27,15 +30,19 @@ public class StructTestCase extends AbstractSchemaTestCase { try { ApplicationBuilder.buildFromFile("src/test/examples/badstruct.sd"); fail("Should throw exception."); - } catch (ParseException expected) { + } catch (IllegalArgumentException|ParseException expected) { + System.err.println("As expected, with message: "+expected.getMessage()); // success } } @Test + @Ignore public void testStructAndDocumentWithSameNames() { try { DocumenttypesConfig.Builder dt = Deriver.getDocumentTypesConfig("src/test/examples/structanddocumentwithsamenames.sd"); + // while the above line may work, the config generated will fail. + // See also NameCollisionTestCase. } catch (Exception e) { fail("Should not have thrown exception " + e); } @@ -46,7 +53,17 @@ public class StructTestCase extends AbstractSchemaTestCase { */ @Test(expected = IllegalArgumentException.class) public void testStructOutsideDocumentIllegal() throws IOException, ParseException { - ApplicationBuilder.buildFromFile("src/test/examples/structoutsideofdocument.sd"); + var builder = new ApplicationBuilder(new TestProperties().setExperimentalSdParsing(false)); + builder.addSchemaFile("src/test/examples/structoutsideofdocument.sd"); + } + + /** + * Declaring a struct before a document should work + */ + @Test + public void testStructOutsideDocumentLegal() throws IOException, ParseException { + var builder = new ApplicationBuilder(new TestProperties().setExperimentalSdParsing(true)); + builder.addSchemaFile("src/test/examples/structoutsideofdocument.sd"); } } 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 456efdb08ae..ad4ff4be4b3 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 @@ -100,6 +100,7 @@ public abstract class AbstractExportingTestCase extends AbstractSchemaTestCase { DeployLogger logger) throws IOException, ParseException { return assertCorrectDeriving(dirName, searchDefinitionName, new TestProperties(), logger); } + protected DerivedConfiguration assertCorrectDeriving(String dirName, TestProperties properties) throws IOException, ParseException { diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/derived/AnnotationsTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/derived/AnnotationsTestCase.java index b9f471f4cc7..65d6c15d3e2 100755 --- a/config-model/src/test/java/com/yahoo/searchdefinition/derived/AnnotationsTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/derived/AnnotationsTestCase.java @@ -1,6 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.searchdefinition.derived; +import com.yahoo.config.model.deploy.TestProperties; import com.yahoo.searchdefinition.parser.ParseException; import org.junit.Test; @@ -13,55 +14,74 @@ public class AnnotationsTestCase extends AbstractExportingTestCase { @Test public void requireThatStructRegistersIfOnlyUsedByAnnotation() throws IOException, ParseException { - assertCorrectDeriving("annotationsstruct"); + assertCorrectDeriving("annotationsstruct", + new TestProperties().setExperimentalSdParsing(true)); } @Test public void requireThatStructRegistersIfOnlyUsedAsArrayByAnnotation() throws IOException, ParseException { - assertCorrectDeriving("annotationsstructarray"); + assertCorrectDeriving("annotationsstructarray", + new TestProperties().setExperimentalSdParsing(true)); } @Test public void testSimpleAnnotationDeriving() throws IOException, ParseException { - assertCorrectDeriving("annotationssimple"); + assertCorrectDeriving("annotationssimple", + new TestProperties().setExperimentalSdParsing(true)); } @Test public void testAnnotationDerivingWithImplicitStruct() throws IOException, ParseException { - assertCorrectDeriving("annotationsimplicitstruct"); + assertCorrectDeriving("annotationsimplicitstruct", + new TestProperties().setExperimentalSdParsing(true)); } @Test public void testAnnotationDerivingInheritance() throws IOException, ParseException { - assertCorrectDeriving("annotationsinheritance"); + assertCorrectDeriving("annotationsinheritance", + new TestProperties().setExperimentalSdParsing(true)); } @Test public void testAnnotationDerivingInheritance2() throws IOException, ParseException { - assertCorrectDeriving("annotationsinheritance2"); + assertCorrectDeriving("annotationsinheritance2", + new TestProperties().setExperimentalSdParsing(true)); } @Test public void testSimpleReference() throws IOException, ParseException { - assertCorrectDeriving("annotationsreference"); + assertCorrectDeriving("annotationsreference", + new TestProperties().setExperimentalSdParsing(true)); } @Test public void testAdvancedReference() throws IOException, ParseException { - assertCorrectDeriving("annotationsreference2"); + assertCorrectDeriving("annotationsreference2", + new TestProperties().setExperimentalSdParsing(true)); } @Test public void testAnnotationsPolymorphy() throws IOException, ParseException { - assertCorrectDeriving("annotationspolymorphy"); + assertCorrectDeriving("annotationspolymorphy", + new TestProperties().setExperimentalSdParsing(true)); } /** * An annotation declared before document {} won't work, no doc type to add it to. */ @Test(expected = IllegalArgumentException.class) - public void testAnnotationOutsideOfDocumment() throws IOException, ParseException { - assertCorrectDeriving("annotationsoutsideofdocument"); + public void testAnnotationOutsideOfDocumentOld() throws IOException, ParseException { + assertCorrectDeriving("annotationsoutsideofdocument", + new TestProperties().setExperimentalSdParsing(false)); + } + + /** + * An annotation declared before document {} should work. + */ + @Test + public void testAnnotationOutsideOfDocumentNew() throws IOException, ParseException { + assertCorrectDeriving("annotationsoutsideofdocument", + new TestProperties().setExperimentalSdParsing(true)); } } 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 719d353f03a..412206d34ed 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 @@ -25,7 +25,7 @@ public class ExportingTestCase extends AbstractExportingTestCase { @Test public void testPositionArray() throws IOException, ParseException { assertCorrectDeriving("position_array", - new TestProperties().setUseV8GeoPositions(true)); + new TestProperties().setExperimentalSdParsing(true).setUseV8GeoPositions(true)); } @Test @@ -49,7 +49,7 @@ public class ExportingTestCase extends AbstractExportingTestCase { @Test public void testPositionSummary() throws IOException, ParseException { assertCorrectDeriving("position_summary", - new TestProperties().setUseV8GeoPositions(true)); + new TestProperties().setExperimentalSdParsing(true).setUseV8GeoPositions(true)); } @Test @@ -108,14 +108,14 @@ public class ExportingTestCase extends AbstractExportingTestCase { } @Test - public void testRankExpression() throws IOException, ParseException { - assertCorrectDeriving("rankexpression"); + public void testRankingExpression() throws IOException, ParseException { + assertCorrectDeriving("rankingexpression"); } @Test public void testAvoidRenamingRankingExpression() throws IOException, ParseException { assertCorrectDeriving("renamedfeatures", "foo", - new TestProperties().setAvoidRenamingSummaryFeatures(true), + new TestProperties().setExperimentalSdParsing(true).setAvoidRenamingSummaryFeatures(true), new TestableDeployLogger()); } diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/derived/ImportedFieldsTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/derived/ImportedFieldsTestCase.java index 34354612d04..5dcb9e4ca01 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/derived/ImportedFieldsTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/derived/ImportedFieldsTestCase.java @@ -1,6 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.searchdefinition.derived; +import com.yahoo.config.model.deploy.TestProperties; import com.yahoo.searchdefinition.parser.ParseException; import org.junit.Test; @@ -18,7 +19,16 @@ public class ImportedFieldsTestCase extends AbstractExportingTestCase { @Test public void configs_for_imported_struct_fields_are_derived() throws IOException, ParseException { - assertCorrectDeriving("imported_struct_fields", "child", new TestableDeployLogger()); + assertCorrectDeriving("imported_struct_fields", "child", + new TestProperties().setExperimentalSdParsing(false), + new TestableDeployLogger()); + } + + @Test + public void configs_for_imported_struct_fields_are_derived_new() throws IOException, ParseException { + assertCorrectDeriving("imported_struct_fields", "child", + new TestProperties().setExperimentalSdParsing(true), + new TestableDeployLogger()); } @Test diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/derived/MultipleSummariesTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/derived/MultipleSummariesTestCase.java index 0e6d7b8442f..b13e88f5f1f 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/derived/MultipleSummariesTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/derived/MultipleSummariesTestCase.java @@ -1,6 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.searchdefinition.derived; +import com.yahoo.config.model.deploy.TestProperties; import com.yahoo.searchdefinition.parser.ParseException; import org.junit.Test; @@ -14,6 +15,13 @@ import java.io.IOException; public class MultipleSummariesTestCase extends AbstractExportingTestCase { @Test public void testMultipleSummaries() throws IOException, ParseException { - assertCorrectDeriving("multiplesummaries"); + assertCorrectDeriving("multiplesummaries", + new TestProperties().setExperimentalSdParsing(false)); + } + + @Test + public void testMultipleSummariesNew() throws IOException, ParseException { + assertCorrectDeriving("multiplesummaries", + new TestProperties().setExperimentalSdParsing(true)); } } diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/derived/NameCollisionTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/derived/NameCollisionTestCase.java index 5fce5c06943..70f6187be12 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/derived/NameCollisionTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/derived/NameCollisionTestCase.java @@ -2,7 +2,12 @@ package com.yahoo.searchdefinition.derived; +import com.yahoo.config.model.deploy.TestProperties; +import com.yahoo.document.DocumentTypeManager; +import com.yahoo.searchdefinition.ApplicationBuilder; + import org.junit.Test; +import static org.junit.Assert.assertThrows; /** * Verifies that a struct in a document type is preferred over another document type @@ -14,7 +19,21 @@ public class NameCollisionTestCase extends AbstractExportingTestCase { @Test public void testNameCollision() throws Exception { - assertCorrectDeriving("namecollision", "collisionstruct", new TestableDeployLogger()); + var ex = assertThrows(IllegalArgumentException.class, () -> { + assertCorrectDeriving("namecollision", "collisionstruct", + new TestProperties().setExperimentalSdParsing(false), + new TestableDeployLogger()); + var docman = DocumentTypeManager.fromFile("temp/namecollision/documentmanager.cfg"); + }); + System.err.println("MSG 1: "+ex.getClass()+" -> "+ex.getMessage()); + var ey = assertThrows(IllegalArgumentException.class, () -> { + assertCorrectDeriving("namecollision", "collisionstruct", + new TestProperties().setExperimentalSdParsing(true), + new TestableDeployLogger()); + var docman = DocumentTypeManager.fromFile("temp/namecollision/documentmanager.cfg"); + }); + System.err.println("MSG 2: "+ey.getMessage()); + } } diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/parser/ConvertIntermediateTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/parser/ConvertIntermediateTestCase.java index 264481cb3ec..127f5184c4c 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/parser/ConvertIntermediateTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/parser/ConvertIntermediateTestCase.java @@ -26,7 +26,6 @@ public class ConvertIntermediateTestCase { var collection = new IntermediateCollection(); ParsedSchema schema = collection.addSchemaFromString(input); assertEquals("foo", schema.getDocument().name()); - collection.resolveInternalConnections(); var docMan = new DocumentTypeManager(); var converter = new ConvertSchemaCollection(collection, docMan); converter.convertTypes(); @@ -41,7 +40,6 @@ public class ConvertIntermediateTestCase { collection.addSchemaFromFile("src/test/derived/deriver/grandparent.sd"); collection.addSchemaFromFile("src/test/derived/deriver/parent.sd"); assertEquals(collection.getParsedSchemas().size(), 3); - collection.resolveInternalConnections(); var docMan = new DocumentTypeManager(); var converter = new ConvertSchemaCollection(collection, docMan); converter.convertTypes(); @@ -60,7 +58,6 @@ public class ConvertIntermediateTestCase { collection.addSchemaFromFile("src/test/converter/other.sd"); collection.addSchemaFromFile("src/test/converter/parent.sd"); collection.addSchemaFromFile("src/test/converter/grandparent.sd"); - collection.resolveInternalConnections(); var docMan = new DocumentTypeManager(); var converter = new ConvertSchemaCollection(collection, docMan); converter.convertTypes(); diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/parser/IntermediateCollectionTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/parser/IntermediateCollectionTestCase.java index cd78f1faeb2..e29e4833856 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/parser/IntermediateCollectionTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/parser/IntermediateCollectionTestCase.java @@ -36,6 +36,20 @@ public class IntermediateCollectionTestCase { } @Test + public void names_may_differ() throws Exception { + String input = joinLines + ("schema foo_search {", + " document foo {", + " }", + "}"); + var collection = new IntermediateCollection(); + ParsedSchema schema = collection.addSchemaFromString(input); + assertEquals("foo_search", schema.name()); + assertTrue(schema.hasDocument()); + assertEquals("foo", schema.getDocument().name()); + } + + @Test public void can_add_schema_files() throws Exception { var collection = new IntermediateCollection(); collection.addSchemaFromFile("src/test/derived/deriver/child.sd"); @@ -127,16 +141,16 @@ public class IntermediateCollectionTestCase { public void bad_parse_throws() throws Exception { var collection = new IntermediateCollection(); var ex = assertThrows(ParseException.class, () -> - collection.addSchemaFromFile("src/test/examples/structoutsideofdocument.sd")); - assertTrue(ex.getMessage().startsWith("Failed parsing schema from src/test/examples/structoutsideofdocument.sd: Encountered")); + collection.addSchemaFromFile("src/test/examples/badparse.sd")); + assertTrue(ex.getMessage().startsWith("Failed parsing schema from src/test/examples/badparse.sd: Encountered")); ex = assertThrows(ParseException.class, () -> - collection.addSchemaFromReader(readerOf("src/test/examples/structoutsideofdocument.sd"))); - assertTrue(ex.getMessage().startsWith("Failed parsing schema from src/test/examples/structoutsideofdocument.sd: Encountered")); + collection.addSchemaFromReader(readerOf("src/test/examples/badparse.sd"))); + assertTrue(ex.getMessage().startsWith("Failed parsing schema from src/test/examples/badparse.sd: Encountered")); collection.addSchemaFromFile("src/test/derived/rankprofilemodularity/test.sd"); collection.addRankProfileFile("test", "src/test/derived/rankprofilemodularity/test/outside_schema1.profile"); ex = assertThrows(ParseException.class, () -> - collection.addRankProfileFile("test", "src/test/examples/structoutsideofdocument.sd")); - assertTrue(ex.getMessage().startsWith("Failed parsing rank-profile from src/test/examples/structoutsideofdocument.sd: Encountered")); + collection.addRankProfileFile("test", "src/test/examples/badparse.sd")); + assertTrue(ex.getMessage().startsWith("Failed parsing rank-profile from src/test/examples/badparse.sd: Encountered")); } @Test @@ -167,7 +181,7 @@ public class IntermediateCollectionTestCase { assertEquals(collection.getParsedSchemas().size(), 3); var ex = assertThrows(IllegalArgumentException.class, () -> collection.resolveInternalConnections()); - assertTrue(ex.getMessage().startsWith("Inheritance cycle for schemas: ")); + assertTrue(ex.getMessage().startsWith("Inheritance/reference cycle for schemas: ")); } @Test @@ -180,7 +194,7 @@ public class IntermediateCollectionTestCase { var ex = assertThrows(IllegalArgumentException.class, () -> collection.resolveInternalConnections()); System.err.println("ex: "+ex.getMessage()); - assertTrue(ex.getMessage().startsWith("Inheritance cycle for documents: ")); + assertTrue(ex.getMessage().startsWith("Inheritance/reference cycle for documents: ")); } @Test @@ -194,4 +208,30 @@ public class IntermediateCollectionTestCase { assertEquals("document foo inherits from unavailable document bar", ex.getMessage()); } + @Test + public void can_detect_document_reference_cycle() throws Exception { + var collection = new IntermediateCollection(); + collection.addSchemaFromString("schema foo { document foo { field oneref type reference<bar> {} } }"); + collection.addSchemaFromString("schema bar { document bar { field tworef type reference<foo> {} } }"); + assertEquals(collection.getParsedSchemas().size(), 2); + var ex = assertThrows(IllegalArgumentException.class, () -> + collection.resolveInternalConnections()); + System.err.println("ex: "+ex.getMessage()); + assertTrue(ex.getMessage().startsWith("Inheritance/reference cycle for documents: ")); + } + + @Test + public void can_detect_cycles_with_reference() throws Exception { + var collection = new IntermediateCollection(); + collection.addSchemaFromString("schema foo { document foodoc inherits bardoc {} }"); + collection.addSchemaFromString("schema bar { document bardoc { field myref type reference<qux> { } } }"); + collection.addSchemaFromString("schema qux inherits foo { document qux inherits foodoc {} }"); + assertEquals(collection.getParsedSchemas().size(), 3); + var ex = assertThrows(IllegalArgumentException.class, () -> + collection.resolveInternalConnections()); + System.err.println("ex: "+ex.getMessage()); + assertTrue(ex.getMessage().startsWith("Inheritance/reference cycle for documents: ")); + } + + } diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/parser/IntermediateParserTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/parser/IntermediateParserTestCase.java index 4e212ccd574..8bd04af8c54 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/parser/IntermediateParserTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/parser/IntermediateParserTestCase.java @@ -22,8 +22,12 @@ public class IntermediateParserTestCase { var deployLogger = new BaseDeployLogger(); var modelProperties = new TestProperties(); var stream = new SimpleCharStream(input); - var parser = new IntermediateParser(stream, deployLogger, modelProperties); - return parser.schema(); + try { + var parser = new IntermediateParser(stream, deployLogger, modelProperties); + return parser.schema(); + } catch (ParseException pe) { + throw new ParseException(stream.formatException(pe.getMessage())); + } } ParsedSchema parseFile(String fileName) throws Exception { @@ -174,7 +178,7 @@ public class IntermediateParserTestCase { checkFileParses("src/test/derived/position_summary/position_summary.sd"); checkFileParses("src/test/derived/predicate_attribute/predicate_attribute.sd"); checkFileParses("src/test/derived/prefixexactattribute/prefixexactattribute.sd"); - checkFileParses("src/test/derived/rankexpression/rankexpression.sd"); + checkFileParses("src/test/derived/rankingexpression/rankexpression.sd"); checkFileParses("src/test/derived/rankprofileinheritance/child.sd"); checkFileParses("src/test/derived/rankprofileinheritance/parent1.sd"); checkFileParses("src/test/derived/rankprofileinheritance/parent2.sd"); @@ -208,9 +212,9 @@ public class IntermediateParserTestCase { checkFileParses("src/test/derived/uri_wset/uri_wset.sd"); checkFileParses("src/test/examples/arrays.sd"); checkFileParses("src/test/examples/arraysweightedsets.sd"); + checkFileParses("src/test/examples/attributeposition.sd"); checkFileParses("src/test/examples/attributesettings.sd"); checkFileParses("src/test/examples/attributesexactmatch.sd"); - checkFileParses("src/test/examples/badstruct.sd"); checkFileParses("src/test/examples/casing.sd"); checkFileParses("src/test/examples/comment.sd"); checkFileParses("src/test/examples/documentidinsummary.sd"); @@ -252,7 +256,6 @@ public class IntermediateParserTestCase { checkFileParses("src/test/examples/stemmingdefault.sd"); checkFileParses("src/test/examples/stemmingsetting.sd"); checkFileParses("src/test/examples/strange.sd"); - checkFileParses("src/test/examples/structanddocumentwithsamenames.sd"); checkFileParses("src/test/examples/struct.sd"); checkFileParses("src/test/examples/summaryfieldcollision.sd"); checkFileParses("src/test/examples/weightedset-summaryto.sd"); diff --git a/config-model/src/test/java/com/yahoo/vespa/model/ml/OnnxModelProbeTest.java b/config-model/src/test/java/com/yahoo/vespa/model/ml/OnnxModelProbeTest.java deleted file mode 100644 index 6c4c919a229..00000000000 --- a/config-model/src/test/java/com/yahoo/vespa/model/ml/OnnxModelProbeTest.java +++ /dev/null @@ -1,52 +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.ml; - -import com.yahoo.config.application.api.ApplicationPackage; -import com.yahoo.config.model.application.provider.FilesApplicationPackage; -import com.yahoo.io.IOUtils; -import com.yahoo.path.Path; -import com.yahoo.tensor.TensorType; -import org.junit.Test; - -import java.io.IOException; -import java.util.Map; - -import static org.junit.Assert.assertEquals; - -public class OnnxModelProbeTest { - - @Test - public void testProbedOutputTypes() throws IOException { - - Path appDir = Path.fromString("src/test/cfg/application/onnx_probe"); - Path storedAppDir = appDir.append("copy"); - try { - FilesApplicationPackage app = FilesApplicationPackage.fromFile(appDir.toFile()); - Path modelPath = Path.fromString("files/dynamic_model.onnx"); - String output = "out"; - Map<String, TensorType> inputTypes = Map.of( - "input1", TensorType.fromSpec("tensor<float>(d0[1],d1[2])"), - "input2", TensorType.fromSpec("tensor<float>(d0[1],d1[2])")); - TensorType expected = TensorType.fromSpec("tensor<float>(d0[1],d1[2],d2[2])"); - - // Can't test model probing directly as 'vespa-analyze-onnx-model' is not available - TensorType outputType = OnnxModelProbe.probeModel(app, modelPath, output, inputTypes); - assertEquals(outputType, TensorType.empty); - - OnnxModelProbe.writeProbedOutputType(app, modelPath, output, inputTypes, expected); - - // Test loading from generated info - storedAppDir.toFile().mkdirs(); - IOUtils.copyDirectory(appDir.append(ApplicationPackage.MODELS_GENERATED_DIR).toFile(), - storedAppDir.append(ApplicationPackage.MODELS_GENERATED_DIR).toFile()); - app = FilesApplicationPackage.fromFile(storedAppDir.toFile()); - outputType = OnnxModelProbe.probeModel(app, modelPath, output, inputTypes); - assertEquals(outputType, expected); - - } finally { - IOUtils.recursiveDeleteDir(appDir.append(ApplicationPackage.MODELS_GENERATED_DIR).toFile()); - IOUtils.recursiveDeleteDir(storedAppDir.toFile()); - } - } - -} |