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());
}
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);
}
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());
}
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);
}
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));
}
Aggregations