Search in sources :

Example 1 with HandlersConfigurerTestWrapper

use of com.yahoo.container.core.config.testutil.HandlersConfigurerTestWrapper 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 HandlersConfigurerTestWrapper

use of com.yahoo.container.core.config.testutil.HandlersConfigurerTestWrapper in project vespa by vespa-engine.

the class SearchChainConfigurerTestCase method testConfigurableSearcher.

@Test
public void testConfigurableSearcher() {
    HandlersConfigurerTestWrapper configurer = new HandlersConfigurerTestWrapper("dir:" + testDir);
    SearchChain configurable = getSearchChainRegistryFrom(configurer).getComponent("configurable");
    assertNotNull(configurable);
    Searcher s = configurable.searchers().get(0);
    assertThat(s, instanceOf(ConfigurableSearcher.class));
    ConfigurableSearcher searcher = (ConfigurableSearcher) s;
    assertThat("Value from int.cfg file", searcher.intConfig.intVal(), is(7));
    assertThat("Value from string.cfg file", searcher.stringConfig.stringVal(), is("com.yahoo.search.searchchain.config.test"));
    configurer.shutdown();
}
Also used : HandlersConfigurerTestWrapper(com.yahoo.container.core.config.testutil.HandlersConfigurerTestWrapper) Searcher(com.yahoo.search.Searcher) SearchChain(com.yahoo.search.searchchain.SearchChain) Test(org.junit.Test)

Example 3 with HandlersConfigurerTestWrapper

use of com.yahoo.container.core.config.testutil.HandlersConfigurerTestWrapper in project vespa by vespa-engine.

the class SearchChainConfigurerTestCase method testConfiguration.

@Test
public synchronized void testConfiguration() throws Exception {
    HandlersConfigurerTestWrapper configurer = new HandlersConfigurerTestWrapper("dir:" + testDir);
    SearchChain simple = getSearchChainRegistryFrom(configurer).getComponent("simple");
    assertNotNull(simple);
    assertThat(getSearcherNumbers(simple), is(Arrays.asList(1, 2, 3)));
    SearchChain child1 = getSearchChainRegistryFrom(configurer).getComponent("child:1");
    assertThat(getSearcherNumbers(child1), is(Arrays.asList(1, 2, 4, 5, 7, 8)));
    SearchChain child2 = getSearchChainRegistryFrom(configurer).getComponent("child");
    assertThat(getSearcherNumbers(child2), is(Arrays.asList(3, 6, 7, 9)));
    // Verify successful loading of an explicitly declared searcher that takes no user-defined configs.
    // assertNotNull(SearchChainRegistry.get().getSearcherRegistry().getComponent
    // ("com.yahoo.search.searchchain.config.test.SearchChainConfigurerTestCase$DeclaredTestSearcher"));
    configurer.shutdown();
}
Also used : HandlersConfigurerTestWrapper(com.yahoo.container.core.config.testutil.HandlersConfigurerTestWrapper) SearchChain(com.yahoo.search.searchchain.SearchChain) Test(org.junit.Test)

Example 4 with HandlersConfigurerTestWrapper

use of com.yahoo.container.core.config.testutil.HandlersConfigurerTestWrapper in project vespa by vespa-engine.

the class SearchChainConfigurerTestCase method testSearcherConfigUpdate.

/**
 * Verifies that only searchers with updated config are re-instantiated after a config update
 * that does not contain any bootstrap configs.
 */
@Test
public void testSearcherConfigUpdate() throws IOException, InterruptedException {
    File cfgDir = getCfgDir();
    copyFile(testDir + "handlers.cfg", cfgDir + "/handlers.cfg");
    copyFile(testDir + "qr-search.cfg", cfgDir + "/qr-search.cfg");
    copyFile(testDir + "qr-searchers.cfg", cfgDir + "/qr-searchers.cfg");
    copyFile(testDir + "index-info.cfg", cfgDir + "/index-info.cfg");
    copyFile(testDir + "specialtokens.cfg", cfgDir + "/specialtokens.cfg");
    copyFile(testDir + "three-searchers.cfg", cfgDir + "/chains.cfg");
    copyFile(testDir + "container-http.cfg", cfgDir + "/container-http.cfg");
    createComponentsConfig(testDir + "three-searchers.cfg", testDir + "handlers.cfg", cfgDir + "/components.cfg");
    printFile(new File(cfgDir + "/int.cfg"), "intVal 16\n");
    printFile(new File(cfgDir + "/string.cfg"), "stringVal \"testSearcherConfigUpdate\"\n");
    HandlersConfigurerTestWrapper configurer = new HandlersConfigurerTestWrapper("dir:" + cfgDir);
    SearcherRegistry searchers = getSearchChainRegistryFrom(configurer).getSearcherRegistry();
    assertThat(searchers.getComponentCount(), is(3));
    IntSearcher intSearcher = (IntSearcher) searchers.getComponent(IntSearcher.class.getName());
    assertThat(intSearcher.intConfig.intVal(), is(16));
    StringSearcher stringSearcher = (StringSearcher) searchers.getComponent(StringSearcher.class.getName());
    DeclaredTestSearcher noConfigSearcher = (DeclaredTestSearcher) searchers.getComponent(DeclaredTestSearcher.class.getName());
    // Update int config for IntSearcher,
    printFile(new File(cfgDir + "/int.cfg"), "intVal 17\n");
    configurer.reloadConfig();
    // Registry is rebuilt
    assertThat(getSearchChainRegistryFrom(configurer).getSearcherRegistry(), not(searchers));
    searchers = getSearchChainRegistryFrom(configurer).getSearcherRegistry();
    assertThat(searchers.getComponentCount(), is(3));
    // Searcher with updated config is re-instantiated.
    IntSearcher intSearcher2 = (IntSearcher) searchers.getComponent(IntSearcher.class.getName());
    assertThat(intSearcher2, not(sameInstance(intSearcher)));
    assertThat(intSearcher2.intConfig.intVal(), is(17));
    // Searchers with unchanged config (or that takes no config) are the same as before.
    Searcher s = searchers.getComponent(DeclaredTestSearcher.class.getName());
    assertThat((DeclaredTestSearcher) s, sameInstance(noConfigSearcher));
    s = searchers.getComponent(StringSearcher.class.getName());
    assertThat((StringSearcher) s, sameInstance(stringSearcher));
    configurer.shutdown();
    cleanup(cfgDir);
}
Also used : SearcherRegistry(com.yahoo.search.searchchain.SearcherRegistry) HandlersConfigurerTestWrapper(com.yahoo.container.core.config.testutil.HandlersConfigurerTestWrapper) Searcher(com.yahoo.search.Searcher) Test(org.junit.Test)

