diff options
author | Jon Bratseth <jonbratseth@yahoo.com> | 2017-01-12 22:17:49 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-12 22:17:49 +0100 |
commit | 585a5b38c5811da950336c26326636773ca289e3 (patch) | |
tree | bacb7cb5b8d3e881a2df260589b9b0e046b12e89 /config-model/src/test/java | |
parent | b72c29c29a2c8dd8ecac8aeffdaff688b21ee41c (diff) |
Revert "Revert "Bratseth/tensor type info in documents""
Diffstat (limited to 'config-model/src/test/java')
7 files changed, 46 insertions, 29 deletions
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 4a3119e55b7..83d5c422fdf 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/FieldOfTypeDocumentTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/FieldOfTypeDocumentTestCase.java @@ -14,9 +14,10 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; /** - * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + * @author Einar M R Rosenvinge */ public class FieldOfTypeDocumentTestCase extends SearchDefinitionTestCase { + @Test public void testDocument() throws IOException, ParseException { @@ -25,7 +26,7 @@ public class FieldOfTypeDocumentTestCase extends SearchDefinitionTestCase { sds.add("src/test/examples/fieldoftypedocument.sd"); DocumentmanagerConfig.Builder value = Deriver.getDocumentManagerConfig(sds); assertConfigFile("src/test/examples/fieldoftypedocument.cfg", - new DocumentmanagerConfig(value).toString() + "\n"); + new DocumentmanagerConfig(value).toString() + "\n"); DocumentTypeManager manager = new DocumentTypeManager(); DocumentTypeManagerConfigurer.configure(manager, "raw:" + new DocumentmanagerConfig(value).toString()); diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/NameFieldCheckTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/NameFieldCheckTestCase.java index f8fe979c866..5542c1ce5e9 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/NameFieldCheckTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/NameFieldCheckTestCase.java @@ -6,14 +6,16 @@ import org.junit.Test; import java.io.IOException; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; + /** * Tests that "name" is not allowed as name for a field. * * And that duplicate names are not allowed. * - * @author <a href="mailto:larschr@yahoo-inc.com">Lars Christian Jensen</a> + * @author Lars Christian Jensen */ public class NameFieldCheckTestCase extends SearchDefinitionTestCase { @@ -22,8 +24,8 @@ public class NameFieldCheckTestCase extends SearchDefinitionTestCase { try { SearchBuilder.buildFromFile("src/test/examples/name-check.sd"); fail("Should throw exception."); - } catch (Exception e) { - e.printStackTrace(); + } catch (Exception expected) { + // Success } } @@ -33,8 +35,7 @@ public class NameFieldCheckTestCase extends SearchDefinitionTestCase { SearchBuilder.buildFromFile("src/test/examples/duplicatenamesinsearchdifferenttype.sd"); fail("Should throw exception."); } catch (Exception e) { - e.printStackTrace(); - assertTrue(e.getMessage().matches(".*Duplicate.*different type.*")); + assertEquals("For search 'duplicatenamesinsearch', field 'grpphotoids64': Incompatible types. Expected Array<long> for index field 'grpphotoids64', got string.", e.getMessage()); } } @@ -44,7 +45,6 @@ public class NameFieldCheckTestCase extends SearchDefinitionTestCase { SearchBuilder.buildFromFile("src/test/examples/duplicatenamesindoc.sd"); fail("Should throw exception."); } catch (Exception e) { - e.printStackTrace(); assertTrue(e.getMessage().matches(".*Duplicate.*")); } } 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 ae3b775f13d..b2968eb4a85 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/RankProfileTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/RankProfileTestCase.java @@ -102,9 +102,9 @@ public class RankProfileTestCase extends SearchDefinitionTestCase { SearchBuilder builder = new SearchBuilder(registry); builder.importString("search test {\n" + " document test { \n" + - " field a type tensor { indexing: attribute \n attribute: tensor(x[10]) }\n" + - " field b type tensor { indexing: attribute \n attribute: tensor(y{}) }\n" + - " field c type tensor { indexing: attribute }\n" + + " field a type tensor(x[]) { indexing: attribute \n attribute: tensor(x[10]) }\n" + + " field b type tensor(y{}) { indexing: attribute \n attribute: tensor(y{}) }\n" + + " field c type tensor(x[]) { indexing: attribute }\n" + " }\n" + " rank-profile p1 {}\n" + " rank-profile p2 {}\n" + @@ -123,7 +123,7 @@ public class RankProfileTestCase extends SearchDefinitionTestCase { RawRankProfile rawProfile = new RawRankProfile(profile, new AttributeFields(search)); assertEquals("tensor(x[10])", findProperty(rawProfile.configProperties(), "vespa.type.attribute.a").get()); assertEquals("tensor(y{})", findProperty(rawProfile.configProperties(), "vespa.type.attribute.b").get()); - assertFalse(findProperty(rawProfile.configProperties(), "vespa.type.attribute.c").isPresent()); + assertEquals("tensor(x[])", findProperty(rawProfile.configProperties(), "vespa.type.attribute.c").get()); } @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 c33ebc95bd2..3236be983d8 100755 --- a/config-model/src/test/java/com/yahoo/searchdefinition/StructTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/StructTestCase.java @@ -10,26 +10,28 @@ import java.io.IOException; import static org.junit.Assert.fail; /** - * tests importing of document containing array type fields + * Tests importing of document containing array type fields * * @author bratseth */ public class StructTestCase extends SearchDefinitionTestCase { + @Test public void testStruct() throws IOException, ParseException { assertConfigFile("src/test/examples/structresult.cfg", - new DocumentmanagerConfig(Deriver.getDocumentManagerConfig("src/test/examples/struct.sd")).toString() + "\n"); + new DocumentmanagerConfig(Deriver.getDocumentManagerConfig("src/test/examples/struct.sd")).toString() + "\n"); } + @Test public void testBadStruct() throws IOException { try { SearchBuilder.buildFromFile("src/test/examples/badstruct.sd"); fail("Should throw exception."); - } catch (ParseException e) { - //ok! - //e.printStackTrace(); + } catch (ParseException expected) { + // success } } + @Test public void testStructAndDocumentWithSameNames() throws IOException, ParseException { try { @@ -41,8 +43,6 @@ public class StructTestCase extends SearchDefinitionTestCase { /** * Declaring a struct before a document will fail, no doc type to add it to. - * @throws IOException - * @throws ParseException */ @Test(expected = IllegalArgumentException.class) public void testStructOutsideDocumentIllegal() throws IOException, ParseException { 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 ecadf8e1b71..0007019e6b4 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 @@ -19,28 +19,28 @@ public class TensorFieldTestCase { 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> {}")); + SearchBuilder.createFromString(getSd("field f1 type array<tensor(x{})> {}")); } @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 { indexing: index }")); + SearchBuilder.createFromString(getSd("field f1 type tensor(x{}) { indexing: index }")); } @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 { indexing: attribute \n attribute: fast-search }")); + SearchBuilder.createFromString(getSd("field f1 type tensor(x{}) { indexing: attribute \n attribute: fast-search }")); } @Test public void requireThatIllegalTensorTypeSpecThrowsException() throws ParseException { exception.expect(IllegalArgumentException.class); exception.expectMessage("For attribute field 'f1': Illegal tensor type spec: Failed parsing element 'invalid' in type spec 'tensor(invalid)'"); - SearchBuilder.createFromString(getSd("field f1 type tensor { indexing: attribute \n attribute: tensor(invalid) }")); + SearchBuilder.createFromString(getSd("field f1 type tensor(x{}) { indexing: attribute \n attribute: tensor(invalid) }")); } private static String getSd(String field) { diff --git a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/SearchDataTypeValidatorTestCase.java b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/SearchDataTypeValidatorTestCase.java index 8c1a288c46d..a8b4065ef38 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/SearchDataTypeValidatorTestCase.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/SearchDataTypeValidatorTestCase.java @@ -8,7 +8,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; /** - * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a> + * @author Simon Thoresen */ public class SearchDataTypeValidatorTestCase { @@ -37,4 +37,5 @@ public class SearchDataTypeValidatorTestCase { "'simple' for cluster 'content').", e.getMessage()); } } + } diff --git a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/search/AttributeChangeValidatorTest.java b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/search/AttributeChangeValidatorTest.java index b3ef8c6d7f2..e43827d7693 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/search/AttributeChangeValidatorTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/search/AttributeChangeValidatorTest.java @@ -9,6 +9,7 @@ import java.util.List; import static com.yahoo.vespa.model.application.validation.change.ConfigChangeTestUtils.newRefeedAction; import static com.yahoo.vespa.model.application.validation.change.ConfigChangeTestUtils.newRestartAction; +import static org.junit.Assert.assertEquals; public class AttributeChangeValidatorTest { @@ -110,8 +111,8 @@ public class AttributeChangeValidatorTest { @Test public void requireThatChangingTensorTypeOfTensorFieldRequiresRefeed() throws Exception { new Fixture( - "field f1 type tensor { indexing: attribute \n attribute: tensor(x[100]) }", - "field f1 type tensor { indexing: attribute \n attribute: tensor(y[]) }") + "field f1 type tensor(x[]) { indexing: attribute \n attribute: tensor(x[100]) }", + "field f1 type tensor(y[]) { indexing: attribute \n attribute: tensor(y[]) }") .assertValidation(newRefeedAction( "tensor-type-change", ValidationOverrides.empty(), @@ -119,10 +120,24 @@ public class AttributeChangeValidatorTest { } @Test - public void requireThatNotChangingTensorTypeOfTensorFieldIsOk() throws Exception { + public void requireThatCompatibleTensorTypeChangeIsOk() throws Exception { new Fixture( - "field f1 type tensor { indexing: attribute \n attribute: tensor(x[104], y[52]) }", - "field f1 type tensor { indexing: attribute \n attribute: tensor(x[104], y[52]) }") + "field f1 type tensor(x[],y[]) { indexing: attribute \n attribute: tensor(x[104], y[52]) }", + "field f1 type tensor(x[200],y[]) { indexing: attribute \n attribute: tensor(x[104], y[52]) }") .assertValidation(); } + + @Test + public void requireIncompatibleTensorTypeChangeIsNotOk() throws Exception { + try { + new Fixture( + "field f1 type tensor(x[],y[]) { indexing: attribute \n attribute: tensor(x[104], y[52]) }", + "field f1 type tensor(x[100],y[]) { indexing: attribute \n attribute: tensor(x[104], y[52]) }") + .assertValidation(); + } + catch (IllegalArgumentException e) { + assertEquals("For search 'test', field 'f1': Incompatible types. Expected tensor(x[100],y[]) for attribute 'f1', got tensor(x[104],y[52]).", e.getMessage()); + } + } + } |