use of com.yahoo.search.Searcher 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.Searcher 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.Searcher 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.Searcher in project vespa by vespa-engine.
the class JsonRendererTestCase method testEmptyTracing.
@Test
public final void testEmptyTracing() throws IOException, InterruptedException, ExecutionException {
String expected = "{\n" + " \"root\": {\n" + " \"fields\": {\n" + " \"totalCount\": 0\n" + " },\n" + " \"id\": \"toplevel\",\n" + " \"relevance\": 1.0\n" + " }\n" + "}\n";
Query q = new Query("/?query=a&tracelevel=0");
Execution execution = new Execution(Execution.Context.createContextStub());
Result r = new Result(q);
execution.search(q);
Execution e2 = new Execution(new Chain<Searcher>(), execution.context());
Query subQuery = new Query("/?query=b&tracelevel=0");
e2.search(subQuery);
subQuery.trace("yellow", 1);
q.trace("marker", 1);
ByteArrayOutputStream bs = new ByteArrayOutputStream();
ListenableFuture<Boolean> f = renderer.render(bs, r, execution, null);
assertTrue(f.get());
String summary = Utf8.toString(bs.toByteArray());
assertEqualJson(expected, summary);
}
use of com.yahoo.search.Searcher in project vespa by vespa-engine.
the class SyncDefaultRendererTestCase method testRenderWriterResult.
@SuppressWarnings("deprecation")
@Test
public final void testRenderWriterResult() throws IOException, InterruptedException, ExecutionException {
Query q = new Query("/?query=a&tracelevel=5&reportCoverage=true");
q.getPresentation().setTiming(true);
Result r = new Result(q);
r.setCoverage(new Coverage(500, 1, true));
TimeTracker t = new TimeTracker(new Chain<Searcher>(new UselessSearcher("first"), new UselessSearcher("second"), new UselessSearcher("third")));
ElapsedTimeTestCase.doInjectTimeSource(t, new CreativeTimeSource(new long[] { 1L, 2L, 3L, 4L, 5L, 6L, 7L }));
t.sampleSearch(0, true);
t.sampleSearch(1, true);
t.sampleSearch(2, true);
t.sampleSearch(3, true);
t.sampleSearchReturn(2, true, null);
t.sampleSearchReturn(1, true, null);
t.sampleSearchReturn(0, true, null);
r.getElapsedTime().add(t);
r.getTemplating().setRenderer(d);
FastHit h = new FastHit("http://localhost/", .95);
h.setField("$a", "Hello, world.");
h.setField("b", "foo");
r.hits().add(h);
HitGroup g = new HitGroup("usual");
h = new FastHit("http://localhost/1", .90);
h.setField("c", "d");
g.add(h);
r.hits().add(g);
HitGroup gg = new HitGroup("type grouphit");
gg.types().add("grouphit");
gg.setField("e", "f");
r.hits().add(gg);
r.hits().addError(ErrorMessage.createInternalServerError("boom"));
ByteArrayOutputStream bs = new ByteArrayOutputStream();
ListenableFuture<Boolean> f = d.render(bs, r, null, null);
assertTrue(f.get());
String summary = Utf8.toString(bs.toByteArray());
// TODO figure out a reasonably strict and reasonably flexible way to test
assertTrue(summary.length() > 1000);
}
Aggregations