Search in sources :

Example 1 with Container

use of com.yahoo.container.Container in project vespa by vespa-engine.

the class QueryProfileIntegrationTestCase method testTyped.

public void testTyped() {
    String configId = "dir:src/test/java/com/yahoo/search/query/profile/config/test/typed";
    System.setProperty("config.id", configId);
    Container container = new Container();
    HandlersConfigurerTestWrapper configurer = new HandlersConfigurerTestWrapper(container, configId);
    SearchHandler searchHandler = (SearchHandler) configurer.getRequestHandlerRegistry().getComponent(SearchHandler.class.getName());
    // Should get "default" query profile containing the "test" search chain containing the "test" searcher
    HttpRequest request = HttpRequest.createTestRequest("search", Method.GET);
    // Cast to access content directly
    HttpSearchResponse response = (HttpSearchResponse) searchHandler.handle(request);
    assertNotNull(response.getResult().hits().get("from:test"));
    // Should get the "test' query profile containing the "default" search chain containing the "default" searcher
    request = HttpRequest.createTestRequest("search?queryProfile=test", Method.GET);
    // Cast to access content directly
    response = (HttpSearchResponse) searchHandler.handle(request);
    assertNotNull(response.getResult().hits().get("from:default"));
    // Should get "default" query profile, but override the search chain to default
    request = HttpRequest.createTestRequest("search?searchChain=default", Method.GET);
    // Cast to access content directly
    response = (HttpSearchResponse) searchHandler.handle(request);
    assertNotNull(response.getResult().hits().get("from:default"));
    // Tests a profile setting hits and offset
    request = HttpRequest.createTestRequest("search?queryProfile=hitsoffset", Method.GET);
    // Cast to access content directly
    response = (HttpSearchResponse) searchHandler.handle(request);
    assertEquals(22, response.getQuery().getHits());
    assertEquals(80, response.getQuery().getOffset());
    // Tests a non-resolved profile request
    request = HttpRequest.createTestRequest("search?queryProfile=none", Method.GET);
    // Cast to access content directly
    response = (HttpSearchResponse) searchHandler.handle(request);
    assertNotNull("Got an error", response.getResult().hits().getError());
    assertEquals("Could not resolve query profile 'none'", response.getResult().hits().getError().getDetailedMessage());
    // Test overriding a sub-profile in the request
    request = HttpRequest.createTestRequest("search?queryProfile=root&sub=newsub", Method.GET);
    // Cast to access content directly
    response = (HttpSearchResponse) searchHandler.handle(request);
    assertEquals("newsubvalue1", response.getQuery().properties().get("sub.value1"));
    assertEquals("newsubvalue2", response.getQuery().properties().get("sub.value2"));
    configurer.shutdown();
}
Also used : SearchHandler(com.yahoo.search.handler.SearchHandler) HttpRequest(com.yahoo.container.jdisc.HttpRequest) Container(com.yahoo.container.Container) HandlersConfigurerTestWrapper(com.yahoo.container.core.config.testutil.HandlersConfigurerTestWrapper) HttpSearchResponse(com.yahoo.search.handler.HttpSearchResponse)

Example 2 with Container

use of com.yahoo.container.Container in project vespa by vespa-engine.

the class VespaFeedHandlerTestCase method setup.

