Search in sources :

Example 56 with ComponentId

use of com.yahoo.component.ComponentId in project vespa by vespa-engine.

the class FederationSearcherTest method custom_federation_target.

@Test
public void custom_federation_target() {
    ComponentId targetSelectorId = ComponentId.fromString("TargetSelector");
    ComponentRegistry<TargetSelector> targetSelectors = new ComponentRegistry<>();
    targetSelectors.register(targetSelectorId, new TestTargetSelector());
    FederationSearcher searcher = new FederationSearcher(new FederationConfig(new FederationConfig.Builder().targetSelector(targetSelectorId.toString())), new StrictContractsConfig(new StrictContractsConfig.Builder()), targetSelectors);
    Result result = new Execution(searcher, Context.createContextStub()).search(new Query());
    HitGroup myChainGroup = (HitGroup) result.hits().get(0);
    assertThat(myChainGroup.getId(), is(new URI("source:myChain")));
    assertThat(myChainGroup.get(0).getId(), is(new URI("myHit")));
}
Also used : FederationSearcher(com.yahoo.search.federation.FederationSearcher) Query(com.yahoo.search.Query) URI(com.yahoo.net.URI) Result(com.yahoo.search.Result) StrictContractsConfig(com.yahoo.search.federation.StrictContractsConfig) Execution(com.yahoo.search.searchchain.Execution) ComponentRegistry(com.yahoo.component.provider.ComponentRegistry) TargetSelector(com.yahoo.search.federation.selection.TargetSelector) ComponentId(com.yahoo.component.ComponentId) FederationConfig(com.yahoo.search.federation.FederationConfig) HitGroup(com.yahoo.search.result.HitGroup) Test(org.junit.Test)

Example 57 with ComponentId

use of com.yahoo.component.ComponentId in project vespa by vespa-engine.

the class FederationSearcherTest method target_selectors_can_have_multiple_targets.

@Test
public void target_selectors_can_have_multiple_targets() {
    ComponentId targetSelectorId = ComponentId.fromString("TestMultipleTargetSelector");
    ComponentRegistry<TargetSelector> targetSelectors = new ComponentRegistry<>();
    targetSelectors.register(targetSelectorId, new TestMultipleTargetSelector());
    FederationSearcher searcher = new FederationSearcher(new FederationConfig(new FederationConfig.Builder().targetSelector(targetSelectorId.toString())), new StrictContractsConfig(new StrictContractsConfig.Builder()), targetSelectors);
    Result result = new Execution(searcher, Context.createContextStub()).search(new Query());
    Iterator<Hit> hitsIterator = result.hits().deepIterator();
    Hit hit1 = hitsIterator.next();
    Hit hit2 = hitsIterator.next();
    assertThat(hit1.getSource(), is("chain1"));
    assertThat(hit2.getSource(), is("chain2"));
    assertThat((String) hit1.getField("data"), is("modifyTargetQuery:custom-data:1"));
    assertThat((String) hit2.getField("data"), is("modifyTargetQuery:custom-data:2"));
}
Also used : FederationSearcher(com.yahoo.search.federation.FederationSearcher) Query(com.yahoo.search.Query) Result(com.yahoo.search.Result) StrictContractsConfig(com.yahoo.search.federation.StrictContractsConfig) ErrorHit(com.yahoo.search.result.ErrorHit) Hit(com.yahoo.search.result.Hit) Execution(com.yahoo.search.searchchain.Execution) ComponentRegistry(com.yahoo.component.provider.ComponentRegistry) TargetSelector(com.yahoo.search.federation.selection.TargetSelector) ComponentId(com.yahoo.component.ComponentId) FederationConfig(com.yahoo.search.federation.FederationConfig) Test(org.junit.Test)

Example 58 with ComponentId

use of com.yahoo.component.ComponentId in project vespa by vespa-engine.

the class ClusterSearcherTestCase method testSimple.

public void testSimple() {
    Hit blockingHit = new Hit("blocking");
    Hit nonblockingHit = new Hit("nonblocking");
    BlockingBackendSearcher blockingSearcher = new BlockingBackendSearcher(blockingHit);
    List<Searcher> searchers = new ArrayList<>();
    searchers.add(blockingSearcher);
    searchers.add(new TestingBackendSearcher(nonblockingHit));
    ClusterSearcher<?> provider = new SearcherClusterSearcher(new ComponentId("simple"), searchers, new SimpleHasher<>());
    Result blockingResult = new Execution(provider, Execution.Context.createContextStub()).search(new SimpleQuery(0));
    assertEquals(blockingHit, blockingResult.hits().get(0));
    Result nonblockingResult = new Execution(provider, Execution.Context.createContextStub()).search(new SimpleQuery(1));
    assertEquals(nonblockingHit, nonblockingResult.hits().get(0));
    blockingSearcher.setBlocking(true);
    blockingResult = new Execution(provider, Execution.Context.createContextStub()).search(new SimpleQuery(0));
    assertEquals(blockingResult.hits().get(0), nonblockingHit);
    nonblockingResult = new Execution(provider, Execution.Context.createContextStub()).search(new SimpleQuery(1));
    assertEquals(nonblockingResult.hits().get(0), nonblockingHit);
}
Also used : PingableSearcher(com.yahoo.search.cluster.PingableSearcher) Searcher(com.yahoo.search.Searcher) ClusterSearcher(com.yahoo.search.cluster.ClusterSearcher) ArrayList(java.util.ArrayList) Result(com.yahoo.search.Result) Hit(com.yahoo.search.result.Hit) Execution(com.yahoo.search.searchchain.Execution) ComponentId(com.yahoo.component.ComponentId)

