Search in sources :

Example 71 with Chain

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

the class AsyncExecutionTestCase method testWaitForAll.

public void testWaitForAll() {
    Chain<Searcher> slowChain = new Chain<>(new ComponentId("slow"), Arrays.asList(new Searcher[] { new WaitingSearcher("slow", 30000) }));
    Chain<Searcher> fastChain = new Chain<>(new ComponentId("fast"), Arrays.asList(new Searcher[] { new SimpleSearcher() }));
    FutureResult slowFuture = new AsyncExecution(slowChain, Execution.Context.createContextStub()).search(new Query("?hits=0"));
    FutureResult fastFuture = new AsyncExecution(fastChain, Execution.Context.createContextStub()).search(new Query("?hits=0"));
    fastFuture.get();
    FutureResult[] reslist = new FutureResult[] { slowFuture, fastFuture };
    List<Result> results = AsyncExecution.waitForAll(Arrays.asList(reslist), 0);
    // assertTrue(slowFuture.isCancelled());
    assertTrue(fastFuture.isDone() && !fastFuture.isCancelled());
    assertNotNull(results.get(0).hits().getErrorHit());
    assertNull(results.get(1).hits().getErrorHit());
}
Also used : Chain(com.yahoo.component.chain.Chain) FutureResult(com.yahoo.search.searchchain.FutureResult) Query(com.yahoo.search.Query) AsyncExecution(com.yahoo.search.searchchain.AsyncExecution) Searcher(com.yahoo.search.Searcher) ComponentId(com.yahoo.component.ComponentId) FutureResult(com.yahoo.search.searchchain.FutureResult) Result(com.yahoo.search.Result)

Example 72 with Chain

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

the class AsyncExecutionTestCase method testAsyncExecutionTimeout.

@SuppressWarnings("deprecation")
public void testAsyncExecutionTimeout() {
    Chain<Searcher> chain = new Chain<>(new Searcher() {

        @Override
        public Result search(Query query, Execution execution) {
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return new Result(query);
        }
    });
    Execution execution = new Execution(chain, Execution.Context.createContextStub());
    AsyncExecution async = new AsyncExecution(execution);
    FutureResult future = async.searchAndFill(new Query());
    future.get(1, TimeUnit.MILLISECONDS);
}
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) FutureResult(com.yahoo.search.searchchain.FutureResult) AsyncExecution(com.yahoo.search.searchchain.AsyncExecution) Searcher(com.yahoo.search.Searcher) FutureResult(com.yahoo.search.searchchain.FutureResult) Result(com.yahoo.search.Result)

Example 73 with Chain

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

the class FutureDataTestCase method testFutureData.

@Test
public void testFutureData() throws InterruptedException, ExecutionException, TimeoutException {
    // Set up
    AsyncProviderSearcher futureDataSource = new AsyncProviderSearcher();
    Chain<Searcher> chain = new Chain<>(Collections.<Searcher>singletonList(futureDataSource));
    // Execute
    Query query = new Query();
    Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
    // Verify the result prior to completion of delayed data
    assertEquals("The result has been returned, but no hits are available yet", 0, result.hits().getConcreteSize());
    // pretend we're the IO layer and complete delayed data - this is typically done in a callback from jDisc
    futureDataSource.simulateOneHitIOComplete(new Hit("hit:0"));
    futureDataSource.simulateOneHitIOComplete(new Hit("hit:1"));
    futureDataSource.simulateAllHitsIOComplete();
    assertEquals("Async arriving hits are still not visible because we haven't asked for them", 0, result.hits().getConcreteSize());
    // Results with future hit groups will be passed to rendering directly and start rendering immediately.
    // For this test we block and wait for the data instead:
    result.hits().complete().get(1000, TimeUnit.MILLISECONDS);
    assertEquals(2, result.hits().getConcreteSize());
}
Also used : Chain(com.yahoo.component.chain.Chain) Hit(com.yahoo.search.result.Hit) Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher) FederationSearcher(com.yahoo.search.federation.FederationSearcher) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 74 with Chain

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

the class LowercasingTestCase method testLowercasingWordAlternatives.

@Test
public void testLowercasingWordAlternatives() {
    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();
    WordAlternativesItem root;
    List<WordAlternativesItem.Alternative> terms = new ArrayList<>();
    terms.add(new Alternative("ABC", 1.0));
    terms.add(new Alternative("def", 1.0));
    root = new WordAlternativesItem(BAMSE, true, null, terms);
    q.getModel().getQueryTree().setRoot(root);
    Result r = execution.search(q);
    root = (WordAlternativesItem) r.getQuery().getModel().getQueryTree().getRoot();
    assertEquals(3, root.getAlternatives().size());
    assertEquals("ABC", root.getAlternatives().get(0).word);
    assertEquals(1.0d, root.getAlternatives().get(0).exactness, 1e-15d);
    assertEquals("abc", root.getAlternatives().get(1).word);
    assertEquals(.7d, root.getAlternatives().get(1).exactness, 1e-15d);
    assertEquals("def", root.getAlternatives().get(2).word);
    assertEquals(1.0d, root.getAlternatives().get(2).exactness, 1e-15d);
}
Also used : Chain(com.yahoo.component.chain.Chain) Execution(com.yahoo.search.searchchain.Execution) Alternative(com.yahoo.prelude.query.WordAlternativesItem.Alternative) Query(com.yahoo.search.Query) ArrayList(java.util.ArrayList) WordAlternativesItem(com.yahoo.prelude.query.WordAlternativesItem) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 75 with Chain

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

the class LowercasingTestCase method setUp.

@Before
public void setUp() throws Exception {
    IndexFacts f = new IndexFacts();
    Index bamse = new Index(BAMSE);
    Index teddy = new Index(TEDDY);
    Index defaultIndex = new Index("default");
    bamse.setLowercase(true);
    teddy.setLowercase(false);
    defaultIndex.setLowercase(true);
    f.addIndex("nalle", bamse);
    f.addIndex("nalle", teddy);
    f.addIndex("nalle", defaultIndex);
    f.freeze();
    settings = f;
    execution = new Execution(new Chain<Searcher>(new VespaLowercasingSearcher(new LowercasingConfig(new LowercasingConfig.Builder()))), Execution.Context.createContextStub(settings));
}
Also used : Chain(com.yahoo.component.chain.Chain) Execution(com.yahoo.search.searchchain.Execution) IndexFacts(com.yahoo.prelude.IndexFacts) Index(com.yahoo.prelude.Index) Before(org.junit.Before)

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