public void setup(com.yahoo.messagebus.Error e, LoadTypeConfig loadTypeCfg, boolean autoReply, DummySessionFactory.ReplyFactory autoReplyFactory) throws Exception {
    DocumentTypeManager docMan = new DocumentTypeManager();
    DocumentTypeManagerConfigurer.configure(docMan, "file:" + xmlFilesPath + "documentmanager.cfg");
    if (autoReply) {
        if (autoReplyFactory != null) {
            factory = DummySessionFactory.createWithAutoReplyFactory(autoReplyFactory);
        } else {
            factory = DummySessionFactory.createWithErrorAutoReply(e);
        }
    } else {
        factory = DummySessionFactory.createDefault();
    }
    context = new FeedContext(new MessagePropertyProcessor(new FeederConfig(new FeederConfig.Builder()), loadTypeCfg), factory, docMan, new ClusterList(), new NullFeedMetric());
    Executor threadPool = Executors.newCachedThreadPool();
    feedHandler = new VespaFeedHandler(context, threadPool);
    removeHandler = new VespaFeedHandlerRemove(context, threadPool);
    statusHandler = new VespaFeedHandlerStatus(context, false, false, threadPool);
    removeLocationHandler = new VespaFeedHandlerRemoveLocation(context, threadPool);
    CallStack dpCallstack = new CallStack("bar");
    dpCallstack.addLast(new TestDocProc());
    dpCallstack.addLast(new TestLaterDocProc());
    DocprocService myservice = new DocprocService("bar");
    myservice.setCallStack(dpCallstack);
    myservice.setInService(true);
    ComponentRegistry<DocprocService> registry = new ComponentRegistry<DocprocService>();
    registry.register(new ComponentId(myservice.getName()), myservice);
    DocumentProcessingHandler handler = new DocumentProcessingHandler(registry, new ComponentRegistry<>(), new ComponentRegistry<>(), new DocumentProcessingHandlerParameters());
    Container container = Container.get();
    ComponentRegistry<RequestHandler> requestHandlerComponentRegistry = new ComponentRegistry<>();
    requestHandlerComponentRegistry.register(new ComponentId(DocumentProcessingHandler.class.getName()), handler);
    container.setRequestHandlerRegistry(requestHandlerComponentRegistry);
}
Also used : ClusterList(com.yahoo.vespaclient.ClusterList) CallStack(com.yahoo.docproc.CallStack) FeederConfig(com.yahoo.vespaclient.config.FeederConfig) Container(com.yahoo.container.Container) Executor(java.util.concurrent.Executor) DocumentProcessingHandler(com.yahoo.docproc.jdisc.DocumentProcessingHandler) MessagePropertyProcessor(com.yahoo.feedapi.MessagePropertyProcessor) RequestHandler(com.yahoo.jdisc.handler.RequestHandler) ComponentRegistry(com.yahoo.component.provider.ComponentRegistry) FeedContext(com.yahoo.feedapi.FeedContext) ComponentId(com.yahoo.component.ComponentId) DocumentProcessingHandlerParameters(com.yahoo.docproc.jdisc.DocumentProcessingHandlerParameters)

Example 3 with Container

use of com.yahoo.container.Container in project vespa by vespa-engine.

the class MessagePropertyProcessor method getDocprocServiceRegistry.

public synchronized ComponentRegistry<DocprocService> getDocprocServiceRegistry(HttpRequest request) {
    String docprocChain = getDocprocChainParameter(request);
    if (docprocChain == null) {
        return null;
    }
    Container container = Container.get();
    if (container == null) {
        throw new IllegalStateException("Could not get Container instance.");
    }
    ComponentRegistry<RequestHandler> requestHandlerRegistry = container.getRequestHandlerRegistry();
    if (requestHandlerRegistry == null) {
        throw new IllegalStateException("Could not get requesthandlerregistry.");
    }
    DocumentProcessingHandler handler = (DocumentProcessingHandler) requestHandlerRegistry.getComponent(DocumentProcessingHandler.class.getName());
    if (handler == null) {
        return null;
    }
    ComponentRegistry<DocprocService> services = handler.getDocprocServiceRegistry();
    if (services == null) {
        throw new IllegalStateException("Could not get DocprocServiceRegistry.");
    }
    return services;
}
Also used : Container(com.yahoo.container.Container) RequestHandler(com.yahoo.jdisc.handler.RequestHandler) DocumentProcessingHandler(com.yahoo.docproc.jdisc.DocumentProcessingHandler) DocprocService(com.yahoo.docproc.DocprocService)

Example 4 with Container

use of com.yahoo.container.Container in project vespa by vespa-engine.

the class SearchHandlerTestCase method startUp.

@Before
public void startUp() throws IOException {
    File cfgDir = tempfolder.newFolder("SearchHandlerTestCase");
    tempDir = cfgDir.getAbsolutePath();
    configId = "dir:" + tempDir;
    // make configs active
    IOUtils.copyDirectory(new File(testDir), cfgDir, 1);
    generateComponentsConfigForActive();
    configurer = new HandlersConfigurerTestWrapper(new Container(), configId);
    searchHandler = (SearchHandler) configurer.getRequestHandlerRegistry().getComponent(SearchHandler.class.getName());
    driver = new RequestHandlerTestDriver(searchHandler);
}
Also used : SearchHandler(com.yahoo.search.handler.SearchHandler) Container(com.yahoo.container.Container) HandlersConfigurerTestWrapper(com.yahoo.container.core.config.testutil.HandlersConfigurerTestWrapper) RequestHandlerTestDriver(com.yahoo.container.jdisc.RequestHandlerTestDriver) File(java.io.File) Before(org.junit.Before)

Example 5 with Container

use of com.yahoo.container.Container in project vespa by vespa-engine.