Example 59 with ComponentId

use of com.yahoo.component.ComponentId in project vespa by vespa-engine.

the class AsyncExecutionTestCase method testAsync.

// This should take ~50+ ms
public void testAsync() {
    List<Searcher> searchList = new ArrayList<>();
    searchList.add(new WaitingSearcher("one", 60000));
    searchList.add(new WaitingSearcher("two", 0));
    Chain<Searcher> searchChain = new Chain<>(new ComponentId("chain"), searchList);
    AsyncExecution asyncExecution = new AsyncExecution(searchChain, Execution.Context.createContextStub());
    FutureResult future = asyncExecution.search(new Query("?hits=0"));
    Result result = future.get(0, TimeUnit.MILLISECONDS);
    assertTrue(result.hits().getError() != null);
}
Also used : Chain(com.yahoo.component.chain.Chain) FutureResult(com.yahoo.search.searchchain.FutureResult) Query(com.yahoo.search.Query) AsyncExecution(com.yahoo.search.searchchain.AsyncExecution) Searcher(com.yahoo.search.Searcher) ArrayList(java.util.ArrayList) ComponentId(com.yahoo.component.ComponentId) FutureResult(com.yahoo.search.searchchain.FutureResult) Result(com.yahoo.search.Result)

Example 60 with ComponentId

use of com.yahoo.component.ComponentId in project vespa by vespa-engine.

the class AsyncExecutionTestCase method testWaitForAll.

public void testWaitForAll() {
    Chain<Searcher> slowChain = new Chain<>(new ComponentId("slow"), Arrays.asList(new Searcher[] { new WaitingSearcher("slow", 30000) }));
    Chain<Searcher> fastChain = new Chain<>(new ComponentId("fast"), Arrays.asList(new Searcher[] { new SimpleSearcher() }));
    FutureResult slowFuture = new AsyncExecution(slowChain, Execution.Context.createContextStub()).search(new Query("?hits=0"));
    FutureResult fastFuture = new AsyncExecution(fastChain, Execution.Context.createContextStub()).search(new Query("?hits=0"));
    fastFuture.get();
    FutureResult[] reslist = new FutureResult[] { slowFuture, fastFuture };
    List<Result> results = AsyncExecution.waitForAll(Arrays.asList(reslist), 0);
    // assertTrue(slowFuture.isCancelled());
    assertTrue(fastFuture.isDone() && !fastFuture.isCancelled());
    assertNotNull(results.get(0).hits().getErrorHit());
    assertNull(results.get(1).hits().getErrorHit());
}
Also used : Chain(com.yahoo.component.chain.Chain) FutureResult(com.yahoo.search.searchchain.FutureResult) Query(com.yahoo.search.Query) AsyncExecution(com.yahoo.search.searchchain.AsyncExecution) Searcher(com.yahoo.search.Searcher) ComponentId(com.yahoo.component.ComponentId) FutureResult(com.yahoo.search.searchchain.FutureResult) Result(com.yahoo.search.Result)

Aggregations

ComponentId (com.yahoo.component.ComponentId)68 Test (org.junit.Test)25 Result (com.yahoo.search.Result)14 Query (com.yahoo.search.Query)13 Execution (com.yahoo.search.searchchain.Execution)13 ArrayList (java.util.ArrayList)10 Chain (com.yahoo.component.chain.Chain)8 Searcher (com.yahoo.search.Searcher)8 ComponentRegistry (com.yahoo.component.provider.ComponentRegistry)7 QueryProfileType (com.yahoo.search.query.profile.types.QueryProfileType)7 FederationSearcher (com.yahoo.search.federation.FederationSearcher)6 Hit (com.yahoo.search.result.Hit)6 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 DomBuilderTest (com.yahoo.config.model.builder.xml.test.DomBuilderTest)4 ChainsConfig (com.yahoo.container.core.ChainsConfig)4 FilterChainRepository (com.yahoo.container.http.filter.FilterChainRepository)4 FieldDescription (com.yahoo.search.query.profile.types.FieldDescription)4 QueryProfileTypeRegistry (com.yahoo.search.query.profile.types.QueryProfileTypeRegistry)4 Component (com.yahoo.vespa.model.container.component.Component)4 HashMap (java.util.HashMap)4