Search in sources :

Example 36 with Chain

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

the class ProcessingTestCase method testChainedProcessing2.

/**
 * Execute the same processors in a different order
 */
@Test
public void testChainedProcessing2() {
    // Create a chain
    Chain<Processor> chain = new Chain<>(new Get6DataItems(), new CombineData(), new DataSource());
    // Execute it
    Request request = new Request();
    request.properties().set("appendage", 1);
    Response response = Execution.createRoot(chain, 0, Execution.Environment.createEmpty()).process(request);
    // Check the result
    assertEquals(6, response.data().asList().size());
    assertEquals("first.2, third.2", response.data().get(0).toString());
    assertEquals("second.2", response.data().get(1).toString());
    assertEquals("first.4, third.4", response.data().get(2).toString());
    assertEquals("second.4", response.data().get(3).toString());
    assertEquals("first.6, third.6", response.data().get(4).toString());
    assertEquals("second.6", response.data().get(5).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 37 with Chain

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

the class AsyncExecutionTestCase method testAsyncExecution.

/**
 * Execute a processing chain which forks off into multiple threads
 */
@Test
public void testAsyncExecution() {
    // Create a chain
    Chain<Processor> chain = new Chain<>(new CombineData(), new BlockingSplitter(2), 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 * 2 - 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());
    // from the parallel execution
    assertEquals("first.2", response.data().get(5).toString());
    assertEquals("second.2", response.data().get(6).toString());
    assertEquals("third.2", response.data().get(7).toString());
    assertEquals("first.3", response.data().get(8).toString());
    assertEquals("second.3", response.data().get(9).toString());
    assertEquals("third.3", response.data().get(10).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 38 with Chain

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

the class AsyncExecutionOfOneChainTestCase method testParallelExecutionOfOneChain.

/**
 * Tests having a result with some slow source data which should pass directly to rendering
 */
public void testParallelExecutionOfOneChain() {
    // Setup
    Chain<Searcher> mainChain = new Chain<>(new ParallelExecutor(), new ResultProcessor(), new RegularProvider());
    // Execute
    Result result = new Execution(mainChain, Execution.Context.createContextStub()).search(new Query());
    // Verify
    assertEquals("Received 2 hits from 3 threads", 3 * 2, result.hits().size());
    assertEquals(1.0, result.hits().get("thread-0:hit-0").getRelevance().getScore());
    assertEquals(1.0, result.hits().get("thread-1:hit-0").getRelevance().getScore());
    assertEquals(1.0, result.hits().get("thread-2:hit-0").getRelevance().getScore());
    assertEquals(0.5, result.hits().get("thread-0:hit-1").getRelevance().getScore());
    assertEquals(0.5, result.hits().get("thread-1:hit-1").getRelevance().getScore());
    assertEquals(0.5, result.hits().get("thread-2:hit-1").getRelevance().getScore());
}
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) FutureResult(com.yahoo.search.searchchain.FutureResult) Result(com.yahoo.search.Result)

Example 39 with Chain

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

the class ExecutionTestCase method testNestedExecution.

public void testNestedExecution() {
    // Make a chain
    List<Searcher> searchers1 = new ArrayList<>();
    searchers1.add(new FillableTestSearcher("searcher1"));
    searchers1.add(new WorkflowSearcher());
    searchers1.add(new TestSearcher("searcher2"));
    searchers1.add(new FillingSearcher());
    searchers1.add(new FillableTestSearcherAtTheEnd("searcher3"));
    Chain<Searcher> chain1 = new Chain<>(new ComponentId("chain1"), searchers1);
    // Execute it
    Query query = new Query("test");
    Result result1 = new Execution(chain1, Execution.Context.createContextStub()).search(query);
    // Verify results
    assertEquals(7, result1.getConcreteHitCount());
    assertNotNull(result1.hits().get("searcher1-1"));
    assertNotNull(result1.hits().get("searcher2-1"));
    assertNotNull(result1.hits().get("searcher3-1"));
    assertNotNull(result1.hits().get("searcher3-1-filled"));
    assertNotNull(result1.hits().get("searcher2-2"));
    assertNotNull(result1.hits().get("searcher3-2"));
    assertNotNull(result1.hits().get("searcher3-2-filled"));
}
Also used : Chain(com.yahoo.component.chain.Chain) Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher) ArrayList(java.util.ArrayList) Result(com.yahoo.search.Result) Execution(com.yahoo.search.searchchain.Execution) ComponentId(com.yahoo.component.ComponentId)

Example 40 with Chain

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

the class ExecutionTestCase method testBasicFill.

@Test
public void testBasicFill() {
    Chain<Searcher> chain = new Chain<Searcher>(new FillableResultSearcher());
    Execution execution = new Execution(chain, Execution.Context.createContextStub(null));
    Result result = execution.search(new Query(com.yahoo.search.test.QueryTestCase.httpEncode("?presentation.summary=all")));
    assertNotNull(result.hits().get("a"));
    assertNull(result.hits().get("a").getField("filled"));
    execution.fill(result);
    assertTrue((Boolean) result.hits().get("a").getField("filled"));
}
Also used : Chain(com.yahoo.component.chain.Chain) Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher) Result(com.yahoo.search.Result) 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