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")));
}
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"));
}
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);
}
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);
}
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());
}
Aggregations