Search in sources :

Example 91 with Chain

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

the class FutureDataTestCase method testAsyncDataProcessing.

/**
 * Register a chain which will be called when some async data is available
 */
@SuppressWarnings("unchecked")
@Test
public void testAsyncDataProcessing() throws InterruptedException, ExecutionException, TimeoutException {
    // Set up
    FutureDataSource futureDataSource = new FutureDataSource();
    Chain<Processor> asyncChain = new Chain<Processor>(new DataCounter());
    Chain<Processor> chain = new Chain<>(new AsyncDataProcessingInitiator(asyncChain), futureDataSource);
    // Execute
    Request request = new Request();
    Response response = Execution.createRoot(chain, 0, Execution.Environment.createEmpty()).process(request);
    // Verify the result prior to completion of delayed data
    assertEquals("No data yet", 0, response.data().asList().size());
    // complete async data
    futureDataSource.incomingData.get(0).add(new StringData(request, "d1"));
    assertEquals("New data is not visible because it is not complete", 0, response.data().asList().size());
    futureDataSource.incomingData.get(0).addLast(new StringData(request, "d2"));
    assertEquals("Not visible because it has not been synced yet", 0, response.data().asList().size());
    response.data().complete().get(1000, TimeUnit.MILLISECONDS);
    assertEquals("Now the data as well as the count is available", 3, response.data().asList().size());
    assertEquals("d1", response.data().get(0).toString().toString());
    assertEquals("d2", response.data().get(1).toString().toString());
    assertEquals("Data count: 2", response.data().get(2).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)

Example 92 with Chain

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

the class FutureDataTestCase method testFutureDataPassThrough.

/**
 * Run a chain which ends in a processor which returns a response containing future data.
 */
@SuppressWarnings("unchecked")
@Test
public void testFutureDataPassThrough() throws InterruptedException, ExecutionException, TimeoutException {
    // Set up
    FutureDataSource futureDataSource = new FutureDataSource();
    Chain<Processor> chain = new Chain<>(new DataCounter(), futureDataSource);
    // Execute
    Request request = new Request();
    // Urk ...
    Response response = Execution.createRoot(chain, 0, Execution.Environment.createEmpty()).process(request);
    // Verify the result prior to completion of delayed data
    assertEquals(1, response.data().asList().size());
    assertEquals("Data count: 0", response.data().get(0).toString());
    // complete delayed data
    assertEquals("Delayed data was requested once", 1, futureDataSource.incomingData.size());
    futureDataSource.incomingData.get(0).add(new StringData(request, "d1"));
    futureDataSource.incomingData.get(0).addLast(new StringData(request, "d2"));
    assertEquals("New data is not visible because we haven't asked for it", 1, response.data().asList().size());
    response.data().complete().get(1000, TimeUnit.MILLISECONDS);
    assertEquals("Now the data is available", 3, response.data().asList().size());
    assertEquals("d1", response.data().get(1).toString().toString());
    assertEquals("d2", response.data().get(2).toString().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