aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2023-10-10 13:05:15 +0200
committerGitHub <noreply@github.com>2023-10-10 13:05:15 +0200
commit98cc1dc0aa08f744ec663cda0237009d8f1ee46b (patch)
tree69e248a67771703a1c7f4ecb24edf2cd1d8ded80 /config-model/src/test/java/com/yahoo
parent6e7ab82743f982610a86a1f5c1d12c29cb894fd9 (diff)
parent76b76110106d690196d714312e6bd881da701d7f (diff)
Merge pull request #28831 from vespa-engine/bratseth/inherit-multiple-summaries
Bratseth/inherit multiple summaries
Diffstat (limited to 'config-model/src/test/java/com/yahoo')
-rw-r--r--config-model/src/test/java/com/yahoo/schema/IncorrectSummaryTypesTestCase.java2
-rw-r--r--config-model/src/test/java/com/yahoo/schema/SchemaTestCase.java32
-rw-r--r--config-model/src/test/java/com/yahoo/schema/SummaryTestCase.java92
3 files changed, 107 insertions, 19 deletions
diff --git a/config-model/src/test/java/com/yahoo/schema/IncorrectSummaryTypesTestCase.java b/config-model/src/test/java/com/yahoo/schema/IncorrectSummaryTypesTestCase.java
index acc872f6798..f981e0fc174 100644
--- a/config-model/src/test/java/com/yahoo/schema/IncorrectSummaryTypesTestCase.java
+++ b/config-model/src/test/java/com/yahoo/schema/IncorrectSummaryTypesTestCase.java
@@ -30,7 +30,7 @@ public class IncorrectSummaryTypesTestCase extends AbstractSchemaTestCase {
"}\n");
fail("processing should have failed");
} catch (RuntimeException e) {
- assertEquals("'summary somestring type string' in 'destinations(default )' is inconsistent with 'summary somestring type int' in 'destinations(incorrect )': All declarations of the same summary field must have the same type", e.getMessage());
+ assertEquals("summary somestring type string in document summary 'default' is inconsistent with summary somestring type int in document summary 'incorrect': All declarations of the same summary field must have the same type", e.getMessage());
}
}
diff --git a/config-model/src/test/java/com/yahoo/schema/SchemaTestCase.java b/config-model/src/test/java/com/yahoo/schema/SchemaTestCase.java
index 366c78e22c6..650e2f88f2a 100644
--- a/config-model/src/test/java/com/yahoo/schema/SchemaTestCase.java
+++ b/config-model/src/test/java/com/yahoo/schema/SchemaTestCase.java
@@ -119,6 +119,9 @@ public class SchemaTestCase {
" field pf1 type string {" +
" indexing: summary" +
" }" +
+ " field pf2 type string {" +
+ " indexing: summary" +
+ " }" +
" }" +
" fieldset parent_set {" +
" fields: pf1" +
@@ -139,9 +142,12 @@ public class SchemaTestCase {
" onnx-model parent_model {" +
" file: models/my_model.onnx" +
" }" +
- " document-summary parent_summary {" +
+ " document-summary parent_summary1 {" +
" summary pf1 type string {}" +
" }" +
+ " document-summary parent_summary2 {" +
+ " summary pf2 type string {}" +
+ " }" +
" import field parentschema_ref.name as parent_imported {}" +
" raw-as-base64-in-summary" +
"}");
@@ -170,7 +176,7 @@ public class SchemaTestCase {
" onnx-model child1_model {" +
" file: models/my_model.onnx" +
" }" +
- " document-summary child1_summary inherits parent_summary {" +
+ " document-summary child1_summary inherits parent_summary1 {" +
" summary c1f1 type string {}" +
" }" +
" import field parentschema_ref.name as child1_imported {}" +
@@ -201,7 +207,7 @@ public class SchemaTestCase {
" onnx-model child2_model {" +
" file: models/my_model.onnx" +
" }" +
- " document-summary child2_summary inherits parent_summary {" +
+ " document-summary child2_summary inherits parent_summary1, parent_summary2 {" +
" summary c2f1 type string {}" +
" }" +
" import field parentschema_ref.name as child2_imported {}" +
@@ -239,14 +245,15 @@ public class SchemaTestCase {
assertNotNull(child1.onnxModels().get("child1_model"));
assertTrue(child1.onnxModels().containsKey("parent_model"));
assertTrue(child1.onnxModels().containsKey("child1_model"));
- assertNotNull(child1.getSummary("parent_summary"));
+ assertNotNull(child1.getSummary("parent_summary1"));
assertNotNull(child1.getSummary("child1_summary"));
- assertEquals("parent_summary", child1.getSummary("child1_summary").inherited().get().getName());
- assertTrue(child1.getSummaries().containsKey("parent_summary"));
+ assertEquals("parent_summary1", child1.getSummary("child1_summary").inherited().get(0).getName());
+ assertTrue(child1.getSummaries().containsKey("parent_summary1"));
assertTrue(child1.getSummaries().containsKey("child1_summary"));
assertNotNull(child1.getSummaryField("pf1"));
assertNotNull(child1.getSummaryField("c1f1"));
assertNotNull(child1.getExplicitSummaryField("pf1"));
+ assertNotNull(child1.getExplicitSummaryField("pf2"));
assertNotNull(child1.getExplicitSummaryField("c1f1"));
assertNotNull(child1.getUniqueNamedSummaryFields().get("pf1"));
assertNotNull(child1.getUniqueNamedSummaryFields().get("c1f1"));
@@ -274,24 +281,29 @@ public class SchemaTestCase {
assertNotNull(child2.onnxModels().get("child2_model"));
assertTrue(child2.onnxModels().containsKey("parent_model"));
assertTrue(child2.onnxModels().containsKey("child2_model"));
- assertNotNull(child2.getSummary("parent_summary"));
+ assertNotNull(child2.getSummary("parent_summary1"));
+ assertNotNull(child2.getSummary("parent_summary2"));
assertNotNull(child2.getSummary("child2_summary"));
- assertEquals("parent_summary", child2.getSummary("child2_summary").inherited().get().getName());
- assertTrue(child2.getSummaries().containsKey("parent_summary"));
+ assertEquals("parent_summary1", child2.getSummary("child2_summary").inherited().get(0).getName());
+ assertEquals("parent_summary2", child2.getSummary("child2_summary").inherited().get(1).getName());
+ assertTrue(child2.getSummaries().containsKey("parent_summary1"));
+ assertTrue(child2.getSummaries().containsKey("parent_summary2"));
assertTrue(child2.getSummaries().containsKey("child2_summary"));
assertNotNull(child2.getSummaryField("pf1"));
assertNotNull(child2.getSummaryField("c2f1"));
assertNotNull(child2.getExplicitSummaryField("pf1"));
assertNotNull(child2.getExplicitSummaryField("c2f1"));
assertNotNull(child2.getUniqueNamedSummaryFields().get("pf1"));
+ assertNotNull(child2.getUniqueNamedSummaryFields().get("pf2"));
assertNotNull(child2.getUniqueNamedSummaryFields().get("c2f1"));
assertNotNull(child2.temporaryImportedFields().get().fields().get("parent_imported"));
assertNotNull(child2.temporaryImportedFields().get().fields().get("child2_imported"));
DocumentSummary child2DefaultSummary = child2.getSummary("default");
- assertEquals(6, child2DefaultSummary.getSummaryFields().size());
+ assertEquals(7, child2DefaultSummary.getSummaryFields().size());
assertTrue(child2DefaultSummary.getSummaryFields().containsKey("child2_field"));
assertTrue(child2DefaultSummary.getSummaryFields().containsKey("parent_field"));
assertTrue(child2DefaultSummary.getSummaryFields().containsKey("pf1"));
+ assertTrue(child2DefaultSummary.getSummaryFields().containsKey("pf2"));
assertTrue(child2DefaultSummary.getSummaryFields().containsKey("c2f1"));
DocumentSummary child2AttributeprefetchSummary = child2.getSummary("attributeprefetch");
assertEquals(4, child2AttributeprefetchSummary.getSummaryFields().size());
diff --git a/config-model/src/test/java/com/yahoo/schema/SummaryTestCase.java b/config-model/src/test/java/com/yahoo/schema/SummaryTestCase.java
index 268e0b17b24..6b60005539e 100644
--- a/config-model/src/test/java/com/yahoo/schema/SummaryTestCase.java
+++ b/config-model/src/test/java/com/yahoo/schema/SummaryTestCase.java
@@ -5,6 +5,7 @@ import com.yahoo.schema.parser.ParseException;
import com.yahoo.vespa.documentmodel.DocumentSummary;
import com.yahoo.vespa.model.test.utils.DeployLoggerStub;
import com.yahoo.vespa.objects.FieldBase;
+import com.yahoo.yolean.Exceptions;
import org.junit.jupiter.api.Test;
import static com.yahoo.config.model.test.TestUtil.joinLines;
@@ -67,7 +68,7 @@ public class SummaryTestCase {
"Fields [foo2] references non-attribute fields: " +
"Using this summary will cause disk accesses. " +
"Set 'from-disk' on this summary class to silence this warning.",
- logger.entries.get(0).message);
+ logger.entries.get(0).message);
}
@Test
@@ -176,9 +177,13 @@ public class SummaryTestCase {
var actualFields = testValue.summary.getSummaryFields().values().stream()
.map(FieldBase::getName)
.toList();
- assertEquals(Optional.ofNullable(testValue.parent),
- testValue.summary.inherited(),
- testValue.summary.getName() + (testValue.parent == null ? " does not inherit anything" : " inherits " + testValue.parent.getName()));
+ if (testValue.parent != null)
+ assertEquals(testValue.parent, testValue.summary.inherited().get(0),
+ testValue.summary.getName() + " inherits " + testValue.parent.getName());
+ else
+ assertTrue(testValue.summary.inherited().isEmpty(),
+ testValue.summary.getName() + " does not inherit anything");
+
assertEquals(testValue.fields, actualFields, "Summary " + testValue.summary.getName() + " has expected fields");
});
}
@@ -229,17 +234,89 @@ public class SummaryTestCase {
"}");
DeployLoggerStub logger = new DeployLoggerStub();
ApplicationBuilder.createFromStrings(logger, schema);
- assertEquals("document summary 'test_summary' inherits nonesuch but this is not present in schema 'test'",
- logger.entries.get(0).message);
+ assertEquals("document summary 'test_summary' inherits 'nonesuch' but this is not present in schema 'test'",
+ logger.entries.get(0).message);
// fail("Expected failure");
}
catch (IllegalArgumentException e) {
+ fail();
// assertEquals("document summary 'test_summary' inherits nonesuch but this is not present in schema 'test'",
// e.getMessage());
}
}
@Test
+ void testInheritingTwoSummariesWithConflictingFieldsFails() throws ParseException {
+ try {
+ String schema = """
+ schema test {
+ document test {
+ field field1 type string {
+ indexing: summary | index | attribute
+ }
+ field field2 type int {
+ indexing: summary | attribute
+ }
+ }
+ document-summary parent1 {
+ summary s1 type string {
+ source: field1
+ }
+ }
+ document-summary parent2 {
+ summary field1 type int {
+ source: field2
+ }
+ }
+ document-summary child inherits parent1, parent2 {
+ }
+ }
+ """;
+ DeployLoggerStub logger = new DeployLoggerStub();
+ ApplicationBuilder.createFromStrings(logger, schema);
+ fail("Expected failure");
+ }
+ catch (IllegalArgumentException e) {
+ assertEquals("summary field1 type string in document summary 'default' is inconsistent with " +
+ "summary field1 type int in document summary 'parent2': " +
+ "All declarations of the same summary field must have the same type",
+ Exceptions.toMessageString(e));
+ }
+ }
+
+ @Test
+ void testInheritingTwoSummariesWithNonConflictingFieldsWorks() throws ParseException {
+ String schema = """
+ schema test {
+ document test {
+ field field1 type string {
+ indexing: summary | index | attribute
+ }
+ field field2 type int {
+ indexing: summary | attribute
+ }
+ }
+ document-summary parent1 {
+ summary s1 type string {
+ source: field1
+ }
+ }
+ document-summary parent2 {
+ summary field1 type string {
+ source: field1
+ }
+ }
+ document-summary child inherits parent1, parent2 {
+ }
+ }
+ """;
+ DeployLoggerStub logger = new DeployLoggerStub();
+ ApplicationBuilder.createFromStrings(logger, schema);
+ System.out.println("logger.entries = " + logger.entries);
+ assertTrue(logger.entries.isEmpty());
+ }
+
+ @Test
void testInheritingParentSummary() throws ParseException {
String parent = joinLines(
"schema parent {" +
@@ -265,8 +342,7 @@ public class SummaryTestCase {
"}");
DeployLoggerStub logger = new DeployLoggerStub();
ApplicationBuilder.createFromStrings(logger, parent, child);
- logger.entries.forEach(e -> System.out.println(e));
- //assertTrue(logger.entries.isEmpty());
+ assertTrue(logger.entries.isEmpty());
}
private static class TestValue {