FederationSearcher extends Searcher<FederationSearcherModel> implements FederationConfig.Producer { @Override public void getConfig(FederationConfig.Builder builder) { for (Target target : resolvedTargets.values()) { builder.target(target.getTargetConfig()); } if (targetSelector.isPresent()) { builder.targetSelector(targetSelector.get().getGlobalComponentId().stringValue()); } } FederationSearcher(FederationSearcherModel searcherModel, Optional<Component> targetSelector); @Override void getConfig(FederationConfig.Builder builder); @Override void initialize();  }
@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()); 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()); }