Search in sources :

Example 26 with Chain

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

the class GetSearcherTestCase method testLegacyHeadersOnly.

@Test
public void testLegacyHeadersOnly() throws Exception {
    // Needs auto-reply
    DocumentSessionFactory factory = new DocumentSessionFactory(docType);
    GetSearcher searcher = new GetSearcher(new FeedContext(new MessagePropertyProcessor(defFeedCfg, defLoadTypeCfg), factory, docMan, new ClusterList(), new NullFeedMetric()));
    Chain<Searcher> searchChain = new Chain<>(searcher);
    Result result = new Execution(searchChain, Execution.Context.createContextStub()).search(newQuery("?id=userdoc:kittens:1:2&headersonly=true"));
    assertEquals(1, factory.messages.size());
    {
        Message m = factory.messages.get(0);
        assertEquals(DocumentProtocol.MESSAGE_GETDOCUMENT, m.getType());
        GetDocumentMessage gdm = (GetDocumentMessage) m;
        DocumentId d = gdm.getDocumentId();
        assertEquals("userdoc:kittens:1:2", d.toString());
        assertEquals("[header]", gdm.getFieldSet());
    }
    assertEquals(1, result.hits().size());
    assertHits(result.hits(), "userdoc:kittens:1:2");
}
Also used : Chain(com.yahoo.component.chain.Chain) ClusterList(com.yahoo.vespaclient.ClusterList) Message(com.yahoo.messagebus.Message) GetDocumentMessage(com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage) Searcher(com.yahoo.search.Searcher) Result(com.yahoo.search.Result) Execution(com.yahoo.search.searchchain.Execution) FeedContext(com.yahoo.feedapi.FeedContext) GetDocumentMessage(com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage) MessagePropertyProcessor(com.yahoo.feedapi.MessagePropertyProcessor) NullFeedMetric(com.yahoo.feedhandler.NullFeedMetric) Test(org.junit.Test)

Example 27 with Chain

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

the class GetSearcherTestCase method testDocumentFieldWithMultipleIDs.

@Test
public void testDocumentFieldWithMultipleIDs() throws Exception {
    DocumentSessionFactory factory = new DocumentSessionFactory(docType);
    GetSearcher searcher = new GetSearcher(new FeedContext(new MessagePropertyProcessor(defFeedCfg, defLoadTypeCfg), factory, docMan, new ClusterList(), new NullFeedMetric()));
    Chain<Searcher> searchChain = new Chain<>(searcher);
    Result result = new Execution(searchChain, Execution.Context.createContextStub()).search(newQuery("?id[0]=userdoc:kittens:1:2&id[1]=userdoc:kittens:3:4&field=name"));
    assertNotNull(result.hits().getErrorHit());
    assertRendered("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<result>\n" + "<errors>\n" + "<error type=\"searcher\" code=\"3\" message=\"Illegal query: " + "java.lang.IllegalArgumentException: Field only valid for single document id query\"/>\n" + "</errors>\n" + "</result>\n", result);
}
Also used : Chain(com.yahoo.component.chain.Chain) ClusterList(com.yahoo.vespaclient.ClusterList) Execution(com.yahoo.search.searchchain.Execution) FeedContext(com.yahoo.feedapi.FeedContext) Searcher(com.yahoo.search.Searcher) MessagePropertyProcessor(com.yahoo.feedapi.MessagePropertyProcessor) NullFeedMetric(com.yahoo.feedhandler.NullFeedMetric) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 28 with Chain

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

the class VisitorSearcherTestCase method testSimple.

@Test
public void testSimple() throws Exception {
    Chain<Searcher> searchChain = new Chain<>(create());
    Result result = new Execution(searchChain, Execution.Context.createContextStub()).search(newQuery("visit?visit.selection=id.user=1234&hits=100"));
    assertEquals(1, result.hits().size());
    assertRendered("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<result>\n" + "<document documenttype=\"kittens\" documentid=\"userdoc:foo:1234:bar\"/>\n" + "</result>\n", result);
}
Also used : Chain(com.yahoo.component.chain.Chain) Execution(com.yahoo.search.searchchain.Execution) Searcher(com.yahoo.search.Searcher) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 29 with Chain

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

the class StreamingTestCase method testStreamingData.

/**
 * Tests adding a chain which is called every time new data is added to a data list
 */
