use of com.yahoo.component.chain.Chain in project vespa by vespa-engine.
the class GetSearcherTestCase method testLegacyHeadersOnly.
@Test
public void testLegacyHeadersOnly() throws Exception {
// Needs auto-reply
DocumentSessionFactory factory = new DocumentSessionFactory(docType);
GetSearcher searcher = new GetSearcher(new FeedContext(new MessagePropertyProcessor(defFeedCfg, defLoadTypeCfg), factory, docMan, new ClusterList(), new NullFeedMetric()));
Chain<Searcher> searchChain = new Chain<>(searcher);
Result result = new Execution(searchChain, Execution.Context.createContextStub()).search(newQuery("?id=userdoc:kittens:1:2&headersonly=true"));
assertEquals(1, factory.messages.size());
{
Message m = factory.messages.get(0);
assertEquals(DocumentProtocol.MESSAGE_GETDOCUMENT, m.getType());
GetDocumentMessage gdm = (GetDocumentMessage) m;
DocumentId d = gdm.getDocumentId();
assertEquals("userdoc:kittens:1:2", d.toString());
assertEquals("[header]", gdm.getFieldSet());
}
assertEquals(1, result.hits().size());
assertHits(result.hits(), "userdoc:kittens:1:2");
}
use of com.yahoo.component.chain.Chain in project vespa by vespa-engine.
the class GetSearcherTestCase method testDocumentFieldWithMultipleIDs.
@Test
public void testDocumentFieldWithMultipleIDs() throws Exception {
DocumentSessionFactory factory = new DocumentSessionFactory(docType);
GetSearcher searcher = new GetSearcher(new FeedContext(new MessagePropertyProcessor(defFeedCfg, defLoadTypeCfg), factory, docMan, new ClusterList(), new NullFeedMetric()));
Chain<Searcher> searchChain = new Chain<>(searcher);
Result result = new Execution(searchChain, Execution.Context.createContextStub()).search(newQuery("?id[0]=userdoc:kittens:1:2&id[1]=userdoc:kittens:3:4&field=name"));
assertNotNull(result.hits().getErrorHit());
assertRendered("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<result>\n" + "<errors>\n" + "<error type=\"searcher\" code=\"3\" message=\"Illegal query: " + "java.lang.IllegalArgumentException: Field only valid for single document id query\"/>\n" + "</errors>\n" + "</result>\n", result);
}
use of com.yahoo.component.chain.Chain in project vespa by vespa-engine.
the class VisitorSearcherTestCase method testSimple.
@Test
public void testSimple() throws Exception {
Chain<Searcher> searchChain = new Chain<>(create());
Result result = new Execution(searchChain, Execution.Context.createContextStub()).search(newQuery("visit?visit.selection=id.user=1234&hits=100"));
assertEquals(1, result.hits().size());
assertRendered("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<result>\n" + "<document documenttype=\"kittens\" documentid=\"userdoc:foo:1234:bar\"/>\n" + "</result>\n", result);
}
use of com.yahoo.component.chain.Chain in project vespa by vespa-engine.
the class StreamingTestCase method testStreamingData.
/**
* Tests adding a chain which is called every time new data is added to a data list
*/
@SuppressWarnings("unchecked")
@Test
public void testStreamingData() throws InterruptedException, ExecutionException, TimeoutException {
// Set up
StreamProcessor streamProcessor = new StreamProcessor();
Chain<Processor> streamProcessing = new Chain<Processor>(streamProcessor);
ProcessorLibrary.FutureDataSource futureDataSource = new ProcessorLibrary.FutureDataSource();
Chain<Processor> main = new Chain<>(new ProcessorLibrary.DataCounter(), new ProcessorLibrary.StreamProcessingInitiator(streamProcessing), futureDataSource);
// Execute
Request request = new Request();
Response response = Execution.createRoot(main, 0, Execution.Environment.createEmpty()).process(request);
IncomingData incomingData = futureDataSource.incomingData.get(0);
// State prior to receiving any additional data
assertEquals(1, response.data().asList().size());
assertEquals("Data count: 0", response.data().get(0).toString());
assertEquals("Add data listener invoked also for DataCounter", 1, streamProcessor.invocationCount);
assertEquals("Initial data count", 1, response.data().asList().size());
// add first data - we have no listener so the data is held in the incoming buffer
incomingData.add(new ProcessorLibrary.StringData(request, "d1"));
assertEquals("Data add listener not invoked as we are not listening on new data yet", 1, streamProcessor.invocationCount);
assertEquals("New data is not consumed", 1, response.data().asList().size());
// start listening on incoming data - this is what a renderer will do
incomingData.addNewDataListener(new MockNewDataListener(incomingData), MoreExecutors.directExecutor());
assertEquals("We got a data add event for the data which was already added", 2, streamProcessor.invocationCount);
assertEquals("New data is consumed", 2, response.data().asList().size());
incomingData.add(new ProcessorLibrary.StringData(request, "d2"));
assertEquals("We are now getting data add events each time", 3, streamProcessor.invocationCount);
assertEquals("New data is consumed", 3, response.data().asList().size());
incomingData.addLast(new ProcessorLibrary.StringData(request, "d3"));
assertEquals("We are getting data add events also the last time", 4, streamProcessor.invocationCount);
assertEquals("New data is consumed", 4, response.data().asList().size());
// no-op here
response.data().complete().get(1000, TimeUnit.MILLISECONDS);
assertEquals("d1", response.data().get(1).toString().toString());
assertEquals("d2", response.data().get(2).toString().toString());
assertEquals("d3", response.data().get(3).toString().toString());
}
use of com.yahoo.component.chain.Chain in project vespa by vespa-engine.
the class FutureDataTestCase method testAsyncFederation.
@Test
public void testAsyncFederation() throws InterruptedException, ExecutionException, TimeoutException {
// Setup environment
AsyncProviderSearcher asyncProviderSearcher = new AsyncProviderSearcher();
Searcher syncProviderSearcher = new SyncProviderSearcher();
Chain<Searcher> asyncSource = new Chain<Searcher>(new ComponentId("async"), asyncProviderSearcher);
Chain<Searcher> syncSource = new Chain<>(new ComponentId("sync"), syncProviderSearcher);
SearchChainResolver searchChainResolver = new SearchChainResolver.Builder().addSearchChain(new ComponentId("sync"), new FederationOptions().setUseByDefault(true)).addSearchChain(new ComponentId("async"), new FederationOptions().setUseByDefault(true)).build();
Chain<Searcher> main = new Chain<Searcher>(new FederationSearcher(new ComponentId("federator"), searchChainResolver));
SearchChainRegistry searchChainRegistry = new SearchChainRegistry();
searchChainRegistry.register(main);
searchChainRegistry.register(syncSource);
searchChainRegistry.register(asyncSource);
Result result = new Execution(main, Execution.Context.createContextStub(searchChainRegistry, null)).search(new Query());
assertNotNull(result);
HitGroup syncGroup = (HitGroup) result.hits().get("source:sync");
assertNotNull(syncGroup);
HitGroup asyncGroup = (HitGroup) result.hits().get("source:async");
assertNotNull(asyncGroup);
assertEquals("Got all sync data", 3, syncGroup.size());
assertEquals("sync:0", syncGroup.get(0).getId().toString());
assertEquals("sync:1", syncGroup.get(1).getId().toString());
assertEquals("sync:2", syncGroup.get(2).getId().toString());
assertTrue(asyncGroup.incoming() == asyncProviderSearcher.incomingData);
assertEquals("Got no async data yet", 0, asyncGroup.size());
asyncProviderSearcher.simulateOneHitIOComplete(new Hit("async:0"));
assertEquals("Got no async data yet, as we haven't completed the incoming buffer and there is no data listener", 0, asyncGroup.size());
asyncProviderSearcher.simulateOneHitIOComplete(new Hit("async:1"));
asyncProviderSearcher.simulateAllHitsIOComplete();
assertEquals("Got no async data yet, as we haven't pulled it", 0, asyncGroup.size());
asyncGroup.complete().get();
assertEquals("Completed, so we have the data", 2, asyncGroup.size());
assertEquals("async:0", asyncGroup.get(0).getId().toString());
assertEquals("async:1", asyncGroup.get(1).getId().toString());
}
Aggregations