Example 5 with HandlersConfigurerTestWrapper

use of com.yahoo.container.core.config.testutil.HandlersConfigurerTestWrapper in project vespa by vespa-engine.

the class SearchChainConfigurerTestCase method testChainsConfigUpdate.

/**
 * Updates the chains config, while the searcher configs are unchanged.
 * Verifies that a new searcher that was not in the old config is instantiated,
 * and that a searcher that has been removed from the configuration is not in the new registry.
 */
@Test
public void testChainsConfigUpdate() throws IOException, InterruptedException {
    File cfgDir = getCfgDir();
    copyFile(testDir + "handlers.cfg", cfgDir + "/handlers.cfg");
    copyFile(testDir + "qr-search.cfg", cfgDir + "/qr-search.cfg");
    copyFile(testDir + "qr-searchers.cfg", cfgDir + "/qr-searchers.cfg");
    copyFile(testDir + "index-info.cfg", cfgDir + "/index-info.cfg");
    copyFile(testDir + "specialtokens.cfg", cfgDir + "/specialtokens.cfg");
    copyFile(testDir + "chainsConfigUpdate_1.cfg", cfgDir + "/chains.cfg");
    copyFile(testDir + "container-http.cfg", cfgDir + "/container-http.cfg");
    createComponentsConfig(testDir + "chainsConfigUpdate_1.cfg", testDir + "handlers.cfg", cfgDir + "/components.cfg");
    HandlersConfigurerTestWrapper configurer = new HandlersConfigurerTestWrapper("dir:" + cfgDir);
    SearchChainRegistry scReg = getSearchChainRegistryFrom(configurer);
    SearcherRegistry searchers = scReg.getSearcherRegistry();
    assertThat(searchers.getComponentCount(), is(2));
    assertThat(searchers.getComponent(IntSearcher.class.getName()), instanceOf(IntSearcher.class));
    assertThat(searchers.getComponent(StringSearcher.class.getName()), instanceOf(StringSearcher.class));
    assertThat(searchers.getComponent(ConfigurableSearcher.class.getName()), nullValue());
    assertThat(searchers.getComponent(DeclaredTestSearcher.class.getName()), nullValue());
    IntSearcher intSearcher = (IntSearcher) searchers.getComponent(IntSearcher.class.getName());
    // Update chains config
    copyFile(testDir + "chainsConfigUpdate_2.cfg", cfgDir + "/chains.cfg");
    createComponentsConfig(testDir + "chainsConfigUpdate_2.cfg", testDir + "handlers.cfg", cfgDir + "/components.cfg");
    configurer.reloadConfig();
    assertThat(getSearchChainRegistryFrom(configurer), not(scReg));
    // In the new registry, the correct searchers are removed and added
    assertThat(getSearchChainRegistryFrom(configurer).getSearcherRegistry(), not(searchers));
    searchers = getSearchChainRegistryFrom(configurer).getSearcherRegistry();
    assertThat(searchers.getComponentCount(), is(3));
    assertThat((IntSearcher) searchers.getComponent(IntSearcher.class.getName()), sameInstance(intSearcher));
    assertThat(searchers.getComponent(ConfigurableSearcher.class.getName()), instanceOf(ConfigurableSearcher.class));
    assertThat(searchers.getComponent(DeclaredTestSearcher.class.getName()), instanceOf(DeclaredTestSearcher.class));
    assertThat(searchers.getComponent(StringSearcher.class.getName()), nullValue());
    configurer.shutdown();
    cleanup(cfgDir);
}
Also used : SearcherRegistry(com.yahoo.search.searchchain.SearcherRegistry) HandlersConfigurerTestWrapper(com.yahoo.container.core.config.testutil.HandlersConfigurerTestWrapper) SearchChainRegistry(com.yahoo.search.searchchain.SearchChainRegistry) Test(org.junit.Test)

Aggregations

HandlersConfigurerTestWrapper (com.yahoo.container.core.config.testutil.HandlersConfigurerTestWrapper)8 Test (org.junit.Test)4 Container (com.yahoo.container.Container)3 SearchHandler (com.yahoo.search.handler.SearchHandler)3 HttpRequest (com.yahoo.container.jdisc.HttpRequest)2 Searcher (com.yahoo.search.Searcher)2 HttpSearchResponse (com.yahoo.search.handler.HttpSearchResponse)2 SearchChain (com.yahoo.search.searchchain.SearchChain)2 SearcherRegistry (com.yahoo.search.searchchain.SearcherRegistry)2 RequestHandlerTestDriver (com.yahoo.container.jdisc.RequestHandlerTestDriver)1 SearchChainRegistry (com.yahoo.search.searchchain.SearchChainRegistry)1 File (java.io.File)1 Before (org.junit.Before)1