@SuppressWarnings("unchecked")
@Test
public void testStreamingData() throws InterruptedException, ExecutionException, TimeoutException {
    // Set up
    StreamProcessor streamProcessor = new StreamProcessor();
    Chain<Processor> streamProcessing = new Chain<Processor>(streamProcessor);
    ProcessorLibrary.FutureDataSource futureDataSource = new ProcessorLibrary.FutureDataSource();
    Chain<Processor> main = new Chain<>(new ProcessorLibrary.DataCounter(), new ProcessorLibrary.StreamProcessingInitiator(streamProcessing), futureDataSource);
    // Execute
    Request request = new Request();
    Response response = Execution.createRoot(main, 0, Execution.Environment.createEmpty()).process(request);
    IncomingData incomingData = futureDataSource.incomingData.get(0);
    // State prior to receiving any additional data
    assertEquals(1, response.data().asList().size());
    assertEquals("Data count: 0", response.data().get(0).toString());
    assertEquals("Add data listener invoked also for DataCounter", 1, streamProcessor.invocationCount);
    assertEquals("Initial data count", 1, response.data().asList().size());
    // add first data - we have no listener so the data is held in the incoming buffer
    incomingData.add(new ProcessorLibrary.StringData(request, "d1"));
    assertEquals("Data add listener not invoked as we are not listening on new data yet", 1, streamProcessor.invocationCount);
    assertEquals("New data is not consumed", 1, response.data().asList().size());
    // start listening on incoming data - this is what a renderer will do
    incomingData.addNewDataListener(new MockNewDataListener(incomingData), MoreExecutors.directExecutor());
    assertEquals("We got a data add event for the data which was already added", 2, streamProcessor.invocationCount);
    assertEquals("New data is consumed", 2, response.data().asList().size());
    incomingData.add(new ProcessorLibrary.StringData(request, "d2"));
    assertEquals("We are now getting data add events each time", 3, streamProcessor.invocationCount);
    assertEquals("New data is consumed", 3, response.data().asList().size());
    incomingData.addLast(new ProcessorLibrary.StringData(request, "d3"));
    assertEquals("We are getting data add events also the last time", 4, streamProcessor.invocationCount);
    assertEquals("New data is consumed", 4, response.data().asList().size());
    // no-op here
    response.data().complete().get(1000, TimeUnit.MILLISECONDS);
    assertEquals("d1", response.data().get(1).toString().toString());
    assertEquals("d2", response.data().get(2).toString().toString());
    assertEquals("d3", response.data().get(3).toString().toString());
}
Also used : Chain(com.yahoo.component.chain.Chain) Processor(com.yahoo.processing.Processor) Request(com.yahoo.processing.Request) ProcessorLibrary(com.yahoo.processing.test.ProcessorLibrary) Response(com.yahoo.processing.Response) IncomingData(com.yahoo.processing.response.IncomingData) Test(org.junit.Test)

Example 30 with Chain

use of com.yahoo.component.chain.Chain 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());
}
Also used : Chain(com.yahoo.component.chain.Chain) FederationSearcher(com.yahoo.search.federation.FederationSearcher) Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher) FederationSearcher(com.yahoo.search.federation.FederationSearcher) SearchChainResolver(com.yahoo.search.federation.sourceref.SearchChainResolver) Result(com.yahoo.search.Result) FederationOptions(com.yahoo.search.searchchain.model.federation.FederationOptions) Hit(com.yahoo.search.result.Hit) Execution(com.yahoo.search.searchchain.Execution) SearchChainRegistry(com.yahoo.search.searchchain.SearchChainRegistry) ComponentId(com.yahoo.component.ComponentId) HitGroup(com.yahoo.search.result.HitGroup) Test(org.junit.Test)

Aggregations

Chain (com.yahoo.component.chain.Chain)92 Execution (com.yahoo.search.searchchain.Execution)59 Searcher (com.yahoo.search.Searcher)57 Test (org.junit.Test)56 Result (com.yahoo.search.Result)48 Query (com.yahoo.search.Query)47 FeedContext (com.yahoo.feedapi.FeedContext)21 MessagePropertyProcessor (com.yahoo.feedapi.MessagePropertyProcessor)21 NullFeedMetric (com.yahoo.feedhandler.NullFeedMetric)21 ClusterList (com.yahoo.vespaclient.ClusterList)21 Processor (com.yahoo.processing.Processor)17 Request (com.yahoo.processing.Request)10 Response (com.yahoo.processing.Response)10 ComponentId (com.yahoo.component.ComponentId)8 FederationSearcher (com.yahoo.search.federation.FederationSearcher)8 ArrayList (java.util.ArrayList)8 GetDocumentMessage (com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage)7 Message (com.yahoo.messagebus.Message)7 Hit (com.yahoo.search.result.Hit)7 AsyncExecution (com.yahoo.search.searchchain.AsyncExecution)6