the class QueryProfileIntegrationTestCase method testUntyped.

public void testUntyped() {
    String configId = "dir:src/test/java/com/yahoo/search/query/profile/config/test/untyped";
    System.setProperty("config.id", configId);
    Container container = new Container();
    HandlersConfigurerTestWrapper configurer = new HandlersConfigurerTestWrapper(container, configId);
    SearchHandler searchHandler = (SearchHandler) configurer.getRequestHandlerRegistry().getComponent(SearchHandler.class.getName());
    // Should get "default" query profile containing the "test" search chain containing the "test" searcher
    HttpRequest request = HttpRequest.createTestRequest("search", Method.GET);
    // Cast to access content directly
    HttpSearchResponse response = (HttpSearchResponse) searchHandler.handle(request);
    assertNotNull(response.getResult().hits().get("from:test"));
    // Should get the "test' query profile containing the "default" search chain containing the "default" searcher
    request = HttpRequest.createTestRequest("search?queryProfile=test", Method.GET);
    // Cast to access content directly
    response = (HttpSearchResponse) searchHandler.handle(request);
    assertNotNull(response.getResult().hits().get("from:default"));
    // Should get "default" query profile, but override the search chain to default
    request = HttpRequest.createTestRequest("search?searchChain=default", Method.GET);
    // Cast to access content directly
    response = (HttpSearchResponse) searchHandler.handle(request);
    assertNotNull(response.getResult().hits().get("from:default"));
    // Tests a profile setting hits and offset
    request = HttpRequest.createTestRequest("search?queryProfile=hitsoffset", Method.GET);
    // Cast to access content directly
    response = (HttpSearchResponse) searchHandler.handle(request);
    assertEquals(20, response.getQuery().getHits());
    assertEquals(80, response.getQuery().getOffset());
    // Tests a non-resolved profile request
    request = HttpRequest.createTestRequest("search?queryProfile=none", Method.GET);
    // Cast to access content directly
    response = (HttpSearchResponse) searchHandler.handle(request);
    assertNotNull("Got an error", response.getResult().hits().getError());
    assertEquals("Could not resolve query profile 'none'", response.getResult().hits().getError().getDetailedMessage());
    // Tests that properties in objects owned by query is handled correctly
    request = HttpRequest.createTestRequest("search?query=word&queryProfile=test", Method.GET);
    // Cast to access content directly
    response = (HttpSearchResponse) searchHandler.handle(request);
    assertEquals("index", response.getQuery().getModel().getDefaultIndex());
    assertEquals("index:word", response.getQuery().getModel().getQueryTree().toString());
    configurer.shutdown();
}
Also used : SearchHandler(com.yahoo.search.handler.SearchHandler) HttpRequest(com.yahoo.container.jdisc.HttpRequest) Container(com.yahoo.container.Container) HandlersConfigurerTestWrapper(com.yahoo.container.core.config.testutil.HandlersConfigurerTestWrapper) HttpSearchResponse(com.yahoo.search.handler.HttpSearchResponse)

Aggregations

Container (com.yahoo.container.Container)5 HandlersConfigurerTestWrapper (com.yahoo.container.core.config.testutil.HandlersConfigurerTestWrapper)3 SearchHandler (com.yahoo.search.handler.SearchHandler)3 HttpRequest (com.yahoo.container.jdisc.HttpRequest)2 DocumentProcessingHandler (com.yahoo.docproc.jdisc.DocumentProcessingHandler)2 RequestHandler (com.yahoo.jdisc.handler.RequestHandler)2 HttpSearchResponse (com.yahoo.search.handler.HttpSearchResponse)2 ComponentId (com.yahoo.component.ComponentId)1 ComponentRegistry (com.yahoo.component.provider.ComponentRegistry)1 RequestHandlerTestDriver (com.yahoo.container.jdisc.RequestHandlerTestDriver)1 CallStack (com.yahoo.docproc.CallStack)1 DocprocService (com.yahoo.docproc.DocprocService)1 DocumentProcessingHandlerParameters (com.yahoo.docproc.jdisc.DocumentProcessingHandlerParameters)1 FeedContext (com.yahoo.feedapi.FeedContext)1 MessagePropertyProcessor (com.yahoo.feedapi.MessagePropertyProcessor)1 ClusterList (com.yahoo.vespaclient.ClusterList)1 FeederConfig (com.yahoo.vespaclient.config.FeederConfig)1 File (java.io.File)1 Executor (java.util.concurrent.Executor)1 Before (org.junit.Before)1