use of com.yahoo.search.searchchain.Execution in project vespa by vespa-engine.
the class FutureDataTestCase method testAsyncFederation.
@Test
public void testAsyncFederation() throws InterruptedException, ExecutionException, TimeoutException {
// Setup environment
AsyncProviderSearcher asyncProviderSearcher = new AsyncProviderSearcher();
Searcher syncProviderSearcher = new SyncProviderSearcher();
Chain<Searcher> asyncSource = new Chain<Searcher>(new ComponentId("async"), asyncProviderSearcher);
Chain<Searcher> syncSource = new Chain<>(new ComponentId("sync"), syncProviderSearcher);
SearchChainResolver searchChainResolver = new SearchChainResolver.Builder().addSearchChain(new ComponentId("sync"), new FederationOptions().setUseByDefault(true)).addSearchChain(new ComponentId("async"), new FederationOptions().setUseByDefault(true)).build();
Chain<Searcher> main = new Chain<Searcher>(new FederationSearcher(new ComponentId("federator"), searchChainResolver));
SearchChainRegistry searchChainRegistry = new SearchChainRegistry();
searchChainRegistry.register(main);
searchChainRegistry.register(syncSource);
searchChainRegistry.register(asyncSource);
Result result = new Execution(main, Execution.Context.createContextStub(searchChainRegistry, null)).search(new Query());
assertNotNull(result);
HitGroup syncGroup = (HitGroup) result.hits().get("source:sync");
assertNotNull(syncGroup);
HitGroup asyncGroup = (HitGroup) result.hits().get("source:async");
assertNotNull(asyncGroup);
assertEquals("Got all sync data", 3, syncGroup.size());
assertEquals("sync:0", syncGroup.get(0).getId().toString());
assertEquals("sync:1", syncGroup.get(1).getId().toString());
assertEquals("sync:2", syncGroup.get(2).getId().toString());
assertTrue(asyncGroup.incoming() == asyncProviderSearcher.incomingData);
assertEquals("Got no async data yet", 0, asyncGroup.size());
asyncProviderSearcher.simulateOneHitIOComplete(new Hit("async:0"));
assertEquals("Got no async data yet, as we haven't completed the incoming buffer and there is no data listener", 0, asyncGroup.size());
asyncProviderSearcher.simulateOneHitIOComplete(new Hit("async:1"));
asyncProviderSearcher.simulateAllHitsIOComplete();
assertEquals("Got no async data yet, as we haven't pulled it", 0, asyncGroup.size());
asyncGroup.complete().get();
assertEquals("Completed, so we have the data", 2, asyncGroup.size());
assertEquals("async:0", asyncGroup.get(0).getId().toString());
assertEquals("async:1", asyncGroup.get(1).getId().toString());
}
use of com.yahoo.search.searchchain.Execution in project vespa by vespa-engine.
the class VespaAsyncSearcherTest method testAsyncExecution.
public void testAsyncExecution() {
Chain<Searcher> chain = new Chain<>(new FirstSearcher(), new SecondSearcher());
Execution execution = new Execution(chain, Execution.Context.createContextStub(null));
Query query = new Query();
// fails with exception on old versions
execution.search(query);
}
use of com.yahoo.search.searchchain.Execution in project vespa by vespa-engine.
the class ConnectionControlSearcherTestCase method doSearch.
private Result doSearch(URI uri, long connectedAtMillis, long nowMillis) {
SocketAddress remoteAddress = Mockito.mock(SocketAddress.class);
Version version = Version.HTTP_1_1;
Method method = Method.GET;
CurrentContainer container = Mockito.mock(CurrentContainer.class);
Mockito.when(container.newReference(Mockito.any())).thenReturn(Mockito.mock(Container.class));
final com.yahoo.jdisc.http.HttpRequest serverRequest = com.yahoo.jdisc.http.HttpRequest.newServerRequest(container, uri, method, version, remoteAddress, connectedAtMillis);
HttpRequest incoming = new HttpRequest(serverRequest, new ByteArrayInputStream(new byte[0]));
Query query = new Query(incoming);
Execution e = new Execution(new Chain<Searcher>(ConnectionControlSearcher.createTestInstance(() -> nowMillis)), Execution.Context.createContextStub());
Result r = e.search(query);
return r;
}
use of com.yahoo.search.searchchain.Execution in project vespa by vespa-engine.
the class LowercasingTestCase method testDisableLowercasingWeightedSet.
@Test
public void testDisableLowercasingWeightedSet() {
execution = new Execution(new Chain<Searcher>(new VespaLowercasingSearcher(new LowercasingConfig(new LowercasingConfig.Builder().transform_weighted_sets(false)))), Execution.Context.createContextStub(settings));
Query q = new Query();
AndItem root = new AndItem();
WeightedSetItem tmp;
tmp = new WeightedSetItem(BAMSE);
tmp.addToken("AbC", 3);
root.addItem(tmp);
tmp = new WeightedSetItem(TEDDY);
tmp.addToken("dEf", 5);
root.addItem(tmp);
q.getModel().getQueryTree().setRoot(root);
Result r = execution.search(q);
root = (AndItem) r.getQuery().getModel().getQueryTree().getRoot();
WeightedSetItem w0 = (WeightedSetItem) root.getItem(0);
WeightedSetItem w1 = (WeightedSetItem) root.getItem(1);
assertEquals(1, w0.getNumTokens());
assertEquals(1, w1.getNumTokens());
assertEquals("AbC", w0.getTokens().next().getKey());
assertEquals("dEf", w1.getTokens().next().getKey());
}
use of com.yahoo.search.searchchain.Execution in project vespa by vespa-engine.
the class QueryCombinatorTestCase method testDefaultIndexWithoutQuery.
public void testDefaultIndexWithoutQuery() {
Query q = new Query("?defidx.juhu=b");
Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts()));
e.search(q);
assertEquals("NULL", q.getModel().getQueryTree().toString());
q = new Query("?query=a&defidx.juhu=b");
e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts()));
e.search(q);
assertEquals("a", q.getModel().getQueryTree().toString());
}
Aggregations