Search in sources :

Example 31 with Chain

use of com.yahoo.component.chain.Chain 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);
}
Also used : Chain(com.yahoo.component.chain.Chain) Execution(com.yahoo.search.searchchain.Execution) AsyncExecution(com.yahoo.search.searchchain.AsyncExecution) Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher)

Example 32 with Chain

use of com.yahoo.component.chain.Chain 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());
}
Also used : Chain(com.yahoo.component.chain.Chain) Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) AndItem(com.yahoo.prelude.query.AndItem) WeightedSetItem(com.yahoo.prelude.query.WeightedSetItem) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 33 with Chain

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

the class FutureDataTestCase method testAsyncDataProcessingOfFederatedResult.

/**
 * Register a chain which federates over three sources, two of which are future.
 * When the first of the futures are done one additional chain is to be run.
 * When both are done another chain is to be run.
 */
@SuppressWarnings("unchecked")
@Test
public void testAsyncDataProcessingOfFederatedResult() throws InterruptedException, ExecutionException, TimeoutException {
    // Set up
    // Source 1 (async with completion chain)
    FutureDataSource futureSource1 = new FutureDataSource();
    Chain<Processor> asyncChainSource1 = new Chain<Processor>(new DataCounter("source1"));
    Chain<Processor> chainSource1 = new Chain<>(new AsyncDataProcessingInitiator(asyncChainSource1), futureSource1);
    // Source 2 (async source)
    FutureDataSource futureSource2 = new FutureDataSource();
    Chain<Processor> chainSource2 = new Chain<Processor>(futureSource2);
    // Source 3 (sync source)
    Chain<Processor> chainSource3 = new Chain<Processor>(new DataSource());
    // Main chain federating to the above - not waiting for source 1 and 2 but invoking asyncMain when both are complete
    Chain<Processor> asyncMain = new Chain<Processor>(new DataCounter("main"));
    Chain<Processor> main = new Chain<>(new AsyncDataProcessingInitiator(asyncMain), new Federator(chainSource1, chainSource2, chainSource3));
    // Execute
    Request request = new Request();
    Response response = Execution.createRoot(main, 0, Execution.Environment.createEmpty()).process(request);
    // Verify the result prior to completion of delayed data
    assertEquals("We have the sync data plus placeholders for the async lists", 3, response.data().asList().size());
    DataList source1Data = ((DataList) response.data().get(0));
    DataList source2Data = ((DataList) response.data().get(1));
    DataList source3Data = ((DataList) response.data().get(2));
    assertEquals("No data yet", 0, source1Data.asList().size());
    assertEquals("No data yet", 0, source2Data.asList().size());
    assertEquals(3, source3Data.asList().size());
    // complete async data in source1
    futureSource1.incomingData.get(0).addLast(new StringData(request, "source1Data"));
    assertEquals("Not visible yet", 0, source1Data.asList().size());
    source1Data.complete().get(1000, TimeUnit.MILLISECONDS);
    assertEquals(2, source1Data.asList().size());
    assertEquals("source1Data", source1Data.get(0).toString());
    assertEquals("Completion listener chain on this has run", "[source1] Data count: 1", source1Data.get(1).toString());
    // source2 & main completion
    assertEquals("Main completion listener has not run", 3, response.data().asList().size());
    futureSource2.incomingData.get(0).addLast(new StringData(request, "source2Data"));
    assertEquals("Main completion listener has not run", 3, response.data().asList().size());
    Response.recursiveComplete(response.data()).get();
    assertEquals("Main completion listener has run", 4, response.data().asList().size());
    assertEquals("The main data counter saw all sync data, but not source2 data as it executes after this", "[main] Data count: " + (2 + 0 + 3), response.data().get(3).toString());
}
Also used : Response(com.yahoo.processing.Response) Chain(com.yahoo.component.chain.Chain) DataList(com.yahoo.processing.response.DataList) Processor(com.yahoo.processing.Processor) Request(com.yahoo.processing.Request) Test(org.junit.Test)

Example 34 with Chain

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

the class DocumentationTestCase method test.

@SuppressWarnings("unchecked")
@Test
public final void test() {
    Processor p = new ExampleProcessor();
    Chain<Processor> basic = new Chain<>(p);
    Processor initiator = new AsyncDataProcessingInitiator(basic);
    Chain<Processor> postProcessing = new Chain<>(initiator);
    Execution e = Execution.createRoot(postProcessing, 0, Execution.Environment.createEmpty());
    Response r = e.process(new Request());
    // just adds a listener to the result returned from basic
    assertEquals(0, r.data().asList().size());
    Processor producer = new AsyncDataProducer();
    Chain<Processor> asyncChain = new Chain<>(producer);
    Processor federator = new Federator(basic, asyncChain);
    e = Execution.createRoot(federator, 0, Execution.Environment.createEmpty());
    r = e.process(new Request());
    assertEquals(2, r.data().asList().size());
}
Also used : Response(com.yahoo.processing.Response) AsyncDataProducer(com.yahoo.processing.test.documentation.AsyncDataProducer) Chain(com.yahoo.component.chain.Chain) AsyncDataProcessingInitiator(com.yahoo.processing.test.documentation.AsyncDataProcessingInitiator) Federator(com.yahoo.processing.test.documentation.Federator) ExampleProcessor(com.yahoo.processing.test.documentation.ExampleProcessor) Processor(com.yahoo.processing.Processor) Execution(com.yahoo.processing.execution.Execution) ExampleProcessor(com.yahoo.processing.test.documentation.ExampleProcessor) Request(com.yahoo.processing.Request) Test(org.junit.Test)

Example 35 with Chain

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

the class ProcessingTestCase method testChainedProcessing1.

/**
 * Execute three simple processors doing some phony processing
 */
@Test
public void testChainedProcessing1() {
    // Create a chain
    Chain<Processor> chain = new Chain<>(new CombineData(), new Get6DataItems(), new DataSource());
    // Execute it
    Request request = new Request();
    request.properties().set("appendage", 1);
    Response response = Execution.createRoot(chain, 0, Execution.Environment.createEmpty()).process(request);
    // Verify the result
    assertEquals(6 - 1, response.data().asList().size());
    assertEquals("first.2, third.2", response.data().get(0).toString());
    assertEquals("second.2", response.data().get(1).toString());
    assertEquals("first.3", response.data().get(2).toString());
    assertEquals("second.3", response.data().get(3).toString());
    assertEquals("third.3", response.data().get(4).toString());
}
Also used : Response(com.yahoo.processing.Response) Chain(com.yahoo.component.chain.Chain) Processor(com.yahoo.processing.Processor) Request(com.yahoo.processing.Request) 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