diff options
author | Geir Storli <geirst@oath.com> | 2017-12-13 14:04:21 +0100 |
---|---|---|
committer | Geir Storli <geirst@oath.com> | 2017-12-13 14:05:06 +0100 |
commit | f3e55bba1a7862223d3bc1e5d4852c02e9be0480 (patch) | |
tree | 9d940853231a29283078892d23b188009a1884ab /config-model | |
parent | d0a2b2f3aec7286e8504278f52135f737b106a3b (diff) |
Add common representation of doc type used for testing.
Diffstat (limited to 'config-model')
4 files changed, 76 insertions, 76 deletions
diff --git a/config-model/src/test/java/com/yahoo/vespa/model/content/ContentSearchClusterTest.java b/config-model/src/test/java/com/yahoo/vespa/model/content/ContentSearchClusterTest.java index 5f18b28d6ce..ee4fa5c1725 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/content/ContentSearchClusterTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/content/ContentSearchClusterTest.java @@ -4,6 +4,7 @@ package com.yahoo.vespa.model.content; import com.yahoo.vespa.config.search.core.ProtonConfig; import com.yahoo.vespa.model.content.cluster.ContentCluster; import com.yahoo.vespa.model.content.utils.ContentClusterBuilder; +import com.yahoo.vespa.model.content.utils.DocType; import com.yahoo.vespa.model.content.utils.SearchDefinitionBuilder; import org.junit.Test; @@ -36,8 +37,8 @@ public class ContentSearchClusterTest { private static ContentCluster createClusterWithGlobalType() throws Exception { return createCluster(new ContentClusterBuilder().docTypes(Arrays.asList( - new ContentClusterBuilder.DocType("global", true), - new ContentClusterBuilder.DocType("regular"))).getXml(), + DocType.indexGlobal("global"), + DocType.index("regular"))).getXml(), createSearchDefinitions("global", "regular")); } @@ -108,9 +109,9 @@ public class ContentSearchClusterTest { .content("field ref_to_c type reference<c> { indexing: attribute }").build()); searchDefinitions.add(new SearchDefinitionBuilder().name("c").build()); return createCluster(new ContentClusterBuilder().docTypes(Arrays.asList( - new ContentClusterBuilder.DocType("a"), - new ContentClusterBuilder.DocType("b", true), - new ContentClusterBuilder.DocType("c", true))).getXml(), + DocType.index("a"), + DocType.indexGlobal("b"), + DocType.indexGlobal("c"))).getXml(), searchDefinitions); } diff --git a/config-model/src/test/java/com/yahoo/vespa/model/content/DistributorTest.java b/config-model/src/test/java/com/yahoo/vespa/model/content/DistributorTest.java index d4e804d3f95..30fe336a932 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/content/DistributorTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/content/DistributorTest.java @@ -8,12 +8,11 @@ import com.yahoo.vespa.config.content.core.StorServerConfig; import com.yahoo.config.model.test.MockRoot; import com.yahoo.vespa.model.content.cluster.ContentCluster; import com.yahoo.vespa.model.content.utils.ContentClusterUtils; +import com.yahoo.vespa.model.content.utils.DocType; import com.yahoo.vespa.model.test.utils.ApplicationPackageUtils; import org.junit.Test; -import java.util.Arrays; import java.util.List; -import java.util.stream.Collectors; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; @@ -303,80 +302,47 @@ public class DistributorTest { return new StorDistributormanagerConfig(builder); } - private static class DocDef { - public final String type; - public final String mode; - public final boolean global; - - private DocDef(String type, String mode, boolean global) { - this.type = type; - this.mode = mode; - this.global = global; - } - - public static DocDef storeOnly(String type) { - return new DocDef(type, "store-only", false); - } - - public static DocDef index(String type) { - return new DocDef(type, "index", false); - } - - public static DocDef indexGlobal(String type) { - return new DocDef(type, "index", true); - } - - public static DocDef streaming(String type) { - return new DocDef(type, "streaming", false); - } - } - - private String generateXmlForDocDefs(DocDef... defs) { + private String generateXmlForDocTypes(DocType... docTypes) { return "<content id='storage'>\n" + - " <documents>\n" + - Arrays.stream(defs) - .map(def -> String.format(" <document type='%s' mode='%s' global='%s'/>", - def.type, def.mode, (def.global ? "true" : "false"))) - .collect(Collectors.joining("\n")) + - "\n </documents>\n" + - "</content>"; + DocType.listToXml(docTypes) + + "\n</content>"; } @Test public void bucket_activation_disabled_if_no_documents_in_indexed_mode() { StorDistributormanagerConfig config = clusterXmlToConfig( - generateXmlForDocDefs(DocDef.storeOnly("music"))); + generateXmlForDocTypes(DocType.storeOnly("music"))); assertThat(config.disable_bucket_activation(), is(true)); } @Test public void bucket_activation_enabled_with_single_indexed_document() { StorDistributormanagerConfig config = clusterXmlToConfig( - generateXmlForDocDefs(DocDef.index("music"))); + generateXmlForDocTypes(DocType.index("music"))); assertThat(config.disable_bucket_activation(), is(false)); } @Test public void bucket_activation_enabled_with_multiple_indexed_documents() { StorDistributormanagerConfig config = clusterXmlToConfig( - generateXmlForDocDefs(DocDef.index("music"), - DocDef.index("movies"))); + generateXmlForDocTypes(DocType.index("music"), + DocType.index("movies"))); assertThat(config.disable_bucket_activation(), is(false)); } @Test public void bucket_activation_enabled_if_at_least_one_document_indexed() { StorDistributormanagerConfig config = clusterXmlToConfig( - generateXmlForDocDefs(DocDef.storeOnly("music"), - DocDef.streaming("bunnies"), - DocDef.index("movies"))); + generateXmlForDocTypes(DocType.storeOnly("music"), + DocType.streaming("bunnies"), + DocType.index("movies"))); assertThat(config.disable_bucket_activation(), is(false)); } @Test public void bucket_activation_disabled_for_single_streaming_type() { StorDistributormanagerConfig config = clusterXmlToConfig( - generateXmlForDocDefs(DocDef.streaming("music"))); + generateXmlForDocTypes(DocType.streaming("music"))); assertThat(config.disable_bucket_activation(), is(true)); } @@ -394,7 +360,7 @@ public class DistributorTest { @Test public void bucket_spaces_config_is_produced_for_distributor_cluster() { BucketspacesConfig config = clusterXmlToBucketspacesConfig( - generateXmlForDocDefs(DocDef.index("music"), DocDef.indexGlobal("movies"))); + generateXmlForDocTypes(DocType.index("music"), DocType.indexGlobal("movies"))); assertEquals(2, config.documenttype().size()); assertDocumentType("movies", "global", config.documenttype(0)); assertDocumentType("music", "default", config.documenttype(1)); diff --git a/config-model/src/test/java/com/yahoo/vespa/model/content/utils/ContentClusterBuilder.java b/config-model/src/test/java/com/yahoo/vespa/model/content/utils/ContentClusterBuilder.java index 592e90efd22..95c57bb544c 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/content/utils/ContentClusterBuilder.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/content/utils/ContentClusterBuilder.java @@ -18,29 +18,10 @@ import static com.yahoo.config.model.test.TestUtil.joinLines; */ public class ContentClusterBuilder { - public static class DocType { - private final String name; - private final boolean global; - - public DocType(String name, boolean global) { - this.name = name; - this.global = global; - } - - public DocType(String name) { - this(name, false); - } - - public String toXml() { - return (global ? "<document mode='index' type='" + name + "' global='true'/>" : - "<document mode='index' type='" + name + "'/>"); - } - } - private String name = "mycluster"; private int redundancy = 1; private int searchableCopies = 1; - private List<DocType> docTypes = Arrays.asList(new DocType("test")); + private List<DocType> docTypes = Arrays.asList(DocType.index("test")); private String groupXml = getSimpleGroupXml(); private Optional<String> dispatchXml = Optional.empty(); private Optional<Double> protonDiskLimit = Optional.empty(); @@ -66,7 +47,7 @@ public class ContentClusterBuilder { public ContentClusterBuilder docTypes(String ... docTypes) { this.docTypes = Arrays.asList(docTypes).stream(). - map(type -> new DocType(type)). + map(type -> DocType.index(type)). collect(Collectors.toList()); return this; } @@ -103,9 +84,7 @@ public class ContentClusterBuilder { public String getXml() { String xml = joinLines("<content version='1.0' id='" + name + "'>", " <redundancy>" + redundancy + "</redundancy>", - " <documents>", - docTypes.stream().map(DocType::toXml).collect(Collectors.joining("\n")), - " </documents>", + DocType.listToXml(docTypes), " <engine>", " <proton>", " <searchable-copies>" + searchableCopies + "</searchable-copies>", diff --git a/config-model/src/test/java/com/yahoo/vespa/model/content/utils/DocType.java b/config-model/src/test/java/com/yahoo/vespa/model/content/utils/DocType.java new file mode 100644 index 00000000000..3a5f679509b --- /dev/null +++ b/config-model/src/test/java/com/yahoo/vespa/model/content/utils/DocType.java @@ -0,0 +1,54 @@ +package com.yahoo.vespa.model.content.utils; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +/** + * Definition of a document type used for testing. + * + * @author geirst + */ +public class DocType { + private final String type; + private final String mode; + private final boolean global; + + private DocType(String type, String mode, boolean global) { + this.type = type; + this.mode = mode; + this.global = global; + } + + public String toXml() { + return (global ? "<document mode='" + mode + "' type='" + type + "' global='true'/>" : + "<document mode='" + mode + "' type='" + type + "'/>"); + } + + public static DocType storeOnly(String type) { + return new DocType(type, "store-only", false); + } + + public static DocType index(String type) { + return new DocType(type, "index", false); + } + + public static DocType indexGlobal(String type) { + return new DocType(type, "index", true); + } + + public static DocType streaming(String type) { + return new DocType(type, "streaming", false); + } + + public static String listToXml(DocType... docTypes) { + return listToXml(Arrays.asList(docTypes)); + } + + public static String listToXml(List<DocType> docTypes) { + return "<documents>\n" + + docTypes.stream().map(DocType::toXml).collect(Collectors.joining("\n")) + "\n" + + "</documents>"; + } + +} |