diff options
author | Olli Virtanen <olli.virtanen@oath.com> | 2018-05-24 13:51:49 +0200 |
---|---|---|
committer | Olli Virtanen <olli.virtanen@oath.com> | 2018-05-24 13:51:49 +0200 |
commit | 3a1bc7fa8991b033ab0989717c3ef982b5edd769 (patch) | |
tree | dee201ffd4eb7c22279089353862039e6c37022c /config-model | |
parent | 96ebcb01c2719dcf3f267aa2612878b564c7892e (diff) |
Scala code replaced with Java equivalent
Diffstat (limited to 'config-model')
7 files changed, 302 insertions, 336 deletions
diff --git a/config-model/pom.xml b/config-model/pom.xml index 9388608fdcb..bab2f37e667 100644 --- a/config-model/pom.xml +++ b/config-model/pom.xml @@ -276,11 +276,6 @@ <version>${project.version}</version> </dependency> <dependency> - <groupId>org.scalatest</groupId> - <artifactId>scalatest_${scala.major-version}</artifactId> - <scope>test</scope> - </dependency> - <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> </dependency> @@ -300,11 +295,6 @@ <scope>test</scope> </dependency> <dependency> - <groupId>org.scala-lang.modules</groupId> - <artifactId>scala-xml_${scala.major-version}</artifactId> - <scope>test</scope> - </dependency> - <dependency> <groupId>com.google.protobuf</groupId> <artifactId>protobuf-java</artifactId> </dependency> @@ -531,19 +521,6 @@ <updateReleaseInfo>true</updateReleaseInfo> </configuration> </plugin> - <plugin> - <groupId>net.alchim31.maven</groupId> - <artifactId>scala-maven-plugin</artifactId> - <executions> - <execution> - <id>test-compile</id> - <goals> - <goal>testCompile</goal> - </goals> - <phase>test-compile</phase> - </execution> - </executions> - </plugin> </plugins> </build> </project> diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/search/ImplicitIndexingClusterTest.java b/config-model/src/test/java/com/yahoo/vespa/model/container/search/ImplicitIndexingClusterTest.java new file mode 100644 index 00000000000..bc812e12f43 --- /dev/null +++ b/config-model/src/test/java/com/yahoo/vespa/model/container/search/ImplicitIndexingClusterTest.java @@ -0,0 +1,63 @@ +// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.model.container.search; + +import com.yahoo.config.model.deploy.DeployProperties; +import com.yahoo.config.model.deploy.DeployState; +import com.yahoo.config.model.provision.InMemoryProvisioner; +import com.yahoo.config.model.test.MockApplicationPackage; +import com.yahoo.vespa.model.VespaModel; +import com.yahoo.vespa.model.container.ContainerCluster; +import com.yahoo.vespa.model.test.utils.VespaModelCreatorWithMockPkg; +import org.junit.Test; + +import static org.junit.Assert.assertNotNull; + +/** + * @author Tony Vaagenes + * @author ollivir + */ +public class ImplicitIndexingClusterTest { + @Test + public void existing_jdisc_is_used_as_indexing_cluster_when_multitenant() { + final String servicesXml = "<services version=\"1.0\">\n" + // + " <jdisc version=\"1.0\" id=\"jdisc\">\n" + // + " <search />\n" + // + " <nodes count=\"1\" />\n" + // + ACCESS_CONTROL_XML + // + " </jdisc>\n" + // + " <content id=\"music\" version=\"1.0\">\n" + // + " <redundancy>1</redundancy>\n" + // + " <documents>\n" + // + " <document type=\"music\" mode=\"index\" />\n" + // + " </documents>\n" + // + " <nodes count=\"1\" />\n" + // + " </content>\n" + // + "</services>\n"; + + + VespaModel vespaModel = buildMultiTenantVespaModel(servicesXml); + ContainerCluster jdisc = vespaModel.getContainerClusters().get("jdisc"); + assertNotNull("Docproc not added to jdisc", jdisc.getDocproc()); + assertNotNull("Indexing chain not added to jdisc", jdisc.getDocprocChains().allChains().getComponent("indexing")); + } + + private final String ACCESS_CONTROL_XML = "<http>\n" +// + " <filtering>\n" +// + " <access-control domain=\"foo\" />\n" +// + " </filtering>\n" +// + " <server id=\"bar\" port=\"4080\" />\n" +// + "</http>\n"; + + private static VespaModel buildMultiTenantVespaModel(String servicesXml) { + DeployProperties properties = new DeployProperties.Builder().multitenant(true).hostedVespa(true).build(); + DeployState.Builder deployStateBuilder = new DeployState.Builder() + .properties(properties) + .modelHostProvisioner(new InMemoryProvisioner(true, "host1.yahoo.com", "host2.yahoo.com", "host3.yahoo.com")); + + return new VespaModelCreatorWithMockPkg(new MockApplicationPackage.Builder() + .withServices("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + servicesXml) + .withSearchDefinition(MockApplicationPackage.MUSIC_SEARCHDEFINITION) + .build()) + .create(deployStateBuilder); + } +} diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/search/searchchain/FederationSearcherTest.java b/config-model/src/test/java/com/yahoo/vespa/model/container/search/searchchain/FederationSearcherTest.java new file mode 100644 index 00000000000..bc6ff9e9be4 --- /dev/null +++ b/config-model/src/test/java/com/yahoo/vespa/model/container/search/searchchain/FederationSearcherTest.java @@ -0,0 +1,180 @@ +// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.model.container.search.searchchain; + +import com.yahoo.component.ComponentId; +import com.yahoo.component.ComponentSpecification; +import com.yahoo.component.chain.dependencies.Dependencies; +import com.yahoo.component.chain.model.ChainSpecification; +import com.yahoo.component.provider.ComponentRegistry; +import com.yahoo.search.federation.FederationConfig; +import com.yahoo.search.searchchain.model.federation.FederationOptions; +import com.yahoo.search.searchchain.model.federation.FederationSearcherModel; +import com.yahoo.search.searchchain.model.federation.FederationSearcherModel.TargetSpec; +import com.yahoo.vespa.model.ConfigProducer; +import com.yahoo.vespa.model.container.search.searchchain.Source.GroupOption; +import org.junit.Assert; +import org.junit.Test; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; + +import static java.util.Collections.emptyList; +import static java.util.Collections.emptySet; +import static java.util.Collections.singletonList; +import static java.util.stream.Collectors.toList; +import static org.hamcrest.Matchers.contains; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + +/** + * @author Tony Vaagenes + * @author ollivir + */ +public class FederationSearcherTest { + + private static class FederationFixture { + FederationSearcher federationSearchWithDefaultSources = newFederationSearcher(true, emptyList()); + private ComponentRegistry<SearchChain> searchChainRegistry = new ComponentRegistry<>(); + private SourceGroupRegistry sourceGroupRegistry = new SourceGroupRegistry(); + + void initializeFederationSearcher(FederationSearcher searcher) { + searcher.initialize(searchChainRegistry, sourceGroupRegistry); + } + + void registerProviderWithSources(Provider provider) { + List<GenericTarget> sources = new ArrayList<>(); + sources.add(provider); + sources.addAll(provider.getSources()); + for (GenericTarget gt : sources) { + searchChainRegistry.register(gt.getId(), gt); + } + sourceGroupRegistry.addSources(provider); + } + } + + private static class ProvidersWithSourceFixture extends FederationFixture { + Provider provider1 = createProvider(ComponentId.fromString("provider1")); + Provider provider2 = createProvider(ComponentId.fromString("provider2")); + + private ProvidersWithSourceFixture() { + super(); + provider1.addSource(createSource(ComponentId.fromString("source"), GroupOption.leader)); + provider2.addSource(createSource(ComponentId.fromString("source"), GroupOption.participant)); + + registerProviderWithSources(provider1); + registerProviderWithSources(provider2); + initializeFederationSearcher(federationSearchWithDefaultSources); + } + } + + @Test + public void default_providers_are_inherited_when_inheritDefaultSources_is_true() throws Exception { + FederationFixture f = new FederationFixture(); + + final String providerId = "providerId"; + + f.registerProviderWithSources(createProvider(ComponentId.fromString(providerId))); + f.initializeFederationSearcher(f.federationSearchWithDefaultSources); + + FederationConfig federationConfig = getConfig(f.federationSearchWithDefaultSources); + FederationConfig.Target target = federationConfig.target(0); + + assertSame(providerId, target.id()); // by identity + assertTrue("Not used by default", target.searchChain(0).useByDefault()); + } + + @Test + public void source_groups_are_inherited_when_inheritDefaultSources_is_true() throws Exception { + FederationFixture f = new ProvidersWithSourceFixture(); + + FederationConfig federationConfig = getConfig(f.federationSearchWithDefaultSources); + Assert.assertEquals(1, federationConfig.target().size()); + + FederationConfig.Target target = federationConfig.target(0); + assertEquals(target.id(), "source"); + assertTrue("Not used by default", target.useByDefault()); + assertEquals(2, target.searchChain().size()); + assertThat(target.searchChain().stream().map(FederationConfig.Target.SearchChain::providerId).collect(toList()), + contains("provider1", "provider2")); + } + + @Test + public void source_groups_are_not_inherited_when_inheritDefaultSources_is_false() throws Exception { + FederationFixture f = new ProvidersWithSourceFixture(); + + FederationSearcher federationSearcherWithoutDefaultSources = newFederationSearcher(false, emptyList()); + f.initializeFederationSearcher(federationSearcherWithoutDefaultSources); + + FederationConfig federationConfig = getConfig(federationSearcherWithoutDefaultSources); + assertEquals(0, federationConfig.target().size()); + } + + @Test + public void leaders_must_be_the_first_search_chain_in_a_target() throws Exception { + FederationFixture f = new ProvidersWithSourceFixture(); + + FederationConfig federationConfig = getConfig(f.federationSearchWithDefaultSources); + List<FederationConfig.Target.SearchChain> searchChain = federationConfig.target(0).searchChain(); + + assertEquals("provider1", searchChain.get(0).providerId()); + assertEquals("provider2", searchChain.get(1).providerId()); + } + + @Test + public void manually_specified_targets_overrides_inherited_targets() throws Exception { + FederationFixture f = new FederationFixture(); + + f.registerProviderWithSources(createProvider(ComponentId.fromString("provider1"))); + FederationSearcher federation = newFederationSearcher(true, + singletonList(new TargetSpec(ComponentSpecification.fromString("provider1"), + new FederationOptions().setTimeoutInMilliseconds(12345)))); + f.initializeFederationSearcher(federation); + + FederationConfig federationConfig = getConfig(federation); + assertEquals(1, federationConfig.target().size()); + + FederationConfig.Target target = federationConfig.target(0); + assertEquals(1, target.searchChain().size()); + + FederationConfig.Target.SearchChain searchChain = target.searchChain(0); + assertEquals(12345, searchChain.timeoutMillis()); + } + + private static FederationSearcher newFederationSearcher(boolean inheritDefaultSources, List<TargetSpec> targets) { + return new FederationSearcher(new FederationSearcherModel(ComponentSpecification.fromString("federation"), + Dependencies.emptyDependencies(), targets, inheritDefaultSources), Optional.empty()); + } + + private static ChainSpecification searchChainSpecification(ComponentId id) { + return new ChainSpecification(id, new ChainSpecification.Inheritance(null, null), emptyList(), emptySet()); + } + + private static Provider createProvider(ComponentId id) { + return new Provider(searchChainSpecification(id), new FederationOptions()); + } + + private static Source createSource(ComponentId id, GroupOption groupOption) { + return new Source(searchChainSpecification(id), new FederationOptions(), groupOption); + } + + private static FederationConfig getConfig(ConfigProducer configProducer) throws Exception { + Optional<Class<?>> builderClassOpt = Arrays.stream(FederationConfig.class.getDeclaredClasses()) + .filter(c -> c.getSimpleName().equals("Builder")).findFirst(); + if (builderClassOpt.isPresent() == false) { + throw new RuntimeException("No Builder class in ConfigInstance."); + } + Class<?> builderClass = builderClassOpt.get(); + + Object builder = builderClass.getDeclaredConstructor().newInstance(); + Method getConfigMethod = configProducer.getClass().getMethod("getConfig", builderClass); + + getConfigMethod.invoke(configProducer, builder); + + return FederationConfig.class.getConstructor(builderClass).newInstance(builder); + } +} diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/BundleInstantiationSpecificationBuilderTest.java b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/BundleInstantiationSpecificationBuilderTest.java new file mode 100644 index 00000000000..c58f3308ced --- /dev/null +++ b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/BundleInstantiationSpecificationBuilderTest.java @@ -0,0 +1,59 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.model.container.xml; + +import com.yahoo.component.ComponentSpecification; +import com.yahoo.config.model.builder.xml.XmlHelper; +import com.yahoo.container.bundle.BundleInstantiationSpecification; +import com.yahoo.search.grouping.GroupingValidator; +import org.apache.commons.io.IOUtils; +import org.junit.Test; +import org.w3c.dom.Element; +import org.xml.sax.SAXException; + +import java.io.IOException; +import java.io.InputStream; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +/** + * @author gjoranv + * @author ollivir + */ + +public class BundleInstantiationSpecificationBuilderTest { + + @Test + public void bundle_is_not_replaced_for_user_defined_class() throws IOException, SAXException { + final String userDefinedClass = "my own class that will also be set as bundle"; + verifyExpectedBundle(userDefinedClass, null, userDefinedClass); + } + + @Test + public void bundle_is_replaced_for_internal_class() throws IOException, SAXException { + String internalClass = GroupingValidator.class.getName(); + verifyExpectedBundle(internalClass, null, BundleMapper.searchAndDocprocBundle); + } + + @Test + public void bundle_is_not_replaced_for_internal_class_with_explicitly_set_bundle() + throws IOException, SAXException { + String internalClass = GroupingValidator.class.getName(); + String explicitBundle = "my-own-implementation"; + verifyExpectedBundle(internalClass, explicitBundle, explicitBundle); + } + + private static void verifyExpectedBundle(String className, String explicitBundle, String expectedBundle) + throws IOException, SAXException { + String xml = "<component id=\"_\" class=\"" + className + "\""; + if (explicitBundle != null) { + xml += " bundle=\"" + explicitBundle + "\""; + } + xml += " />"; + InputStream xmlStream = IOUtils.toInputStream(xml); + Element component = XmlHelper.getDocumentBuilder().parse(xmlStream).getDocumentElement(); + + BundleInstantiationSpecification spec = BundleInstantiationSpecificationBuilder.build(component, false); + assertThat(spec.bundle, is(ComponentSpecification.fromString(expectedBundle))); + } +} diff --git a/config-model/src/test/scala/com/yahoo/vespa/model/container/search/ImplicitIndexingClusterTest.scala b/config-model/src/test/scala/com/yahoo/vespa/model/container/search/ImplicitIndexingClusterTest.scala deleted file mode 100644 index 4ebe14c1e85..00000000000 --- a/config-model/src/test/scala/com/yahoo/vespa/model/container/search/ImplicitIndexingClusterTest.scala +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.model.container.search - -import com.yahoo.config.model.provision.InMemoryProvisioner -import com.yahoo.config.model.test.MockApplicationPackage -import com.yahoo.vespa.model.test.utils.VespaModelCreatorWithMockPkg -import org.junit.Test - -import org.junit.Assert.assertNotNull -import scala.xml.{XML, Elem} -import java.io.StringWriter -import com.yahoo.config.model.deploy.{DeployProperties, DeployState} - -/** - * @author tonytv - */ -class ImplicitIndexingClusterTest { - @Test - def existing_jdisc_is_used_as_indexing_cluster_when_multitenant() { - val servicesXml = - <services version="1.0"> - <jdisc version="1.0" id="jdisc"> - <search /> - <nodes count="1" /> - {accessControlXml} - </jdisc> - <content id="music" version="1.0"> - <redundancy>1</redundancy> - <documents> - <document type="music" mode="index" /> - </documents> - <nodes count="1" /> - </content> - </services> - - - val vespaModel = buildMultiTenantVespaModel(servicesXml) - val jdisc = vespaModel.getContainerClusters.get("jdisc") - assertNotNull("Docproc not added to jdisc", jdisc.getDocproc) - assertNotNull("Indexing chain not added to jdisc", jdisc.getDocprocChains.allChains().getComponent("indexing")) - } - - private val accessControlXml = - <http> - <filtering> - <access-control domain="foo" /> - </filtering> - <server id="bar" port="4080" /> - </http> - - - def buildMultiTenantVespaModel(servicesXml: Elem) = { - val properties = new DeployProperties.Builder().multitenant(true).hostedVespa(true).build() - val deployStateBuilder = new DeployState.Builder() - .properties(properties) - .modelHostProvisioner(new InMemoryProvisioner(true, "host1.yahoo.com", "host2.yahoo.com", "host3.yahoo.com")) - - val writer = new StringWriter - XML.write(writer, servicesXml, "UTF-8", xmlDecl = true, doctype = null) - writer.close() - - new VespaModelCreatorWithMockPkg(new MockApplicationPackage.Builder() - .withServices(writer.toString) - .withSearchDefinition(MockApplicationPackage.MUSIC_SEARCHDEFINITION) - .build()) - .create(deployStateBuilder) - } -} diff --git a/config-model/src/test/scala/com/yahoo/vespa/model/container/search/searchchain/FederationSearcherTest.scala b/config-model/src/test/scala/com/yahoo/vespa/model/container/search/searchchain/FederationSearcherTest.scala deleted file mode 100644 index a1eeb297367..00000000000 --- a/config-model/src/test/scala/com/yahoo/vespa/model/container/search/searchchain/FederationSearcherTest.scala +++ /dev/null @@ -1,183 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.model.container.search.searchchain - -import java.util.Collections.{emptyList, emptySet} -import java.util.Optional - -import com.yahoo.component.chain.dependencies.Dependencies -import com.yahoo.component.chain.model.ChainSpecification -import com.yahoo.component.provider.ComponentRegistry -import com.yahoo.component.{ComponentId, ComponentSpecification} -import com.yahoo.config.ConfigInstance -import com.yahoo.search.federation.FederationConfig -import com.yahoo.search.searchchain.model.federation.FederationSearcherModel.TargetSpec -import com.yahoo.search.searchchain.model.federation.{FederationOptions, FederationSearcherModel} -import com.yahoo.vespa.model.ConfigProducer -import com.yahoo.vespa.model.container.search.searchchain.FederationSearcherTest._ -import com.yahoo.vespa.model.container.search.searchchain.Source.GroupOption -import org.junit.runner.RunWith -import org.scalatest.FunSuite -import org.scalatest.junit.JUnitRunner - -import scala.collection.JavaConverters._ -import scala.collection.breakOut -import scala.language.implicitConversions -import scala.reflect.ClassTag - -/** - * @author tonytv - */ -@RunWith(classOf[JUnitRunner]) -class FederationSearcherTest extends FunSuite{ - - class FederationFixture { - val federationSearchWithDefaultSources = newFederationSearcher(inheritDefaultSources = true) - val searchChainRegistry = new ComponentRegistry[SearchChain] - val sourceGroupRegistry = new SourceGroupRegistry - - def initializeFederationSearcher(searcher: FederationSearcher = federationSearchWithDefaultSources) { - searcher.initialize(searchChainRegistry, sourceGroupRegistry) - } - - def registerProviderWithSources(provider: Provider) = { - provider :: provider.getSources.asScala.toList foreach { chain => searchChainRegistry.register(chain.getId, chain) } - sourceGroupRegistry.addSources(provider) - } - } - - class ProvidersWithSourceFixture extends FederationFixture { - val provider1 = createProvider("provider1") - val provider2 = createProvider("provider2") - - provider1.addSource(createSource("source", GroupOption.leader)) - provider2.addSource(createSource("source", GroupOption.participant)) - - registerProviderWithSources(provider1) - registerProviderWithSources(provider2) - initializeFederationSearcher() - } - - test("default providers are inherited when inheritDefaultSources=true") { - val f = new FederationFixture - import f._ - - val providerId = "providerId" - - registerProviderWithSources(createProvider(providerId)) - initializeFederationSearcher() - - val federationConfig = getConfig[FederationConfig](federationSearchWithDefaultSources) - val target = federationConfig.target(0) - - assert( providerId === target.id() ) - assert( target.searchChain(0).useByDefault(), "Not used by default" ) - } - - def toMapByKey[KEY, VALUE](collection: java.util.Collection[VALUE])(f: VALUE => KEY): Map[KEY, VALUE] = - collection.asScala.map(e => (f(e), e))(breakOut) - - test("source groups are inherited when inheritDefaultSources=true") { - val f = new ProvidersWithSourceFixture - import f._ - - val federationConfig = getConfig[FederationConfig](federationSearchWithDefaultSources) - assert(federationConfig.target().size == 1) - - val target = federationConfig.target(0) - assert(target.id() == "source") - assert(target.useByDefault(), "Not used by default") - - //val chainsByProviderId = toMapByKey(target.searchChain())(_.providerId()) - - assert(Set("provider1", "provider2") === target.searchChain().asScala.map(_.providerId()).toSet) - } - - test("source groups are not inherited when inheritDefaultSources=false") { - val f = new ProvidersWithSourceFixture - import f._ - - val federationSearcherWithoutDefaultSources = newFederationSearcher(inheritDefaultSources = false) - initializeFederationSearcher(federationSearcherWithoutDefaultSources) - - val federationConfig = getConfig[FederationConfig](federationSearcherWithoutDefaultSources) - assert(federationConfig.target().size == 0) - } - - test("leaders must be the first search chain in a target") { - val f = new ProvidersWithSourceFixture - import f._ - - val federationConfig = getConfig[FederationConfig](federationSearchWithDefaultSources) - val searchChain = federationConfig.target(0).searchChain - - assert(searchChain.get(0).providerId() === "provider1") - assert(searchChain.get(1).providerId() === "provider2") - - } - - test("manually specified targets overrides inherited targets") { - val f = new FederationFixture - import f._ - - registerProviderWithSources(createProvider("provider1")) - val federation = newFederationSearcher(inheritDefaultSources = true, - targets = List(new TargetSpec("provider1", new FederationOptions().setTimeoutInMilliseconds(12345))).asJava) - - initializeFederationSearcher(federation) - - val federationConfig = getConfig[FederationConfig](federation) - - assert(federationConfig.target().size === 1) - val target = federationConfig.target(0) - - assert(target.searchChain().size === 1) - val searchChain = target.searchChain(0) - - assert(searchChain.timeoutMillis() === 12345) - } - - - def newFederationSearcher(inheritDefaultSources: Boolean, - targets: java.util.List[TargetSpec] = emptyList()): FederationSearcher = { - new FederationSearcher( - new FederationSearcherModel("federation", - Dependencies.emptyDependencies(), - targets, - inheritDefaultSources), - Optional.empty()) - } -} - -object FederationSearcherTest { - implicit def toComponentId(name: String): ComponentId = ComponentId.fromString(name) - implicit def toComponentSpecification(name: String): ComponentSpecification = ComponentSpecification.fromString(name) - - def newBuilder[T <: ConfigInstance.Builder](implicit c: ClassTag[T]): T = { - c.runtimeClass.getDeclaredConstructor().newInstance().asInstanceOf[T] - } - - def searchChainSpecification(id: ComponentId) = - new ChainSpecification(id, new ChainSpecification.Inheritance(null, null), emptyList(), emptySet()) - - def createProvider(id: ComponentId) = - new Provider(searchChainSpecification(id), new FederationOptions()) - - def createSource(id: ComponentId, groupOption: GroupOption) = - new Source(searchChainSpecification(id), new FederationOptions(), groupOption) - - - //TODO: TVT: move - def getConfig[T <: ConfigInstance : ClassTag](configProducer: ConfigProducer): T = { - val configClass = implicitly[ClassTag[T]].runtimeClass - val builderClass = configClass.getDeclaredClasses.collectFirst {case c if c.getSimpleName == "Builder" => c } getOrElse { - sys.error("No Builder class in ConfigInstance.") - } - - val builder = builderClass.getDeclaredConstructor().newInstance().asInstanceOf[AnyRef] - val getConfigMethod = configProducer.getClass.getMethod("getConfig", builderClass) - - getConfigMethod.invoke(configProducer, builder) - - configClass.getConstructor(builderClass).newInstance(builder).asInstanceOf[T] - } -} diff --git a/config-model/src/test/scala/com/yahoo/vespa/model/container/xml/BundleInstantiationSpecificationBuilderTest.scala b/config-model/src/test/scala/com/yahoo/vespa/model/container/xml/BundleInstantiationSpecificationBuilderTest.scala deleted file mode 100644 index 1f849f91c2e..00000000000 --- a/config-model/src/test/scala/com/yahoo/vespa/model/container/xml/BundleInstantiationSpecificationBuilderTest.scala +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.model.container.xml - -import com.yahoo.component.ComponentSpecification -import com.yahoo.search.grouping.GroupingValidator - -import scala.language.implicitConversions -import BundleInstantiationSpecificationBuilderTest._ -import com.yahoo.config.model.builder.xml.test.DomBuilderTest -import org.hamcrest.CoreMatchers._ -import org.junit.Assert._ -import org.junit.Test -import org.w3c.dom.Element - -import scala.xml.Elem - -/** - * @author gjoranv - * @since 5.45 - */ - -class BundleInstantiationSpecificationBuilderTest { - - @Test - def bundle_is_not_replaced_for_user_defined_class() { - val userDefinedClass = "my own class that will also be set as bundle" - verifyExpectedBundle(userDefinedClass, - expectedBundle = userDefinedClass) - } - - @Test - def bundle_is_replaced_for_internal_class() = { - val internalClass = classOf[GroupingValidator].getName - verifyExpectedBundle(internalClass, - expectedBundle = BundleMapper.searchAndDocprocBundle) - } - - @Test - def bundle_is_not_replaced_for_internal_class_with_explicitly_set_bundle() = { - val internalClass = classOf[GroupingValidator].getName - val explicitBundle = "my-own-implementation" - verifyExpectedBundle(internalClass, - explicitBundle = Some(explicitBundle), - expectedBundle = explicitBundle) - } -} - -object BundleInstantiationSpecificationBuilderTest { - - def verifyExpectedBundle(className: String, - explicitBundle: Option[String] = None, - expectedBundle:String) = { - val xml = <component id="_" class={className} bundle={explicitBundle.orNull} /> - - val spec = BundleInstantiationSpecificationBuilder.build(xml, false) - assertThat(spec.bundle, is(ComponentSpecification.fromString(expectedBundle))) - } - - implicit def toDomElement(elem: Elem): Element = { - DomBuilderTest.parse(elem.toString()) - } -} |